public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] [gdb/build] Fix frame_list position in frame.c
@ 2023-05-03 19:43 Tom de Vries
0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2023-05-03 19:43 UTC (permalink / raw)
To: gdb-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=751c7c72c0105c7d55e58bba3c069c36a74c8937
commit 751c7c72c0105c7d55e58bba3c069c36a74c8937
Author: Tom de Vries <tdevries@suse.de>
Date: Wed May 3 21:43:03 2023 +0200
[gdb/build] Fix frame_list position in frame.c
In commit 995a34b1772 ("Guard against frame.c destructors running before
frame-info.c's") the following problem was addressed.
The frame_info_ptr destructor:
...
~frame_info_ptr ()
{
frame_list.erase (frame_list.iterator_to (*this));
}
...
uses frame_list, which is a static member of class frame_info_ptr,
instantiated in frame-info.c:
...
intrusive_list<frame_info_ptr> frame_info_ptr::frame_list;
...
Then there's a static frame_info_pointer variable named selected_frame in
frame.c:
...
static frame_info_ptr selected_frame;
...
Because the destructor of selected_frame uses frame_list, its destructor needs
to be called before the destructor of frame_list.
But because they're in different compilation units, the initialization order and
consequently destruction order is not guarantueed.
The commit fixed this by handling the case that the destructor of frame_list
is called first, adding a check on is_linked ():
...
~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));
}
...
However, since then frame_list has been moved into frame.c, and
initialization/destruction order is guarantueed inside a compilation unit.
Revert aforementioned commit, and fix the destruction order problem by moving
frame_list before selected_frame.
Reverting the commit is another way of fixing the already fixed
Wdangling-pointer warning reported in PR build/30413, in a different way than
commit 9b0ccb1ebae ("Pass const frame_info_ptr reference for
skip_[language_]trampoline").
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Tested on x86_64-linux.
PR build/30413
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30413
Diff:
---
gdb/frame.c | 11 +++++++----
gdb/frame.h | 8 +++-----
2 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/gdb/frame.c b/gdb/frame.c
index 36fb02f3c8e..c8b8d2e257e 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -1733,6 +1733,13 @@ get_current_frame (void)
static frame_id selected_frame_id = null_frame_id;
static int selected_frame_level = -1;
+/* See frame.h. This definition should come before any definition of a static
+ frame_info_ptr, to ensure that frame_list is destroyed after any static
+ frame_info_ptr. This is necessary because the destructor of frame_info_ptr
+ uses frame_list. */
+
+intrusive_list<frame_info_ptr> frame_info_ptr::frame_list;
+
/* The cached frame_info object pointing to the selected frame.
Looked up on demand by get_selected_frame. */
static frame_info_ptr selected_frame;
@@ -3275,10 +3282,6 @@ maintenance_print_frame_id (const char *args, int from_tty)
/* See frame-info-ptr.h. */
-intrusive_list<frame_info_ptr> frame_info_ptr::frame_list;
-
-/* See frame-info-ptr.h. */
-
frame_info_ptr::frame_info_ptr (struct frame_info *ptr)
: m_ptr (ptr)
{
diff --git a/gdb/frame.h b/gdb/frame.h
index 6ed8db0af56..355150ab585 100644
--- a/gdb/frame.h
+++ b/gdb/frame.h
@@ -254,11 +254,9 @@ public:
~frame_info_ptr ()
{
- /* 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));
+ /* If this node has static storage, it should be be deleted before
+ frame_list. */
+ frame_list.erase (frame_list.iterator_to (*this));
}
frame_info_ptr &operator= (const frame_info_ptr &other)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-05-03 19:43 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-03 19:43 [binutils-gdb] [gdb/build] Fix frame_list position in frame.c Tom de Vries
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).