Merge "Add an interface for stopping in certain maps."
diff --git a/libbacktrace/UnwindStack.cpp b/libbacktrace/UnwindStack.cpp
index 4c0c1a8..c3f08c8 100644
--- a/libbacktrace/UnwindStack.cpp
+++ b/libbacktrace/UnwindStack.cpp
@@ -45,12 +45,12 @@
bool Backtrace::Unwind(unwindstack::Regs* regs, BacktraceMap* back_map,
std::vector<backtrace_frame_data_t>* frames, size_t num_ignore_frames) {
- static std::set<std::string> skip_names{"libunwindstack.so", "libbacktrace.so"};
+ static std::vector<std::string> skip_names{"libunwindstack.so", "libbacktrace.so"};
UnwindStackMap* stack_map = reinterpret_cast<UnwindStackMap*>(back_map);
auto process_memory = stack_map->process_memory();
unwindstack::Unwinder unwinder(MAX_BACKTRACE_FRAMES + num_ignore_frames, stack_map->stack_maps(),
regs, stack_map->process_memory());
- unwinder.Unwind(&skip_names);
+ unwinder.Unwind(&skip_names, &stack_map->GetSuffixesToIgnore());
if (num_ignore_frames >= unwinder.NumFrames()) {
frames->resize(0);
diff --git a/libbacktrace/include/backtrace/BacktraceMap.h b/libbacktrace/include/backtrace/BacktraceMap.h
index e176c78..84e7132 100644
--- a/libbacktrace/include/backtrace/BacktraceMap.h
+++ b/libbacktrace/include/backtrace/BacktraceMap.h
@@ -107,13 +107,20 @@
return map.end > 0;
}
-protected:
+ void SetSuffixesToIgnore(std::vector<std::string> suffixes) {
+ suffixes_to_ignore_.insert(suffixes_to_ignore_.end(), suffixes.begin(), suffixes.end());
+ }
+
+ const std::vector<std::string>& GetSuffixesToIgnore() { return suffixes_to_ignore_; }
+
+ protected:
BacktraceMap(pid_t pid);
virtual bool ParseLine(const char* line, backtrace_map_t* map);
- std::deque<backtrace_map_t> maps_;
pid_t pid_;
+ std::deque<backtrace_map_t> maps_;
+ std::vector<std::string> suffixes_to_ignore_;
};
class ScopedBacktraceMapIteratorLock {
diff --git a/libunwindstack/Unwinder.cpp b/libunwindstack/Unwinder.cpp
index f1580a4..2190711 100644
--- a/libunwindstack/Unwinder.cpp
+++ b/libunwindstack/Unwinder.cpp
@@ -22,6 +22,8 @@
#include <sys/types.h>
#include <unistd.h>
+#include <algorithm>
+
#include <android-base/stringprintf.h>
#include <unwindstack/Elf.h>
@@ -64,7 +66,8 @@
}
}
-static bool ShouldStop(const std::set<std::string>* map_suffixes_to_ignore, std::string& map_name) {
+static bool ShouldStop(const std::vector<std::string>* map_suffixes_to_ignore,
+ std::string& map_name) {
if (map_suffixes_to_ignore == nullptr) {
return false;
}
@@ -72,11 +75,13 @@
if (pos == std::string::npos) {
return false;
}
- return map_suffixes_to_ignore->find(map_name.substr(pos + 1)) != map_suffixes_to_ignore->end();
+
+ return std::find(map_suffixes_to_ignore->begin(), map_suffixes_to_ignore->end(),
+ map_name.substr(pos + 1)) != map_suffixes_to_ignore->end();
}
-void Unwinder::Unwind(const std::set<std::string>* initial_map_names_to_skip,
- const std::set<std::string>* map_suffixes_to_ignore) {
+void Unwinder::Unwind(const std::vector<std::string>* initial_map_names_to_skip,
+ const std::vector<std::string>* map_suffixes_to_ignore) {
frames_.clear();
bool return_address_attempt = false;
@@ -97,8 +102,8 @@
}
if (map_info == nullptr || initial_map_names_to_skip == nullptr ||
- initial_map_names_to_skip->find(basename(map_info->name.c_str())) ==
- initial_map_names_to_skip->end()) {
+ 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()) {
FillInFrame(map_info, elf, rel_pc, adjust_pc);
// Once a frame is added, stop skipping frames.
initial_map_names_to_skip = nullptr;
diff --git a/libunwindstack/include/unwindstack/Unwinder.h b/libunwindstack/include/unwindstack/Unwinder.h
index ca5933d..37a76b2 100644
--- a/libunwindstack/include/unwindstack/Unwinder.h
+++ b/libunwindstack/include/unwindstack/Unwinder.h
@@ -21,7 +21,6 @@
#include <sys/types.h>
#include <memory>
-#include <set>
#include <string>
#include <vector>
@@ -60,8 +59,8 @@
}
~Unwinder() = default;
- void Unwind(const std::set<std::string>* initial_map_names_to_skip = nullptr,
- const std::set<std::string>* map_suffixes_to_ignore = nullptr);
+ void Unwind(const std::vector<std::string>* initial_map_names_to_skip = nullptr,
+ const std::vector<std::string>* map_suffixes_to_ignore = nullptr);
size_t NumFrames() { return frames_.size(); }
diff --git a/libunwindstack/tests/UnwinderTest.cpp b/libunwindstack/tests/UnwinderTest.cpp
index 8384473..8a90bae 100644
--- a/libunwindstack/tests/UnwinderTest.cpp
+++ b/libunwindstack/tests/UnwinderTest.cpp
@@ -308,8 +308,8 @@
ElfInterfaceFake::FakePushStepData(StepData(0, 0, true));
Unwinder unwinder(64, &maps_, ®s_, process_memory_);
- std::set<std::string> skip_set{"libunwind.so", "libanother.so"};
- unwinder.Unwind(&skip_set);
+ std::vector<std::string> skip_libs{"libunwind.so", "libanother.so"};
+ unwinder.Unwind(&skip_libs);
ASSERT_EQ(3U, unwinder.NumFrames());
@@ -572,7 +572,7 @@
ElfInterfaceFake::FakePushStepData(StepData(0, 0, true));
Unwinder unwinder(64, &maps_, ®s_, process_memory_);
- std::set<std::string> suffixes{"oat"};
+ std::vector<std::string> suffixes{"oat"};
unwinder.Unwind(nullptr, &suffixes);
ASSERT_EQ(2U, unwinder.NumFrames());