From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id iGZCCzcFDGRznwsAWB0awg (envelope-from ) for ; Fri, 10 Mar 2023 23:36:07 -0500 Received: by simark.ca (Postfix, from userid 112) id 2B81F1E223; Fri, 10 Mar 2023 23:36:07 -0500 (EST) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=ndmW7zzE; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DATE_IN_PAST_03_06, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 0C5F61E128 for ; Fri, 10 Mar 2023 23:36:06 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 718E53858D1E for ; Sat, 11 Mar 2023 04:36:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 718E53858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678509364; bh=jYeyslYobV/g8xuezhnZVavT0220B4JbjTks0+qBqn8=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=ndmW7zzEJSPH5SJDTSyPmBLxQjSXMaW72hVo/N61RsjmT/YoXPa+hPjonWFnhEKYW 8ReNnI2XVXKDU36gtI8hTDg9LwMWLebJRUwfdpYM7wm1aTmEjKe+xXeKGSYcoC5O2Q 4AZXAkN9bFo9Xsfe2W8nLMAlCDlVfIw0VB9RemPQ= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 6454C3858D1E for ; Sat, 11 Mar 2023 04:35:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6454C3858D1E Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-20-dL2VpPmVMGylYEvv-xwR7Q-1; Fri, 10 Mar 2023 23:35:39 -0500 X-MC-Unique: dL2VpPmVMGylYEvv-xwR7Q-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7D05F101A521; Sat, 11 Mar 2023 04:35:39 +0000 (UTC) Received: from f38-1.lan (unknown [10.2.16.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id DDBB51121315; Sat, 11 Mar 2023 04:35:38 +0000 (UTC) To: gdb-patches@sourceware.org Cc: pedro@palves.net, simon.marchi@polymtl.ca, Kevin Buettner Subject: [PATCH] PR gdb/30219: Clear sync_quit_force_run in quit_force Date: Fri, 10 Mar 2023 16:18:53 -0700 Message-Id: <20230310231851.141981-1-kevinb@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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: , From: Kevin Buettner via Gdb-patches Reply-To: Kevin Buettner Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" PR 30219 shows an internal error due to a "Bad switch" in print_exception() in gdb/exceptions.c. The switch in question contains cases for RETURN_QUIT and RETURN_ERROR, but is missing a case for the recently added RETURN_FORCED_QUIT. This commit adds that case in addition to introducing annotate_forced_quit() which will print a suitable annotation when annotations are turned on. Making the above change allows the errant test case to pass, but does not fix the underlying problem, which I'll describe shortly. Even though the addition of a case for RETURN_FORCED_QUIT isn't the actual fix, I still think it's important to add this case so that other situations which lead to print_exeption() being called won't generate that "Bad switch" internal error. In order to understand the underlying problem, please examine this portion of the backtrace from the bug report: 0x5576e4ff5780 print_exception /home/smarchi/src/binutils-gdb/gdb/exceptions.c:100 0x5576e4ff5930 exception_print(ui_file*, gdb_exception const&) /home/smarchi/src/binutils-gdb/gdb/exceptions.c:110 0x5576e6a896dd quit_force(int*, int) /home/smarchi/src/binutils-gdb/gdb/top.c:1849 The real problem is in quit_force; here's the try/catch which eventually leads to the internal error: /* Get out of tfind mode, and kill or detach all inferiors. */ try { disconnect_tracing (); for (inferior *inf : all_inferiors ()) kill_or_detach (inf, from_tty); } catch (const gdb_exception &ex) { exception_print (gdb_stderr, ex); } While running the calls in the try-block, a QUIT check is being performed. This check finds that sync_quit_force_run is (still) set, causing a gdb_exception_forced_quit to be thrown. The exception gdb_exception_forced_quit is derived from gdb_exception, causing exception_print to be called. As shown by the backtrace, print_exception is then called, leading to the internal error. The actual fix, also implemented by this commit, is to clear sync_quit_force_run along with the quit flag. This will allow the various cleanup code, called by quit_force, to run without triggering a gdb_exception_forced_quit. (Though, if another SIGTERM is sent to the gdb process, these flags will be set again and a QUIT check in the cleanup code will detect it and throw the exception.) Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30219 --- gdb/annotate.c | 7 +++++++ gdb/annotate.h | 1 + gdb/exceptions.c | 3 +++ gdb/top.c | 8 ++++++++ 4 files changed, 19 insertions(+) diff --git a/gdb/annotate.c b/gdb/annotate.c index 60fe6ccd5c2..36efce1af7c 100644 --- a/gdb/annotate.c +++ b/gdb/annotate.c @@ -282,6 +282,13 @@ annotate_quit (void) printf_unfiltered (("\n\032\032quit\n")); } +void +annotate_forced_quit (void) +{ + if (annotation_level > 1) + printf_unfiltered (("\n\032\032forced-quit\n")); +} + void annotate_error (void) { diff --git a/gdb/annotate.h b/gdb/annotate.h index 48fdb7a61d9..a2686d6bb51 100644 --- a/gdb/annotate.h +++ b/gdb/annotate.h @@ -55,6 +55,7 @@ extern void annotate_field_value (void); extern void annotate_field_end (void); extern void annotate_quit (void); +extern void annotate_forced_quit (void); extern void annotate_error (void); extern void annotate_error_begin (void); diff --git a/gdb/exceptions.c b/gdb/exceptions.c index 4ab8dce58de..e23135f1866 100644 --- a/gdb/exceptions.c +++ b/gdb/exceptions.c @@ -96,6 +96,9 @@ print_exception (struct ui_file *file, const struct gdb_exception &e) /* Assume that these are all errors. */ annotate_error (); break; + case RETURN_FORCED_QUIT: + annotate_forced_quit (); + break; default: internal_error (_("Bad switch.")); } diff --git a/gdb/top.c b/gdb/top.c index aa2a6409d98..81f74f72f61 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -1824,6 +1824,14 @@ quit_force (int *exit_arg, int from_tty) { int exit_code = 0; + /* Clear the quit flag and sync_quit_force_run so that a + gdb_exception_forced_quit isn't inadvertently triggered by a QUIT + check while running the various cleanup/exit code below. Note + that the call to 'check_quit_flag' clears the quit flag as a side + effect. */ + check_quit_flag (); + sync_quit_force_run = false; + /* An optional expression may be used to cause gdb to terminate with the value of that expression. */ if (exit_arg) -- 2.39.2