]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
tracepoint->step_count fixes
authorPedro Alves <palves@redhat.com>
Thu, 4 Apr 2013 19:15:55 +0000 (19:15 +0000)
committerPedro Alves <palves@redhat.com>
Thu, 4 Apr 2013 19:15:55 +0000 (19:15 +0000)
If a tracepoint's actions list includes a while-stepping action, and
then the actions are changed to a list without any while-stepping
action, the tracepoint's step_count will be left with a stale value.
For example:

 (gdb) trace subr
 Tracepoint 1 at 0x4004d9: file ../../../src/gdb/testsuite//actions-changed.c, line 31.
 (gdb) actions
 Enter actions for tracepoint 1, one per line.
 End with a line saying just "end".
 >collect $reg
 >end
 (gdb) set debug remote 1
 (gdb) tstart
 Sending packet: $QTinit#59...Packet received: OK
 Sending packet: $QTDP:1:00000000004004d9:E:0:0-#a3...Packet received: OK
 Sending packet: $QTDP:-1:00000000004004d9:R03FFFFFFFFFFFFFFFFFF#2b...Packet received: OK
 (gdb) tstop
 Sending packet: $QTStop#4b...Packet received: OK
 Sending packet: $QTNotes:#e8...Packet received: OK
 (gdb) actions
 Enter actions for tracepoint 1, one per line.
 End with a line saying just "end".
 >collect $reg
 >while-stepping 1
   >collect $reg
   >end
 >end
 (gdb) tstart
 Sending packet: $QTinit#59...Packet received: OK
 Sending packet: $QTDP:1:00000000004004d9:E:1:0-#a4...Packet received: OK
 Sending packet: $QTDP:-1:00000000004004d9:R03FFFFFFFFFFFFFFFFFF-#58...Packet received: OK
 Sending packet: $QTDP:-1:00000000004004d9:SR03FFFFFFFFFFFFFFFFFF#7e...Packet received: OK
 (gdb) tstop
 Sending packet: $QTStop#4b...Packet received: OK
 Sending packet: $QTNotes:#e8...Packet received: OK
 (gdb) actions
 Enter actions for tracepoint 1, one per line.
 End with a line saying just "end".
 >collect $regs
 >end
 (gdb) tstart
 Sending packet: $QTinit#59...Packet received: OK
 Sending packet: $QTDP:1:00000000004004d9:E:1:0-#a4...Packet received: OK
 Sending packet: $QTDP:-1:00000000004004d9:R03FFFFFFFFFFFFFFFFFF#2b...Packet received: OK

The last "$QTDP:1:00000000004004d9:E:1:0-#a4" should be "$QTDP:1:00000000004004d9:E:0:0-#a3".
In pseudo-diff:

  -$QTDP:1:00000000004004d9:E:1:0-#a4
  +$QTDP:1:00000000004004d9:E:0:0-#a3

A related issue is that the "commands" command actually supports
setting commands to a range of breakpoints/tracepoints at once.  But,
hacking "maint info breakpoints" to print t->step_count, reveals:

 (gdb) trace main
 Tracepoint 5 at 0x45a2ab: file ../../src/gdb/gdb.c, line 29.
 (gdb) trace main
 Note: breakpoint 5 also set at pc 0x45a2ab.
 Tracepoint 6 at 0x45a2ab: file ../../src/gdb/gdb.c, line 29.
 (gdb) commands 5-6
 Type commands for breakpoint(s) 5-6, one per line.
 End with a line saying just "end".
 > while-stepping 5
  >end
 > end
 (gdb) maint info breakpoints 5
 Num     Type           Disp Enb Address            What
 5       tracepoint     keep y   0x000000000045a2ab in main at ../../src/gdb/gdb.c:29 inf 1
         step_count=5
         ^^^^^^^^^^^^
         while-stepping 5
         end
         not installed on target
 (gdb) maint info breakpoints 6
 Num     Type           Disp Enb Address            What
 6       tracepoint     keep y   0x000000000045a2ab in main at ../../src/gdb/gdb.c:29 inf 1
         step_count=0
         ^^^^^^^^^^^^
         while-stepping 5
         end
         not installed on target
 (gdb)

that tracepoint 6 doesn't end up with the correct step_count.

