sched/misc: Optimize thread saving order in coredump for easier gdb debug

When GDB opens a coredump file, it first selects a "current thread",
and the bt command by default only performs backtracing on this current
thread. When there is no dedicated "crash thread marker" for this current
thread in NuttX's coredump.elf, it usually degenerates to
"the first thread parsed in the core file".

Signed-off-by: zhanxiaoqi <zhanxiaoqi@bytedance.com>
This commit is contained in:
zhanxiaoqi
2026-04-14 15:06:49 +08:00
committed by Xiang Xiao
parent ba6a4d55fe
commit 29114efb41
+29 -3
View File
@@ -368,9 +368,21 @@ static void elf_emit_note(FAR struct elf_dumpinfo_s *cinfo)
if (cinfo->pid == INVALID_PROCESS_ID)
{
FAR struct tcb_s *rtcb = running_task();
/* Emit the current (typically crashing) task first so that GDB's
* default thread selection shows the crashing backtrace on the initial
* `bt`.
*/
if (rtcb != NULL)
{
elf_emit_tcb_note(cinfo, rtcb);
}
for (i = 0; i < g_npidhash; i++)
{
if (g_pidhash[i] != NULL)
if (g_pidhash[i] != NULL && g_pidhash[i] != rtcb)
{
elf_emit_tcb_note(cinfo, g_pidhash[i]);
}
@@ -457,9 +469,16 @@ static void elf_emit_stack(FAR struct elf_dumpinfo_s *cinfo)
if (cinfo->pid == INVALID_PROCESS_ID)
{
FAR struct tcb_s *rtcb = running_task();
if (rtcb != NULL)
{
elf_emit_tcb_stack(cinfo, rtcb);
}
for (i = 0; i < g_npidhash; i++)
{
if (g_pidhash[i] != NULL)
if (g_pidhash[i] != NULL && g_pidhash[i] != rtcb)
{
elf_emit_tcb_stack(cinfo, g_pidhash[i]);
}
@@ -640,9 +659,16 @@ static void elf_emit_phdr(FAR struct elf_dumpinfo_s *cinfo,
phdr.p_align = ELF_PAGESIZE;
if (cinfo->pid == INVALID_PROCESS_ID)
{
FAR struct tcb_s *rtcb = running_task();
if (rtcb != NULL)
{
elf_emit_tcb_phdr(cinfo, rtcb, &phdr, &offset);
}
for (i = 0; i < g_npidhash; i++)
{
if (g_pidhash[i] != NULL)
if (g_pidhash[i] != NULL && g_pidhash[i] != rtcb)
{
elf_emit_tcb_phdr(cinfo, g_pidhash[i], &phdr, &offset);
}