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:
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.