diff --git a/engine/src/flutter/fml/BUILD.gn b/engine/src/flutter/fml/BUILD.gn index 267f7f193e..e0452219a2 100644 --- a/engine/src/flutter/fml/BUILD.gn +++ b/engine/src/flutter/fml/BUILD.gn @@ -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. diff --git a/engine/src/flutter/fml/backtrace.cc b/engine/src/flutter/fml/backtrace.cc index cf6fc21bd0..1a9fbdd4ae 100644 --- a/engine/src/flutter/fml/backtrace.cc +++ b/engine/src/flutter/fml/backtrace.cc @@ -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); } diff --git a/engine/src/flutter/fml/paths.cc b/engine/src/flutter/fml/paths.cc index 1566726f05..b55f447cb1 100644 --- a/engine/src/flutter/fml/paths.cc +++ b/engine/src/flutter/fml/paths.cc @@ -52,5 +52,13 @@ std::string SanitizeURIEscapedCharacters(const std::string& str) { return result; } +std::pair GetExecutableDirectoryPath() { + auto path = GetExecutablePath(); + if (!path.first) { + return {false, ""}; + } + return {true, fml::paths::GetDirectoryName(path.second)}; +} + } // namespace paths } // namespace fml diff --git a/engine/src/flutter/fml/paths.h b/engine/src/flutter/fml/paths.h index 69408317a2..b692a7b9e7 100644 --- a/engine/src/flutter/fml/paths.h +++ b/engine/src/flutter/fml/paths.h @@ -13,6 +13,7 @@ namespace fml { namespace paths { +std::pair GetExecutablePath(); std::pair GetExecutableDirectoryPath(); // Get the directory to the application's caches directory. diff --git a/engine/src/flutter/fml/platform/android/paths_android.cc b/engine/src/flutter/fml/platform/android/paths_android.cc index 36f5844a15..0df6d0ec44 100644 --- a/engine/src/flutter/fml/platform/android/paths_android.cc +++ b/engine/src/flutter/fml/platform/android/paths_android.cc @@ -9,7 +9,7 @@ namespace fml { namespace paths { -std::pair GetExecutableDirectoryPath() { +std::pair GetExecutablePath() { return {false, ""}; } diff --git a/engine/src/flutter/fml/platform/darwin/paths_darwin.mm b/engine/src/flutter/fml/platform/darwin/paths_darwin.mm index 72e6f35a80..1ce0ebfbae 100644 --- a/engine/src/flutter/fml/platform/darwin/paths_darwin.mm +++ b/engine/src/flutter/fml/platform/darwin/paths_darwin.mm @@ -11,9 +11,9 @@ namespace fml { namespace paths { -std::pair GetExecutableDirectoryPath() { +std::pair GetExecutablePath() { @autoreleasepool { - return {true, GetDirectoryName([NSBundle mainBundle].executablePath.UTF8String)}; + return {true, [NSBundle mainBundle].executablePath.UTF8String}; } } diff --git a/engine/src/flutter/fml/platform/fuchsia/paths_fuchsia.cc b/engine/src/flutter/fml/platform/fuchsia/paths_fuchsia.cc index e26b32d8ce..47c29b9792 100644 --- a/engine/src/flutter/fml/platform/fuchsia/paths_fuchsia.cc +++ b/engine/src/flutter/fml/platform/fuchsia/paths_fuchsia.cc @@ -8,7 +8,7 @@ namespace fml { namespace paths { -std::pair GetExecutableDirectoryPath() { +std::pair GetExecutablePath() { return {false, ""}; } diff --git a/engine/src/flutter/fml/platform/linux/paths_linux.cc b/engine/src/flutter/fml/platform/linux/paths_linux.cc index 41983819b6..6d77eb07d3 100644 --- a/engine/src/flutter/fml/platform/linux/paths_linux.cc +++ b/engine/src/flutter/fml/platform/linux/paths_linux.cc @@ -9,15 +9,14 @@ namespace fml { namespace paths { -std::pair GetExecutableDirectoryPath() { +std::pair 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(read_size)})}; + return {true, std::string{path, static_cast(read_size)}}; } fml::UniqueFD GetCachesDirectory() { diff --git a/engine/src/flutter/fml/platform/win/paths_win.cc b/engine/src/flutter/fml/platform/win/paths_win.cc index 6787a56ee1..4a94e5b656 100644 --- a/engine/src/flutter/fml/platform/win/paths_win.cc +++ b/engine/src/flutter/fml/platform/win/paths_win.cc @@ -53,7 +53,7 @@ size_t LastSeparator(const std::string& path) { } // namespace -std::pair GetExecutableDirectoryPath() { +std::pair GetExecutablePath() { HMODULE module = GetModuleHandle(NULL); if (module == NULL) { return {false, ""}; @@ -63,7 +63,7 @@ std::pair 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) {