From patchwork Thu Jan 12 01:56:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Buettner X-Patchwork-Id: 62993 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AF7D238432E5 for ; Thu, 12 Jan 2023 01:58:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AF7D238432E5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673488706; bh=S+yykIqeAiFmwrAs08Wid6+ckJIj0R7tVUW9nCwuadI=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=narM0MFoT8pa9BkADb/QJAquzS6qzcxY/U5Av5AdZtylWGswkbZHmQ7tMCuGKgfDL nKTG8jRftbMkiZsy2Bkh0icd/a/ZbEQJAXX+CA+9Dlvs33213n2T4HOEBmfkDSlMwG DM8CSbHw4dq+G5VrVo8CWdo33CXluy+QGLar94Is= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 71468385B52B for ; Thu, 12 Jan 2023 01:57:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 71468385B52B Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-27-7lwStyd7Nc6b9vO-lIiUBA-1; Wed, 11 Jan 2023 20:57:08 -0500 X-MC-Unique: 7lwStyd7Nc6b9vO-lIiUBA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A03722999B2E; Thu, 12 Jan 2023 01:57:07 +0000 (UTC) Received: from f34-1.lan (unknown [10.2.17.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id EEB6A492C14; Thu, 12 Jan 2023 01:57:06 +0000 (UTC) To: gdb-patches@sourceware.org Cc: pedro@palves.net, simark@simark.ca, tdevries@suse.de, Kevin Buettner Subject: [PATCH v4 3/8] Catch gdb_exception_error instead of gdb_exception (in many places) Date: Wed, 11 Jan 2023 18:56:25 -0700 Message-Id: <20230112015630.32999-4-kevinb@redhat.com> In-Reply-To: <20230112015630.32999-1-kevinb@redhat.com> References: <20230112015630.32999-1-kevinb@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Kevin Buettner via Gdb-patches From: Kevin Buettner Reply-To: Kevin Buettner Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" As described in the previous commit for this series, I became concerned that there might be instances in which a QUIT (due to either a SIGINT or SIGTERM) might not cause execution to return to the top level. In some (though very few) instances, it is okay to not propagate the exception for a Ctrl-C / SIGINT, but I don't think that it is ever okay to swallow the exception caused by a SIGTERM. Allowing that to happen would definitely be a deviation from the current behavior in which GDB exits upon receipt of a SIGTERM. I looked at all cases where an exception handler catches a gdb_exception. Handlers which did NOT need modification were those which satisifed one or more of the following conditions: 1) There is no call path to maybe_quit() in the try block. I used a static analysis tool to help make this determination. In instances where the tool didn't provide an answer of "yes, this call path can result in maybe_quit() being called", I reviewed it by hand. 2) The catch block contains a throw for conditions that it doesn't want to handle; these "not handled" conditions must include the quit exception and the new "forced quit" exception. 3) There was (also) a catch for gdb_exception_quit. Any try/catch blocks not meeting the above conditions could potentially swallow a QUIT exception. My first thought was to add catch blocks for gdb_exception_quit and then rethrow the exception. But Pedro pointed out that this can be handled without adding additional code by simply catching gdb_exception_error instead. That's what this patch series does. There are some oddball cases which needed to be handled differently, plus the extension languages, but those are handled in later patches. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26761 --- gdb/ada-lang.c | 2 +- gdb/breakpoint.c | 8 ++++---- gdb/i386-linux-tdep.c | 2 +- gdb/inf-loop.c | 2 +- gdb/infcmd.c | 2 +- gdb/infrun.c | 2 +- gdb/jit.c | 2 +- gdb/mi/mi-cmd-break.c | 2 +- gdb/mi/mi-interp.c | 2 +- gdb/objc-lang.c | 2 +- gdb/parse.c | 2 +- gdb/printcmd.c | 2 +- gdb/record-btrace.c | 2 +- gdb/record-full.c | 2 +- gdb/solib.c | 2 +- gdb/sparc64-linux-tdep.c | 2 +- gdb/symfile-mem.c | 2 +- 17 files changed, 20 insertions(+), 20 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 40f85914a56..241dd1b9f24 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -12320,7 +12320,7 @@ should_stop_exception (const struct bp_location *bl) scoped_value_mark mark; stop = value_true (evaluate_expression (ada_loc->excep_cond_expr.get ())); } - catch (const gdb_exception &ex) + catch (const gdb_exception_error &ex) { exception_fprintf (gdb_stderr, ex, _("Error in testing exception condition:\n")); diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 8cfc46e0bed..af8b62e4880 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -2833,7 +2833,7 @@ insert_bp_location (struct bp_location *bl, if (val) bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; } - catch (gdb_exception &e) + catch (gdb_exception_error &e) { rethrow_on_target_close_error (e); bp_excpt = std::move (e); @@ -5295,7 +5295,7 @@ bpstat_check_watchpoint (bpstat *bs) { e = watchpoint_check (bs); } - catch (const gdb_exception &ex) + catch (const gdb_exception_error &ex) { exception_fprintf (gdb_stderr, ex, "Error evaluating expression " @@ -5539,7 +5539,7 @@ bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread) { condition_result = breakpoint_cond_eval (cond); } - catch (const gdb_exception &ex) + catch (const gdb_exception_error &ex) { exception_fprintf (gdb_stderr, ex, "Error in testing breakpoint condition:\n"); @@ -13476,7 +13476,7 @@ enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, bpt->enable_state = bp_enabled; update_watchpoint (w, true /* reparse */); } - catch (const gdb_exception &e) + catch (const gdb_exception_error &e) { bpt->enable_state = orig_enable_state; exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c index ad0377de5a6..a6adeca1b97 100644 --- a/gdb/i386-linux-tdep.c +++ b/gdb/i386-linux-tdep.c @@ -415,7 +415,7 @@ i386_linux_report_signal_info (struct gdbarch *gdbarch, struct ui_out *uiout, access = parse_and_eval_long ("$_siginfo._sifields._sigfault.si_addr"); } - catch (const gdb_exception &exception) + catch (const gdb_exception_error &exception) { return; } diff --git a/gdb/inf-loop.c b/gdb/inf-loop.c index f49d1c3c872..b9f25008247 100644 --- a/gdb/inf-loop.c +++ b/gdb/inf-loop.c @@ -69,7 +69,7 @@ inferior_event_handler (enum inferior_event_type event_type) { bpstat_do_actions (); } - catch (const gdb_exception &e) + catch (const gdb_exception_error &e) { /* If the user was running a foreground execution command, then propagate the error so that the prompt diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 0497ad05091..895d84025cf 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -1588,7 +1588,7 @@ print_return_value (struct ui_out *uiout, struct return_value_info *rv) delete the breakpoint. */ print_return_value_1 (uiout, rv); } - catch (const gdb_exception &ex) + catch (const gdb_exception_error &ex) { exception_print (gdb_stdout, ex); } diff --git a/gdb/infrun.c b/gdb/infrun.c index 181d961d80d..9cfafda5ace 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -8730,7 +8730,7 @@ normal_stop (void) { execute_cmd_pre_hook (stop_command); } - catch (const gdb_exception &ex) + catch (const gdb_exception_error &ex) { exception_fprintf (gdb_stderr, ex, "Error while running hook_stop:\n"); diff --git a/gdb/jit.c b/gdb/jit.c index 48bfef0a026..7f6b289cdd3 100644 --- a/gdb/jit.c +++ b/gdb/jit.c @@ -715,7 +715,7 @@ jit_reader_try_read_symtab (gdbarch *gdbarch, jit_code_entry *code_entry, code_entry->symfile_size)) status = 0; } - catch (const gdb_exception &e) + catch (const gdb_exception_error &e) { status = 0; } diff --git a/gdb/mi/mi-cmd-break.c b/gdb/mi/mi-cmd-break.c index 8b0483803b6..75957b75bad 100644 --- a/gdb/mi/mi-cmd-break.c +++ b/gdb/mi/mi-cmd-break.c @@ -58,7 +58,7 @@ breakpoint_notify (struct breakpoint *b) { print_breakpoint (b); } - catch (const gdb_exception &ex) + catch (const gdb_exception_error &ex) { exception_print (gdb_stderr, ex); } diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c index cf3d738edce..ba58044f868 100644 --- a/gdb/mi/mi-interp.c +++ b/gdb/mi/mi-interp.c @@ -847,7 +847,7 @@ mi_print_breakpoint_for_event (struct mi_interp *mi, breakpoint *bp) print_breakpoint (bp); } - catch (const gdb_exception &ex) + catch (const gdb_exception_error &ex) { exception_print (gdb_stderr, ex); } diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c index e17a4c406c0..054895c02e3 100644 --- a/gdb/objc-lang.c +++ b/gdb/objc-lang.c @@ -1286,7 +1286,7 @@ find_objc_msgcall_submethod (int (*f) (CORE_ADDR, CORE_ADDR *), if (f (pc, new_pc) == 0) return 1; } - catch (const gdb_exception &ex) + catch (const gdb_exception_error &ex) { exception_fprintf (gdb_stderr, ex, "Unable to determine target of " diff --git a/gdb/parse.c b/gdb/parse.c index 2f7d58061ab..9aa080ff974 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -514,7 +514,7 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc, { lang->parser (&ps); } - catch (const gdb_exception &except) + catch (const gdb_exception_error &except) { /* If parsing for completion, allow this to succeed; but if no expression elements have been written, then there's nothing diff --git a/gdb/printcmd.c b/gdb/printcmd.c index c3c2e5ad612..fe26771abe4 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -2109,7 +2109,7 @@ do_one_display (struct display *d) d->exp = parse_expression (d->exp_string.c_str (), &tracker); d->block = tracker.block (); } - catch (const gdb_exception &ex) + catch (const gdb_exception_error &ex) { /* Can't re-parse the expression. Disable this display item. */ d->enabled_p = false; diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c index 0daba893813..61de8491bb9 100644 --- a/gdb/record-btrace.c +++ b/gdb/record-btrace.c @@ -2932,7 +2932,7 @@ cmd_record_btrace_start (const char *args, int from_tty) { execute_command ("target record-btrace", from_tty); } - catch (const gdb_exception &exception) + catch (const gdb_exception_error &exception) { record_btrace_conf.format = BTRACE_FORMAT_BTS; diff --git a/gdb/record-full.c b/gdb/record-full.c index e3cfa3f45d5..15c5b7d682e 100644 --- a/gdb/record-full.c +++ b/gdb/record-full.c @@ -785,7 +785,7 @@ record_full_message_wrapper_safe (struct regcache *regcache, { record_full_message (regcache, signal); } - catch (const gdb_exception &ex) + catch (const gdb_exception_error &ex) { exception_print (gdb_stderr, ex); return false; diff --git a/gdb/solib.c b/gdb/solib.c index 60bdf46cb91..ec0fcfb5beb 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -785,7 +785,7 @@ update_solib_list (int from_tty) { ops->open_symbol_file_object (from_tty); } - catch (const gdb_exception &ex) + catch (const gdb_exception_error &ex) { exception_fprintf (gdb_stderr, ex, "Error reading attached " diff --git a/gdb/sparc64-linux-tdep.c b/gdb/sparc64-linux-tdep.c index beff812eeef..685df066f3a 100644 --- a/gdb/sparc64-linux-tdep.c +++ b/gdb/sparc64-linux-tdep.c @@ -139,7 +139,7 @@ sparc64_linux_report_signal_info (struct gdbarch *gdbarch, struct ui_out *uiout, if (si_code >= SEGV_ACCADI && si_code <= SEGV_ADIPERR) addr = parse_and_eval_long ("$_siginfo._sifields._sigfault.si_addr"); } - catch (const gdb_exception &exception) + catch (const gdb_exception_error &exception) { return; } diff --git a/gdb/symfile-mem.c b/gdb/symfile-mem.c index d36b9090e7e..7ac3ac709ec 100644 --- a/gdb/symfile-mem.c +++ b/gdb/symfile-mem.c @@ -197,7 +197,7 @@ add_vsyscall_page (inferior *inf) name.c_str (), 0 /* from_tty */); } - catch (const gdb_exception &ex) + catch (const gdb_exception_error &ex) { exception_print (gdb_stderr, ex); }