diff options
author | Christopher Ferris <cferris@google.com> | 2017-07-14 10:37:19 -0700 |
---|---|---|
committer | Christopher Ferris <cferris@google.com> | 2017-07-14 12:20:23 -0700 |
commit | 81e61fa6964dfa45301b555ea1ae000bb97df07b (patch) | |
tree | 3b5a8dbdb189045d23108e26e6d0a2f4ca11940e /libunwindstack/Elf.cpp | |
parent | c29ea6ea7802b15fa4eb07b02a4e73b599b3cc21 (diff) | |
download | unwinding-81e61fa6964dfa45301b555ea1ae000bb97df07b.tar.gz |
Make the library usable as a library.
- Add namespace unwindstack everywhere so that it's easier for other
code to use the library.
- Move some of the header files into include/unwindstack so that they
can be exposed.
- Modify the headers so that only a limited number need to be exposed.
- Update the tools to use the new headers.
- Add a GetLoadBias() call on the Elf object. This prevents the need
to get the interface object out of the Elf object.
- Move the GetRelPc() call out of the Reg class, to the Elf class. It's
not always the case that a Reg object will be around when you want to
get a relative pc. The tests for this moved to ElfTest.cpp.
Bug: 23762183
Test: Unit tests pass.
Change-Id: Iac609dac1dd90ed83d1a1e24ff2579c96c023bc3
Diffstat (limited to 'libunwindstack/Elf.cpp')
-rw-r--r-- | libunwindstack/Elf.cpp | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/libunwindstack/Elf.cpp b/libunwindstack/Elf.cpp index ad1447a..a800c31 100644 --- a/libunwindstack/Elf.cpp +++ b/libunwindstack/Elf.cpp @@ -23,12 +23,17 @@ #define LOG_TAG "unwind" #include <log/log.h> -#include "Elf.h" -#include "ElfInterface.h" +#include <unwindstack/Elf.h> +#include <unwindstack/ElfInterface.h> +#include <unwindstack/MapInfo.h> +#include <unwindstack/Memory.h> +#include <unwindstack/Regs.h> + #include "ElfInterfaceArm.h" #include "Machine.h" -#include "Memory.h" -#include "Regs.h" +#include "Symbols.h" + +namespace unwindstack { bool Elf::Init() { if (!memory_) { @@ -71,6 +76,36 @@ void Elf::InitGnuDebugdata() { } } +bool Elf::GetSoname(std::string* name) { + return valid_ && interface_->GetSoname(name); +} + +uint64_t Elf::GetRelPc(uint64_t pc, const MapInfo* map_info) { + uint64_t load_bias = 0; + if (valid()) { + load_bias = interface_->load_bias(); + } + + return pc - map_info->start + load_bias + map_info->elf_offset; +} + +bool Elf::GetFunctionName(uint64_t addr, std::string* name, uint64_t* func_offset) { + return valid_ && (interface_->GetFunctionName(addr, name, func_offset) || + (gnu_debugdata_interface_ && + gnu_debugdata_interface_->GetFunctionName(addr, name, func_offset))); +} + +bool Elf::Step(uint64_t rel_pc, Regs* regs, Memory* process_memory) { + return valid_ && (interface_->Step(rel_pc, regs, process_memory) || + (gnu_debugdata_interface_ && + gnu_debugdata_interface_->Step(rel_pc, regs, process_memory))); +} + +uint64_t Elf::GetLoadBias() { + if (!valid_) return 0; + return interface_->load_bias(); +} + bool Elf::IsValidElf(Memory* memory) { if (memory == nullptr) { return false; @@ -133,3 +168,5 @@ ElfInterface* Elf::CreateInterfaceFromMemory(Memory* memory) { return interface.release(); } + +} // namespace unwindstack |