gdbserver: on GDB breakpoint reinsertion, also delete the breakpoint's commands.
authorPedro Alves <palves@redhat.com>
Mon, 2 Jun 2014 21:27:32 +0000 (22:27 +0100)
committerPedro Alves <palves@redhat.com>
Mon, 2 Jun 2014 21:27:32 +0000 (22:27 +0100)
If GDB decides to change the breakpoint's conditions or commands,
it'll reinsert the same breakpoint again, with the new options
attached, without deleting the previous breakpoint.  E.g.,

 (gdb) set breakpoint always-inserted on
 (gdb) b main if 0
 Breakpoint 1 at 0x400594: file foo.c, line 21.
 Sending packet: $Z0,400594,1;X3,220027#68...Packet received: OK
 (gdb) b main
 Breakpoint 15 at 0x400594: file foo.c, line 21.
 Sending packet: $Z0,400594,1#49...Packet received: OK

GDBserver understands this and deletes the breakpoint's previous
conditions.  But, it forgets to delete the previous commands.

gdb/gdbserver/
2014-06-02  Pedro Alves  <palves@redhat.com>

* ax.c (gdb_free_agent_expr): New function.
* ax.h (gdb_free_agent_expr): New declaration.
* mem-break.c (delete_gdb_breakpoint_1): Also clear the commands
list.
(clear_breakpoint_conditions, clear_breakpoint_commands): Make
static.
(clear_breakpoint_conditions_and_commands): New function.
* mem-break.h (clear_breakpoint_conditions): Delete declaration.
(clear_breakpoint_conditions_and_commands): New declaration.

gdb/gdbserver/ChangeLog
gdb/gdbserver/ax.c
gdb/gdbserver/ax.h
gdb/gdbserver/mem-break.c
gdb/gdbserver/mem-break.h
gdb/gdbserver/server.c

index e591108d508e535933e7e4ad1040243266441003..02105363de8c5920063284b25fb5436ac097de76 100644 (file)
@@ -1,3 +1,15 @@
+2014-06-02  Pedro Alves  <palves@redhat.com>
+
+       * ax.c (gdb_free_agent_expr): New function.
+       * ax.h (gdb_free_agent_expr): New declaration.
+       * mem-break.c (delete_gdb_breakpoint_1): Also clear the commands
+       list.
+       (clear_breakpoint_conditions, clear_breakpoint_commands): Make
+       static.
+       (clear_breakpoint_conditions_and_commands): New function.
+       * mem-break.h (clear_breakpoint_conditions): Delete declaration.
+       (clear_breakpoint_conditions_and_commands): New declaration.
+
 2014-05-23  Ramana Radhakrishnan  <ramana.radhakrishnan@arm.com>
 
        * linux-aarch64-low.c (asm/ptrace.h): Include.
index ef659dc79da0bbe862d63ddde1dbdfdb9252b260..8b28c72cf458c451808dbd25907f31e5e6cacb20 100644 (file)
@@ -110,6 +110,16 @@ gdb_parse_agent_expr (char **actparm)
   return aexpr;
 }
 
+void
+gdb_free_agent_expr (struct agent_expr *aexpr)
+{
+  if (aexpr != NULL)
+    {
+      free (aexpr->bytes);
+      free (aexpr);
+    }
+}
+
 /* Convert the bytes of an agent expression back into hex digits, so
    they can be printed or uploaded.  This allocates the buffer,
    callers should free when they are done with it.  */
index ce4ff4fe8b908e014729e3ed78f23d3b0aa41dd6..63180042600f7596205d85163c521c4e4c7fe594 100644 (file)
@@ -58,6 +58,9 @@ struct agent_expr
    of bytes in expression, a comma, and then the bytes.  */
 struct agent_expr *gdb_parse_agent_expr (char **actparm);
 
