From patchwork Mon Jun 2 22:32:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 1248 Received: (qmail 10736 invoked by alias); 2 Jun 2014 22:32:49 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 10698 invoked by uid 89); 2 Jun 2014 22:32:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 02 Jun 2014 22:32:45 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s52MWhWY019033 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 2 Jun 2014 18:32:43 -0400 Received: from brno.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s52MWfvb027840 for ; Mon, 2 Jun 2014 18:32:43 -0400 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [pushed 1/3] gdbserver: on GDB breakpoint reinsertion, also delete the breakpoint's commands. Date: Mon, 2 Jun 2014 23:32:39 +0100 Message-Id: <1401748361-27085-2-git-send-email-palves@redhat.com> In-Reply-To: <1401748361-27085-1-git-send-email-palves@redhat.com> References: <1401748361-27085-1-git-send-email-palves@redhat.com> 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 * 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 | 12 ++++++++++++ gdb/gdbserver/ax.c | 10 ++++++++++ gdb/gdbserver/ax.h | 3 +++ gdb/gdbserver/mem-break.c | 43 +++++++++++++++++++++++++++++++++++++------ gdb/gdbserver/mem-break.h | 5 +++-- gdb/gdbserver/server.c | 2 +- 6 files changed, 66 insertions(+), 9 deletions(-) diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index e591108..0210536 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,3 +1,15 @@ +2014-06-02 Pedro Alves + + * 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 * linux-aarch64-low.c (asm/ptrace.h): Include. diff --git a/gdb/gdbserver/ax.c b/gdb/gdbserver/ax.c index ef659dc..8b28c72 100644 --- a/gdb/gdbserver/ax.c +++ b/gdb/gdbserver/ax.c @@ -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. */ diff --git a/gdb/gdbserver/ax.h b/gdb/gdbserver/ax.h index ce4ff4f..6318004 100644 --- a/gdb/gdbserver/ax.h +++ b/gdb/gdbserver/ax.h @@ -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. */ diff --git a/gdb/gdbserver/mem-break.c b/gdb/gdbserver/mem-break.c index daeb521..71876f7 100644 --- a/gdb/gdbserver/mem-break.c +++ b/gdb/gdbserver/mem-break.c @@ -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 diff --git a/gdb/gdbserver/mem-break.h b/gdb/gdbserver/mem-break.h index 2649462..c84c688 100644 --- a/gdb/gdbserver/mem-break.h +++ b/gdb/gdbserver/mem-break.h @@ -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 diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c index ebc7735..cea56c1 100644 --- a/gdb/gdbserver/server.c +++ b/gdb/gdbserver/server.c @@ -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); } }