aboutsummaryrefslogtreecommitdiffstats
path: root/pseudo.h
diff options
context:
space:
mode:
authorPeter Seebach <peter.seebach@windriver.com>2013-06-21 15:46:30 -0500
committerPeter Seebach <peter.seebach@windriver.com>2013-06-25 20:32:25 -0500
commite199ed80a0a67a2135d419e169ba378621dd55bd (patch)
treec284919558317f6a122df93438e2c93ce96acd68 /pseudo.h
parent62177dc38fabb880132e63aeef3b8d3878f9584c (diff)
downloadpseudo-e199ed80a0a67a2135d419e169ba378621dd55bd.tar.gz
pseudo-e199ed80a0a67a2135d419e169ba378621dd55bd.tar.bz2
pseudo-e199ed80a0a67a2135d419e169ba378621dd55bd.zip
Change debugging to use flags rather than levels
This is a moderately intrusive change. The basic overall effect: Debugging messages are now controlled, not by a numeric "level", but by a series of flags, which are expressed as a string of letters. Each flag has a single-letter form used for string specifications, a name, a description, a numeric value (1 through N), and a flag value (which is 1 << the numeric value). (This does mean that no flag has the value 1, so we only have 31 bits available. Tiny violins play.) The other significant change is that the pseudo_debug calls are now implemented with a do/while macro containing a conditional, so that computationally-expensive arguments are never evaluated if the corresponding debug flags weren't set. The assumption is that in the vast majority of cases (specifically, all of them so far) the debug flags for a given call are a compile-time constant, so the nested conditional will never actually show up in code when compiled with optimization; we'll just see the appropriate conditional test. The VERBOSE flag is magical, in that if the VERBOSE flag is used in a message, the debug flags have to have both VERBOSE and at least one other flag for the call to be made. This should dramatically improve performance for a lot of cases without as much need for PSEUDO_NDEBUG, and improve the ability of users to get coherent debugging output that means something and is relevant to a given case. It's also intended to set the stage for future development work involving improving the clarity and legibility of pseudo's diagnostic messages in general. Old things which used numeric values for PSEUDO_DEBUG will sort of continue to work, though they will almost always be less verbose than they used to. There should probably be a pass through adding "| PDBGF_CONSISTENCY" to a lot of the messages that are specific to some other type.
Diffstat (limited to 'pseudo.h')
-rw-r--r--pseudo.h15
1 files changed, 12 insertions, 3 deletions
diff --git a/pseudo.h b/pseudo.h
index 56760a4..15df164 100644
--- a/pseudo.h
+++ b/pseudo.h
@@ -33,12 +33,22 @@ char *pseudo_get_value(const char *key);
extern void pseudo_debug_verbose(void);
extern void pseudo_debug_terse(void);
+extern void pseudo_debug_set(char *);
+extern void pseudo_debug_clear(char *);
+extern void pseudo_debug_flags_finalize(void);
+extern unsigned long pseudo_util_debug_flags;
extern int pseudo_util_debug_fd;
extern int pseudo_disabled;
extern int pseudo_allow_fsync;
+extern int pseudo_diag(char *, ...) __attribute__ ((format (printf, 1, 2)));
#ifndef NDEBUG
-extern int pseudo_debug_real(int, char *, ...) __attribute__ ((format (printf, 2, 3)));
-#define pseudo_debug pseudo_debug_real
+#define pseudo_debug(x, ...) do { \
+ if ((x) & PDBGF_VERBOSE) { \
+ if ((pseudo_util_debug_flags & PDBGF_VERBOSE) && (pseudo_util_debug_flags & ((x) & ~PDBGF_VERBOSE))) { pseudo_diag(__VA_ARGS__); } \
+ } else { \
+ if (pseudo_util_debug_flags & (x)) { pseudo_diag(__VA_ARGS__); } \
+ } \
+} while (0)
#else
/* this used to be a static inline function, but that meant that arguments
* were still evaluated for side effects. We don't want that. The ...
@@ -46,7 +56,6 @@ extern int pseudo_debug_real(int, char *, ...) __attribute__ ((format (printf, 2
*/
#define pseudo_debug(...) 0
#endif
-extern int pseudo_diag(char *, ...) __attribute__ ((format (printf, 1, 2)));
void pseudo_new_pid(void);
/* pseudo_fix_path resolves symlinks up to this depth */
#define PSEUDO_MAX_LINK_RECURSION 16