]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
gdb: adjust the default place of 'list' to main's prologue
authorStephan Rohr <stephan.rohr@intel.com>
Sat, 3 Aug 2024 09:07:42 +0000 (02:07 -0700)
committerAndrew Burgess <aburgess@redhat.com>
Fri, 9 Aug 2024 10:29:51 +0000 (11:29 +0100)
commit49e607f511c1fab82a0116990a72d1915c74bb4a
tree83b07e844b9a8bd1c0b9635dcf63664d7863639d
parent7dd0dfbde7ee31167a3b2e192a575493d26b7b0a
gdb: adjust the default place of 'list' to main's prologue

The 'list' command prints around the 'main' function if the current
source location is not set.  The prologue of 'main' is skipped and the
first real line of 'main' is offset by 'lines_to_print - 1'.  This is
incorrect, the location should be defaulted to main's prologue without
applying offsets (similar to 'list main').  Printing around the selected
line is then done in 'list_around_line'.

The patch also fixes an issue if the list command is used before the
program is started.  For example, with the following code:

26 static void attribute ((used)) ambiguous_fun (void) {}
27
28 static int attribute ((used)) ambiguous_var;
29
30
31
32
33
34
35
36
37
38 int
39 main (void)
40 {
41   return 0;
42 }

GDB offsets the relevant line by 'lines_to_print - 1' and then by another
'lines_to_print / 2' and prints:

(gdb) list
27
28 static int attribute ((used)) ambiguous_var;
29
30
31
32
33
34
35
36

With this patch, GDB correctly prints:

37
38      int
39      main (void)
40      {
41        return 0;
42      }

Approved-By: Andrew Burgess <aburgess@redhat.com>
gdb/source.c
gdb/testsuite/gdb.base/cursal.c
gdb/testsuite/gdb.base/cursal.exp
gdb/testsuite/gdb.base/list-ambiguous0.c
gdb/testsuite/gdb.base/list-before-start.exp [new file with mode: 0644]
gdb/testsuite/gdb.mi/mi-file.exp