gdb: check for empty offsets vector in inherit_abstract_dies
authorSimon Marchi <simon.marchi@polymtl.ca>
Fri, 21 Oct 2022 13:08:03 +0000 (09:08 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Fri, 21 Oct 2022 18:26:58 +0000 (14:26 -0400)
commitf2423983a8f4b5eba77b1d8510be022d600714b6
treede66d55ef708fe7dafe58734062dac82fa41c0b5
parent1f5a3546126b47fd3b7a5fbc4ec5fad1397b726b
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>
gdb/dwarf2/read.c