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]

unbreak tracepoints with no actions


t->commands is NULL if there are no actions, so GDB currently
crashes in the t->commands->commands statement in encode_actions,
when you do simply:

 (gdb) trace foo
 (gdb) tstart
 Program received signal SIGSEGV, Segmentation fault.
 0x00000000004c5cae in encode_actions (t=0xd262e0, tloc=0xd26440, tdp_actions=0x7fffffffc920, stepping_actions=0x7fffffffc918)
     at ../../src/gdb/tracepoint.c:1442
 1442      actions = t->commands->commands;
 (top-gdb) p t->commands
 $1 = (struct counted_command_line *) 0x0

 (top-gdb) bt
 #0  0x00000000004c5cae in encode_actions (t=0xd262e0, tloc=0xd26440, tdp_actions=0x7fffffffc920,
     stepping_actions=0x7fffffffc918) at ../../src/gdb/tracepoint.c:1442
 #1  0x00000000004bf25e in remote_download_tracepoint (t=0xd262e0) at ../../src/gdb/remote.c:9383
 #2  0x00000000004c5f9f in start_tracing () at ../../src/gdb/tracepoint.c:1534
 #3  0x00000000004c6107 in trace_start_command (args=0x0, from_tty=1) at ../../src/gdb/tracepoint.c:1580

I've applied this patch to fix it.  Fixes a bunch of regressions
in the gdb.trace/ tests, but only visible if you have a target
that does tracing.

-- 
Pedro Alves

2010-04-02  Pedro Alves  <pedro@codesourcery.com>

	gdb/
	* breakpoint.h (struct counted_command_line): Moved definition to
	breakpoint.c, and forward declare.
	(breakpoint_commands): Declare.
	* breakpoint.c (struct counted_command_line): Moved here.
	(breakpoint_commands): New.
	* tracepoint.c (encode_actions): Use breakpoint_commands.
	* remote.c (remote_download_tracepoint): Ditto.

---
 gdb/breakpoint.c |   16 ++++++++++++++++
 gdb/breakpoint.h |   16 +++++++---------
 gdb/remote.c     |    2 +-
 gdb/tracepoint.c |    6 +++---
 4 files changed, 27 insertions(+), 13 deletions(-)

Index: src/gdb/breakpoint.h
===================================================================
--- src.orig/gdb/breakpoint.h	2010-04-02 02:13:51.000000000 +0100
+++ src/gdb/breakpoint.h	2010-04-02 02:15:53.000000000 +0100
@@ -384,15 +384,9 @@ typedef struct bp_location *bp_location_
 DEF_VEC_P(bp_location_p);
 
 /* A reference-counted struct command_line.  This lets multiple
-   breakpoints share a single command list.  */
-struct counted_command_line
-{
-  /* The reference count.  */
-  int refc;
-
-  /* The command list.  */
-  struct command_line *commands;
-};
+   breakpoints share a single command list.  This is an implementation
+   detail to the breakpoints module.  */
+struct counted_command_line;
 
 /* Note that the ->silent field is not currently used by any commands
    (though the code is in there if it was to be, and set_raw_breakpoint
@@ -814,6 +808,10 @@ extern void delete_breakpoint (struct br
 
 extern void breakpoint_auto_delete (bpstat);
 
+/* Return the chain of command lines to execute when this breakpoint
+   is hit.  */
+extern struct command_line *breakpoint_commands (struct breakpoint *b);
+
 extern void break_command (char *, int);
 
 extern void hbreak_command_wrapper (char *, int);
Index: src/gdb/breakpoint.c
===================================================================
--- src.orig/gdb/breakpoint.c	2010-04-02 02:13:51.000000000 +0100
+++ src/gdb/breakpoint.c	2010-04-02 02:15:53.000000000 +0100
@@ -222,6 +222,22 @@ static void disable_trace_command (char 
 
 static void trace_pass_command (char *, int);
 
+/* A reference-counted struct command_line.  This lets multiple
+   breakpoints share a single command list.  */
+struct counted_command_line
+{
+  /* The reference count.  */
+  int refc;
+
+  /* The command list.  */
+  struct command_line *commands;
+};
+
+struct command_line *
+breakpoint_commands (struct breakpoint *b)
+{
+  return b->commands ? b->commands->commands : NULL;
+}
 
 /* Flag indicating that a command has proceeded the inferior past the
    current breakpoint.  */
Index: src/gdb/tracepoint.c
===================================================================
--- src.orig/gdb/tracepoint.c	2010-04-02 02:14:22.000000000 +0100
+++ src/gdb/tracepoint.c	2010-04-02 02:16:27.000000000 +0100
@@ -1439,7 +1439,7 @@ encode_actions (struct breakpoint *t, st
   gdbarch_virtual_frame_pointer (t->gdbarch,
 				 t->loc->address, &frame_reg, &frame_offset);
 
-  actions = t->commands->commands;
+  actions = breakpoint_commands (t);
 
   /* If there are default expressions to collect, make up a collect
      action and prepend to the action list to encode.  Note that since
@@ -1458,7 +1458,7 @@ encode_actions (struct breakpoint *t, st
 
       default_collect_action = xmalloc (sizeof (struct command_line));
       make_cleanup (xfree, default_collect_action);
-      default_collect_action->next = t->commands->commands;
+      default_collect_action->next = actions;
       default_collect_action->line = line;
       actions = default_collect_action;
     }
@@ -2417,7 +2417,7 @@ trace_dump_command (char *args, int from
     if (loc->address == regcache_read_pc (regcache))
       stepping_frame = 0;
 
-  for (action = t->commands->commands; action; action = action->next)
+  for (action = breakpoint_commands (t); action; action = action->next)
     {
       struct cmd_list_element *cmd;
 
Index: src/gdb/remote.c
===================================================================
--- src.orig/gdb/remote.c	2010-04-02 02:14:22.000000000 +0100
+++ src/gdb/remote.c	2010-04-02 02:15:53.000000000 +0100
@@ -9507,7 +9507,7 @@ remote_download_tracepoint (struct break
 		warning (_("Target does not support source download."));
 	    }
 	  remote_download_command_source (t->number, loc->address,
-					  t->commands->commands);
+					  breakpoint_commands (t));
 	}
 
       do_cleanups (old_chain);


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