+/* Release an agent expression.  */
+void gdb_free_agent_expr (struct agent_expr *aexpr);
+
 /* Convert the bytes of an agent expression back into hex digits, so
    they can be printed or uploaded.  This allocates the buffer,
    callers should free when they are done with it.  */
index daeb521ff056f9d917373fbde69be3008693d830..71876f728ea4eab93dcf45f0f149adc7dcba4ae8 100644 (file)
@@ -1045,9 +1045,9 @@ delete_gdb_breakpoint_1 (char z_type, CORE_ADDR addr, int size)
   if (bp == NULL)
     return -1;
 
-  /* Before deleting the breakpoint, make sure to free
-     its condition list.  */
-  clear_breakpoint_conditions (bp);
+  /* Before deleting the breakpoint, make sure to free its condition
+     and command lists.  */
+  clear_breakpoint_conditions_and_commands (bp);
   err = delete_breakpoint (bp);
   if (err != 0)
     return -1;
@@ -1087,7 +1087,7 @@ delete_gdb_breakpoint (char z_type, CORE_ADDR addr, int size)
 
 /* Clear all conditions associated with a breakpoint.  */
 
-void
+static void
 clear_breakpoint_conditions (struct breakpoint *bp)
 {
   struct point_cond_list *cond;
@@ -1102,8 +1102,7 @@ clear_breakpoint_conditions (struct breakpoint *bp)
       struct point_cond_list *cond_next;
 
       cond_next = cond->next;
-      free (cond->cond->bytes);
-      free (cond->cond);
+      gdb_free_agent_expr (cond->cond);
       free (cond);
       cond = cond_next;
     }
@@ -1111,6 +1110,38 @@ clear_breakpoint_conditions (struct breakpoint *bp)
   bp->cond_list = NULL;
 }
 
+/* Clear all commands associated with a breakpoint.  */
+
+static void
+clear_breakpoint_commands (struct breakpoint *bp)
+{
+  struct point_command_list *cmd;
+
+  if (bp->command_list == NULL)
+    return;
+
+  cmd = bp->command_list;
+
+  while (cmd != NULL)
+    {
+      struct point_command_list *cmd_next;
+
+      cmd_next = cmd->next;
+      gdb_free_agent_expr (cmd->cmd);
+      free (cmd);
+      cmd = cmd_next;
+    }
+
+  bp->command_list = NULL;
+}
+
+void
+clear_breakpoint_conditions_and_commands (struct breakpoint *bp)
+{
+  clear_breakpoint_conditions (bp);
+  clear_breakpoint_commands (bp);
+}
+
 /* Add condition CONDITION to GDBserver's breakpoint BP.  */
 
 static void
index 2649462b50c96c2b140192e9c82956af0aef57fd..c84c688e9d848be50c8c4bd4661d38543d361187 100644 (file)
@@ -90,9 +90,10 @@ int breakpoint_here (CORE_ADDR addr);
 
 int breakpoint_inserted_here (CORE_ADDR addr);
 
-/* Clear all breakpoint conditions associated with this address.  */
+/* Clear all breakpoint conditions and commands associated with a
+   breakpoint.  */
 
-void clear_breakpoint_conditions (struct breakpoint *bp);
+void clear_breakpoint_conditions_and_commands (struct breakpoint *bp);
 
 /* Set target-side condition CONDITION to the breakpoint at ADDR.
    Returns false on failure.  On success, advances CONDITION pointer
index ebc773534009e2a1ee70b0d1ca9567c8da4eed47..cea56c14ad926f351e5b309dfd0491370a56bdfd 100644 (file)
@@ -3746,7 +3746,7 @@ process_serial_event (void)
                   here.  If we already have a list of parameters, GDB
                   is telling us to drop that list and use this one
                   instead.  */
-               clear_breakpoint_conditions (bp);
+               clear_breakpoint_conditions_and_commands (bp);
                process_point_options (bp, &dataptr);
              }
          }
This page took 0.038229 seconds and 4 git commands to generate.