[PATCH v4] gdb/manual: Introduce location specs

Pedro Alves pedro@palves.net
Fri May 27 19:05:25 GMT 2022


On 2022-05-27 19:55, Eli Zaretskii wrote:
>> Date: Fri, 27 May 2022 19:42:50 +0100
>> Cc: gdb-patches@sourceware.org
>> From: Pedro Alves <pedro@palves.net>
>>
>>> Yes, but note that the last revision of your patch says "resolves
>>> into", not "matches".  Which I think is a change for the better; I'm
>>> trying to have a more accurate idea of what that "resolution" entails.
>>
>> Resolution is the act of find all the actual code location that match the user
>> input.  The found locations are the resolved code locations.
>>
>> Here for example:
>>
>>  +@item list @var{locspec}
>>  +Print lines centered around the line or lines that @var{locspec}
>>  +resolves to.
>>
>> The meaning is that the user passes some input spec to GDB, which
>> may even not specify any line at all, like "line func", and GDB
>> finds all the matching locations.  For each resolved location, you have
>> a resolved line, resolved source file, resolved addr, resolved function, etc.
> 
> I understand (I think).  But all this does is fill in the attributes
> that were missing from the input location spec.  This is done either
> by using the (implied) defaults, like the name of the current file, or
> bhy using the debug info.  And if it turns out that some attribute can
> be filled in more than one way, we have a breakpoint with multiple
> code locations.  Right?
> 

You start with e.g., just one attribute, like "-function func".  This
makes GDB iterate over all the functions is knows about, finding the
ones that are called "func".  This matches "func(int)", "A::func()",
"func(long)", etc.  GDB collects the PC and source file and line number of
those functions too along the wa.  If you did "break -function func", then
you end up with a breakpoint with multiple code locations, one
for each function matched.

Or you start with "a/file.c:100".  This makes GDB iterate over all source
files it knows about, and then for each that has a file name that ends
with "a/file.c", like e.g., "src/program/a/file.c" and "somelib/a/file.c"
it searches for line 100, collecting the PC and function name of the
location.  If you did "break a/file.c:100", you end up with a breakpoint with
multiple locations, one per resolved location.  If you did 
"list a/file.c:100", GDB lists the source for around each of the locations.
Etc.

Or you start with "*0x1000".  Conceptually it's the same.  GDB finds the code
locations that match that, resolves that to a location with
PC/function/source/line, and then the command does what it wants with it.


More information about the Gdb-patches mailing list