Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/boot.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ Read the startup trace first; the first event that is not the expected one is th
3. **`tls_callback` / `dllmain`** — a failed DllMain, or a TLS callback that faults, usually points at the CRT or
TLS index; the loader's own TLS is checked by `run_tiny_game_tls`.
4. **`exception`** — code, `at`, access/address and the stack frames. The loader's vectored handler only records,
so the process behaviour is the same with or without the trace.
so the process behaviour is the same with or without the trace. When exceptions exceed `--limit`, the summary
shows the first entries plus the last observed exception (`last_exception` in JSON). The title can handle that
last exception and continue running.
5. **`exit` / `error`** — a clean exit is not a correct frame; continue to the D3D12 trace.
6. **D3D12 trace** — the `failed`, `unsupported` and `refused` lines name the method. Compare its position with
the public SDK vtable; an unknown slot is expected until the executable names it (Q2, Q6). The `[rt]` lines in
Expand Down
30 changes: 30 additions & 0 deletions tests/test_boot_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,38 @@ def test_startup_summary(self):
trace["exceptions"][0]["stack"], ["game.exe+0x40", "game.exe+0x120"]
)
self.assertIs(trace["exceptions"][1]["cpp"], True)
self.assertNotIn("last_exception", trace)
self.assertEqual(trace["exit"], 0)

def test_last_observed_exception_is_reported_beyond_limit(self):
first = {"seq": 2, "kind": "exception", "code": "0xe06d7363",
"at": "fixture.exe+0x10", "cpp": True}
middle = dict(first, seq=3, at="fixture.exe+0x20")
last = {"seq": 4, "kind": "exception", "code": "0xc0000005",
"at": "last.dll+0x32", "stack": ["last.dll+0x46"]}
self.write(self.startup, [STARTUP[0], first, middle, last, {"seq": 5, "kind": "exit", "code": 0}])

with contextlib.redirect_stdout(io.StringIO()) as output:
self.assertEqual(bt.main([self.startup, "--limit", "1", "--json"]), 0)
summary = json.loads(output.getvalue())
startup = summary["startup"]
self.assertEqual(startup["exception_count"], 3)
self.assertEqual([e["at"] for e in startup["exceptions"]], [first["at"]])
self.assertIn("last_exception", startup)
self.assertEqual(startup["last_exception"]["at"], last["at"])
self.assertEqual(startup["last_exception"]["stack"], last["stack"])
self.assertEqual(startup["exit"], 0)

with contextlib.redirect_stdout(io.StringIO()) as output:
self.assertEqual(bt.main([self.startup, "--limit", "1"]), 0)
text = output.getvalue()
self.assertIn("code 0xe06d7363 at fixture.exe+0x10", text)
self.assertIn("last observed exception: code 0xc0000005 at last.dll+0x32", text)
self.assertIn("stack: last.dll+0x46", text)
self.assertNotIn(middle["at"], text)
full = bt.summarize(bt.parse_startup(self.startup), None)
self.assertIn("last observed exception: code 0xc0000005 at last.dll+0x32", bt.format_text(full, 1))

def test_debug_text_is_not_printed(self):
self.write(self.startup, STARTUP)
text = bt.format_text(bt.summarize(bt.parse_startup(self.startup), None), 10)
Expand Down
37 changes: 23 additions & 14 deletions tools/boot_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,19 @@ def parse_startup(path: str, limit: int = 10) -> dict:
trace["debug_strings"] += 1
elif kind == "exception":
trace["exception_count"] += 1
stack = event.get("stack")
exc = {
"code": event.get("code"),
"at": event.get("at"),
"cpp": event.get("cpp"),
"access": event.get("access"),
"address": event.get("address"),
"stack": stack[:8] if isinstance(stack, list) else [],
}
if len(trace["exceptions"]) < limit:
stack = event.get("stack")
trace["exceptions"].append(
{
"code": event.get("code"),
"at": event.get("at"),
"cpp": event.get("cpp"),
"access": event.get("access"),
"address": event.get("address"),
"stack": stack[:8] if isinstance(stack, list) else [],
}
)
trace["exceptions"].append(exc)
else:
trace["last_exception"] = exc
elif kind == "exit":
trace["exit"] = event.get("code")
elif kind == "error":
Expand Down Expand Up @@ -238,15 +239,22 @@ def format_text(summary: dict, limit: int) -> str:
out.append(f" debug strings: {startup['debug_strings']} (text not shown)")
if startup["exception_count"]:
out.append(f" exceptions: {startup['exception_count']}")
for exc in startup["exceptions"][:limit]:
sampled = startup["exceptions"]
details = [("code", exc) for exc in sampled[:limit]]
last = startup.get("last_exception")
if last is None and len(sampled) > limit:
last = sampled[-1]
if last is not None:
details.append(("last observed exception: code", last))
for label, exc in details:
cpp = exc.get("cpp")
detail = " (C++ throw)" if cpp is True else f" ({cpp})" if cpp else ""
if exc.get("access"):
detail += f" ({exc['access']}"
if exc.get("address"):
detail += f" {exc['address']}"
detail += ")"
out.append(f" code {exc['code']} at {exc['at']}{detail}")
out.append(f" {label} {exc['code']} at {exc['at']}{detail}")
if exc.get("stack"):
out.append(f" stack: {_tail(exc['stack'], limit)}")
if startup["error"]:
Expand Down Expand Up @@ -284,7 +292,8 @@ def main(argv=None) -> int:
ap.add_argument("--d3d12", help="the stderr log written with --trace-d3d12")
ap.add_argument("--json", action="store_true", help="print the summary as JSON")
ap.add_argument(
"--limit", type=int, default=10, help="items listed per section (default 10)"
"--limit", type=int, default=10,
help="items listed per section (default 10), plus the last observed exception if omitted",
)
a = ap.parse_args(argv)
if not a.startup and not a.d3d12:
Expand Down