gdb: remove assertion in psymbol_functions::expand_symtabs_matching
authorSimon Marchi <simon.marchi@polymtl.ca>
Thu, 31 Mar 2022 20:38:33 +0000 (16:38 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Mon, 4 Apr 2022 21:48:54 +0000 (17:48 -0400)
commitcb25fdbb76e41d9c02fe86009fc8a3ecf8737c9a
treeb28d904b155e5336b729dd400b2d2d26fea896f4
parent7b01c1cc1d111ba0afa51e60fa9842d3b971e2d1
gdb: remove assertion in psymbol_functions::expand_symtabs_matching

psymtab_to_symtab is documented as possibly returning nullptr, if the
primary symtab of the partial symtab has no symbols.  However,
psymbol_functions::expand_symtabs_matching asserts that the result of
psymtab_to_symtab as non-nullptr.

I caught this assert by trying the CTF symbol reader on a library I
built with -gctf:

    $ ./gdb --data-directory=data-directory /tmp/babeltrace-ctf/src/lib/.libs/libbabeltrace2.so.0.0.0
    ...
    Reading symbols from /tmp/babeltrace-ctf/src/lib/.libs/libbabeltrace2.so.0.0.0...
    (gdb) maintenance expand-symtabs
    /home/simark/src/binutils-gdb/gdb/psymtab.c:1142: internal-error: expand_symtabs_matching: Assertion `symtab != nullptr' failed.

The "symtab" in question is:

    $  readelf --ctf=.ctf /tmp/babeltrace-ctf/src/lib/.libs/libbabeltrace2.so.0.0.0
    ...
    CTF archive member: /home/simark/src/babeltrace/src/lib/graph/component-descriptor-set.c:

      Header:
        Magic number: 0xdff2
        Version: 4 (CTF_VERSION_3)
        Flags: 0xe (CTF_F_NEWFUNCINFO, CTF_F_IDXSORTED, CTF_F_DYNSTR)
        Parent name: .ctf
        Compilation unit name: /home/simark/src/babeltrace/src/lib/graph/component-descriptor-set.c
        Type section:       0x0 -- 0x13 (0x14 bytes)
        String section:     0x14 -- 0x5f (0x4c bytes)

      Labels:

      Data objects:

      Function objects:

      Variables:

      Types:
        0x80000001: (kind 5) bt_bool (*) (const bt_value *) (aligned at 0x8)

      Strings:
        0x0:
        0x1: .ctf
        0x6: /home/simark/src/babeltrace/src/lib/graph/component-descriptor-set.c

It contains a single type, and it is skipped by ctf_add_type_cb, because
an identical type was already seen earlier in this objfile.  As a
result, no compunit_symtab is created.

Change psymbol_functions::expand_symtabs_matching to expect that
psymtab_to_symtab can return nullptr.

Another possibility would be to make the CTF symbol reader always create
a compunit_symtab, even if there are no symbols in it (like the DWARF
parser does), but so far I don't see any advantage in doing so.

Change-Id: Ic43c38202c838a5eb87630ed1fd61d33528164f4
gdb/psymtab.c