This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] infrun debug output: Print the random signal's enum name in debug output in addition to its number.


The other day while debugging something related to random signals, I
got confused with "set debug infrun 1" output, for it said:

 infrun: TARGET_WAITKIND_STOPPED
 infrun: stop_pc = 0x323d4e8b94
 infrun: random signal 20

On GNU/Linux, 20 is SIGTSTP.  For some reason, it took me a few
minutes to realize that 20 is actually a GDB signal number, not a
target signal number (duh!).  In any case, I propose making GDB's
output clearer here:

One way would be to use gdb_signal_to_name, like already used
elsewhere:

 infrun: TARGET_WAITKIND_STOPPED
 infrun: stop_pc = 0x323d4e8b94
 infrun: random signal SIGCHLD (20)

but I think that'd confuse me too.  So I thought of printing the enum
string instead:

 infrun: TARGET_WAITKIND_STOPPED
 infrun: stop_pc = 0x323d4e8b94
 infrun: random signal GDB_SIGNAL_CHLD (20)

Suprisingly (to me), there's no method to get a string version of the
enum symbol, so this adds one.

I'll apply this after a short while if there are no objections.

Tested on x86_64 Fedora 17.

gdb/
2013-10-21  Pedro Alves  <palves@redhat.com>

	* common/signals.c (signals): New field 'symbol'.
	(SET): Use the 'symbol' parameter.
	(gdb_signal_to_symbol_string): New function.
	* infrun.c (handle_inferior_event) <random signal>: In debug
	output, print the random signal enum as string in addition to its
	number.
---
 gdb/common/gdb_signals.h |  4 ++++
 gdb/common/signals.c     | 11 ++++++++++-
 gdb/infrun.c             |  5 +++--
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/gdb/common/gdb_signals.h b/gdb/common/gdb_signals.h
index 76e64f8..e02d1ee 100644
--- a/gdb/common/gdb_signals.h
+++ b/gdb/common/gdb_signals.h
@@ -42,6 +42,10 @@ extern int gdb_signal_to_host_p (enum gdb_signal signo);
 extern enum gdb_signal gdb_signal_from_host (int);
 extern int gdb_signal_to_host (enum gdb_signal);
 
+/* Return the enum symbol name of SIG as a string, to use in debug
+   output.  */
+extern const char *gdb_signal_to_symbol_string (enum gdb_signal sig);
+
 /* Return the string for a signal.  */
 extern const char *gdb_signal_to_string (enum gdb_signal);
 
diff --git a/gdb/common/signals.c b/gdb/common/signals.c
index 4b3b951..1609544 100644
--- a/gdb/common/signals.c
+++ b/gdb/common/signals.c
@@ -50,15 +50,24 @@ struct gdbarch;
    gdb_signal.  */
 
 static const struct {
+  const char *symbol;
   const char *name;
   const char *string;
   } signals [] =
 {
-#define SET(symbol, constant, name, string) { name, string },
+#define SET(symbol, constant, name, string) { #symbol, name, string },
 #include "gdb/signals.def"
 #undef SET
 };
 
+const char *
+gdb_signal_to_symbol_string (enum gdb_signal sig)
+{
+  if ((int) sig >= GDB_SIGNAL_FIRST && (int) sig <= GDB_SIGNAL_LAST)
+    return signals[sig].symbol;
+  else
+    return "?";
+}
 
 /* Return the string for a signal.  */
 const char *
diff --git a/gdb/infrun.c b/gdb/infrun.c
index b1f9611..715b462 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -4322,10 +4322,11 @@ process_event_stop_test:
       /* Signal not for debugging purposes.  */
       int printed = 0;
       struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
+      enum gdb_signal stop_signal = ecs->event_thread->suspend.stop_signal;
 
       if (debug_infrun)
-	 fprintf_unfiltered (gdb_stdlog, "infrun: random signal %d\n",
-			     ecs->event_thread->suspend.stop_signal);
+	 fprintf_unfiltered (gdb_stdlog, "infrun: random signal %s (%d)\n",
+			     gdb_signal_to_symbol_string (stop_signal), stop_signal);
 
       stopped_by_random_signal = 1;
 
-- 
1.7.11.7


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]