public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [pushed] gdb: skip objfiles with no BFD in DWARF unwinder
@ 2022-12-08 11:52 Jan Vrany
  0 siblings, 0 replies; only message in thread
From: Jan Vrany @ 2022-12-08 11:52 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany, Simon Marchi

While playing with JIT reader I experienced GDB to crash on null-pointer
dereference when stepping through non-jitted code.

The problem was that dwarf2_frame_find_fde () assumed that all objfiles
have BFD but that's not always true. To address this problem, this
commit skips such objfiles.

To test the fix we put breakpoint in jit_function_add (). The JIT reader
does not know how unwind this function so unwinding eventually falls
back to DWARF unwinder which in turn iterates over objfiles. Since the
the code is jitted, it is guaranteed it would eventually process JIT
objfile.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
---
 gdb/dwarf2/frame.c                    |  3 +++
 gdb/objfiles.h                        |  4 +++-
 gdb/testsuite/gdb.base/jit-reader.exp | 13 +++++++++++++
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/gdb/dwarf2/frame.c b/gdb/dwarf2/frame.c
index 3f884abe1d5..54a0912ebc6 100644
--- a/gdb/dwarf2/frame.c
+++ b/gdb/dwarf2/frame.c
@@ -1560,6 +1560,9 @@ dwarf2_frame_find_fde (CORE_ADDR *pc, dwarf2_per_objfile **out_per_objfile)
       CORE_ADDR offset;
       CORE_ADDR seek_pc;
 
+      if (objfile->obfd == nullptr)
+	continue;
+
       comp_unit *unit = find_comp_unit (objfile);
       if (unit == NULL)
 	{
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 9a152cbc387..0d887ce112f 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -646,7 +646,9 @@ struct objfile
   struct compunit_symtab *compunit_symtabs = nullptr;
 
   /* The object file's BFD.  Can be null if the objfile contains only
-     minimal symbols, e.g. the run time common symbols for SunOS4.  */
+     minimal symbols (e.g. the run time common symbols for SunOS4) or
+     if the objfile is a dynamic objfile (e.g. created by JIT reader
+     API).  */
 
   gdb_bfd_ref_ptr obfd;
 
diff --git a/gdb/testsuite/gdb.base/jit-reader.exp b/gdb/testsuite/gdb.base/jit-reader.exp
index 69bf721d90a..a66896dda67 100644
--- a/gdb/testsuite/gdb.base/jit-reader.exp
+++ b/gdb/testsuite/gdb.base/jit-reader.exp
@@ -277,6 +277,19 @@ proc jit_reader_test {} {
 	    "True" \
 	    "at least one file-based objfile"
     }
+
+    with_test_prefix "test dwarf unwinder" {
+	# Check that the DWARF unwinder does not crash in presence of
+	# JIT objfiles.
+	gdb_test "up"
+	gdb_breakpoint "*function_add" temporary
+	gdb_test "cont" ".*Temporary breakpoint ${any} in jit_function_add .*"
+	gdb_test "bt" \
+	    [multi_line \
+		 "#0 ${any} in jit_function_add ${any}" \
+		 "#1 ${any} in main ${any}" \
+		]
+    }
 }
 
 jit_reader_test
-- 
2.35.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-08 11:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-08 11:52 [pushed] gdb: skip objfiles with no BFD in DWARF unwinder Jan Vrany

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