diff --git a/sandboxed_api/sandbox2/BUILD.bazel b/sandboxed_api/sandbox2/BUILD.bazel index 2271b46..5d54466 100644 --- a/sandboxed_api/sandbox2/BUILD.bazel +++ b/sandboxed_api/sandbox2/BUILD.bazel @@ -168,7 +168,6 @@ cc_library( deps = [ ":bpfdisassembler", ":comms", - ":fs", ":namespace", ":regs", ":syscall", @@ -271,7 +270,6 @@ cc_library( ":violation_proto_cc", ":forkserver", ":forkserver_proto_cc", - ":fs", ":global_forkserver", ":ipc", ":limits", @@ -281,7 +279,6 @@ cc_library( ":notify", ":policy", ":regs", - ":reporter", ":result", ":syscall", ":util", diff --git a/sandboxed_api/sandbox2/stack-trace_test.cc b/sandboxed_api/sandbox2/stack-trace_test.cc index b12e44e..b36e842 100644 --- a/sandboxed_api/sandbox2/stack-trace_test.cc +++ b/sandboxed_api/sandbox2/stack-trace_test.cc @@ -92,6 +92,8 @@ void SymbolizationWorksCommon( ASSERT_THAT(result.final_status(), Eq(Result::SIGNALED)); ASSERT_THAT(result.GetStackTrace(), HasSubstr("CrashMe")); + // Check that demangling works as well. + ASSERT_THAT(result.GetStackTrace(), HasSubstr("CrashMe()")); } TEST(StackTraceTest, SymbolizationWorksNonSandboxedLibunwind) { diff --git a/sandboxed_api/sandbox2/unwind/unwind.cc b/sandboxed_api/sandbox2/unwind/unwind.cc index 803692a..0ffc75d 100644 --- a/sandboxed_api/sandbox2/unwind/unwind.cc +++ b/sandboxed_api/sandbox2/unwind/unwind.cc @@ -14,6 +14,8 @@ #include "sandboxed_api/sandbox2/unwind/unwind.h" +#include + #include #include #include @@ -34,6 +36,16 @@ namespace sandbox2 { namespace { +std::string DemangleSymbol(const std::string& maybe_mangled) { + int status; + std::unique_ptr> symbol = { + abi::__cxa_demangle(maybe_mangled.c_str(), nullptr, nullptr, &status), + free}; + if (symbol && status == 0) { + return symbol.get(); + } + return maybe_mangled; +} std::string GetSymbolAt(const std::map& addr_to_symbol, uint64_t addr) { auto entry_for_next_symbol = addr_to_symbol.lower_bound(addr); @@ -41,13 +53,14 @@ std::string GetSymbolAt(const std::map& addr_to_symbol, entry_for_next_symbol != addr_to_symbol.begin()) { // Matches the addr exactly: if (entry_for_next_symbol->first == addr) { - return entry_for_next_symbol->second; + return DemangleSymbol(entry_for_next_symbol->second); } // Might be inside a function, return symbol+offset; const auto entry_for_previous_symbol = --entry_for_next_symbol; if (!entry_for_previous_symbol->second.empty()) { - return absl::StrCat(entry_for_previous_symbol->second, "+0x", + return absl::StrCat(DemangleSymbol(entry_for_previous_symbol->second), + "+0x", absl::Hex(addr - entry_for_previous_symbol->first)); } } @@ -166,7 +179,7 @@ void RunLibUnwindAndSymbolizer(pid_t pid, std::string* stack_trace_out, addr_to_symbol[entry.end] = ""; } - if (!entry.path.empty() && entry.is_executable) { + if (!entry.path.empty() && entry.path != "[vdso]" && entry.is_executable) { auto elf_or = ElfFile::ParseFromFile(entry.path, ElfFile::kLoadSymbols); if (!elf_or.ok()) { SAPI_RAW_LOG(WARNING, "Could not load symbols for %s: %s", entry.path, diff --git a/sandboxed_api/util/BUILD.bazel b/sandboxed_api/util/BUILD.bazel index 9fd8ea8..babb2b8 100644 --- a/sandboxed_api/util/BUILD.bazel +++ b/sandboxed_api/util/BUILD.bazel @@ -76,7 +76,6 @@ cc_test( name = "status_test", srcs = ["status_test.cc"], deps = [ - ":status", ":status_matchers", "@com_google_googletest//:gtest_main", ],