Repository navigation
Runtime: opt-in startup trace (gta6rt --trace FILE) (RT-29) - #1756
Conversation
645012f to
c620c2c
Compare
Vonsek
left a comment
There was a problem hiding this comment.
I tested c620c2c on Windows with a small MSVC probe using the actual trace header and synthetic inputs.
- Trace output can replace an input.
wmainopens the trace before the loader reads the image, andopen()useswb. If the two paths refer to the same file, the image gets truncated before loading. The probe confirmed that an existing synthetic file was replaced. Please create the trace only if the destination is new and add a control that checks the existing input bytes survive. - ANSI debug output can break the JSONL. An ANSI debug record containing a single-byte
éproduced a literal0xe9in the file and failed strict UTF-8 decoding. Convert the ANSI payload to UTF-8 before quoting it and exercise a non-ASCII input. The Windows documentation describes the locale-dependent ANSI path.
No game inputs or GPU tests. AI-assisted.
|
Tested
I didn't run AI-assisted. |
|
Tested on Windows 11 with two GPUs on one machine (runtime built from this PR's head, MSVC 14.51): no regression from this PR. RTX 4080 SUPER: 101/102 pass. |
Writes one JSON object per line, flushed per event: module maps, TLS callbacks, DllMain results, the first call of each unimplemented import with its caller as module+RVA, OutputDebugString text, exceptions with module+RVA and a short unwind, and the exit code. A vectored handler records and returns EXCEPTION_CONTINUE_SEARCH, so behaviour is unchanged. Off by default. startup_trace_test builds a synthetic DLL image (no game data) and checks each event kind.
Review on ItsNotRexed#1756 (Vonsek): - The trace is opened before the loader reads the image, so `wb` could truncate an input named by mistake (the image itself). open() now uses "x" mode and fails with EEXIST on an existing path; gta6rt says so and exits with 2. - OutputDebugStringA text is in the ANSI code page. It is converted to UTF-8 before quoting, so a byte such as 0xE9 no longer breaks the JSON lines. Host module names now come from GetModuleFileNameW, converted to UTF-8, for the same reason. startup_trace_test: an existing file is refused with EEXIST and its bytes survive, the trace stays off; an ANSI debug string with 0xE9 appears as its UTF-8 form and the whole file is valid UTF-8.
c620c2c to
d6443b1
Compare
|
@Vonsek thanks, both reproduced and fixed in d6443b1. The branch is also rebased on current
@Thatters @kapitche thanks for the runs. The |
|
Thanks. I built the isolated AI-assisted. |
Claimed in the coordination issue as: RT-29 (claim: #634 (comment))
What and why
Nothing records what happens once
--initor--runstarts running mapped code. Today a crash is a bare0xC0000005with a host address. This adds an opt-in trace,gta6rt --trace FILE, that writes one JSON object per line and flushes after each event, so the file survives a crash:kindmapmodule,base,size,relocated)tls_callbackatas module+RVA)dllmainDllMain(DLL_PROCESS_ATTACH)returns (result)unimplemented_callimportasdll!name,calleras module+RVA)debug_stringOutputDebugStringA/Wwhen no debugger is attachedexceptioncode,at, access kind and address for AVs, up to 16 unwound frames)exit/error--runreturns, or the loader throwsEXCEPTION_CONTINUE_SEARCH. The trace is off by default, and when it is off each hook costs one relaxed load.shims::make_unimplemented_thunkpath:rt_unimplementedlogs the first call per import. It works with anyLEONIDA_UNIMPLEMENTEDpolicy.OutputDebugStringis captured throughDBG_PRINTEXCEPTION_C/DBG_PRINTEXCEPTION_WIDE_Cin the same handler.run_callbacksalso runs them fromgta6rt_tls_host.dll'sDllMain, under the Windows loader lock. To keep file I/O and the module-lookup mutex out of that context, only the Loader's own process attach and detach calls passtrace=true.shims::module_offset()formats an address asa.dll+0x1234,host:ntdll.dll+0x1234or bare hex, using the existing module lookups.--trace-d3d12) covers the D3D12 layer. This covers the loader and process side. The two flags are independent.The file can quote whatever the game prints, so the README says it stays on the player's machine. Only counts or lines from synthetic fixtures should go in issues and PRs.
Code written from scratch for this repository.
Tested
startup_trace_test: it builds a synthetic DLL image by hand, with one import that binds to nothing,kernel32!OutputDebugStringA, and a read of address 0. It checks every event kind, including the module+RVA of the caller and of the faulting instruction, and that a repeated call logs only once. No game files and no GPU.ctest -R "startup_trace|^loader|unimplemented_policy": 4 of 4 pass (loader,loader_tls,unimplemented_policy,startup_trace).main.cppandpe_loader.cppcompile forgta6rt.gta6rt_d3d12_comdoes not compile here with Windows SDK 10.0.26100, because itsd3d12.hhas noD3D12_STANDARD_MULTISAMPLE_PATTERN/D3D12_CENTER_MULTISAMPLE_PATTERN(used ind3d12_vulkan_device.cppsince D3D-49). This happens on currentmaintoo and is unrelated to this change.AI-assisted (Claude Code).
Checklist
docs/design.md, with how it was confirmed. (n/a: no translator change)