diff options
author | Tom de Vries <tdevries@suse.de> | 2022-09-11 09:01:03 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2022-09-11 09:01:03 +0200 |
commit | a34a90995ae7c2f0c0b79ad32d8087d507fe42db (patch) | |
tree | 75bf74f90d3d068a2609d34fd662eaed0534742f /gdb/testsuite | |
parent | 20a64ae9cb271e0ebcea2425e57b53f6d4a0c1d8 (diff) | |
download | binutils-a34a90995ae7c2f0c0b79ad32d8087d507fe42db.zip binutils-a34a90995ae7c2f0c0b79ad32d8087d507fe42db.tar.gz binutils-a34a90995ae7c2f0c0b79ad32d8087d507fe42db.tar.bz2 |
[gdb/symtab] Fix handling of DW_TAG_unspecified_type
Currently, the test-case contained in this patch fails:
...
(gdb) p (int) foo ()^M
Invalid cast.^M
(gdb) FAIL: gdb.dwarf2/dw2-unspecified-type.exp: p (int) foo ()
...
because DW_TAG_unspecified_type is translated as void.
There's some code in read_unspecified_type that marks the type as stub, but
that's only active for ada:
...
if (cu->lang () == language_ada)
type->set_is_stub (true);
...
Fix this by:
- marking the type as a stub for all languages, and
- handling the stub return type case in call_function_by_hand_dummy.
Tested on x86_64-linux.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29558
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/gdb.dwarf2/dw2-unspecified-type-foo.c | 22 | ||||
-rw-r--r-- | gdb/testsuite/gdb.dwarf2/dw2-unspecified-type.c | 25 | ||||
-rw-r--r-- | gdb/testsuite/gdb.dwarf2/dw2-unspecified-type.exp | 72 |
3 files changed, 119 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type-foo.c b/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type-foo.c new file mode 100644 index 0000000..b1e3a8b --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type-foo.c @@ -0,0 +1,22 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2022 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/>. */ + +int +foo (void) +{ + asm ("foo_label: .globl foo_label"); +} diff --git a/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type.c b/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type.c new file mode 100644 index 0000000..e321820 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type.c @@ -0,0 +1,25 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2022 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/>. */ + +extern int foo (void); + +int +main (void) +{ + int res = foo (); + return res; +} diff --git a/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type.exp b/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type.exp new file mode 100644 index 0000000..20c31dc --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type.exp @@ -0,0 +1,72 @@ +# Copyright 2022 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 dwarf.exp + +# This test can only be run on targets which support DWARF-2 and use gas. +if {![dwarf2_support]} { + return 0 +} + +standard_testfile .c -foo.c dwz.S + +set foo_res \ + [function_range foo \ + [list ${srcdir}/${subdir}/$srcfile ${srcdir}/${subdir}/$srcfile2]] +lassign $foo_res \ + foo_start foo_len +set foo_end "$foo_start + $foo_len" + +# Create the DWARF. +set asm_file [standard_output_file $srcfile3] +Dwarf::assemble $asm_file { + global foo_start foo_end + declare_labels unspecified_type_label + + cu {} { + compile_unit { + {language @DW_LANG_Mips_Assembler} + } { + unspecified_type_label: unspecified_type {} + + DW_TAG_subprogram { + {name foo} + {low_pc $foo_start addr} + {high_pc $foo_end addr} + {type :$unspecified_type_label} + } + + } + } +} + +if [prepare_for_testing "failed to prepare" $testfile \ + "${asm_file} ${srcfile} ${srcfile2}" {}] { + return -1 +} + +if ![runto_main] { + return -1 +} + +# Print the function type. Return type should be stub type, which is printed +# as void. +gdb_test "ptype foo" "type = void \\(void\\)" + +# Call the function, casting the function to the correct function type. +gdb_test "p ((int (*) ()) foo) ()" " = 0" + +# Call the function, casting the function result to the correct type. +gdb_test "p (int) foo ()" " = 0" |