From: Simon Marchi <simon.marchi@polymtl.ca>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/2] gdb: check for empty offsets vector in inherit_abstract_dies
Date: Fri, 21 Oct 2022 09:21:03 -0400 [thread overview]
Message-ID: <20221021132104.1772565-1-simon.marchi@polymtl.ca> (raw)
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
---
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 89ba9122e910..bf52354c4260 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)
{
base-commit: 75436c534bfd7f548a13b5f926c3bd234b23b8d0
--
2.38.0
next reply other threads:[~2022-10-21 13:21 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-21 13:21 Simon Marchi [this message]
2022-10-21 13:21 ` [PATCH 2/2] gdb: make inherit_abstract_dies use vector iterators Simon Marchi
2022-10-21 18:04 ` Tom Tromey
2022-10-21 18:04 ` Tom Tromey
2022-10-21 18:26 ` Simon Marchi
2022-10-21 15:35 ` [PATCH 1/2] gdb: check for empty offsets vector in inherit_abstract_dies Tom Tromey
2022-10-21 15:35 ` Tom Tromey
2022-10-21 15:46 ` Simon Marchi
2022-10-21 18:02 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221021132104.1772565-1-simon.marchi@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).