The issue is that here:

 static void
 do_map_commands_command (struct breakpoint *b, void *data)
 {
  struct commands_info *info = data;

  if (info->cmd == NULL)
    {
      struct command_line *l;

      if (info->control != NULL)
l = copy_command_lines (info->control->body_list[0]);
      else
{
  struct cleanup *old_chain;
  char *str;

  str = xstrprintf (_("Type commands for breakpoint(s) "
      "%s, one per line."),
    info->arg);

  old_chain = make_cleanup (xfree, str);

  l = read_command_lines (str,
  info->from_tty, 1,
  (is_tracepoint (b)
   ? check_tracepoint_command : 0),
  b);

  do_cleanups (old_chain);
}

      info->cmd = alloc_counted_command_line (l);
    }

validate_actionline is never called for tracepoints other than the
first (the copy_command_lines path).  Right below, we have:

  /* If a breakpoint was on the list more than once, we don't need to
     do anything.  */
  if (b->commands != info->cmd)
    {
      validate_commands_for_breakpoint (b, info->cmd->commands);
      incref_counted_command_line (info->cmd);
      decref_counted_command_line (&b->commands);
      b->commands = info->cmd;
      observer_notify_breakpoint_modified (b);
    }

And validate_commands_for_breakpoint looks like the right place to put
a call; if we reset step_count there too, we have a nice central fix
for the first issue as well, because trace_actions_command calls
breakpoint_set_commands that also calls
validate_commands_for_breakpoint.

We end up calling validate_actionline twice for the first tracepoint,
since read_command_lines calls it too, through
check_tracepoint_command, but that should be harmless.

2013-04-04  Pedro Alves  <palves@redhat.com>
    Hui Zhu  <hui@codesourcery.com>

* breakpoint.c (validate_commands_for_breakpoint): If validating a
tracepoint, reset its STEP_COUNT and call validate_actionline.

2013-04-04  Stan Shebs  <stan@codesourcery.com>
    Pedro Alves  <palves@redhat.com>

* gdb.trace/Makefile.in (PROGS): Add actions-changed.
* gdb.trace/actions-changed.c: New file.
* gdb.trace/actions-changed.exp: New file.
* lib/trace-support.exp (gdb_trace_setactions): Rename to ...
(gdb_trace_setactions_command): ... this.  Add "actions_command"
parameter, and handle it.
(gdb_trace_setactions, gdb_trace_setcommands): New procedures.

gdb/ChangeLog
gdb/breakpoint.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.trace/Makefile.in
gdb/testsuite/lib/trace-support.exp

index 4f8875f93982a2727772b81511a203b8653bc665..bbe96ef9f6f82927a5748443bc9f9d3ea790d12d 100644 (file)
@@ -1,3 +1,9 @@
+2013-04-04  Pedro Alves  <palves@redhat.com>
+           Hui Zhu  <hui@codesourcery.com>
+
+       * breakpoint.c (validate_commands_for_breakpoint): If validating a
+       tracepoint, reset its STEP_COUNT and call validate_actionline.
+
 2013-04-03  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
        * NEWS (Changes in GDB 7.6): Update the data-disassemble for "fullname".
index e5ee4d0e28fc343c6c5dda54dadc1f58d9940bb2..d038bd2f1aa3db5f9db5d310f38de58f76c9de07 100644 (file)
@@ -1141,12 +1141,25 @@ validate_commands_for_breakpoint (struct breakpoint *b,
 {
   if (is_tracepoint (b))
     {
-      /* We need to verify that each top-level element of commands is
-        valid for tracepoints, that there's at most one
-        while-stepping element, and that while-stepping's body has
-        valid tracing commands excluding nested while-stepping.  */
+      struct tracepoint *t = (struct tracepoint *) b;
       struct command_line *c;
       struct command_line *while_stepping = 0;
+
+      /* Reset the while-stepping step count.  The previous commands
+         might have included a while-stepping action, while the new
+         ones might not.  */
+      t->step_count = 0;
+
+      /* We need to verify that each top-level element of commands is
+        valid for tracepoints, that there's at most one
+        while-stepping element, and that the while-stepping's body
+        has valid tracing commands excluding nested while-stepping.
+        We also need to validate the tracepoint action line in the
+        context of the tracepoint --- validate_actionline actually
+        has side effects, like setting the tracepoint's
+        while-stepping STEP_COUNT, in addition to checking if the
+        collect/teval actions parse and make sense in the
+        tracepoint's context.  */
       for (c = commands; c; c = c->next)
        {
          if (c->control_type == while_stepping_control)
@@ -1164,6 +1177,8 @@ validate_commands_for_breakpoint (struct breakpoint *b,
              else
                while_stepping = c;
            }
+
+         validate_actionline (&c->line, b);
        }
       if (while_stepping)
        {
index 068a08952672a77ad6453c20d041dfb3226be556..59d806adf6d52414271e6f483191d88f15fbbd7f 100644 (file)
@@ -1,3 +1,14 @@
+2013-04-04  Stan Shebs  <stan@codesourcery.com>
+           Pedro Alves  <palves@redhat.com>
+
+       * gdb.trace/Makefile.in (PROGS): Add actions-changed.
+       * gdb.trace/actions-changed.c: New file.
+       * gdb.trace/actions-changed.exp: New file.
+       * lib/trace-support.exp (gdb_trace_setactions): Rename to ...
+       (gdb_trace_setactions_command): ... this.  Add "actions_command"
+       parameter, and handle it.
+       (gdb_trace_setactions, gdb_trace_setcommands): New procedures.
+
 2013-04-04  Yao Qi  <yao@codesourcery.com>
 
        * gdb.server/server-kill.exp: Use command 'tstatus' instead of
index 8a7d523da2b968ac66d3a5582d691b88cb07d7cb..2e23223dd18e886cdb94efc7a3589451d30da685 100644 (file)
@@ -3,9 +3,9 @@ srcdir = @srcdir@
 
 .PHONY: all clean mostlyclean distclean realclean
 
-PROGS = ax backtrace deltrace disconnected-tracing infotrace packetlen \
-       passc-dyn passcount report save-trace tfile tfind tracecmd tsv \
-       unavailable while-dyn while-stepping
+PROGS = actions-changed ax backtrace deltrace disconnected-tracing \
+       infotrace packetlen passc-dyn passcount report save-trace tfile \
+       tfind tracecmd tsv unavailable while-dyn while-stepping
 
 all info install-info dvi install uninstall installcheck check:
        @echo "Nothing to be done for $@..."
index 2c0c999994a922b6b3a87d73ccb43a907c05c30a..653a464a5ca1b2f47d76ad9db8d50b368c64391a 100644 (file)
@@ -86,23 +86,23 @@ proc gdb_delete_tracepoints {} {
     }
 }
 
-#
-# Procedure: gdb_trace_setactions
 #   Define actions for a tracepoint.
 #   Arguments:
+#       actions_command -- the command used to create the actions.
+#                          either "actions" or "commands".
 #      testname   -- identifying string for pass/fail output
-#      tracepoint -- to which tracepoint do these actions apply? (optional)
+#      tracepoint -- to which tracepoint(s) do these actions apply? (optional)
 #      args       -- list of actions to be defined.
 #   Returns:
 #      zero       -- success
 #      non-zero   -- failure
 
-proc gdb_trace_setactions { testname tracepoint args } {
+proc gdb_trace_setactions_command { actions_command testname tracepoint args } {
     global gdb_prompt;
 
     set state 0;
     set passfail "pass";
-    send_gdb "actions $tracepoint\n";
+    send_gdb "$actions_command $tracepoint\n";
     set expected_result "";
     gdb_expect 5 {
        -re "No tracepoint number .*$gdb_prompt $" {
@@ -165,6 +165,20 @@ proc gdb_trace_setactions { testname tracepoint args } {
     }
 }
 
+# Define actions for a tracepoint, using the "actions" command.  See
+# gdb_trace_setactions_command.
+#
+proc gdb_trace_setactions { testname tracepoint args } {
+    eval gdb_trace_setactions_command "actions" {$testname} {$tracepoint} $args
+}
+
+# Define actions for a tracepoint, using the "commands" command.  See
+# gdb_trace_setactions_command.
+#
+proc gdb_trace_setcommands { testname tracepoint args } {
+    eval gdb_trace_setactions_command "commands" {$testname} {$tracepoint} $args
+}
+
 #
 # Procedure: gdb_tfind_test
 #   Find a specified trace frame.