This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 0d7e5235e2a sched/misc: shrink coredump code
0d7e5235e2a is described below

commit 0d7e5235e2a791325a94f3547ece8a71e3603bfb
Author: jingfei <[email protected]>
AuthorDate: Fri Oct 16 00:09:10 2026 +0800

    sched/misc: shrink coredump code
    
    elf_emit() and elf_emit_align() are called from every part of the dump
    (headers, notes, stacks, memory). At -O2 GCC inlines them into each
    caller. Mark them noinline_function: the crash path does not need the
    speed and one copy is enough.
    
    When a single task is dumped, coredump() looks up its TCB to validate
    the PID, then the program header, note and stack passes look it up
    again. Keep the TCB in elf_dumpinfo_s and reuse it. The dump runs in
    one critical section, so the TCB stays valid.
    
    stm32f103-minimum:nsh with COREDUMP: flash -8 bytes at -Os, -208 bytes
    at -O2.
    
    Signed-off-by: jingfei <[email protected]>
---
 sched/misc/coredump.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/sched/misc/coredump.c b/sched/misc/coredump.c
index 7d89fdc6c85..b72aff10838 100644
--- a/sched/misc/coredump.c
+++ b/sched/misc/coredump.c
@@ -75,8 +75,9 @@
 struct elf_dumpinfo_s
 {
   FAR const struct memory_region_s *regions;
-  FAR struct lib_outstream_s *stream;
-  pid_t                       pid;
+  FAR struct lib_outstream_s       *stream;
+  pid_t                             pid;
+  FAR struct tcb_s                 *tcb;
 };
 
 /****************************************************************************
@@ -142,6 +143,7 @@ static int elf_flush(FAR struct elf_dumpinfo_s *cinfo)
  *
  ****************************************************************************/
 
+noinline_function
 static int elf_emit(FAR struct elf_dumpinfo_s *cinfo,
                     FAR const void *buf, size_t len)
 {
@@ -172,6 +174,7 @@ static int elf_emit(FAR struct elf_dumpinfo_s *cinfo,
  *
  ****************************************************************************/
 
+noinline_function
 static int elf_emit_align(FAR struct elf_dumpinfo_s *cinfo)
 {
   off_t align = ALIGN_UP(cinfo->stream->nput,
@@ -403,7 +406,7 @@ static void elf_emit_note(FAR struct elf_dumpinfo_s *cinfo)
     }
   else
     {
-      elf_emit_tcb_note(cinfo, nxsched_get_tcb(cinfo->pid));
+      elf_emit_tcb_note(cinfo, cinfo->tcb);
     }
 }
 
@@ -499,7 +502,7 @@ static void elf_emit_stack(FAR struct elf_dumpinfo_s *cinfo)
     }
   else
     {
-      elf_emit_tcb_stack(cinfo, nxsched_get_tcb(cinfo->pid));
+      elf_emit_tcb_stack(cinfo, cinfo->tcb);
     }
 }
 
@@ -689,8 +692,7 @@ static void elf_emit_phdr(FAR struct elf_dumpinfo_s *cinfo,
     }
   else
     {
-      elf_emit_tcb_phdr(cinfo, nxsched_get_tcb(cinfo->pid),
-                        &phdr, &offset);
+      elf_emit_tcb_phdr(cinfo, cinfo->tcb, &phdr, &offset);
     }
 
   /* Write program headers for segments dump */
@@ -1043,12 +1045,14 @@ int coredump(FAR const struct memory_region_s *regions,
   cinfo.regions = regions;
   cinfo.stream  = stream;
   cinfo.pid     = pid;
+  cinfo.tcb     = NULL;
 
   flags = enter_critical_section();
 
   if (cinfo.pid != INVALID_PROCESS_ID)
     {
-      if (nxsched_get_tcb(cinfo.pid) == NULL)
+      cinfo.tcb = nxsched_get_tcb(cinfo.pid);
+      if (cinfo.tcb == NULL)
         {
           leave_critical_section(flags);
           return -EINVAL;

Reply via email to