Re: [PATCH][gdb/symtab] Fix infinite recursion in dwarf2_cu::get_builder()

Tom de Vries
2021-05-06T15:24:25Z

On 5/6/21 5:16 PM, Eli Zaretskii wrote:
>> Date: Thu, 6 May 2021 14:02:49 +0200
>> From: Tom de Vries <tdevries@suse.de>
>> Cc: Tom Tromey <tom@tromey.com>
>>
>> Removing this code (that is, doing SYMBOL_IS_ARGUMENT (sym) = 1
>> unconditially), fixes the crash. The ancestor variable also seems to have
>> been added specifically to deal with fallout from this code, so remove that as
>> well.
>>
>> Tested on x86_64-linux:
>> - openSUSE Leap 15.2 with gcc 7.5.0, and
>> - openSUSE Tumbleweed with gcc 10.3.0.
>>
>> Any comments?
>>
>> Thanks,
>> - Tom
>>
>> [gdb/symtab] Fix infinite recursion in dwarf2_cu::get_builder()
>>
>> gdb/ChangeLog:
>>
>> 2021-05-06 Tom de Vries <tdevries@suse.de>
>>
>> PR symtab/26327
>> * dwarf2/read.c (struct dwarf2_cu): Remove ancestor.
>> (dwarf2_cu::get_builder): Remove ancestor-related code.
>> (new_symbol): Remove code supporting pre-4.1 gcc that show arguments
>> of inlined functions as locals.
>> (follow_die_offset, follow_die_sig_1): Remove setting of ancestor.
>>
>> ---
>> gdb/doc/gdb.texinfo | 4 ++--
>> gdb/dwarf2/read.c | 25 ++-----------------------
>> 2 files changed, 4 insertions(+), 25 deletions(-)
>>
>> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
>> index 56f37eb2288..f4d7085da58 100644
>> --- a/gdb/doc/gdb.texinfo
>> +++ b/gdb/doc/gdb.texinfo
>> @@ -13842,8 +13842,8 @@ when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
>> do not emit two required attributes (@samp{DW_AT_call_file} and
>> @samp{DW_AT_call_line}); @value{GDBN} does not display inlined
>> function calls with earlier versions of @value{NGCC}. It instead
>> -displays the arguments and local variables of inlined functions as
>> -local variables in the caller.
>> +displays local variables of inlined functions as local variables in
>> +the caller.
>>
>> The body of an inlined function is directly included at its call site;
>> unlike a non-inlined function, there are no instructions devoted to
>> diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
>
> I'm not sure I understand why you are changing the manual as part of
> this fix?
>

Hi Eli,

The 2009 commit edb3359dff90ef8a3352408bfef8ce1438c2b2e1 did this change:
...
case DW_TAG_formal_parameter:
- SYMBOL_IS_ARGUMENT (sym) = 1;
+ /* If we are inside a function, mark this as an argument. If
+ not, we might be looking at an argument to an inlined
+ function
+ when we do not have enough information to show inlined
+ frames;
+ pretend it's a local variable in that case so that the user
+ can
+ still see it. */
+ if (context_stack_depth > 0
+ && context_stack[context_stack_depth - 1].name != NULL)
+ SYMBOL_IS_ARGUMENT (sym) = 1;
...
and described it in the documentation:
...
+when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
+do not emit two required attributes (@samp{DW_AT_call_file} and
+@samp{DW_AT_call_line}); @value{GDBN} does not display inlined
+function calls with earlier versions of @value{NGCC}. It instead
+displays the arguments and local variables of inlined functions as
+local variables in the caller.
...

I'm undoing that change, and updating the documentation accordingly.

Thanks,
- Tom