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

Closed
github-bot wants to merge 2 commits from gh-pr/1801/head into gh-pr/1801/base
Owner

@⁠tedin7 on GitHub · 2026-11-24 18:51 UTC · original
tedin7:x2w-frontier-throwinfo → main · +496 −0 · 4 files · 2 commits · closed without merging

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.

**@⁠tedin7** on GitHub · 2026-11-24 18:51 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1801) `tedin7:x2w-frontier-throwinfo` → `main` · +496 −0 · 4 files · 2 commits · closed without merging 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.
tools/startup/msvc_throw_info.py reads the public x64 throw info (magic, thrown object, _ThrowInfo, _CatchableTypeArray, _CatchableType, type_info name) through a read_mem callback and returns a record with no address and no path: the catchable types (built-in scalars and public library classes by name, any other class as other) and, for a thrown 32-bit scalar such as long, the HRESULT as a public name with its facility. It is not wired into debug_launch.py yet.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:34:13 +00:00
github-bot closed this pull request 2026-11-26 23:34:13 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 19:14 UTC · original

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.

**@⁠tedin7** on GitHub · 2026-11-24 19:14 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1801#issuecomment-7141812531) 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

This discussion has been locked. Commenting is limited to contributors.
No description provided.