Skip to content

[WIP] feat(native): capture referenced .rodata pages - #2321

Open
jpnurmi wants to merge 9 commits into
v1from
jpnurmi/feat/native-rodata
Open

jpnurmi wants to merge 9 commits into
v1from
jpnurmi/feat/native-rodata

Conversation

@jpnurmi

@jpnurmi jpnurmi commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

SMART minidumps now also capture the pages of module data that thread stacks and registers point to, such as string literals in .rodata, so debuggers can show those values from the dump alone.

  • Linux: read-only mappings backed by a file.
  • macOS: __TEXT,__cstring, __TEXT,__const and __DATA_CONST of modules outside the dyld shared cache. Without task_for_pid access, such as in release builds without the get-task-allow entitlement, only the __TEXT sections are captured, read from the module files on disk.
  • Windows: .rdata and .data pages of loaded images, added through a MiniDumpWriteDump memory callback because MiniDumpWithIndirectlyReferencedMemory skips image memory.

Also fixes indirect capture on Linux and macOS taking the page before the pointee for pointers in the first 512 bytes of a page, and macOS minidumps written without task_for_pid access leaving thread stacks out of the memory list.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

jpnurmi added a commit that referenced this pull request Nov 18, 2026
The SMART mode callback returned `FALSE` for
`ReadMemoryFailureCallback`. Per the dbghelp docs, anything but `TRUE`
with `S_OK` "results in a failure to write to the minidump", so one
unreadable block, such as an image page unmapped after `VirtualQueryEx`
checked it, failed the whole dump. Return `TRUE` with `S_OK` so dbghelp
omits the block instead.

Ref: #2321 (comment)
jpnurmi added a commit that referenced this pull request Nov 18, 2026
The Windows SMART mode callback only scanned thread stacks for
pointers into image data, while the Linux and macOS walkers also scan
registers. A string literal pointer held only in a register, such as a
call argument at the crash, was left out of the dump. Also scan the
general-purpose registers of each thread and the crashing thread's
exception context.

Ref: #2321 (comment)

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit fa70d8f. Configure here.

jpnurmi added a commit that referenced this pull request Nov 18, 2026
Without `task_for_pid` access, the macOS daemon only parsed universal
binaries with a 32-bit `FAT_MAGIC` header, so modules in a
`FAT_MAGIC_64` file got no `__TEXT,__cstring` or `__TEXT,__const`
pages. Walk the `fat_arch_64` entries of those files too.

Ref: #2321 (comment)
@jpnurmi
jpnurmi force-pushed the jpnurmi/feat/native-rodata branch from 2009430 to 1b73f6c Compare November 19, 2026 08:53
jpnurmi added a commit that referenced this pull request Nov 19, 2026
The SMART mode callback returned `FALSE` for
`ReadMemoryFailureCallback`. Per the dbghelp docs, anything but `TRUE`
with `S_OK` "results in a failure to write to the minidump", so one
unreadable block, such as an image page unmapped after `VirtualQueryEx`
checked it, failed the whole dump. Return `TRUE` with `S_OK` so dbghelp
omits the block instead.

Ref: #2321 (comment)
jpnurmi added a commit that referenced this pull request Nov 19, 2026
The Windows SMART mode callback only scanned thread stacks for
pointers into image data, while the Linux and macOS walkers also scan
registers. A string literal pointer held only in a register, such as a
call argument at the crash, was left out of the dump. Also scan the
general-purpose registers of each thread and the crashing thread's
exception context.

Ref: #2321 (comment)
jpnurmi added a commit that referenced this pull request Nov 19, 2026
Without `task_for_pid` access, the macOS daemon only parsed universal
binaries with a 32-bit `FAT_MAGIC` header, so modules in a
`FAT_MAGIC_64` file got no `__TEXT,__cstring` or `__TEXT,__const`
pages. Walk the `fat_arch_64` entries of those files too.

Ref: #2321 (comment)
jpnurmi added a commit that referenced this pull request Nov 19, 2026
The SMART mode callback returned `FALSE` for
`ReadMemoryFailureCallback`. Per the dbghelp docs, anything but `TRUE`
with `S_OK` "results in a failure to write to the minidump", so one
unreadable block, such as an image page unmapped after `VirtualQueryEx`
checked it, failed the whole dump. Return `TRUE` with `S_OK` so dbghelp
omits the block instead.

