public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH][gdb/symtab] Fix check-psymtab failure for inline function
@ 2020-03-09 14:52 Tom de Vries
  2020-03-11  0:08 ` Tom Tromey
  0 siblings, 1 reply; 8+ messages in thread
From: Tom de Vries @ 2020-03-09 14:52 UTC (permalink / raw)
  To: gdb-patches

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"

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-04-06 20:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-09 14:52 [PATCH][gdb/symtab] Fix check-psymtab failure for inline function Tom de Vries
2020-03-11  0:08 ` Tom Tromey
2020-03-18 13:48   ` [committed][gdb/testsuite] Add test-case gdb.dwarf2/break-inline-psymtab.exp Tom de Vries
2020-04-02 14:24     ` Pedro Alves
2020-04-02 15:14       ` Tom de Vries
2020-03-18 15:58   ` [PATCH][gdb/symtab] Fix check-psymtab failure for inline function Tom de Vries
2020-04-02  8:46     ` [PING][PATCH][gdb/symtab] " Tom de Vries
2020-04-06 20:40     ` [PATCH][gdb/symtab] " Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).