summaryrefslogtreecommitdiff
path: root/libunwindstack/include/unwindstack
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2018-06-21 10:44:02 -0700
committerChristopher Ferris <cferris@google.com>2018-06-27 14:52:21 -0700
commiteeaea0910e0b5892b615efa9b7c2370b94cc1f30 (patch)
tree84c490bfd12e1c940c2b350916c0e8b3cb43afe2 /libunwindstack/include/unwindstack
parentd553837a4bb69cad8f18ce3c596c407ffd3adda1 (diff)
downloadunwinding-eeaea0910e0b5892b615efa9b7c2370b94cc1f30.tar.gz
Refactor the DwarfSection classes.
Modify the code for the no header sections because it turns out that it is not okay to assume that the fdes are non-overlapping. It's necessary to read the fdes in order and match as you go. Modify the code so that it only reads until it finds the given pc rather than reading all of the cie/fde entries at once. Rewrote the tests to verify the new behavior. Bug: 68998033 Bug: 110235461 Test: Ran libbacktrace/libunwindstack unit tests. Test: Unwind the mediaserver process on a walleye and verify it Test: unwinds properly. Change-Id: I7bb59d1db72c13fa34caa9735ec34c1a60e20ed2
Diffstat (limited to 'libunwindstack/include/unwindstack')
-rw-r--r--libunwindstack/include/unwindstack/DwarfSection.h97
1 files changed, 59 insertions, 38 deletions
diff --git a/libunwindstack/include/unwindstack/DwarfSection.h b/libunwindstack/include/unwindstack/DwarfSection.h
index 847f382..e9942de 100644
--- a/libunwindstack/include/unwindstack/DwarfSection.h
+++ b/libunwindstack/include/unwindstack/DwarfSection.h
@@ -43,7 +43,12 @@ class DwarfSection {
class iterator : public std::iterator<std::bidirectional_iterator_tag, DwarfFde*> {
public:
- iterator(DwarfSection* section, size_t index) : section_(section), index_(index) {}
+ iterator(DwarfSection* section, size_t index) : index_(index) {
+ section->GetFdes(&fdes_);
+ if (index_ == static_cast<size_t>(-1)) {
+ index_ = fdes_.size();
+ }
+ }
iterator& operator++() {
index_++;
@@ -65,15 +70,18 @@ class DwarfSection {
bool operator==(const iterator& rhs) { return this->index_ == rhs.index_; }
bool operator!=(const iterator& rhs) { return this->index_ != rhs.index_; }
- const DwarfFde* operator*() { return section_->GetFdeFromIndex(index_); }
+ const DwarfFde* operator*() {
+ if (index_ > fdes_.size()) return nullptr;
+ return fdes_[index_];
+ }
private:
- DwarfSection* section_ = nullptr;
+ std::vector<const DwarfFde*> fdes_;
size_t index_ = 0;
};
iterator begin() { return iterator(this, 0); }
- iterator end() { return iterator(this, fde_count_); }
+ iterator end() { return iterator(this, static_cast<size_t>(-1)); }
DwarfErrorCode LastErrorCode() { return last_error_.code; }
uint64_t LastErrorAddress() { return last_error_.address; }
@@ -82,15 +90,11 @@ class DwarfSection {
virtual bool Eval(const DwarfCie*, Memory*, const dwarf_loc_regs_t&, Regs*, bool*) = 0;
- virtual bool GetFdeOffsetFromPc(uint64_t pc, uint64_t* fde_offset) = 0;
-
virtual bool Log(uint8_t indent, uint64_t pc, const DwarfFde* fde) = 0;
- virtual const DwarfFde* GetFdeFromIndex(size_t index) = 0;
-
- const DwarfFde* GetFdeFromPc(uint64_t pc);
+ virtual void GetFdes(std::vector<const DwarfFde*>* fdes) = 0;
- virtual const DwarfFde* GetFdeFromOffset(uint64_t fde_offset) = 0;
+ virtual const DwarfFde* GetFdeFromPc(uint64_t pc) = 0;
virtual bool GetCfaLocationInfo(uint64_t pc, const DwarfFde* fde, dwarf_loc_regs_t* loc_regs) = 0;
@@ -109,7 +113,6 @@ class DwarfSection {
uint32_t cie32_value_ = 0;
uint64_t cie64_value_ = 0;
- uint64_t fde_count_ = 0;
std::unordered_map<uint64_t, DwarfFde> fde_entries_;
std::unordered_map<uint64_t, DwarfCie> cie_entries_;
std::unordered_map<uint64_t, dwarf_loc_regs_t> cie_loc_regs_;
@@ -119,55 +122,73 @@ class DwarfSection {
template <typename AddressType>
class DwarfSectionImpl : public DwarfSection {
public:
- struct FdeInfo {
- FdeInfo(uint64_t offset, uint64_t start, uint64_t length)
- : offset(offset), start(start), end(start + length) {}
-
- uint64_t offset;
- AddressType start;
- AddressType end;
- };
-
DwarfSectionImpl(Memory* memory) : DwarfSection(memory) {}
virtual ~DwarfSectionImpl() = default;
- bool Init(uint64_t offset, uint64_t size, uint64_t load_bias) override;
-
- bool GetFdeOffsetFromPc(uint64_t pc, uint64_t* fde_offset) override;
+ const DwarfCie* GetCieFromOffset(uint64_t offset);
- const DwarfFde* GetFdeFromIndex(size_t index) override;
+ const DwarfFde* GetFdeFromOffset(uint64_t offset);
bool EvalRegister(const DwarfLocation* loc, uint32_t reg, AddressType* reg_ptr, void* info);
bool Eval(const DwarfCie* cie, Memory* regular_memory, const dwarf_loc_regs_t& loc_regs,
Regs* regs, bool* finished) override;
- const DwarfCie* GetCie(uint64_t offset);
- bool FillInCie(DwarfCie* cie);
-
- const DwarfFde* GetFdeFromOffset(uint64_t offset) override;
- bool FillInFde(DwarfFde* fde);
-
bool GetCfaLocationInfo(uint64_t pc, const DwarfFde* fde, dwarf_loc_regs_t* loc_regs) override;
bool Log(uint8_t indent, uint64_t pc, const DwarfFde* fde) override;
protected:
- bool EvalExpression(const DwarfLocation& loc, Memory* regular_memory, AddressType* value,
- RegsInfo<AddressType>* regs_info, bool* is_dex_pc);
+ bool FillInCieHeader(DwarfCie* cie);
+
+ bool FillInCie(DwarfCie* cie);
- bool GetCieInfo(uint8_t* segment_size, uint8_t* encoding);
+ bool FillInFdeHeader(DwarfFde* fde);
- bool AddFdeInfo(uint64_t entry_offset, uint8_t segment_size, uint8_t encoding);
+ bool FillInFde(DwarfFde* fde);
- bool CreateSortedFdeList();
+ bool EvalExpression(const DwarfLocation& loc, Memory* regular_memory, AddressType* value,
+ RegsInfo<AddressType>* regs_info, bool* is_dex_pc);
uint64_t load_bias_ = 0;
+ uint64_t entries_offset_ = 0;
+ uint64_t entries_end_ = 0;
uint64_t pc_offset_ = 0;
+};
+
+template <typename AddressType>
+class DwarfSectionImplNoHdr : public DwarfSectionImpl<AddressType> {
+ public:
+ // Add these so that the protected members of DwarfSectionImpl
+ // can be accessed without needing a this->.
+ using DwarfSectionImpl<AddressType>::memory_;
+ using DwarfSectionImpl<AddressType>::pc_offset_;
+ using DwarfSectionImpl<AddressType>::entries_offset_;
+ using DwarfSectionImpl<AddressType>::entries_end_;
+ using DwarfSectionImpl<AddressType>::last_error_;
+ using DwarfSectionImpl<AddressType>::load_bias_;
+ using DwarfSectionImpl<AddressType>::cie_entries_;
+ using DwarfSectionImpl<AddressType>::fde_entries_;
+ using DwarfSectionImpl<AddressType>::cie32_value_;
+ using DwarfSectionImpl<AddressType>::cie64_value_;
+
+ DwarfSectionImplNoHdr(Memory* memory) : DwarfSectionImpl<AddressType>(memory) {}
+ virtual ~DwarfSectionImplNoHdr() = default;
+
+ bool Init(uint64_t offset, uint64_t size, uint64_t load_bias) override;
+
+ const DwarfFde* GetFdeFromPc(uint64_t pc) override;
+
+ void GetFdes(std::vector<const DwarfFde*>* fdes) override;
+
+ protected:
+ bool GetNextCieOrFde(DwarfFde** fde_entry);
+
+ void InsertFde(const DwarfFde* fde);
+
+ uint64_t next_entries_offset_ = 0;
- std::vector<FdeInfo> fdes_;
- uint64_t entries_offset_;
- uint64_t entries_end_;
+ std::map<uint64_t, std::pair<uint64_t, const DwarfFde*>> fdes_;
};
} // namespace unwindstack