From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id C0E47397301A for ; Fri, 11 Dec 2020 19:01:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C0E47397301A X-ASG-Debug-ID: 1607713303-0c856e6cd54322b0001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id jTiCrCAoPCP8Muq2 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 11 Dec 2020 14:01:43 -0500 (EST) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.localdomain (173-246-6-90.qc.cable.ebox.net [173.246.6.90]) by smtp.ebox.ca (Postfix) with ESMTP id 85466441D64; Fri, 11 Dec 2020 14:01:43 -0500 (EST) From: Simon Marchi X-Barracuda-RBL-IP: 173.246.6.90 X-Barracuda-Effective-Source-IP: 173-246-6-90.qc.cable.ebox.net[173.246.6.90] X-Barracuda-Apparent-Source-IP: 173.246.6.90 To: gdb-patches@sourceware.org Subject: [pushed] gdb: factor out debug_prefixed_printf_cond Date: Fri, 11 Dec 2020 14:01:43 -0500 X-ASG-Orig-Subj: [pushed] gdb: factor out debug_prefixed_printf_cond Message-Id: <20201211190143.2176592-1-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1607713303 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 6999 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.50 X-Barracuda-Spam-Status: No, SCORE=0.50 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests=BSF_RULE7568M X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.86454 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.50 BSF_RULE7568M Custom Rule 7568M X-Spam-Status: No, score=-16.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_QUARANTINE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Dec 2020 19:01:46 -0000 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 | 9 +++++++++ gdb/displaced-stepping.h | 7 +------ gdb/dwarf2/read.c | 16 ++++------------ gdb/infrun.h | 7 +------ gdb/linux-nat.c | 7 +------ gdbsupport/ChangeLog | 6 ++++++ gdbsupport/common-debug.h | 17 +++++++++++++++++ gdbsupport/event-loop.h | 8 ++------ 8 files changed, 41 insertions(+), 36 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 992da3db3022..787ee0d60a6b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +2020-12-11 Simon Marchi + + * 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 * p-exp.y (intvar): Remove global. diff --git a/gdb/displaced-stepping.h b/gdb/displaced-stepping.h index d1a1cebb93e1..146c3d0feb2e 100644 --- a/gdb/displaced-stepping.h +++ b/gdb/displaced-stepping.h @@ -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 { diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 2bf14535f051..91f669b1e834 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -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; diff --git a/gdb/infrun.h b/gdb/infrun.h index d5e6d279f1a0..4a4db84baa88 100644 --- a/gdb/infrun.h +++ b/gdb/infrun.h @@ -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. */ diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index f1b2c744bed9..da5f277b5530 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -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 { diff --git a/gdbsupport/ChangeLog b/gdbsupport/ChangeLog index 417e44aff31d..6be1f245bc5b 100644 --- a/gdbsupport/ChangeLog +++ b/gdbsupport/ChangeLog @@ -1,3 +1,9 @@ +2020-12-11 Simon Marchi + + * 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 * pathstuff.cc (get_standard_cache_dir): Use LOCALAPPDATA environment diff --git a/gdbsupport/common-debug.h b/gdbsupport/common-debug.h index f9ddccab0633..7bc62185f7ab 100644 --- a/gdbsupport/common-debug.h +++ b/gdbsupport/common-debug.h @@ -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 */ diff --git a/gdbsupport/event-loop.h b/gdbsupport/event-loop.h index 68808997364b..09d665f7e69d 100644 --- a/gdbsupport/event-loop.h +++ b/gdbsupport/event-loop.h @@ -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). */ -- 2.29.2