]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit - gdb/frame.c
[gdb/build] Fix frame_list position in frame.c
authorTom de Vries <tdevries@suse.de>
Wed, 3 May 2023 19:43:03 +0000 (21:43 +0200)
committerTom de Vries <tdevries@suse.de>
Wed, 3 May 2023 19:43:03 +0000 (21:43 +0200)
commit751c7c72c0105c7d55e58bba3c069c36a74c8937
treecb5fd15e8e17b40cb9aad6040018431499aca02b
parent2ad00a4b42f89b61fdab24940b67713daf81c988
[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
gdb/frame.c
gdb/frame.h