From e26624c669037529816f89ce1b9c78954c389ca1 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 14 Dec 2020 07:42:23 -0700 Subject: Be more careful when rewriting thick pointer array type To handle thick pointers with -fgnat-encodings=minimal, gdb will rewrite the underlying array type to remove the bounds. However, if the same DWARF type is used both for a thick pointer and for an ordinary array, this will have the side effect of removing the bounds from the array. This breaks the printing of objects of this type. This patch fixes the problem by copying the array type, its range, and its bounds. gdb/ChangeLog 2020-12-14 Tom Tromey * dwarf2/read.c (rewrite_array_type): New function. (quirk_ada_thick_pointer_struct): Use rewrite_array_type. gdb/testsuite/ChangeLog 2020-12-14 Tom Tromey * gdb.dwarf2/ada-thick-pointer.exp: New file. --- gdb/testsuite/ChangeLog | 4 ++ gdb/testsuite/gdb.dwarf2/ada-thick-pointer.exp | 95 ++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 gdb/testsuite/gdb.dwarf2/ada-thick-pointer.exp (limited to 'gdb/testsuite') diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index dba9292..f0d452b 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2020-12-14 Tom Tromey + * gdb.dwarf2/ada-thick-pointer.exp: New file. + +2020-12-14 Tom Tromey + * gdb.dwarf2/dw2-fixed-point.exp: Add test for division by zero. 2020-12-13 Tom de Vries diff --git a/gdb/testsuite/gdb.dwarf2/ada-thick-pointer.exp b/gdb/testsuite/gdb.dwarf2/ada-thick-pointer.exp new file mode 100644 index 0000000..7077b4c --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/ada-thick-pointer.exp @@ -0,0 +1,95 @@ +# Copyright 2020 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 . + +# Test that handling of Ada thick pointers does not rewrite other +# similar types. + +load_lib dwarf.exp + +# This test can only be run on targets which support DWARF-2 and use gas. +if {![dwarf2_support]} { + return 0 +} + +standard_testfile main.c -debug.S + +# Set up the DWARF for the test. + +set asm_file [standard_output_file $srcfile2] +Dwarf::assemble $asm_file { + global srcdir subdir srcfile + + cu {} { + DW_TAG_compile_unit { + {DW_AT_language @DW_LANG_Ada95} + {DW_AT_name $srcfile} + } { + declare_labels integer array array_pointer bounds_pointer + + integer: DW_TAG_base_type { + {DW_AT_byte_size 8 DW_FORM_sdata} + {DW_AT_encoding @DW_ATE_signed} + {DW_AT_name integer} + } + + array: DW_TAG_array_type { + {DW_AT_name array_type} + {DW_AT_type :$integer} + } { + DW_TAG_subrange_type { + {DW_AT_type :$integer} + {DW_AT_lower_bound 1 DW_FORM_data1} + {DW_AT_upper_bound 7 DW_FORM_data1} + } + } + + array_pointer: DW_TAG_pointer_type { + {DW_AT_type :$array} + {DW_AT_byte_size 8 DW_FORM_sdata} + } + + # This isn't exactly what GNAT emits, but it doesn't + # matter. + bounds_pointer: DW_TAG_pointer_type { + {DW_AT_type :$integer} + {DW_AT_byte_size 8 DW_FORM_sdata} + } + + DW_TAG_structure_type { + {DW_AT_name thick_pointer_type} + {DW_AT_byte_size 8 DW_FORM_sdata} + } { + DW_TAG_member { + {DW_AT_name P_ARRAY} + {DW_AT_type :$array_pointer} + {DW_AT_data_member_location 0 DW_FORM_sdata} + } + DW_TAG_member { + {DW_AT_name P_BOUNDS} + {DW_AT_type :$bounds_pointer} + {DW_AT_data_member_location 8 DW_FORM_sdata} + } + } + } + } +} + +if { [prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $asm_file] {nodebug}] } { + return -1 +} + +gdb_test_no_output "set language ada" +gdb_test "ptype array_type" "type = array \\(1 \\.\\. 7\\) of integer" -- cgit v1.1