Symbolize crash backtraces using the Abseil debugging library (flutter/engine#26916)
This commit is contained in:
@@ -97,6 +97,7 @@ source_set("fml") {
|
||||
public_deps = [ ":command_line" ]
|
||||
|
||||
deps = [
|
||||
"//third_party/abseil-cpp/absl/debugging:symbolize",
|
||||
"//third_party/dart/runtime:dart_api",
|
||||
|
||||
# These need to be in sync with the Fuchsia buildroot.
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#endif
|
||||
|
||||
#include "flutter/fml/logging.h"
|
||||
#include "flutter/fml/paths.h"
|
||||
#include "third_party/abseil-cpp/absl/debugging/symbolize.h"
|
||||
|
||||
namespace fml {
|
||||
|
||||
@@ -45,16 +47,12 @@ static std::string DemangleSymbolName(const std::string& mangled) {
|
||||
}
|
||||
|
||||
static std::string GetSymbolName(void* symbol) {
|
||||
Dl_info info = {};
|
||||
|
||||
if (::dladdr(symbol, &info) == 0) {
|
||||
return kKUnknownFrameName;
|
||||
}
|
||||
if (info.dli_sname == nullptr) {
|
||||
char name[1024];
|
||||
if (!absl::Symbolize(symbol, name, sizeof(name))) {
|
||||
return kKUnknownFrameName;
|
||||
}
|
||||
|
||||
return DemangleSymbolName({info.dli_sname});
|
||||
return DemangleSymbolName({name});
|
||||
}
|
||||
|
||||
std::string BacktraceHere(size_t offset) {
|
||||
@@ -140,6 +138,10 @@ void InstallCrashHandler() {
|
||||
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
|
||||
}
|
||||
#endif
|
||||
auto exe_path = fml::paths::GetExecutablePath();
|
||||
if (exe_path.first) {
|
||||
absl::InitializeSymbolizer(exe_path.second.c_str());
|
||||
}
|
||||
ToggleSignalHandlers(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -52,5 +52,13 @@ std::string SanitizeURIEscapedCharacters(const std::string& str) {
|
||||
return result;
|
||||
}
|
||||
|
||||
std::pair<bool, std::string> GetExecutableDirectoryPath() {
|
||||
auto path = GetExecutablePath();
|
||||
if (!path.first) {
|
||||
return {false, ""};
|
||||
}
|
||||
return {true, fml::paths::GetDirectoryName(path.second)};
|
||||
}
|
||||
|
||||
} // namespace paths
|
||||
} // namespace fml
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
namespace fml {
|
||||
namespace paths {
|
||||
|
||||
std::pair<bool, std::string> GetExecutablePath();
|
||||
std::pair<bool, std::string> GetExecutableDirectoryPath();
|
||||
|
||||
// Get the directory to the application's caches directory.
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
namespace fml {
|
||||
namespace paths {
|
||||
|
||||
std::pair<bool, std::string> GetExecutableDirectoryPath() {
|
||||
std::pair<bool, std::string> GetExecutablePath() {
|
||||
return {false, ""};
|
||||
}
|
||||
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
namespace fml {
|
||||
namespace paths {
|
||||
|
||||
std::pair<bool, std::string> GetExecutableDirectoryPath() {
|
||||
std::pair<bool, std::string> GetExecutablePath() {
|
||||
@autoreleasepool {
|
||||
return {true, GetDirectoryName([NSBundle mainBundle].executablePath.UTF8String)};
|
||||
return {true, [NSBundle mainBundle].executablePath.UTF8String};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
namespace fml {
|
||||
namespace paths {
|
||||
|
||||
std::pair<bool, std::string> GetExecutableDirectoryPath() {
|
||||
std::pair<bool, std::string> GetExecutablePath() {
|
||||
return {false, ""};
|
||||
}
|
||||
|
||||
|
||||
@@ -9,15 +9,14 @@
|
||||
namespace fml {
|
||||
namespace paths {
|
||||
|
||||
std::pair<bool, std::string> GetExecutableDirectoryPath() {
|
||||
std::pair<bool, std::string> GetExecutablePath() {
|
||||
const int path_size = 255;
|
||||
char path[path_size] = {0};
|
||||
auto read_size = ::readlink("/proc/self/exe", path, path_size);
|
||||
if (read_size == -1) {
|
||||
return {false, ""};
|
||||
}
|
||||
return {true, fml::paths::GetDirectoryName(
|
||||
std::string{path, static_cast<size_t>(read_size)})};
|
||||
return {true, std::string{path, static_cast<size_t>(read_size)}};
|
||||
}
|
||||
|
||||
fml::UniqueFD GetCachesDirectory() {
|
||||
|
||||
@@ -53,7 +53,7 @@ size_t LastSeparator(const std::string& path) {
|
||||
|
||||
} // namespace
|
||||
|
||||
std::pair<bool, std::string> GetExecutableDirectoryPath() {
|
||||
std::pair<bool, std::string> GetExecutablePath() {
|
||||
HMODULE module = GetModuleHandle(NULL);
|
||||
if (module == NULL) {
|
||||
return {false, ""};
|
||||
@@ -63,7 +63,7 @@ std::pair<bool, std::string> GetExecutableDirectoryPath() {
|
||||
if (read_size == 0 || read_size == MAX_PATH) {
|
||||
return {false, ""};
|
||||
}
|
||||
return {true, GetDirectoryName(std::string{path, read_size})};
|
||||
return {true, std::string{path, read_size}};
|
||||
}
|
||||
|
||||
std::string AbsolutePath(const std::string& path) {
|
||||
|
||||
Reference in New Issue
Block a user