[PATCH][gdb/symtab] Fix check-psymtab failure for inline function

Tom de Vries
2020-03-09T14:52:41Z

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 <tdevries@suse.de>

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 <tdevries@suse.de>

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 <http://www.gnu.org/licenses/>. */
+
+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 <http://www.gnu.org/licenses/>. */
+
+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"