diff options
author | Christopher Ferris <cferris@google.com> | 2017-12-01 21:37:37 -0800 |
---|---|---|
committer | Christopher Ferris <cferris@google.com> | 2017-12-05 13:12:47 -0800 |
commit | b7de5f542925216dbb8b7124260d2915570598d1 (patch) | |
tree | 2126153a21557204dd60a05605c4aa0445155b11 /libbacktrace/include/backtrace/BacktraceMap.h | |
parent | ebca57adecb3521d78e4e1e5c220df897f84e336 (diff) | |
download | system_core-b7de5f542925216dbb8b7124260d2915570598d1.tar.gz system_core-b7de5f542925216dbb8b7124260d2915570598d1.tar.bz2 system_core-b7de5f542925216dbb8b7124260d2915570598d1.zip |
Demand read load bias for a map.
Add a static GetLoadBias method to the Elf object that only reads just
enough to get the load bias.
Add a method to MapInfo that gets the load bias. First attempt to get
it if the elf object already exists. If no elf object was created, use
the new static method to get the load bias.
In BacktraceMap, add a custom iterator so that when code dereferences
a map element, that's when the load bias will be retrieved if it hasn't
already been set.
Bug: 69871050
Test: New unit tests, verify tombstones have non-zero load bias values for
Test: libraries with a non-zero load bias.
Change-Id: I125f4abc827589957fce2f0df24b0f25d037d732
Diffstat (limited to 'libbacktrace/include/backtrace/BacktraceMap.h')
-rw-r--r-- | libbacktrace/include/backtrace/BacktraceMap.h | 54 |
1 files changed, 46 insertions, 8 deletions
diff --git a/libbacktrace/include/backtrace/BacktraceMap.h b/libbacktrace/include/backtrace/BacktraceMap.h index d0783929a..4ae68dde0 100644 --- a/libbacktrace/include/backtrace/BacktraceMap.h +++ b/libbacktrace/include/backtrace/BacktraceMap.h @@ -30,6 +30,7 @@ #endif #include <deque> +#include <iterator> #include <string> #include <vector> @@ -61,6 +62,49 @@ public: virtual ~BacktraceMap(); + class iterator : public std::iterator<std::bidirectional_iterator_tag, backtrace_map_t*> { + public: + iterator(BacktraceMap* map, size_t index) : map_(map), index_(index) {} + + iterator& operator++() { + index_++; + return *this; + } + iterator& operator++(int increment) { + index_ += increment; + return *this; + } + iterator& operator--() { + index_--; + return *this; + } + iterator& operator--(int decrement) { + index_ -= decrement; + return *this; + } + + bool operator==(const iterator& rhs) { return this->index_ == rhs.index_; } + bool operator!=(const iterator& rhs) { return this->index_ != rhs.index_; } + + const backtrace_map_t* operator*() { + if (index_ >= map_->size()) { + return nullptr; + } + backtrace_map_t* map = &map_->maps_[index_]; + if (map->load_bias == static_cast<uintptr_t>(-1)) { + map->load_bias = map_->GetLoadBias(index_); + } + return map; + } + + private: + BacktraceMap* map_ = nullptr; + size_t index_ = 0; + }; + + iterator begin() { return iterator(this, 0); } + iterator end() { return iterator(this, maps_.size()); } + // Fill in the map data structure for the given address. virtual void FillIn(uintptr_t addr, backtrace_map_t* map); @@ -89,14 +133,6 @@ public: virtual void LockIterator() {} virtual void UnlockIterator() {} - typedef std::deque<backtrace_map_t>::iterator iterator; - iterator begin() { return maps_.begin(); } - iterator end() { return maps_.end(); } - - typedef std::deque<backtrace_map_t>::const_iterator const_iterator; - const_iterator begin() const { return maps_.begin(); } - const_iterator end() const { return maps_.end(); } - size_t size() const { return maps_.size(); } virtual bool Build(); @@ -114,6 +150,8 @@ public: protected: BacktraceMap(pid_t pid); + virtual uint64_t GetLoadBias(size_t /* index */) { return 0; } + virtual bool ParseLine(const char* line, backtrace_map_t* map); pid_t pid_; |