From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id F059E3858C27; Mon, 27 Feb 2023 23:21:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F059E3858C27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677540088; bh=EvMl5kvSMh1j9jewAybmoNIgYfhSFR30Gf8AAAMvNuo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=RzFIZao7LJERlAZWP65w3iE5imuxQw+394VjW44Mj36u0DJqXK6n+YEqSjtE42/9S NiMqJjbLj2PabibYpKJcWskAKNbLcq3sSOT8WLpTC4+1OOzDzs3ZLBpuvZHtaUEQ+Y E2bX9Hg4qGe2QsTgO2hJN2CNW0M7EqxqG0Ltjydc= From: "cvs-commit at gcc dot gnu.org" To: gdb-prs@sourceware.org Subject: [Bug gdb/26761] thread.c:95: internal-error: thread_info* inferior_thread(): Assertion `current_thread_ != nullptr' failed Date: Mon, 27 Feb 2023 23:21:28 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: gdb X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D26761 --- Comment #16 from cvs-commit at gcc dot gnu.org --- The master branch has been updated by Kevin Buettner : https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D63509715af86= 7d635ad0e8cfe5a662bfc67b4ddf commit 63509715af867d635ad0e8cfe5a662bfc67b4ddf Author: Kevin Buettner Date: Mon Feb 27 16:11:37 2023 -0700 Handle gdb SIGTERM by throwing / catching gdb_exception_force_quit When a GDB process receives the SIGTERM signal, handle_sigterm() in event-top.c is called. The global variable 'sync_quit_force_run' is set by this signal handler. It does some other things too, but the setting of this global is the important bit for the SIGTERM part of this discussion. GDB will periodically check to see whether a Ctrl-C or SIGTERM has been received. This is performed via use of the QUIT macro in GDB's code. QUIT is defined to invoke maybe_quit(), which will be periodically called during any lengthy operation. This is supposed to ensure that the user won't have to wait too long for a Ctrl-C or SIGTERM to be acted upon. When a Ctrl-C / SIGINT is received, quit_handler() will decide whether to pass the SIGINT onto the inferior or to call quit() which causes gdb_exception_quit to be thrown. This exception (usually) propagates to the top level. Control is then returned to the top level event loop. At the moment, SIGTERM is handled very differently. Instead of throwing an exception, quit_force() is called. This does eventually cause GDB to exit(), but prior to that happening, the inferiors are killed or detached and other target related cleanup occurs. As shown in this discussion between Pedro Alves and myself... https://sourceware.org/pipermail/gdb-patches/2021-July/180802.html https://sourceware.org/pipermail/gdb-patches/2021-July/180902.html https://sourceware.org/pipermail/gdb-patches/2021-July/180903.html ...we found that it is possible for inferior_ptid and current_thread_ to get out of sync. When that happens, the "current_thread_ !=3D nullp= tr" assertion in inferior_thread() can fail resulting in a GDB internal error. Pedro recommended that we "let the normal quit exception propagate all the way to the top level, and then have the top level call quit_force if sync_quit_force_run is set." However, after the v2 series for this patch set, we tweaked that idea by introducing a new exception for handling SIGTERM. This commit implements the obvious part of Pedro's suggestion: Instead of calling quit_force from quit(), throw_forced_quit() is now called instead. This causes the new exception 'gdb_exception_forced_qu= it' to be thrown. At the top level, I changed catch_command_errors() and captured_main() to catch gdb_exception_forced_quit and then call quit_force() from the catch block. I also changed start_event_loop() to also catch gdb_exception_forced_quit; while we could also call quit_force() from that catch block, it's sufficient to simply rethrow the exception since it'll be caught by the newly added code in captured_main(). Making these changes fixed the failure / regression that I was seeing for gdb.base/gdb-sigterm.exp when run on a machine with glibc-2.34. However, there are many other paths back to the top level which this test case does not test. I did an audit of all of the try / catch code in GDB in which calls in the try-block might (eventually) call QUIT. I found many cases where gdb_exception_quit and the new gdb_exception_forced_quit will be swallowed. (When using GDB, have you ever hit Ctrl-C and not have it do anything; if so, it could be due to a swallowed gdb_exception_quit in one of the cases I've identified.) The rest of the patches in this series deal with this concern. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D26761 Tested-by: Tom de Vries Approved-by: Pedro Alves --=20 You are receiving this mail because: You are on the CC list for the bug.=