Skip to content

feat(libc): optionally dump indirect memory in Windows crash reports - #4780

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
ivica00:codex/crash-indirect-memory
Oct 14, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
ivica00:codex/crash-indirect-memory

Conversation

@ivica00

@ivica00 ivica00 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What

Windows crash reports show the words pointed to by registers, but stop before the structures those words reference. Set APS5_CRASH_INDIRECT_MEMORY=1 to include one additional pointer level: up to eight 64-byte blocks per register, labelled with the register, pointer offset and target address. The option is disabled when unset or empty. Executable targets and reads that fail or return fewer than 64 bytes are skipped through ReadProcessMemory.

This is a generic diagnostic aid.

Tested

  • Windows 11 x64, WinLibs GCC 15.2, Release, AMD Radeon RX 9070 XT.
  • windows_exceptions and guest_raise_exception: passed.
  • Rebased on current upstream/main and verified with tools/check_conventions.py --base upstream/main.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, the idea is fine and the code is small. One thing to fix:

  • core/libs/prx/libc/src/specifics/windows/CrashReport.cpp:285: GetEnvironmentVariableA("APS5_CRASH_INDIRECT_MEMORY", nullptr, 0) != 0 returns the required buffer size including the terminator when the variable exists, so an empty value returns 1 and enables the dump. The description and docs/user/USAGE.md say an empty variable keeps it disabled. Read the value into a small buffer and enable it only when it is non-empty (or exactly 1, and then say so in USAGE.md, which currently documents =1 while any value works).

Please also check the Windows build job once pushed (PR CI skips it; it runs on dispatch). Happy to merge after that.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 13, 2026
@ivica00
ivica00 force-pushed the codex/crash-indirect-memory branch from 50f5f3a to 139bc7b Compare October 13, 2026 17:16
@ivica00

ivica00 commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @adriadam10! Rebased onto current \upstream/main\ and updated the \APS5_CRASH_INDIRECT_MEMORY\ environment check to read into a buffer so that an unset or empty variable keeps the indirect memory dump disabled as documented in \USAGE.md.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 13, 2026
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#4855 docs/user/USAGE.md L175

@gunerky

gunerky commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

I checked the updated environment-value handling at PR head 139bc7b9816939bf9a00905cb12656d387cdcd2d on Windows x64, WinLibs GCC 15.2.0, optimized (-O3 -DNDEBUG) with native SEH defaults. The unset/empty fix works, and the advertised APS5_CRASH_INDIRECT_MEMORY=1 setting produces the expected indirect data.

One small boundary case remains: nonempty values that do not fit in the 16-byte buffer disable the option in my run.

Value Indirect blocks in the controlled fixture
Unset or empty none
1, 0, true, or 15 x characters present
16, 17, 255, or 4096 x characters none

At the longer lengths, GetEnvironmentVariableA returns the required size rather than successfully filling the buffer. Microsoft documents that the buffer contents are undefined in that case, so testing indirectBuffer[0] then does not reliably implement the description's nonempty-value rule. This is a configuration edge; =1 works normally.

The unchanged head CrashReport.cpp and CallTrace.cpp were compiled into an isolated probe with synthetic exception data and fixture-owned memory. Correct labels/data, read-only targets, and exclusion of executable/partial/unreadable targets passed; partial, unaligned and null register roots completed without indirect output. No game was used. This probe is not a full PR build and does not replace the requested Windows build job or validate concurrent mapping changes.

AI-assisted: yes; fixture, execution and result checking assisted by Codex.

…alue

GetEnvironmentVariableA leaves the buffer undefined when the value does not fit, so a 16-byte read disabled longer settings. A size query treats every nonempty value as enabled and still leaves unset and empty disabled.

Co-authored-by: Cursor <cursoragent@cursor.com>
@ivica00

ivica00 commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @gunerky. The 16-byte buffer was the problem: when GetEnvironmentVariableA cannot store the value it returns the required size and leaves the buffer undefined, so indirectBuffer[0] was not a reliable nonempty check.

6d33b36e7 queries the required size with a null buffer instead. An unset variable returns 0 and an empty value returns 1, so both stay disabled. Any nonempty value, including ones longer than 15 characters, returns a size greater than 1 and enables the dump. USAGE.md is unchanged: unset or empty disables it, and any other value enables it.

@ivica00
ivica00 requested a review from adriadam10 October 13, 2026 20:28

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Checked the env-value handling (GetEnvironmentVariableA with a null buffer returns 0 unset, 1 empty, >1 otherwise, so > 1 matches USAGE.md), the readability/executable skips and the 64-byte read, and the libc build and ctest on Linux; the Windows job covers the rest. Merging once the Windows build is green.

@adriadam10
adriadam10 merged commit bb70063 into boykopovar:main Oct 14, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants