public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] [gdb/symtab] Handle failure to open .gnu_debugaltlink file
@ 2022-11-19 10:32 Tom de Vries
  2022-11-26 13:19 ` Tom de Vries
  0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries @ 2022-11-19 10:32 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

If we instrument cc-with-tweaks.sh to remove the .gnu_debugaltlink file after
dwz has created it, with test-case
gdb.threads/access-mem-running-thread-exit.exp and target board cc-with-dwz-m
we run into:
...
(gdb) file access-mem-running-thread-exit^M
Reading symbols from access-mem-running-thread-exit...^M
could not find '.gnu_debugaltlink' file for access-mem-running-thread-exit^M
...
followed a bit later by:
...
(gdb) file access-mem-running-thread-exit^M
Reading symbols from access-mem-running-thread-exit...^M
gdb/dwarf2/read.c:7284: internal-error: create_all_units: \
  Assertion `per_objfile->per_bfd->all_units.empty ()' failed.^M
...

The problem is that create_units does not catch the error thrown by
dwarf2_get_dwz_file.

Fix this by catching the error and performing the necessary cleanup, getting
the same result for the first and second file command.

PR symtab/29805
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29805
---
 gdb/dwarf2/read.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 60e120a9d76..53a6a8b5e6d 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -7291,7 +7291,16 @@ create_all_units (dwarf2_per_objfile *per_objfile)
 				  &per_objfile->per_bfd->abbrev, 0,
 				  types_htab, rcuh_kind::TYPE);
 
-  dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd);
+  dwz_file *dwz;
+  try
+    {
+      dwz = dwarf2_get_dwz_file (per_objfile->per_bfd);
+    }
+  catch (const gdb_exception_error &)
+    {
+      per_objfile->per_bfd->all_units.clear ();
+      throw;
+    }
   if (dwz != NULL)
     {
       /* Pre-read the sections we'll need to construct an index.  */

base-commit: 15253318be0995200cc59929ca32eedbfd041e45
-- 
2.35.3


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

* Re: [PATCH] [gdb/symtab] Handle failure to open .gnu_debugaltlink file
  2022-11-19 10:32 [PATCH] [gdb/symtab] Handle failure to open .gnu_debugaltlink file Tom de Vries
@ 2022-11-26 13:19 ` Tom de Vries
  0 siblings, 0 replies; 2+ messages in thread
From: Tom de Vries @ 2022-11-26 13:19 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

[-- Attachment #1: Type: text/plain, Size: 117 bytes --]

On 11/19/22 11:32, Tom de Vries via Gdb-patches wrote:

I've added a test-case and committed as below.

Thanks,
- Tom

[-- Attachment #2: 0001-gdb-symtab-Handle-failure-to-open-.gnu_debugaltlink-.patch --]
[-- Type: text/x-patch, Size: 3972 bytes --]

From d5bcb458a9b3150aae55ba805bc94d4450b62c63 Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Sat, 19 Nov 2022 07:44:15 +0100
Subject: [pushed] [gdb/symtab] Handle failure to open .gnu_debugaltlink file

If we instrument cc-with-tweaks.sh to remove the .gnu_debugaltlink file after
dwz has created it, with test-case
gdb.threads/access-mem-running-thread-exit.exp and target board cc-with-dwz-m
we run into:
...
(gdb) file access-mem-running-thread-exit^M
Reading symbols from access-mem-running-thread-exit...^M
could not find '.gnu_debugaltlink' file for access-mem-running-thread-exit^M
...
followed a bit later by:
...
(gdb) file access-mem-running-thread-exit^M
Reading symbols from access-mem-running-thread-exit...^M
gdb/dwarf2/read.c:7284: internal-error: create_all_units: \
  Assertion `per_objfile->per_bfd->all_units.empty ()' failed.^M
...

The problem is that create_units does not catch the error thrown by
dwarf2_get_dwz_file.

Fix this by catching the error and performing the necessary cleanup, getting
the same result for the first and second file command.

PR symtab/29805
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29805
---
 gdb/dwarf2/read.c                             | 11 ++++-
 gdb/testsuite/gdb.dwarf2/no-gnu-debuglink.exp | 48 +++++++++++++++++++
 2 files changed, 58 insertions(+), 1 deletion(-)
 create mode 100644 gdb/testsuite/gdb.dwarf2/no-gnu-debuglink.exp

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 60e120a9d76..53a6a8b5e6d 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -7291,7 +7291,16 @@ create_all_units (dwarf2_per_objfile *per_objfile)
 				  &per_objfile->per_bfd->abbrev, 0,
 				  types_htab, rcuh_kind::TYPE);
 
-  dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd);
+  dwz_file *dwz;
+  try
+    {
+      dwz = dwarf2_get_dwz_file (per_objfile->per_bfd);
+    }
+  catch (const gdb_exception_error &)
+    {
+      per_objfile->per_bfd->all_units.clear ();
+      throw;
+    }
   if (dwz != NULL)
     {
       /* Pre-read the sections we'll need to construct an index.  */
diff --git a/gdb/testsuite/gdb.dwarf2/no-gnu-debuglink.exp b/gdb/testsuite/gdb.dwarf2/no-gnu-debuglink.exp
new file mode 100644
index 00000000000..73f7233192e
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/no-gnu-debuglink.exp
@@ -0,0 +1,48 @@
+# 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/>.
+
+# Check that loading a file with a broken .gnu_debugaltlink doesn't crash gdb.
+
+load_lib dwarf.exp
+
+# This test can only be run on targets which support DWARF-2 and use gas.
+if {![dwarf2_support]} {
+    return 0
+}
+
+# No remote host testing either.
+if {[is_remote host]} {
+    return 0
+}
+
+standard_testfile main.c no-gnu-debuglink.S
+
+set asm_file [standard_output_file $srcfile2]
+
+Dwarf::assemble $asm_file {
+    gnu_debugaltlink "file-not-here" "0000000000000000000000000000000000000000"
+}
+
+if { [build_executable $testfile.exp $testfile [list $srcfile $asm_file]] } {
+    return -1
+}
+
+clean_restart
+
+set msg "\r\ncould not find '\.gnu_debugaltlink' file for \[^\r\n\]*"
+gdb_test "file $binfile" "$msg" "file command"
+
+set question "Load new symbol table from .*\? .y or n. "
+gdb_test "file $binfile" "$msg" "file command, again" $question "y"

base-commit: 14ae285f344fe76aff1d0da8366cd54599aea730
-- 
2.35.3


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

end of thread, other threads:[~2022-11-26 13:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-19 10:32 [PATCH] [gdb/symtab] Handle failure to open .gnu_debugaltlink file Tom de Vries
2022-11-26 13:19 ` Tom de Vries

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).