Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Avoid GC allocation when building the search path #3391

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 2 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
35 changes: 20 additions & 15 deletions src/core/sys/windows/stacktrace.d
Original file line number Diff line number Diff line change
Expand Up @@ -345,26 +345,28 @@ extern(Windows) BOOL FixupDebugHeader(HANDLE hProcess, ULONG ActionCode,
return FALSE;
}

private string generateSearchPath()
private size_t generateSearchPath(ref char[MAX_PATH] path)
{
__gshared string[3] defaultPathList = ["_NT_SYMBOL_PATH",
"_NT_ALTERNATE_SYMBOL_PATH",
"SYSTEMROOT"];
__gshared string[3] defaultPathList = [
"_NT_SYMBOL_PATH", "_NT_ALTERNATE_SYMBOL_PATH", "SYSTEMROOT"
];

string path;
char[2048] temp = void;
char[MAX_PATH] temp = void;
DWORD len;

foreach ( e; defaultPathList )
size_t index = 0;
foreach (e; defaultPathList)
{
if ( (len = GetEnvironmentVariableA( e.ptr, temp.ptr, temp.length )) > 0 )
if ((len = GetEnvironmentVariableA(e.ptr, temp.ptr, temp.length)) > 0)
{
path ~= temp[0 .. len];
path ~= ";";
path[index .. index + len] = temp[0 .. len];
index += len;
path[index] = ';';
index += 1;
}
}
path ~= "\0";
return path;
path[index] = '\0';
index += 1;
return index;
}


Expand Down Expand Up @@ -400,9 +402,12 @@ shared static this()
symOptions |= SYMOPT_DEFERRED_LOAD;
symOptions = dbghelp.SymSetOptions( symOptions );

debug(PRINTF) printf("Search paths: %s\n", generateSearchPath().ptr);
char[MAX_PATH] buffer;
generateSearchPath(buffer);

debug(PRINTF) printf("Search paths: %s\n", buffer.ptr);

if (!dbghelp.SymInitialize(hProcess, generateSearchPath().ptr, TRUE))
if (!dbghelp.SymInitialize(hProcess, buffer.ptr, TRUE))
return;

dbghelp.SymRegisterCallback64(hProcess, &FixupDebugHeader, 0);
Expand Down