diff options
author | Colin Cross <ccross@android.com> | 2021-09-14 11:56:31 -0700 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2021-09-14 15:51:35 -0700 |
commit | 98ef35a53c2632ec1d25bbda9435f3261e0f1c64 (patch) | |
tree | e4f23e5b94171788abcdbb217039d856045bf8fb | |
parent | 863ec57b2691763ae5f36267526e86c459fd8dea (diff) | |
download | unwinding-98ef35a53c2632ec1d25bbda9435f3261e0f1c64.tar.gz |
Fix system/unwinding building against musl
musl only provides the posix version of basename, which is slightly
different from the gnu version used here. Switch to the libbase
version instead.
Bug: 190084016
Test: m USE_HOST_MUSL=true
Change-Id: I6e436b95f01a2b6313230ba40d801799590bb11a
-rw-r--r-- | libbacktrace/BacktraceCurrent.cpp | 3 | ||||
-rw-r--r-- | libbacktrace/backtrace_test.cpp | 5 | ||||
-rw-r--r-- | libunwindstack/Global.cpp | 4 | ||||
-rw-r--r-- | libunwindstack/Unwinder.cpp | 3 | ||||
-rw-r--r-- | libunwindstack/tools/unwind_for_offline.cpp | 6 | ||||
-rw-r--r-- | libunwindstack/utils/ProcessTracer.cpp | 4 |
6 files changed, 16 insertions, 9 deletions
diff --git a/libbacktrace/BacktraceCurrent.cpp b/libbacktrace/BacktraceCurrent.cpp index a506575..84c7bc8 100644 --- a/libbacktrace/BacktraceCurrent.cpp +++ b/libbacktrace/BacktraceCurrent.cpp @@ -28,6 +28,7 @@ #include <string> +#include <android-base/file.h> #include <android-base/threads.h> #include <backtrace/Backtrace.h> #include <backtrace/BacktraceMap.h> @@ -97,7 +98,7 @@ bool BacktraceCurrent::Unwind(size_t num_ignore_frames, void* ucontext) { bool BacktraceCurrent::DiscardFrame(const backtrace_frame_data_t& frame) { if (BacktraceMap::IsValid(frame.map)) { - const std::string library = basename(frame.map.name.c_str()); + const std::string library = android::base::Basename(frame.map.name); if (library == "libunwind.so" || library == "libbacktrace.so") { return true; } diff --git a/libbacktrace/backtrace_test.cpp b/libbacktrace/backtrace_test.cpp index a9160d5..b978349 100644 --- a/libbacktrace/backtrace_test.cpp +++ b/libbacktrace/backtrace_test.cpp @@ -45,6 +45,7 @@ #include <backtrace/Backtrace.h> #include <backtrace/BacktraceMap.h> +#include <android-base/file.h> #include <android-base/macros.h> #include <android-base/stringprintf.h> #include <android-base/test_utils.h> @@ -281,7 +282,7 @@ TEST_F(BacktraceTest, local_no_unwind_frames) { // None of the frames should be in the backtrace libraries. for (const auto& frame : *backtrace ) { if (BacktraceMap::IsValid(frame.map)) { - const std::string name = basename(frame.map.name.c_str()); + const std::string name = android::base::Basename(frame.map.name); for (const auto& lib : kBacktraceLibs) { ASSERT_TRUE(name != lib) << DumpFrames(backtrace.get()); } @@ -302,7 +303,7 @@ TEST_F(BacktraceTest, local_unwind_frames) { size_t first_frame_non_backtrace_lib = 0; for (const auto& frame : *backtrace) { if (BacktraceMap::IsValid(frame.map)) { - const std::string name = basename(frame.map.name.c_str()); + const std::string name = android::base::Basename(frame.map.name); bool found = false; for (const auto& lib : kBacktraceLibs) { if (name == lib) { diff --git a/libunwindstack/Global.cpp b/libunwindstack/Global.cpp index b8adc5c..0ad6945 100644 --- a/libunwindstack/Global.cpp +++ b/libunwindstack/Global.cpp @@ -21,6 +21,8 @@ #include <string> #include <vector> +#include <android-base/file.h> + #include <unwindstack/Global.h> #include <unwindstack/MapInfo.h> #include <unwindstack/Maps.h> @@ -48,7 +50,7 @@ bool Global::Searchable(const std::string& name) { return false; } - const char* base_name = basename(name.c_str()); + std::string base_name = android::base::Basename(name); for (const std::string& lib : search_libs_) { if (base_name == lib) { return true; diff --git a/libunwindstack/Unwinder.cpp b/libunwindstack/Unwinder.cpp index bd34465..592f021 100644 --- a/libunwindstack/Unwinder.cpp +++ b/libunwindstack/Unwinder.cpp @@ -25,6 +25,7 @@ #include <algorithm> +#include <android-base/file.h> #include <android-base/stringprintf.h> #include <android-base/strings.h> @@ -217,7 +218,7 @@ void Unwinder::Unwind(const std::vector<std::string>* initial_map_names_to_skip, FrameData* frame = nullptr; if (map_info == nullptr || initial_map_names_to_skip == nullptr || std::find(initial_map_names_to_skip->begin(), initial_map_names_to_skip->end(), - basename(map_info->name().c_str())) == initial_map_names_to_skip->end()) { + android::base::Basename(map_info->name())) == initial_map_names_to_skip->end()) { if (regs_->dex_pc() != 0) { // Add a frame to represent the dex file. FillInDexFrame(); diff --git a/libunwindstack/tools/unwind_for_offline.cpp b/libunwindstack/tools/unwind_for_offline.cpp index 3036d6f..25e0b59 100644 --- a/libunwindstack/tools/unwind_for_offline.cpp +++ b/libunwindstack/tools/unwind_for_offline.cpp @@ -37,6 +37,7 @@ #include <unwindstack/Unwinder.h> #include "utils/ProcessTracer.h" +#include <android-base/file.h> #include <android-base/parseint.h> #include <android-base/stringprintf.h> @@ -158,7 +159,8 @@ bool CreateElfFromMemory(std::shared_ptr<unwindstack::Memory>& memory, map_info_ if (info->name.empty()) { cur_name = android::base::StringPrintf("anonymous_%" PRIx64, info->start); } else { - cur_name = android::base::StringPrintf("%s_%" PRIx64, basename(info->name.c_str()), info->start); + cur_name = android::base::StringPrintf( + "%s_%" PRIx64, android::base::Basename(info->name).c_str(), info->start); } std::vector<uint8_t> buffer(info->end - info->start); @@ -191,7 +193,7 @@ bool CreateElfFromMemory(std::shared_ptr<unwindstack::Memory>& memory, map_info_ } bool CopyElfFromFile(map_info_t* info, bool* file_copied) { - std::string cur_name = basename(info->name.c_str()); + std::string cur_name = android::base::Basename(info->name); if (*file_copied) { info->name = cur_name; return true; diff --git a/libunwindstack/utils/ProcessTracer.cpp b/libunwindstack/utils/ProcessTracer.cpp index db7be32..6ce34eb 100644 --- a/libunwindstack/utils/ProcessTracer.cpp +++ b/libunwindstack/utils/ProcessTracer.cpp @@ -184,7 +184,7 @@ bool ProcessTracer::UsesSharedLibrary(pid_t pid, const std::string& desired_elf_ return false; } for (const auto& map : *maps) { - if (basename(map->name().c_str()) == desired_elf_name) return true; + if (android::base::Basename(map->name()).c_str() == desired_elf_name) return true; } return false; } @@ -211,7 +211,7 @@ bool ProcessTracer::ProcIsInDesiredElf(pid_t pid, const std::string& desired_elf } } - const std::string& current_elf_name = basename(map_info->name().c_str()); + const std::string& current_elf_name = android::base::Basename(map_info->name()).c_str(); bool in_desired_elf = current_elf_name == desired_elf_name; if (in_desired_elf) printf("pid %d is in %s! Unwinding...\n\n", pid, desired_elf_name.c_str()); return in_desired_elf; |