* [PATCH] [gdb/tui] Fix assert in ~gdbpy_tui_window_maker
@ 2023-07-17 16:31 Tom de Vries
0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2023-07-17 16:31 UTC (permalink / raw)
To: gdb-patches; +Cc: Andrew Burgess
In gdb/tui/tui-layout.c, we have:
...
static window_types_map known_window_types;
...
and in gdb/python/py-tui.c:
...
/* A global list of all gdbpy_tui_window_maker objects. */
static intrusive_list<gdbpy_tui_window_maker> m_window_maker_list;
};
/* See comment in class declaration above. */
intrusive_list<gdbpy_tui_window_maker>
gdbpy_tui_window_maker::m_window_maker_list;
...
With a gdb build with -O0 or -O2, the static destructor calling order seems to be:
- first gdb/tui/tui-layout.c,
- then gdb/python/py-tui.c.
So when running test-case gdb.python/tui-window-factory.exp, we see the
following order of events:
- the destructor for known_window_types is called, which triggers calling the
destructor for the only element E of m_window_maker_list. The destructor
destroys E, and also removes E from m_window_maker_list, leaving it empty.
- the destructor for m_window_maker_list is called. It's empty, so it's a nop.
However, when building gdb with -O2 -flto=auto, the static destructor calling
order seems to be reversed.
Instead, we have these events:
- the destructor for m_window_maker_list is called. This doesn't destroy it's
only element E, but it does make m_window_maker_list empty.
- the destructor for known_window_types is called, which triggers calling the
destructor for E. An attempt is done to remove E from m_window_maker_list,
but we run into an assertion failure, because the list is empty.
Fix this by checking is_linked () before attempting to remove from
m_window_maker_list, similar to how things were addressed in commit 995a34b1772
("Guard against frame.c destructors running before frame-info.c's").
Tested on x86_64-linux.
PR tui/30646
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30646
---
gdb/python/py-tui.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/gdb/python/py-tui.c b/gdb/python/py-tui.c
index f47f2278dda..64f22dbb462 100644
--- a/gdb/python/py-tui.c
+++ b/gdb/python/py-tui.c
@@ -339,7 +339,8 @@ intrusive_list<gdbpy_tui_window_maker>
gdbpy_tui_window_maker::~gdbpy_tui_window_maker ()
{
/* Remove this gdbpy_tui_window_maker from the global list. */
- m_window_maker_list.erase (m_window_maker_list.iterator_to (*this));
+ if (is_linked ())
+ m_window_maker_list.erase (m_window_maker_list.iterator_to (*this));
if (m_constr != nullptr)
{
base-commit: 8193fa9cbe1a6cdb2cb41cedb835de33a1c755e3
--
2.35.3
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-07-17 16:31 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-17 16:31 [PATCH] [gdb/tui] Fix assert in ~gdbpy_tui_window_maker 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).