public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: infrun: fix function name in start_step_over debug message
@ 2021-10-26 15:13 Simon Marchi
  0 siblings, 0 replies; only message in thread
From: Simon Marchi @ 2021-10-26 15:13 UTC (permalink / raw)
  To: gdb-patches

The debug messages in the SCOPE_EXIT of start_step_over currently appear
like this:

    [infrun] start_step_over: enter
      [infrun] start_step_over: stealing global queue of threads to step, length = 0
      [infrun] operator(): step-over queue now empty
    [infrun] start_step_over: exit

The function name on the 3rd line is wrong because __func__ resolves to
the name of the method on the temporary RAII object used to implement
SCOPE_EXIT.  This is worked around in stop_all_threads by hardcoding the
function name, but I don't really like it, as if this code is ever
moved, it is doomed to become stale.

Instead, put the function name in a static-local variable outside scope
exit, and refer to it in the SCOPE_EXIT.  If the function gets renamed
or this code is moved, the function name will follow.  Add new macros to
allow passing down the function name all the way down.  Fix
start_step_over and stop_all_threads.  After the patch, we get the
expected / clearer:

    [infrun] start_step_over: enter
      [infrun] start_step_over: stealing global queue of threads to step, length = 0
      [infrun] start_step_over: step-over queue now empty
    [infrun] start_step_over: exit

Change-Id: I7e232f8f9653dd272bf18aba225db026d5c58f5a
---
 gdb/infrun.c              | 14 +++++++++-----
 gdb/infrun.h              |  5 +++++
 gdbsupport/common-debug.h | 12 ++++++++++++
 3 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/gdb/infrun.c b/gdb/infrun.c
index edc0e8f1d730..f59c7bed6426 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -1867,14 +1867,17 @@ start_step_over (void)
   /* On scope exit (whatever the reason, return or exception), if there are
      threads left in the THREADS_TO_STEP chain, put back these threads in the
      global list.  */
+  static const char *func = __func__;
   SCOPE_EXIT
     {
       if (threads_to_step.empty ())
-	infrun_debug_printf ("step-over queue now empty");
+	infrun_debug_printf_func (func, "step-over queue now empty");
       else
 	{
-	  infrun_debug_printf ("putting back %d threads to step in global queue",
-			       thread_step_over_chain_length (threads_to_step));
+	  infrun_debug_printf_func (func,
+				    "putting back %d threads to step in global "
+				    "queue",
+				    thread_step_over_chain_length (threads_to_step));
 
 	  global_thread_step_over_chain_enqueue_chain
 	    (std::move (threads_to_step));
@@ -4934,6 +4937,8 @@ stop_all_threads (void)
       target_thread_events (true);
     }
 
+  static const char *func = __func__;
+
   SCOPE_EXIT
     {
       /* Disable thread events of all targets.  */
@@ -4945,8 +4950,7 @@ stop_all_threads (void)
 
       /* Use debug_prefixed_printf directly to get a meaningful function
 	 name.  */
-      if (debug_infrun)
-	debug_prefixed_printf ("infrun", "stop_all_threads", "done");
+      infrun_debug_printf_func (func, "done");
     };
 
   /* Request threads to stop, and then wait for the stops.  Because
diff --git a/gdb/infrun.h b/gdb/infrun.h
index c5f98d9d305a..fe7eec7636aa 100644
--- a/gdb/infrun.h
+++ b/gdb/infrun.h
@@ -38,6 +38,11 @@ extern bool debug_infrun;
 #define infrun_debug_printf(fmt, ...) \
   debug_prefixed_printf_cond (debug_infrun, "infrun", fmt, ##__VA_ARGS__)
 
+/* Same as the above, but function name FUNC is passed explicitly.  */
+
+#define infrun_debug_printf_func(func, fmt, ...) \
+  debug_prefixed_printf_cond_func(debug_infrun, "infrun", func, fmt, ##__VA_ARGS__)
+
 /* Print "infrun" start/end debug statements.  */
 
 #define INFRUN_SCOPED_DEBUG_START_END(msg) \
diff --git a/gdbsupport/common-debug.h b/gdbsupport/common-debug.h
index 8b9b0040719d..f6d8b9d6640c 100644
--- a/gdbsupport/common-debug.h
+++ b/gdbsupport/common-debug.h
@@ -71,6 +71,18 @@ extern void ATTRIBUTE_PRINTF (3, 0) debug_prefixed_vprintf
     } \
   while (0)
 
+/* Same as the above, but function name FUNC is passed explicitly.  */
+
+#define debug_prefixed_printf_cond_func(debug_enabled_cond, module, func, fmt, ...) \
+  do \
+    { \
+      if (debug_enabled_cond) \
+	debug_prefixed_printf (module, func, fmt, ##__VA_ARGS__); \
+    } \
+  while (0)
+
+/* Same as the above, but don't include the function name in the message.  */
+
 #define debug_prefixed_printf_cond_nofunc(debug_enabled_cond, module, fmt, ...) \
   do \
     { \
-- 
2.33.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-10-26 15:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-26 15:13 [PATCH] gdb: infrun: fix function name in start_step_over debug message Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).