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

   *Note: Please adhere to [Contributing 
Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md).*
   ## Summary
   When a core dump is written on a crash there is no record of which memory 
ranges it is supposed to contain, and a wrong `CONFIG_BOARD_MEMORY_RANGE` only 
shows up as a second fault in the middle of the dump data.
   
   - **sched/coredump: add an option to print the memory regions before 
dumping**: new `CONFIG_BOARD_COREDUMP_PRINT_REGIONS` (default `n`). When 
enabled, `coredump_dump()` logs the regions from `CONFIG_BOARD_MEMORY_RANGE` 
and `coredump_add_memory_region()` before the dump is written, or `No memory 
regions defined.` when there is none. `Documentation/debugging/coredump.rst` 
mentions the option.
   - **sched/coredump: read each memory region when printing it**: the first 
and the last word of each region are read right after its `Region[n]` line, so 
a bad range faults before any dump data is written and the last log line shows 
the range.
   
   ## Impact
   - New Kconfig option `BOARD_COREDUMP_PRINT_REGIONS`, default `n`, depends on 
`COREDUMP && DEBUG_ALERT`. With the default the generated code is unchanged.
   - No API change. Only `sched/misc/coredump.c`, `boards/Kconfig` and the 
coredump documentation are touched.
   
   ## Testing
   Host: Ubuntu 22.04 x86_64, Arm GNU Toolchain 13.2.rel1, GCC 13.4.0 
aarch64-none-elf and x86_64, CMake 3.23 + Ninja. Runtime tests on QEMU 6.2 
`mps2-an500` only.
   
   Builds: `mps2-an500:nsh` (the four configurations below), `qemu-armv8a:nsh` 
with `CONFIG_COREDUMP=y CONFIG_BOARD_COREDUMP_SYSLOG=y 
CONFIG_BOARD_COREDUMP_PRINT_REGIONS=y`, and `sim:nsh`.
   
   `./tools/checkpatch.sh -c -u -m -g HEAD~2..HEAD` passes.
   
   All runs use `mps2-an500:nsh` with `CONFIG_COREDUMP=y 
CONFIG_BOARD_COREDUMP_SYSLOG=y CONFIG_NSH_DISABLE_MW=n` and crash with `mw 
0xf0000000=1` (bus fault).
   
   `CONFIG_BOARD_COREDUMP_PRINT_REGIONS=y CONFIG_ARM_COREDUMP_REGION=y` (the 
NVIC registers are the only region):
   ```
   arm_busfault: PANIC!!! Bus Fault:
   dump_assert_info: Assertion failed panic: at file: 
/arch/arm/src/armv7-m/arm_busfault.c:108 task: nsh_main process: nsh_main 
0x18d39
   ...
   coredump_print_memory_regions: Memory regions will be printed:
   coredump_print_memory_regions: Region[0] start=0xe000e000, end=0xe000f000
   coredump_dump_syslog: Start coredump:
   ...
   coredump_dump_syslog: Finish coredump. hex formatted
   ```
   
   `CONFIG_BOARD_COREDUMP_PRINT_REGIONS=y`, no region:
   ```
   coredump_print_memory_regions: No memory regions defined.
   coredump_dump_syslog: Start coredump:
   ...
   coredump_dump_syslog: Finish coredump. hex formatted
   ```
   
   `CONFIG_BOARD_COREDUMP_PRINT_REGIONS=y` and a bad second range, 
`CONFIG_BOARD_MEMORY_RANGE="{0x60000000,0x60000100,0x6},{0xf0000000,0xf0000100,0x6},{0x0,0x0,0x0}"`.
 The read of the bad range faults inside the fault handler (QEMU reports a 
lockup) right after its line:
   ```
   coredump_print_memory_regions: Memory regions will be printed:
   coredump_print_memory_regions: Region[0] start=0x60000000, end=0x60000100
   coredump_print_memory_regions: Region[1] start=0xf0000000, end=0xf0000100
   qemu: fatal: Lockup: can't escalate 3 to HardFault (current priority -1)
   ```
   
   `CONFIG_BOARD_COREDUMP_PRINT_REGIONS` not set: no region lines, the dump is 
as before:
   ```
   dump_task:       3     3 100 RR       Task    -   Running            
0000000000000000 0x60007a38      4048       976    24.1%    nsh_main
   coredump_dump_syslog: Start coredump:
   ...
   coredump_dump_syslog: Finish coredump. hex formatted
   ```
   


-- 
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