Skip to content

[WIP] Fix StackDumperWin64.cpp reversion for correct API adaptations#778

Closed
Copilot wants to merge 1 commit intomainfrom
copilot/fix-stackdumperwin64-reversion
Closed

[WIP] Fix StackDumperWin64.cpp reversion for correct API adaptations#778
Copilot wants to merge 1 commit intomainfrom
copilot/fix-stackdumperwin64-reversion

Conversation

Copy link
Contributor

Copilot AI commented Mar 20, 2026

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.

Agent Instructions: Fix PR #775
This PR correctly reverts 3 things from commit 5711bf6, but StackDumperWin64.cpp was reverted too broadly — it reverted necessary x64 API adaptations along with the targeted fix. The file needs to be mostly restored to the base version, with only the specific GetProcAddress bug fix applied surgically.

File 1: Slice.cs
No changes needed. The current PR version is correct.

File 2: StackDumper.cpp
No changes needed. The current PR version is correct. It correctly restores:

The deliberate null-pointer dereference SEH pattern in DumpStackHere (lines 193–213)
The removal of the RtlCaptureStackBackTrace import
The HandleThrowable format string simplification (lines 512–513)
File 3: StackDumperWin64.cpp
This file needs significant rework. Start from the base version (b6ac397) and apply ONLY the following targeted fix:

The one change to make: In the ShowStackCore method (called ShowStackCoreInternal in the base), fix the SymGetLineFromAddr64 loading block. In the base version at lines 261–266, the code checks if (!g_pfnSymGetLineFromAddr64) but the body of that block is broken — it never actually calls GetProcAddress to load the function. Instead it contains dead error-reporting code:

// BASE (broken) — lines 261-266:
if (!g_pfnSymGetLineFromAddr64)
{
StrApp staModName("IMAGEHLP.DLL");
if (g_pfnSymGetLineFromAddr64 && gle != 487) // <-- always false, dead code
m_pstaDump->FormatAppend("SymGetLineFromAddr64(): gle = %u\r\n", gle);
}
Replace that block with the actual GetProcAddress call, using the 64-bit function name and types. The corrected block should be:

if (!g_pfnSymGetLineFromAddr64)
{
StrApp staModName("IMAGEHLP.DLL");
g_pfnSymGetLineFromAddr64 = (PFNSYMGETLINEFROMADDR64PROC) GetProcAddress(
GetModuleHandle(staModName.Chars()), "SymGetLineFromAddr64");
}
Everything else in this file must remain as it was in the base version. Specifically, preserve all of the following from the base:

64-bit types and APIs throughout — IMAGEHLP_SYMBOL64, IMAGEHLP_MODULE64, IMAGEHLP_LINE64, STACKFRAME64, StackWalk64, SymGetSymFromAddr64, SymLoadModule64, SymGetModuleBase64, SymFunctionTableAccess64, SymGetModuleInfo64 (line 22: sizeof IMAGEHLP_SYMBOL64, line 99: IMAGE_FILE_MACHINE_AMD64, etc.)
DWORD64 offsetFromSymbol = 0; at line 103 (a value type, NOT PDWORD64 which is a pointer type)
PFNSYMGETLINEFROMADDR64PROC typedef and g_pfnSymGetLineFromAddr64 static variable (lines 33–41)
s.AddrStack.Offset = c.Rsp; and s.AddrStack.Mode = AddrModeFlat; at lines 181–182 (required for x64 stack walking)
The SEH wrapper in ShowStackCore with __try/__except delegating to ShowStackCoreInternal (lines 73–96)
DWORD lineDisplacement = 0; as the displacement variable passed to g_pfnSymGetLineFromAddr64 (line 267), separate from offsetFromSymbol
64-bit format strings: "%016I64x" (line 227), "RIP" header (line 213), "0x%I64x" for module base (line 292)
File 4: Src/Generic/StackDumper.h
No changes needed. The ShowStackCoreInternal declaration at line 46 is already present and matches the base version's ShowStackCore/ShowStackCoreInternal split that must be preserved in StackDumperWin64.cpp.

Summary of net changes from base when done
The entire PR, when complete, should contain exactly these behavioral changes from the base commit:

Slice.cs:1133 — == "expanded" → != "doNotExpand" (already correct in PR)
StackDumper.cpp — Restore DumpStackHere SEH/NPE pattern, remove RtlCaptureStackBackTrace, simplify HandleThrowable format string (already correct in PR)
StackDumperWin64.cpp — Fix ONLY the GetProcAddress loading of SymGetLineFromAddr64 inside the if (!g_pfnSymGetLineFromAddr64) block. All other code in this file should match the base.


⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.


This change is Reviewable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants