From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 2F29238582A1 for ; Thu, 8 Sep 2022 13:05:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2F29238582A1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4FA9733682; Thu, 8 Sep 2022 13:05:34 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 379071322C; Thu, 8 Sep 2022 13:05:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id RANnDJ7oGWPMMgAAMHmgww (envelope-from ); Thu, 08 Sep 2022 13:05:34 +0000 Date: Thu, 8 Sep 2022 15:05:32 +0200 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH][gdb/symtab] Fix handling of DW_TAG_unspecified_type Message-ID: <20220908130531.GA19459@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Sep 2022 13:05:38 -0000 Hi, 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 Any comments? Thanks, - Tom [gdb/symtab] Fix handling of DW_TAG_unspecified_type --- gdb/dwarf2/read.c | 6 +- gdb/infcall.c | 2 +- .../gdb.dwarf2/dw2-unspecified-type-foo.c | 22 +++++++ gdb/testsuite/gdb.dwarf2/dw2-unspecified-type.c | 25 ++++++++ gdb/testsuite/gdb.dwarf2/dw2-unspecified-type.exp | 72 ++++++++++++++++++++++ 5 files changed, 123 insertions(+), 4 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 3ca441c4cae..da99402cff0 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -17714,9 +17714,9 @@ read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) /* In Ada, an unspecified type is typically used when the description of the type is deferred to a different unit. When encountering such a type, we treat it as a stub, and try to resolve it later on, - when needed. */ - if (cu->lang () == language_ada) - type->set_is_stub (true); + when needed. + Mark this as a stub type for all languages though. */ + type->set_is_stub (true); return set_die_type (die, type, cu); } diff --git a/gdb/infcall.c b/gdb/infcall.c index 2acceed4b07..dd70682bc76 100644 --- a/gdb/infcall.c +++ b/gdb/infcall.c @@ -814,7 +814,7 @@ call_function_by_hand_dummy (struct value *function, "target calling convention."), get_function_name (funaddr, name_buf, sizeof (name_buf))); - if (values_type == NULL) + if (values_type == NULL || values_type->is_stub ()) values_type = default_return_type; if (values_type == NULL) { 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 00000000000..b1e3a8b98e4 --- /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 . */ + +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 00000000000..e3218205560 --- /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 . */ + +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 00000000000..20c31dc5740 --- /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 . + +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"