gdb: factor out debug_prefixed_printf_cond
authorSimon Marchi <simon.marchi@polymtl.ca>
Fri, 11 Dec 2020 18:48:11 +0000 (13:48 -0500)
committerSimon Marchi <simon.marchi@polymtl.ca>
Fri, 11 Dec 2020 19:01:12 +0000 (14:01 -0500)
The same pattern happens often to define a "debug_printf" macro:

    #define displaced_debug_printf(fmt, ...) \
      do \
        { \
          if (debug_displaced) \
     debug_prefixed_printf ("displaced", __func__, fmt, ##__VA_ARGS__); \
        } \
      while (0)

Move this pattern behind a helper macro, debug_prefixed_printf_cond and
update the existing macros to use it.

gdb/ChangeLog:

* displaced-stepping.h (displaced_debug_printf): Use
debug_prefixed_printf_cond.
* dwarf2/read.c (dwarf_read_debug_printf): Likewise.
(dwarf_read_debug_printf_v): Likewise.
* infrun.h (infrun_debug_printf): Likewise.
* linux-nat.c (linux_nat_debug_printf): Likewise.

gdbsupport/ChangeLog:

* common-debug.h (debug_prefixed_printf_cond): New.
* event-loop.h (event_loop_debug_printf): Use
debug_prefixed_printf_cond.

Change-Id: I1ff48b98b8d1cc405d1c7e8da8ceadf4e3a17f99

gdb/ChangeLog
gdb/displaced-stepping.h
gdb/dwarf2/read.c
gdb/infrun.h
gdb/linux-nat.c
gdbsupport/ChangeLog
gdbsupport/common-debug.h
gdbsupport/event-loop.h

index 992da3db30223a1f3a17283326c6d57ea21539fb..787ee0d60a6b6f2880d10e85245d2ff9e7ea1015 100644 (file)
@@ -1,3 +1,12 @@
+2020-12-11  Simon Marchi  <simon.marchi@polymtl.ca>
+
+       * displaced-stepping.h (displaced_debug_printf): Use
+       debug_prefixed_printf_cond.
+       * dwarf2/read.c (dwarf_read_debug_printf): Likewise.
+       (dwarf_read_debug_printf_v): Likewise.
+       * infrun.h (infrun_debug_printf): Likewise.
+       * linux-nat.c (linux_nat_debug_printf): Likewise.
+
 2020-12-11  Tom Tromey  <tom@tromey.com>
 
        * p-exp.y (intvar): Remove global.
index d1a1cebb93e17623d93bea8ce481a6a9942dff97..146c3d0feb2eb4179e1c33f3538c9d045be00494 100644 (file)
@@ -33,12 +33,7 @@ extern bool debug_displaced;
 /* Print a "displaced" debug statement.  */
 
 #define displaced_debug_printf(fmt, ...) \
-  do \
-    { \
-      if (debug_displaced) \
-       debug_prefixed_printf ("displaced", __func__, fmt, ##__VA_ARGS__); \
-    } \
-  while (0)
+  debug_prefixed_printf_cond (debug_displaced, "displaced",fmt, ##__VA_ARGS__)
 
 enum displaced_step_prepare_status
 {
index 2bf14535f0518dd7909d2d0259d0a96aa190ad41..91f669b1e834c916d0f78f4586767d22598309b7 100644 (file)
@@ -96,22 +96,14 @@ static unsigned int dwarf_read_debug = 0;
 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 1.  */
 
 #define dwarf_read_debug_printf(fmt, ...) \
-  do \
-    { \
-      if (dwarf_read_debug >= 1) \
-       debug_prefixed_printf ("dwarf-read", __func__, fmt, ##__VA_ARGS__); \
-    } \
-  while (0)
+  debug_prefixed_printf_cond (dwarf_read_debug >= 1, "dwarf-read", fmt, \
+                             ##__VA_ARGS__)
 
 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 2.  */
 
 #define dwarf_read_debug_printf_v(fmt, ...) \
-  do \
-    { \
-      if (dwarf_read_debug >= 2) \
-       debug_prefixed_printf ("dwarf-read", __func__, fmt, ##__VA_ARGS__); \
-    } \
-  while (0)
+  debug_prefixed_printf_cond (dwarf_read_debug >= 2, "dwarf-read", fmt, \
+                             ##__VA_ARGS__)
 
 /* When non-zero, dump DIEs after they are read in.  */
 static unsigned int dwarf_die_debug = 0;
index d5e6d279f1a093d18959b8bd4e16376b5eaeb0a0..4a4db84baa880314f8efb300f3974ec2c4b31c93 100644 (file)
@@ -34,12 +34,7 @@ extern unsigned int debug_infrun;
 /* Print an "infrun" debug statement.  */
 
 #define infrun_debug_printf(fmt, ...) \
-  do \
-    { \
-      if (debug_infrun) \
-       debug_prefixed_printf ("infrun", __func__, fmt, ##__VA_ARGS__); \
-    } \
-  while (0)
+  debug_prefixed_printf_cond (debug_infrun, "infrun",fmt, ##__VA_ARGS__)
 
 /* Nonzero if we want to give control to the user when we're notified
    of shared library events by the dynamic linker.  */
index f1b2c744bed9be01ff21a74e86d2a45b60d4eb65..da5f277b5530ca386205ef983363354eb786bac7 100644 (file)
@@ -202,12 +202,7 @@ show_debug_linux_nat (struct ui_file *file, int from_tty,
 /* Print a linux-nat debug statement.  */
 
 #define linux_nat_debug_printf(fmt, ...) \
-  do \
-    { \
-      if (debug_linux_nat) \
-       debug_prefixed_printf ("linux-nat", __func__, fmt, ##__VA_ARGS__); \
-    } \
-  while (0)
+  debug_prefixed_printf_cond (debug_linux_nat, "linux-nat", fmt, ##__VA_ARGS__)
 
 struct simple_pid_list
 {
index 417e44aff31dc5ccdad140dbad85991d6dd46834..6be1f245bc5ba0f63420dfb92707c1b486468fc3 100644 (file)
@@ -1,3 +1,9 @@
+2020-12-11  Simon Marchi  <simon.marchi@polymtl.ca>
+
+       * common-debug.h (debug_prefixed_printf_cond): New.
+       * event-loop.h (event_loop_debug_printf): Use
+       debug_prefixed_printf_cond.
+
 2020-12-08  Alexander Fedotov  <alfedotov@gmail.com>
 
        * pathstuff.cc (get_standard_cache_dir): Use LOCALAPPDATA environment
index f9ddccab06331e3c97c5ceafa566a1f28f518757..7bc62185f7abf94488f5c6907bf0e1e6fbae5c62 100644 (file)
@@ -50,4 +50,21 @@ extern void ATTRIBUTE_PRINTF (3, 4) debug_prefixed_printf
 extern void ATTRIBUTE_PRINTF (3, 0) debug_prefixed_vprintf
   (const char *module, const char *func, const char *format, va_list args);
 
+
+/* Helper to define "_debug_print" macros.
+
+   DEBUG_ENABLED_COND is an expression that evaluates to true if the debugging
+   statement is enabled and should be printed.
+
+   The other arguments, as well as the name of the current function, are
+   forwarded to debug_prefixed_printf.  */
+
+#define debug_prefixed_printf_cond(debug_enabled_cond, module, fmt, ...) \
+  do \
+    { \
+      if (debug_enabled_cond) \
+       debug_prefixed_printf (module, __func__, fmt, ##__VA_ARGS__); \
+    } \
+  while (0)
+
 #endif /* COMMON_COMMON_DEBUG_H */
index 68808997364b287f8c71aa485b733286790f6197..09d665f7e69d4fe85404361d0e52d20d9513265d 100644 (file)
@@ -129,12 +129,8 @@ extern debug_event_loop_kind debug_event_loop;
 /* Print an "event loop" debug statement.  */
 
 #define event_loop_debug_printf(fmt, ...) \
-  do \
-    { \
-      if (debug_event_loop != debug_event_loop_kind::OFF) \
-       debug_prefixed_printf ("event-loop", __func__, fmt, ##__VA_ARGS__); \
-    } \
-  while (0)
+  debug_prefixed_printf_cond (debug_event_loop != debug_event_loop_kind::OFF, \
+                             "event-loop", fmt, ##__VA_ARGS__)
 
 /* Print an "event loop" debug statement that is know to come from a UI-related
    event (e.g. calling the event handler for the fd of the CLI).  */
This page took 0.043328 seconds and 4 git commands to generate.