From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 386E63858D20; Mon, 29 Jan 2024 10:45:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 386E63858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1706525110; bh=A5C4UYN7WchJDfZGujq8d+HXbivoY81NdBkZdgdB2dY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=kPAwMpzk0sI87TJQkoV6txHZ2HGeIo3JU0S2QHU76+6kxXQ7FOYU9QQhVCFGNRfzc BDufblh3u7xd6dcLbMSU0UkY3ejZNExMg20493XpOkSO+dZiFvLjQ72xvX6ivA4FDR WESTSjktNVO3Q99Ctc+d6eIPjgA5U6zr1wQOvC/Y= From: "vries at gcc dot gnu.org" To: gdb-prs@sourceware.org Subject: [Bug python/31172] gdb.post_event SIGSEGV in batch mode Date: Mon, 29 Jan 2024 10:45:09 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: python X-Bugzilla-Version: 13.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vries at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED 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: cc 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=3D31172 Tom de Vries changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |vries at gcc dot gnu.org --- Comment #1 from Tom de Vries --- Tentative fix, similar to what is done for finalize_values: ... diff --git a/gdb/run-on-main-thread.c b/gdb/run-on-main-thread.c index 2d40048de56..e06b751f221 100644 --- a/gdb/run-on-main-thread.c +++ b/gdb/run-on-main-thread.c @@ -33,6 +33,14 @@ static struct serial_event *runnable_event; static std::vector> runnables; +/* See run-on-main-thread.h. */ + +void +finalize_runnables (void) +{ + runnables.clear (); +} + #if CXX_STD_THREAD /* Mutex to hold when handling RUNNABLE_EVENT or RUNNABLES. */ diff --git a/gdb/run-on-main-thread.h b/gdb/run-on-main-thread.h index 4f370dddb9e..27eaff3df72 100644 --- a/gdb/run-on-main-thread.h +++ b/gdb/run-on-main-thread.h @@ -29,4 +29,8 @@ extern void run_on_main_thread (std::function &&= ); extern bool is_main_thread (); +/* Destroy the runnables currently allocated. This is called when GDB is + exiting (e.g., on quit_force). */ +extern void finalize_runnables (); + #endif /* GDB_RUN_ON_MAIN_THREAD_H */ diff --git a/gdb/top.c b/gdb/top.c index fb15c719564..221ef329951 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -74,6 +74,7 @@ #include "cli-out.h" #include "tracepoint.h" #include "inf-loop.h" +#include "run-on-main-thread.h" #if defined(TUI) # include "tui/tui.h" @@ -1813,6 +1814,10 @@ quit_force (int *exit_arg, int from_tty) runtime, which is finalized via a final cleanup. */ finalize_values (); + /* Likewise, destroy any runnables currenctly allocated now. The destru= ctor + of gdbpy_event calls into the Python runtime. */ + finalize_runnables (); + /* Do any final cleanups before exiting. */ try { ... With this patch, we have: ... $ gdb --batch -ex 'pi gdb.post_event(lambda : print("test"))'=20 $=20 ... --=20 You are receiving this mail because: You are on the CC list for the bug.=