diff options
author | Tom Tromey <tromey@adacore.com> | 2019-04-09 07:46:39 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2019-04-19 13:23:05 -0600 |
commit | 8ecb59f8567956c1520b491ea31396363efcb1ef (patch) | |
tree | f0e0de7b531df940914dadf2d8a9df74fd079498 /gdb/testsuite | |
parent | 62160ec9547cdd21ac7334d9a378ca2930aac61c (diff) | |
download | gdb-8ecb59f8567956c1520b491ea31396363efcb1ef.zip gdb-8ecb59f8567956c1520b491ea31396363efcb1ef.tar.gz gdb-8ecb59f8567956c1520b491ea31396363efcb1ef.tar.bz2 |
Print non-Ada unions without crashing
ada-lang.c is a bit too eager trying to decode unions in the Ada style
-- looking for discriminants and such. This causes crashes when
printing a non-Ada union in Ada mode, something that can easily happen
when printing a value from history or certain registers on AArch64.
This patch fixes the bug by changing ada-lang.c to only apply special
Ada treatment to types coming from an Ada CU. This in turn required a
couple of surprising changes.
First, some of the Ada code was already using HAVE_GNAT_AUX_INFO to
decide whether a type had already been fixed -- such types had
INIT_CPLUS_SPECIFIC called on them. This patch changes these spots to
use the "none" identifier instead.
This then required changing value_rtti_type to avoid changing the
language-specific object attached to an Ada type, which seems like a
good change regardless.
Tested on x86-64 Fedora 29.
gdb/ChangeLog
2019-04-19 Tom Tromey <tromey@adacore.com>
* ada-lang.c (ada_is_variant_part, ada_to_fixed_type_1):
Check ADA_TYPE_P.
(empty_record, ada_template_to_fixed_record_type_1)
(template_to_static_fixed_type)
(to_record_with_fixed_variant_part): Use INIT_NONE_SPECIFIC.
* cp-abi.c (value_rtti_type): Check HAVE_CPLUS_STRUCT.
* gdbtypes.h (INIT_NONE_SPECIFIC, ADA_TYPE_P): New
macros.
gdb/testsuite/ChangeLog
2019-04-19 Tom Tromey <tromey@adacore.com>
* gdb.ada/ptype_union.c: New file.
* gdb.ada/ptype_union.exp: New file.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/testsuite/gdb.ada/ptype_union.c | 41 | ||||
-rw-r--r-- | gdb/testsuite/gdb.ada/ptype_union.exp | 34 |
3 files changed, 80 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 89058f4..aaa110c 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2019-04-19 Tom Tromey <tromey@adacore.com> + * gdb.ada/ptype_union.c: New file. + * gdb.ada/ptype_union.exp: New file. + +2019-04-19 Tom Tromey <tromey@adacore.com> + PR symtab/24423: * gdb.base/list0.h (foo): Add a control-l character. diff --git a/gdb/testsuite/gdb.ada/ptype_union.c b/gdb/testsuite/gdb.ada/ptype_union.c new file mode 100644 index 0000000..eef9c5a --- /dev/null +++ b/gdb/testsuite/gdb.ada/ptype_union.c @@ -0,0 +1,41 @@ +/* This test program is part of GDB, the GNU debugger. + + Copyright 2019 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/>. */ + +union a +{ + int l; + double m; +}; + +union b +{ + char *n; + float o; +}; + +struct s +{ + union a af; + union b bf; +}; + +struct s global; + +int main () +{ + return 0; +} diff --git a/gdb/testsuite/gdb.ada/ptype_union.exp b/gdb/testsuite/gdb.ada/ptype_union.exp new file mode 100644 index 0000000..4f33721 --- /dev/null +++ b/gdb/testsuite/gdb.ada/ptype_union.exp @@ -0,0 +1,34 @@ +# Copyright 2019 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/>. + +standard_testfile .c + +if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile}]} { + return -1 +} + +# The test case is written in C, because it was easy to make the +# required type there; but the bug itself only happens in Ada. +gdb_test "set lang ada" "" + +gdb_test "ptype global" \ + [multi_line \ + "type = record" \ + "\[ \t\]*af: a;" \ + "\[ \t\]*bf: b;" \ + "end record"] + +gdb_test "print global" \ + " = \\(af => \\(l => 0, m => 0.0\\), bf => \\(n => 0x0, o => 0.0\\)\\)" |