This is the mail archive of the dwarf2@corp.sgi.com mailing list for the dwarf2 project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: PROPOSAL: Permit AT_location with AT_declaration



The two issues I raised are orthogonal, so I'll respond to each
separately.

> 
> Please read the second paragraph under item 5 from the specification, 
> as quoted in the proposal.
> 

Oops.  Yeah, I missed that.  So, attributes can be omitted.  That's good.

> > 
> >    int x;
> > 
> >    void myfunc()
> >    {
> >       int x;
> > 
> >       // complex sequence of code using ::x
> >       // where a local copy is placed in a register
> >    }
> > 
> > It seems that it would be unwise for a compiler to describe the local copy of
> > x in myfunc() with a DW_AT_name, because it would conflict with the proper
> > definition of x in that scope.  So, presumably, the DW_AT_name would be
> > omitted.
> 
> There is no need for a non-defining declaration in this example.
> 
> This seems to be a case which is addressed by current debuggers 
> without any changes to the Dwarf 2 specification.
> 

If there's no non-defining declaration for the global x in myfunc(), then how
does the debugger know about the local copy of the global x?  I've asked this
exact same question in various forms repeatedly before, but never received a
satisfactory answer.  It's very bothersome that you keep saying that current
compilers & debuggers deal with this, when they couldn't possibly, at least
not in general.  So, here goes: I assert that, in general, there is no way to
describe this without the anonymous non-defining declaration, and also
without using location lists for the global (which is bad for reasons that
we've beaten to death).  I can't prove that assertion, of course, because
it's so far-reaching.  But if so many compilers & debuggers support this, you
ought to have no trouble at all disproving it with a counterexample.  (BTW,
GCC is not a valid counterexample.)

And just in case this is in question, I do contend that the first declaration
of "x" is a global.  Any other source file could have an "extern int x;"
declaration and then be free to reference it or modify it.  That qualifies as
global, and I'd certainly give the DIE for the first "x" an DW_AT_external
attribute.

Now, I'll give an example of how I thought to describe the above, using an
anonymous non-defining declaration (which happens to correspond pretty
closely to Jason's local copy suggestion, too):

   DW_TAG_compile_unit

      DW_TAG_variable   <-----------------\
      DW_AT_name "x"                      |
      DW_AT_location [DW_OP_addr ...]     |  <-- Not a location list!
      DW_AT_external TRUE                 |
                                          |
      DW_TAG_subroutine                   |
      DW_AT_name "myfunc"                 |
      DW_AT_low_pc 0x4000                 |
      DW_AT_high_pc 0x5000                |
                                          |
         DW_TAG_variable                  |
         DW_AT_name "x"                   |
         DW_AT_location [DW_OP_reg...]    |
                                          |
         DW_TAG_variable                  |
         DW_AT_declaration TRUE           |
         DW_AT_specification -------------/
         DW_AT_location [0x4000 .. 0x5000 => DW_OP_addr ...,
                         0x4200 .. 0x4c00 => DW_OP_reg...]

         ...

      NULL

   NULL

>
> If the first declaration were "extern int x;", then a non-defining
> declaration would be needed.  And it should have a name, like any
> other variable declaration.  Should the debugger wish to reference 
> 'x' in this context, then it would need to distinguish whether this
> referred to the local or global.  This would seem straightforward.
> 

It seems to me that if the example had "extern int x;" for the first
non-defining declaration, then you might very well want two non-defining
declarations: one at global scope, probably with the name "x" (as you
described), and another anonymous one within myfunc() which described the
local copy within myfunc().

In that case, my thought on how to describe it would look nearly like the
example above, except that the description of the first "x" would also have a
DW_AT_declaration TRUE (because it's a non-defining declaration).  

   DW_TAG_compile_unit

      DW_TAG_variable   <-----------------\
      DW_AT_name "x"                      |
      DW_AT_declaration TRUE              |
      DW_AT_location [DW_OP_addr ...]     |  <-- Not a location list!
      DW_AT_external TRUE                 |
                                          |
      DW_TAG_subroutine                   |
      DW_AT_name "myfunc"                 |
      DW_AT_low_pc 0x4000                 |
      DW_AT_high_pc 0x5000                |
                                          |
         DW_TAG_variable                  |
         DW_AT_name "x"                   |
         DW_AT_location [DW_OP_reg...]    |
                                          |
         DW_TAG_variable                  |
         DW_AT_declaration TRUE           |
         DW_AT_specification -------------/
         DW_AT_location [0x4000 .. 0x5000 => DW_OP_addr ...,
                         0x4200 .. 0x4c00 => DW_OP_reg...]

         ...

      NULL

   NULL

Also, maybe you could argue that the DW_AT_external for the first "x" should
be omitted, given that it's a non-defining declaration and presumably there's
already a defining declaration at global scope.

-- 
Todd Allen
Concurrent Computer Corporation


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]