XuNeo opened a new pull request, #20375:
URL: https://github.com/apache/nuttx/pull/20375

   ## Summary
   
   Coredump mode and extra memory ranges were fixed by Kconfig, so they
   could not be changed at runtime.
   
   Add `/proc/coredump` to control them at runtime. It supports:
   
   ```text
   off                // coredump at all
   current        // dump current thread information together with additional 
memory added
   all                // dump all thread information together with additional 
memory added
   range clear // clean all memory range
   range add {start,end,flags} // add one memory range to coredump, merge with 
existing ranges.
   range set {start,end,flags}[,{start,end,flags}...] // clear and set memory 
range
   ```
   
   The Kconfig values are still used as boot defaults, so it's a compatible 
change. 
   `coredump_dump()` takes a snapshot of the runtime configuration before 
generating the dump.
   A single write can contain multiple newline-separated commands, so we can 
store a conf file and change freely.
   E.g.
   
   ```
   cat /data/coredump-core0.conf > /proc/coredump
   ```
   
   ## Impact
   
   No behavior change unless `CONFIG_COREDUMP` and `CONFIG_FS_PROCFS` are
   enabled. The `/proc/coredump` node can be disabled with
   `CONFIG_FS_PROCFS_EXCLUDE_COREDUMP`.
   
   This only changes crash dumps generated through `coredump_dump()`. The
   userspace `coredump` command still calls `coredump()` directly and is not
   affected.
   
   ## Testing
   
   Host: Ubuntu 22.04.5 x86_64
   
   Board: `mps3-an547:nsh` on QEMU 6.2.0
   
   Config:
   
   ```diff
   # CONFIG_NSH_DISABLE_MW is not set
   CONFIG_ARCH="arm"
   CONFIG_ARCH_BOARD="mps3-an547"
   CONFIG_ARCH_BOARD_MPS3_AN547=y
        @@ -15,6 +16,7 @@ CONFIG_ARCH_CHIP_MPS=y
   CONFIG_ARCH_INTERRUPTSTACK=2048
   CONFIG_ARCH_STACKDUMP=y
   CONFIG_ARMV8M_SYSTICK=y
   CONFIG_BOARD_COREDUMP_SYSLOG=y
   CONFIG_BUILTIN=y
   CONFIG_CMSDK_UART0=y
   CONFIG_CMSDK_UART0_BASE=0x49303000
        @@ -24,6 +26,7 @@ CONFIG_CMSDK_UART0_RX_IRQ=50
   CONFIG_CMSDK_UART0_SERIAL_CONSOLE=y
   CONFIG_CMSDK_UART0_TX_IRQ=49
   CONFIG_CMSDK_UART=y
   CONFIG_COREDUMP=y
   ```
   
   Build:
   
   ```console
   cmake -S nuttx -B build-mps3-coredump -G Ninja \
     -DBOARD_CONFIG=mps3-an547:nsh \
     -DNUTTX_APPS_DIR=/home/neo/projects/nuttx/apps
   ninja -C build-mps3-coredump
   ```
   
   Build result:
   
   ```text
   Memory region         Used Size  Region Size  %age Used
              flash:      339060 B       512 KB     64.67%
              sram1:       16256 B         2 MB      0.78%
              sram2:           0 B         2 MB      0.00%
   ```
   
   Run:
   
   ```console
   qemu-system-arm -M mps3-an547 -nographic \
     -kernel build-mps3-coredump/nuttx.bin
   ```
   
   Read and update the configuration:
   
   ```text
   nsh> cat /proc/coredump
   mode: all
   range:
     none
   
   nsh> echo current > /proc/coredump
   nsh> cat /proc/coredump
   mode: current
   range:
     none
   ```
   
   Verified multiple commands in one write and range merging:
   
   ```text
   nsh> echo "range set {0x01000000,0x01000020,0x7}" > /tmp/cmd
   nsh> echo "range add {0x01000040,0x01000060,0x7}" >> /tmp/cmd
   nsh> echo current >> /tmp/cmd
   nsh> cat /tmp/cmd > /proc/coredump
   nsh> echo "range add {0x01000010,0x01000050,0x7}" > /proc/coredump
   nsh> cat /proc/coredump
   mode: current
   range:
     {0x1000000,0x1000060,0x7}
   ```
   
   Used `mw ffffffff=1` to trigger a BusFault.
   
   With mode `off`:
   
   ```text
   coredump_select_dump_scope: Coredump skipped: runtime mode off
   ```
   
   With mode `current` and `all`:
   
   ```text
   coredump_dump_syslog: Start coredump:
   coredump_dump_syslog: Finish coredump. hex formatted
   ```
   
   Converted the logs with `tools/coredump.py` and checked them with
   `arm-none-eabi-readelf`:
   
   ```text
   current NT_PRSTATUS=1
   all NT_PRSTATUS=4
   LOAD  0x002400 0x01000000 0x01000000 0x00040 0x00040 RWE 0x400
   ```
   
   This verifies the dump scope and the extra memory range in the generated
   ELF core.
   
   `git diff --check`, `checkpatch.sh`, and the CMake/Ninja build passed.
   
   
   full log:
   
   
[pr-coredump-runtime-test.log](https://github.com/user-attachments/files/32680978/pr-coredump-runtime-test.log)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to