Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.
Merged
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
32 changes: 23 additions & 9 deletions src/rt/backtrace/dwarf.d
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,37 @@ else
int ret = 0;
foreach (size_t i; 0 .. callstack.length)
{
char[1536] buffer = void; buffer[0] = 0;
char[256] addressBuffer = void; addressBuffer[0] = 0;
char[1536] buffer = void;
size_t bufferLength = 0;

void appendToBuffer(Args...)(const(char)* format, Args args)
{
const count = snprintf(buffer.ptr + bufferLength, buffer.length - bufferLength, format, args);
assert(count >= 0);
bufferLength += count;
if (bufferLength >= buffer.length)
bufferLength = buffer.length - 1;
}

if (locations.length > 0 && locations[i].line != -1)
snprintf(addressBuffer.ptr, addressBuffer.length, "%.*s:%d ", cast(int) locations[i].file.length, locations[i].file.ptr, locations[i].line);
{
appendToBuffer("%.*s:%d ", cast(int) locations[i].file.length, locations[i].file.ptr, locations[i].line);
}
else
addressBuffer[] = "??:? \0";
{
buffer[0 .. 5] = "??:? ";
bufferLength = 5;
}

char[1024] symbolBuffer = void;
int bufferLength;
auto symbol = getDemangledSymbol(frameList[i][0 .. strlen(frameList[i])], symbolBuffer);
if (symbol.length > 0)
bufferLength = snprintf(buffer.ptr, buffer.length, "%s%.*s [0x%x]", addressBuffer.ptr, cast(int) symbol.length, symbol.ptr, callstack[i]);
else
bufferLength = snprintf(buffer.ptr, buffer.length, "%s[0x%x]", addressBuffer.ptr, callstack[i]);
appendToBuffer("%.*s ", cast(int) symbol.length, symbol.ptr);

assert(bufferLength >= 0);
static if (size_t.sizeof == 8)
appendToBuffer("[0x%llx]", callstack[i]);
else
appendToBuffer("[0x%x]", callstack[i]);

auto output = buffer[0 .. bufferLength];
auto pos = i;
Expand Down