Re: GDB 15/16 crashing in add_thread_silent()

Paul Smith via Gdb <[email protected]> Mon, 24 Nov 2025 10:19:17 -0500
Newsgroups gmane.comp.gdb.devel
Organization GNU's Not UNIX!
Message-ID <[email protected]>
On Fri, 2025-11-21 at 12:59 +0100, Tom de Vries wrote:
> On 11/14/25 8:38 PM, Paul Smith via Gdb wrote:
> > However, if I use the native GDB 8.2 that comes with Rocky Linux,
> > then
> > it will open the core file without these errors, and even show me
> > the
> > backtrace for all threads.
> 
> An interesting thing to know here would be the size of the PRSTATUS
> note:
> ...
> $ eu-readelf -n core | grep -i prstatus
>    CORE                 336  PRSTATUS
> $ readelf -n core | grep -i prstatus
>    CORE                 0x00000150 NT_PRSTATUS (prstatus structure)
> ...
> 
> AFAIU, the note should be grokked by elf_x86_64_grok_prstatus, which 
> bails out unless the size is either 296 (x32 abi) or 336.

I did have some time to look at this over the weekend, but not as much
as I'd like so I don't have too much to share.  I did find a few
interesting things.

First, thank you Tom for your message that was extremely enlightening.
I discovered that yes indeed for this core the PRSTATUS note size is
not as expected:

  $ readelf -n core | grep -i prstatus | sort -u
    CORE                 0x00000188       NT_PRSTATUS (prstatus structure)

If I look at some other cores (generated from different systems) that
work with unpatched GDB I see that the size for those is as expected
(0x150).  So, that's suspicious at least.

Based on your email I decided to first build a vanilla GDB 8.2 and try
that.  It failed in the same way as the latest GDB (minus the bug
regarding the incorrect PID value that causes GDB to crash):

  warning: Couldn't find general-purpose registers in core file.

  warning: Unexpected size of section `.reg2' in core file.
  Cannot access memory at address 0x8ab31264
  Cannot access memory at address 0x8ab31260
  Core was generated by `myprog'.

  warning: Couldn't find general-purpose registers in core file.

  warning: Unexpected size of section `.reg2' in core file.
  #0  <unavailable> in ?? ()
  (gdb) bt
  #0  <unavailable> in ?? ()
  Backtrace stopped: not enough registers or memory available to unwind further

So, this implies there's some fix added by Red Hat that is needed, for
at least some kernels, but has not been upstreamed for some reason.

I then tried to apply the patches by hand (there are about 200 patches)
but this didn't work well.  So I used the Red Hat rpmbuild tool to
generate a GDB 8.2 fully patched and built the same way as the Red Hat
/bin/gdb.

The GDB binary created by rpmbuild worked just as well as /bin/gdb, so
that's good!

I did grep the 200 patches and didn't find any patches obviously
related to prstatus or grok: there are some "grok" patches
adding/updating support for PPC and ARM but I didn't see anything for
Intel/AMD (but could well have missed it).

Unfortunately I ran out of time here.

My next steps are to investigate the configure options used when
compiling the RedHat /bin/gdb, and compare the source code as one big
diff rather than 200 small diffs.