Skip to content

Commit ebca9e1

Browse files
committed
print_stacktrace_win: print also file/line
and displacement, if present Also print common (frame number, stacktrace ptr) in one place.
1 parent 38da0cd commit ebca9e1

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/utils/windows.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,26 @@ print_stacktrace_win()
314314
for (unsigned short i = 0; i < frames; i++) {
315315
BOOL ret = SymFromAddr(process, (DWORD64) (stack[i]), 0, symbol);
316316
char buf[STR_LEN];
317+
snprintf_ch(buf, "%i (%p): ", frames - i - 1, stack[i]);
317318
if (ret == TRUE) {
318-
snprintf_ch(buf, "%i (%p): %s - 0x%0llX\n",
319-
frames - i - 1, stack[i], symbol->Name,
320-
symbol->Address);
319+
snprintf(buf + strlen(buf), sizeof buf - strlen(buf),
320+
"%s - 0x%0llX\n", symbol->Name,
321+
symbol->Address);
322+
323+
IMAGEHLP_LINE64 line = { .SizeOfStruct = sizeof line };
324+
DWORD displacementLine = 0;
325+
if (SymGetLineFromAddr64(process, (DWORD64) (stack[i]),
326+
&displacementLine, &line)) {
327+
snprintf(buf + strlen(buf),
328+
sizeof buf - strlen(buf),
329+
"\tFile: %s, line: %lu, displacement: "
330+
"%lu\n",
331+
line.FileName, line.LineNumber,
332+
displacementLine);
333+
}
321334
} else {
322-
snprintf_ch(buf, "%i (%p): (cannot resolve)\n",
323-
frames - i - 1, stack[i]);
335+
snprintf(buf + strlen(buf), sizeof buf - strlen(buf),
336+
"(cannot resolve)\n");
324337
}
325338
_write(STDERR_FILENO, buf, strlen(buf));
326339
}

0 commit comments

Comments
 (0)