Bug 28740 - Internal error: internal_type_vptr_fieldno() crashes
Summary: Internal error: internal_type_vptr_fieldno() crashes
Status: NEW
Alias: None
Product: gdb
Classification: Unclassified
Component: c++ (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-01-03 10:02 UTC by smurf
Modified: 2022-01-05 06:38 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2022-01-03 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description smurf 2022-01-03 10:02:38 UTC
I managed to build a shared library (C++) which aborts GDB in function internal_type_vptr_fieldno().

Debian Bullseye:

/build/gdb-Nav6Es/gdb-10.1/gdb/gdbtypes.c:1926: internal-error: int internal_type_vptr_fieldno(type*): Assertion `type->code () == TYPE_CODE_STRUCT || type->code () == TYPE_CODE_UNION' failed.

To reproduce:

Fetch, build and install https://github.com/smurfix/clew.git

Fetch https://github.com/smurfix/kf2.git
check out commit ed25cacee

apt install $(grep -v '#' REQUIREMENTS)
make embed -j20  # more CPUs are better …
gdb libkf2-embed.so
b CFr<Tab>St<Tab>

which should find method CFraktalSFT::Stop() but instead emits the above error.

I have verified that the bug exists in current HEAD. Replacing the gdb_abort in internal_type_vptr_fieldno (with a test that returns -1 instead of crashing) "fixes" the problem and at first glance does not show any adverse effects.

I have not been able to create a smaller standalone example. (Admittedly I didn't try very hard.)

I cannot attach the shared library in question because it's 155 MBytes large, but if anybody needs it I can supply a download link.
Comment 1 smurf 2022-01-03 10:06:43 UTC
The library is here:

https://storgrid.noris.net/share.xhtml?token=L44e42cf1a7d347d296beb6f062ea6d8c

I compressed it with lz4, now "only" 55 MByte.
Comment 2 Andrew Burgess 2022-01-03 11:05:40 UTC
Using the pre-compiled library, I can reproduce the original error.  I also observed this weird behaviour:

  (gdb) set max-value-size 200000
  (gdb) ptype CFraktalSFT
  type = struct CFraktalSFT {
    <snip lots of fields>
  gdb/gdbtypes.c:932: internal-error: type* create_range_type(type*, type*, const dynamic_prop*, const dynamic_prop*, LONGEST): Assertion `TYPE_LENGTH (index_type) > 0' failed.

Clearly a different error, but there's something odd about CFraktalSFT...
Comment 3 Tom Tromey 2022-01-04 18:28:54 UTC
I think the problem is just that this is compiled with stabs and not DWARF:

murgatroyd. readelf -WS ./libkf2-embed.so | grep debug
murgatroyd. readelf -WS ./libkf2-embed.so | grep stab
  [26] .stab             PROGBITS        0000000000000000 617c300 2ed14ec 0c     27   0  4
  [27] .stabstr          STRTAB          0000000000000000 904d7ec 9382c3 00      0   0  1


The Makefile specifies -gstabs:

https://github.com/smurfix/kf2/blame/main/Makefile#L30

To the OP: stabs is an old, deprecated debug format.  It never supported
C++ very well, and is only kept around because there are a couple of
legacy C programs that use it.  Eventually we hope to remove it entirely.

You should basically never use -gstabs.  Use plain -g instead.
Comment 4 smurf 2022-01-05 06:38:33 UTC
Ah. Thanks.

Ancient Makefiles building Windows binaries with mingw … among its myriad of flags I missed that one, cleaning it up for transplanting to Linux.

Still, it'd be nice not to crash gdb when it encounters something like that.