Re: [PATCH] Show optimized out local variables in "info locals"

Simon Marchi
2017-11-22T20:58:20Z

On 2017-11-14 11:54 PM, Simon Marchi wrote:
> On 2017-11-14 05:44 PM, Yao Qi wrote:
>> On Tue, Nov 14, 2017 at 5:08 PM, Simon Marchi <simon.marchi@ericsson.com> wrote:
>>>
>>> However, this change reveals what I think is a bug in GDB, see:
>>>
>>> http://lists.dwarfstd.org/pipermail/dwarf-discuss-dwarfstd.org/2017-September/004394.html
>>>
>>
>> IMO, it is not necessary to emit DW_TAG_lexical_block in concrete instances.
>> See comment #4 in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=37801
>> At least, looks gcc generates unnecessary debug information, and we need
>> to fix GCC somehow.
>>
>> Whether it is a bug in GDB or not, I don't know. The answer depends on it is
>> *unnecessary* or *wrong* to have DW_TAG_lexical_block in concrete instances.
>
> I had an email discussion with some gcc developers (Nathan Sidwell, Richard Biener,
> Jason Merill) after a chat on IRC. Unfortunately, they answered privately so it's
> not on dwarf-discuss. I'll try to update the thread on dwarf-discuss with their
> answers tomorrow, for future reference. But the gist of it was:
>
> Richard said:
>
>> I think the lexical block is just the function scope itself and the inliner
>> inserts this BLOCK which then corresponds to the DW_TAG_inlined_subroutine.
>> I suppose we should avoid emitting that BLOCK itself as a DW_TAG_lexical_block
>> but use the emitted DW_TAG_inlined_subroutine for that.
>>
>> Not sure if I remember the details correctly.
>>
>> I don't think the DWARF is invalid btw, with early LTO debug we have plenty of
>> abstract origins where source and destination context don't match 1:1. We're
>> just using it as a "get some more info from this DIE" link which I think is
>> all that is documented as semantics (though the 'inline' term pops up too
>> often there and the relation to DW_AT_specification is unclear to me though
>> the latter is restricted to DW_TAG_subroutine AFAIR).
>
> Jason said (replying to Richard):
>
>>> I think the lexical block is just the function scope itself and the inliner
>>> inserts this BLOCK which then corresponds to the DW_TAG_inlined_subroutine.
>>> I suppose we should avoid emitting that BLOCK itself as a DW_TAG_lexical_block
>>> but use the emitted DW_TAG_inlined_subroutine for that.
>>
>> Agreed. It's curious that we would generate the lexical block in the
>> inlined instance and not the abstract.
>>
>>> I don't think the DWARF is invalid btw, with early LTO debug we have plenty of
>>> abstract origins where source and destination context don't match 1:1. We're
>>> just using it as a "get some more info from this DIE" link which I think is
>>> all that is documented as semantics (though the 'inline' term pops up too
>>> often there and the relation to DW_AT_specification is unclear to me though
>>> the latter is restricted to DW_TAG_subroutine AFAIR).
>>
>> Also agreed, GDB ought to be able to handle this situation.
>>
>> So, bugs on both sides...
>
> So even though there might be something to fix in GCC, I think we'll have to handle
> the current case in GDB as well.
>
> Simon
>

I've updated the thread on dwarf-discuss, and pushed the patch.

Thanks,

Simon