startup: decode the MSVC C++ exception record into a sanitized summary #1794

Closed
tedin7 wants to merge 2 commits from upstream-pr/1801 into main
tedin7 commented 2026-11-24 18:51:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T18:51:39Z.


Refs #1758. This is the decoder only: it is not wired into tools/startup/debug_launch.py (untouched, so it does not collide with #1408 or the other open PRs that edit that file). The follow-up that calls it at the first-chance stop is a separate change.

What it does

tools/startup/msvc_throw_info.py turns a 0xE06D7363 exception record into a sanitized summary. #1758 needs the thrown HRESULT of the BVH builder, whose throw info says the catchable type is the built-in long (.J), without putting addresses or names from the title in a public comment.

decode_throw(exception_code, params, read_mem) follows the public MSVC x64 layout (ehdata.h): params[0] magic, [1] thrown object, [2] _ThrowInfo, [3] image base; _ThrowInfo → RVA of _CatchableTypeArray → RVAs of _CatchableType → RVA of type_info, whose decorated name is at offset 16. read_mem(address, size) -> bytes | None is the only access to memory, so the core has no Win32 dependency: in debug_launch.py it would be the existing read.

The record it returns has:

  • status: ok, not_msvc_exception, missing_parameters (fewer than four, so no image base), bad_magic, no_throw_info, unreadable, bad_throw_info, too_many_types (cap of 16, a safety limit).
  • types: one entry per catchable type. Built-in scalars and a short list of public library classes (std::runtime_error, _com_error, ...) are named; any other class is other, so a class of the title never appears.
  • value, only when the first catchable type is a 32-bit scalar (.J, .H, .I, .K) of size 4: the HRESULT as a public name (E_INVALIDARG, E_OUTOFMEMORY, DXGI_ERROR_DEVICE_REMOVED, DXGI_ERROR_DEVICE_HUNG, D3D12_ERROR_*, common HRESULT_FROM_WIN32(...)), or HRESULT(0x........), with its facility category (win32, dxgi, d3d12, other). A positive number above 65535 is not reported.
  • Never an address, a path, a name from the title or a number over 32 bits. describe(record) gives a one-line form made of those fields only.

Test

tests/startup_msvc_throw_info_check.py builds synthetic exception records in a fake address space (no title data) and checks 83 cases: ten HRESULTs through .J (E_INVALIDARG, E_OUTOFMEMORY, DXGI_ERROR_DEVICE_REMOVED, a generic one, ...), .H and .I, another exception code, wrong magic, three parameters, null throw info and image base, a read that fails at each of the four steps (and a callback that returns short data or raises), an RVA beyond the readable range and one that overflows 64 bits, a negative count, 16 and 17 catchable types, a zero RVA, runtime_error, _com_error, a class of the title, a long of the wrong size, malformed names, a name that ends before unmapped memory, and a sweep that no record contains an address, a path, long hex or a number over 32 bits.

It is registered in CMakeLists.txt after startup_triage_run and in the Python check list of .github/workflows/windows.yml next to startup_triage_run_check.py.

