From patchwork Mon Nov 6 23:27:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 24128 Received: (qmail 122095 invoked by alias); 6 Nov 2017 23:27:22 -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 122025 invoked by uid 89); 6 Nov 2017 23:27:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= 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, 06 Nov 2017 23:27:20 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DE2355AFC4 for ; Mon, 6 Nov 2017 23:27:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DE2355AFC4 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=palves@redhat.com Received: from cascais.lan (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5397B60C8D for ; Mon, 6 Nov 2017 23:27:18 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 1/5] Fix swallowed "Quit" when inserting breakpoints Date: Mon, 6 Nov 2017 23:27:12 +0000 Message-Id: <1510010836-15287-2-git-send-email-palves@redhat.com> In-Reply-To: <1510010836-15287-1-git-send-email-palves@redhat.com> References: <1510010836-15287-1-git-send-email-palves@redhat.com> If GDB is inserting a breakpoint and you type Ctrl-C at the exact "right" time, you'll hit a QUIT call in target_read, and the breakpoint insertion is cancelled. However, the related TRY/CATCH code in insert_bp_location does: CATCH (e, RETURN_MASK_ALL) { bp_err = e.error; bp_err_message = e.message; } The problem with that is that a RETURN_QUIT exception has e.error == 0, which means that further below, in the places that check for error with: if (bp_err != GDB_NO_ERROR) because GDB_NO_ERROR == 0, GDB continues as if the breakpoint was inserted succesfully, and resumes the inferior. Since the breakpoint wasn't inserted the inferior runs free, out of our control... Fix this by having insert_bp_location store a copy of the whole exception instead of just a error/message parts, and then checking "gdb_exception::reason" instead. This was exposed by the new gdb.base/bp-cmds-continue-ctrl-c.exp testcase added later in the series. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * breakpoint.c (insert_bp_location): Replace bp_err and bp_err_message locals by a gdb_exception local. --- gdb/breakpoint.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index adc8950..9723227 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -2482,8 +2482,7 @@ insert_bp_location (struct bp_location *bl, int *hw_breakpoint_error, int *hw_bp_error_explained_already) { - enum errors bp_err = GDB_NO_ERROR; - const char *bp_err_message = NULL; + gdb_exception bp_excpt = exception_none; if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) return 0; @@ -2592,12 +2591,11 @@ insert_bp_location (struct bp_location *bl, val = bl->owner->ops->insert_location (bl); if (val) - bp_err = GENERIC_ERROR; + bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; } CATCH (e, RETURN_MASK_ALL) { - bp_err = e.error; - bp_err_message = e.message; + bp_excpt = e; } END_CATCH } @@ -2632,16 +2630,16 @@ insert_bp_location (struct bp_location *bl, val = target_insert_breakpoint (bl->gdbarch, &bl->overlay_target_info); if (val) - bp_err = GENERIC_ERROR; + bp_excpt + = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; } CATCH (e, RETURN_MASK_ALL) { - bp_err = e.error; - bp_err_message = e.message; + bp_excpt = e; } END_CATCH - if (bp_err != GDB_NO_ERROR) + if (bp_excpt.reason != 0) fprintf_unfiltered (tmp_error_stream, "Overlay breakpoint %d " "failed: in ROM?\n", @@ -2658,12 +2656,11 @@ insert_bp_location (struct bp_location *bl, val = bl->owner->ops->insert_location (bl); if (val) - bp_err = GENERIC_ERROR; + bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; } CATCH (e, RETURN_MASK_ALL) { - bp_err = e.error; - bp_err_message = e.message; + bp_excpt = e; } END_CATCH } @@ -2675,7 +2672,7 @@ insert_bp_location (struct bp_location *bl, } } - if (bp_err != GDB_NO_ERROR) + if (bp_excpt.reason != 0) { /* Can't set the breakpoint. */ @@ -2687,7 +2684,9 @@ insert_bp_location (struct bp_location *bl, breakpoint insertion failed (e.g., the remote target doesn't define error codes), so we must treat generic errors as memory errors. */ - if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR) + if (bp_excpt.reason == RETURN_ERROR + && (bp_excpt.error == GENERIC_ERROR + || bp_excpt.error == MEMORY_ERROR) && bl->loc_type == bp_loc_software_breakpoint && (solib_name_from_address (bl->pspace, bl->address) || shared_objfile_contains_address_p (bl->pspace, @@ -2715,16 +2714,18 @@ insert_bp_location (struct bp_location *bl, if (bl->loc_type == bp_loc_hardware_breakpoint) { *hw_breakpoint_error = 1; - *hw_bp_error_explained_already = bp_err_message != NULL; + *hw_bp_error_explained_already = bp_excpt.message != NULL; fprintf_unfiltered (tmp_error_stream, "Cannot insert hardware breakpoint %d%s", - bl->owner->number, bp_err_message ? ":" : ".\n"); - if (bp_err_message != NULL) - fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message); + bl->owner->number, + bp_excpt.message ? ":" : ".\n"); + if (bp_excpt.message != NULL) + fprintf_unfiltered (tmp_error_stream, "%s.\n", + bp_excpt.message); } else { - if (bp_err_message == NULL) + if (bp_excpt.message == NULL) { std::string message = memory_error_message (TARGET_XFER_E_IO, @@ -2740,7 +2741,7 @@ insert_bp_location (struct bp_location *bl, fprintf_unfiltered (tmp_error_stream, "Cannot insert breakpoint %d: %s\n", bl->owner->number, - bp_err_message); + bp_excpt.message); } } return 1;