Skip to content

Commit

Permalink
Small crash trace update (dkfans#3567)
Browse files Browse the repository at this point in the history
  • Loading branch information
yani authored Nov 2, 2024
1 parent 436d6e8 commit ca28f12
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/bflib_crash.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,25 @@ _backtrace(int depth , LPCONTEXT context)
// We don't want that size at the beginning, but we do want the library path.
char *splitPos = strchr(prevName, ' ');
if (strncmp(prevName, "0x", 2) == 0 && splitPos != NULL){
memmove(prevName, splitPos + 1, strlen(splitPos)); // remove anything before the space
memmove(prevName + 4, prevName, strlen(prevName) + 1); // make space for the arrow symbol
memcpy(prevName, "-> ", 3); // prepend the arrow symbol

// Remove everything before the space
memmove(prevName, splitPos + 1, strlen(splitPos));

// Find the last slash in the string to isolate the filename
char *lastSlash = strrchr(prevName, '/');
if (lastSlash != NULL) {
// Move the filename to the start
memmove(prevName, lastSlash + 1, strlen(lastSlash + 1) + 1);
}

// Prepend the arrow symbol
memmove(prevName + 3, prevName, strlen(prevName) + 1); // make space for the arrow symbol
memcpy(prevName, "-> ", 3); // prepend the arrow symbol
}

// Log it
LbJustLog(
"[#%-2d] in %14-s : %-40s [0x%llx+0x%llx] \t(map lookup for %04x:%08x, base: %08x)\n",
"[#%-2d] %12-s : %-36s [0x%llx+0x%llx]\t map lookup for: %04x:%08x, base: %08x\n",
depth, module_name, prevName, prevAddr, displacement, context->SegCs, frame.AddrPC.Offset, module_base);

addrFound = true;
Expand Down Expand Up @@ -261,13 +273,13 @@ _backtrace(int depth , LPCONTEXT context)
// This works if there are any debug symbols available and also works for most OS libraries
if (SymFromAddr(process, frame.AddrPC.Offset, &sfaDisplacement, pSymbol))
{
LbJustLog("[#%-2d] in %14-s : %-40s [%04x:%08x+0x%llx, base %08x] (symbol lookup)\n",
LbJustLog("[#%-2d] %12-s : %-36s [%04x:%08x+0x%llx, base %08x]\t symbol lookup\n",
depth, module_name, pSymbol->Name, context->SegCs, frame.AddrPC.Offset, sfaDisplacement, module_base);
}
else
{
// Fallback
LbJustLog("[#%-2d] in %13-s at %04x:%08x, base %08x\n", depth, module_name, context->SegCs, frame.AddrPC.Offset, module_base);
LbJustLog("[#%-2d] %12-s : at %04x:%08x, base %08x\n", depth, module_name, context->SegCs, frame.AddrPC.Offset, module_base);
}
}

Expand Down

0 comments on commit ca28f12

Please sign in to comment.