@@ -481,28 +481,38 @@ is also printed if stdio is not available.
481
481
#include "pl-debug.h"
482
482
483
483
#if O_DEBUG
484
- #define DEBUG (n , g ) do \
485
- { if (DEBUGGING(n)) \
486
- { ENTER_DEBUG(n); g; EXIT_DEBUG(n); } \
487
- } while(0)
488
- #define ENTER_DEBUG (n ) pl_internaldebugstatus_t \
489
- __orig_ld_debug = GLOBAL_LD->internal_debug, \
490
- __new_ld_debug = GLOBAL_LD->internal_debug = \
491
- (pl_internaldebugstatus_t) \
492
- { .channel = DEBUGGING(n) ? prolog_debug_topic_name(n) : NULL, \
493
- .depth = __orig_ld_debug.depth + 1, \
494
- }
495
- #define EXIT_DEBUG (n ) GLOBAL_LD->internal_debug = \
496
- ( GLOBAL_LD->internal_debug.depth != __new_ld_debug.depth \
497
- ? Sdprintf("DEBUG stack depth mismatch! %d != %d\n", GLOBAL_LD->internal_debug.depth, __new_ld_debug.depth) \
498
- : 1 \
499
- ) ? __orig_ld_debug : __orig_ld_debug
484
+ #define DEBUG (n , g ) \
485
+ do \
486
+ { if (DEBUGGING(n)) \
487
+ { PL_local_data_t *__dbg_ld = GLOBAL_LD; \
488
+ if ( __dbg_ld ) \
489
+ { ENTER_DEBUG(__dbg_ld, n); g; EXIT_DEBUG(__dbg_ld, n); \
490
+ } else \
491
+ { g; \
492
+ } \
493
+ } \
494
+ } while(0)
495
+ #define ENTER_DEBUG (ld , n ) \
496
+ pl_internaldebugstatus_t \
497
+ __orig_ld_debug = ld->internal_debug, \
498
+ __new_ld_debug = ld->internal_debug = \
499
+ (pl_internaldebugstatus_t) \
500
+ { .channel = DEBUGGING(n) ? prolog_debug_topic_name(n) : NULL, \
501
+ .depth = __orig_ld_debug.depth + 1, \
502
+ }
503
+ #define EXIT_DEBUG (ld , n ) \
504
+ ld->internal_debug = \
505
+ ( GLOBAL_LD->internal_debug.depth != __new_ld_debug.depth \
506
+ ? Sdprintf("DEBUG stack depth mismatch! %d != %d\n", \
507
+ GLOBAL_LD->internal_debug.depth, __new_ld_debug.depth) \
508
+ : 1 \
509
+ ) ? __orig_ld_debug : __orig_ld_debug
500
510
#define DEBUGGING (n ) ((n) <= DBG_LEVEL9 ? GD->debug_level >= (n) : \
501
511
(GD->debug_topics && true_bit(GD->debug_topics, n)))
502
- #define WITH_DEBUG_FOR (n ) for \
503
- ( ENTER_DEBUG(n); \
504
- __orig_ld_debug.depth >= 0; \
505
- EXIT_DEBUG(n), __orig_ld_debug.depth = -1 )
512
+ #define WITH_DEBUG_FOR (n ) for \
513
+ ( ENTER_DEBUG(GLOBAL_LD, n); \
514
+ __orig_ld_debug.depth >= 0; \
515
+ EXIT_DEBUG(GLOBAL_LD, n), __orig_ld_debug.depth = -1 )
506
516
#define IF_DEBUGGING (n ) if (DEBUGGING(n)) WITH_DEBUG_FOR(n)
507
517
508
518
/* We want to use the version of Sdprintf with the debug channel, if possible */
@@ -512,8 +522,8 @@ int Sdprintf_ex(const char *channel, const char *file, int line, const char *fm,
512
522
513
523
#else
514
524
#define DEBUG (a , b ) ((void)0)
515
- #define ENTER_DEBUG (n ) ;
516
- #define EXIT_DEBUG (n ) ;
525
+ #define ENTER_DEBUG (ld , n ) ;
526
+ #define EXIT_DEBUG (ld , n ) ;
517
527
#define DEBUGGING (n ) false
518
528
#define WITH_DEBUG_FOR (n ) /* empty */
519
529
#define IF_DEBUGGING (n ) if (0)
0 commit comments