aboutsummaryrefslogtreecommitdiff
path: root/gdb/infrun.c
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2024-08-05 14:00:42 +0200
committerTom de Vries <tdevries@suse.de>2024-08-05 14:00:42 +0200
commitb464e193d116bd752375b92cc65c676cbd6f00fa (patch)
treee7b21ecb6cf4ed24a2eb996182f5d9b1e6166c6f /gdb/infrun.c
parent3a83f0342e545a638aba06f27bba76938ef251ab (diff)
downloadgdb-b464e193d116bd752375b92cc65c676cbd6f00fa.zip
gdb-b464e193d116bd752375b92cc65c676cbd6f00fa.tar.gz
gdb-b464e193d116bd752375b92cc65c676cbd6f00fa.tar.bz2
[gdb] Notice when stepping into different file
Consider the following test-case: ... $ cat -n test.c 1 int var; 2 3 int 4 foo (void) 5 { 6 var = 1; 7 #include "test.h" 8 } 9 10 int 11 main () 12 { 13 return foo (); 14 } $ cat -n test.h 1 return 1; $ gcc test.c -g ... When stepping through the test-case, gdb doesn't make it explicit that line 1 is not in test.c: ... Temporary breakpoint 1, main () at test.c:13 13 return foo (); (gdb) step foo () at test.c:6 6 var = 1; (gdb) n 1 return 1; (gdb) 8 } (gdb) ... which makes it easy to misinterpret the output. This is with the default "print frame-info" == auto, with documented behaviour [1]: ... stepi will switch between source-line and source-and-location depending on the program counter. ... What is actually implemented is that source-line is used unless stepping into or out of a function. The problem can be worked around by using "set print frame-info source-and-location", but that's a bit verbose. Instead, change the behaviour of "print frame-info" == auto to also use source-and-location when stepping into another file, which gets us: ... (gdb) n foo () at test.h:1 1 return 1; ... Tested on x86_64-linux. Reviewed-By: Kevin Buettner <kevinb@redhat.com> Reviewed-By: Kévin Le Gouguec <legouguec@adacore.com> PR gdb/32011 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32011 [1] https://sourceware.org/gdb/current/onlinedocs/gdb.html/Print-Settings.html#index-set-print-frame_002dinfo
Diffstat (limited to 'gdb/infrun.c')
-rw-r--r--gdb/infrun.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 06b454b..05e81a0 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -9296,12 +9296,24 @@ print_stop_location (const target_waitstatus &ws)
&& (tp->control.step_start_function
== find_pc_function (tp->stop_pc ())))
{
- /* Finished step, just print source line. */
- source_flag = SRC_LINE;
+ symtab_and_line sal = find_frame_sal (get_selected_frame (nullptr));
+ if (sal.symtab != tp->current_symtab)
+ {
+ /* Finished step in same frame but into different file, print
+ location and source line. */
+ source_flag = SRC_AND_LOC;
+ }
+ else
+ {
+ /* Finished step in same frame and same file, just print source
+ line. */
+ source_flag = SRC_LINE;
+ }
}
else
{
- /* Print location and source line. */
+ /* Finished step into different frame, print location and source
+ line. */
source_flag = SRC_AND_LOC;
}
break;