[PATCH v2 2/2] gdb/dwarf2: fix "info locals" for clang-compiled inlined functions
Aktemur, Tankut Baris
tankut.baris.aktemur@intel.com
Wed Apr 14 17:00:48 GMT 2021
On Wednesday, April 14, 2021 5:47 PM, Andrew Burgess wrote:
> * Aktemur, Tankut Baris via Gdb-patches <gdb-patches@sourceware.org> [2021-04-14 12:18:26
> +0000]:
>
> > On Wednesday, April 14, 2021 10:15 AM, Aktemur, Tankut Baris wrote:
> > > diff --git a/gdb/testsuite/gdb.dwarf2/dw2-inline-with-lexical-scope.exp
> > > b/gdb/testsuite/gdb.dwarf2/dw2-inline-with-lexical-scope.exp
> > > new file mode 100644
> > > index 00000000000..e815c859639
> > > --- /dev/null
> > > +++ b/gdb/testsuite/gdb.dwarf2/dw2-inline-with-lexical-scope.exp
> > > @@ -0,0 +1,137 @@
> > > +# Copyright 2021 Free Software Foundation, Inc.
> > > +
> > > +# This program is free software; you can redistribute it and/or modify
> > > +# it under the terms of the GNU General Public License as published by
> > > +# the Free Software Foundation; either version 3 of the License, or
> > > +# (at your option) any later version.
> > > +#
> > > +# This program is distributed in the hope that it will be useful,
> > > +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> > > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > > +# GNU General Public License for more details.
> > > +#
> > > +# You should have received a copy of the GNU General Public License
> > > +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> > > +
> > > +# Test that scoped local variables in an inlined function are printed
> > > +# properly.
> > > +
> > > +load_lib dwarf.exp
> > > +
> > > +# This test can only be run on targets that support DWARF-2 and use
> > > +# gas.
> > > +if {![dwarf2_support]} {
> > > + return 0
> > > +}
> > > +
> > > +standard_testfile .c .S
> > > +
> > > +# Make some DWARF for the test. The concrete inlined instance
> > > +# (i.e. the DW_TAG_inlined_subroutine) has a DW_TAG_lexical_block that
> > > +# does not contain a DW_AT_abstract_origin attribute. This is
> > > +# deliberate. Bad GDB printed duplicate local variables with
> > > +# "optimized out" values in this case.
> > > +
> > > +set asm_file [standard_output_file $srcfile2]
> > > +Dwarf::assemble $asm_file {
> > > + global srcfile srcdir subdir
> > > + declare_labels int_label func_label num_label value_label lines_label
> > > +
> > > + get_func_info main
> > > + set func_call [gdb_get_line_number "func call"]
> > > +
> > > + cu {} {
> > > + compile_unit {
> > > + {language @DW_LANG_C99}
> > > + {name $srcfile}
> > > + {low_pc $main_start addr}
> > > + {high_pc "$main_start + $main_len" addr}
> > > + {stmt_list ${lines_label} DW_FORM_sec_offset}
> > > + } {
> > > + int_label: base_type {
> > > + {name "int"}
> > > + {byte_size 4 sdata}
> > > + {encoding @DW_ATE_signed}
> > > + }
> > > +
> > > + func_label: subprogram {
> > > + {name func}
> > > + {inline 3 data1}
> > > + } {
> > > + num_label: DW_TAG_variable {
> > > + {name num}
> > > + {type :$int_label}
> > > + }
> > > + lexical_block {
> > > + } {
> > > + value_label: DW_TAG_variable {
> > > + {name value}
> > > + {type :$int_label}
> > > + }
> > > + }
> > > + }
> > > +
> > > + subprogram {
> > > + {name main}
> > > + {frame_base {DW_OP_reg6} SPECIAL_expr}
> >
> > I think I'll have to limit the test to X86_64 targets.
>
> As I understand the problem description, the important part of this
> test is the lack of DW_AT_abstract_origin, not the location of the
> variables.
>
> The approach I usually take for tests like this is to mirror the
> variables into global parameters, and just have the location attribute
> point to the global location.
>
> I tested this approach with your patch, the test still fails before
> the fix, and works afterwards, so I think we're good - but now there's
> no need to reference specific stack locations, or register numbers.
>
> The patch below is what I came up with, feel free to use this if you
> think it is helpful. It should apply on top of your two patches.
>
> Thanks,
> Andrew
This worked very well. Thank you for the suggestion.
I pushed the patch.
-Baris
> ---
>
> diff --git a/gdb/testsuite/gdb.dwarf2/dw2-inline-with-lexical-scope.c
> b/gdb/testsuite/gdb.dwarf2/dw2-inline-with-lexical-scope.c
> index 0fd909459ba..57ef6a8f035 100644
> --- a/gdb/testsuite/gdb.dwarf2/dw2-inline-with-lexical-scope.c
> +++ b/gdb/testsuite/gdb.dwarf2/dw2-inline-with-lexical-scope.c
> @@ -16,6 +16,9 @@
> along with this program. If not, see
> <http://www.gnu.org/licenses/>. */
>
> +int global_num = 0;
> +int global_value = 0;
> +
> #ifdef __GNUC__
> #define ATTR __attribute__((always_inline))
> #else
> @@ -26,12 +29,15 @@ inline ATTR
> static void
> func ()
> { /* func prologue */
> - int num= 42;
> + global_num = 42;
> + int num = 42;
> if (num > 2)
> {
> asm ("scope_label1: .globl scope_label1");
> + global_value = num;
> int value = num;
> asm ("breakpoint_label: .globl breakpoint_label");
> + global_value += 10;
> value += 10; /* break here */
> asm ("scope_label2: .globl scope_label2");
> }
> diff --git a/gdb/testsuite/gdb.dwarf2/dw2-inline-with-lexical-scope.exp
> b/gdb/testsuite/gdb.dwarf2/dw2-inline-with-lexical-scope.exp
> index e815c859639..d85d2fe06b0 100644
> --- a/gdb/testsuite/gdb.dwarf2/dw2-inline-with-lexical-scope.exp
> +++ b/gdb/testsuite/gdb.dwarf2/dw2-inline-with-lexical-scope.exp
> @@ -40,6 +40,9 @@ Dwarf::assemble $asm_file {
> get_func_info main
> set func_call [gdb_get_line_number "func call"]
>
> + set num_var [gdb_target_symbol global_num]
> + set value_var [gdb_target_symbol global_value]
> +
> cu {} {
> compile_unit {
> {language @DW_LANG_C99}
> @@ -73,7 +76,6 @@ Dwarf::assemble $asm_file {
>
> subprogram {
> {name main}
> - {frame_base {DW_OP_reg6} SPECIAL_expr}
> {external 1 flag}
> {low_pc $main_start addr}
> {high_pc "$main_start + $main_len" addr}
> @@ -87,7 +89,7 @@ Dwarf::assemble $asm_file {
> } {
> DW_TAG_variable {
> {abstract_origin %$num_label}
> - {location {DW_OP_fbreg -4} SPECIAL_expr}
> + {location {addr $num_var} SPECIAL_expr}
> }
> lexical_block {
> {low_pc scope_label1 addr}
> @@ -95,7 +97,7 @@ Dwarf::assemble $asm_file {
> } {
> DW_TAG_variable {
> {abstract_origin %$value_label}
> - {location {DW_OP_fbreg -8} SPECIAL_expr}
> + {location {addr $value_var} SPECIAL_expr}
> }
> }
> }
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
More information about the Gdb-patches
mailing list