Re: [PATCH v4] gdb/manual: Introduce location specs

Pedro Alves
2022-05-27T17:11:21Z

On 2022-05-27 16:52, Eli Zaretskii wrote:
>> Date: Fri, 27 May 2022 16:04:32 +0100
>> Cc: gdb-patches@sourceware.org
>> From: Pedro Alves <pedro@palves.net>
>>
>>> > +A concrete code location in your program is uniquely identifiable by a
>>> > +set of logical attributes. Typically, a line number, the source file
>>> > +the line belongs to, the fully-qualified and prototyped function it is
>>> > +defined in, and an instruction address. Because each inferior has its
>>> > +own address space, also an inferior number.
>>>
>>> The "typically" part and the overall style seem to say that this is
>>> not the exhaustive list of all the attributes of a code location, just
>>> a general idea. Can you please present a full exhaustive list of the
>>> attributes of a code location?
>>
>> I meant to remove the "typically", and forgot it, sorry. It is not
>> supposed to be there.
>
> OK, so I take it the full list is:
>
> . absolute file name of the source
> . line number in the source file
> . fully-qualified and prototyped function
> . address
> . inferior number

Yes. Well, except "absolute" in the file name. The file names in the
debug info aren't always absolute, they can be something like ../a/b/c/foo.c,
and we may not be able to find the source file in the filesystem, so the
path the debug info tells us is all we get.

>
>>> And another question: does the process of resolving a location spec to
>>> obtain the corresponding code locations involve only filling in of the
>>> attributes that were omitted from the spec, or does it also produce
>>> attributes that can _never_ be part of the location spec? IOW, can
>>> the user type a location spec which will yield a code location that is
>>> 100% identical to the input spec?
>>
>> Currently there's no way to explicitly specify the inferior with
>> any format of location specifications. So if you do "b func", and you
>> have multiple inferiors, GDB will find code locations for "func" in all
>> the inferiors. All the other attributes you can explicitly specify.
>> Not sure whether that answers your question.
>
> I think it does, but:
>
>> I am not sure what you
>> mean by "100% identical". A spec can never the identical to the actual
>> thing, the same way a cake recipe can never be identical to a cake, for
>> they are things of different nature. It can only be that the actual
>> thing complies with or follows the spec.
>
> I thought you just explained above that, when there's only one
> inferior, the user can give a location spec which will resolve to a
> code location that has exactly the same attributes as the spec? IOW,
> in this case the "resolution" of the spec produces a "thing" that to
> the user looks exactly the same as the input spec?

When you specify a function name, you can't specify an address
at the same time, for example. There's no format that allows that.
So if you specify a function, you end up with code location that has
an address, but you didn't specify the address. Conversely, when you
specify an address, gdb finds the source/line for the address if available,
as well as the function.

So you can't pass the whole set of attributes at once, some combinations can't
be specified, or are incompatible/ignored.

And then GDB knows more about the code locations than that set of attributes,
of course. GDB knows the architecture of the instruction the location points
at, for example.