Ref: #2321 (comment)
@jpnurmi
jpnurmi force-pushed the jpnurmi/feat/native-rodata branch from 1b73f6c to 29c0ef1 Compare November 19, 2026 10:53
jpnurmi added a commit that referenced this pull request Nov 19, 2026
The Windows SMART mode callback only scanned thread stacks for
pointers into image data, while the Linux and macOS walkers also scan
registers. A string literal pointer held only in a register, such as a
call argument at the crash, was left out of the dump. Also scan the
general-purpose registers of each thread and the crashing thread's
exception context.

Ref: #2321 (comment)
jpnurmi added a commit that referenced this pull request Nov 19, 2026
Without `task_for_pid` access, the macOS daemon only parsed universal
binaries with a 32-bit `FAT_MAGIC` header, so modules in a
`FAT_MAGIC_64` file got no `__TEXT,__cstring` or `__TEXT,__const`
pages. Walk the `fat_arch_64` entries of those files too.

Ref: #2321 (comment)
@jpnurmi
jpnurmi changed the base branch from v1 to jpnurmi/fix/native-minidump-only November 19, 2026 10:53
@jpnurmi
jpnurmi added this pull request to stack #2325 November 19, 2026 10:54
Base automatically changed from jpnurmi/fix/native-minidump-only to v1 November 19, 2026 14:19
SMART minidumps on Linux and macOS capture memory for pointers found
on thread stacks and in registers. The capture window started 512
bytes below the pointer, so for a pointer in the first 512 bytes of
a page it rounded down to the previous page and missed the pointee.
For example, a pointer to `0x10000100` captured `0xffff000` to
`0x10000000`.

Capture the page that contains the pointer instead.

Ref: #1694
SMART minidumps now also capture pages of module data, such as string
literals in `.rodata`, that thread stacks and registers point to, so
debuggers can show them from the dump alone.
The SMART mode callback returned `FALSE` for
`ReadMemoryFailureCallback`. Per the dbghelp docs, anything but `TRUE`
with `S_OK` "results in a failure to write to the minidump", so one
unreadable block, such as an image page unmapped after `VirtualQueryEx`
checked it, failed the whole dump. Return `TRUE` with `S_OK` so dbghelp
omits the block instead.

Ref: #2321 (comment)
The Windows SMART mode callback only scanned thread stacks for
pointers into image data, while the Linux and macOS walkers also scan
registers. A string literal pointer held only in a register, such as a
call argument at the crash, was left out of the dump. Also scan the
general-purpose registers of each thread and the crashing thread's
exception context.

Ref: #2321 (comment)
The SMART pointer walker only skipped pages it had captured itself,
so it captured thread stack pages, module header pages, `[heap]` and
the crash mapping a second time. Breakpad's processor rejects a memory
list with overlapping regions ("MinidumpMemoryList could not store
memory region"). In a Linux dump of a Qt app, 17 of 18 thread stacks
and the first pages of the executable and `ld-linux-x86-64.so.2`
appeared twice, and macOS duplicated stack pages the same way.

Write those regions to the memory list first and skip candidate pages
that overlap them.
Without `task_for_pid` access, the macOS daemon wrote a minimal SMART
minidump that left out the string literals referenced from stacks.
Apps only grant that access with the `get-task-allow` entitlement,
which notarization rejects, so a `const char *` local in a crashed app
showed no value.

Read the referenced `__TEXT,__cstring` and `__TEXT,__const` pages from
the module files on disk instead.
Without `task_for_pid` access, the macOS memory list held only module
header pages and captured module data, but no thread stacks.
Symbolicator reads stack variables through the memory list, so a
`const char *` local showed no value even with the string captured.
List the thread stacks first, as the task-port path already does.
Without `task_for_pid` access, the macOS daemon only parsed universal
binaries with a 32-bit `FAT_MAGIC` header, so modules in a
`FAT_MAGIC_64` file got no `__TEXT,__cstring` or `__TEXT,__const`
pages. Walk the `fat_arch_64` entries of those files too.

Ref: #2321 (comment)
@jpnurmi
jpnurmi force-pushed the jpnurmi/feat/native-rodata branch from 29c0ef1 to 562bf90 Compare November 19, 2026 14:20

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant