Commit 22c1b628 authored by Kenton Varda's avatar Kenton Varda

More robust stripping of path prefixes for stack traces.

Fixes a spurrious test failure with out-of-tree builds.

Fixes #235
Closes #325
parent 61820c8f
...@@ -217,20 +217,36 @@ void printStackTraceOnCrash() { ...@@ -217,20 +217,36 @@ void printStackTraceOnCrash() {
kj::StringPtr trimSourceFilename(kj::StringPtr filename) { kj::StringPtr trimSourceFilename(kj::StringPtr filename) {
// Removes noisy prefixes from source code file name. // Removes noisy prefixes from source code file name.
//
static constexpr const char* PREFIXES[] = { // The goal here is to produce the "canonical" filename given the filename returned by e.g.
"../", // addr2line. addr2line gives us the full path of the file as passed on the compiler
"/ekam-provider/canonical/", // command-line, which in turn is affected by build system and by whether and where we're
"/ekam-provider/c++header/", // performing an out-of-tree build.
"src/", //
"tmp/" // To deal with all this, we look for directory names in the path which we recognize to be
// locations that represent roots of the source tree. We strip said root and everything before
// it.
static constexpr const char* ROOTS[] = {
"ekam-provider/canonical/", // Ekam source file.
"ekam-provider/c++header/", // Ekam include file.
"src/", // Non-Ekam source root.
"tmp/" // Non-Ekam generated code.
}; };
retry: retry:
for (const char* prefix: PREFIXES) { for (size_t i: kj::indices(filename)) {
if (filename.startsWith(prefix)) { if (i == 0 || filename[i-1] == '/') {
filename = filename.slice(strlen(prefix)); // We're at the start of a directory name. Check for valid prefixes.
goto retry; for (kj::StringPtr root: ROOTS) {
if (filename.slice(i).startsWith(root)) {
filename = filename.slice(i + root.size());
// We should keep searching to find the last instance of a root name. `i` is no longer
// a valid index for `filename` so start the loop over.
goto retry;
}
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment