binutils-gdb/gdb/testsuite/gdb.ada/array_of_symbolic_length.exp
Tom Tromey 386de171cb 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.
2021-06-04 13:51:23 -06:00

60 lines
1.7 KiB
Plaintext

# 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/>.
load_lib "ada.exp"
if { [skip_ada_tests] } { return -1 }
standard_ada_testfile foo
foreach_with_prefix scenario {all minimal} {
set flags [list debug additional_flags=-fgnat-encodings=$scenario]
if {[gdb_compile_ada "${srcfile}" "${binfile}" executable $flags] != ""} {
return -1
}
clean_restart ${testfile}
set bp_location [gdb_get_line_number "BREAK" ${testdir}/foo.adb]
runto "foo.adb:$bp_location"
set test "print my_value"
gdb_test_multiple "$test" $test {
-re " = \\(23, 23, 23, 23, 23, 23, 23\\).*$gdb_prompt $" {
pass $test
}
-re " = \\(\\).*$gdb_prompt $" {
if {$scenario == "minimal"} {
setup_kfail "minimal encodings" *-*-*
}
fail $test
}
}
set test "print rt"
gdb_test_multiple "$test" $test {
-re " = \\(a => \\(\\(a1 => \\(4, 4\\), a2 => \\(8, 8\\)\\), \\(a1 => \\(4, 4\\), a2 => \\(8, 8\\)\\)\\)\\).*$gdb_prompt $" {
pass $test
}
-re " = \\(a => \\(\\)\\).*$gdb_prompt $" {
if {$scenario == "minimal"} {
setup_kfail "minimal encodings" *-*-*
}
fail $test
}
}
}