public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gdb: check for empty offsets vector in inherit_abstract_dies
@ 2022-10-21 18:27 Simon Marchi
  0 siblings, 0 replies; only message in thread
From: Simon Marchi @ 2022-10-21 18:27 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f2423983a8f4b5eba77b1d8510be022d600714b6

commit f2423983a8f4b5eba77b1d8510be022d600714b6
Author: Simon Marchi <simon.marchi@polymtl.ca>
Date:   Fri Oct 21 09:08:03 2022 -0400

    gdb: check for empty offsets vector in inherit_abstract_dies
    
    When building GDB with clang and --enable-ubsan, I get:
    
      UNRESOLVED: gdb.dwarf2/frame-inlined-in-outer-frame.exp: starti prompt
    
    The cause being:
    
        $ ./gdb --data-directory=data-directory -nx -q -readnow testsuite/outputs/gdb.dwarf2/frame-inlined-in-outer-frame/frame-inlined-in-outer-frame
        Reading symbols from testsuite/outputs/gdb.dwarf2/frame-inlined-in-outer-frame/frame-inlined-in-outer-frame...
        Expanding full symbols from testsuite/outputs/gdb.dwarf2/frame-inlined-in-outer-frame/frame-inlined-in-outer-frame...
        /home/simark/src/binutils-gdb/gdb/dwarf2/read.c:11954:47: runtime error: applying non-zero offset 8 to null pointer
    
    I found this to happen with ld-linux on at least Arch Linux and Ubuntu
    22.04:
    
        $ ./gdb --data-directory=data-directory -nx -q -readnow -iex "set debuginfod enabled on" /lib64/ld-linux-x86-64.so.2
        Reading symbols from /lib64/ld-linux-x86-64.so.2...
        Reading symbols from /home/simark/.cache/debuginfod_client/22bd7a2c03d8cfc05ef7092bfae5932223189bc1/debuginfo...
        Expanding full symbols from /home/simark/.cache/debuginfod_client/22bd7a2c03d8cfc05ef7092bfae5932223189bc1/debuginfo...
        /home/simark/src/binutils-gdb/gdb/dwarf2/read.c:11954:47: runtime error: applying non-zero offset 8 to null pointer
    
    The problem happens when doing this:
    
        sect_offset *offsetp = offsets.data () + 1
    
    When `offsets` is an empty vector, `offsets.data ()` returns nullptr.
    Fix it by wrapping that in a `!offsets.empty ()` check.
    
    Change-Id: I6d29ba2fe80ba4308f68effd9c57d4ee8d67c29f
    Approved-By: Tom Tromey <tom@tromey.com>

Diff:
---
 gdb/dwarf2/read.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index cde7a5bd01f..077af064663 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -11949,17 +11949,22 @@ inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
 	corresponding_abstract_child = corresponding_abstract_child->sibling;
     }
 
-  std::sort (offsets.begin (), offsets.end ());
-  sect_offset *offsets_end = offsets.data () + offsets.size ();
-  for (sect_offset *offsetp = offsets.data () + 1;
-       offsetp < offsets_end;
-       offsetp++)
-    if (offsetp[-1] == *offsetp)
-      complaint (_("Multiple children of DIE %s refer "
-		   "to DIE %s as their abstract origin"),
-		 sect_offset_str (die->sect_off), sect_offset_str (*offsetp));
+  if (!offsets.empty ())
+    {
+      std::sort (offsets.begin (), offsets.end ());
+      sect_offset *offsets_end = offsets.data () + offsets.size ();
+      for (sect_offset *offsetp = offsets.data () + 1;
+	   offsetp < offsets_end;
+	   offsetp++)
+	if (offsetp[-1] == *offsetp)
+	  complaint (_("Multiple children of DIE %s refer "
+		       "to DIE %s as their abstract origin"),
+		     sect_offset_str (die->sect_off),
+		     sect_offset_str (*offsetp));
+    }
 
   sect_offset *offsetp = offsets.data ();
+  sect_offset *offsets_end = offsets.data () + offsets.size ();
   die_info *origin_child_die = origin_die->child;
   while (origin_child_die != nullptr && origin_child_die->tag != 0)
     {

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

only message in thread, other threads:[~2022-10-21 18:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-21 18:27 [binutils-gdb] gdb: check for empty offsets vector in inherit_abstract_dies Simon Marchi

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