Skip to content

Commit 30baee6

Browse files
committed
Use frame.name() in FrameDecorator
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.
1 parent b1c0ab2 commit 30baee6

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

gdb/python/lib/gdb/FrameDecorator.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,10 @@ def function(self):
7575
elif frame.type() == gdb.SIGTRAMP_FRAME:
7676
return "<signal handler called>"
7777

78-
func = frame.function()
79-
80-
# If we cannot determine the function name, return the
81-
# address. If GDB detects an integer value from this function
82-
# it will attempt to find the function name from minimal
83-
# symbols via its own internal functions.
84-
if func is None:
85-
pc = frame.pc()
86-
return pc
87-
88-
return str(func)
78+
func = frame.name()
79+
if not isinstance(func, str):
80+
func = "???"
81+
return func
8982

9083
def address(self):
9184
"""Return the address of the frame's pc"""

gdb/testsuite/gdb.dap/bt-nodebug.exp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ lassign [dap_wait_for_event_and_check "stopped at function breakpoint" stopped \
4444
"body hitBreakpointIds" $fn_bpno] unused objs
4545

4646
# The bug was that this request would fail.
47-
dap_check_request_and_response "backtrace" stackTrace {o threadId [i 1]}
47+
set obj [dap_check_request_and_response "backtrace" \
48+
stackTrace {o threadId [i 1]}]
49+
set frames [dict get [lindex $obj 0] body stackFrames]
50+
51+
gdb_assert {[llength $frames] == 3} "three frames"
52+
53+
gdb_assert {[dict get [lindex $frames 1] name] == "no_debug_info"} \
54+
"name of no-debug frame"
4855

4956
dap_shutdown

0 commit comments

Comments
 (0)