[PATCH] gdb, dwarf: Don't follow the parent of a subprogram to get a prefix.

Simon Marchi simon.marchi@polymtl.ca
Fri Jun 25 15:15:10 GMT 2021


On 2021-06-24 7:50 a.m., Felix Willgerodt via Gdb-patches wrote:
> During prefix resolution, if the parent is a subprogram, there is no need
> to go to the parent of the subprogram.  The DIE will be local.
> 
> For a program like:
> ~~~
>   class F1
>   {
>   public:
>     int a;
>     int
>     vvv ()
>     {
>       class F2
>       {
> 	int f;
>       };
>       F2 abcd;
>       return 1;
>     }
>   };
> ~~~
> 
> The class F2 should not be seen as a member of F1.
> 
> Before:
> ~~~
> (gdb) ptype abcd
> type = class F1::F2 {
>   private:
>     int f;
> }
> ~~~
> 
> After:
> ~~~
> (gdb) ptype abcd
> type = class F2 {
>   private:
>     int f;
> }
> ~~~

I played a bit with this and have a question.  The "fully-qualified
name" of F2 seems to be

  F1::vvv()::F2

since the symbol of method foo is

  _ZZN2F13vvvEvEN2F23fooEv
  F1::vvv()::F2::foo()

So would it make sense to display:

  (gdb) ptype abcd
  type = class F1::vvv()::F2 {
    ...
  }

?

And since these two work:

  (gdb) ptype F1
  type = class F1 {
    public:
      int a;

      int vvv(void);
  }
  (gdb) p 'F1::vvv()::F2::foo'
  $4 = {void (F1::F2 * const)} 0x555555555184 <F1::vvv()::F2::foo()>

I would kind of expect this to work:

  (gdb) ptype F1::vvv()::F2
  No symbol "F2" in specified context.
  (gdb) ptype 'F1::vvv()::F2'
  No symbol "F1::vvv()::F2" in current context.

Simon


More information about the Gdb-patches mailing list