Re: GDB 15/16 crashing in add_thread_silent()
Paul Smith via Gdb <[email protected]> Fri, 14 Nov 2025 14:38:37 -0500
| Newsgroups | gmane.comp.gdb.devel |
|---|---|
| Organization | GNU's Not UNIX! |
| Message-ID | <[email protected]> |
On Fri, 2025-11-14 at 14:25 -0500, Simon Marchi wrote:
> If your core is threaded, you shouldn't get to that fallback "if" at
> all. This is where GDB should add all your threads:
>
> /* Build up thread list from BFD sections, and possibly set the
> current thread to the .reg/NN section matching the .reg
> section. */
> asection *reg_sect
> = bfd_get_section_by_name (current_program_space->core_bfd (), ".reg");
> for (asection *sect : gdb_bfd_sections (current_program_space->core_bfd ()))
> add_to_thread_list (sect, reg_sect, inf);
>
> If this doesn't add any threads, then you need to dig to understand
> why BFD doesn't create the .reg pseudo sections.
I applied this patch, which I think is correct:
--- a/gdb/corelow.c 2025-04-20 13:22:05.000000000 -0400
+++ b/gdb/corelow.c 2025-11-14 14:17:57.220145722 -0500
@@ -1120,7 +1120,7 @@
thread_info *thread = first_thread_of_inferior (inf);
if (thread == NULL)
- thread = add_thread_silent (target, ptid_t (CORELOW_PID));
+ thread = add_thread_silent (target, ptid_t (pid));
switch_to_thread (thread);
}
Earlier if the PID couldn't be found then pid is set to CORELOW_PID
anyway, so this works and prevents the crash (although, I think GDB
should check for the nullptr return and do _something_ non-crashy...
maybe?)
After preventing the crash I get these errors which seem to align with
your diagnosis:
warning: Couldn't find general-purpose registers in core file.
warning: Unexpected size of section `.reg2' in core file.
Cannot access memory at address 0x84a21264
Cannot access memory at address 0x84a21260
Cannot access memory at address 0x84a21260
Core was generated by `myprogram'.
warning: Couldn't find general-purpose registers in core file.
warning: Unexpected size of section `.reg2' in core file.
and the core is unusable:
(gdb) bt
#0 <unavailable> in ?? ()
Backtrace stopped: not enough registers or memory available to unwind further
(gdb) thr a a bt
Thread 1 (process 9168):
#0 <unavailable> in ?? ()
Backtrace stopped: not enough registers or memory available to unwind further
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.