CV-Bowen opened a new pull request, #22073:
URL: https://github.com/apache/nuttx/pull/22073
## Summary
Two small fixes in `sched/misc`, independent of each other.
- `coredump: do not dump non-writeable memory segment`: `elf_emit_memory()`
wrote every region of the core file, including the read-only ones (text,
rodata). A debugger cannot use their contents to change state, and on a
small target they can be most of the file. Only the writeable segments
are needed to reconstruct what the crashed task could modify.
`PF_REGISTER` regions are handled before this point and are unaffected.
- `sched/assert: add CONFIG_SCHED_DUMP_FDLIST for fd list dump`: the fd
list dump in `_assert()` was tied to `CONFIG_SCHED_DUMP_ON_EXIT`, so a
board that wanted the task dump always got the fd dump as well. The fd
dump now has its own switch.
## Impact
- Core files no longer carry the read-only segments; on the `sabre-6quad`
probe below that is 40% of the file removed.
- `CONFIG_SCHED_DUMP_FDLIST` is new and defaults to `n`. A board that
relied on the fd dump appearing under `CONFIG_SCHED_DUMP_ON_EXIT` must
enable it separately — the one behaviour change in this PR, limited to
debug instrumentation.
- `dump_fdlist()` / `fdlist_dump()` are no longer compiled in unless the
new option is set.
## Testing
Host: Ubuntu 22.04.5 LTS x86_64; gcc 13.1.0;
`qemu-system-arm -M sabrelite -cpu cortex-a9`; `sabre-6quad:nsh` with
`CONFIG_COREDUMP=y`.
**coredump**: `coredump()` only counts the regions passed to it as an
argument, so the probe hands it one read-only and one writeable 4 KiB
region directly and dumps to a memory stream:
| tree | core size |
|---|---|
| master | 10460 |
| this PR | 6364 |
4096 bytes = exactly the read-only region; the writeable one is still
dumped.
**assert fd dump**: `sabre-6quad:nsh`, symbol table of `nuttx`
| config | `nm nuttx \| grep dump_fdlist` |
|---|---|
| `CONFIG_SCHED_DUMP_ON_EXIT=y` only | (absent) |
| `CONFIG_SCHED_DUMP_FDLIST=y` | `t dump_fdlist` |
Both builds finish with 0 warnings, and checkpatch passes on both commits.
There is no host-runnable test for either fix; the coredump path needs
`CONFIG_COREDUMP`, which `sim` cannot build (`elf_gregset_t` is not
defined there — plain master fails the same way).
<details><summary>Test program (not part of this PR)</summary>
```c
#include <nuttx/config.h>
#include <stdio.h>
#include <string.h>
#include <nuttx/coredump.h>
#include <nuttx/streams.h>
#include <elf.h>
static uint8_t g_ro[4096];
static uint8_t g_rw[4096];
static uint8_t g_buf[64 * 1024];
static const struct memory_region_s g_regions[] =
{
{ (uintptr_t)g_ro, (uintptr_t)g_ro + sizeof(g_ro), PF_R },
{ (uintptr_t)g_rw, (uintptr_t)g_rw + sizeof(g_rw), PF_R | PF_W },
{ 0, 0, 0 }
};
int main(int argc, FAR char *argv[])
{
struct lib_memsostream_s mos;
int ret;
memset(g_ro, 0xa5, sizeof(g_ro));
memset(g_rw, 0x5a, sizeof(g_rw));
lib_memsostream(&mos, (FAR char *)g_buf, sizeof(g_buf));
ret = coredump(g_regions, &mos, 1);
printf("coredump ret=%d bytes=%ld\n", ret, (long)mos.common.nput);
return 0;
}
```
</details>
--
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]