]> git.feebdaed.xyz Git - 0xmirror/binutils-gdb.git/commit
gdb: shortcut 'list LINENO'
authorAndrew Burgess <aburgess@redhat.com>
Sat, 15 Nov 2025 14:55:19 +0000 (14:55 +0000)
committerAndrew Burgess <aburgess@redhat.com>
Tue, 16 Dec 2025 15:29:11 +0000 (15:29 +0000)
commitc1859f4b6863655c84646816f0885d316d35871b
treeaffca49ff0a75b7ab7ec9a91908ed746c34bd378
parente5ba60c83639d04c296c8d9c47568c5557af9b8d
gdb: shortcut 'list LINENO'

While working on a test for a weird interaction between the DWARF
parser, debuginfod, and the 'list' command, I noticed that performing
'list LINENO' can incur a significant amount of work trying to figure
out which symtab the source should be listed from.  This seems a
little weird as a plain 'list' just uses the default symtab with no
searching through all of the symtabs.

The symtab lookup is all hidden behind the decode_line_1 call, which
is made from list_command (cli/cli-cmds.c).

The thing is, in list_command we already have code which (basically)
checks if the argument to 'list' is a line number, here's the code:

  for (p = arg; p != arg1 && *p >= '0' && *p <= '9'; p++);
  linenum_beg = (p == arg1);

And we already have code within list_command which depends on the
default symtab, look at how 'list .', 'list +', and 'list -' are
handled.

I think that 'list LINENO' is such a common use case that is makes
sense to optimise this case in order to avoid the need to perform
symtab lookup.  I think this can be achieved without any significant
changes to the list_command function; we'll just move the existing
line number check (see above code) a little earlier in the function
and change it to a strtol call so that the actual line number is
recorded.  Then there's a little error checking, before finally we can
skip straight to listing the source code using the default symtab.

For anything other than 'list LINENO' we will handle the command just
as we've always done.

I think there's actually scope for list_command to handle more cases
internally, without calling out to decode_line_1, but I thought I'd
see how happy people were with this smaller change first before I
tried anything larger.

There should be no user visible changes after this commit, other than
'list LINENO' might be a little faster.

Reviewed-By: Keith Seitz <keiths@redhat.com>
gdb/cli/cli-cmds.c