From: Simon Marchi via Gdb <gdb@sourceware.org>
To: psmith@gnu.org, gdb@sourceware.org
Subject: Re: GDB 15/16 crashing in add_thread_silent()
Date: Fri, 14 Nov 2025 14:25:37 -0500 [thread overview]
Message-ID: <a4e84585-5ed2-488f-8aa1-9ced39601225@simark.ca> (raw)
In-Reply-To: <78bf54fc9dfbb57d3434d8435e94b091e1fa6785.camel@gnu.org>
On 2025-11-14 14:20, Paul Smith via Gdb wrote:
> I investigated more and the problem is that GDB cannot determine the
> PID of the core file. I checked the inferiors list and it looks
> correct, but the ptid value passed into add_thread_silent() has a bad
> PID:
>
> (gdb) fr 8
> #8 0x00000000013817cd in add_thread_silent (targ=0x3ed1ae0, ptid=...)
> at gdb/thread.c:311
> warning: 311 gdb/thread.c: No such file or directory
> (gdb) p ptid
> $6 = {
> m_pid = 1,
> m_lwp = 0,
> m_tid = 0
> }
>
> This is apparently because we entered this code in corelow.c:
>
> if (inferior_ptid == null_ptid)
> {
> /* Either we found no .reg/NN section, and hence we have a
> non-threaded core (single-threaded, from gdb's perspective),
> or for some reason add_to_thread_list couldn't determine
> which was the "main" thread. The latter case shouldn't
> usually happen, but we're dealing with input here, which can
> always be broken in different ways. */
> thread_info *thread = first_thread_of_inferior (inf);
>
> if (thread == NULL)
> thread = add_thread_silent (target, ptid_t (CORELOW_PID));
>
> switch_to_thread (thread);
> }
>
> It appears that add_thread_silent() doesn't work properly with
> CORELOW_PID (1).
>
> Just to note, my program is decidedly NOT single-threaded; there are
> 20+ active threads in it.
>
> I see that this (still in corelow.c:core_target_open()) returns the
> correct PID:
>
> int pid = bfd_core_file_pid (current_program_space->core_bfd ());
>
> so I think it's a bug that when we invoke add_thread_silent() above we
> use CORELOW_PID instead of just pid.
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.
Simon
next prev parent reply other threads:[~2025-11-14 19:26 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-14 18:56 Paul Smith via Gdb
2025-11-14 19:12 ` Simon Marchi via Gdb
2025-11-14 19:20 ` Paul Smith via Gdb
2025-11-14 19:25 ` Simon Marchi via Gdb [this message]
2025-11-14 19:38 ` Paul Smith via Gdb
2025-11-14 20:03 ` Simon Marchi via Gdb
2025-11-14 20:13 ` Tom Tromey
2025-11-14 20:29 ` Paul Smith via Gdb
2025-11-14 20:42 ` Paul Smith via Gdb
2025-11-18 18:33 ` Tom Tromey
2025-11-18 19:30 ` Paul Smith via Gdb
2025-11-18 20:24 ` Simon Marchi via Gdb
2025-11-24 16:36 ` Paul Smith via Gdb
2025-11-21 11:59 ` Tom de Vries via Gdb
2025-11-24 15:19 ` Paul Smith via Gdb
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a4e84585-5ed2-488f-8aa1-9ced39601225@simark.ca \
--to=gdb@sourceware.org \
--cc=psmith@gnu.org \
--cc=simark@simark.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox