From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7906) id 51327382E50D; Wed, 16 Nov 2022 23:27:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 51327382E50D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1668641245; bh=RLAI3dZo01SQtXzGMjK5MLcp5cxKc/bZoLnKfcmlUvE=; h=From:To:Subject:Date:From; b=qK5tY2MgcDNFDNxy/eKcYhqXHWm6aQIO24Vf6Ax8mxtzbLLfTLXrkkKi7hYmzxRep I+c3/YAOG7LZFw23rU5hVOXp26txmqapN283mLRI7VfknXvupPzrua5tmUydKiL312 gc8/nYWvDDMV0TcMFjh0S8nmwZ75h7SzOFF0eWfo= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: =?utf-8?q?K=C3=A9vin_Le_Gouguec?= To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Guard against frame.c destructors running before frame-info.c's X-Act-Checkin: binutils-gdb X-Git-Author: =?utf-8?q?K=C3=A9vin_Le_Gouguec?= X-Git-Refname: refs/heads/master X-Git-Oldrev: ab11c8905fecb3f2321f0a0ea2e719648560f2ad X-Git-Newrev: 995a34b1772f1c04d6a98641c6d29d68628b9063 Message-Id: <20221116232725.51327382E50D@sourceware.org> Date: Wed, 16 Nov 2022 23:27:25 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D995a34b1772f= 1c04d6a98641c6d29d68628b9063 commit 995a34b1772f1c04d6a98641c6d29d68628b9063 Author: K=C3=A9vin Le Gouguec Date: Tue Nov 15 16:08:04 2022 +0100 Guard against frame.c destructors running before frame-info.c's =20 On x86_64-windows, since 04e2ac7b2a7, we observe this internal error: =20 [...]/gdbsupport/intrusive_list.h:458: internal-error: erase_element: Assertion `elem_node->prev !=3D INTRUSIVE_LIST_UNLINKED_VALUE' failed. =20 Breaking in the destructors for intrusive_list and frame_info_ptr shows= that in this configuration, the destructors for frame.c's statically-stored objects are run before frame-info.c's: =20 Thread 1 hit Breakpoint 7, intrusive_list >::~intrusive_list (this=3D0x7ff6= 9c418c90 , __in_chrg=3D) [...]/../gdbsupport/intrusive_list.h:250 250 clear (); (gdb) bt #0 intrusive_list > ::~intrusive_list (this=3D0x7ff69c418c90 , __in_chrg=3D) [...]/../gdbsupport/intrusive_list.h= :250 #1 0x00007ff69b78edba in __tcf_1 () [...]/frame-info.c:27 #2 0x00007ff9c457aa9f in msvcrt!_initterm_e () from C:\Windows\System32\msvcrt.dll #3 0x00007ff69b8246a6 in captured_main_1 (context=3D0x5ffe00) [...]/main.c:1111 #4 0x00007ff69b825149 in captured_main (data=3D0x5ffe00) [...]/main.= c:1320 #5 0x00007ff69b8251b1 in gdb_main (args=3D0x5ffe00) [...]/main.c:1345 #6 0x00007ff69b5d1730 in main (argc=3D2, argv=3D0x751730) [...]/gdb.= c:32 (gdb) c Continuing. =20 Thread 1 hit Breakpoint 8, frame_info_ptr::~frame_info_ptr (this=3D0x7ff69c418e20 , __in_chrg=3D) [...]/frame-info.h:74 74 if (is_linked ()) (gdb) bt #0 frame_info_ptr::~frame_info_ptr (this=3D0x7ff69c418e20 , __in_chrg=3D) [...]/frame-info.h:74 #1 0x00007ff69b79a643 in __tcf_1 () [...]/frame.c:1675 #2 0x00007ff9c457aa9f in msvcrt!_initterm_e () from C:\Windows\System32\msvcrt.dll #3 0x00007ff69b8246a6 in captured_main_1 (context=3D0x5ffe00) [...]/main.c:1111 #4 0x00007ff69b825149 in captured_main (data=3D0x5ffe00) [...]/main.= c:1320 #5 0x00007ff69b8251b1 in gdb_main (args=3D0x5ffe00) [...]/main.c:1345 #6 0x00007ff69b5d1730 in main (argc=3D2, argv=3D0x751730) [...]/gdb.= c:32 =20 Approved-By: Simon Marchi Diff: --- gdb/frame-info.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gdb/frame-info.h b/gdb/frame-info.h index 3369b114326..893b6632363 100644 --- a/gdb/frame-info.h +++ b/gdb/frame-info.h @@ -76,7 +76,11 @@ public: =20 ~frame_info_ptr () { - frame_list.erase (frame_list.iterator_to (*this)); + /* If this node has static storage, it may be deleted after + frame_list. Attempting to erase ourselves would then trigger + internal errors, so make sure we are still linked first. */ + if (is_linked ()) + frame_list.erase (frame_list.iterator_to (*this)); } =20 frame_info_ptr &operator=3D (const frame_info_ptr &other)