From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id CFECF394CC28 for ; Mon, 9 Mar 2020 14:52:41 +0000 (GMT) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id B197BB297 for ; Mon, 9 Mar 2020 14:52:40 +0000 (UTC) Date: Mon, 9 Mar 2020 15:52:39 +0100 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH][gdb/symtab] Fix check-psymtab failure for inline function Message-ID: <20200309145237.GA20334@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=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Mon, 09 Mar 2020 14:52:43 -0000 Hi, Consider test-case inline.c, containing an inline function foo: ... static inline int foo (void) { return 0; } int main (void) { return foo (); } ... And the test-case compiled with -O2 and debug info: ... $ gcc -g inline.c -O2 ... This results in a DWARF entry for foo without pc info: ... <1><114>: Abbrev Number: 4 (DW_TAG_subprogram) <115> DW_AT_name : foo <119> DW_AT_decl_file : 1 <11a> DW_AT_decl_line : 2 <11b> DW_AT_prototyped : 1 <11b> DW_AT_type : <0x10d> <11f> DW_AT_inline : 3 (declared as inline and inlined) ... When loading the executable in gdb, we create a partial symbol for foo, but after expansion into a full symbol table no actual symbol is created, resulting in a maint check-psymtab failure: ... (gdb) maint check-psymtab Static symbol `foo' only found in inline.c psymtab ... Fix this by preventing the creation of this type of partial symbol. Build and reg-tested on x86_64-linux, native and with target board cc-with-dwz. This fixes the only remaining native vs cc-with-dwz regression: ... FAIL: gdb.ada/maint_with_ada.exp: maintenance check-psymtabs ... OK for trunk? Thanks, - Tom [gdb/symtab] Fix check-psymtab failure for inline function gdb/ChangeLog: 2020-03-09 Tom de Vries PR symtab/25256 * dwarf2/read.c (add_partial_subprogram): Don't create partial symbol without pc info. gdb/testsuite/ChangeLog: 2020-03-09 Tom de Vries PR symtab/25256 * gdb.base/check-psymtab.c: New test. * gdb.base/check-psymtab.exp: New file. --- gdb/dwarf2/read.c | 2 +- gdb/testsuite/gdb.base/check-psymtab.c | 28 ++++++++++++++++++++++++++++ gdb/testsuite/gdb.base/check-psymtab.exp | 27 +++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 1d4397dfab..299f532088 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -8445,7 +8445,7 @@ add_partial_subprogram (struct partial_die_info *pdi, } } - if (pdi->has_pc_info || (!pdi->is_external && pdi->may_be_inlined)) + if (pdi->has_pc_info) { if (!pdi->is_declaration) /* Ignore subprogram DIEs that do not have a name, they are diff --git a/gdb/testsuite/gdb.base/check-psymtab.c b/gdb/testsuite/gdb.base/check-psymtab.c new file mode 100644 index 0000000000..2c1e69955e --- /dev/null +++ b/gdb/testsuite/gdb.base/check-psymtab.c @@ -0,0 +1,28 @@ +/* This testcase is part of GDB, the GNU debugger. + + 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 . */ + +static inline int +foo (void) +{ + return 0; +} + +int +main (void) +{ + return foo (); +} diff --git a/gdb/testsuite/gdb.base/check-psymtab.exp b/gdb/testsuite/gdb.base/check-psymtab.exp new file mode 100644 index 0000000000..06438fc7c0 --- /dev/null +++ b/gdb/testsuite/gdb.base/check-psymtab.exp @@ -0,0 +1,27 @@ +# 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 . */ + +standard_testfile + +if {[prepare_for_testing "failed to prepare" $testfile $srcfile \ + {debug optimize=-O2}]} { + return -1 +} + +gdb_test_no_output "maint expand-symtabs" + +# Check that we don't get: +# Static symbol `foo' only found in check-psymtab.c psymtab +gdb_test_no_output "maint check-psymtab"