Commit cc9459da authored by Kenton Varda's avatar Kenton Varda

Simplify stack trace generation.

parent 6cf2b5a7
...@@ -93,22 +93,22 @@ String stringifyStackTrace(ArrayPtr<void* const> trace) { ...@@ -93,22 +93,22 @@ String stringifyStackTrace(ArrayPtr<void* const> trace) {
String lines[32]; String lines[32];
FILE* p = nullptr; FILE* p = nullptr;
auto strTrace = strArray(trace, " ");
#if __linux__ #if __linux__
// Get executable name from /proc/self/exe, then pass it and the stack trace to addr2line to if (access("/proc/self/exe", R_OK) < 0) {
// get file/line pairs. // Apparently /proc is not available?
char exe[512];
ssize_t n = readlink("/proc/self/exe", exe, sizeof(exe));
if (n < 0 || n >= static_cast<ssize_t>(sizeof(exe))) {
return nullptr; return nullptr;
} }
exe[n] = '\0';
p = popen(str("addr2line -e ", exe, ' ', strArray(trace, " ")).cStr(), "r"); // Obtain symbolic stack trace using addr2line.
// TODO(cleanup): Use fork() and exec() or maybe our own Subprocess API (once it exists), to
// avoid depending on a shell.
p = popen(str("addr2line -e /proc/", getpid(), "/exe ", strTrace).cStr(), "r");
#elif __APPLE__ #elif __APPLE__
// The Mac OS X equivalent of addr2line is atos. // The Mac OS X equivalent of addr2line is atos.
// (Internally, it uses the private CoreSymbolication.framework library.) // (Internally, it uses the private CoreSymbolication.framework library.)
p = popen(str("xcrun atos -p ", getpid(), ' ', strArray(trace, " ")).cStr(), "r"); p = popen(str("xcrun atos -p ", getpid(), ' ', strTrace).cStr(), "r");
#endif #endif
if (p == nullptr) { if (p == nullptr) {
......
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