Re: GDB 15/16 crashing in add_thread_silent()

Simon Marchi via Gdb <[email protected]> Fri, 14 Nov 2025 15:03:40 -0500
Newsgroups gmane.comp.gdb.devel
Message-ID <[email protected]>

On 2025-11-14 14:38, Paul Smith wrote:
> 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?)

I agree that part seems clearly buggy, but I don't think you should
focus on that.  The problem has already happened earlier in the
execution.

Simon