Merge "Add an interface for stopping in certain maps."

This commit is contained in:
Christopher Ferris 2017-10-25 19:18:21 +00:00 committed by Gerrit Code Review
commit 3adedf9895
5 changed files with 27 additions and 16 deletions

View File

@ -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);

View File

@ -107,13 +107,20 @@ public:
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 {

View File

@ -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 @@ void Unwinder::FillInFrame(MapInfo* map_info, Elf* elf, uint64_t rel_pc, bool ad
}
}
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 @@ static bool ShouldStop(const std::set<std::string>* map_suffixes_to_ignore, std:
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 @@ void Unwinder::Unwind(const std::set<std::string>* initial_map_names_to_skip,
}
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;

View File

@ -21,7 +21,6 @@
#include <sys/types.h>
#include <memory>
#include <set>
#include <string>
#include <vector>
@ -60,8 +59,8 @@ class Unwinder {
}
~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(); }

View File

@ -308,8 +308,8 @@ TEST_F(UnwinderTest, verify_frames_skipped) {
ElfInterfaceFake::FakePushStepData(StepData(0, 0, true));
Unwinder unwinder(64, &maps_, &regs_, 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 @@ TEST_F(UnwinderTest, map_ignore_suffixes) {
ElfInterfaceFake::FakePushStepData(StepData(0, 0, true));
Unwinder unwinder(64, &maps_, &regs_, process_memory_);
std::set<std::string> suffixes{"oat"};
std::vector<std::string> suffixes{"oat"};
unwinder.Unwind(nullptr, &suffixes);
ASSERT_EQ(2U, unwinder.NumFrames());