Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Enduro/X Debug library header
0003  *
0004  * @file ndebug.h
0005  */
0006 /* -----------------------------------------------------------------------------
0007  * Enduro/X Middleware Platform for Distributed Transaction Processing
0008  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0010  * This software is released under one of the following licenses:
0011  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012  * See LICENSE file for full text.
0013  * -----------------------------------------------------------------------------
0014  * AGPL license:
0015  *
0016  * This program is free software; you can redistribute it and/or modify it under
0017  * the terms of the GNU Affero General Public License, version 3 as published
0018  * by the Free Software Foundation;
0019  *
0020  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023  * for more details.
0024  *
0025  * You should have received a copy of the GNU Affero General Public License along 
0026  * with this program; if not, write to the Free Software Foundation, Inc.,
0027  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028  *
0029  * -----------------------------------------------------------------------------
0030  * A commercial use license is available from Mavimax, Ltd
0031  * contact@mavimax.com
0032  * -----------------------------------------------------------------------------
0033  */
0034 #ifndef NDEBUG_H
0035 #define NDEBUG_H
0036 
0037 #ifdef  __cplusplus
0038 extern "C" {
0039 #endif
0040 /*---------------------------Includes-----------------------------------*/
0041 #include <ndrx_config.h>
0042 #include <stdio.h>
0043 #include <limits.h>
0044 #include <thlock.h>
0045 #include <stdarg.h>
0046 #include <ndebugcmn.h>
0047 #include <nstd_tls.h>
0048 #include <userlog.h>
0049 #include <errno.h>
0050 #include <fpalloc.h>
0051 /*---------------------------Externs------------------------------------*/
0052 extern NDRX_API ndrx_debug_t G_ubf_debug;
0053 extern NDRX_API ndrx_debug_t G_tp_debug;
0054 extern NDRX_API ndrx_debug_t G_ndrx_debug;
0055 extern NDRX_API ndrx_debug_t G_stdout_debug;
0056 extern NDRX_API volatile int G_ndrx_debug_first;
0057 /*---------------------------Macros-------------------------------------*/
0058 
0059 /*
0060  * Log levels
0061  */
0062 #define log_always                  1 
0063 #define log_error                   2
0064 #define log_warn                    3
0065 #define log_info                    4
0066 #define log_debug                   5
0067 #define log_dump                    6
0068 
0069 /*
0070  * Logging settings
0071  */
0072 /** settings for ATMI logging        */
0073 #define LOG_FACILITY_NDRX           0x00000001
0074 /** settings for UBF logging         */
0075 #define LOG_FACILITY_UBF            0x00000002
0076 /** settings for TP logging          */
0077 #define LOG_FACILITY_TP             0x00000004
0078 /** settings for TP, thread based logging */
0079 #define LOG_FACILITY_TP_THREAD      0x00000008
0080 /** tp, Request logging, thread based*/
0081 #define LOG_FACILITY_TP_REQUEST     0x00000010
0082 /** ndrx thread logging              */
0083 #define LOG_FACILITY_NDRX_THREAD    0x00000020
0084 /** ubf thread logging               */
0085 #define LOG_FACILITY_UBF_THREAD     0x00000040
0086 /** ndrx request logging             */
0087 #define LOG_FACILITY_NDRX_REQUEST   0x00000080
0088 /** ubf request logging              */
0089 #define LOG_FACILITY_UBF_REQUEST    0x00000100
0090 
0091 /** process level logging facility flag */
0092 #define LOG_FACILITY_PROCESS        0x00010000
0093 
0094 /** Mask of the log facility bitwise flags */
0095 #define LOG_FACILITY_MASK           0x0000ffff
0096 
0097 /** first byte is reserved for log level (should not collide with LOG_FACILITY!) */
0098 #define TPLOGQI_RET_HAVDETAILED     0x00010000
0099 /** Bit offset for log level in return of info query */
0100 #define TPLOGQI_RET_DBGLEVBITS      24
0101 
0102 /** Macros for extracting log level from query results */
0103 #define TPLOGQI_RET_DBGLEVGET(LEV)  LEV >> TPLOGQI_RET_DBGLEVBITS
0104 
0105 /** Get log level for NDRXD        */
0106 #define TPLOGQI_GET_NDRX            0x00000001
0107 /** Get log level for UBF        */
0108 #define TPLOGQI_GET_UBF             0x00000002
0109 /** Get level for tp logger */
0110 #define TPLOGQI_GET_TP              0x00000004
0111 /** Eval detailed flag  */
0112 #define TPLOGQI_EVAL_DETAILED       0x00000008
0113 /** Return results (log level & detailed flag) event logging shall not be done */
0114 #define TPLOGQI_EVAL_RETURN         0x00000010
0115 
0116 
0117 /** Integration flags, detailed logging (incl. stack backtrace) */
0118 #define LOG_IFLAGS_DETAILED         "detailed"
0119 #define LOG_THREADED_TEMPL          0x0001      /**< threaded by templates    */
0120 #define LOG_THREADED_LINEL          0x0002      /**< threaded by line lock    */
0121 
0122 #define LOG_CODE_NDRX               'N'
0123 #define LOG_CODE_UBF                'U'
0124 #define LOG_CODE_TP                 't'
0125 #define LOG_CODE_TP_THREAD          'T'
0126 #define LOG_CODE_TP_REQUEST         'R'
0127 
0128 #define LOG_CODE_NDRX_THREAD        'n'
0129 #define LOG_CODE_NDRX_REQUEST       'm'
0130 
0131 #define LOG_CODE_UBF_THREAD         'u'
0132 #define LOG_CODE_UBF_REQUEST        'v'
0133 
0134 
0135 /**
0136  * Wait two seconds to let other threads to finish with
0137  * logging before closing & re-opening debug logger
0138  * This logic might be changed in future to introduce RW locks.
0139  */
0140 #define NDRX_LOG_SWAIT_DEFAULT      2000
0141 
0142 #define NDRX_DBG_MAX_LEV log_dump
0143 
0144 /**
0145  * Have double check on G_ndrx_debug_first, as on after getting first mutex, object
0146  * might be already initialized
0147  * Maybe want to think of checking only ndrx_G_shmcfg_ver, but then we need atomic
0148  * pointer swap during the init to avoid any concurrent threads reading the
0149  * memory address and getting some partial pointer. 
0150  * Thus G_ndrx_debug_first can be set to OK, only when shmcfg init is completed.
0151  */
0152 #define NDRX_DBG_INIT_ENTRY    if (NDRX_UNLIKELY(G_ndrx_debug_first) || NDRX_UNLIKELY(ndrx_G_shmcfgver_chk!=ndrx_G_shmcfg_ver->shmcfgver_lcf)) \
0153     {\
0154         if (NDRX_UNLIKELY(G_ndrx_debug_first)) { ndrx_dbg_lock(); if (G_ndrx_debug_first) { ndrx_init_debug(); } ndrx_dbg_unlock();}\
0155         ndrx_lcf_run();\
0156     }
0157 
0158 #define UBF_DBG_INIT(X) (ndrx_dbg_init X )
0159 #define NDRX_DBG_INIT(X) (ndrx_dbg_init X )
0160 
0161 /*
0162  * This logger can be used for very early bootstrapping logs - logging when
0163  * logger is not yet initialised.
0164  * Thus we run alternate route in case init lock is acquired.
0165  */
0166 #define NDRX_LOG_EARLY(lev, fmt, ...) do {if (ndrx_dbg_intlock_isset()) {\
0167     __ndrx_debug__(&G_ndrx_debug, lev, __FILE__, __LINE__, __func__, fmt, ##__VA_ARGS__);} else {\
0168     NDRX_DBG_INIT_ENTRY; if (lev<=G_ndrx_debug.level)\
0169     {__ndrx_debug__(&G_ndrx_debug, lev, __FILE__, __LINE__, __func__, fmt, ##__VA_ARGS__);}}} while(0)
0170 
0171 #define UBF_LOG_EARLY(lev, fmt, ...) do {if (ndrx_dbg_intlock_isset()) {\
0172     __ndrx_debug__(&G_ubf_debug, lev, __FILE__, __LINE__, __func__, fmt, ##__VA_ARGS__);} else {\
0173     NDRX_DBG_INIT_ENTRY; if (lev<=G_ubf_debug.level)\
0174     {__ndrx_debug__(&G_ubf_debug, lev, __FILE__, __LINE__, __func__, fmt, ##__VA_ARGS__);}}} while (0)
0175 
0176 #define TP_LOG_EARLY(lev, fmt, ...) do {if (ndrx_dbg_intlock_isset()) {\
0177     __ndrx_debug__(&G_tp_debug, lev, __FILE__, __LINE__, __func__, fmt, ##__VA_ARGS__);} else {\
0178     NDRX_DBG_INIT_ENTRY; if (lev<=G_tp_debug.level)\
0179     {__ndrx_debug__(&G_tp_debug, lev, __FILE__, __LINE__, __func__, fmt, ##__VA_ARGS__);}}} while (0)
0180 
0181 /*
0182  * Normal loggers 
0183  */
0184 #define NDRX_LOG(lev, fmt, ...) do {NDRX_DBG_INIT_ENTRY; if (lev<=G_ndrx_debug.level)\
0185     {__ndrx_debug__(&G_ndrx_debug, lev, __FILE__, __LINE__, __func__, fmt, ##__VA_ARGS__);}} while (0)
0186 
0187 #define NDRX_LOGEX(lev, file, line, fmt, ...) do {NDRX_DBG_INIT_ENTRY; if (lev<=G_ndrx_debug.level)\
0188     {__ndrx_debug__(&G_ndrx_debug, lev, file, line, __func__, fmt, ##__VA_ARGS__);}} while (0)
0189 
0190 #define UBF_LOG(lev, fmt, ...) do {NDRX_DBG_INIT_ENTRY; if (lev<=G_ubf_debug.level)\
0191     {__ndrx_debug__(&G_ubf_debug, lev, __FILE__, __LINE__, __func__, fmt, ##__VA_ARGS__);}} while (0)
0192 
0193 #define UBF_LOGEX(lev, file, line, fmt, ...) do {NDRX_DBG_INIT_ENTRY; if (lev<=G_ubf_debug.level)\
0194     {__ndrx_debug__(&G_ubf_debug, lev, file, line, __func__, fmt, ##__VA_ARGS__);}} while (0)
0195 
0196 /* User logging */
0197 #define TP_LOG(lev, fmt, ...) do {NDRX_DBG_INIT_ENTRY; if (lev<=G_tp_debug.level)\
0198     {__ndrx_debug__(&G_tp_debug, lev, __FILE__, __LINE__, __func__, fmt, ##__VA_ARGS__);}} while (0)
0199 
0200 /* Extended user logging, with filename name and line */
0201 #define TP_LOGEX(lev, file, line, fmt, ...) do {NDRX_DBG_INIT_ENTRY; if (lev<=G_tp_debug.level)\
0202     {__ndrx_debug__(&G_tp_debug, lev, file, line, __func__, fmt, ##__VA_ARGS__);}} while (0)
0203 
0204 #define TP_LOGGETIFLAGS do {NDRX_DBG_INIT_ENTRY; return G_tp_debug.iflags; } while (0)
0205 
0206 #define UBF_DUMP(lev,comment,ptr,len) do {NDRX_DBG_INIT_ENTRY; if (lev<=G_ubf_debug.level)\
0207     {__ndrx_debug_dump__(&G_ubf_debug, lev, __FILE__, __LINE__, __func__, comment, ptr, len);}} while (0)
0208 
0209 #define NDRX_DUMP(lev,comment,ptr,len) do {NDRX_DBG_INIT_ENTRY; if (lev<=G_ndrx_debug.level)\
0210     {__ndrx_debug_dump__(&G_ndrx_debug, lev, __FILE__, __LINE__, __func__, comment, ptr, len);}} while (0)
0211 
0212 #define STDOUT_DUMP(lev,comment,ptr,len) do {NDRX_DBG_INIT_ENTRY; if (lev<=G_stdout_debug.level)\
0213     {__ndrx_debug_dump__(&G_stdout_debug, lev, __FILE__, __LINE__, __func__, comment, ptr, len);}} while (0)
0214 
0215 #define TP_DUMP(lev,comment,ptr,len) do {NDRX_DBG_INIT_ENTRY; if (lev<=G_tp_debug.level)\
0216     {__ndrx_debug_dump__(&G_tp_debug, lev, __FILE__, __LINE__, __func__, comment, ptr, len);}} while (0)
0217 
0218 
0219 #define UBF_DUMP_DIFF(lev,comment,ptr,ptr2,len) do {NDRX_DBG_INIT_ENTRY; if (lev<=G_ubf_debug.level)\
0220     {__ndrx_debug_dump_diff__(&G_ubf_debug, lev, __FILE__, __LINE__, __func__, comment, ptr, ptr2, len);}} while (0)
0221 
0222 #define NDRX_DUMP_DIFF(lev,comment,ptr,ptr2,len) do {NDRX_DBG_INIT_ENTRY; if (lev<=G_ndrx_debug.level)\
0223     {__ndrx_debug_dump_diff__(&G_ndrx_debug, lev, __FILE__, __LINE__, __func__, comment, ptr, ptr2, len);}} while (0)
0224 
0225 #define TP_DUMP_DIFF(lev,comment,ptr,ptr2,len) do {NDRX_DBG_INIT_ENTRY; if (lev<=G_tp_debug.level)\
0226     {__ndrx_debug_dump_diff__(&G_tp_debug, lev, __FILE__, __LINE__, __func__, comment, ptr, ptr2, len);}} while (0)
0227 
0228 #define NDRX_DBG_SETTHREAD(X) ndrx_dbg_setthread(X)
0229 
0230 /* Standard replacements for system errors */
0231 /* Debug msg for malloc: */
0232 #define NDRX_ERR_MALLOC(SZ)        NDRX_LOG(log_error, "Failed to allocate %ld bytes", SZ)
0233 
0234 /* Memory debug macros */
0235 
0236 
0237 #ifdef EX_HAVE_ASPRINTF
0238 
0239 #define NDRX_ASPRINTF_INT(strp, lenp, fmt, ...) do {\
0240         (*strp) = NULL;\
0241         if (((*lenp) = asprintf(strp, fmt, ##__VA_ARGS__)) < 0 && NULL!=*strp)  \
0242         {\
0243             NDRX_FREE((*strp)); \
0244             (*strp)=NULL;\
0245         }\
0246     } while (0)
0247 
0248 #else
0249 
0250 /**
0251  * Perform sprintf to newly allocated buffer
0252  * @param strp double ptr to char buffer that will be allocated. In case of error it will
0253  *  be deallocated and set to NULL
0254  * @param lenp ptr to long type where on error -1 is returned, for 
0255  */
0256 #define NDRX_ASPRINTF_INT(strp, lenp, fmt, ...) do {\
0257         int Emh39KCmwH0M_numbytes;\
0258         (*strp) = NULL;\
0259         Emh39KCmwH0M_numbytes = snprintf( (char*)NULL, 0, fmt, ##__VA_ARGS__);\
0260         if (Emh39KCmwH0M_numbytes > 0)\
0261         {\
0262             (*strp) = NDRX_MALLOC(Emh39KCmwH0M_numbytes+1);\
0263             (*lenp) = snprintf( (*strp), Emh39KCmwH0M_numbytes+1, fmt, ##__VA_ARGS__);\
0264             if ((*lenp) < 0) \
0265             {\
0266                 int Emh39KCmwH0M_errno = errno;\
0267                 NDRX_FREE((*strp)); \
0268                 errno = Emh39KCmwH0M_errno;\
0269                 (*strp)=NULL;\
0270             }\
0271         }\
0272     }\
0273     while (0)
0274 #endif
0275 
0276 /**
0277  * Allocate the ATMI system buffer (MALLOC mode, just a hint)
0278  */
0279 #define NDRX_SYSBUF_MALLOC_OUT(__buf, __p_bufsz, __ret) \
0280 do {\
0281     int __buf_size__ = NDRX_MSGSIZEMAX;\
0282     __buf = NDRX_FPMALLOC(__buf_size__, NDRX_FPSYSBUF);\
0283     if (NULL==__buf)\
0284     {\
0285         int err = errno;\
0286         NDRX_LOG(log_error, "%s: failed to allocate sysbuf: %s", __func__,  strerror(errno));\
0287         userlog("%s: failed to allocate sysbuf: %s", __func__,  strerror(errno));\
0288         errno = err;\
0289         EXFAIL_OUT(__ret);\
0290     }\
0291     __p_bufsz = __buf_size__;\
0292 } while (0)
0293 
0294 /**
0295  * Free up resources
0296  */
0297 #define NDRX_SYSBUF_FREE(__buf) NDRX_FPFREE(__buf)
0298 
0299 #ifdef NDRX_MEMORY_DEBUG
0300 
0301 #define NDRX_MALLOC(size) ndrx_malloc_dbg(size, __LINE__, __FILE__, __func__)
0302 #define NDRX_FREE(ptr) ndrx_free_dbg(ptr, __LINE__, __FILE__, __func__)
0303 #define NDRX_CALLOC(nmemb, size) ndrx_calloc_dbg(nmemb, size, __LINE__, __FILE__, __func__)
0304 #define NDRX_REALLOC(ptr, size) ndrx_realloc_dbg(ptr, size, __LINE__, __FILE__, __func__)
0305 #define NDRX_STRDUP(ptr) ndrx_strdup_dbg(ptr, __LINE__, __FILE__, __func__)
0306 
0307 #define NDRX_FOPEN(path, mode) ndrx_fopen_dbg(path, mode, __LINE__, __FILE__, __func__)
0308 #define NDRX_FCLOSE(fp) ndrx_fclose_dbg(fp,__LINE__, __FILE__, __func__)
0309 
0310 /* Have some extra debug here */
0311 #define NDRX_ASPRINTF(strp, lenp, fmt, ...) do {\
0312     NDRX_ASPRINTF_INT(strp, lenp, fmt, ##__VA_ARGS__)\
0313     userlog("[%p] <= asprintf(%s):%s %s:%ld", *strp, fmt, __func__, __FILE__, __LINE__);\
0314     } while (0)
0315 #else
0316 
0317 #define NDRX_MALLOC(size) malloc(size)
0318 #define NDRX_FREE(ptr) free(ptr)
0319 #define NDRX_CALLOC(nmemb, size) calloc(nmemb, size)
0320 #define NDRX_REALLOC(ptr, size) realloc(ptr, size)
0321 #define NDRX_STRDUP(ptr) strdup(ptr)
0322 
0323 #define NDRX_FPMALLOC(size, flags) ndrx_fpmalloc(size, flags)
0324 #define NDRX_FPREALLOC(ptr, size) ndrx_fprealloc(ptr, size)
0325 #define NDRX_FPFREE(ptr) ndrx_fpfree(ptr)
0326 
0327 #define NDRX_FOPEN(path, mode) fopen(path, mode)
0328 #define NDRX_FCLOSE(fp) fclose(fp)
0329 
0330 /**
0331  * Sprintf with memory allocation. In case of error, strp will be NULL.
0332  * Note that this requires _GNU_SOURCE before include of stdio in start of C file.
0333  * @param strp double ptr to hander that will be allocated
0334  * @param fmt format string
0335  * @param ... var args
0336  */
0337 #define NDRX_ASPRINTF(strp, lenp, fmt, ...) NDRX_ASPRINTF_INT(strp, lenp, fmt, ##__VA_ARGS__)
0338 
0339 #endif
0340 
0341 /* Quick macros for standard memory allocation with error printing and
0342  * returning to out with ret flag
0343  */
0344 
0345 /**
0346  * Allocate buffer, if error goto out. Do not init memory to 0
0347  * @param PTR__ pointer to give the address to 
0348  * @param SIZE__ number of bytes to allocate
0349  * @param TYPE__ type to allocated buffer (dest type not ptr)
0350  */
0351 #define NDRX_MALLOC_OUT(PTR__, SIZE__, TYPE__) \
0352 if ( (PTR__ = (TYPE__ *)NDRX_MALLOC(SIZE__)) == NULL) \
0353 {\
0354     int ERR__ = errno;\
0355     NDRX_LOG(log_error, "%s: Failed to mallocate %ld bytes: %s",\
0356         __func__, (long)SIZE__, strerror(ERR__));\
0357     userlog("%s: Failed to mallocate %ld bytes: %s",\
0358         __func__, (long)SIZE__, strerror(ERR__));\
0359     EXFAIL_OUT(ret);\
0360 }
0361 
0362 /**
0363  * Duplicate the string and in case of error fail out in standard way
0364  * @param DST__ dest pointer
0365  * @param SRC__ source pointer
0366  */
0367 #define NDRX_STRDUP_OUT(DST__, SRC__) \
0368 if ( (DST__ = NDRX_STRDUP(SRC__)) == NULL) \
0369 {\
0370     int ERR__ = errno;\
0371     NDRX_LOG(log_error, "%s: Failed to strdup [%s]: %s",\
0372         __func__, SRC__, strerror(ERR__));\
0373     userlog("%s: Failed to strdup [%s] bytes: %s",\
0374         __func__, SRC__, strerror(ERR__));\
0375     EXFAIL_OUT(ret);\
0376 }
0377 
0378 /**
0379  * Allocate buffer, if error goto out. Do init memory to 0
0380  * @param PTR__ pointer to give the address to 
0381  * @param NMEMB__ Number of members
0382  * @param SIZE__ number of bytes to allocate
0383  * @param TYPE__ type to allocated buffer (dest type not ptr)
0384  */
0385 #define NDRX_CALLOC_OUT(PTR__, NMEMB__, SIZE__, TYPE__) \
0386 if ( (PTR__ = (TYPE__ *)NDRX_CALLOC(NMEMB__, SIZE__)) == NULL) \
0387 {\
0388     int ERR__ = errno;\
0389     NDRX_LOG(log_error, "%s: Failed to callocate %ld bytes: %s",\
0390         __func__, (long)(NMEMB__ *SIZE__), strerror(ERR__));\
0391     userlog("%s: Failed to mallocate %ld bytes: %s",\
0392         __func__, (long)(NMEMB__ *SIZE__), strerror(ERR__));\
0393     EXFAIL_OUT(ret);\
0394 }
0395 
0396 /**
0397  * Standard logging of malloc error
0398  * @param X size to allocate
0399  */
0400 #define NDRX_MALLOC_FAIL_NDRX(X) \
0401 {\
0402     int ERR__ = errno;\
0403     NDRX_LOG(log_error, "Failed to malloc %ld bytes: %s",\
0404         (long)X, strerror(ERR__));\
0405     userlog("Failed to malloc %ld bytes: %s",\
0406         __func__, (long)X, strerror(ERR__));\
0407     EXFAIL_OUT(ret);\
0408 }
0409 
0410 /*---------------------------Enums--------------------------------------*/
0411 /*---------------------------Typedefs-----------------------------------*/
0412 /*---------------------------Globals------------------------------------*/
0413 /*---------------------------Statics------------------------------------*/
0414 /*---------------------------Prototypes---------------------------------*/
0415 /* Real externals... */
0416 extern NDRX_API void ndrx_dbg_init(char *module, char *config_key);
0417 extern NDRX_API void ndrx_dbg_setlev(ndrx_debug_t *dbg_ptr, int level);
0418 extern NDRX_API int debug_get_ndrx_level(void);
0419 extern NDRX_API int debug_get_ubf_level(void);
0420 extern NDRX_API int debug_get_tp_level(void);
0421 extern NDRX_API ndrx_debug_t * debug_get_ndrx_ptr(void);
0422 extern NDRX_API ndrx_debug_t * debug_get_ubf_ptr(void);
0423 extern NDRX_API ndrx_debug_t * debug_get_tp_ptr(void);
0424 
0425 extern NDRX_API void __ndrx_debug__(ndrx_debug_t *dbg_ptr, int lev, const char *file, 
0426         long line, const char *func, const char *fmt, ...);
0427 
0428 extern NDRX_API void __ndrx_debug_dump_diff__(ndrx_debug_t *dbg_ptr, int lev, const char *file, 
0429         long line, const char *func, const char *comment, void *ptr, void *ptr2, long len);
0430 
0431 extern NDRX_API void __ndrx_debug_dump__(ndrx_debug_t *dbg_ptr, int lev, const char *file, 
0432         long line, const char *func, const char *comment, void *ptr, long len);
0433 
0434 extern NDRX_API void ndrx_dbg_lock(void);
0435 extern NDRX_API void ndrx_dbg_unlock(void);
0436 extern NDRX_API void ndrx_dbg_pid_update(void);
0437 extern NDRX_API void ndrx_init_debug(void);
0438 extern NDRX_API void ndrx_dbg_setthread(long threadnr);
0439 extern NDRX_API int ndrx_dbg_intlock_isset(void);
0440 
0441 /* TPLOG: */
0442 
0443 extern NDRX_API void tplogdumpdiff(int lev, const char *comment, void *ptr1, void *ptr2, int len);
0444 extern NDRX_API void tplogdump(int lev, const char *comment, void *ptr, int len);
0445 extern NDRX_API void tplog(int lev, const char *message);
0446 extern NDRX_API long tplogqinfo(int lev, long flags);
0447 
0448 /* extended logging: */
0449 extern NDRX_API void tplogex(int lev, const char *file, long line, const char *message);
0450 extern NDRX_API void ndrxlogex(int lev, const char *file, long line, const char *message);
0451 extern NDRX_API void ubflogex(int lev, const char *file, long line, const char *message);
0452 
0453 /* get integration flags: */
0454 extern NDRX_API char * tploggetiflags(void);
0455 
0456 extern NDRX_API void ndrxlogdumpdiff(int lev, const char *comment, void *ptr1, void *ptr2, int len);
0457 extern NDRX_API void ndrxlogdump(int lev, const char *comment, void *ptr, int len);
0458 extern NDRX_API void ndrxlog(int lev, const char *message);
0459 
0460 extern NDRX_API void ubflogdumpdiff(int lev, const char *comment, void *ptr1, void *ptr2, int len);
0461 extern NDRX_API void ubflogdump(int lev, const char *comment, void *ptr, int len);
0462 extern NDRX_API void ubflog(int lev, const char *message);
0463 
0464 extern NDRX_API int tploggetreqfile(char *filename, int bufsize);
0465 extern NDRX_API int tplogconfig(int logger, int lev, const char *debug_string, const char *module, const char *new_file);
0466 extern NDRX_API int tplogreopen(void);
0467 extern NDRX_API void tplogclosereqfile(void);
0468 extern NDRX_API void tplogclosethread(void);
0469 extern NDRX_API void tplogsetreqfile_direct(const char *filename);
0470 extern NDRX_API void ndrx_nstd_tls_loggers_close(nstd_tls_t *tls);
0471 
0472 extern NDRX_API ndrx_debug_t * tplogfplock(int lev, long flags);
0473 extern NDRX_API FILE *tplogfpget(ndrx_debug_t *dbg, long flags);
0474 extern NDRX_API void tplogfpunlock(ndrx_debug_t *dbg);
0475 
0476 /* memory debugging */
0477 extern NDRX_API void *ndrx_malloc_dbg(size_t size, long line, const char *file, const char *func);
0478 extern NDRX_API void ndrx_free_dbg(void *ptr, long line, const char *file, const char *func);
0479 extern NDRX_API void *ndrx_calloc_dbg(size_t nmemb, size_t size, long line, const char *file, const char *func);
0480 extern NDRX_API void *ndrx_realloc_dbg(void *ptr, size_t size, long line, const char *file, const char *func);
0481 
0482 
0483 extern NDRX_API FILE *ndrx_fopen_dbg(const char *path, const char *mode, long line, const char *file, const char *func);
0484 extern NDRX_API int ndrx_fclose_dbg(FILE *fp, long line, const char *file, const char *func);
0485 extern NDRX_API char *ndrx_strdup_dbg(char *ptr, long line, const char *file, const char *func);
0486 
0487 
0488 /* Bootstrapping: */
0489 extern NDRX_API int ndrx_dbg_intlock_isset(void);
0490 extern NDRX_API void ndrx_dbg_intlock_set(void);
0491 extern NDRX_API void ndrx_dbg_intlock_unset(int *do_reply);
0492 extern NDRX_API void ndrx_dbg_reply_memlog_all(void);
0493 extern NDRX_API int ndrx_lcf_run(void);
0494 
0495 #ifdef  __cplusplus
0496 }
0497 #endif
0498 
0499 #endif  /* NDEBUG_H */
0500 
0501 /* vim: set ts=4 sw=4 et smartindent: */