summaryrefslogtreecommitdiff
path: root/perl.h
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2021-02-23 09:33:38 -0700
committerKarl Williamson <khw@cpan.org>2021-03-17 11:22:04 -0600
commit50e8f677c30c6af7e17d923d97f6c32fa36be35f (patch)
tree9f998c4a106698d14b1ada6132830df1b265de90 /perl.h
parent8aed2978e7b4c9fe0f26c471125a1ab2a1fd4802 (diff)
downloadperl-50e8f677c30c6af7e17d923d97f6c32fa36be35f.tar.gz
Add ability to easily add info to DEBUG output
This commit adds two macros that a user can define and recompile Perl to get every active DEBUG statement to do some thing beyond what it would normally do. This allows someone to recompile Perl when they need to delve deeper into fixing a bug without otherwise increasing memory use or slowing execution.
Diffstat (limited to 'perl.h')
-rw-r--r--perl.h35
1 files changed, 33 insertions, 2 deletions
diff --git a/perl.h b/perl.h
index 3235ee1254..17a21a1c42 100644
--- a/perl.h
+++ b/perl.h
@@ -4487,16 +4487,47 @@ Gid_t getegid (void);
} \
} STMT_END
+/* These allow you to customize your debugging output for specialized,
+ * generally temporary ad-hoc purposes. For example, if you need 'errno'
+ * preserved, you can add definitions to these macros (either in this file for
+ * the whole program, or before the #include "perl.h" in a particular .c file
+ * you're trying to debug) and recompile:
+ *
+ * #define DEBUG_PRE_STMTS dSAVE_ERRNO;
+ * #define DEBUG_POST_STMTS RESTORE_ERRNO;
+ *
+ * Other potential things include displaying timestamps, location information,
+ * which thread, etc. Heres an example with both errno and location info:
+ *
+ * #define DEBUG_PRE_STMTS dSAVE_ERRNO; \
+ * PerlIO_printf(Perl_debug_log, "%s:%d: ", __FILE__, __LINE__);
+ * #define DEBUG_POST RESTORE_ERRNO;
+ *
+ * All DEBUG statements in the compiled scope will be have these extra
+ * statements compiled in; they will be executed only for the DEBUG statements
+ * whose flags are turned on.
+ */
+#ifndef DEBUG_PRE_STMTS
+# define DEBUG_PRE_STMTS
+#endif
+#ifndef DEBUG_POST_STMTS
+# define DEBUG_POST_STMTS
+#endif
+
# define DEBUG__(t, a) \
STMT_START { \
- if (t) STMT_START {a;} STMT_END; \
+ if (t) STMT_START { \
+ DEBUG_PRE_STMTS a; DEBUG_POST_STMTS \
+ } STMT_END; \
} STMT_END
# define DEBUG_f(a) DEBUG__(DEBUG_f_TEST, a)
/* For re_comp.c, re_exec.c, assume -Dr has been specified */
# ifdef PERL_EXT_RE_BUILD
-# define DEBUG_r(a) STMT_START {a;} STMT_END
+# define DEBUG_r(a) STMT_START { \
+ DEBUG_PRE_STMTS a; DEBUG_POST_STMTS \
+ } STMT_END;
# else
# define DEBUG_r(a) DEBUG__(DEBUG_r_TEST, a)
# endif /* PERL_EXT_RE_BUILD */