Results (Linux, local)

  • python3 -B tests/startup_msvc_throw_info_check.py: 83 ok, PASS.
  • Nine mutations of msvc_throw_info.py, each restored with git checkout --; all nine fail the test: magic not checked, facility 0x87A changed to 0x87B, cap >= instead of >, other classes reported by name, negative count accepted, type name read at +8, scalar size not checked, two DXGI names swapped, a raising callback not caught.
  • tests/docs_links_check.py and tests/bidi_controls_check.py pass; git diff --check origin/main...HEAD is clean.
  • git merge-tree of this branch against the head of every open PR (109, including #1408, #1787, #1788, #1789): no conflict that origin/main does not already have.

Not run, not established

  • No Windows run and no real exception record: the layout is the public one as documented, and the test builds records from it, so a difference in a real record would not show here. The first real use is the capture step of #1758.
  • The HRESULT list is short on purpose; a code outside it prints as HRESULT(0x........) with its facility.
  • Rethrows (null throw info) and 32-bit records (three parameters) are reported as such and not decoded.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6589059859 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1801). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T18:51:39Z. --- Refs #1758. This is the decoder only: it is not wired into `tools/startup/debug_launch.py` (untouched, so it does not collide with #1408 or the other open PRs that edit that file). The follow-up that calls it at the first-chance stop is a separate change. ## What it does `tools/startup/msvc_throw_info.py` turns a `0xE06D7363` exception record into a sanitized summary. #1758 needs the thrown HRESULT of the BVH builder, whose throw info says the catchable type is the built-in `long` (`.J`), without putting addresses or names from the title in a public comment. `decode_throw(exception_code, params, read_mem)` follows the public MSVC x64 layout (`ehdata.h`): `params[0]` magic, `[1]` thrown object, `[2]` `_ThrowInfo`, `[3]` image base; `_ThrowInfo` → RVA of `_CatchableTypeArray` → RVAs of `_CatchableType` → RVA of `type_info`, whose decorated name is at offset 16. `read_mem(address, size) -> bytes | None` is the only access to memory, so the core has no Win32 dependency: in `debug_launch.py` it would be the existing `read`. The record it returns has: - `status`: `ok`, `not_msvc_exception`, `missing_parameters` (fewer than four, so no image base), `bad_magic`, `no_throw_info`, `unreadable`, `bad_throw_info`, `too_many_types` (cap of 16, a safety limit). - `types`: one entry per catchable type. Built-in scalars and a short list of public library classes (`std::runtime_error`, `_com_error`, ...) are named; any other class is `other`, so a class of the title never appears. - `value`, only when the first catchable type is a 32-bit scalar (`.J`, `.H`, `.I`, `.K`) of size 4: the HRESULT as a public name (`E_INVALIDARG`, `E_OUTOFMEMORY`, `DXGI_ERROR_DEVICE_REMOVED`, `DXGI_ERROR_DEVICE_HUNG`, `D3D12_ERROR_*`, common `HRESULT_FROM_WIN32(...)`), or `HRESULT(0x........)`, with its facility category (`win32`, `dxgi`, `d3d12`, `other`). A positive number above 65535 is not reported. - Never an address, a path, a name from the title or a number over 32 bits. `describe(record)` gives a one-line form made of those fields only. ## Test `tests/startup_msvc_throw_info_check.py` builds synthetic exception records in a fake address space (no title data) and checks 83 cases: ten HRESULTs through `.J` (`E_INVALIDARG`, `E_OUTOFMEMORY`, `DXGI_ERROR_DEVICE_REMOVED`, a generic one, ...), `.H` and `.I`, another exception code, wrong magic, three parameters, null throw info and image base, a read that fails at each of the four steps (and a callback that returns short data or raises), an RVA beyond the readable range and one that overflows 64 bits, a negative count, 16 and 17 catchable types, a zero RVA, `runtime_error`, `_com_error`, a class of the title, a `long` of the wrong size, malformed names, a name that ends before unmapped memory, and a sweep that no record contains an address, a path, long hex or a number over 32 bits. It is registered in `CMakeLists.txt` after `startup_triage_run` and in the Python check list of `.github/workflows/windows.yml` next to `startup_triage_run_check.py`. ## Results (Linux, local) - `python3 -B tests/startup_msvc_throw_info_check.py`: 83 ok, PASS. - Nine mutations of `msvc_throw_info.py`, each restored with `git checkout --`; all nine fail the test: magic not checked, facility `0x87A` changed to `0x87B`, cap `>=` instead of `>`, other classes reported by name, negative count accepted, type name read at +8, scalar size not checked, two DXGI names swapped, a raising callback not caught. - `tests/docs_links_check.py` and `tests/bidi_controls_check.py` pass; `git diff --check origin/main...HEAD` is clean. - `git merge-tree` of this branch against the head of every open PR (109, including #1408, #1787, #1788, #1789): no conflict that `origin/main` does not already have. ## Not run, not established - No Windows run and no real exception record: the layout is the public one as documented, and the test builds records from it, so a difference in a real record would not show here. The first real use is the capture step of #1758. - The HRESULT list is short on purpose; a code outside it prints as `HRESULT(0x........)` with its facility. - Rethrows (null throw info) and 32-bit records (three parameters) are reported as such and not decoded. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-24 20:00:40 +00:00
tedin7 commented 2026-11-24 20:01:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:14:39Z.


Closing this draft for now to help keep the open PR queue manageable; the branch stays preserved on the fork so it can be reopened once the queue clears.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7141812531 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1801#issuecomment-7141812531). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T19:14:39Z. --- Closing this draft for now to help keep the open PR queue manageable; the branch stays preserved on the fork so it can be reopened once the queue clears.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!1794
No description provided.