public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix crash when calling Frame.static_link
       [not found] <20240211122507.1069-1-ssbssa.ref@yahoo.de>
@ 2024-02-11 12:25 ` Hannes Domani
  2024-02-11 16:25   ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: Hannes Domani @ 2024-02-11 12:25 UTC (permalink / raw)
  To: gdb-patches

If you try to call Frame.static_link for a frame without debug info,
gdb crashes:
```
Temporary breakpoint 1, 0x000000013f821650 in main ()
(gdb) py print(gdb.selected_frame().static_link())

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
```

The problem was a missing check if get_frame_block returns nullptr
inside frame_follow_static_link.

With this, it works:
```
Temporary breakpoint 1, 0x000000013f941650 in main ()
(gdb) py print(gdb.selected_frame().static_link())
None
```

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31366
---
 gdb/frame.c                           |  3 +++
 gdb/testsuite/gdb.python/py-frame.exp | 14 ++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/gdb/frame.c b/gdb/frame.c
index fae89cbbc0a..72a34fcfedc 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -3121,6 +3121,9 @@ frame_info_ptr
 frame_follow_static_link (frame_info_ptr frame)
 {
   const block *frame_block = get_frame_block (frame, nullptr);
+  if (frame_block == nullptr)
+    return {};
+
   frame_block = frame_block->function_block ();
 
   const struct dynamic_prop *static_link = frame_block->static_link ();
diff --git a/gdb/testsuite/gdb.python/py-frame.exp b/gdb/testsuite/gdb.python/py-frame.exp
index 016fbacdb49..110ddf24480 100644
--- a/gdb/testsuite/gdb.python/py-frame.exp
+++ b/gdb/testsuite/gdb.python/py-frame.exp
@@ -187,3 +187,17 @@ gdb_test "python print(gdb.selected_frame().language())" "c" \
 gdb_test "python print(gdb.selected_frame().read_register(list()))" \
     ".*Invalid type for register.*" \
     "test Frame.read_register with list"
+
+# Compile again without debug info.
+gdb_exit
+if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} {}] } {
+    return -1
+}
+
+if {![runto_main]} {
+    return 0
+}
+
+# Test if Frame.static_link works for a frame without debug info.
+gdb_test "python print(gdb.selected_frame().static_link())" "None" \
+    "test Frame.static_link for a frame without debug info"
-- 
2.35.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix crash when calling Frame.static_link
  2024-02-11 12:25 ` [PATCH] Fix crash when calling Frame.static_link Hannes Domani
@ 2024-02-11 16:25   ` Tom Tromey
  2024-02-11 16:45     ` Hannes Domani
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2024-02-11 16:25 UTC (permalink / raw)
  To: Hannes Domani; +Cc: gdb-patches

>>>>> "Hannes" == Hannes Domani <ssbssa@yahoo.de> writes:

Hannes> The problem was a missing check if get_frame_block returns nullptr
Hannes> inside frame_follow_static_link.

Thank you.  This is ok.
I think this is also ok for the gdb-14 branch.

thanks,
Tom

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix crash when calling Frame.static_link
  2024-02-11 16:25   ` Tom Tromey
@ 2024-02-11 16:45     ` Hannes Domani
  2024-02-11 17:46       ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: Hannes Domani @ 2024-02-11 16:45 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

 Am Sonntag, 11. Februar 2024 um 17:25:18 MEZ hat Tom Tromey <tom@tromey.com> Folgendes geschrieben:

> >>>>> "Hannes" == Hannes Domani <ssbssa@yahoo.de> writes:
>
> Hannes> The problem was a missing check if get_frame_block returns nullptr
> Hannes> inside frame_follow_static_link.
>
> Thank you.  This is ok.
> I think this is also ok for the gdb-14 branch.

Pushed to both, thanks.

Note that I also added this:
Approved-By: Tom Tromey <tom@tromey.com>


Hannes.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix crash when calling Frame.static_link
  2024-02-11 16:45     ` Hannes Domani
@ 2024-02-11 17:46       ` Tom Tromey
  0 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2024-02-11 17:46 UTC (permalink / raw)
  To: Hannes Domani; +Cc: Tom Tromey, gdb-patches

Hannes> Note that I also added this:
Hannes> Approved-By: Tom Tromey <tom@tromey.com>

Thanks, it slipped my mind.

Tom

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-02-11 17:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20240211122507.1069-1-ssbssa.ref@yahoo.de>
2024-02-11 12:25 ` [PATCH] Fix crash when calling Frame.static_link Hannes Domani
2024-02-11 16:25   ` Tom Tromey
2024-02-11 16:45     ` Hannes Domani
2024-02-11 17:46       ` Tom Tromey

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).