public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Use frame.name() in FrameDecorator
@ 2023-08-01 20:06 Tom Tromey
  2023-08-03 13:50 ` Alexandra Petlanova Hajkova
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2023-08-01 20:06 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

A co-worker pointed out that gdb's DAP implementation might return an
integer for the name of a stack frame, like:

    {"id": 1, "name": 93824992310799, ...}

This can be seen currently in the logs of the bt-nodebug.exp test
case.

What is happening is that FrameDecorator falls back on returning the
PC when the frame's function symbol cannot be found, relying on the
gdb core to look up the minsym and print its name.

This can actually yield the wrong answer sometimes, because it falls
into the get_frame_pc / get_frame_address_in_block problem -- if the
frame is at a call to a noreturn function, the PC in this case might
appear to be in the next function in memory.  For more on this, see:

    https://sourceware.org/bugzilla/show_bug.cgi?id=8416

and related bugs.

However, there's a different approach we can take: the code here can
simply use Frame.name.  This handles the PC problem correctly, and
gets us the information we need.
---
 gdb/python/lib/gdb/FrameDecorator.py | 15 ++++-----------
 gdb/testsuite/gdb.dap/bt-nodebug.exp |  9 ++++++++-
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/gdb/python/lib/gdb/FrameDecorator.py b/gdb/python/lib/gdb/FrameDecorator.py
index aa9a2201bec..39ee2e2547c 100644
--- a/gdb/python/lib/gdb/FrameDecorator.py
+++ b/gdb/python/lib/gdb/FrameDecorator.py
@@ -75,17 +75,10 @@ class _FrameDecoratorBase(object):
         elif frame.type() == gdb.SIGTRAMP_FRAME:
             return "<signal handler called>"
 
-        func = frame.function()
-
-        # If we cannot determine the function name, return the
-        # address.  If GDB detects an integer value from this function
-        # it will attempt to find the function name from minimal
-        # symbols via its own internal functions.
-        if func is None:
-            pc = frame.pc()
-            return pc
-
-        return str(func)
+        func = frame.name()
+        if not isinstance(func, str):
+            func = "???"
+        return func
 
     def address(self):
         """Return the address of the frame's pc"""
diff --git a/gdb/testsuite/gdb.dap/bt-nodebug.exp b/gdb/testsuite/gdb.dap/bt-nodebug.exp
index e4dcef35a67..e9726d2e17d 100644
--- a/gdb/testsuite/gdb.dap/bt-nodebug.exp
+++ b/gdb/testsuite/gdb.dap/bt-nodebug.exp
@@ -44,6 +44,13 @@ lassign [dap_wait_for_event_and_check "stopped at function breakpoint" stopped \
 	    "body hitBreakpointIds" $fn_bpno] unused objs
 
 # The bug was that this request would fail.
-dap_check_request_and_response "backtrace" stackTrace {o threadId [i 1]}
+set obj [dap_check_request_and_response "backtrace" \
+	     stackTrace {o threadId [i 1]}]
+set frames [dict get [lindex $obj 0] body stackFrames]
+
+gdb_assert {[llength $frames] == 3} "three frames"
+
+gdb_assert {[dict get [lindex $frames 1] name] == "no_debug_info"} \
+    "name of no-debug frame"
 
 dap_shutdown
-- 
2.40.1


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

* Re: [PATCH] Use frame.name() in FrameDecorator
  2023-08-01 20:06 [PATCH] Use frame.name() in FrameDecorator Tom Tromey
@ 2023-08-03 13:50 ` Alexandra Petlanova Hajkova
  2023-08-03 15:36   ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Alexandra Petlanova Hajkova @ 2023-08-03 13:50 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1317 bytes --]

On Tue, Aug 1, 2023 at 10:07 PM Tom Tromey via Gdb-patches <
gdb-patches@sourceware.org> wrote:

> A co-worker pointed out that gdb's DAP implementation might return an
> integer for the name of a stack frame, like:
>
>     {"id": 1, "name": 93824992310799, ...}
>
> This can be seen currently in the logs of the bt-nodebug.exp test
> case.
>
> What is happening is that FrameDecorator falls back on returning the
> PC when the frame's function symbol cannot be found, relying on the
> gdb core to look up the minsym and print its name.
>
> This can actually yield the wrong answer sometimes, because it falls
> into the get_frame_pc / get_frame_address_in_block problem -- if the
> frame is at a call to a noreturn function, the PC in this case might
> appear to be in the next function in memory.  For more on this, see:
>
>     https://sourceware.org/bugzilla/show_bug.cgi?id=8416
>
> and related bugs.
>
> However, there's a different approach we can take: the code here can
> simply use Frame.name.  This handles the PC problem correctly, and
> gets us the information we need.
> ---
>
>
I tested this for Fedora-Rawhide on ppc64le. I can confirm this causes no
regressions and I can see  {"id": 1, "name": "no_debug_info",
is outputted instead of {"id": 1, "name": 268501652.

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

* Re: [PATCH] Use frame.name() in FrameDecorator
  2023-08-03 13:50 ` Alexandra Petlanova Hajkova
@ 2023-08-03 15:36   ` Tom Tromey
  0 siblings, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2023-08-03 15:36 UTC (permalink / raw)
  To: Alexandra Petlanova Hajkova; +Cc: Tom Tromey, gdb-patches

>>>>> Alexandra Petlanova Hajkova <ahajkova@redhat.com> writes:

>>  However, there's a different approach we can take: the code here can
>>  simply use Frame.name.  This handles the PC problem correctly, and
>>  gets us the information we need.

> I tested this for Fedora-Rawhide on ppc64le. I can confirm this causes
> no regressions and I can see {"id": 1, "name": "no_debug_info", is
> outputted instead of {"id": 1, "name": 268501652.

Thank you.  I'm going to check this in.

Tom

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

end of thread, other threads:[~2023-08-03 15:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-01 20:06 [PATCH] Use frame.name() in FrameDecorator Tom Tromey
2023-08-03 13:50 ` Alexandra Petlanova Hajkova
2023-08-03 15:36   ` 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).