Add PROP_VARIABLE_NAME
authorTom Tromey <tromey@adacore.com>
Fri, 4 Jun 2021 19:51:23 +0000 (13:51 -0600)
committerTom Tromey <tromey@adacore.com>
Fri, 4 Jun 2021 19:51:23 +0000 (13:51 -0600)
commit386de171cbffa86e804057030f3d64a404279f43
treefb9c127f3c004533fa43110baa467b7405e323ce
parent4351271e9c98553900f6ae3cbcaaa75198909daa
Add PROP_VARIABLE_NAME

With -fgnat-encodings=minimal, an internal version (these patches will
be upstreamed in the near future) of the Ada compiler can emit DWARF
for an array where the bound comes from a variable, like:

 <1><12a7>: Abbrev Number: 7 (DW_TAG_array_type)
    <12a8>   DW_AT_name        : (indirect string, offset: 0x1ae9): pck__my_array
[...]
 <2><12b4>: Abbrev Number: 8 (DW_TAG_subrange_type)
    <12b5>   DW_AT_type        : <0x1294>
    <12b9>   DW_AT_upper_bound : <0x1277>

With the upper bound DIE being:

 <1><1277>: Abbrev Number: 2 (DW_TAG_variable)
    <1278>   DW_AT_name        : (indirect string, offset: 0x1a4d): pck__my_length___U
    <127c>   DW_AT_type        : <0x128f>
    <1280>   DW_AT_external    : 1
    <1280>   DW_AT_artificial  : 1
    <1280>   DW_AT_declaration : 1

Note that the variable is just a declaration -- in this situation, the
variable comes from another compilation unit, and must be found when
trying to compute the array bound.

This patch adds a new PROP_VARIABLE_NAME kind, to enable this search.

This same scenario can occur with DW_OP_GNU_variable_value, so this
patch adds support for that as well.

gdb/ChangeLog
2021-06-04  Tom Tromey  <tromey@adacore.com>

* dwarf2/read.h (dwarf2_fetch_die_type_sect_off): Add 'var_name'
parameter.
* dwarf2/loc.c (dwarf2_evaluate_property) <case
PROP_VARIABLE_NAME>: New case.
(compute_var_value): New function.
(sect_variable_value): Use compute_var_value.
* dwarf2/read.c (attr_to_dynamic_prop): Handle DW_TAG_variable.
(var_decl_name): New function.
(dwarf2_fetch_die_type_sect_off): Add 'var_name' parameter.
* gdbtypes.h (enum dynamic_prop_kind) <PROP_VARIABLE_NAME>: New
constant.
(union dynamic_prop_data) <variable_name>: New member.
(struct dynamic_prop) <variable_name, set_variable_name>: New
methods.

gdb/testsuite/ChangeLog
2021-06-04  Tom Tromey  <tromey@adacore.com>

* gdb.ada/array_of_symbolic_length.exp: New file.
* gdb.ada/array_of_symbolic_length/foo.adb: New file.
* gdb.ada/array_of_symbolic_length/gl.adb: New file.
* gdb.ada/array_of_symbolic_length/gl.ads: New file.
* gdb.ada/array_of_symbolic_length/pck.adb: New file.
* gdb.ada/array_of_symbolic_length/pck.ads: New file.
12 files changed:
gdb/ChangeLog
gdb/dwarf2/loc.c
gdb/dwarf2/read.c
gdb/dwarf2/read.h
gdb/gdbtypes.h
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ada/array_of_symbolic_length.exp [new file with mode: 0644]
gdb/testsuite/gdb.ada/array_of_symbolic_length/foo.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/array_of_symbolic_length/gl.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/array_of_symbolic_length/gl.ads [new file with mode: 0644]
gdb/testsuite/gdb.ada/array_of_symbolic_length/pck.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/array_of_symbolic_length/pck.ads [new file with mode: 0644]