summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2023-11-15 01:40:11 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-11-15 01:40:11 +0000
commit7c553de67b663b05b1f3df64c4583404e37a1289 (patch)
tree45842e2fd1b434141588d664df6383532c7fc48d
parentff931d68fe9a1b87fa9836cf37ef5b281b549207 (diff)
parent26ef69aabe3178f014d980b66bb68c511210c7e1 (diff)
downloadunwinding-7c553de67b663b05b1f3df64c4583404e37a1289.tar.gz
Use a shared_ptr for Elf memory objects. am: 26ef69aabe
Original change: https://android-review.googlesource.com/c/platform/system/unwinding/+/2825167 Change-Id: If7eab7a75d08753f36f80d689cd8a47e361c32a9 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--libunwindstack/DexFile.cpp4
-rw-r--r--libunwindstack/DexFile.h2
-rw-r--r--libunwindstack/DwarfDebugFrame.h4
-rw-r--r--libunwindstack/DwarfEhFrame.h4
-rw-r--r--libunwindstack/DwarfEhFrameWithHdr.h4
-rw-r--r--libunwindstack/DwarfSection.cpp2
-rw-r--r--libunwindstack/Elf.cpp12
-rw-r--r--libunwindstack/ElfInterface.cpp10
-rw-r--r--libunwindstack/ElfInterfaceArm.cpp2
-rw-r--r--libunwindstack/ElfInterfaceArm.h7
-rw-r--r--libunwindstack/JitDebug.cpp7
-rw-r--r--libunwindstack/MapInfo.cpp65
-rw-r--r--libunwindstack/Memory.cpp4
-rw-r--r--libunwindstack/RegsArm.cpp5
-rw-r--r--libunwindstack/RegsArm64.cpp5
-rw-r--r--libunwindstack/RegsRiscv64.cpp5
-rw-r--r--libunwindstack/RegsX86.cpp5
-rw-r--r--libunwindstack/RegsX86_64.cpp4
-rw-r--r--libunwindstack/benchmarks/ElfBenchmark.cpp2
-rw-r--r--libunwindstack/benchmarks/EvalBenchmark.cpp34
-rw-r--r--libunwindstack/benchmarks/SymbolBenchmark.cpp3
-rw-r--r--libunwindstack/include/unwindstack/DwarfMemory.h6
-rw-r--r--libunwindstack/include/unwindstack/DwarfSection.h11
-rw-r--r--libunwindstack/include/unwindstack/Elf.h10
-rw-r--r--libunwindstack/include/unwindstack/ElfInterface.h11
-rw-r--r--libunwindstack/include/unwindstack/MapInfo.h4
-rw-r--r--libunwindstack/include/unwindstack/Memory.h2
-rw-r--r--libunwindstack/tests/DexFilesTest.cpp6
-rw-r--r--libunwindstack/tests/DwarfCfaLogTest.cpp113
-rw-r--r--libunwindstack/tests/DwarfCfaTest.cpp114
-rw-r--r--libunwindstack/tests/DwarfDebugFrameTest.cpp125
-rw-r--r--libunwindstack/tests/DwarfEhFrameTest.cpp45
-rw-r--r--libunwindstack/tests/DwarfEhFrameWithHdrTest.cpp317
-rw-r--r--libunwindstack/tests/DwarfMemoryTest.cpp60
-rw-r--r--libunwindstack/tests/DwarfOpLogTest.cpp12
-rw-r--r--libunwindstack/tests/DwarfOpTest.cpp111
-rw-r--r--libunwindstack/tests/DwarfSectionImplTest.cpp101
-rw-r--r--libunwindstack/tests/DwarfSectionTest.cpp11
-rw-r--r--libunwindstack/tests/ElfFake.h11
-rw-r--r--libunwindstack/tests/ElfInterfaceArmTest.cpp153
-rw-r--r--libunwindstack/tests/ElfInterfaceTest.cpp379
-rw-r--r--libunwindstack/tests/ElfTest.cpp107
-rw-r--r--libunwindstack/tests/GlobalTest.cpp17
-rw-r--r--libunwindstack/tests/JitDebugTest.cpp6
-rw-r--r--libunwindstack/tests/MapInfoCreateMemoryTest.cpp38
-rw-r--r--libunwindstack/tests/MapInfoGetBuildIDTest.cpp9
-rw-r--r--libunwindstack/tests/MapInfoGetLoadBiasTest.cpp3
-rw-r--r--libunwindstack/tests/MapInfoTest.cpp5
-rw-r--r--libunwindstack/tests/RegsStepIfSignalHandlerTest.cpp25
-rw-r--r--libunwindstack/tests/RegsTest.cpp20
-rw-r--r--libunwindstack/tests/UnwinderTest.cpp53
-rw-r--r--libunwindstack/tests/VerifyBionicTerminationTest.cpp6
-rw-r--r--libunwindstack/tests/fuzz/UnwinderComponentCreator.cpp6
-rw-r--r--libunwindstack/tools/unwind_info.cpp7
-rw-r--r--libunwindstack/tools/unwind_reg_info.cpp18
-rw-r--r--libunwindstack/tools/unwind_symbols.cpp5
-rw-r--r--libunwindstack/utils/DwarfSectionImplFake.h4
57 files changed, 1100 insertions, 1021 deletions
diff --git a/libunwindstack/DexFile.cpp b/libunwindstack/DexFile.cpp
index 220ee82..cb2a28a 100644
--- a/libunwindstack/DexFile.cpp
+++ b/libunwindstack/DexFile.cpp
@@ -67,7 +67,7 @@ std::shared_ptr<DexFile> DexFile::CreateFromDisk(uint64_t addr, uint64_t size, M
}
// Load the file from disk and cache it.
- std::unique_ptr<Memory> memory = Memory::CreateFileMemory(map->name(), offset_in_file, size);
+ auto memory = Memory::CreateFileMemory(map->name(), offset_in_file, size);
if (memory == nullptr) {
return nullptr; // failed to map the file.
}
@@ -76,7 +76,7 @@ std::shared_ptr<DexFile> DexFile::CreateFromDisk(uint64_t addr, uint64_t size, M
if (dex == nullptr) {
return nullptr; // invalid DEX file.
}
- dex_api.reset(new DexFileApi{std::move(dex), std::move(memory), std::mutex()});
+ dex_api.reset(new DexFileApi{std::move(dex), memory, std::mutex()});
cache_entry = dex_api;
return std::shared_ptr<DexFile>(new DexFile(addr, size, std::move(dex_api)));
}
diff --git a/libunwindstack/DexFile.h b/libunwindstack/DexFile.h
index 3bb65da..c4235db 100644
--- a/libunwindstack/DexFile.h
+++ b/libunwindstack/DexFile.h
@@ -54,7 +54,7 @@ class DexFile {
// The underlying C API. It might be shared by multiple DexFiles (with different base_addr).
struct DexFileApi {
std::unique_ptr<art_api::dex::DexFile> dex_;
- std::unique_ptr<Memory> memory_; // Keep alive the memory object backing the dex file data.
+ std::shared_ptr<Memory> memory_; // Keep alive the memory object backing the dex file data.
std::mutex lock_; // The C API is not thread-safe so we need to lock it.
};
diff --git a/libunwindstack/DwarfDebugFrame.h b/libunwindstack/DwarfDebugFrame.h
index 017568d..43acaab 100644
--- a/libunwindstack/DwarfDebugFrame.h
+++ b/libunwindstack/DwarfDebugFrame.h
@@ -18,7 +18,7 @@
#include <stdint.h>
-#include <vector>
+#include <memory>
#include <unwindstack/DwarfSection.h>
@@ -27,7 +27,7 @@ namespace unwindstack {
template <typename AddressType>
class DwarfDebugFrame : public DwarfSectionImpl<AddressType> {
public:
- DwarfDebugFrame(Memory* memory) : DwarfSectionImpl<AddressType>(memory) {
+ DwarfDebugFrame(std::shared_ptr<Memory>& memory) : DwarfSectionImpl<AddressType>(memory) {
this->cie32_value_ = static_cast<uint32_t>(-1);
this->cie64_value_ = static_cast<uint64_t>(-1);
}
diff --git a/libunwindstack/DwarfEhFrame.h b/libunwindstack/DwarfEhFrame.h
index 93befd4..594761e 100644
--- a/libunwindstack/DwarfEhFrame.h
+++ b/libunwindstack/DwarfEhFrame.h
@@ -18,6 +18,8 @@
#include <stdint.h>
+#include <memory>
+
#include <unwindstack/DwarfSection.h>
#include <unwindstack/Memory.h>
@@ -26,7 +28,7 @@ namespace unwindstack {
template <typename AddressType>
class DwarfEhFrame : public DwarfSectionImpl<AddressType> {
public:
- DwarfEhFrame(Memory* memory) : DwarfSectionImpl<AddressType>(memory) {}
+ DwarfEhFrame(std::shared_ptr<Memory>& memory) : DwarfSectionImpl<AddressType>(memory) {}
virtual ~DwarfEhFrame() = default;
uint64_t GetCieOffsetFromFde32(uint32_t pointer) override {
diff --git a/libunwindstack/DwarfEhFrameWithHdr.h b/libunwindstack/DwarfEhFrameWithHdr.h
index c5cdb11..d3f0c61 100644
--- a/libunwindstack/DwarfEhFrameWithHdr.h
+++ b/libunwindstack/DwarfEhFrameWithHdr.h
@@ -18,7 +18,9 @@
#include <stdint.h>
+#include <memory>
#include <unordered_map>
+#include <vector>
#include <unwindstack/DwarfSection.h>
@@ -41,7 +43,7 @@ class DwarfEhFrameWithHdr : public DwarfSectionImpl<AddressType> {
uint64_t offset;
};
- DwarfEhFrameWithHdr(Memory* memory) : DwarfSectionImpl<AddressType>(memory) {}
+ DwarfEhFrameWithHdr(std::shared_ptr<Memory>& memory) : DwarfSectionImpl<AddressType>(memory) {}
virtual ~DwarfEhFrameWithHdr() = default;
uint64_t GetCieOffsetFromFde32(uint32_t pointer) override {
diff --git a/libunwindstack/DwarfSection.cpp b/libunwindstack/DwarfSection.cpp
index 1ee0988..2d664d6 100644
--- a/libunwindstack/DwarfSection.cpp
+++ b/libunwindstack/DwarfSection.cpp
@@ -41,7 +41,7 @@
namespace unwindstack {
-DwarfSection::DwarfSection(Memory* memory) : memory_(memory) {}
+DwarfSection::DwarfSection(std::shared_ptr<Memory>& memory) : memory_(memory) {}
bool DwarfSection::Step(uint64_t pc, Regs* regs, Memory* process_memory, bool* finished,
bool* is_signal_frame) {
diff --git a/libunwindstack/Elf.cpp b/libunwindstack/Elf.cpp
index c751346..f7905b8 100644
--- a/libunwindstack/Elf.cpp
+++ b/libunwindstack/Elf.cpp
@@ -51,7 +51,7 @@ bool Elf::Init() {
return false;
}
- interface_.reset(CreateInterfaceFromMemory(memory_.get()));
+ interface_.reset(CreateInterfaceFromMemory(memory_));
if (!interface_) {
return false;
}
@@ -73,8 +73,8 @@ void Elf::InitGnuDebugdata() {
return;
}
- gnu_debugdata_memory_ = interface_->CreateGnuDebugdataMemory();
- gnu_debugdata_interface_.reset(CreateInterfaceFromMemory(gnu_debugdata_memory_.get()));
+ auto memory = interface_->CreateGnuDebugdataMemory();
+ gnu_debugdata_interface_.reset(CreateInterfaceFromMemory(memory));
ElfInterface* gnu = gnu_debugdata_interface_.get();
if (gnu == nullptr) {
return;
@@ -87,8 +87,6 @@ void Elf::InitGnuDebugdata() {
gnu->InitHeaders();
interface_->SetGnuDebugdataInterface(gnu);
} else {
- // Free all of the memory associated with the gnu_debugdata section.
- gnu_debugdata_memory_.reset(nullptr);
gnu_debugdata_interface_.reset(nullptr);
}
}
@@ -280,8 +278,8 @@ bool Elf::GetTextRange(uint64_t* addr, uint64_t* size) {
return false;
}
-ElfInterface* Elf::CreateInterfaceFromMemory(Memory* memory) {
- if (!IsValidElf(memory)) {
+ElfInterface* Elf::CreateInterfaceFromMemory(std::shared_ptr<Memory>& memory) {
+ if (!IsValidElf(memory.get())) {
return nullptr;
}
diff --git a/libunwindstack/ElfInterface.cpp b/libunwindstack/ElfInterface.cpp
index fe9dc79..5901f08 100644
--- a/libunwindstack/ElfInterface.cpp
+++ b/libunwindstack/ElfInterface.cpp
@@ -75,13 +75,13 @@ bool ElfInterface::GetTextRange(uint64_t* addr, uint64_t* size) {
return false;
}
-std::unique_ptr<Memory> ElfInterface::CreateGnuDebugdataMemory() {
+std::shared_ptr<Memory> ElfInterface::CreateGnuDebugdataMemory() {
if (gnu_debugdata_offset_ == 0 || gnu_debugdata_size_ == 0) {
return nullptr;
}
- auto decompressed =
- std::make_unique<MemoryXz>(memory_, gnu_debugdata_offset_, gnu_debugdata_size_, GetSoname());
+ auto decompressed = std::make_shared<MemoryXz>(memory_.get(), gnu_debugdata_offset_,
+ gnu_debugdata_size_, GetSoname());
if (!decompressed || !decompressed->Init()) {
gnu_debugdata_offset_ = 0;
gnu_debugdata_size_ = 0;
@@ -426,7 +426,7 @@ bool ElfInterfaceImpl<ElfTypes>::GetFunctionName(uint64_t addr, SharedString* na
}
for (const auto symbol : symbols_) {
- if (symbol->template GetName<SymType>(addr, memory_, name, func_offset)) {
+ if (symbol->template GetName<SymType>(addr, memory_.get(), name, func_offset)) {
return true;
}
}
@@ -441,7 +441,7 @@ bool ElfInterfaceImpl<ElfTypes>::GetGlobalVariable(const std::string& name,
}
for (const auto symbol : symbols_) {
- if (symbol->template GetGlobal<SymType>(memory_, name, memory_address)) {
+ if (symbol->template GetGlobal<SymType>(memory_.get(), name, memory_address)) {
return true;
}
}
diff --git a/libunwindstack/ElfInterfaceArm.cpp b/libunwindstack/ElfInterfaceArm.cpp
index de6a5d7..a960048 100644
--- a/libunwindstack/ElfInterfaceArm.cpp
+++ b/libunwindstack/ElfInterfaceArm.cpp
@@ -124,7 +124,7 @@ bool ElfInterfaceArm::StepExidx(uint64_t pc, Regs* regs, Memory* process_memory,
return false;
}
- ArmExidx arm(regs_arm, memory_, process_memory);
+ ArmExidx arm(regs_arm, memory_.get(), process_memory);
arm.set_cfa(regs_arm->sp());
bool return_value = false;
if (arm.ExtractEntryData(entry_offset) && arm.Eval()) {
diff --git a/libunwindstack/ElfInterfaceArm.h b/libunwindstack/ElfInterfaceArm.h
index b4db7da..0630abe 100644
--- a/libunwindstack/ElfInterfaceArm.h
+++ b/libunwindstack/ElfInterfaceArm.h
@@ -17,8 +17,11 @@
#pragma once
#include <elf.h>
+#include <stddef.h>
#include <stdint.h>
+#include <iterator>
+#include <memory>
#include <unordered_map>
#include <unwindstack/ElfInterface.h>
@@ -28,14 +31,14 @@ namespace unwindstack {
class ElfInterfaceArm : public ElfInterface32 {
public:
- ElfInterfaceArm(Memory* memory) : ElfInterface32(memory) {}
+ ElfInterfaceArm(std::shared_ptr<Memory>& memory) : ElfInterface32(memory) {}
virtual ~ElfInterfaceArm() = default;
class iterator {
public:
using iterator_category = std::bidirectional_iterator_tag;
using value_type = uint32_t;
- using difference_type = std::ptrdiff_t;
+ using difference_type = ptrdiff_t;
using pointer = uint32_t*;
using reference = uint32_t&;
diff --git a/libunwindstack/JitDebug.cpp b/libunwindstack/JitDebug.cpp
index 1aebcf5..20e981e 100644
--- a/libunwindstack/JitDebug.cpp
+++ b/libunwindstack/JitDebug.cpp
@@ -26,11 +26,12 @@ namespace unwindstack {
template <>
bool GlobalDebugInterface<Elf>::Load(Maps*, std::shared_ptr<Memory>& memory, uint64_t addr,
uint64_t size, /*out*/ std::shared_ptr<Elf>& elf) {
- std::unique_ptr<MemoryBuffer> copy(new MemoryBuffer());
- if (!copy->Resize(size) || !memory->ReadFully(addr, copy->GetPtr(0), size)) {
+ MemoryBuffer* buffer = new MemoryBuffer;
+ std::shared_ptr<Memory> copy(buffer);
+ if (!buffer->Resize(size) || !memory->ReadFully(addr, buffer->GetPtr(0), size)) {
return false;
}
- elf.reset(new Elf(copy.release()));
+ elf.reset(new Elf(copy));
return elf->Init() && elf->valid();
}
diff --git a/libunwindstack/MapInfo.cpp b/libunwindstack/MapInfo.cpp
index 6db1183..b67f098 100644
--- a/libunwindstack/MapInfo.cpp
+++ b/libunwindstack/MapInfo.cpp
@@ -28,6 +28,7 @@
#include <unwindstack/Elf.h>
#include <unwindstack/MapInfo.h>
#include <unwindstack/Maps.h>
+#include <unwindstack/Memory.h>
#include "MemoryFileAtOffset.h"
#include "MemoryRange.h"
@@ -100,16 +101,16 @@ bool MapInfo::InitFileMemoryFromPreviousReadOnlyMap(MemoryFileAtOffset* memory)
return true;
}
-Memory* MapInfo::GetFileMemory() {
+std::shared_ptr<Memory> MapInfo::CreateFileMemory() {
// Fail on device maps.
if (flags() & MAPS_FLAGS_DEVICE_MAP) {
return nullptr;
}
- std::unique_ptr<MemoryFileAtOffset> memory(new MemoryFileAtOffset);
+ auto file_memory = std::make_shared<MemoryFileAtOffset>();
if (offset() == 0) {
- if (memory->Init(name(), 0)) {
- return memory.release();
+ if (file_memory->Init(name(), 0)) {
+ return file_memory;
}
return nullptr;
}
@@ -133,49 +134,49 @@ Memory* MapInfo::GetFileMemory() {
// which can be smaller than elf header size. So make sure map_size is large enough
// to read elf header.
uint64_t map_size = std::max<uint64_t>(end() - start(), sizeof(ElfTypes64::Ehdr));
- if (!memory->Init(name(), offset(), map_size)) {
+ if (!file_memory->Init(name(), offset(), map_size)) {
return nullptr;
}
// Check if the start of this map is an embedded elf.
uint64_t max_size = 0;
- if (Elf::GetInfo(memory.get(), &max_size)) {
+ if (Elf::GetInfo(file_memory.get(), &max_size)) {
set_elf_start_offset(offset());
if (max_size > map_size) {
- if (memory->Init(name(), offset(), max_size)) {
- return memory.release();
+ if (file_memory->Init(name(), offset(), max_size)) {
+ return file_memory;
}
// Try to reinit using the default map_size.
- if (memory->Init(name(), offset(), map_size)) {
- return memory.release();
+ if (file_memory->Init(name(), offset(), map_size)) {
+ return file_memory;
}
set_elf_start_offset(0);
return nullptr;
}
- return memory.release();
+ return file_memory;
}
// No elf at offset, try to init as if the whole file is an elf.
- if (memory->Init(name(), 0) && Elf::IsValidElf(memory.get())) {
+ if (file_memory->Init(name(), 0) && Elf::IsValidElf(file_memory.get())) {
set_elf_offset(offset());
- return memory.release();
+ return file_memory;
}
// See if the map previous to this one contains a read-only map
// that represents the real start of the elf data.
- if (InitFileMemoryFromPreviousReadOnlyMap(memory.get())) {
- return memory.release();
+ if (InitFileMemoryFromPreviousReadOnlyMap(file_memory.get())) {
+ return file_memory;
}
// Failed to find elf at start of file or at read-only map, return
// file object from the current map.
- if (memory->Init(name(), offset(), map_size)) {
- return memory.release();
+ if (file_memory->Init(name(), offset(), map_size)) {
+ return file_memory;
}
return nullptr;
}
-Memory* MapInfo::CreateMemory(const std::shared_ptr<Memory>& process_memory) {
+std::shared_ptr<Memory> MapInfo::CreateMemory(const std::shared_ptr<Memory>& process_memory) {
if (end() <= start()) {
return nullptr;
}
@@ -189,7 +190,7 @@ Memory* MapInfo::CreateMemory(const std::shared_ptr<Memory>& process_memory) {
// First try and use the file associated with the info.
if (!name().empty()) {
- Memory* memory = GetFileMemory();
+ auto memory = CreateFileMemory();
if (memory != nullptr) {
return memory;
}
@@ -206,8 +207,9 @@ Memory* MapInfo::CreateMemory(const std::shared_ptr<Memory>& process_memory) {
// map. In this case, there will be another read-only map that includes the
// first part of the elf file. This is done if the linker rosegment
// option is used.
- std::unique_ptr<MemoryRange> memory(new MemoryRange(process_memory, start(), end() - start(), 0));
- if (Elf::IsValidElf(memory.get())) {
+ std::shared_ptr<Memory> memory_range(
+ new MemoryRange(process_memory, start(), end() - start(), 0));
+ if (Elf::IsValidElf(memory_range.get())) {
set_elf_start_offset(offset());
auto next_real_map = GetNextRealMap();
@@ -215,7 +217,7 @@ Memory* MapInfo::CreateMemory(const std::shared_ptr<Memory>& process_memory) {
// Might need to peek at the next map to create a memory object that
// includes that map too.
if (offset() != 0 || next_real_map == nullptr || offset() >= next_real_map->offset()) {
- return memory.release();
+ return memory_range;
}
// There is a possibility that the elf object has already been created
@@ -223,12 +225,13 @@ Memory* MapInfo::CreateMemory(const std::shared_ptr<Memory>& process_memory) {
// redo the work. If this happens, the elf for this map will eventually
// be discarded.
MemoryRanges* ranges = new MemoryRanges;
+ std::shared_ptr<Memory> memory_ranges(ranges);
ranges->Insert(new MemoryRange(process_memory, start(), end() - start(), 0));
ranges->Insert(new MemoryRange(process_memory, next_real_map->start(),
next_real_map->end() - next_real_map->start(),
next_real_map->offset() - offset()));
- return ranges;
+ return memory_ranges;
}
auto prev_real_map = GetPrevRealMap();
@@ -248,7 +251,8 @@ Memory* MapInfo::CreateMemory(const std::shared_ptr<Memory>& process_memory) {
// the r-x section, which is not quite the right information.
set_elf_start_offset(prev_real_map->offset());
- std::unique_ptr<MemoryRanges> ranges(new MemoryRanges);
+ MemoryRanges* ranges = new MemoryRanges;
+ std::shared_ptr<Memory> memory_ranges(ranges);
if (!ranges->Insert(new MemoryRange(process_memory, prev_real_map->start(),
prev_real_map->end() - prev_real_map->start(), 0))) {
return nullptr;
@@ -256,7 +260,7 @@ Memory* MapInfo::CreateMemory(const std::shared_ptr<Memory>& process_memory) {
if (!ranges->Insert(new MemoryRange(process_memory, start(), end() - start(), elf_offset()))) {
return nullptr;
}
- return ranges.release();
+ return memory_ranges;
}
class ScopedElfCacheLock {
@@ -284,7 +288,8 @@ Elf* MapInfo::GetElf(const std::shared_ptr<Memory>& process_memory, ArchEnum exp
}
}
- elf().reset(new Elf(CreateMemory(process_memory)));
+ auto elf_memory = CreateMemory(process_memory);
+ elf().reset(new Elf(elf_memory));
// If the init fails, keep the elf around as an invalid object so we
// don't try to reinit the object.
elf()->Init();
@@ -366,7 +371,7 @@ uint64_t MapInfo::GetLoadBias(const std::shared_ptr<Memory>& process_memory) {
// Call lightweight static function that will only read enough of the
// elf data to get the load bias.
- std::unique_ptr<Memory> memory(CreateMemory(process_memory));
+ auto memory = CreateMemory(process_memory);
cur_load_bias = Elf::GetLoadBias(memory.get());
set_load_bias(cur_load_bias);
return cur_load_bias;
@@ -415,9 +420,9 @@ SharedString MapInfo::GetBuildID() {
// This will only work if we can get the file associated with this memory.
// If this is only available in memory, then the section name information
// is not present and we will not be able to find the build id info.
- std::unique_ptr<Memory> memory(GetFileMemory());
- if (memory != nullptr) {
- result = Elf::GetBuildID(memory.get());
+ auto file_memory = CreateFileMemory();
+ if (file_memory != nullptr) {
+ result = Elf::GetBuildID(file_memory.get());
}
}
return SetBuildID(std::move(result));
diff --git a/libunwindstack/Memory.cpp b/libunwindstack/Memory.cpp
index 5cfe2f0..29fc5cd 100644
--- a/libunwindstack/Memory.cpp
+++ b/libunwindstack/Memory.cpp
@@ -190,9 +190,9 @@ bool Memory::ReadString(uint64_t addr, std::string* dst, size_t max_read) {
return false;
}
-std::unique_ptr<Memory> Memory::CreateFileMemory(const std::string& path, uint64_t offset,
+std::shared_ptr<Memory> Memory::CreateFileMemory(const std::string& path, uint64_t offset,
uint64_t size) {
- auto memory = std::make_unique<MemoryFileAtOffset>();
+ auto memory = std::make_shared<MemoryFileAtOffset>();
if (memory->Init(path, offset, size)) {
return memory;
diff --git a/libunwindstack/RegsArm.cpp b/libunwindstack/RegsArm.cpp
index 1aaa08f..302f659 100644
--- a/libunwindstack/RegsArm.cpp
+++ b/libunwindstack/RegsArm.cpp
@@ -97,11 +97,10 @@ Regs* RegsArm::CreateFromUcontext(void* ucontext) {
}
bool RegsArm::StepIfSignalHandler(uint64_t elf_offset, Elf* elf, Memory* process_memory) {
- uint32_t data;
- Memory* elf_memory = elf->memory();
// Read from elf memory since it is usually more expensive to read from
// process memory.
- if (!elf_memory->ReadFully(elf_offset, &data, sizeof(data))) {
+ uint32_t data;
+ if (!elf->memory()->ReadFully(elf_offset, &data, sizeof(data))) {
return false;
}
diff --git a/libunwindstack/RegsArm64.cpp b/libunwindstack/RegsArm64.cpp
index 99eddb0..cf19454 100644
--- a/libunwindstack/RegsArm64.cpp
+++ b/libunwindstack/RegsArm64.cpp
@@ -152,11 +152,10 @@ Regs* RegsArm64::CreateFromUcontext(void* ucontext) {
}
bool RegsArm64::StepIfSignalHandler(uint64_t elf_offset, Elf* elf, Memory* process_memory) {
- uint64_t data;
- Memory* elf_memory = elf->memory();
// Read from elf memory since it is usually more expensive to read from
// process memory.
- if (!elf_memory->ReadFully(elf_offset, &data, sizeof(data))) {
+ uint64_t data;
+ if (!elf->memory()->ReadFully(elf_offset, &data, sizeof(data))) {
return false;
}
diff --git a/libunwindstack/RegsRiscv64.cpp b/libunwindstack/RegsRiscv64.cpp
index d7cd7dd..63070e4 100644
--- a/libunwindstack/RegsRiscv64.cpp
+++ b/libunwindstack/RegsRiscv64.cpp
@@ -116,11 +116,10 @@ Regs* RegsRiscv64::CreateFromUcontext(void* ucontext) {
}
bool RegsRiscv64::StepIfSignalHandler(uint64_t elf_offset, Elf* elf, Memory* process_memory) {
- uint64_t data;
- Memory* elf_memory = elf->memory();
// Read from elf memory since it is usually more expensive to read from
// process memory.
- if (!elf_memory->ReadFully(elf_offset, &data, sizeof(data))) {
+ uint64_t data;
+ if (!elf->memory()->ReadFully(elf_offset, &data, sizeof(data))) {
return false;
}
// Look for the kernel sigreturn function.
diff --git a/libunwindstack/RegsX86.cpp b/libunwindstack/RegsX86.cpp
index 4d3c246..48e8de6 100644
--- a/libunwindstack/RegsX86.cpp
+++ b/libunwindstack/RegsX86.cpp
@@ -113,11 +113,10 @@ Regs* RegsX86::CreateFromUcontext(void* ucontext) {
}
bool RegsX86::StepIfSignalHandler(uint64_t elf_offset, Elf* elf, Memory* process_memory) {
- uint64_t data;
- Memory* elf_memory = elf->memory();
// Read from elf memory since it is usually more expensive to read from
// process memory.
- if (!elf_memory->ReadFully(elf_offset, &data, sizeof(data))) {
+ uint64_t data;
+ if (!elf->memory()->ReadFully(elf_offset, &data, sizeof(data))) {
return false;
}
diff --git a/libunwindstack/RegsX86_64.cpp b/libunwindstack/RegsX86_64.cpp
index 26d9f65..c8a3a21 100644
--- a/libunwindstack/RegsX86_64.cpp
+++ b/libunwindstack/RegsX86_64.cpp
@@ -133,10 +133,10 @@ Regs* RegsX86_64::CreateFromUcontext(void* ucontext) {
}
bool RegsX86_64::StepIfSignalHandler(uint64_t elf_offset, Elf* elf, Memory* process_memory) {
- uint64_t data;
- Memory* elf_memory = elf->memory();
// Read from elf memory since it is usually more expensive to read from
// process memory.
+ uint64_t data;
+ auto elf_memory = elf->memory();
if (!elf_memory->ReadFully(elf_offset, &data, sizeof(data)) || data != 0x0f0000000fc0c748) {
return false;
}
diff --git a/libunwindstack/benchmarks/ElfBenchmark.cpp b/libunwindstack/benchmarks/ElfBenchmark.cpp
index d2ff64c..45010c8 100644
--- a/libunwindstack/benchmarks/ElfBenchmark.cpp
+++ b/libunwindstack/benchmarks/ElfBenchmark.cpp
@@ -40,7 +40,7 @@ class ElfCreateBenchmark : public benchmark::Fixture {
auto file_memory = unwindstack::Memory::CreateFileMemory(elf_file, 0);
state.ResumeTiming();
- unwindstack::Elf elf(file_memory.release());
+ unwindstack::Elf elf(file_memory);
if (!elf.Init() || !elf.valid()) {
errx(1, "Internal Error: Cannot open elf: %s", elf_file.c_str());
}
diff --git a/libunwindstack/benchmarks/EvalBenchmark.cpp b/libunwindstack/benchmarks/EvalBenchmark.cpp
index 8fb9fd4..1dec5b8 100644
--- a/libunwindstack/benchmarks/EvalBenchmark.cpp
+++ b/libunwindstack/benchmarks/EvalBenchmark.cpp
@@ -16,6 +16,7 @@
#include <cstdint>
#include <ios>
+#include <memory>
#include <sstream>
#include <benchmark/benchmark.h>
@@ -41,8 +42,9 @@ template <typename AddresssType>
class EvalBenchmark : public benchmark::Fixture {
public:
EvalBenchmark() {
- memory_.Clear();
- section_ = std::make_unique<DwarfSectionImplFake<AddresssType>>(&memory_);
+ fake_memory_ = new MemoryFake;
+ std::shared_ptr<Memory> memory(fake_memory_);
+ section_ = std::make_unique<DwarfSectionImplFake<AddresssType>>(memory);
}
// Benchmarks DwarfSectionImpl::Eval given the DwarfLocation object, loc_regs, initialized in each
@@ -72,7 +74,7 @@ class EvalBenchmark : public benchmark::Fixture {
state.ResumeTiming();
std::stringstream err_stream;
- if (!section_->Eval(&cie, &memory_, loc_regs, &regs, &finished)) {
+ if (!section_->Eval(&cie, fake_memory_, loc_regs, &regs, &finished)) {
err_stream << "Eval() failed at address " << section_->LastErrorAddress();
state.SkipWithError(err_stream.str().c_str());
return;
@@ -94,7 +96,7 @@ class EvalBenchmark : public benchmark::Fixture {
}
protected:
- MemoryFake memory_;
+ MemoryFake* fake_memory_;
std::unique_ptr<DwarfSectionImplFake<AddresssType>> section_;
};
@@ -137,7 +139,7 @@ BENCHMARK_TEMPLATE_F(EvalBenchmark, BM_eval_val_offset_many_regs, uint64_t)
// Benchmarks exercising Eval with the DWARF_LOCATION_OFFSET evaluation method.
BENCHMARK_TEMPLATE_F(EvalBenchmark, BM_eval_offset_few_regs, uint64_t)
(benchmark::State& state) {
- memory_.SetData64(0x20000000, 0x60000000);
+ fake_memory_->SetData64(0x20000000, 0x60000000);
DwarfLocations loc_regs;
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_REGISTER, {0, 0}};
loc_regs[kReturnAddressReg] = DwarfLocation{DWARF_LOCATION_OFFSET, {0x10000000, 0}};
@@ -146,8 +148,8 @@ BENCHMARK_TEMPLATE_F(EvalBenchmark, BM_eval_offset_few_regs, uint64_t)
BENCHMARK_TEMPLATE_F(EvalBenchmark, BM_eval_offset_many_regs, uint64_t)
(benchmark::State& state) {
- memory_.SetData64(0x20000000, 0x60000000);
- memory_.SetData64(0x30000000, 0x10000000);
+ fake_memory_->SetData64(0x20000000, 0x60000000);
+ fake_memory_->SetData64(0x30000000, 0x10000000);
DwarfLocations loc_regs;
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_REGISTER, {0, 0}};
for (uint64_t i = 1; i < 64; i++) {
@@ -163,9 +165,9 @@ BENCHMARK_TEMPLATE_F(EvalBenchmark, BM_eval_offset_many_regs, uint64_t)
// The dwarf op-code used for the expression benchmarks are OP_const4u (see DwarfOp::Eval).
BENCHMARK_TEMPLATE_F(EvalBenchmark, BM_eval_expression_few_regs, uint64_t)
(benchmark::State& state) {
- memory_.SetMemory(0x5000, std::vector<uint8_t>{0x0c, 0x00, 0x00, 0x00, 0x80});
+ fake_memory_->SetMemory(0x5000, std::vector<uint8_t>{0x0c, 0x00, 0x00, 0x00, 0x80});
uint64_t pc_value = 0x60000000;
- memory_.SetMemory(0x80000000, &pc_value, sizeof(pc_value));
+ fake_memory_->SetMemory(0x80000000, &pc_value, sizeof(pc_value));
DwarfLocations loc_regs;
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_REGISTER, {0, 0}};
loc_regs[kReturnAddressReg] = DwarfLocation{DWARF_LOCATION_EXPRESSION, {0x4, 0x5004}};
@@ -174,13 +176,13 @@ BENCHMARK_TEMPLATE_F(EvalBenchmark, BM_eval_expression_few_regs, uint64_t)
BENCHMARK_TEMPLATE_F(EvalBenchmark, BM_eval_expression_many_regs, uint64_t)
(benchmark::State& state) {
- memory_.SetMemory(0x5000, std::vector<uint8_t>{0x0c, 0x00, 0x00, 0x00, 0x80});
+ fake_memory_->SetMemory(0x5000, std::vector<uint8_t>{0x0c, 0x00, 0x00, 0x00, 0x80});
uint64_t pc_value = 0x60000000;
- memory_.SetMemory(0x80000000, &pc_value, sizeof(pc_value));
+ fake_memory_->SetMemory(0x80000000, &pc_value, sizeof(pc_value));
- memory_.SetMemory(0x6000, std::vector<uint8_t>{0x0c, 0x00, 0x00, 0x00, 0x90});
+ fake_memory_->SetMemory(0x6000, std::vector<uint8_t>{0x0c, 0x00, 0x00, 0x00, 0x90});
uint64_t sp_value = 0x10000000;
- memory_.SetMemory(0x90000000, &sp_value, sizeof(sp_value));
+ fake_memory_->SetMemory(0x90000000, &sp_value, sizeof(sp_value));
DwarfLocations loc_regs;
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_REGISTER, {0, 0}};
@@ -197,7 +199,7 @@ BENCHMARK_TEMPLATE_F(EvalBenchmark, BM_eval_expression_many_regs, uint64_t)
// The dwarf op-code used for the value expression benchmarks are OP_const4u (see DwarfOp::Eval).
BENCHMARK_TEMPLATE_F(EvalBenchmark, BM_eval_val_expression_few_regs, uint64_t)
(benchmark::State& state) {
- memory_.SetMemory(0x5000, std::vector<uint8_t>{0x0c, 0x00, 0x00, 0x00, 0x60});
+ fake_memory_->SetMemory(0x5000, std::vector<uint8_t>{0x0c, 0x00, 0x00, 0x00, 0x60});
DwarfLocations loc_regs;
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_REGISTER, {0, 0}};
loc_regs[kReturnAddressReg] = DwarfLocation{DWARF_LOCATION_VAL_EXPRESSION, {0x4, 0x5004}};
@@ -206,8 +208,8 @@ BENCHMARK_TEMPLATE_F(EvalBenchmark, BM_eval_val_expression_few_regs, uint64_t)
BENCHMARK_TEMPLATE_F(EvalBenchmark, BM_eval_val_expression_many_regs, uint64_t)
(benchmark::State& state) {
- memory_.SetMemory(0x5000, std::vector<uint8_t>{0x0c, 0x00, 0x00, 0x00, 0x60});
- memory_.SetMemory(0x6000, std::vector<uint8_t>{0x0c, 0x00, 0x00, 0x00, 0x10});
+ fake_memory_->SetMemory(0x5000, std::vector<uint8_t>{0x0c, 0x00, 0x00, 0x00, 0x60});
+ fake_memory_->SetMemory(0x6000, std::vector<uint8_t>{0x0c, 0x00, 0x00, 0x00, 0x10});
DwarfLocations loc_regs;
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_REGISTER, {0, 0}};
for (uint64_t i = 1; i < 64; i++) {
diff --git a/libunwindstack/benchmarks/SymbolBenchmark.cpp b/libunwindstack/benchmarks/SymbolBenchmark.cpp
index 0fbda15..cd72772 100644
--- a/libunwindstack/benchmarks/SymbolBenchmark.cpp
+++ b/libunwindstack/benchmarks/SymbolBenchmark.cpp
@@ -39,7 +39,8 @@ class SymbolLookupBenchmark : public benchmark::Fixture {
mem_tracker.StartTrackingAllocations();
state.ResumeTiming();
- unwindstack::Elf elf(unwindstack::Memory::CreateFileMemory(elf_file, 0).release());
+ auto elf_memory = unwindstack::Memory::CreateFileMemory(elf_file, 0);
+ unwindstack::Elf elf(elf_memory);
if (!elf.Init() || !elf.valid()) {
errx(1, "Internal Error: Cannot open elf: %s", elf_file.c_str());
}
diff --git a/libunwindstack/include/unwindstack/DwarfMemory.h b/libunwindstack/include/unwindstack/DwarfMemory.h
index 2ef3b30..fd9c33b 100644
--- a/libunwindstack/include/unwindstack/DwarfMemory.h
+++ b/libunwindstack/include/unwindstack/DwarfMemory.h
@@ -18,6 +18,8 @@
#include <stdint.h>
+#include <memory>
+
namespace unwindstack {
// Forward declarations.
@@ -25,7 +27,7 @@ class Memory;
class DwarfMemory {
public:
- DwarfMemory(Memory* memory) : memory_(memory) {}
+ DwarfMemory(std::shared_ptr<Memory>& memory) : memory_(memory) {}
virtual ~DwarfMemory() = default;
bool ReadBytes(void* dst, size_t num_bytes);
@@ -61,7 +63,7 @@ class DwarfMemory {
void clear_text_offset() { text_offset_ = static_cast<uint64_t>(-1); }
private:
- Memory* memory_;
+ std::shared_ptr<Memory> memory_;
uint64_t cur_offset_ = 0;
int64_t pc_offset_ = INT64_MAX;
diff --git a/libunwindstack/include/unwindstack/DwarfSection.h b/libunwindstack/include/unwindstack/DwarfSection.h
index 880bfde..24931b8 100644
--- a/libunwindstack/include/unwindstack/DwarfSection.h
+++ b/libunwindstack/include/unwindstack/DwarfSection.h
@@ -16,11 +16,16 @@
#pragma once
+#include <stddef.h>
#include <stdint.h>
+#include <iterator>
#include <map>
+#include <memory>
#include <optional>
#include <unordered_map>
+#include <utility>
+#include <vector>
#include <unwindstack/DwarfError.h>
#include <unwindstack/DwarfLocation.h>
@@ -39,14 +44,14 @@ struct SectionInfo;
class DwarfSection {
public:
- DwarfSection(Memory* memory);
+ DwarfSection(std::shared_ptr<Memory>& memory);
virtual ~DwarfSection() = default;
class iterator {
public:
using iterator_category = std::bidirectional_iterator_tag;
using value_type = DwarfFde*;
- using difference_type = std::ptrdiff_t;
+ using difference_type = ptrdiff_t;
using pointer = DwarfFde**;
using reference = DwarfFde*&;
@@ -130,7 +135,7 @@ class DwarfSection {
template <typename AddressType>
class DwarfSectionImpl : public DwarfSection {
public:
- DwarfSectionImpl(Memory* memory) : DwarfSection(memory) {}
+ DwarfSectionImpl(std::shared_ptr<Memory>& memory) : DwarfSection(memory) {}
virtual ~DwarfSectionImpl() = default;
bool Init(const SectionInfo& info) override;
diff --git a/libunwindstack/include/unwindstack/Elf.h b/libunwindstack/include/unwindstack/Elf.h
index 190cb57..15616b6 100644
--- a/libunwindstack/include/unwindstack/Elf.h
+++ b/libunwindstack/include/unwindstack/Elf.h
@@ -23,7 +23,6 @@
#include <mutex>
#include <string>
#include <unordered_map>
-#include <utility>
#include <unwindstack/Arch.h>
#include <unwindstack/ElfInterface.h>
@@ -50,7 +49,7 @@ class Regs;
class Elf {
public:
- Elf(Memory* memory) : memory_(memory) {}
+ Elf(std::shared_ptr<Memory>& memory) : memory_(memory) {}
virtual ~Elf() = default;
bool Init();
@@ -72,7 +71,7 @@ class Elf {
bool Step(uint64_t rel_pc, Regs* regs, Memory* process_memory, bool* finished,
bool* is_signal_frame);
- ElfInterface* CreateInterfaceFromMemory(Memory* memory);
+ ElfInterface* CreateInterfaceFromMemory(std::shared_ptr<Memory>& memory);
std::string GetBuildID();
@@ -96,7 +95,7 @@ class Elf {
ArchEnum arch() { return arch_; }
- Memory* memory() { return memory_.get(); }
+ std::shared_ptr<Memory> memory() { return memory_; }
ElfInterface* interface() { return interface_.get(); }
@@ -129,14 +128,13 @@ class Elf {
bool valid_ = false;
int64_t load_bias_ = 0;
std::unique_ptr<ElfInterface> interface_;
- std::unique_ptr<Memory> memory_;
+ std::shared_ptr<Memory> memory_;
uint32_t machine_type_;
uint8_t class_type_;
ArchEnum arch_;
// Protect calls that can modify internal state of the interface object.
std::mutex lock_;
- std::unique_ptr<Memory> gnu_debugdata_memory_;
std::unique_ptr<ElfInterface> gnu_debugdata_interface_;
static bool cache_enabled_;
diff --git a/libunwindstack/include/unwindstack/ElfInterface.h b/libunwindstack/include/unwindstack/ElfInterface.h
index 5564f28..9b911a0 100644
--- a/libunwindstack/include/unwindstack/ElfInterface.h
+++ b/libunwindstack/include/unwindstack/ElfInterface.h
@@ -22,6 +22,7 @@
#include <memory>
#include <string>
#include <unordered_map>
+#include <utility>
#include <vector>
#include <unwindstack/DwarfSection.h>
@@ -76,7 +77,7 @@ struct ElfTypes64 {
class ElfInterface {
public:
- ElfInterface(Memory* memory) : memory_(memory) {}
+ ElfInterface(std::shared_ptr<Memory>& memory) : memory_(memory) {}
virtual ~ElfInterface();
virtual bool Init(int64_t* load_bias) = 0;
@@ -98,9 +99,9 @@ class ElfInterface {
bool GetTextRange(uint64_t* addr, uint64_t* size);
- std::unique_ptr<Memory> CreateGnuDebugdataMemory();
+ std::shared_ptr<Memory> CreateGnuDebugdataMemory();
- Memory* memory() { return memory_; }
+ std::shared_ptr<Memory> memory() { return memory_; }
const std::unordered_map<uint64_t, LoadInfo>& pt_loads() { return pt_loads_; }
@@ -140,7 +141,7 @@ class ElfInterface {
protected:
virtual void HandleUnknownType(uint32_t, uint64_t, uint64_t) {}
- Memory* memory_;
+ std::shared_ptr<Memory> memory_;
std::unordered_map<uint64_t, LoadInfo> pt_loads_;
// Stored elf data.
@@ -190,7 +191,7 @@ class ElfInterfaceImpl : public ElfInterface {
using ShdrType = typename ElfTypes::Shdr;
using SymType = typename ElfTypes::Sym;
- ElfInterfaceImpl(Memory* memory) : ElfInterface(memory) {}
+ ElfInterfaceImpl(std::shared_ptr<Memory>& memory) : ElfInterface(memory) {}
virtual ~ElfInterfaceImpl() = default;
bool Init(int64_t* load_bias) override { return ReadAllHeaders(load_bias); }
diff --git a/libunwindstack/include/unwindstack/MapInfo.h b/libunwindstack/include/unwindstack/MapInfo.h
index 12711f5..9f025ff 100644
--- a/libunwindstack/include/unwindstack/MapInfo.h
+++ b/libunwindstack/include/unwindstack/MapInfo.h
@@ -190,7 +190,7 @@ class MapInfo {
// Otherwise, this function only returns the name of the map.
std::string GetFullName();
- Memory* CreateMemory(const std::shared_ptr<Memory>& process_memory);
+ std::shared_ptr<Memory> CreateMemory(const std::shared_ptr<Memory>& process_memory);
bool GetFunctionName(uint64_t addr, SharedString* name, uint64_t* func_offset);
@@ -212,7 +212,7 @@ class MapInfo {
MapInfo(const MapInfo&) = delete;
void operator=(const MapInfo&) = delete;
- Memory* GetFileMemory();
+ std::shared_ptr<Memory> CreateFileMemory();
bool InitFileMemoryFromPreviousReadOnlyMap(MemoryFileAtOffset* memory);
// Protect the creation of the elf object.
diff --git a/libunwindstack/include/unwindstack/Memory.h b/libunwindstack/include/unwindstack/Memory.h
index d6ca29e..112fe19 100644
--- a/libunwindstack/include/unwindstack/Memory.h
+++ b/libunwindstack/include/unwindstack/Memory.h
@@ -37,7 +37,7 @@ class Memory {
static std::shared_ptr<Memory> CreateProcessMemoryThreadCached(pid_t pid);
static std::shared_ptr<Memory> CreateOfflineMemory(const uint8_t* data, uint64_t start,
uint64_t end);
- static std::unique_ptr<Memory> CreateFileMemory(const std::string& path, uint64_t offset,
+ static std::shared_ptr<Memory> CreateFileMemory(const std::string& path, uint64_t offset,
uint64_t size = UINT64_MAX);
virtual MemoryCacheBase* AsMemoryCacheBase() { return nullptr; }
diff --git a/libunwindstack/tests/DexFilesTest.cpp b/libunwindstack/tests/DexFilesTest.cpp
index 9250d6d..500f00d 100644
--- a/libunwindstack/tests/DexFilesTest.cpp
+++ b/libunwindstack/tests/DexFilesTest.cpp
@@ -39,10 +39,10 @@ class DexFilesTest : public ::testing::Test {
protected:
void CreateFakeElf(MapInfo* map_info, uint64_t global_offset, uint64_t data_offset,
uint64_t data_vaddr, uint64_t data_size) {
- MemoryFake* memory = new MemoryFake;
- ElfFake* elf = new ElfFake(memory);
+ std::shared_ptr<Memory> fake_memory(new MemoryFake);
+ ElfFake* elf = new ElfFake(fake_memory);
elf->FakeSetValid(true);
- ElfInterfaceFake* interface = new ElfInterfaceFake(memory);
+ ElfInterfaceFake* interface = new ElfInterfaceFake(fake_memory);
elf->FakeSetInterface(interface);
interface->FakeSetGlobalVariable("__dex_debug_descriptor", global_offset);
diff --git a/libunwindstack/tests/DwarfCfaLogTest.cpp b/libunwindstack/tests/DwarfCfaLogTest.cpp
index 876f951..01f3a90 100644
--- a/libunwindstack/tests/DwarfCfaLogTest.cpp
+++ b/libunwindstack/tests/DwarfCfaLogTest.cpp
@@ -41,9 +41,9 @@ class DwarfCfaLogTest : public ::testing::Test {
protected:
void SetUp() override {
ResetLogs();
- memory_.Clear();
-
- dmem_.reset(new DwarfMemory(&memory_));
+ fake_memory_ = new MemoryFake;
+ std::shared_ptr<Memory> memory(fake_memory_);
+ dmem_.reset(new DwarfMemory(memory));
cie_.cfa_instructions_offset = 0x1000;
cie_.cfa_instructions_end = 0x1030;
@@ -61,7 +61,7 @@ class DwarfCfaLogTest : public ::testing::Test {
cfa_.reset(new DwarfCfa<TypeParam>(dmem_.get(), &fde_, ARCH_UNKNOWN));
}
- MemoryFake memory_;
+ MemoryFake* fake_memory_;
std::unique_ptr<DwarfMemory> dmem_;
std::unique_ptr<DwarfCfa<TypeParam>> cfa_;
DwarfCie cie_;
@@ -77,7 +77,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_illegal) {
// Skip gnu extension ops and aarch64 specialized op.
continue;
}
- this->memory_.SetMemory(0x2000, std::vector<uint8_t>{i});
+ this->fake_memory_->SetMemory(0x2000, std::vector<uint8_t>{i});
ResetLogs();
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x2000, 0x2001));
@@ -89,7 +89,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_illegal) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_nop) {
- this->memory_.SetMemory(0x2000, std::vector<uint8_t>{0x00});
+ this->fake_memory_->SetMemory(0x2000, std::vector<uint8_t>{0x00});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x2000, 0x2001));
std::string expected =
@@ -100,7 +100,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_nop) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_offset) {
- this->memory_.SetMemory(0x2000, std::vector<uint8_t>{0x83, 0x04});
+ this->fake_memory_->SetMemory(0x2000, std::vector<uint8_t>{0x83, 0x04});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x2000, 0x2002));
std::string expected =
@@ -110,7 +110,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_offset) {
ASSERT_EQ("", GetFakeLogBuf());
ResetLogs();
- this->memory_.SetMemory(0x2100, std::vector<uint8_t>{0x83, 0x84, 0x01});
+ this->fake_memory_->SetMemory(0x2100, std::vector<uint8_t>{0x83, 0x84, 0x01});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x2100, 0x2103));
expected =
@@ -121,7 +121,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_offset) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_offset_extended) {
- this->memory_.SetMemory(0x500, std::vector<uint8_t>{0x05, 0x03, 0x02});
+ this->fake_memory_->SetMemory(0x500, std::vector<uint8_t>{0x05, 0x03, 0x02});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x500, 0x503));
std::string expected =
@@ -131,7 +131,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_offset_extended) {
ASSERT_EQ("", GetFakeLogBuf());
ResetLogs();
- this->memory_.SetMemory(0x1500, std::vector<uint8_t>{0x05, 0x81, 0x01, 0x82, 0x12});
+ this->fake_memory_->SetMemory(0x1500, std::vector<uint8_t>{0x05, 0x81, 0x01, 0x82, 0x12});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x1500, 0x1505));
expected =
@@ -142,7 +142,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_offset_extended) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_offset_extended_sf) {
- this->memory_.SetMemory(0x500, std::vector<uint8_t>{0x11, 0x05, 0x10});
+ this->fake_memory_->SetMemory(0x500, std::vector<uint8_t>{0x11, 0x05, 0x10});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x500, 0x503));
std::string expected =
@@ -153,7 +153,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_offset_extended_sf) {
// Check a negative value for the offset.
ResetLogs();
- this->memory_.SetMemory(0x1500, std::vector<uint8_t>{0x11, 0x86, 0x01, 0xff, 0x7f});
+ this->fake_memory_->SetMemory(0x1500, std::vector<uint8_t>{0x11, 0x86, 0x01, 0xff, 0x7f});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x1500, 0x1505));
expected =
@@ -164,7 +164,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_offset_extended_sf) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_restore) {
- this->memory_.SetMemory(0x2000, std::vector<uint8_t>{0xc2});
+ this->fake_memory_->SetMemory(0x2000, std::vector<uint8_t>{0xc2});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x2000, 0x2001));
std::string expected =
@@ -174,7 +174,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_restore) {
ASSERT_EQ("", GetFakeLogBuf());
ResetLogs();
- this->memory_.SetMemory(0x3000, std::vector<uint8_t>{0x82, 0x04, 0xc2});
+ this->fake_memory_->SetMemory(0x3000, std::vector<uint8_t>{0x82, 0x04, 0xc2});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x3000, 0x3003));
expected =
@@ -187,7 +187,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_restore) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_restore_extended) {
- this->memory_.SetMemory(0x4000, std::vector<uint8_t>{0x06, 0x08});
+ this->fake_memory_->SetMemory(0x4000, std::vector<uint8_t>{0x06, 0x08});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x4000, 0x4002));
std::string expected =
@@ -197,7 +197,8 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_restore_extended) {
ASSERT_EQ("", GetFakeLogBuf());
ResetLogs();
- this->memory_.SetMemory(0x5000, std::vector<uint8_t>{0x05, 0x82, 0x02, 0x04, 0x06, 0x82, 0x02});
+ this->fake_memory_->SetMemory(0x5000,
+ std::vector<uint8_t>{0x05, 0x82, 0x02, 0x04, 0x06, 0x82, 0x02});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x5000, 0x5007));
expected =
@@ -226,7 +227,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_set_loc) {
}
memcpy(&buffer[1], &address, sizeof(address));
- this->memory_.SetMemory(0x50, buffer, sizeof(buffer));
+ this->fake_memory_->SetMemory(0x50, buffer, sizeof(buffer));
ResetLogs();
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x50, 0x51 + sizeof(TypeParam)));
@@ -251,7 +252,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_set_loc) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_advance_loc) {
- this->memory_.SetMemory(0x200, std::vector<uint8_t>{0x44});
+ this->fake_memory_->SetMemory(0x200, std::vector<uint8_t>{0x44});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x200, 0x201));
std::string expected =
@@ -264,7 +265,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_advance_loc) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_advance_loc1) {
- this->memory_.SetMemory(0x200, std::vector<uint8_t>{0x02, 0x04});
+ this->fake_memory_->SetMemory(0x200, std::vector<uint8_t>{0x02, 0x04});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x200, 0x202));
std::string expected =
@@ -277,7 +278,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_advance_loc1) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_advance_loc2) {
- this->memory_.SetMemory(0x600, std::vector<uint8_t>{0x03, 0x04, 0x03});
+ this->fake_memory_->SetMemory(0x600, std::vector<uint8_t>{0x03, 0x04, 0x03});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x600, 0x603));
std::string expected =
@@ -290,7 +291,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_advance_loc2) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_advance_loc4) {
- this->memory_.SetMemory(0x500, std::vector<uint8_t>{0x04, 0x04, 0x03, 0x02, 0x01});
+ this->fake_memory_->SetMemory(0x500, std::vector<uint8_t>{0x04, 0x04, 0x03, 0x02, 0x01});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x500, 0x505));
std::string expected =
@@ -303,7 +304,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_advance_loc4) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_undefined) {
- this->memory_.SetMemory(0xa00, std::vector<uint8_t>{0x07, 0x09});
+ this->fake_memory_->SetMemory(0xa00, std::vector<uint8_t>{0x07, 0x09});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0xa00, 0xa02));
std::string expected =
@@ -314,7 +315,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_undefined) {
ResetLogs();
DwarfLocations cie_loc_regs;
- this->memory_.SetMemory(0x1a00, std::vector<uint8_t>{0x07, 0x81, 0x01});
+ this->fake_memory_->SetMemory(0x1a00, std::vector<uint8_t>{0x07, 0x81, 0x01});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x1a00, 0x1a03));
expected =
@@ -325,7 +326,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_undefined) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_same) {
- this->memory_.SetMemory(0x100, std::vector<uint8_t>{0x08, 0x7f});
+ this->fake_memory_->SetMemory(0x100, std::vector<uint8_t>{0x08, 0x7f});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x100, 0x102));
std::string expected =
@@ -335,7 +336,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_same) {
ASSERT_EQ("", GetFakeLogBuf());
ResetLogs();
- this->memory_.SetMemory(0x2100, std::vector<uint8_t>{0x08, 0xff, 0x01});
+ this->fake_memory_->SetMemory(0x2100, std::vector<uint8_t>{0x08, 0xff, 0x01});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x2100, 0x2103));
expected =
@@ -346,7 +347,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_same) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_register) {
- this->memory_.SetMemory(0x300, std::vector<uint8_t>{0x09, 0x02, 0x01});
+ this->fake_memory_->SetMemory(0x300, std::vector<uint8_t>{0x09, 0x02, 0x01});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x300, 0x303));
std::string expected =
@@ -356,7 +357,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_register) {
ASSERT_EQ("", GetFakeLogBuf());
ResetLogs();
- this->memory_.SetMemory(0x4300, std::vector<uint8_t>{0x09, 0xff, 0x01, 0xff, 0x03});
+ this->fake_memory_->SetMemory(0x4300, std::vector<uint8_t>{0x09, 0xff, 0x01, 0xff, 0x03});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x4300, 0x4305));
expected =
@@ -367,7 +368,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_register) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_state) {
- this->memory_.SetMemory(0x300, std::vector<uint8_t>{0x0a});
+ this->fake_memory_->SetMemory(0x300, std::vector<uint8_t>{0x0a});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x300, 0x301));
@@ -378,7 +379,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_state) {
ASSERT_EQ("", GetFakeLogBuf());
ResetLogs();
- this->memory_.SetMemory(0x4300, std::vector<uint8_t>{0x0b});
+ this->fake_memory_->SetMemory(0x4300, std::vector<uint8_t>{0x0b});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x4300, 0x4301));
@@ -390,7 +391,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_state) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_state_cfa_offset_restore) {
- this->memory_.SetMemory(0x3000, std::vector<uint8_t>{0x0a, 0x0e, 0x40, 0x0b});
+ this->fake_memory_->SetMemory(0x3000, std::vector<uint8_t>{0x0a, 0x0e, 0x40, 0x0b});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x3000, 0x3004));
@@ -406,7 +407,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_state_cfa_offset_restore) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_def_cfa) {
- this->memory_.SetMemory(0x100, std::vector<uint8_t>{0x0c, 0x7f, 0x74});
+ this->fake_memory_->SetMemory(0x100, std::vector<uint8_t>{0x0c, 0x7f, 0x74});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x100, 0x103));
@@ -417,7 +418,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_def_cfa) {
ASSERT_EQ("", GetFakeLogBuf());
ResetLogs();
- this->memory_.SetMemory(0x200, std::vector<uint8_t>{0x0c, 0xff, 0x02, 0xf4, 0x04});
+ this->fake_memory_->SetMemory(0x200, std::vector<uint8_t>{0x0c, 0xff, 0x02, 0xf4, 0x04});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x200, 0x205));
@@ -429,7 +430,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_def_cfa) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_def_cfa_sf) {
- this->memory_.SetMemory(0x100, std::vector<uint8_t>{0x12, 0x30, 0x25});
+ this->fake_memory_->SetMemory(0x100, std::vector<uint8_t>{0x12, 0x30, 0x25});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x100, 0x103));
@@ -441,7 +442,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_def_cfa_sf) {
// Test a negative value.
ResetLogs();
- this->memory_.SetMemory(0x200, std::vector<uint8_t>{0x12, 0xa3, 0x01, 0xfa, 0x7f});
+ this->fake_memory_->SetMemory(0x200, std::vector<uint8_t>{0x12, 0xa3, 0x01, 0xfa, 0x7f});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x200, 0x205));
@@ -453,7 +454,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_def_cfa_sf) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_def_cfa_register) {
- this->memory_.SetMemory(0x100, std::vector<uint8_t>{0x0d, 0x72});
+ this->fake_memory_->SetMemory(0x100, std::vector<uint8_t>{0x0d, 0x72});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x100, 0x102));
@@ -464,7 +465,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_def_cfa_register) {
ASSERT_EQ("", GetFakeLogBuf());
ResetLogs();
- this->memory_.SetMemory(0x200, std::vector<uint8_t>{0x0d, 0xf9, 0x20});
+ this->fake_memory_->SetMemory(0x200, std::vector<uint8_t>{0x0d, 0xf9, 0x20});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x200, 0x203));
@@ -476,7 +477,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_def_cfa_register) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_def_cfa_offset) {
- this->memory_.SetMemory(0x100, std::vector<uint8_t>{0x0e, 0x59});
+ this->fake_memory_->SetMemory(0x100, std::vector<uint8_t>{0x0e, 0x59});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x100, 0x102));
@@ -496,7 +497,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_def_cfa_offset) {
ASSERT_EQ("", GetFakeLogBuf());
ResetLogs();
- this->memory_.SetMemory(0x200, std::vector<uint8_t>{0x0e, 0xd4, 0x0a});
+ this->fake_memory_->SetMemory(0x200, std::vector<uint8_t>{0x0e, 0xd4, 0x0a});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x200, 0x203));
@@ -508,7 +509,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_def_cfa_offset) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_def_cfa_offset_sf) {
- this->memory_.SetMemory(0x100, std::vector<uint8_t>{0x13, 0x23});
+ this->fake_memory_->SetMemory(0x100, std::vector<uint8_t>{0x13, 0x23});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x100, 0x102));
@@ -529,7 +530,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_def_cfa_offset_sf) {
// Negative offset.
ResetLogs();
- this->memory_.SetMemory(0x200, std::vector<uint8_t>{0x13, 0xf6, 0x7f});
+ this->fake_memory_->SetMemory(0x200, std::vector<uint8_t>{0x13, 0xf6, 0x7f});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x200, 0x203));
@@ -541,7 +542,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_def_cfa_offset_sf) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_def_cfa_expression) {
- this->memory_.SetMemory(0x100, std::vector<uint8_t>{0x0f, 0x04, 0x01, 0x02, 0x04, 0x05});
+ this->fake_memory_->SetMemory(0x100, std::vector<uint8_t>{0x0f, 0x04, 0x01, 0x02, 0x04, 0x05});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x100, 0x106));
@@ -574,7 +575,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_def_cfa_expression) {
}
}
expected += '\n';
- this->memory_.SetMemory(0x200, ops);
+ this->fake_memory_->SetMemory(0x200, ops);
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x200, 0x284));
expected = "4 unwind DW_CFA_def_cfa_expression 129\n" + expected;
@@ -583,7 +584,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_def_cfa_expression) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_expression) {
- this->memory_.SetMemory(0x100, std::vector<uint8_t>{0x10, 0x04, 0x02, 0xc0, 0xc1});
+ this->fake_memory_->SetMemory(0x100, std::vector<uint8_t>{0x10, 0x04, 0x02, 0xc0, 0xc1});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x100, 0x105));
@@ -612,7 +613,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_expression) {
}
expected = "4 unwind DW_CFA_expression register(255) 130\n" + expected + "\n";
- this->memory_.SetMemory(0x200, ops);
+ this->fake_memory_->SetMemory(0x200, ops);
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x200, 0x287));
ASSERT_EQ(expected + op_string, GetFakeLogPrint());
@@ -620,7 +621,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_expression) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_val_offset) {
- this->memory_.SetMemory(0x100, std::vector<uint8_t>{0x14, 0x45, 0x54});
+ this->fake_memory_->SetMemory(0x100, std::vector<uint8_t>{0x14, 0x45, 0x54});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x100, 0x103));
@@ -631,7 +632,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_val_offset) {
ASSERT_EQ("", GetFakeLogBuf());
ResetLogs();
- this->memory_.SetMemory(0x400, std::vector<uint8_t>{0x14, 0xa2, 0x02, 0xb4, 0x05});
+ this->fake_memory_->SetMemory(0x400, std::vector<uint8_t>{0x14, 0xa2, 0x02, 0xb4, 0x05});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x400, 0x405));
@@ -643,7 +644,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_val_offset) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_val_offset_sf) {
- this->memory_.SetMemory(0x100, std::vector<uint8_t>{0x15, 0x56, 0x12});
+ this->fake_memory_->SetMemory(0x100, std::vector<uint8_t>{0x15, 0x56, 0x12});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x100, 0x103));
@@ -655,7 +656,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_val_offset_sf) {
// Negative value.
ResetLogs();
- this->memory_.SetMemory(0xa00, std::vector<uint8_t>{0x15, 0xff, 0x01, 0xc0, 0x7f});
+ this->fake_memory_->SetMemory(0xa00, std::vector<uint8_t>{0x15, 0xff, 0x01, 0xc0, 0x7f});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0xa00, 0xa05));
@@ -667,7 +668,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_val_offset_sf) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_val_expression) {
- this->memory_.SetMemory(0x100, std::vector<uint8_t>{0x16, 0x05, 0x02, 0xb0, 0xb1});
+ this->fake_memory_->SetMemory(0x100, std::vector<uint8_t>{0x16, 0x05, 0x02, 0xb0, 0xb1});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x100, 0x105));
@@ -696,7 +697,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_val_expression) {
}
expected = "4 unwind DW_CFA_val_expression register(2051) 168\n" + expected + "\n";
- this->memory_.SetMemory(0xa00, ops);
+ this->fake_memory_->SetMemory(0xa00, ops);
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0xa00, 0xaad));
@@ -705,7 +706,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_val_expression) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_gnu_args_size) {
- this->memory_.SetMemory(0x2000, std::vector<uint8_t>{0x2e, 0x04});
+ this->fake_memory_->SetMemory(0x2000, std::vector<uint8_t>{0x2e, 0x04});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x2000, 0x2002));
@@ -716,7 +717,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_gnu_args_size) {
ASSERT_EQ("", GetFakeLogBuf());
ResetLogs();
- this->memory_.SetMemory(0x5000, std::vector<uint8_t>{0x2e, 0xa4, 0x80, 0x04});
+ this->fake_memory_->SetMemory(0x5000, std::vector<uint8_t>{0x2e, 0xa4, 0x80, 0x04});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x5000, 0x5004));
@@ -728,7 +729,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_gnu_args_size) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_gnu_negative_offset_extended) {
- this->memory_.SetMemory(0x500, std::vector<uint8_t>{0x2f, 0x08, 0x10});
+ this->fake_memory_->SetMemory(0x500, std::vector<uint8_t>{0x2f, 0x08, 0x10});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x500, 0x503));
@@ -739,7 +740,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_gnu_negative_offset_extended) {
ASSERT_EQ("", GetFakeLogBuf());
ResetLogs();
- this->memory_.SetMemory(0x1500, std::vector<uint8_t>{0x2f, 0x81, 0x02, 0xff, 0x01});
+ this->fake_memory_->SetMemory(0x1500, std::vector<uint8_t>{0x2f, 0x81, 0x02, 0xff, 0x01});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x1500, 0x1505));
@@ -751,7 +752,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_gnu_negative_offset_extended) {
}
TYPED_TEST_P(DwarfCfaLogTest, cfa_register_override) {
- this->memory_.SetMemory(0x300, std::vector<uint8_t>{0x09, 0x02, 0x01, 0x09, 0x02, 0x04});
+ this->fake_memory_->SetMemory(0x300, std::vector<uint8_t>{0x09, 0x02, 0x01, 0x09, 0x02, 0x04});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x300, 0x306));
@@ -766,7 +767,7 @@ TYPED_TEST_P(DwarfCfaLogTest, cfa_register_override) {
TYPED_TEST_P(DwarfCfaLogTest, cfa_aarch64_negate_ra_state) {
// Verify that if the cfa op is handled properly depending on aarch.
- this->memory_.SetMemory(0x2000, std::vector<uint8_t>{0x2d});
+ this->fake_memory_->SetMemory(0x2000, std::vector<uint8_t>{0x2d});
ASSERT_TRUE(this->cfa_->Log(0, this->fde_.pc_start, 0x2000, 0x2001));
std::string expected = "4 unwind Illegal (Only valid on aarch64)\n";
diff --git a/libunwindstack/tests/DwarfCfaTest.cpp b/libunwindstack/tests/DwarfCfaTest.cpp
index 45728fb..937d50b 100644
--- a/libunwindstack/tests/DwarfCfaTest.cpp
+++ b/libunwindstack/tests/DwarfCfaTest.cpp
@@ -41,9 +41,10 @@ class DwarfCfaTest : public ::testing::Test {
protected:
void SetUp() override {
ResetLogs();
- memory_.Clear();
- dmem_.reset(new DwarfMemory(&memory_));
+ fake_memory_ = new MemoryFake;
+ std::shared_ptr<Memory> memory(fake_memory_);
+ dmem_.reset(new DwarfMemory(memory));
cie_.cfa_instructions_offset = 0x1000;
cie_.cfa_instructions_end = 0x1030;
@@ -60,7 +61,7 @@ class DwarfCfaTest : public ::testing::Test {
cfa_.reset(new DwarfCfa<TypeParam>(dmem_.get(), &fde_, ARCH_UNKNOWN));
}
- MemoryFake memory_;
+ MemoryFake* fake_memory_;
std::unique_ptr<DwarfMemory> dmem_;
std::unique_ptr<DwarfCfa<TypeParam>> cfa_;
DwarfCie cie_;
@@ -76,7 +77,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_illegal) {
// Skip gnu extension ops and aarch64 specialized op.
continue;
}
- this->memory_.SetMemory(0x2000, std::vector<uint8_t>{i});
+ this->fake_memory_->SetMemory(0x2000, std::vector<uint8_t>{i});
DwarfLocations loc_regs;
ASSERT_FALSE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x2000, 0x2001, &loc_regs));
@@ -89,7 +90,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_illegal) {
}
TYPED_TEST_P(DwarfCfaTest, cfa_nop) {
- this->memory_.SetMemory(0x2000, std::vector<uint8_t>{0x00});
+ this->fake_memory_->SetMemory(0x2000, std::vector<uint8_t>{0x00});
DwarfLocations loc_regs;
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x2000, 0x2001, &loc_regs));
@@ -102,7 +103,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_nop) {
// This test needs to be examined.
TYPED_TEST_P(DwarfCfaTest, cfa_offset) {
- this->memory_.SetMemory(0x2000, std::vector<uint8_t>{0x83, 0x04});
+ this->fake_memory_->SetMemory(0x2000, std::vector<uint8_t>{0x83, 0x04});
DwarfLocations loc_regs;
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x2000, 0x2002, &loc_regs));
@@ -117,7 +118,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_offset) {
ASSERT_EQ("", GetFakeLogBuf());
ResetLogs();
- this->memory_.SetMemory(0x2100, std::vector<uint8_t>{0x83, 0x84, 0x01});
+ this->fake_memory_->SetMemory(0x2100, std::vector<uint8_t>{0x83, 0x84, 0x01});
loc_regs.clear();
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x2100, 0x2103, &loc_regs));
@@ -133,7 +134,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_offset) {
}
TYPED_TEST_P(DwarfCfaTest, cfa_offset_extended) {
- this->memory_.SetMemory(0x500, std::vector<uint8_t>{0x05, 0x03, 0x02});
+ this->fake_memory_->SetMemory(0x500, std::vector<uint8_t>{0x05, 0x03, 0x02});
DwarfLocations loc_regs;
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x500, 0x503, &loc_regs));
@@ -149,7 +150,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_offset_extended) {
ResetLogs();
loc_regs.clear();
- this->memory_.SetMemory(0x1500, std::vector<uint8_t>{0x05, 0x81, 0x01, 0x82, 0x12});
+ this->fake_memory_->SetMemory(0x1500, std::vector<uint8_t>{0x05, 0x81, 0x01, 0x82, 0x12});
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x1500, 0x1505, &loc_regs));
ASSERT_EQ(0x1505U, this->dmem_->cur_offset());
@@ -164,7 +165,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_offset_extended) {
}
TYPED_TEST_P(DwarfCfaTest, cfa_offset_extended_sf) {
- this->memory_.SetMemory(0x500, std::vector<uint8_t>{0x11, 0x05, 0x10});
+ this->fake_memory_->SetMemory(0x500, std::vector<uint8_t>{0x11, 0x05, 0x10});
DwarfLocations loc_regs;
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x500, 0x503, &loc_regs));
@@ -181,7 +182,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_offset_extended_sf) {
// Check a negative value for the offset.
ResetLogs();
loc_regs.clear();
- this->memory_.SetMemory(0x1500, std::vector<uint8_t>{0x11, 0x86, 0x01, 0xff, 0x7f});
+ this->fake_memory_->SetMemory(0x1500, std::vector<uint8_t>{0x11, 0x86, 0x01, 0xff, 0x7f});
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x1500, 0x1505, &loc_regs));
ASSERT_EQ(0x1505U, this->dmem_->cur_offset());
@@ -196,7 +197,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_offset_extended_sf) {
}
TYPED_TEST_P(DwarfCfaTest, cfa_restore) {
- this->memory_.SetMemory(0x2000, std::vector<uint8_t>{0xc2});
+ this->fake_memory_->SetMemory(0x2000, std::vector<uint8_t>{0xc2});
DwarfLocations loc_regs;
ASSERT_FALSE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x2000, 0x2001, &loc_regs));
@@ -211,7 +212,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_restore) {
DwarfLocations cie_loc_regs;
cie_loc_regs[2] = {.type = DWARF_LOCATION_REGISTER, .values = {0, 0}};
this->cfa_->set_cie_loc_regs(&cie_loc_regs);
- this->memory_.SetMemory(0x3000, std::vector<uint8_t>{0x82, 0x04, 0xc2});
+ this->fake_memory_->SetMemory(0x3000, std::vector<uint8_t>{0x82, 0x04, 0xc2});
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x3000, 0x3003, &loc_regs));
ASSERT_EQ(0x3003U, this->dmem_->cur_offset());
@@ -225,7 +226,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_restore) {
}
TYPED_TEST_P(DwarfCfaTest, cfa_restore_extended) {
- this->memory_.SetMemory(0x4000, std::vector<uint8_t>{0x06, 0x08});
+ this->fake_memory_->SetMemory(0x4000, std::vector<uint8_t>{0x06, 0x08});
DwarfLocations loc_regs;
ASSERT_FALSE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x4000, 0x4002, &loc_regs));
@@ -238,7 +239,8 @@ TYPED_TEST_P(DwarfCfaTest, cfa_restore_extended) {
ResetLogs();
loc_regs.clear();
- this->memory_.SetMemory(0x5000, std::vector<uint8_t>{0x05, 0x82, 0x02, 0x04, 0x06, 0x82, 0x02});
+ this->fake_memory_->SetMemory(0x5000,
+ std::vector<uint8_t>{0x05, 0x82, 0x02, 0x04, 0x06, 0x82, 0x02});
DwarfLocations cie_loc_regs;
cie_loc_regs[258] = {.type = DWARF_LOCATION_REGISTER, .values = {0, 0}};
this->cfa_->set_cie_loc_regs(&cie_loc_regs);
@@ -271,7 +273,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_set_loc) {
}
memcpy(&buffer[1], &address, sizeof(address));
- this->memory_.SetMemory(0x50, buffer, sizeof(buffer));
+ this->fake_memory_->SetMemory(0x50, buffer, sizeof(buffer));
ResetLogs();
DwarfLocations loc_regs;
ASSERT_TRUE(
@@ -302,7 +304,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_set_loc) {
}
TYPED_TEST_P(DwarfCfaTest, cfa_advance_loc1) {
- this->memory_.SetMemory(0x200, std::vector<uint8_t>{0x02, 0x04});
+ this->fake_memory_->SetMemory(0x200, std::vector<uint8_t>{0x02, 0x04});
DwarfLocations loc_regs;
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x200, 0x202, &loc_regs));
@@ -315,7 +317,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_advance_loc1) {
}
TYPED_TEST_P(DwarfCfaTest, cfa_advance_loc2) {
- this->memory_.SetMemory(0x600, std::vector<uint8_t>{0x03, 0x04, 0x03});
+ this->fake_memory_->SetMemory(0x600, std::vector<uint8_t>{0x03, 0x04, 0x03});
DwarfLocations loc_regs;
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x600, 0x603, &loc_regs));
@@ -328,7 +330,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_advance_loc2) {
}
TYPED_TEST_P(DwarfCfaTest, cfa_advance_loc4) {
- this->memory_.SetMemory(0x500, std::vector<uint8_t>{0x04, 0x04, 0x03, 0x02, 0x01});
+ this->fake_memory_->SetMemory(0x500, std::vector<uint8_t>{0x04, 0x04, 0x03, 0x02, 0x01});
DwarfLocations loc_regs;
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x500, 0x505, &loc_regs));
@@ -341,7 +343,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_advance_loc4) {
}
TYPED_TEST_P(DwarfCfaTest, cfa_undefined) {
- this->memory_.SetMemory(0xa00, std::vector<uint8_t>{0x07, 0x09});
+ this->fake_memory_->SetMemory(0xa00, std::vector<uint8_t>{0x07, 0x09});
DwarfLocations loc_regs;
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0xa00, 0xa02, &loc_regs));
@@ -356,7 +358,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_undefined) {
ResetLogs();
loc_regs.clear();
- this->memory_.SetMemory(0x1a00, std::vector<uint8_t>{0x07, 0x81, 0x01});
+ this->fake_memory_->SetMemory(0x1a00, std::vector<uint8_t>{0x07, 0x81, 0x01});
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x1a00, 0x1a03, &loc_regs));
ASSERT_EQ(0x1a03U, this->dmem_->cur_offset());
@@ -370,7 +372,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_undefined) {
}
TYPED_TEST_P(DwarfCfaTest, cfa_same) {
- this->memory_.SetMemory(0x100, std::vector<uint8_t>{0x08, 0x7f});
+ this->fake_memory_->SetMemory(0x100, std::vector<uint8_t>{0x08, 0x7f});
DwarfLocations loc_regs;
loc_regs[127] = {.type = DWARF_LOCATION_REGISTER, .values = {0, 0}};
@@ -384,7 +386,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_same) {
ResetLogs();
loc_regs.clear();
- this->memory_.SetMemory(0x2100, std::vector<uint8_t>{0x08, 0xff, 0x01});
+ this->fake_memory_->SetMemory(0x2100, std::vector<uint8_t>{0x08, 0xff, 0x01});
loc_regs[255] = {.type = DWARF_LOCATION_REGISTER, .values = {0, 0}};
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x2100, 0x2103, &loc_regs));
@@ -397,7 +399,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_same) {
}
TYPED_TEST_P(DwarfCfaTest, cfa_register) {
- this->memory_.SetMemory(0x300, std::vector<uint8_t>{0x09, 0x02, 0x01});
+ this->fake_memory_->SetMemory(0x300, std::vector<uint8_t>{0x09, 0x02, 0x01});
DwarfLocations loc_regs;
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x300, 0x303, &loc_regs));
@@ -413,7 +415,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_register) {
ResetLogs();
loc_regs.clear();
- this->memory_.SetMemory(0x4300, std::vector<uint8_t>{0x09, 0xff, 0x01, 0xff, 0x03});
+ this->fake_memory_->SetMemory(0x4300, std::vector<uint8_t>{0x09, 0xff, 0x01, 0xff, 0x03});
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x4300, 0x4305, &loc_regs));
ASSERT_EQ(0x4305U, this->dmem_->cur_offset());
@@ -428,7 +430,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_register) {
}
TYPED_TEST_P(DwarfCfaTest, cfa_state) {
- this->memory_.SetMemory(0x300, std::vector<uint8_t>{0x0a});
+ this->fake_memory_->SetMemory(0x300, std::vector<uint8_t>{0x0a});
DwarfLocations loc_regs;
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x300, 0x301, &loc_regs));
@@ -439,7 +441,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_state) {
ASSERT_EQ("", GetFakeLogBuf());
ResetLogs();
- this->memory_.SetMemory(0x4300, std::vector<uint8_t>{0x0b});
+ this->fake_memory_->SetMemory(0x4300, std::vector<uint8_t>{0x0b});
loc_regs.clear();
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x4300, 0x4301, &loc_regs));
@@ -450,7 +452,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_state) {
ASSERT_EQ("", GetFakeLogBuf());
ResetLogs();
- this->memory_.SetMemory(0x2000, std::vector<uint8_t>{0x85, 0x02, 0x0a, 0x86, 0x04, 0x0b});
+ this->fake_memory_->SetMemory(0x2000, std::vector<uint8_t>{0x85, 0x02, 0x0a, 0x86, 0x04, 0x0b});
loc_regs.clear();
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x2000, 0x2005, &loc_regs));
@@ -466,7 +468,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_state) {
ASSERT_NE(loc_regs.end(), loc_regs.find(5));
ResetLogs();
- this->memory_.SetMemory(
+ this->fake_memory_->SetMemory(
0x6000, std::vector<uint8_t>{0x0a, 0x85, 0x02, 0x0a, 0x86, 0x04, 0x0a, 0x87, 0x01, 0x0a, 0x89,
0x05, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b});
@@ -515,7 +517,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_state) {
// Even though the spec is not clear about whether the offset is also
// restored, the gcc unwinder does, and libunwind does too.
TYPED_TEST_P(DwarfCfaTest, cfa_state_cfa_offset_restore) {
- this->memory_.SetMemory(0x3000, std::vector<uint8_t>{0x0a, 0x0e, 0x40, 0x0b});
+ this->fake_memory_->SetMemory(0x3000, std::vector<uint8_t>{0x0a, 0x0e, 0x40, 0x0b});
DwarfLocations loc_regs;
loc_regs[CFA_REG] = {.type = DWARF_LOCATION_REGISTER, .values = {5, 100}};
@@ -531,7 +533,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_state_cfa_offset_restore) {
}
TYPED_TEST_P(DwarfCfaTest, cfa_def_cfa) {
- this->memory_.SetMemory(0x100, std::vector<uint8_t>{0x0c, 0x7f, 0x74});
+ this->fake_memory_->SetMemory(0x100, std::vector<uint8_t>{0x0c, 0x7f, 0x74});
DwarfLocations loc_regs;
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x100, 0x103, &loc_regs));
@@ -546,7 +548,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_def_cfa) {
ResetLogs();
loc_regs.clear();
- this->memory_.SetMemory(0x200, std::vector<uint8_t>{0x0c, 0xff, 0x02, 0xf4, 0x04});
+ this->fake_memory_->SetMemory(0x200, std::vector<uint8_t>{0x0c, 0xff, 0x02, 0xf4, 0x04});
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x200, 0x205, &loc_regs));
ASSERT_EQ(0x205U, this->dmem_->cur_offset());
@@ -560,7 +562,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_def_cfa) {
}
TYPED_TEST_P(DwarfCfaTest, cfa_def_cfa_sf) {
- this->memory_.SetMemory(0x100, std::vector<uint8_t>{0x12, 0x30, 0x25});
+ this->fake_memory_->SetMemory(0x100, std::vector<uint8_t>{0x12, 0x30, 0x25});
DwarfLocations loc_regs;
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x100, 0x103, &loc_regs));
@@ -576,7 +578,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_def_cfa_sf) {
// Test a negative value.
ResetLogs();
loc_regs.clear();
- this->memory_.SetMemory(0x200, std::vector<uint8_t>{0x12, 0xa3, 0x01, 0xfa, 0x7f});
+ this->fake_memory_->SetMemory(0x200, std::vector<uint8_t>{0x12, 0xa3, 0x01, 0xfa, 0x7f});
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x200, 0x205, &loc_regs));
ASSERT_EQ(0x205U, this->dmem_->cur_offset());
@@ -590,7 +592,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_def_cfa_sf) {
}
TYPED_TEST_P(DwarfCfaTest, cfa_def_cfa_register) {
- this->memory_.SetMemory(0x100, std::vector<uint8_t>{0x0d, 0x72});
+ this->fake_memory_->SetMemory(0x100, std::vector<uint8_t>{0x0d, 0x72});
DwarfLocations loc_regs;
// This fails because the cfa is not defined as a register.
@@ -617,7 +619,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_def_cfa_register) {
ASSERT_EQ("", GetFakeLogBuf());
ResetLogs();
- this->memory_.SetMemory(0x200, std::vector<uint8_t>{0x0d, 0xf9, 0x20});
+ this->fake_memory_->SetMemory(0x200, std::vector<uint8_t>{0x0d, 0xf9, 0x20});
loc_regs.clear();
loc_regs[CFA_REG] = {.type = DWARF_LOCATION_REGISTER, .values = {3, 60}};
@@ -633,7 +635,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_def_cfa_register) {
}
TYPED_TEST_P(DwarfCfaTest, cfa_def_cfa_offset) {
- this->memory_.SetMemory(0x100, std::vector<uint8_t>{0x0e, 0x59});
+ this->fake_memory_->SetMemory(0x100, std::vector<uint8_t>{0x0e, 0x59});
DwarfLocations loc_regs;
// This fails because the cfa is not defined as a register.
@@ -660,7 +662,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_def_cfa_offset) {
ASSERT_EQ("", GetFakeLogBuf());
ResetLogs();
- this->memory_.SetMemory(0x200, std::vector<uint8_t>{0x0e, 0xd4, 0x0a});
+ this->fake_memory_->SetMemory(0x200, std::vector<uint8_t>{0x0e, 0xd4, 0x0a});
loc_regs.clear();
loc_regs[CFA_REG] = {.type = DWARF_LOCATION_REGISTER, .values = {3}};
@@ -676,7 +678,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_def_cfa_offset) {
}
TYPED_TEST_P(DwarfCfaTest, cfa_def_cfa_offset_sf) {
- this->memory_.SetMemory(0x100, std::vector<uint8_t>{0x13, 0x23});
+ this->fake_memory_->SetMemory(0x100, std::vector<uint8_t>{0x13, 0x23});
DwarfLocations loc_regs;
// This fails because the cfa is not defined as a register.
@@ -703,7 +705,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_def_cfa_offset_sf) {
// Negative offset.
ResetLogs();
- this->memory_.SetMemory(0x200, std::vector<uint8_t>{0x13, 0xf6, 0x7f});
+ this->fake_memory_->SetMemory(0x200, std::vector<uint8_t>{0x13, 0xf6, 0x7f});
loc_regs.clear();
loc_regs[CFA_REG] = {.type = DWARF_LOCATION_REGISTER, .values = {3}};
@@ -719,7 +721,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_def_cfa_offset_sf) {
}
TYPED_TEST_P(DwarfCfaTest, cfa_def_cfa_expression) {
- this->memory_.SetMemory(0x100, std::vector<uint8_t>{0x0f, 0x04, 0x01, 0x02, 0x03, 0x04});
+ this->fake_memory_->SetMemory(0x100, std::vector<uint8_t>{0x0f, 0x04, 0x01, 0x02, 0x03, 0x04});
DwarfLocations loc_regs;
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x100, 0x106, &loc_regs));
@@ -734,7 +736,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_def_cfa_expression) {
for (uint8_t i = 3; i < 132; i++) {
ops.push_back(i - 1);
}
- this->memory_.SetMemory(0x200, ops);
+ this->fake_memory_->SetMemory(0x200, ops);
loc_regs.clear();
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x200, 0x284, &loc_regs));
ASSERT_EQ(0x284U, this->dmem_->cur_offset());
@@ -747,7 +749,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_def_cfa_expression) {
}
TYPED_TEST_P(DwarfCfaTest, cfa_expression) {
- this->memory_.SetMemory(0x100, std::vector<uint8_t>{0x10, 0x04, 0x02, 0x40, 0x20});
+ this->fake_memory_->SetMemory(0x100, std::vector<uint8_t>{0x10, 0x04, 0x02, 0x40, 0x20});
DwarfLocations loc_regs;
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x100, 0x105, &loc_regs));
@@ -768,7 +770,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_expression) {
ops.push_back(i - 4);
}
- this->memory_.SetMemory(0x200, ops);
+ this->fake_memory_->SetMemory(0x200, ops);
loc_regs.clear();
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x200, 0x287, &loc_regs));
ASSERT_EQ(0x287U, this->dmem_->cur_offset());
@@ -784,7 +786,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_expression) {
}
TYPED_TEST_P(DwarfCfaTest, cfa_val_offset) {
- this->memory_.SetMemory(0x100, std::vector<uint8_t>{0x14, 0x45, 0x54});
+ this->fake_memory_->SetMemory(0x100, std::vector<uint8_t>{0x14, 0x45, 0x54});
DwarfLocations loc_regs;
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x100, 0x103, &loc_regs));
@@ -800,7 +802,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_val_offset) {
ResetLogs();
loc_regs.clear();
- this->memory_.SetMemory(0x400, std::vector<uint8_t>{0x14, 0xa2, 0x02, 0xb4, 0x05});
+ this->fake_memory_->SetMemory(0x400, std::vector<uint8_t>{0x14, 0xa2, 0x02, 0xb4, 0x05});
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x400, 0x405, &loc_regs));
ASSERT_EQ(0x405U, this->dmem_->cur_offset());
@@ -815,7 +817,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_val_offset) {
}
TYPED_TEST_P(DwarfCfaTest, cfa_val_offset_sf) {
- this->memory_.SetMemory(0x100, std::vector<uint8_t>{0x15, 0x56, 0x12});
+ this->fake_memory_->SetMemory(0x100, std::vector<uint8_t>{0x15, 0x56, 0x12});
DwarfLocations loc_regs;
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x100, 0x103, &loc_regs));
@@ -832,7 +834,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_val_offset_sf) {
// Negative value.
ResetLogs();
loc_regs.clear();
- this->memory_.SetMemory(0xa00, std::vector<uint8_t>{0x15, 0xff, 0x01, 0xc0, 0x7f});
+ this->fake_memory_->SetMemory(0xa00, std::vector<uint8_t>{0x15, 0xff, 0x01, 0xc0, 0x7f});
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0xa00, 0xa05, &loc_regs));
ASSERT_EQ(0xa05U, this->dmem_->cur_offset());
@@ -847,7 +849,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_val_offset_sf) {
}
TYPED_TEST_P(DwarfCfaTest, cfa_val_expression) {
- this->memory_.SetMemory(0x100, std::vector<uint8_t>{0x16, 0x05, 0x02, 0x10, 0x20});
+ this->fake_memory_->SetMemory(0x100, std::vector<uint8_t>{0x16, 0x05, 0x02, 0x10, 0x20});
DwarfLocations loc_regs;
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x100, 0x105, &loc_regs));
@@ -868,7 +870,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_val_expression) {
ops.push_back(i);
}
- this->memory_.SetMemory(0xa00, ops);
+ this->fake_memory_->SetMemory(0xa00, ops);
loc_regs.clear();
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0xa00, 0xaad, &loc_regs));
@@ -885,7 +887,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_val_expression) {
}
TYPED_TEST_P(DwarfCfaTest, cfa_gnu_args_size) {
- this->memory_.SetMemory(0x2000, std::vector<uint8_t>{0x2e, 0x04});
+ this->fake_memory_->SetMemory(0x2000, std::vector<uint8_t>{0x2e, 0x04});
DwarfLocations loc_regs;
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x2000, 0x2002, &loc_regs));
@@ -897,7 +899,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_gnu_args_size) {
ResetLogs();
loc_regs.clear();
- this->memory_.SetMemory(0x5000, std::vector<uint8_t>{0x2e, 0xa4, 0x80, 0x04});
+ this->fake_memory_->SetMemory(0x5000, std::vector<uint8_t>{0x2e, 0xa4, 0x80, 0x04});
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x5000, 0x5004, &loc_regs));
ASSERT_EQ(0x5004U, this->dmem_->cur_offset());
@@ -908,7 +910,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_gnu_args_size) {
}
TYPED_TEST_P(DwarfCfaTest, cfa_gnu_negative_offset_extended) {
- this->memory_.SetMemory(0x500, std::vector<uint8_t>{0x2f, 0x08, 0x10});
+ this->fake_memory_->SetMemory(0x500, std::vector<uint8_t>{0x2f, 0x08, 0x10});
DwarfLocations loc_regs;
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x500, 0x503, &loc_regs));
@@ -924,7 +926,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_gnu_negative_offset_extended) {
ResetLogs();
loc_regs.clear();
- this->memory_.SetMemory(0x1500, std::vector<uint8_t>{0x2f, 0x81, 0x02, 0xff, 0x01});
+ this->fake_memory_->SetMemory(0x1500, std::vector<uint8_t>{0x2f, 0x81, 0x02, 0xff, 0x01});
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x1500, 0x1505, &loc_regs));
ASSERT_EQ(0x1505U, this->dmem_->cur_offset());
@@ -939,7 +941,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_gnu_negative_offset_extended) {
}
TYPED_TEST_P(DwarfCfaTest, cfa_register_override) {
- this->memory_.SetMemory(0x300, std::vector<uint8_t>{0x09, 0x02, 0x01, 0x09, 0x02, 0x04});
+ this->fake_memory_->SetMemory(0x300, std::vector<uint8_t>{0x09, 0x02, 0x01, 0x09, 0x02, 0x04});
DwarfLocations loc_regs;
ASSERT_TRUE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x300, 0x306, &loc_regs));
@@ -955,7 +957,7 @@ TYPED_TEST_P(DwarfCfaTest, cfa_register_override) {
}
TYPED_TEST_P(DwarfCfaTest, cfa_aarch64_negate_ra_state) {
- this->memory_.SetMemory(0x2000, std::vector<uint8_t>{0x2d});
+ this->fake_memory_->SetMemory(0x2000, std::vector<uint8_t>{0x2d});
DwarfLocations loc_regs;
ASSERT_FALSE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x2000, 0x2001, &loc_regs));
diff --git a/libunwindstack/tests/DwarfDebugFrameTest.cpp b/libunwindstack/tests/DwarfDebugFrameTest.cpp
index 01ee372..90dab32 100644
--- a/libunwindstack/tests/DwarfDebugFrameTest.cpp
+++ b/libunwindstack/tests/DwarfDebugFrameTest.cpp
@@ -36,14 +36,15 @@ template <typename TypeParam>
class DwarfDebugFrameTest : public ::testing::Test {
protected:
void SetUp() override {
- memory_.Clear();
- debug_frame_ = new DwarfDebugFrame<TypeParam>(&memory_);
+ fake_memory_ = new MemoryFake;
+ std::shared_ptr<Memory> memory(fake_memory_);
+ debug_frame_ = new DwarfDebugFrame<TypeParam>(memory);
ResetLogs();
}
void TearDown() override { delete debug_frame_; }
- MemoryFake memory_;
+ MemoryFake* fake_memory_;
DwarfDebugFrame<TypeParam>* debug_frame_ = nullptr;
};
TYPED_TEST_SUITE_P(DwarfDebugFrameTest);
@@ -122,13 +123,13 @@ static void SetFourFdes32(MemoryFake* memory) {
}
TYPED_TEST_P(DwarfDebugFrameTest, Init_compressed) {
- SetFourFdes32(&this->memory_);
+ SetFourFdes32(this->fake_memory_);
ASSERT_FALSE(this->debug_frame_->Init(
SectionInfo{.offset = 0x5000, .size = 0x600, .flags = SHF_COMPRESSED}));
}
TYPED_TEST_P(DwarfDebugFrameTest, GetFdes32) {
- SetFourFdes32(&this->memory_);
+ SetFourFdes32(this->fake_memory_);
ASSERT_TRUE(this->debug_frame_->Init(SectionInfo{.offset = 0x5000, .size = 0x600}));
std::vector<const DwarfFde*> fdes;
@@ -170,7 +171,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetFdes32) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetFdes32_after_GetFdeFromPc) {
- SetFourFdes32(&this->memory_);
+ SetFourFdes32(this->fake_memory_);
ASSERT_TRUE(this->debug_frame_->Init(SectionInfo{.offset = 0x5000, .size = 0x600}));
const DwarfFde* fde = this->debug_frame_->GetFdeFromPc(0x3600);
@@ -194,7 +195,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetFdes32_after_GetFdeFromPc) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetFdes32_not_in_section) {
- SetFourFdes32(&this->memory_);
+ SetFourFdes32(this->fake_memory_);
ASSERT_TRUE(this->debug_frame_->Init(SectionInfo{.offset = 0x5000, .size = 0x500}));
std::vector<const DwarfFde*> fdes;
@@ -204,8 +205,8 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetFdes32_not_in_section) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetFdes32_big_function_address) {
- SetCie32(&this->memory_, 0x5000, 0xfc, std::vector<uint8_t>{1, '\0', 0, 0, 1});
- SetFde32(&this->memory_, 0x5100, 0xfc, 0, 0xe9ad9b1f, 0x200);
+ SetCie32(this->fake_memory_, 0x5000, 0xfc, std::vector<uint8_t>{1, '\0', 0, 0, 1});
+ SetFde32(this->fake_memory_, 0x5100, 0xfc, 0, 0xe9ad9b1f, 0x200);
ASSERT_TRUE(this->debug_frame_->Init(SectionInfo{.offset = 0x5000, .size = 0x200}));
std::vector<const DwarfFde*> fdes;
@@ -223,7 +224,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetFdes32_big_function_address) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetFdeFromPc32) {
- SetFourFdes32(&this->memory_);
+ SetFourFdes32(this->fake_memory_);
ASSERT_TRUE(this->debug_frame_->Init(SectionInfo{.offset = 0x5000, .size = 0x600}));
const DwarfFde* fde = this->debug_frame_->GetFdeFromPc(0x1600);
@@ -247,7 +248,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetFdeFromPc32) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetFdeFromPc32_reverse) {
- SetFourFdes32(&this->memory_);
+ SetFourFdes32(this->fake_memory_);
ASSERT_TRUE(this->debug_frame_->Init(SectionInfo{.offset = 0x5000, .size = 0x600}));
const DwarfFde* fde = this->debug_frame_->GetFdeFromPc(0x4600);
@@ -271,7 +272,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetFdeFromPc32_reverse) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetFdeFromPc32_not_in_section) {
- SetFourFdes32(&this->memory_);
+ SetFourFdes32(this->fake_memory_);
ASSERT_TRUE(this->debug_frame_->Init(SectionInfo{.offset = 0x5000, .size = 0x500}));
const DwarfFde* fde = this->debug_frame_->GetFdeFromPc(0x4600);
@@ -295,7 +296,7 @@ static void SetFourFdes64(MemoryFake* memory) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetFdes64) {
- SetFourFdes64(&this->memory_);
+ SetFourFdes64(this->fake_memory_);
ASSERT_TRUE(this->debug_frame_->Init(SectionInfo{.offset = 0x5000, .size = 0x600}));
std::vector<const DwarfFde*> fdes;
@@ -337,7 +338,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetFdes64) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetFdes64_after_GetFdeFromPc) {
- SetFourFdes64(&this->memory_);
+ SetFourFdes64(this->fake_memory_);
ASSERT_TRUE(this->debug_frame_->Init(SectionInfo{.offset = 0x5000, .size = 0x600}));
const DwarfFde* fde = this->debug_frame_->GetFdeFromPc(0x2600);
@@ -361,7 +362,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetFdes64_after_GetFdeFromPc) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetFdes64_not_in_section) {
- SetFourFdes64(&this->memory_);
+ SetFourFdes64(this->fake_memory_);
ASSERT_TRUE(this->debug_frame_->Init(SectionInfo{.offset = 0x5000, .size = 0x500}));
std::vector<const DwarfFde*> fdes;
@@ -371,7 +372,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetFdes64_not_in_section) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetFdeFromPc64) {
- SetFourFdes64(&this->memory_);
+ SetFourFdes64(this->fake_memory_);
ASSERT_TRUE(this->debug_frame_->Init(SectionInfo{.offset = 0x5000, .size = 0x600}));
const DwarfFde* fde = this->debug_frame_->GetFdeFromPc(0x1600);
@@ -395,7 +396,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetFdeFromPc64) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetFdeFromPc64_reverse) {
- SetFourFdes64(&this->memory_);
+ SetFourFdes64(this->fake_memory_);
ASSERT_TRUE(this->debug_frame_->Init(SectionInfo{.offset = 0x5000, .size = 0x600}));
const DwarfFde* fde = this->debug_frame_->GetFdeFromPc(0x4600);
@@ -419,7 +420,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetFdeFromPc64_reverse) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetFdeFromPc64_not_in_section) {
- SetFourFdes64(&this->memory_);
+ SetFourFdes64(this->fake_memory_);
ASSERT_TRUE(this->debug_frame_->Init(SectionInfo{.offset = 0x5000, .size = 0x500}));
const DwarfFde* fde = this->debug_frame_->GetFdeFromPc(0x4600);
@@ -427,8 +428,8 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetFdeFromPc64_not_in_section) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetCieFde32) {
- SetCie32(&this->memory_, 0xf000, 0x100, std::vector<uint8_t>{1, '\0', 4, 8, 0x20});
- SetFde32(&this->memory_, 0x14000, 0x20, 0xf000, 0x9000, 0x100);
+ SetCie32(this->fake_memory_, 0xf000, 0x100, std::vector<uint8_t>{1, '\0', 4, 8, 0x20});
+ SetFde32(this->fake_memory_, 0x14000, 0x20, 0xf000, 0x9000, 0x100);
const DwarfFde* fde = this->debug_frame_->GetFdeFromOffset(0x14000);
ASSERT_TRUE(fde != nullptr);
@@ -455,8 +456,8 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetCieFde32) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetCieFde64) {
- SetCie64(&this->memory_, 0x6000, 0x100, std::vector<uint8_t>{1, '\0', 4, 8, 0x20});
- SetFde64(&this->memory_, 0x8000, 0x200, 0x6000, 0x5000, 0x300);
+ SetCie64(this->fake_memory_, 0x6000, 0x100, std::vector<uint8_t>{1, '\0', 4, 8, 0x20});
+ SetFde64(this->fake_memory_, 0x8000, 0x200, 0x6000, 0x5000, 0x300);
const DwarfFde* fde = this->debug_frame_->GetFdeFromOffset(0x8000);
ASSERT_TRUE(fde != nullptr);
@@ -500,14 +501,14 @@ static void VerifyCieVersion(const DwarfCie* cie, uint8_t version, uint8_t segme
}
TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset32_cie_cached) {
- SetCie32(&this->memory_, 0x5000, 0x100, std::vector<uint8_t>{1, '\0', 4, 8, 0x20});
+ SetCie32(this->fake_memory_, 0x5000, 0x100, std::vector<uint8_t>{1, '\0', 4, 8, 0x20});
const DwarfCie* cie = this->debug_frame_->GetCieFromOffset(0x5000);
EXPECT_EQ(DWARF_ERROR_NONE, this->debug_frame_->LastErrorCode());
ASSERT_TRUE(cie != nullptr);
VerifyCieVersion(cie, 1, 0, DW_EH_PE_udata4, 0x20, 0xd, 0x104);
std::vector<uint8_t> zero(0x100, 0);
- this->memory_.SetMemory(0x5000, zero);
+ this->fake_memory_->SetMemory(0x5000, zero);
cie = this->debug_frame_->GetCieFromOffset(0x5000);
EXPECT_EQ(DWARF_ERROR_NONE, this->debug_frame_->LastErrorCode());
ASSERT_TRUE(cie != nullptr);
@@ -515,14 +516,14 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset32_cie_cached) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset64_cie_cached) {
- SetCie64(&this->memory_, 0x5000, 0x100, std::vector<uint8_t>{1, '\0', 4, 8, 0x20});
+ SetCie64(this->fake_memory_, 0x5000, 0x100, std::vector<uint8_t>{1, '\0', 4, 8, 0x20});
const DwarfCie* cie = this->debug_frame_->GetCieFromOffset(0x5000);
EXPECT_EQ(DWARF_ERROR_NONE, this->debug_frame_->LastErrorCode());
ASSERT_TRUE(cie != nullptr);
VerifyCieVersion(cie, 1, 0, DW_EH_PE_udata8, 0x20, 0x19, 0x10c);
std::vector<uint8_t> zero(0x100, 0);
- this->memory_.SetMemory(0x5000, zero);
+ this->fake_memory_->SetMemory(0x5000, zero);
cie = this->debug_frame_->GetCieFromOffset(0x5000);
EXPECT_EQ(DWARF_ERROR_NONE, this->debug_frame_->LastErrorCode());
ASSERT_TRUE(cie != nullptr);
@@ -530,7 +531,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset64_cie_cached) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset32_version1) {
- SetCie32(&this->memory_, 0x5000, 0x100, std::vector<uint8_t>{1, '\0', 4, 8, 0x20});
+ SetCie32(this->fake_memory_, 0x5000, 0x100, std::vector<uint8_t>{1, '\0', 4, 8, 0x20});
const DwarfCie* cie = this->debug_frame_->GetCieFromOffset(0x5000);
EXPECT_EQ(DWARF_ERROR_NONE, this->debug_frame_->LastErrorCode());
ASSERT_TRUE(cie != nullptr);
@@ -538,7 +539,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset32_version1) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset64_version1) {
- SetCie64(&this->memory_, 0x5000, 0x100, std::vector<uint8_t>{1, '\0', 4, 8, 0x20});
+ SetCie64(this->fake_memory_, 0x5000, 0x100, std::vector<uint8_t>{1, '\0', 4, 8, 0x20});
const DwarfCie* cie = this->debug_frame_->GetCieFromOffset(0x5000);
EXPECT_EQ(DWARF_ERROR_NONE, this->debug_frame_->LastErrorCode());
ASSERT_TRUE(cie != nullptr);
@@ -546,7 +547,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset64_version1) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset32_version3) {
- SetCie32(&this->memory_, 0x5000, 0x100, std::vector<uint8_t>{3, '\0', 4, 8, 0x81, 3});
+ SetCie32(this->fake_memory_, 0x5000, 0x100, std::vector<uint8_t>{3, '\0', 4, 8, 0x81, 3});
const DwarfCie* cie = this->debug_frame_->GetCieFromOffset(0x5000);
EXPECT_EQ(DWARF_ERROR_NONE, this->debug_frame_->LastErrorCode());
ASSERT_TRUE(cie != nullptr);
@@ -554,7 +555,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset32_version3) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset64_version3) {
- SetCie64(&this->memory_, 0x5000, 0x100, std::vector<uint8_t>{3, '\0', 4, 8, 0x81, 3});
+ SetCie64(this->fake_memory_, 0x5000, 0x100, std::vector<uint8_t>{3, '\0', 4, 8, 0x81, 3});
const DwarfCie* cie = this->debug_frame_->GetCieFromOffset(0x5000);
EXPECT_EQ(DWARF_ERROR_NONE, this->debug_frame_->LastErrorCode());
ASSERT_TRUE(cie != nullptr);
@@ -562,7 +563,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset64_version3) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset32_version4_32bit_address) {
- SetCie32(&this->memory_, 0x5000, 0x100, std::vector<uint8_t>{4, '\0', 4, 10, 4, 8, 0x81, 3});
+ SetCie32(this->fake_memory_, 0x5000, 0x100, std::vector<uint8_t>{4, '\0', 4, 10, 4, 8, 0x81, 3});
const DwarfCie* cie = this->debug_frame_->GetCieFromOffset(0x5000);
EXPECT_EQ(DWARF_ERROR_NONE, this->debug_frame_->LastErrorCode());
ASSERT_TRUE(cie != nullptr);
@@ -570,7 +571,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset32_version4_32bit_address) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset32_version4_64bit_address) {
- SetCie32(&this->memory_, 0x5000, 0x100, std::vector<uint8_t>{4, '\0', 8, 10, 4, 8, 0x81, 3});
+ SetCie32(this->fake_memory_, 0x5000, 0x100, std::vector<uint8_t>{4, '\0', 8, 10, 4, 8, 0x81, 3});
const DwarfCie* cie = this->debug_frame_->GetCieFromOffset(0x5000);
EXPECT_EQ(DWARF_ERROR_NONE, this->debug_frame_->LastErrorCode());
ASSERT_TRUE(cie != nullptr);
@@ -578,7 +579,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset32_version4_64bit_address) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset64_version4_32bit_address) {
- SetCie64(&this->memory_, 0x5000, 0x100, std::vector<uint8_t>{4, '\0', 4, 10, 4, 8, 0x81, 3});
+ SetCie64(this->fake_memory_, 0x5000, 0x100, std::vector<uint8_t>{4, '\0', 4, 10, 4, 8, 0x81, 3});
const DwarfCie* cie = this->debug_frame_->GetCieFromOffset(0x5000);
EXPECT_EQ(DWARF_ERROR_NONE, this->debug_frame_->LastErrorCode());
ASSERT_TRUE(cie != nullptr);
@@ -586,7 +587,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset64_version4_32bit_address) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset64_version4_64bit_address) {
- SetCie64(&this->memory_, 0x5000, 0x100, std::vector<uint8_t>{4, '\0', 8, 10, 4, 8, 0x81, 3});
+ SetCie64(this->fake_memory_, 0x5000, 0x100, std::vector<uint8_t>{4, '\0', 8, 10, 4, 8, 0x81, 3});
const DwarfCie* cie = this->debug_frame_->GetCieFromOffset(0x5000);
EXPECT_EQ(DWARF_ERROR_NONE, this->debug_frame_->LastErrorCode());
ASSERT_TRUE(cie != nullptr);
@@ -594,7 +595,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset64_version4_64bit_address) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset32_version5) {
- SetCie32(&this->memory_, 0x5000, 0x100, std::vector<uint8_t>{5, '\0', 4, 10, 4, 8, 0x81, 3});
+ SetCie32(this->fake_memory_, 0x5000, 0x100, std::vector<uint8_t>{5, '\0', 4, 10, 4, 8, 0x81, 3});
const DwarfCie* cie = this->debug_frame_->GetCieFromOffset(0x5000);
EXPECT_EQ(DWARF_ERROR_NONE, this->debug_frame_->LastErrorCode());
ASSERT_TRUE(cie != nullptr);
@@ -602,7 +603,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset32_version5) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset64_version5) {
- SetCie64(&this->memory_, 0x5000, 0x100, std::vector<uint8_t>{5, '\0', 8, 10, 4, 8, 0x81, 3});
+ SetCie64(this->fake_memory_, 0x5000, 0x100, std::vector<uint8_t>{5, '\0', 8, 10, 4, 8, 0x81, 3});
const DwarfCie* cie = this->debug_frame_->GetCieFromOffset(0x5000);
EXPECT_EQ(DWARF_ERROR_NONE, this->debug_frame_->LastErrorCode());
ASSERT_TRUE(cie != nullptr);
@@ -610,17 +611,17 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset64_version5) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset_version_invalid) {
- SetCie32(&this->memory_, 0x5000, 0x100, std::vector<uint8_t>{0, '\0', 1, 2, 3, 4, 5, 6, 7});
+ SetCie32(this->fake_memory_, 0x5000, 0x100, std::vector<uint8_t>{0, '\0', 1, 2, 3, 4, 5, 6, 7});
ASSERT_TRUE(this->debug_frame_->GetCieFromOffset(0x5000) == nullptr);
EXPECT_EQ(DWARF_ERROR_UNSUPPORTED_VERSION, this->debug_frame_->LastErrorCode());
- SetCie64(&this->memory_, 0x6000, 0x100, std::vector<uint8_t>{0, '\0', 1, 2, 3, 4, 5, 6, 7});
+ SetCie64(this->fake_memory_, 0x6000, 0x100, std::vector<uint8_t>{0, '\0', 1, 2, 3, 4, 5, 6, 7});
ASSERT_TRUE(this->debug_frame_->GetCieFromOffset(0x6000) == nullptr);
EXPECT_EQ(DWARF_ERROR_UNSUPPORTED_VERSION, this->debug_frame_->LastErrorCode());
- SetCie32(&this->memory_, 0x7000, 0x100, std::vector<uint8_t>{6, '\0', 1, 2, 3, 4, 5, 6, 7});
+ SetCie32(this->fake_memory_, 0x7000, 0x100, std::vector<uint8_t>{6, '\0', 1, 2, 3, 4, 5, 6, 7});
ASSERT_TRUE(this->debug_frame_->GetCieFromOffset(0x7000) == nullptr);
EXPECT_EQ(DWARF_ERROR_UNSUPPORTED_VERSION, this->debug_frame_->LastErrorCode());
- SetCie64(&this->memory_, 0x8000, 0x100, std::vector<uint8_t>{6, '\0', 1, 2, 3, 4, 5, 6, 7});
+ SetCie64(this->fake_memory_, 0x8000, 0x100, std::vector<uint8_t>{6, '\0', 1, 2, 3, 4, 5, 6, 7});
ASSERT_TRUE(this->debug_frame_->GetCieFromOffset(0x8000) == nullptr);
EXPECT_EQ(DWARF_ERROR_UNSUPPORTED_VERSION, this->debug_frame_->LastErrorCode());
}
@@ -645,7 +646,7 @@ static void VerifyCieAugment(const DwarfCie* cie, uint64_t inst_offset, uint64_t
}
TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset32_augment) {
- SetCie32(&this->memory_, 0x5000, 0x100,
+ SetCie32(this->fake_memory_, 0x5000, 0x100,
std::vector<uint8_t>{/* version */ 1,
/* augment string */ 'z', 'L', 'P', 'R', '\0',
/* code alignment factor */ 4,
@@ -662,7 +663,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset32_augment) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset64_augment) {
- SetCie64(&this->memory_, 0x5000, 0x100,
+ SetCie64(this->fake_memory_, 0x5000, 0x100,
std::vector<uint8_t>{/* version */ 1,
/* augment string */ 'z', 'L', 'P', 'R', '\0',
/* code alignment factor */ 4,
@@ -679,7 +680,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetCieFromOffset64_augment) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetFdeFromOffset32_augment) {
- SetCie32(&this->memory_, 0x5000, 0xfc,
+ SetCie32(this->fake_memory_, 0x5000, 0xfc,
std::vector<uint8_t>{/* version */ 4,
/* augment string */ 'z', '\0',
/* address size */ 4,
@@ -690,7 +691,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetFdeFromOffset32_augment) {
/* augment length */ 0x0});
std::vector<uint8_t> data{/* augment length */ 0x80, 0x3};
- SetFde32(&this->memory_, 0x5200, 0x300, 0x5000, 0x4300, 0x300, 0x10, &data);
+ SetFde32(this->fake_memory_, 0x5200, 0x300, 0x5000, 0x4300, 0x300, 0x10, &data);
const DwarfFde* fde = this->debug_frame_->GetFdeFromOffset(0x5200);
ASSERT_TRUE(fde != nullptr);
@@ -705,7 +706,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetFdeFromOffset32_augment) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetFdeFromOffset64_augment) {
- SetCie64(&this->memory_, 0x5000, 0xfc,
+ SetCie64(this->fake_memory_, 0x5000, 0xfc,
std::vector<uint8_t>{/* version */ 4,
/* augment string */ 'z', '\0',
/* address size */ 8,
@@ -716,7 +717,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetFdeFromOffset64_augment) {
/* augment length */ 0x0});
std::vector<uint8_t> data{/* augment length */ 0x80, 0x3};
- SetFde64(&this->memory_, 0x5200, 0x300, 0x5000, 0x4300, 0x300, 0x10, &data);
+ SetFde64(this->fake_memory_, 0x5200, 0x300, 0x5000, 0x4300, 0x300, 0x10, &data);
const DwarfFde* fde = this->debug_frame_->GetFdeFromOffset(0x5200);
ASSERT_TRUE(fde != nullptr);
@@ -731,7 +732,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetFdeFromOffset64_augment) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetFdeFromOffset32_lsda_address) {
- SetCie32(&this->memory_, 0x5000, 0xfc,
+ SetCie32(this->fake_memory_, 0x5000, 0xfc,
std::vector<uint8_t>{/* version */ 1,
/* augment string */ 'z', 'L', '\0',
/* address size */ 8,
@@ -743,7 +744,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetFdeFromOffset32_lsda_address) {
std::vector<uint8_t> data{/* augment length */ 0x80, 0x3,
/* lsda address */ 0x20, 0x45};
- SetFde32(&this->memory_, 0x5200, 0x300, 0x5000, 0x4300, 0x300, 0, &data);
+ SetFde32(this->fake_memory_, 0x5200, 0x300, 0x5000, 0x4300, 0x300, 0, &data);
const DwarfFde* fde = this->debug_frame_->GetFdeFromOffset(0x5200);
ASSERT_TRUE(fde != nullptr);
@@ -758,7 +759,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetFdeFromOffset32_lsda_address) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetFdeFromOffset64_lsda_address) {
- SetCie64(&this->memory_, 0x5000, 0xfc,
+ SetCie64(this->fake_memory_, 0x5000, 0xfc,
std::vector<uint8_t>{/* version */ 1,
/* augment string */ 'z', 'L', '\0',
/* address size */ 8,
@@ -770,7 +771,7 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetFdeFromOffset64_lsda_address) {
std::vector<uint8_t> data{/* augment length */ 0x80, 0x3,
/* lsda address */ 0x20, 0x45};
- SetFde64(&this->memory_, 0x5200, 0x300, 0x5000, 0x4300, 0x300, 0, &data);
+ SetFde64(this->fake_memory_, 0x5200, 0x300, 0x5000, 0x4300, 0x300, 0, &data);
const DwarfFde* fde = this->debug_frame_->GetFdeFromOffset(0x5200);
ASSERT_TRUE(fde != nullptr);
@@ -785,22 +786,22 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetFdeFromOffset64_lsda_address) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetFdeFromPc_interleaved) {
- SetCie32(&this->memory_, 0x5000, 0xfc, std::vector<uint8_t>{1, '\0', 0, 0, 1});
+ SetCie32(this->fake_memory_, 0x5000, 0xfc, std::vector<uint8_t>{1, '\0', 0, 0, 1});
// FDE 0 (0x100 - 0x200)
- SetFde32(&this->memory_, 0x5100, 0xfc, 0, 0x100, 0x100);
+ SetFde32(this->fake_memory_, 0x5100, 0xfc, 0, 0x100, 0x100);
// FDE 1 (0x300 - 0x500)
- SetFde32(&this->memory_, 0x5200, 0xfc, 0, 0x300, 0x200);
+ SetFde32(this->fake_memory_, 0x5200, 0xfc, 0, 0x300, 0x200);
// FDE 2 (0x700 - 0x800)
- SetFde32(&this->memory_, 0x5300, 0xfc, 0, 0x700, 0x100);
+ SetFde32(this->fake_memory_, 0x5300, 0xfc, 0, 0x700, 0x100);
// FDE 3 (0xa00 - 0xb00)
- SetFde32(&this->memory_, 0x5400, 0xfc, 0, 0xa00, 0x100);
+ SetFde32(this->fake_memory_, 0x5400, 0xfc, 0, 0xa00, 0x100);
// FDE 4 (0x100 - 0xb00)
- SetFde32(&this->memory_, 0x5500, 0xfc, 0, 0x150, 0xa00);
+ SetFde32(this->fake_memory_, 0x5500, 0xfc, 0, 0x150, 0xa00);
// FDE 5 (0x50 - 0xa0)
- SetFde32(&this->memory_, 0x5600, 0xfc, 0, 0x50, 0x50);
+ SetFde32(this->fake_memory_, 0x5600, 0xfc, 0, 0x50, 0x50);
// FDE 6 (0x0 - 0x50)
- SetFde32(&this->memory_, 0x5700, 0xfc, 0, 0, 0x50);
+ SetFde32(this->fake_memory_, 0x5700, 0xfc, 0, 0, 0x50);
this->debug_frame_->Init(SectionInfo{.offset = 0x5000, .size = 0x800});
@@ -864,14 +865,14 @@ TYPED_TEST_P(DwarfDebugFrameTest, GetFdeFromPc_interleaved) {
}
TYPED_TEST_P(DwarfDebugFrameTest, GetFdeFromPc_overlap) {
- SetCie32(&this->memory_, 0x5000, 0xfc, std::vector<uint8_t>{1, '\0', 0, 0, 1});
+ SetCie32(this->fake_memory_, 0x5000, 0xfc, std::vector<uint8_t>{1, '\0', 0, 0, 1});
// FDE 0 (0x100 - 0x200)
- SetFde32(&this->memory_, 0x5100, 0xfc, 0, 0x100, 0x100);
+ SetFde32(this->fake_memory_, 0x5100, 0xfc, 0, 0x100, 0x100);
// FDE 1 (0x50 - 0x550)
- SetFde32(&this->memory_, 0x5200, 0xfc, 0, 0x50, 0x500);
+ SetFde32(this->fake_memory_, 0x5200, 0xfc, 0, 0x50, 0x500);
// FDE 2 (0x00 - 0x800)
- SetFde32(&this->memory_, 0x5300, 0xfc, 0, 0x0, 0x800);
+ SetFde32(this->fake_memory_, 0x5300, 0xfc, 0, 0x0, 0x800);
this->debug_frame_->Init(SectionInfo{.offset = 0x5000, .size = 0x400});
diff --git a/libunwindstack/tests/DwarfEhFrameTest.cpp b/libunwindstack/tests/DwarfEhFrameTest.cpp
index ea2e397..c050e3d 100644
--- a/libunwindstack/tests/DwarfEhFrameTest.cpp
+++ b/libunwindstack/tests/DwarfEhFrameTest.cpp
@@ -16,6 +16,8 @@
#include <stdint.h>
+#include <memory>
+
#include <gtest/gtest.h>
#include <unwindstack/DwarfError.h>
@@ -32,15 +34,14 @@ template <typename TypeParam>
class DwarfEhFrameTest : public ::testing::Test {
protected:
void SetUp() override {
- memory_.Clear();
- eh_frame_ = new DwarfEhFrame<TypeParam>(&memory_);
+ fake_memory_ = new MemoryFake;
+ std::shared_ptr<Memory> memory(fake_memory_);
+ eh_frame_.reset(new DwarfEhFrame<TypeParam>(memory));
ResetLogs();
}
- void TearDown() override { delete eh_frame_; }
-
- MemoryFake memory_;
- DwarfEhFrame<TypeParam>* eh_frame_ = nullptr;
+ MemoryFake* fake_memory_;
+ std::unique_ptr<DwarfEhFrame<TypeParam>> eh_frame_;
};
TYPED_TEST_SUITE_P(DwarfEhFrameTest);
@@ -51,16 +52,16 @@ TYPED_TEST_SUITE_P(DwarfEhFrameTest);
TYPED_TEST_P(DwarfEhFrameTest, GetFdeCieFromOffset32) {
// CIE 32 information.
- this->memory_.SetData32(0x5000, 0xfc);
+ this->fake_memory_->SetData32(0x5000, 0xfc);
// Indicates this is a cie for eh_frame.
- this->memory_.SetData32(0x5004, 0);
- this->memory_.SetMemory(0x5008, std::vector<uint8_t>{1, '\0', 16, 32, 1});
+ this->fake_memory_->SetData32(0x5004, 0);
+ this->fake_memory_->SetMemory(0x5008, std::vector<uint8_t>{1, '\0', 16, 32, 1});
// FDE 32 information.
- this->memory_.SetData32(0x5100, 0xfc);
- this->memory_.SetData32(0x5104, 0x104);
- this->memory_.SetData32(0x5108, 0x1500);
- this->memory_.SetData32(0x510c, 0x200);
+ this->fake_memory_->SetData32(0x5100, 0xfc);
+ this->fake_memory_->SetData32(0x5104, 0x104);
+ this->fake_memory_->SetData32(0x5108, 0x1500);
+ this->fake_memory_->SetData32(0x510c, 0x200);
const DwarfFde* fde = this->eh_frame_->GetFdeFromOffset(0x5100);
ASSERT_TRUE(fde != nullptr);
@@ -88,18 +89,18 @@ TYPED_TEST_P(DwarfEhFrameTest, GetFdeCieFromOffset32) {
TYPED_TEST_P(DwarfEhFrameTest, GetFdeCieFromOffset64) {
// CIE 64 information.
- this->memory_.SetData32(0x5000, 0xffffffff);
- this->memory_.SetData64(0x5004, 0xfc);
+ this->fake_memory_->SetData32(0x5000, 0xffffffff);
+ this->fake_memory_->SetData64(0x5004, 0xfc);
// Indicates this is a cie for eh_frame.
- this->memory_.SetData64(0x500c, 0);
- this->memory_.SetMemory(0x5014, std::vector<uint8_t>{1, '\0', 16, 32, 1});
+ this->fake_memory_->SetData64(0x500c, 0);
+ this->fake_memory_->SetMemory(0x5014, std::vector<uint8_t>{1, '\0', 16, 32, 1});
// FDE 64 information.
- this->memory_.SetData32(0x5100, 0xffffffff);
- this->memory_.SetData64(0x5104, 0xfc);
- this->memory_.SetData64(0x510c, 0x10c);
- this->memory_.SetData64(0x5114, 0x1500);
- this->memory_.SetData64(0x511c, 0x200);
+ this->fake_memory_->SetData32(0x5100, 0xffffffff);
+ this->fake_memory_->SetData64(0x5104, 0xfc);
+ this->fake_memory_->SetData64(0x510c, 0x10c);
+ this->fake_memory_->SetData64(0x5114, 0x1500);
+ this->fake_memory_->SetData64(0x511c, 0x200);
const DwarfFde* fde = this->eh_frame_->GetFdeFromOffset(0x5100);
ASSERT_TRUE(fde != nullptr);
diff --git a/libunwindstack/tests/DwarfEhFrameWithHdrTest.cpp b/libunwindstack/tests/DwarfEhFrameWithHdrTest.cpp
index 649b9f4..7eb11da 100644
--- a/libunwindstack/tests/DwarfEhFrameWithHdrTest.cpp
+++ b/libunwindstack/tests/DwarfEhFrameWithHdrTest.cpp
@@ -16,6 +16,9 @@
#include <stdint.h>
+#include <memory>
+#include <vector>
+
#include <gmock/gmock.h>
#include <gtest/gtest.h>
@@ -34,7 +37,8 @@ namespace unwindstack {
template <typename TypeParam>
class TestDwarfEhFrameWithHdr : public DwarfEhFrameWithHdr<TypeParam> {
public:
- TestDwarfEhFrameWithHdr(Memory* memory) : DwarfEhFrameWithHdr<TypeParam>(memory) {}
+ TestDwarfEhFrameWithHdr(std::shared_ptr<Memory>& memory)
+ : DwarfEhFrameWithHdr<TypeParam>(memory) {}
~TestDwarfEhFrameWithHdr() = default;
void TestSetTableEncoding(uint8_t encoding) { this->table_encoding_ = encoding; }
@@ -59,25 +63,24 @@ template <typename TypeParam>
class DwarfEhFrameWithHdrTest : public ::testing::Test {
protected:
void SetUp() override {
- memory_.Clear();
- eh_frame_ = new TestDwarfEhFrameWithHdr<TypeParam>(&memory_);
+ fake_memory_ = new MemoryFake;
+ std::shared_ptr<Memory> memory(fake_memory_);
+ eh_frame_.reset(new TestDwarfEhFrameWithHdr<TypeParam>(memory));
ResetLogs();
}
- void TearDown() override { delete eh_frame_; }
-
- MemoryFake memory_;
- TestDwarfEhFrameWithHdr<TypeParam>* eh_frame_ = nullptr;
+ MemoryFake* fake_memory_;
+ std::unique_ptr<TestDwarfEhFrameWithHdr<TypeParam>> eh_frame_;
};
TYPED_TEST_SUITE_P(DwarfEhFrameWithHdrTest);
// NOTE: All test class variables need to be referenced as this->.
TYPED_TEST_P(DwarfEhFrameWithHdrTest, Init) {
- this->memory_.SetMemory(
+ this->fake_memory_->SetMemory(
0x1000, std::vector<uint8_t>{0x1, DW_EH_PE_udata2, DW_EH_PE_udata4, DW_EH_PE_sdata4});
- this->memory_.SetData16(0x1004, 0x500);
- this->memory_.SetData32(0x1006, 126);
+ this->fake_memory_->SetData16(0x1004, 0x500);
+ this->fake_memory_->SetData32(0x1006, 126);
ASSERT_TRUE(this->eh_frame_->Init(SectionInfo{.offset = 0x1000, .size = 0x100}));
EXPECT_EQ(1U, this->eh_frame_->TestGetVersion());
@@ -88,46 +91,46 @@ TYPED_TEST_P(DwarfEhFrameWithHdrTest, Init) {
EXPECT_EQ(0x1000U, this->eh_frame_->TestGetHdrEntriesDataOffset());
// Verify a zero table entry size fails to init.
- this->memory_.SetData8(0x1003, 0x1);
+ this->fake_memory_->SetData8(0x1003, 0x1);
ASSERT_FALSE(this->eh_frame_->Init(SectionInfo{.offset = 0x1000, .size = 0x100}));
ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->eh_frame_->LastErrorCode());
// Reset the value back to the original.
- this->memory_.SetData8(0x1003, DW_EH_PE_sdata4);
+ this->fake_memory_->SetData8(0x1003, DW_EH_PE_sdata4);
// Verify a zero fde count fails to init.
- this->memory_.SetData32(0x1006, 0);
+ this->fake_memory_->SetData32(0x1006, 0);
ASSERT_FALSE(this->eh_frame_->Init(SectionInfo{.offset = 0x1000, .size = 0x100}));
ASSERT_EQ(DWARF_ERROR_NO_FDES, this->eh_frame_->LastErrorCode());
// Verify an unexpected version will cause a fail.
- this->memory_.SetData32(0x1006, 126);
- this->memory_.SetData8(0x1000, 0);
+ this->fake_memory_->SetData32(0x1006, 126);
+ this->fake_memory_->SetData8(0x1000, 0);
ASSERT_FALSE(this->eh_frame_->Init(SectionInfo{.offset = 0x1000, .size = 0x100}));
ASSERT_EQ(DWARF_ERROR_UNSUPPORTED_VERSION, this->eh_frame_->LastErrorCode());
- this->memory_.SetData8(0x1000, 2);
+ this->fake_memory_->SetData8(0x1000, 2);
ASSERT_FALSE(this->eh_frame_->Init(SectionInfo{.offset = 0x1000, .size = 0x100}));
ASSERT_EQ(DWARF_ERROR_UNSUPPORTED_VERSION, this->eh_frame_->LastErrorCode());
}
TYPED_TEST_P(DwarfEhFrameWithHdrTest, Init_non_zero_load_bias) {
- this->memory_.SetMemory(0x1000, std::vector<uint8_t>{0x1, DW_EH_PE_udata2, DW_EH_PE_udata4,
- DW_EH_PE_pcrel | DW_EH_PE_sdata4});
- this->memory_.SetData16(0x1004, 0x500);
- this->memory_.SetData32(0x1006, 1);
- this->memory_.SetData32(0x100a, 0x2500);
- this->memory_.SetData32(0x100e, 0x1400);
+ this->fake_memory_->SetMemory(0x1000, std::vector<uint8_t>{0x1, DW_EH_PE_udata2, DW_EH_PE_udata4,
+ DW_EH_PE_pcrel | DW_EH_PE_sdata4});
+ this->fake_memory_->SetData16(0x1004, 0x500);
+ this->fake_memory_->SetData32(0x1006, 1);
+ this->fake_memory_->SetData32(0x100a, 0x2500);
+ this->fake_memory_->SetData32(0x100e, 0x1400);
// CIE 32 information.
- this->memory_.SetData32(0x1300, 0xfc);
- this->memory_.SetData32(0x1304, 0);
- this->memory_.SetMemory(0x1308, std::vector<uint8_t>{1, 'z', 'R', '\0', 0, 0, 0, 0, 0x1b});
+ this->fake_memory_->SetData32(0x1300, 0xfc);
+ this->fake_memory_->SetData32(0x1304, 0);
+ this->fake_memory_->SetMemory(0x1308, std::vector<uint8_t>{1, 'z', 'R', '\0', 0, 0, 0, 0, 0x1b});
// FDE 32 information.
- this->memory_.SetData32(0x1400, 0xfc);
- this->memory_.SetData32(0x1404, 0x104);
- this->memory_.SetData32(0x1408, 0x10f8);
- this->memory_.SetData32(0x140c, 0x200);
- this->memory_.SetData16(0x1410, 0);
+ this->fake_memory_->SetData32(0x1400, 0xfc);
+ this->fake_memory_->SetData32(0x1404, 0x104);
+ this->fake_memory_->SetData32(0x1408, 0x10f8);
+ this->fake_memory_->SetData32(0x140c, 0x200);
+ this->fake_memory_->SetData16(0x1410, 0);
ASSERT_TRUE(
this->eh_frame_->EhFrameInit(SectionInfo{.offset = 0x1300, .size = 0x200, .bias = 0x2000}));
@@ -146,24 +149,24 @@ TYPED_TEST_P(DwarfEhFrameWithHdrTest, Init_non_zero_load_bias) {
}
TYPED_TEST_P(DwarfEhFrameWithHdrTest, Init_non_zero_load_bias_different_from_eh_frame_bias) {
- this->memory_.SetMemory(0x1000, std::vector<uint8_t>{0x1, DW_EH_PE_udata2, DW_EH_PE_udata4,
- DW_EH_PE_pcrel | DW_EH_PE_sdata4});
- this->memory_.SetData16(0x1004, 0x500);
- this->memory_.SetData32(0x1006, 1);
- this->memory_.SetData32(0x100a, 0x2500);
- this->memory_.SetData32(0x100e, 0x1400);
+ this->fake_memory_->SetMemory(0x1000, std::vector<uint8_t>{0x1, DW_EH_PE_udata2, DW_EH_PE_udata4,
+ DW_EH_PE_pcrel | DW_EH_PE_sdata4});
+ this->fake_memory_->SetData16(0x1004, 0x500);
+ this->fake_memory_->SetData32(0x1006, 1);
+ this->fake_memory_->SetData32(0x100a, 0x2500);
+ this->fake_memory_->SetData32(0x100e, 0x1400);
// CIE 32 information.
- this->memory_.SetData32(0x1300, 0xfc);
- this->memory_.SetData32(0x1304, 0);
- this->memory_.SetMemory(0x1308, std::vector<uint8_t>{1, 'z', 'R', '\0', 0, 0, 0, 0, 0x1b});
+ this->fake_memory_->SetData32(0x1300, 0xfc);
+ this->fake_memory_->SetData32(0x1304, 0);
+ this->fake_memory_->SetMemory(0x1308, std::vector<uint8_t>{1, 'z', 'R', '\0', 0, 0, 0, 0, 0x1b});
// FDE 32 information.
- this->memory_.SetData32(0x1400, 0xfc);
- this->memory_.SetData32(0x1404, 0x104);
- this->memory_.SetData32(0x1408, 0x20f8);
- this->memory_.SetData32(0x140c, 0x200);
- this->memory_.SetData16(0x1410, 0);
+ this->fake_memory_->SetData32(0x1400, 0xfc);
+ this->fake_memory_->SetData32(0x1404, 0x104);
+ this->fake_memory_->SetData32(0x1408, 0x20f8);
+ this->fake_memory_->SetData32(0x140c, 0x200);
+ this->fake_memory_->SetData16(0x1410, 0);
ASSERT_TRUE(
this->eh_frame_->EhFrameInit(SectionInfo{.offset = 0x1300, .size = 0x200, .bias = 0x1000}));
@@ -182,72 +185,72 @@ TYPED_TEST_P(DwarfEhFrameWithHdrTest, Init_non_zero_load_bias_different_from_eh_
}
TYPED_TEST_P(DwarfEhFrameWithHdrTest, Init_compressed) {
- this->memory_.SetMemory(
+ this->fake_memory_->SetMemory(
0x1000, std::vector<uint8_t>{0x1, DW_EH_PE_udata2, DW_EH_PE_udata4, DW_EH_PE_sdata4});
- this->memory_.SetData16(0x1004, 0x500);
- this->memory_.SetData32(0x1006, 126);
+ this->fake_memory_->SetData16(0x1004, 0x500);
+ this->fake_memory_->SetData32(0x1006, 126);
ASSERT_FALSE(
this->eh_frame_->Init(SectionInfo{.offset = 0x1000, .size = 0x100, .flags = SHF_COMPRESSED}));
}
TYPED_TEST_P(DwarfEhFrameWithHdrTest, EhFrameInit_compressed) {
- this->memory_.SetMemory(0x1000, std::vector<uint8_t>{0x1, DW_EH_PE_udata2, DW_EH_PE_udata4,
- DW_EH_PE_pcrel | DW_EH_PE_sdata4});
- this->memory_.SetData16(0x1004, 0x500);
- this->memory_.SetData32(0x1006, 1);
- this->memory_.SetData32(0x100a, 0x2500);
- this->memory_.SetData32(0x100e, 0x1400);
+ this->fake_memory_->SetMemory(0x1000, std::vector<uint8_t>{0x1, DW_EH_PE_udata2, DW_EH_PE_udata4,
+ DW_EH_PE_pcrel | DW_EH_PE_sdata4});
+ this->fake_memory_->SetData16(0x1004, 0x500);
+ this->fake_memory_->SetData32(0x1006, 1);
+ this->fake_memory_->SetData32(0x100a, 0x2500);
+ this->fake_memory_->SetData32(0x100e, 0x1400);
// CIE 32 information.
- this->memory_.SetData32(0x1300, 0xfc);
- this->memory_.SetData32(0x1304, 0);
- this->memory_.SetMemory(0x1308, std::vector<uint8_t>{1, 'z', 'R', '\0', 0, 0, 0, 0, 0x1b});
+ this->fake_memory_->SetData32(0x1300, 0xfc);
+ this->fake_memory_->SetData32(0x1304, 0);
+ this->fake_memory_->SetMemory(0x1308, std::vector<uint8_t>{1, 'z', 'R', '\0', 0, 0, 0, 0, 0x1b});
// FDE 32 information.
- this->memory_.SetData32(0x1400, 0xfc);
- this->memory_.SetData32(0x1404, 0x104);
- this->memory_.SetData32(0x1408, 0x30f8);
- this->memory_.SetData32(0x140c, 0);
- this->memory_.SetData16(0x1410, 0);
+ this->fake_memory_->SetData32(0x1400, 0xfc);
+ this->fake_memory_->SetData32(0x1404, 0x104);
+ this->fake_memory_->SetData32(0x1408, 0x30f8);
+ this->fake_memory_->SetData32(0x140c, 0);
+ this->fake_memory_->SetData16(0x1410, 0);
// FDE 32 information.
- this->memory_.SetData32(0x1500, 0xfc);
- this->memory_.SetData32(0x1504, 0x204);
- this->memory_.SetData32(0x1508, 0x2ff8);
- this->memory_.SetData32(0x150c, 0x200);
- this->memory_.SetData16(0x1510, 0);
+ this->fake_memory_->SetData32(0x1500, 0xfc);
+ this->fake_memory_->SetData32(0x1504, 0x204);
+ this->fake_memory_->SetData32(0x1508, 0x2ff8);
+ this->fake_memory_->SetData32(0x150c, 0x200);
+ this->fake_memory_->SetData16(0x1510, 0);
ASSERT_FALSE(this->eh_frame_->EhFrameInit(
SectionInfo{.offset = 0x1300, .size = 0x300, .flags = SHF_COMPRESSED}));
}
TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeFromPc_wtih_empty_fde) {
- this->memory_.SetMemory(0x1000, std::vector<uint8_t>{0x1, DW_EH_PE_udata2, DW_EH_PE_udata4,
- DW_EH_PE_pcrel | DW_EH_PE_sdata4});
- this->memory_.SetData16(0x1004, 0x500);
- this->memory_.SetData32(0x1006, 1);
- this->memory_.SetData32(0x100a, 0x2500);
- this->memory_.SetData32(0x100e, 0x1400);
+ this->fake_memory_->SetMemory(0x1000, std::vector<uint8_t>{0x1, DW_EH_PE_udata2, DW_EH_PE_udata4,
+ DW_EH_PE_pcrel | DW_EH_PE_sdata4});
+ this->fake_memory_->SetData16(0x1004, 0x500);
+ this->fake_memory_->SetData32(0x1006, 1);
+ this->fake_memory_->SetData32(0x100a, 0x2500);
+ this->fake_memory_->SetData32(0x100e, 0x1400);
// CIE 32 information.
- this->memory_.SetData32(0x1300, 0xfc);
- this->memory_.SetData32(0x1304, 0);
- this->memory_.SetMemory(0x1308, std::vector<uint8_t>{1, 'z', 'R', '\0', 0, 0, 0, 0, 0x1b});
+ this->fake_memory_->SetData32(0x1300, 0xfc);
+ this->fake_memory_->SetData32(0x1304, 0);
+ this->fake_memory_->SetMemory(0x1308, std::vector<uint8_t>{1, 'z', 'R', '\0', 0, 0, 0, 0, 0x1b});
// FDE 32 information.
- this->memory_.SetData32(0x1400, 0xfc);
- this->memory_.SetData32(0x1404, 0x104);
- this->memory_.SetData32(0x1408, 0x30f8);
- this->memory_.SetData32(0x140c, 0);
- this->memory_.SetData16(0x1410, 0);
+ this->fake_memory_->SetData32(0x1400, 0xfc);
+ this->fake_memory_->SetData32(0x1404, 0x104);
+ this->fake_memory_->SetData32(0x1408, 0x30f8);
+ this->fake_memory_->SetData32(0x140c, 0);
+ this->fake_memory_->SetData16(0x1410, 0);
// FDE 32 information.
- this->memory_.SetData32(0x1500, 0xfc);
- this->memory_.SetData32(0x1504, 0x204);
- this->memory_.SetData32(0x1508, 0x2ff8);
- this->memory_.SetData32(0x150c, 0x200);
- this->memory_.SetData16(0x1510, 0);
+ this->fake_memory_->SetData32(0x1500, 0xfc);
+ this->fake_memory_->SetData32(0x1504, 0x204);
+ this->fake_memory_->SetData32(0x1508, 0x2ff8);
+ this->fake_memory_->SetData32(0x150c, 0x200);
+ this->fake_memory_->SetData16(0x1510, 0);
ASSERT_TRUE(this->eh_frame_->EhFrameInit(SectionInfo{.offset = 0x1300, .size = 0x300}));
ASSERT_TRUE(this->eh_frame_->Init(SectionInfo{.offset = 0x1000, .size = 0x100}));
@@ -259,31 +262,31 @@ TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeFromPc_wtih_empty_fde) {
}
TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdes_with_empty_fde) {
- this->memory_.SetMemory(0x1000, std::vector<uint8_t>{0x1, DW_EH_PE_udata2, DW_EH_PE_udata4,
- DW_EH_PE_pcrel | DW_EH_PE_sdata4});
- this->memory_.SetData16(0x1004, 0x500);
- this->memory_.SetData32(0x1006, 1);
- this->memory_.SetData32(0x100a, 0x2500);
- this->memory_.SetData32(0x100e, 0x1400);
+ this->fake_memory_->SetMemory(0x1000, std::vector<uint8_t>{0x1, DW_EH_PE_udata2, DW_EH_PE_udata4,
+ DW_EH_PE_pcrel | DW_EH_PE_sdata4});
+ this->fake_memory_->SetData16(0x1004, 0x500);
+ this->fake_memory_->SetData32(0x1006, 1);
+ this->fake_memory_->SetData32(0x100a, 0x2500);
+ this->fake_memory_->SetData32(0x100e, 0x1400);
// CIE 32 information.
- this->memory_.SetData32(0x1300, 0xfc);
- this->memory_.SetData32(0x1304, 0);
- this->memory_.SetMemory(0x1308, std::vector<uint8_t>{1, 'z', 'R', '\0', 0, 0, 0, 0, 0x1b});
+ this->fake_memory_->SetData32(0x1300, 0xfc);
+ this->fake_memory_->SetData32(0x1304, 0);
+ this->fake_memory_->SetMemory(0x1308, std::vector<uint8_t>{1, 'z', 'R', '\0', 0, 0, 0, 0, 0x1b});
// FDE 32 information.
- this->memory_.SetData32(0x1400, 0xfc);
- this->memory_.SetData32(0x1404, 0x104);
- this->memory_.SetData32(0x1408, 0x30f8);
- this->memory_.SetData32(0x140c, 0);
- this->memory_.SetData16(0x1410, 0);
+ this->fake_memory_->SetData32(0x1400, 0xfc);
+ this->fake_memory_->SetData32(0x1404, 0x104);
+ this->fake_memory_->SetData32(0x1408, 0x30f8);
+ this->fake_memory_->SetData32(0x140c, 0);
+ this->fake_memory_->SetData16(0x1410, 0);
// FDE 32 information.
- this->memory_.SetData32(0x1500, 0xfc);
- this->memory_.SetData32(0x1504, 0x204);
- this->memory_.SetData32(0x1508, 0x2ff8);
- this->memory_.SetData32(0x150c, 0x200);
- this->memory_.SetData16(0x1510, 0);
+ this->fake_memory_->SetData32(0x1500, 0xfc);
+ this->fake_memory_->SetData32(0x1504, 0x204);
+ this->fake_memory_->SetData32(0x1508, 0x2ff8);
+ this->fake_memory_->SetData32(0x150c, 0x200);
+ this->fake_memory_->SetData16(0x1510, 0);
ASSERT_TRUE(this->eh_frame_->EhFrameInit(SectionInfo{.offset = 0x1300, .size = 0x300}));
ASSERT_TRUE(this->eh_frame_->Init(SectionInfo{.offset = 0x1000, .size = 0x100}));
@@ -297,50 +300,50 @@ TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdes_with_empty_fde) {
}
TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdes) {
- this->memory_.SetMemory(
+ this->fake_memory_->SetMemory(
0x1000, std::vector<uint8_t>{1, DW_EH_PE_udata2, DW_EH_PE_udata4, DW_EH_PE_sdata4});
- this->memory_.SetData16(0x1004, 0x500);
- this->memory_.SetData32(0x1006, 4);
+ this->fake_memory_->SetData16(0x1004, 0x500);
+ this->fake_memory_->SetData32(0x1006, 4);
// Header information.
- this->memory_.SetData32(0x100a, 0x4600);
- this->memory_.SetData32(0x100e, 0x1500);
- this->memory_.SetData32(0x1012, 0x5500);
- this->memory_.SetData32(0x1016, 0x1400);
- this->memory_.SetData32(0x101a, 0x6800);
- this->memory_.SetData32(0x101e, 0x1700);
- this->memory_.SetData32(0x1022, 0x7700);
- this->memory_.SetData32(0x1026, 0x1600);
+ this->fake_memory_->SetData32(0x100a, 0x4600);
+ this->fake_memory_->SetData32(0x100e, 0x1500);
+ this->fake_memory_->SetData32(0x1012, 0x5500);
+ this->fake_memory_->SetData32(0x1016, 0x1400);
+ this->fake_memory_->SetData32(0x101a, 0x6800);
+ this->fake_memory_->SetData32(0x101e, 0x1700);
+ this->fake_memory_->SetData32(0x1022, 0x7700);
+ this->fake_memory_->SetData32(0x1026, 0x1600);
// CIE 32 information.
- this->memory_.SetData32(0x1300, 0xfc);
- this->memory_.SetData32(0x1304, 0);
- this->memory_.SetMemory(0x1308, std::vector<uint8_t>{1, '\0', 0, 0, 0});
+ this->fake_memory_->SetData32(0x1300, 0xfc);
+ this->fake_memory_->SetData32(0x1304, 0);
+ this->fake_memory_->SetMemory(0x1308, std::vector<uint8_t>{1, '\0', 0, 0, 0});
// FDE 32 information.
// pc 0x5500 - 0x5700
- this->memory_.SetData32(0x1400, 0xfc);
- this->memory_.SetData32(0x1404, 0x104);
- this->memory_.SetData32(0x1408, 0x40f8);
- this->memory_.SetData32(0x140c, 0x200);
+ this->fake_memory_->SetData32(0x1400, 0xfc);
+ this->fake_memory_->SetData32(0x1404, 0x104);
+ this->fake_memory_->SetData32(0x1408, 0x40f8);
+ this->fake_memory_->SetData32(0x140c, 0x200);
// pc 0x4600 - 0x4800
- this->memory_.SetData32(0x1500, 0xfc);
- this->memory_.SetData32(0x1504, 0x204);
- this->memory_.SetData32(0x1508, 0x30f8);
- this->memory_.SetData32(0x150c, 0x200);
+ this->fake_memory_->SetData32(0x1500, 0xfc);
+ this->fake_memory_->SetData32(0x1504, 0x204);
+ this->fake_memory_->SetData32(0x1508, 0x30f8);
+ this->fake_memory_->SetData32(0x150c, 0x200);
// pc 0x7700 - 0x7900
- this->memory_.SetData32(0x1600, 0xfc);
- this->memory_.SetData32(0x1604, 0x304);
- this->memory_.SetData32(0x1608, 0x60f8);
- this->memory_.SetData32(0x160c, 0x200);
+ this->fake_memory_->SetData32(0x1600, 0xfc);
+ this->fake_memory_->SetData32(0x1604, 0x304);
+ this->fake_memory_->SetData32(0x1608, 0x60f8);
+ this->fake_memory_->SetData32(0x160c, 0x200);
// pc 0x6800 - 0x6a00
- this->memory_.SetData32(0x1700, 0xfc);
- this->memory_.SetData32(0x1704, 0x404);
- this->memory_.SetData32(0x1708, 0x50f8);
- this->memory_.SetData32(0x170c, 0x200);
+ this->fake_memory_->SetData32(0x1700, 0xfc);
+ this->fake_memory_->SetData32(0x1704, 0x404);
+ this->fake_memory_->SetData32(0x1708, 0x50f8);
+ this->fake_memory_->SetData32(0x170c, 0x200);
ASSERT_TRUE(this->eh_frame_->Init(SectionInfo{.offset = 0x1000, .size = 0x100}));
@@ -378,8 +381,8 @@ TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeInfoFromIndex_read_pcrel) {
this->eh_frame_->TestSetHdrEntriesDataOffset(0x3000);
this->eh_frame_->TestSetTableEntrySize(0x10);
- this->memory_.SetData32(0x1040, 0x340);
- this->memory_.SetData32(0x1044, 0x500);
+ this->fake_memory_->SetData32(0x1040, 0x340);
+ this->fake_memory_->SetData32(0x1044, 0x500);
auto info = this->eh_frame_->GetFdeInfoFromIndex(2);
ASSERT_TRUE(info != nullptr);
@@ -393,8 +396,8 @@ TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeInfoFromIndex_read_datarel) {
this->eh_frame_->TestSetHdrEntriesDataOffset(0x3000);
this->eh_frame_->TestSetTableEntrySize(0x10);
- this->memory_.SetData32(0x1040, 0x340);
- this->memory_.SetData32(0x1044, 0x500);
+ this->fake_memory_->SetData32(0x1040, 0x340);
+ this->fake_memory_->SetData32(0x1044, 0x500);
auto info = this->eh_frame_->GetFdeInfoFromIndex(2);
ASSERT_TRUE(info != nullptr);
@@ -407,8 +410,8 @@ TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeInfoFromIndex_cached) {
this->eh_frame_->TestSetHdrEntriesOffset(0x1000);
this->eh_frame_->TestSetTableEntrySize(0x10);
- this->memory_.SetData32(0x1040, 0x340);
- this->memory_.SetData32(0x1044, 0x500);
+ this->fake_memory_->SetData32(0x1040, 0x340);
+ this->fake_memory_->SetData32(0x1044, 0x500);
auto info = this->eh_frame_->GetFdeInfoFromIndex(2);
ASSERT_TRUE(info != nullptr);
@@ -416,7 +419,7 @@ TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeInfoFromIndex_cached) {
EXPECT_EQ(0x500U, info->offset);
// Clear the memory so that this will fail if it doesn't read cached data.
- this->memory_.Clear();
+ this->fake_memory_->Clear();
info = this->eh_frame_->GetFdeInfoFromIndex(2);
ASSERT_TRUE(info != nullptr);
@@ -503,15 +506,15 @@ TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeOffsetFromPc_search) {
TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetCieFde32) {
// CIE 32 information.
- this->memory_.SetData32(0xf000, 0x100);
- this->memory_.SetData32(0xf004, 0);
- this->memory_.SetMemory(0xf008, std::vector<uint8_t>{1, '\0', 4, 8, 0x20});
+ this->fake_memory_->SetData32(0xf000, 0x100);
+ this->fake_memory_->SetData32(0xf004, 0);
+ this->fake_memory_->SetMemory(0xf008, std::vector<uint8_t>{1, '\0', 4, 8, 0x20});
// FDE 32 information.
- this->memory_.SetData32(0x14000, 0x20);
- this->memory_.SetData32(0x14004, 0x5004);
- this->memory_.SetData32(0x14008, 0x9000);
- this->memory_.SetData32(0x1400c, 0x100);
+ this->fake_memory_->SetData32(0x14000, 0x20);
+ this->fake_memory_->SetData32(0x14004, 0x5004);
+ this->fake_memory_->SetData32(0x14008, 0x9000);
+ this->fake_memory_->SetData32(0x1400c, 0x100);
const DwarfFde* fde = this->eh_frame_->GetFdeFromOffset(0x14000);
ASSERT_TRUE(fde != nullptr);
@@ -539,17 +542,17 @@ TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetCieFde32) {
TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetCieFde64) {
// CIE 64 information.
- this->memory_.SetData32(0x6000, 0xffffffff);
- this->memory_.SetData64(0x6004, 0x100);
- this->memory_.SetData64(0x600c, 0);
- this->memory_.SetMemory(0x6014, std::vector<uint8_t>{1, '\0', 4, 8, 0x20});
+ this->fake_memory_->SetData32(0x6000, 0xffffffff);
+ this->fake_memory_->SetData64(0x6004, 0x100);
+ this->fake_memory_->SetData64(0x600c, 0);
+ this->fake_memory_->SetMemory(0x6014, std::vector<uint8_t>{1, '\0', 4, 8, 0x20});
// FDE 64 information.
- this->memory_.SetData32(0x8000, 0xffffffff);
- this->memory_.SetData64(0x8004, 0x200);
- this->memory_.SetData64(0x800c, 0x200c);
- this->memory_.SetData64(0x8014, 0x5000);
- this->memory_.SetData64(0x801c, 0x300);
+ this->fake_memory_->SetData32(0x8000, 0xffffffff);
+ this->fake_memory_->SetData64(0x8004, 0x200);
+ this->fake_memory_->SetData64(0x800c, 0x200c);
+ this->fake_memory_->SetData64(0x8014, 0x5000);
+ this->fake_memory_->SetData64(0x801c, 0x300);
const DwarfFde* fde = this->eh_frame_->GetFdeFromOffset(0x8000);
ASSERT_TRUE(fde != nullptr);
diff --git a/libunwindstack/tests/DwarfMemoryTest.cpp b/libunwindstack/tests/DwarfMemoryTest.cpp
index b3d04c4..0f78a7b 100644
--- a/libunwindstack/tests/DwarfMemoryTest.cpp
+++ b/libunwindstack/tests/DwarfMemoryTest.cpp
@@ -17,6 +17,7 @@
#include <stdint.h>
#include <ios>
+#include <memory>
#include <vector>
#include <gtest/gtest.h>
@@ -30,8 +31,9 @@ namespace unwindstack {
class DwarfMemoryTest : public ::testing::Test {
protected:
void SetUp() override {
- memory_.Clear();
- dwarf_mem_.reset(new DwarfMemory(&memory_));
+ fake_memory_ = new MemoryFake;
+ std::shared_ptr<Memory> memory(fake_memory_);
+ dwarf_mem_.reset(new DwarfMemory(memory));
}
template <typename AddressType>
@@ -57,12 +59,12 @@ class DwarfMemoryTest : public ::testing::Test {
template <typename AddressType>
void ReadEncodedValue_all();
- MemoryFake memory_;
+ MemoryFake* fake_memory_;
std::unique_ptr<DwarfMemory> dwarf_mem_;
};
TEST_F(DwarfMemoryTest, ReadBytes) {
- memory_.SetMemory(0, std::vector<uint8_t>{0x10, 0x18, 0xff, 0xfe});
+ fake_memory_->SetMemory(0, std::vector<uint8_t>{0x10, 0x18, 0xff, 0xfe});
uint8_t byte;
ASSERT_TRUE(dwarf_mem_->ReadBytes(&byte, 1));
@@ -85,16 +87,16 @@ TEST_F(DwarfMemoryTest, ReadSigned_check) {
uint64_t value;
// Signed 8 byte reads.
- memory_.SetData8(0, static_cast<uint8_t>(-10));
- memory_.SetData8(1, 200);
+ fake_memory_->SetData8(0, static_cast<uint8_t>(-10));
+ fake_memory_->SetData8(1, 200);
ASSERT_TRUE(dwarf_mem_->ReadSigned<int8_t>(&value));
ASSERT_EQ(static_cast<int8_t>(-10), static_cast<int8_t>(value));
ASSERT_TRUE(dwarf_mem_->ReadSigned<int8_t>(&value));
ASSERT_EQ(static_cast<int8_t>(200), static_cast<int8_t>(value));
// Signed 16 byte reads.
- memory_.SetData16(0x10, static_cast<uint16_t>(-1000));
- memory_.SetData16(0x12, 50100);
+ fake_memory_->SetData16(0x10, static_cast<uint16_t>(-1000));
+ fake_memory_->SetData16(0x12, 50100);
dwarf_mem_->set_cur_offset(0x10);
ASSERT_TRUE(dwarf_mem_->ReadSigned<int16_t>(&value));
ASSERT_EQ(static_cast<int16_t>(-1000), static_cast<int16_t>(value));
@@ -102,8 +104,8 @@ TEST_F(DwarfMemoryTest, ReadSigned_check) {
ASSERT_EQ(static_cast<int16_t>(50100), static_cast<int16_t>(value));
// Signed 32 byte reads.
- memory_.SetData32(0x100, static_cast<uint32_t>(-1000000000));
- memory_.SetData32(0x104, 3000000000);
+ fake_memory_->SetData32(0x100, static_cast<uint32_t>(-1000000000));
+ fake_memory_->SetData32(0x104, 3000000000);
dwarf_mem_->set_cur_offset(0x100);
ASSERT_TRUE(dwarf_mem_->ReadSigned<int32_t>(&value));
ASSERT_EQ(static_cast<int32_t>(-1000000000), static_cast<int32_t>(value));
@@ -111,8 +113,8 @@ TEST_F(DwarfMemoryTest, ReadSigned_check) {
ASSERT_EQ(static_cast<int32_t>(3000000000), static_cast<int32_t>(value));
// Signed 64 byte reads.
- memory_.SetData64(0x200, static_cast<uint64_t>(-2000000000000LL));
- memory_.SetData64(0x208, 5000000000000LL);
+ fake_memory_->SetData64(0x200, static_cast<uint64_t>(-2000000000000LL));
+ fake_memory_->SetData64(0x208, 5000000000000LL);
dwarf_mem_->set_cur_offset(0x200);
ASSERT_TRUE(dwarf_mem_->ReadSigned<int64_t>(&value));
ASSERT_EQ(static_cast<int64_t>(-2000000000000), static_cast<int64_t>(value));
@@ -121,7 +123,7 @@ TEST_F(DwarfMemoryTest, ReadSigned_check) {
}
TEST_F(DwarfMemoryTest, ReadULEB128) {
- memory_.SetMemory(0, std::vector<uint8_t>{0x01, 0x80, 0x24, 0xff, 0xc3, 0xff, 0x7f});
+ fake_memory_->SetMemory(0, std::vector<uint8_t>{0x01, 0x80, 0x24, 0xff, 0xc3, 0xff, 0x7f});
uint64_t value;
ASSERT_TRUE(dwarf_mem_->ReadULEB128(&value));
@@ -138,8 +140,8 @@ TEST_F(DwarfMemoryTest, ReadULEB128) {
}
TEST_F(DwarfMemoryTest, ReadSLEB128) {
- memory_.SetMemory(0, std::vector<uint8_t>{0x06, 0x40, 0x82, 0x34, 0x89, 0x64, 0xf9, 0xc3, 0x8f,
- 0x2f, 0xbf, 0xc3, 0xf7, 0x5f});
+ fake_memory_->SetMemory(0, std::vector<uint8_t>{0x06, 0x40, 0x82, 0x34, 0x89, 0x64, 0xf9, 0xc3,
+ 0x8f, 0x2f, 0xbf, 0xc3, 0xf7, 0x5f});
int64_t value;
ASSERT_TRUE(dwarf_mem_->ReadSLEB128(&value));
@@ -255,7 +257,7 @@ TEST_F(DwarfMemoryTest, ReadEncodedValue_absptr_uint32_t) {
uint64_t value = 100;
ASSERT_FALSE(dwarf_mem_->ReadEncodedValue<uint32_t>(0x00, &value));
- memory_.SetData32(0, 0x12345678);
+ fake_memory_->SetData32(0, 0x12345678);
ASSERT_TRUE(dwarf_mem_->ReadEncodedValue<uint32_t>(0x00, &value));
ASSERT_EQ(4U, dwarf_mem_->cur_offset());
@@ -266,7 +268,7 @@ TEST_F(DwarfMemoryTest, ReadEncodedValue_absptr_uint64_t) {
uint64_t value = 100;
ASSERT_FALSE(dwarf_mem_->ReadEncodedValue<uint64_t>(0x00, &value));
- memory_.SetData64(0, 0x12345678f1f2f3f4ULL);
+ fake_memory_->SetData64(0, 0x12345678f1f2f3f4ULL);
ASSERT_TRUE(dwarf_mem_->ReadEncodedValue<uint64_t>(0x00, &value));
ASSERT_EQ(8U, dwarf_mem_->cur_offset());
@@ -278,7 +280,7 @@ TEST_F(DwarfMemoryTest, ReadEncodedValue_aligned_uint32_t) {
dwarf_mem_->set_cur_offset(1);
ASSERT_FALSE(dwarf_mem_->ReadEncodedValue<uint32_t>(0x50, &value));
- memory_.SetData32(4, 0x12345678);
+ fake_memory_->SetData32(4, 0x12345678);
ASSERT_TRUE(dwarf_mem_->ReadEncodedValue<uint32_t>(0x50, &value));
ASSERT_EQ(8U, dwarf_mem_->cur_offset());
@@ -290,7 +292,7 @@ TEST_F(DwarfMemoryTest, ReadEncodedValue_aligned_uint64_t) {
dwarf_mem_->set_cur_offset(1);
ASSERT_FALSE(dwarf_mem_->ReadEncodedValue<uint64_t>(0x50, &value));
- memory_.SetData64(8, 0x12345678f1f2f3f4ULL);
+ fake_memory_->SetData64(8, 0x12345678f1f2f3f4ULL);
ASSERT_TRUE(dwarf_mem_->ReadEncodedValue<uint64_t>(0x50, &value));
ASSERT_EQ(16U, dwarf_mem_->cur_offset());
@@ -299,7 +301,7 @@ TEST_F(DwarfMemoryTest, ReadEncodedValue_aligned_uint64_t) {
template <typename AddressType>
void DwarfMemoryTest::ReadEncodedValue_leb128() {
- memory_.SetMemory(0, std::vector<uint8_t>{0x80, 0x42});
+ fake_memory_->SetMemory(0, std::vector<uint8_t>{0x80, 0x42});
uint64_t value = 100;
// uleb128
@@ -322,7 +324,7 @@ TEST_F(DwarfMemoryTest, ReadEncodedValue_leb128_uint64_t) {
template <typename AddressType>
void DwarfMemoryTest::ReadEncodedValue_data1() {
- memory_.SetData8(0, 0xe0);
+ fake_memory_->SetData8(0, 0xe0);
uint64_t value = 0;
ASSERT_TRUE(dwarf_mem_->ReadEncodedValue<AddressType>(0x0d, &value));
@@ -343,7 +345,7 @@ TEST_F(DwarfMemoryTest, ReadEncodedValue_data1_uint64_t) {
template <typename AddressType>
void DwarfMemoryTest::ReadEncodedValue_data2() {
- memory_.SetData16(0, 0xe000);
+ fake_memory_->SetData16(0, 0xe000);
uint64_t value = 0;
ASSERT_TRUE(dwarf_mem_->ReadEncodedValue<AddressType>(0x02, &value));
@@ -364,7 +366,7 @@ TEST_F(DwarfMemoryTest, ReadEncodedValue_data2_uint64_t) {
template <typename AddressType>
void DwarfMemoryTest::ReadEncodedValue_data4() {
- memory_.SetData32(0, 0xe0000000);
+ fake_memory_->SetData32(0, 0xe0000000);
uint64_t value = 0;
ASSERT_TRUE(dwarf_mem_->ReadEncodedValue<AddressType>(0x03, &value));
@@ -385,7 +387,7 @@ TEST_F(DwarfMemoryTest, ReadEncodedValue_data4_uint64_t) {
template <typename AddressType>
void DwarfMemoryTest::ReadEncodedValue_data8() {
- memory_.SetData64(0, 0xe000000000000000ULL);
+ fake_memory_->SetData64(0, 0xe000000000000000ULL);
uint64_t value = 0;
ASSERT_TRUE(dwarf_mem_->ReadEncodedValue<AddressType>(0x04, &value));
@@ -406,7 +408,7 @@ TEST_F(DwarfMemoryTest, ReadEncodedValue_data8_uint64_t) {
template <typename AddressType>
void DwarfMemoryTest::ReadEncodedValue_non_zero_adjust() {
- memory_.SetData64(0, 0xe000000000000000ULL);
+ fake_memory_->SetData64(0, 0xe000000000000000ULL);
uint64_t value = 0;
dwarf_mem_->set_pc_offset(0x2000);
@@ -424,7 +426,7 @@ TEST_F(DwarfMemoryTest, ReadEncodedValue_non_zero_adjust_uint64_t) {
template <typename AddressType>
void DwarfMemoryTest::ReadEncodedValue_overflow() {
- memory_.SetData64(0, 0);
+ fake_memory_->SetData64(0, 0);
uint64_t value = 0;
dwarf_mem_->set_cur_offset(UINT64_MAX);
@@ -442,7 +444,7 @@ TEST_F(DwarfMemoryTest, ReadEncodedValue_overflow_uint64_t) {
template <typename AddressType>
void DwarfMemoryTest::ReadEncodedValue_high_bit_set() {
uint64_t value;
- memory_.SetData32(0, 0x15234);
+ fake_memory_->SetData32(0, 0x15234);
ASSERT_FALSE(dwarf_mem_->ReadEncodedValue<AddressType>(0xc3, &value));
dwarf_mem_->set_func_offset(0x60000);
@@ -461,8 +463,8 @@ TEST_F(DwarfMemoryTest, ReadEncodedValue_high_bit_set_uint64_t) {
template <typename AddressType>
void DwarfMemoryTest::ReadEncodedValue_all() {
- MemoryFakeAlwaysReadZero memory;
- DwarfMemory dwarf_mem(&memory);
+ std::shared_ptr<Memory> memory(new MemoryFakeAlwaysReadZero);
+ DwarfMemory dwarf_mem(memory);
for (size_t i = 0; i <= 0xff; i++) {
uint64_t value;
diff --git a/libunwindstack/tests/DwarfOpLogTest.cpp b/libunwindstack/tests/DwarfOpLogTest.cpp
index f4dbf8d..edea970 100644
--- a/libunwindstack/tests/DwarfOpLogTest.cpp
+++ b/libunwindstack/tests/DwarfOpLogTest.cpp
@@ -16,7 +16,8 @@
#include <stdint.h>
-#include <ios>
+#include <memory>
+#include <string>
#include <vector>
#include <gtest/gtest.h>
@@ -36,13 +37,14 @@ template <typename TypeParam>
class DwarfOpLogTest : public ::testing::Test {
protected:
void SetUp() override {
- op_memory_.Clear();
+ op_memory_ = new MemoryFake;
+ std::shared_ptr<Memory> memory(op_memory_);
+ mem_.reset(new DwarfMemory(memory));
regular_memory_.Clear();
- mem_.reset(new DwarfMemory(&op_memory_));
op_.reset(new DwarfOp<TypeParam>(mem_.get(), &regular_memory_));
}
- MemoryFake op_memory_;
+ MemoryFake* op_memory_;
MemoryFake regular_memory_;
std::unique_ptr<DwarfMemory> mem_;
@@ -55,7 +57,7 @@ TYPED_TEST_P(DwarfOpLogTest, multiple_ops) {
std::vector<uint8_t> opcode_buffer = {
0x0a, 0x20, 0x10, 0x08, 0x03, 0x12, 0x27,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
std::vector<std::string> lines;
this->op_->GetLogInfo(0, opcode_buffer.size(), &lines);
diff --git a/libunwindstack/tests/DwarfOpTest.cpp b/libunwindstack/tests/DwarfOpTest.cpp
index c990fa9..bd3210f 100644
--- a/libunwindstack/tests/DwarfOpTest.cpp
+++ b/libunwindstack/tests/DwarfOpTest.cpp
@@ -17,6 +17,7 @@
#include <stdint.h>
#include <ios>
+#include <memory>
#include <vector>
#include <gtest/gtest.h>
@@ -36,13 +37,14 @@ template <typename TypeParam>
class DwarfOpTest : public ::testing::Test {
protected:
void SetUp() override {
- op_memory_.Clear();
+ op_memory_ = new MemoryFake;
+ std::shared_ptr<Memory> op_memory(op_memory_);
+ mem_.reset(new DwarfMemory(op_memory));
regular_memory_.Clear();
- mem_.reset(new DwarfMemory(&op_memory_));
op_.reset(new DwarfOp<TypeParam>(mem_.get(), &regular_memory_));
}
- MemoryFake op_memory_;
+ MemoryFake* op_memory_;
MemoryFake regular_memory_;
std::unique_ptr<DwarfMemory> mem_;
@@ -57,7 +59,7 @@ TYPED_TEST_P(DwarfOpTest, decode) {
EXPECT_EQ(0U, this->op_->LastErrorAddress());
// No error.
- this->op_memory_.SetMemory(0, std::vector<uint8_t>{0x96});
+ this->op_memory_->SetMemory(0, std::vector<uint8_t>{0x96});
this->mem_->set_cur_offset(0);
ASSERT_TRUE(this->op_->Decode());
ASSERT_EQ(DWARF_ERROR_NONE, this->op_->LastErrorCode());
@@ -73,7 +75,7 @@ TYPED_TEST_P(DwarfOpTest, eval) {
// Register set.
// Do this first, to verify that subsequent calls reset the value.
- this->op_memory_.SetMemory(0, std::vector<uint8_t>{0x50});
+ this->op_memory_->SetMemory(0, std::vector<uint8_t>{0x50});
ASSERT_TRUE(this->op_->Eval(0, 1));
ASSERT_TRUE(this->op_->is_register());
ASSERT_EQ(1U, this->mem_->cur_offset());
@@ -83,7 +85,7 @@ TYPED_TEST_P(DwarfOpTest, eval) {
std::vector<uint8_t> opcode_buffer = {
0x08, 0x04, 0x08, 0x03, 0x08, 0x02, 0x08, 0x01,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
ASSERT_TRUE(this->op_->Eval(0, 8));
ASSERT_EQ(DWARF_ERROR_NONE, this->op_->LastErrorCode());
@@ -96,7 +98,7 @@ TYPED_TEST_P(DwarfOpTest, eval) {
ASSERT_EQ(4U, this->op_->StackAt(3));
// Infinite loop.
- this->op_memory_.SetMemory(0, std::vector<uint8_t>{0x2f, 0xfd, 0xff});
+ this->op_memory_->SetMemory(0, std::vector<uint8_t>{0x2f, 0xfd, 0xff});
ASSERT_FALSE(this->op_->Eval(0, 4));
ASSERT_EQ(DWARF_ERROR_TOO_MANY_ITERATIONS, this->op_->LastErrorCode());
ASSERT_FALSE(this->op_->is_register());
@@ -109,7 +111,7 @@ TYPED_TEST_P(DwarfOpTest, illegal_opcode) {
for (size_t opcode = 0xa0; opcode < 256; opcode++) {
opcode_buffer.push_back(opcode);
}
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
for (size_t i = 0; i < opcode_buffer.size(); i++) {
ASSERT_FALSE(this->op_->Decode());
@@ -149,7 +151,7 @@ TYPED_TEST_P(DwarfOpTest, not_implemented) {
// stack_value
0x9f,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
// Push the stack values.
ASSERT_TRUE(this->op_->Decode());
@@ -170,7 +172,7 @@ TYPED_TEST_P(DwarfOpTest, op_addr) {
opcode_buffer.push_back(0x78);
opcode_buffer.push_back(0x89);
}
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
ASSERT_TRUE(this->op_->Decode());
ASSERT_EQ(0x03, this->op_->cur_op());
@@ -191,7 +193,7 @@ TYPED_TEST_P(DwarfOpTest, op_deref) {
// Now do another dereference that should fail in memory.
0x06,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
TypeParam value = 0x12345678;
this->regular_memory_.SetMemory(0x2010, &value, sizeof(value));
@@ -211,7 +213,7 @@ TYPED_TEST_P(DwarfOpTest, op_deref) {
}
TYPED_TEST_P(DwarfOpTest, op_deref_size) {
- this->op_memory_.SetMemory(0, std::vector<uint8_t>{0x94});
+ this->op_memory_->SetMemory(0, std::vector<uint8_t>{0x94});
TypeParam value = 0x12345678;
this->regular_memory_.SetMemory(0x2010, &value, sizeof(value));
@@ -220,7 +222,7 @@ TYPED_TEST_P(DwarfOpTest, op_deref_size) {
// Read all byte sizes up to the sizeof the type.
for (size_t i = 1; i < sizeof(TypeParam); i++) {
- this->op_memory_.SetMemory(
+ this->op_memory_->SetMemory(
0, std::vector<uint8_t>{0x0a, 0x10, 0x20, 0x94, static_cast<uint8_t>(i)});
ASSERT_TRUE(this->op_->Eval(0, 5)) << "Failed at size " << i;
ASSERT_EQ(1U, this->op_->StackSize()) << "Failed at size " << i;
@@ -231,17 +233,18 @@ TYPED_TEST_P(DwarfOpTest, op_deref_size) {
}
// Zero byte read.
- this->op_memory_.SetMemory(0, std::vector<uint8_t>{0x0a, 0x10, 0x20, 0x94, 0x00});
+ this->op_memory_->SetMemory(0, std::vector<uint8_t>{0x0a, 0x10, 0x20, 0x94, 0x00});
ASSERT_FALSE(this->op_->Eval(0, 5));
ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->op_->LastErrorCode());
// Read too many bytes.
- this->op_memory_.SetMemory(0, std::vector<uint8_t>{0x0a, 0x10, 0x20, 0x94, sizeof(TypeParam) + 1});
+ this->op_memory_->SetMemory(0,
+ std::vector<uint8_t>{0x0a, 0x10, 0x20, 0x94, sizeof(TypeParam) + 1});
ASSERT_FALSE(this->op_->Eval(0, 5));
ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->op_->LastErrorCode());
// Force bad memory read.
- this->op_memory_.SetMemory(0, std::vector<uint8_t>{0x0a, 0x10, 0x40, 0x94, 0x01});
+ this->op_memory_->SetMemory(0, std::vector<uint8_t>{0x0a, 0x10, 0x40, 0x94, 0x01});
ASSERT_FALSE(this->op_->Eval(0, 5));
ASSERT_EQ(DWARF_ERROR_MEMORY_INVALID, this->op_->LastErrorCode());
EXPECT_EQ(0x4010U, this->op_->LastErrorAddress());
@@ -259,7 +262,7 @@ TYPED_TEST_P(DwarfOpTest, const_unsigned) {
0x0e, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x0e, 0x87, 0x98, 0xa9, 0xba, 0xcb,
0xdc, 0xed, 0xfe,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
// const1u
ASSERT_TRUE(this->op_->Decode());
@@ -326,7 +329,7 @@ TYPED_TEST_P(DwarfOpTest, const_signed) {
0x0f, 0x89, 0x78, 0x67, 0x56, 0x45, 0x34, 0x23, 0x12, 0x0f, 0x04, 0x03, 0x02, 0x01, 0xef,
0xef, 0xef, 0xff,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
// const1s
ASSERT_TRUE(this->op_->Decode());
@@ -389,7 +392,7 @@ TYPED_TEST_P(DwarfOpTest, const_uleb) {
0x10, 0xa2, 0x22, 0x10, 0xa2, 0x74, 0x10, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88,
0x09, 0x10, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x79,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
// Single byte ULEB128
ASSERT_TRUE(this->op_->Decode());
@@ -455,7 +458,7 @@ TYPED_TEST_P(DwarfOpTest, const_sleb) {
opcode_buffer.push_back(0x88);
opcode_buffer.push_back(0x79);
}
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
// Single byte SLEB128
ASSERT_TRUE(this->op_->Decode());
@@ -507,7 +510,7 @@ TYPED_TEST_P(DwarfOpTest, op_dup) {
// Do it again.
0x08, 0x23, 0x12,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode());
ASSERT_EQ(0x12, this->op_->cur_op());
@@ -541,7 +544,7 @@ TYPED_TEST_P(DwarfOpTest, op_drop) {
// Attempt to drop empty stack.
0x13,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
ASSERT_TRUE(this->op_->Decode());
ASSERT_EQ(1U, this->op_->StackSize());
@@ -573,7 +576,7 @@ TYPED_TEST_P(DwarfOpTest, op_over) {
// Provoke a failure with this opcode.
0x14,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
ASSERT_TRUE(this->op_->Decode());
ASSERT_EQ(1U, this->op_->StackSize());
@@ -619,7 +622,7 @@ TYPED_TEST_P(DwarfOpTest, op_pick) {
0x15,
0x10,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode());
ASSERT_EQ(0x15, this->op_->cur_op());
@@ -663,7 +666,7 @@ TYPED_TEST_P(DwarfOpTest, op_swap) {
// Pop a value to cause a failure.
0x13, 0x16,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
ASSERT_TRUE(this->op_->Decode());
ASSERT_EQ(1U, this->op_->StackSize());
@@ -697,7 +700,7 @@ TYPED_TEST_P(DwarfOpTest, op_rot) {
// Should rotate properly.
0x17,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode());
ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
@@ -747,7 +750,7 @@ TYPED_TEST_P(DwarfOpTest, op_abs) {
opcode_buffer.push_back(0x01);
}
opcode_buffer.push_back(0x19);
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode());
ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
@@ -799,7 +802,7 @@ TYPED_TEST_P(DwarfOpTest, op_and) {
// Divide by zero.
0x11, 0x10, 0x11, 0x00, 0x1b,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode());
ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
@@ -865,7 +868,7 @@ TYPED_TEST_P(DwarfOpTest, op_div) {
// Push another value.
0x08, 0xf0, 0x1a,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode());
ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
@@ -896,7 +899,7 @@ TYPED_TEST_P(DwarfOpTest, op_minus) {
// Push another value.
0x08, 0x04, 0x1c,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode());
ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
@@ -929,7 +932,7 @@ TYPED_TEST_P(DwarfOpTest, op_mod) {
// Try a mod of zero.
0x08, 0x01, 0x08, 0x00, 0x1d,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode());
ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
@@ -968,7 +971,7 @@ TYPED_TEST_P(DwarfOpTest, op_mul) {
// Push another value.
0x08, 0x04, 0x1e,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode());
ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
@@ -997,7 +1000,7 @@ TYPED_TEST_P(DwarfOpTest, op_neg) {
// Push a negative value.
0x11, 0x7f, 0x1f,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode());
ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
@@ -1028,7 +1031,7 @@ TYPED_TEST_P(DwarfOpTest, op_not) {
// Push a negative value.
0x11, 0x7c, 0x20,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode());
ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
@@ -1061,7 +1064,7 @@ TYPED_TEST_P(DwarfOpTest, op_or) {
// Push another value.
0x08, 0xf4, 0x21,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode());
ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
@@ -1092,7 +1095,7 @@ TYPED_TEST_P(DwarfOpTest, op_plus) {
// Push another value.
0x08, 0xf2, 0x22,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode());
ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
@@ -1119,7 +1122,7 @@ TYPED_TEST_P(DwarfOpTest, op_plus_uconst) {
// Push a single value.
0x08, 0x50, 0x23, 0x80, 0x51,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode());
ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
@@ -1144,7 +1147,7 @@ TYPED_TEST_P(DwarfOpTest, op_shl) {
// Push another value.
0x08, 0x03, 0x24,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode());
ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
@@ -1175,7 +1178,7 @@ TYPED_TEST_P(DwarfOpTest, op_shr) {
// Push another value.
0x08, 0x03, 0x25,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode());
ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
@@ -1210,7 +1213,7 @@ TYPED_TEST_P(DwarfOpTest, op_shra) {
// Push another value.
0x08, 0x03, 0x26,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode());
ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
@@ -1241,7 +1244,7 @@ TYPED_TEST_P(DwarfOpTest, op_xor) {
// Push another value.
0x08, 0x41, 0x27,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode());
ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
@@ -1274,7 +1277,7 @@ TYPED_TEST_P(DwarfOpTest, op_bra) {
// Push on a zero value with a negative branch.
0x08, 0x00, 0x28, 0xf0, 0xff,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode());
ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
@@ -1335,7 +1338,7 @@ TYPED_TEST_P(DwarfOpTest, compare_opcode_stack_error) {
for (uint8_t opcode = 0x29; opcode <= 0x2e; opcode++) {
opcode_buffer[0] = opcode;
opcode_buffer[3] = opcode;
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Eval(0, 1));
ASSERT_EQ(opcode, this->op_->cur_op());
@@ -1378,7 +1381,7 @@ TYPED_TEST_P(DwarfOpTest, compare_opcodes) {
opcode_buffer[4] = expected[i];
opcode_buffer[9] = expected[i];
opcode_buffer[14] = expected[i];
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
ASSERT_TRUE(this->op_->Eval(0, 15))
<< "Op: 0x" << std::hex << static_cast<uint32_t>(expected[i]) << " failed";
@@ -1397,7 +1400,7 @@ TYPED_TEST_P(DwarfOpTest, op_skip) {
// Negative value.
0x2f, 0xfd, 0xff,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
uint64_t offset = this->mem_->cur_offset() + 3;
ASSERT_TRUE(this->op_->Decode());
@@ -1420,7 +1423,7 @@ TYPED_TEST_P(DwarfOpTest, op_lit) {
for (uint8_t op = 0x30; op <= 0x4f; op++) {
opcode_buffer.push_back(op);
}
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
for (size_t i = 0; i < opcode_buffer.size(); i++) {
uint32_t op = opcode_buffer[i];
@@ -1438,7 +1441,7 @@ TYPED_TEST_P(DwarfOpTest, op_reg) {
for (uint8_t op = 0x50; op <= 0x6f; op++) {
opcode_buffer.push_back(op);
}
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
for (size_t i = 0; i < opcode_buffer.size(); i++) {
uint32_t op = opcode_buffer[i];
@@ -1454,7 +1457,7 @@ TYPED_TEST_P(DwarfOpTest, op_regx) {
std::vector<uint8_t> opcode_buffer = {
0x90, 0x02, 0x90, 0x80, 0x15,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
ASSERT_TRUE(this->op_->Eval(0, 2));
ASSERT_EQ(0x90, this->op_->cur_op());
@@ -1481,7 +1484,7 @@ TYPED_TEST_P(DwarfOpTest, op_breg) {
opcode_buffer.push_back(op);
opcode_buffer.push_back(0x7e);
}
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
RegsImplFake<TypeParam> regs(32);
for (size_t i = 0; i < 32; i++) {
@@ -1512,7 +1515,7 @@ TYPED_TEST_P(DwarfOpTest, op_breg_invalid_register) {
std::vector<uint8_t> opcode_buffer = {
0x7f, 0x12, 0x80, 0x12,
};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
RegsImplFake<TypeParam> regs(16);
for (size_t i = 0; i < 16; i++) {
@@ -1539,7 +1542,7 @@ TYPED_TEST_P(DwarfOpTest, op_bregx) {
0x92, 0x06, 0x80, 0x7e,
// Illegal register.
0x92, 0x80, 0x15, 0x80, 0x02};
- this->op_memory_.SetMemory(0, opcode_buffer);
+ this->op_memory_->SetMemory(0, opcode_buffer);
RegsImplFake<TypeParam> regs(10);
regs[5] = 0x45;
@@ -1562,7 +1565,7 @@ TYPED_TEST_P(DwarfOpTest, op_bregx) {
}
TYPED_TEST_P(DwarfOpTest, op_nop) {
- this->op_memory_.SetMemory(0, std::vector<uint8_t>{0x96});
+ this->op_memory_->SetMemory(0, std::vector<uint8_t>{0x96});
ASSERT_TRUE(this->op_->Decode());
ASSERT_EQ(0x96, this->op_->cur_op());
@@ -1571,7 +1574,7 @@ TYPED_TEST_P(DwarfOpTest, op_nop) {
TYPED_TEST_P(DwarfOpTest, is_dex_pc) {
// Special sequence that indicates this is a dex pc.
- this->op_memory_.SetMemory(0, std::vector<uint8_t>{0x0c, 'D', 'E', 'X', '1', 0x13});
+ this->op_memory_->SetMemory(0, std::vector<uint8_t>{0x0c, 'D', 'E', 'X', '1', 0x13});
ASSERT_TRUE(this->op_->Eval(0, 6));
EXPECT_TRUE(this->op_->dex_pc_set());
@@ -1581,7 +1584,7 @@ TYPED_TEST_P(DwarfOpTest, is_dex_pc) {
EXPECT_FALSE(this->op_->dex_pc_set());
// Change the constant.
- this->op_memory_.SetMemory(0, std::vector<uint8_t>{0x0c, 'D', 'E', 'X', '2', 0x13});
+ this->op_memory_->SetMemory(0, std::vector<uint8_t>{0x0c, 'D', 'E', 'X', '2', 0x13});
ASSERT_TRUE(this->op_->Eval(0, 6));
EXPECT_FALSE(this->op_->dex_pc_set());
}
diff --git a/libunwindstack/tests/DwarfSectionImplTest.cpp b/libunwindstack/tests/DwarfSectionImplTest.cpp
index a487bc0..4c7d34d 100644
--- a/libunwindstack/tests/DwarfSectionImplTest.cpp
+++ b/libunwindstack/tests/DwarfSectionImplTest.cpp
@@ -16,6 +16,9 @@
#include <stdint.h>
+#include <memory>
+#include <vector>
+
#include <gtest/gtest.h>
#include <unwindstack/DwarfError.h>
@@ -35,15 +38,14 @@ template <typename TypeParam>
class DwarfSectionImplTest : public ::testing::Test {
protected:
void SetUp() override {
- memory_.Clear();
- section_ = new DwarfSectionImplFake<TypeParam>(&memory_);
+ fake_memory_ = new MemoryFake;
+ std::shared_ptr<Memory> memory(fake_memory_);
+ section_.reset(new DwarfSectionImplFake<TypeParam>(memory));
ResetLogs();
}
- void TearDown() override { delete section_; }
-
- MemoryFake memory_;
- DwarfSectionImplFake<TypeParam>* section_ = nullptr;
+ MemoryFake* fake_memory_;
+ std::unique_ptr<DwarfSectionImplFake<TypeParam>> section_;
};
TYPED_TEST_SUITE_P(DwarfSectionImplTest);
@@ -82,7 +84,7 @@ TYPED_TEST_P(DwarfSectionImplTest, Eval_cfa_expr_eval_fail) {
regs[9] = 0x3000;
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_VAL_EXPRESSION, {0x2, 0x5002}};
bool finished;
- ASSERT_FALSE(this->section_->Eval(&cie, &this->memory_, loc_regs, &regs, &finished));
+ ASSERT_FALSE(this->section_->Eval(&cie, this->fake_memory_, loc_regs, &regs, &finished));
EXPECT_EQ(DWARF_ERROR_MEMORY_INVALID, this->section_->LastErrorCode());
EXPECT_EQ(0x5000U, this->section_->LastErrorAddress());
}
@@ -96,10 +98,10 @@ TYPED_TEST_P(DwarfSectionImplTest, Eval_cfa_expr_no_stack) {
regs.set_sp(0x2000);
regs[5] = 0x20;
regs[9] = 0x3000;
- this->memory_.SetMemory(0x5000, std::vector<uint8_t>{0x96, 0x96, 0x96});
+ this->fake_memory_->SetMemory(0x5000, std::vector<uint8_t>{0x96, 0x96, 0x96});
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_VAL_EXPRESSION, {0x2, 0x5002}};
bool finished;
- ASSERT_FALSE(this->section_->Eval(&cie, &this->memory_, loc_regs, &regs, &finished));
+ ASSERT_FALSE(this->section_->Eval(&cie, this->fake_memory_, loc_regs, &regs, &finished));
EXPECT_EQ(DWARF_ERROR_ILLEGAL_STATE, this->section_->LastErrorCode());
}
@@ -112,12 +114,12 @@ TYPED_TEST_P(DwarfSectionImplTest, Eval_cfa_expr) {
regs.set_sp(0x2000);
regs[5] = 0x20;
regs[9] = 0x3000;
- this->memory_.SetMemory(0x5000, std::vector<uint8_t>{0x0c, 0x00, 0x00, 0x00, 0x80});
+ this->fake_memory_->SetMemory(0x5000, std::vector<uint8_t>{0x0c, 0x00, 0x00, 0x00, 0x80});
TypeParam cfa_value = 0x12345;
- this->memory_.SetMemory(0x80000000, &cfa_value, sizeof(cfa_value));
+ this->fake_memory_->SetMemory(0x80000000, &cfa_value, sizeof(cfa_value));
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_EXPRESSION, {0x4, 0x5004}};
bool finished;
- ASSERT_FALSE(this->section_->Eval(&cie, &this->memory_, loc_regs, &regs, &finished));
+ ASSERT_FALSE(this->section_->Eval(&cie, this->fake_memory_, loc_regs, &regs, &finished));
EXPECT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->section_->LastErrorCode());
}
@@ -130,10 +132,10 @@ TYPED_TEST_P(DwarfSectionImplTest, Eval_cfa_val_expr) {
regs.set_sp(0x2000);
regs[5] = 0x20;
regs[9] = 0x3000;
- this->memory_.SetMemory(0x5000, std::vector<uint8_t>{0x0c, 0x00, 0x00, 0x00, 0x80});
+ this->fake_memory_->SetMemory(0x5000, std::vector<uint8_t>{0x0c, 0x00, 0x00, 0x00, 0x80});
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_VAL_EXPRESSION, {0x4, 0x5004}};
bool finished;
- ASSERT_TRUE(this->section_->Eval(&cie, &this->memory_, loc_regs, &regs, &finished));
+ ASSERT_TRUE(this->section_->Eval(&cie, this->fake_memory_, loc_regs, &regs, &finished));
ASSERT_FALSE(finished);
EXPECT_EQ(0x80000000U, regs.sp());
EXPECT_EQ(0x20U, regs.pc());
@@ -148,10 +150,10 @@ TYPED_TEST_P(DwarfSectionImplTest, Eval_cfa_expr_is_register) {
regs.set_sp(0x2000);
regs[5] = 0x20;
regs[9] = 0x3000;
- this->memory_.SetMemory(0x5000, std::vector<uint8_t>{0x50, 0x96, 0x96});
+ this->fake_memory_->SetMemory(0x5000, std::vector<uint8_t>{0x50, 0x96, 0x96});
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_VAL_EXPRESSION, {0x2, 0x5002}};
bool finished;
- ASSERT_FALSE(this->section_->Eval(&cie, &this->memory_, loc_regs, &regs, &finished));
+ ASSERT_FALSE(this->section_->Eval(&cie, this->fake_memory_, loc_regs, &regs, &finished));
EXPECT_EQ(DWARF_ERROR_NOT_IMPLEMENTED, this->section_->LastErrorCode());
}
@@ -161,7 +163,7 @@ TYPED_TEST_P(DwarfSectionImplTest, Eval_bad_regs) {
DwarfLocations loc_regs;
bool finished;
- ASSERT_FALSE(this->section_->Eval(&cie, &this->memory_, loc_regs, &regs, &finished));
+ ASSERT_FALSE(this->section_->Eval(&cie, this->fake_memory_, loc_regs, &regs, &finished));
EXPECT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->section_->LastErrorCode());
}
@@ -171,7 +173,7 @@ TYPED_TEST_P(DwarfSectionImplTest, Eval_no_cfa) {
DwarfLocations loc_regs;
bool finished;
- ASSERT_FALSE(this->section_->Eval(&cie, &this->memory_, loc_regs, &regs, &finished));
+ ASSERT_FALSE(this->section_->Eval(&cie, this->fake_memory_, loc_regs, &regs, &finished));
EXPECT_EQ(DWARF_ERROR_CFA_NOT_DEFINED, this->section_->LastErrorCode());
}
@@ -182,25 +184,25 @@ TYPED_TEST_P(DwarfSectionImplTest, Eval_cfa_bad) {
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_REGISTER, {20, 0}};
bool finished;
- ASSERT_FALSE(this->section_->Eval(&cie, &this->memory_, loc_regs, &regs, &finished));
+ ASSERT_FALSE(this->section_->Eval(&cie, this->fake_memory_, loc_regs, &regs, &finished));
EXPECT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->section_->LastErrorCode());
this->section_->FakeClearError();
loc_regs.erase(CFA_REG);
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_INVALID, {0, 0}};
- ASSERT_FALSE(this->section_->Eval(&cie, &this->memory_, loc_regs, &regs, &finished));
+ ASSERT_FALSE(this->section_->Eval(&cie, this->fake_memory_, loc_regs, &regs, &finished));
EXPECT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->section_->LastErrorCode());
this->section_->FakeClearError();
loc_regs.erase(CFA_REG);
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_OFFSET, {0, 0}};
- ASSERT_FALSE(this->section_->Eval(&cie, &this->memory_, loc_regs, &regs, &finished));
+ ASSERT_FALSE(this->section_->Eval(&cie, this->fake_memory_, loc_regs, &regs, &finished));
EXPECT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->section_->LastErrorCode());
this->section_->FakeClearError();
loc_regs.erase(CFA_REG);
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_VAL_OFFSET, {0, 0}};
- ASSERT_FALSE(this->section_->Eval(&cie, &this->memory_, loc_regs, &regs, &finished));
+ ASSERT_FALSE(this->section_->Eval(&cie, this->fake_memory_, loc_regs, &regs, &finished));
EXPECT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->section_->LastErrorCode());
}
@@ -215,7 +217,7 @@ TYPED_TEST_P(DwarfSectionImplTest, Eval_cfa_register_prev) {
regs[9] = 0x3000;
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_REGISTER, {9, 0}};
bool finished;
- ASSERT_TRUE(this->section_->Eval(&cie, &this->memory_, loc_regs, &regs, &finished));
+ ASSERT_TRUE(this->section_->Eval(&cie, this->fake_memory_, loc_regs, &regs, &finished));
EXPECT_FALSE(finished);
EXPECT_EQ(0x20U, regs.pc());
EXPECT_EQ(0x3000U, regs.sp());
@@ -233,7 +235,7 @@ TYPED_TEST_P(DwarfSectionImplTest, Eval_cfa_register_from_value) {
regs[9] = 0x3000;
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_REGISTER, {6, 0}};
bool finished;
- ASSERT_TRUE(this->section_->Eval(&cie, &this->memory_, loc_regs, &regs, &finished));
+ ASSERT_TRUE(this->section_->Eval(&cie, this->fake_memory_, loc_regs, &regs, &finished));
EXPECT_FALSE(finished);
EXPECT_EQ(0x20U, regs.pc());
EXPECT_EQ(0x4000U, regs.sp());
@@ -253,7 +255,7 @@ TYPED_TEST_P(DwarfSectionImplTest, Eval_double_indirection) {
loc_regs[1] = DwarfLocation{DWARF_LOCATION_REGISTER, {3, 1}};
loc_regs[9] = DwarfLocation{DWARF_LOCATION_REGISTER, {1, 2}};
bool finished;
- ASSERT_TRUE(this->section_->Eval(&cie, &this->memory_, loc_regs, &regs, &finished));
+ ASSERT_TRUE(this->section_->Eval(&cie, this->fake_memory_, loc_regs, &regs, &finished));
EXPECT_EQ(0x301U, regs[1]);
EXPECT_EQ(0x300U, regs[3]);
EXPECT_EQ(0x10U, regs[8]);
@@ -281,7 +283,7 @@ TYPED_TEST_P(DwarfSectionImplTest, Eval_register_reference_chain) {
loc_regs[4] = DwarfLocation{DWARF_LOCATION_REGISTER, {3, 4}};
loc_regs[5] = DwarfLocation{DWARF_LOCATION_REGISTER, {4, 5}};
bool finished;
- ASSERT_TRUE(this->section_->Eval(&cie, &this->memory_, loc_regs, &regs, &finished));
+ ASSERT_TRUE(this->section_->Eval(&cie, this->fake_memory_, loc_regs, &regs, &finished));
EXPECT_EQ(0x10U, regs[0]);
EXPECT_EQ(0x11U, regs[1]);
EXPECT_EQ(0x22U, regs[2]);
@@ -302,9 +304,10 @@ TYPED_TEST_P(DwarfSectionImplTest, Eval_dex_pc) {
regs[8] = 0x20;
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_REGISTER, {8, 0}};
loc_regs[1] = DwarfLocation{DWARF_LOCATION_VAL_EXPRESSION, {0x8, 0x5008}};
- this->memory_.SetMemory(0x5000, std::vector<uint8_t>{0x0c, 'D', 'E', 'X', '1', 0x13, 0x08, 0x11});
+ this->fake_memory_->SetMemory(0x5000,
+ std::vector<uint8_t>{0x0c, 'D', 'E', 'X', '1', 0x13, 0x08, 0x11});
bool finished;
- ASSERT_TRUE(this->section_->Eval(&cie, &this->memory_, loc_regs, &regs, &finished));
+ ASSERT_TRUE(this->section_->Eval(&cie, this->fake_memory_, loc_regs, &regs, &finished));
EXPECT_EQ(0x10U, regs[0]);
EXPECT_EQ(0x20U, regs[8]);
EXPECT_EQ(0x11U, regs.dex_pc());
@@ -321,7 +324,7 @@ TYPED_TEST_P(DwarfSectionImplTest, Eval_invalid_register) {
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_REGISTER, {8, 0}};
loc_regs[1] = DwarfLocation{DWARF_LOCATION_REGISTER, {10, 0}};
bool finished;
- ASSERT_FALSE(this->section_->Eval(&cie, &this->memory_, loc_regs, &regs, &finished));
+ ASSERT_FALSE(this->section_->Eval(&cie, this->fake_memory_, loc_regs, &regs, &finished));
EXPECT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->section_->LastErrorCode());
}
@@ -331,9 +334,9 @@ TYPED_TEST_P(DwarfSectionImplTest, Eval_different_reg_locations) {
DwarfLocations loc_regs;
if (sizeof(TypeParam) == sizeof(uint64_t)) {
- this->memory_.SetData64(0x2150, 0x12345678abcdef00ULL);
+ this->fake_memory_->SetData64(0x2150, 0x12345678abcdef00ULL);
} else {
- this->memory_.SetData32(0x2150, 0x12345678);
+ this->fake_memory_->SetData32(0x2150, 0x12345678);
}
regs.set_pc(0x100);
@@ -346,7 +349,7 @@ TYPED_TEST_P(DwarfSectionImplTest, Eval_different_reg_locations) {
loc_regs[2] = DwarfLocation{DWARF_LOCATION_OFFSET, {0x50, 0}};
loc_regs[3] = DwarfLocation{DWARF_LOCATION_UNDEFINED, {0, 0}};
bool finished;
- ASSERT_TRUE(this->section_->Eval(&cie, &this->memory_, loc_regs, &regs, &finished));
+ ASSERT_TRUE(this->section_->Eval(&cie, this->fake_memory_, loc_regs, &regs, &finished));
EXPECT_FALSE(finished);
EXPECT_EQ(0x10U, regs.pc());
EXPECT_EQ(0x2100U, regs.sp());
@@ -371,7 +374,7 @@ TYPED_TEST_P(DwarfSectionImplTest, Eval_return_address_undefined) {
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_REGISTER, {8, 0}};
loc_regs[5] = DwarfLocation{DWARF_LOCATION_UNDEFINED, {0, 0}};
bool finished;
- ASSERT_TRUE(this->section_->Eval(&cie, &this->memory_, loc_regs, &regs, &finished));
+ ASSERT_TRUE(this->section_->Eval(&cie, this->fake_memory_, loc_regs, &regs, &finished));
EXPECT_TRUE(finished);
EXPECT_EQ(0U, regs.pc());
EXPECT_EQ(0x10U, regs.sp());
@@ -388,7 +391,7 @@ TYPED_TEST_P(DwarfSectionImplTest, Eval_pc_zero) {
regs[8] = 0x10;
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_REGISTER, {8, 0}};
bool finished;
- ASSERT_TRUE(this->section_->Eval(&cie, &this->memory_, loc_regs, &regs, &finished));
+ ASSERT_TRUE(this->section_->Eval(&cie, this->fake_memory_, loc_regs, &regs, &finished));
EXPECT_TRUE(finished);
EXPECT_EQ(0U, regs.pc());
EXPECT_EQ(0x10U, regs.sp());
@@ -405,7 +408,7 @@ TYPED_TEST_P(DwarfSectionImplTest, Eval_return_address) {
regs[8] = 0x10;
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_REGISTER, {8, 0}};
bool finished;
- ASSERT_TRUE(this->section_->Eval(&cie, &this->memory_, loc_regs, &regs, &finished));
+ ASSERT_TRUE(this->section_->Eval(&cie, this->fake_memory_, loc_regs, &regs, &finished));
EXPECT_FALSE(finished);
EXPECT_EQ(0x20U, regs.pc());
EXPECT_EQ(0x10U, regs.sp());
@@ -424,7 +427,7 @@ TYPED_TEST_P(DwarfSectionImplTest, Eval_ignore_large_reg_loc) {
// This should not result in any errors.
loc_regs[20] = DwarfLocation{DWARF_LOCATION_REGISTER, {8, 0}};
bool finished;
- ASSERT_TRUE(this->section_->Eval(&cie, &this->memory_, loc_regs, &regs, &finished));
+ ASSERT_TRUE(this->section_->Eval(&cie, this->fake_memory_, loc_regs, &regs, &finished));
EXPECT_FALSE(finished);
EXPECT_EQ(0x20U, regs.pc());
EXPECT_EQ(0x10U, regs.sp());
@@ -438,13 +441,13 @@ TYPED_TEST_P(DwarfSectionImplTest, Eval_reg_expr) {
regs.set_pc(0x100);
regs.set_sp(0x2000);
regs[8] = 0x3000;
- this->memory_.SetMemory(0x5000, std::vector<uint8_t>{0x0c, 0x00, 0x00, 0x00, 0x80});
+ this->fake_memory_->SetMemory(0x5000, std::vector<uint8_t>{0x0c, 0x00, 0x00, 0x00, 0x80});
TypeParam cfa_value = 0x12345;
- this->memory_.SetMemory(0x80000000, &cfa_value, sizeof(cfa_value));
+ this->fake_memory_->SetMemory(0x80000000, &cfa_value, sizeof(cfa_value));
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_REGISTER, {8, 0}};
loc_regs[5] = DwarfLocation{DWARF_LOCATION_EXPRESSION, {0x4, 0x5004}};
bool finished;
- ASSERT_TRUE(this->section_->Eval(&cie, &this->memory_, loc_regs, &regs, &finished));
+ ASSERT_TRUE(this->section_->Eval(&cie, this->fake_memory_, loc_regs, &regs, &finished));
EXPECT_FALSE(finished);
EXPECT_EQ(0x3000U, regs.sp());
EXPECT_EQ(0x12345U, regs.pc());
@@ -458,11 +461,11 @@ TYPED_TEST_P(DwarfSectionImplTest, Eval_reg_val_expr) {
regs.set_pc(0x100);
regs.set_sp(0x2000);
regs[8] = 0x3000;
- this->memory_.SetMemory(0x5000, std::vector<uint8_t>{0x0c, 0x00, 0x00, 0x00, 0x80});
+ this->fake_memory_->SetMemory(0x5000, std::vector<uint8_t>{0x0c, 0x00, 0x00, 0x00, 0x80});
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_REGISTER, {8, 0}};
loc_regs[5] = DwarfLocation{DWARF_LOCATION_VAL_EXPRESSION, {0x4, 0x5004}};
bool finished;
- ASSERT_TRUE(this->section_->Eval(&cie, &this->memory_, loc_regs, &regs, &finished));
+ ASSERT_TRUE(this->section_->Eval(&cie, this->fake_memory_, loc_regs, &regs, &finished));
EXPECT_FALSE(finished);
EXPECT_EQ(0x3000U, regs.sp());
EXPECT_EQ(0x80000000U, regs.pc());
@@ -477,13 +480,13 @@ TYPED_TEST_P(DwarfSectionImplTest, Eval_pseudo_register_invalid) {
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_REGISTER, {8, 0}};
loc_regs[1] = DwarfLocation{DWARF_LOCATION_PSEUDO_REGISTER, {20, 0}};
bool finished;
- ASSERT_FALSE(this->section_->Eval(&cie, &this->memory_, loc_regs, &regs, &finished));
+ ASSERT_FALSE(this->section_->Eval(&cie, this->fake_memory_, loc_regs, &regs, &finished));
EXPECT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->section_->LastErrorCode());
loc_regs.clear();
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_REGISTER, {8, 0}};
loc_regs[12] = DwarfLocation{DWARF_LOCATION_PSEUDO_REGISTER, {20, 0}};
- ASSERT_FALSE(this->section_->Eval(&cie, &this->memory_, loc_regs, &regs, &finished));
+ ASSERT_FALSE(this->section_->Eval(&cie, this->fake_memory_, loc_regs, &regs, &finished));
EXPECT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->section_->LastErrorCode());
}
@@ -496,7 +499,7 @@ TYPED_TEST_P(DwarfSectionImplTest, Eval_pseudo_register) {
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_REGISTER, {8, 0}};
loc_regs[11] = DwarfLocation{DWARF_LOCATION_PSEUDO_REGISTER, {20, 0}};
bool finished;
- ASSERT_TRUE(this->section_->Eval(&cie, &this->memory_, loc_regs, &regs, &finished));
+ ASSERT_TRUE(this->section_->Eval(&cie, this->fake_memory_, loc_regs, &regs, &finished));
uint64_t pseudo_value = 0;
ASSERT_TRUE(regs.GetPseudoRegister(11, &pseudo_value));
EXPECT_EQ(20U, pseudo_value);
@@ -512,8 +515,8 @@ TYPED_TEST_P(DwarfSectionImplTest, GetCfaLocationInfo_cie_not_cached) {
fde.cfa_instructions_offset = 0x6000;
fde.cfa_instructions_end = 0x6002;
- this->memory_.SetMemory(0x3000, std::vector<uint8_t>{0x09, 0x02, 0x01});
- this->memory_.SetMemory(0x6000, std::vector<uint8_t>{0x09, 0x04, 0x03});
+ this->fake_memory_->SetMemory(0x3000, std::vector<uint8_t>{0x09, 0x02, 0x01});
+ this->fake_memory_->SetMemory(0x6000, std::vector<uint8_t>{0x09, 0x04, 0x03});
DwarfLocations loc_regs;
ASSERT_TRUE(this->section_->GetCfaLocationInfo(0x100, &fde, &loc_regs, ARCH_UNKNOWN));
@@ -543,7 +546,7 @@ TYPED_TEST_P(DwarfSectionImplTest, GetCfaLocationInfo_cie_cached) {
DwarfLocations cie_loc_regs;
cie_loc_regs[6] = DwarfLocation{DWARF_LOCATION_REGISTER, {4, 0}};
this->section_->FakeSetCachedCieLocRegs(0x8000, cie_loc_regs);
- this->memory_.SetMemory(0x6000, std::vector<uint8_t>{0x09, 0x04, 0x03});
+ this->fake_memory_->SetMemory(0x6000, std::vector<uint8_t>{0x09, 0x04, 0x03});
DwarfLocations loc_regs;
ASSERT_TRUE(this->section_->GetCfaLocationInfo(0x100, &fde, &loc_regs, ARCH_UNKNOWN));
@@ -569,8 +572,8 @@ TYPED_TEST_P(DwarfSectionImplTest, Log) {
fde.cfa_instructions_offset = 0x6000;
fde.cfa_instructions_end = 0x6001;
- this->memory_.SetMemory(0x5000, std::vector<uint8_t>{0x00});
- this->memory_.SetMemory(0x6000, std::vector<uint8_t>{0xc2});
+ this->fake_memory_->SetMemory(0x5000, std::vector<uint8_t>{0x00});
+ this->fake_memory_->SetMemory(0x6000, std::vector<uint8_t>{0xc2});
ASSERT_TRUE(this->section_->Log(2, 0x1000, &fde, ARCH_UNKNOWN));
ASSERT_EQ(
diff --git a/libunwindstack/tests/DwarfSectionTest.cpp b/libunwindstack/tests/DwarfSectionTest.cpp
index bd801aa..4d82cb5 100644
--- a/libunwindstack/tests/DwarfSectionTest.cpp
+++ b/libunwindstack/tests/DwarfSectionTest.cpp
@@ -16,6 +16,9 @@
#include <stdint.h>
+#include <memory>
+#include <vector>
+
#include <gmock/gmock.h>
#include <gtest/gtest.h>
@@ -30,7 +33,7 @@ namespace unwindstack {
class MockDwarfSection : public DwarfSection {
public:
- MockDwarfSection(Memory* memory) : DwarfSection(memory) {}
+ MockDwarfSection(std::shared_ptr<Memory>& memory) : DwarfSection(memory) {}
virtual ~MockDwarfSection() = default;
MOCK_METHOD(bool, Init, (const SectionInfo&), (override));
@@ -56,9 +59,11 @@ class MockDwarfSection : public DwarfSection {
class DwarfSectionTest : public ::testing::Test {
protected:
- void SetUp() override { section_.reset(new MockDwarfSection(&memory_)); }
+ void SetUp() override {
+ std::shared_ptr<Memory> memory(new MemoryFake);
+ section_.reset(new MockDwarfSection(memory));
+ }
- MemoryFake memory_;
std::unique_ptr<MockDwarfSection> section_;
static RegsFake regs_;
};
diff --git a/libunwindstack/tests/ElfFake.h b/libunwindstack/tests/ElfFake.h
index 4ef8363..6286f08 100644
--- a/libunwindstack/tests/ElfFake.h
+++ b/libunwindstack/tests/ElfFake.h
@@ -19,6 +19,7 @@
#include <stdint.h>
#include <deque>
+#include <memory>
#include <string>
#include <unordered_map>
@@ -48,7 +49,7 @@ struct FunctionData {
class ElfFake : public Elf {
public:
- ElfFake(Memory* memory) : Elf(memory) { valid_ = true; }
+ ElfFake(std::shared_ptr<Memory>& memory) : Elf(memory) { valid_ = true; }
virtual ~ElfFake() = default;
void FakeSetValid(bool valid) { valid_ = valid; }
@@ -65,7 +66,7 @@ class ElfFake : public Elf {
class ElfInterfaceFake : public ElfInterface {
public:
- ElfInterfaceFake(Memory* memory) : ElfInterface(memory) {}
+ ElfInterfaceFake(std::shared_ptr<Memory>& memory) : ElfInterface(memory) {}
virtual ~ElfInterfaceFake() = default;
bool Init(int64_t*) override { return false; }
@@ -121,7 +122,7 @@ class ElfInterfaceFake : public ElfInterface {
class ElfInterface32Fake : public ElfInterface32 {
public:
- ElfInterface32Fake(Memory* memory) : ElfInterface32(memory) {}
+ ElfInterface32Fake(std::shared_ptr<Memory>& memory) : ElfInterface32(memory) {}
virtual ~ElfInterface32Fake() = default;
void FakeSetEhFrameInfo(const SectionInfo& info) { eh_frame_info_ = info; }
@@ -130,7 +131,7 @@ class ElfInterface32Fake : public ElfInterface32 {
class ElfInterface64Fake : public ElfInterface64 {
public:
- ElfInterface64Fake(Memory* memory) : ElfInterface64(memory) {}
+ ElfInterface64Fake(std::shared_ptr<Memory>& memory) : ElfInterface64(memory) {}
virtual ~ElfInterface64Fake() = default;
void FakeSetEhFrameInfo(const SectionInfo& info) { eh_frame_info_ = info; }
@@ -139,7 +140,7 @@ class ElfInterface64Fake : public ElfInterface64 {
class ElfInterfaceArmFake : public ElfInterfaceArm {
public:
- ElfInterfaceArmFake(Memory* memory) : ElfInterfaceArm(memory) {}
+ ElfInterfaceArmFake(std::shared_ptr<Memory>& memory) : ElfInterfaceArm(memory) {}
virtual ~ElfInterfaceArmFake() = default;
void FakeSetStartOffset(uint64_t offset) { start_offset_ = offset; }
diff --git a/libunwindstack/tests/ElfInterfaceArmTest.cpp b/libunwindstack/tests/ElfInterfaceArmTest.cpp
index ee70cc0..62d7a0e 100644
--- a/libunwindstack/tests/ElfInterfaceArmTest.cpp
+++ b/libunwindstack/tests/ElfInterfaceArmTest.cpp
@@ -18,6 +18,7 @@
#include <gtest/gtest.h>
+#include <memory>
#include <vector>
#include <unwindstack/MachineArm.h>
@@ -33,33 +34,35 @@ namespace unwindstack {
class ElfInterfaceArmTest : public ::testing::Test {
protected:
void SetUp() override {
- memory_.Clear();
+ fake_memory_ = new MemoryFake;
+ memory_.reset(fake_memory_);
process_memory_.Clear();
}
- MemoryFake memory_;
+ std::shared_ptr<Memory> memory_;
+ MemoryFake* fake_memory_;
MemoryFake process_memory_;
};
TEST_F(ElfInterfaceArmTest, GetPrel32Addr) {
- ElfInterfaceArmFake interface(&memory_);
- memory_.SetData32(0x1000, 0x230000);
+ ElfInterfaceArmFake interface(memory_);
+ fake_memory_->SetData32(0x1000, 0x230000);
uint32_t value;
ASSERT_TRUE(interface.GetPrel31Addr(0x1000, &value));
ASSERT_EQ(0x231000U, value);
- memory_.SetData32(0x1000, 0x80001000);
+ fake_memory_->SetData32(0x1000, 0x80001000);
ASSERT_TRUE(interface.GetPrel31Addr(0x1000, &value));
ASSERT_EQ(0x2000U, value);
- memory_.SetData32(0x1000, 0x70001000);
+ fake_memory_->SetData32(0x1000, 0x70001000);
ASSERT_TRUE(interface.GetPrel31Addr(0x1000, &value));
ASSERT_EQ(0xf0002000U, value);
}
TEST_F(ElfInterfaceArmTest, FindEntry_start_zero) {
- ElfInterfaceArmFake interface(&memory_);
+ ElfInterfaceArmFake interface(memory_);
interface.FakeSetStartOffset(0);
interface.FakeSetTotalEntries(10);
@@ -68,7 +71,7 @@ TEST_F(ElfInterfaceArmTest, FindEntry_start_zero) {
}
TEST_F(ElfInterfaceArmTest, FindEntry_no_entries) {
- ElfInterfaceArmFake interface(&memory_);
+ ElfInterfaceArmFake interface(memory_);
interface.FakeSetStartOffset(0x100);
interface.FakeSetTotalEntries(0);
@@ -77,7 +80,7 @@ TEST_F(ElfInterfaceArmTest, FindEntry_no_entries) {
}
TEST_F(ElfInterfaceArmTest, FindEntry_no_valid_memory) {
- ElfInterfaceArmFake interface(&memory_);
+ ElfInterfaceArmFake interface(memory_);
interface.FakeSetStartOffset(0x100);
interface.FakeSetTotalEntries(2);
@@ -86,20 +89,20 @@ TEST_F(ElfInterfaceArmTest, FindEntry_no_valid_memory) {
}
TEST_F(ElfInterfaceArmTest, FindEntry_ip_before_first) {
- ElfInterfaceArmFake interface(&memory_);
+ ElfInterfaceArmFake interface(memory_);
interface.FakeSetStartOffset(0x1000);
interface.FakeSetTotalEntries(1);
- memory_.SetData32(0x1000, 0x6000);
+ fake_memory_->SetData32(0x1000, 0x6000);
uint64_t entry_offset;
ASSERT_FALSE(interface.FindEntry(0x1000, &entry_offset));
}
TEST_F(ElfInterfaceArmTest, FindEntry_single_entry_negative_value) {
- ElfInterfaceArmFake interface(&memory_);
+ ElfInterfaceArmFake interface(memory_);
interface.FakeSetStartOffset(0x8000);
interface.FakeSetTotalEntries(1);
- memory_.SetData32(0x8000, 0x7fffff00);
+ fake_memory_->SetData32(0x8000, 0x7fffff00);
uint64_t entry_offset;
ASSERT_TRUE(interface.FindEntry(0x7ff0, &entry_offset));
@@ -107,11 +110,11 @@ TEST_F(ElfInterfaceArmTest, FindEntry_single_entry_negative_value) {
}
TEST_F(ElfInterfaceArmTest, FindEntry_two_entries) {
- ElfInterfaceArmFake interface(&memory_);
+ ElfInterfaceArmFake interface(memory_);
interface.FakeSetStartOffset(0x1000);
interface.FakeSetTotalEntries(2);
- memory_.SetData32(0x1000, 0x6000);
- memory_.SetData32(0x1008, 0x7000);
+ fake_memory_->SetData32(0x1000, 0x6000);
+ fake_memory_->SetData32(0x1008, 0x7000);
uint64_t entry_offset;
ASSERT_TRUE(interface.FindEntry(0x7000, &entry_offset));
@@ -119,10 +122,10 @@ TEST_F(ElfInterfaceArmTest, FindEntry_two_entries) {
}
TEST_F(ElfInterfaceArmTest, FindEntry_last_check_single_entry) {
- ElfInterfaceArmFake interface(&memory_);
+ ElfInterfaceArmFake interface(memory_);
interface.FakeSetStartOffset(0x1000);
interface.FakeSetTotalEntries(1);
- memory_.SetData32(0x1000, 0x6000);
+ fake_memory_->SetData32(0x1000, 0x6000);
uint64_t entry_offset;
ASSERT_TRUE(interface.FindEntry(0x7000, &entry_offset));
@@ -130,17 +133,17 @@ TEST_F(ElfInterfaceArmTest, FindEntry_last_check_single_entry) {
// To guarantee that we are using the cache on the second run,
// set the memory to a different value.
- memory_.SetData32(0x1000, 0x8000);
+ fake_memory_->SetData32(0x1000, 0x8000);
ASSERT_TRUE(interface.FindEntry(0x7004, &entry_offset));
ASSERT_EQ(0x1000U, entry_offset);
}
TEST_F(ElfInterfaceArmTest, FindEntry_last_check_multiple_entries) {
- ElfInterfaceArmFake interface(&memory_);
+ ElfInterfaceArmFake interface(memory_);
interface.FakeSetStartOffset(0x1000);
interface.FakeSetTotalEntries(2);
- memory_.SetData32(0x1000, 0x6000);
- memory_.SetData32(0x1008, 0x8000);
+ fake_memory_->SetData32(0x1000, 0x6000);
+ fake_memory_->SetData32(0x1008, 0x8000);
uint64_t entry_offset;
ASSERT_TRUE(interface.FindEntry(0x9008, &entry_offset));
@@ -148,20 +151,20 @@ TEST_F(ElfInterfaceArmTest, FindEntry_last_check_multiple_entries) {
// To guarantee that we are using the cache on the second run,
// set the memory to a different value.
- memory_.SetData32(0x1000, 0x16000);
- memory_.SetData32(0x1008, 0x18000);
+ fake_memory_->SetData32(0x1000, 0x16000);
+ fake_memory_->SetData32(0x1008, 0x18000);
ASSERT_TRUE(interface.FindEntry(0x9100, &entry_offset));
ASSERT_EQ(0x1008U, entry_offset);
}
TEST_F(ElfInterfaceArmTest, FindEntry_multiple_entries_even) {
- ElfInterfaceArmFake interface(&memory_);
+ ElfInterfaceArmFake interface(memory_);
interface.FakeSetStartOffset(0x1000);
interface.FakeSetTotalEntries(4);
- memory_.SetData32(0x1000, 0x6000);
- memory_.SetData32(0x1008, 0x7000);
- memory_.SetData32(0x1010, 0x8000);
- memory_.SetData32(0x1018, 0x9000);
+ fake_memory_->SetData32(0x1000, 0x6000);
+ fake_memory_->SetData32(0x1008, 0x7000);
+ fake_memory_->SetData32(0x1010, 0x8000);
+ fake_memory_->SetData32(0x1018, 0x9000);
uint64_t entry_offset;
ASSERT_TRUE(interface.FindEntry(0x9100, &entry_offset));
@@ -169,23 +172,23 @@ TEST_F(ElfInterfaceArmTest, FindEntry_multiple_entries_even) {
// To guarantee that we are using the cache on the second run,
// set the memory to a different value.
- memory_.SetData32(0x1000, 0x16000);
- memory_.SetData32(0x1008, 0x17000);
- memory_.SetData32(0x1010, 0x18000);
- memory_.SetData32(0x1018, 0x19000);
+ fake_memory_->SetData32(0x1000, 0x16000);
+ fake_memory_->SetData32(0x1008, 0x17000);
+ fake_memory_->SetData32(0x1010, 0x18000);
+ fake_memory_->SetData32(0x1018, 0x19000);
ASSERT_TRUE(interface.FindEntry(0x9100, &entry_offset));
ASSERT_EQ(0x1010U, entry_offset);
}
TEST_F(ElfInterfaceArmTest, FindEntry_multiple_entries_odd) {
- ElfInterfaceArmFake interface(&memory_);
+ ElfInterfaceArmFake interface(memory_);
interface.FakeSetStartOffset(0x1000);
interface.FakeSetTotalEntries(5);
- memory_.SetData32(0x1000, 0x5000);
- memory_.SetData32(0x1008, 0x6000);
- memory_.SetData32(0x1010, 0x7000);
- memory_.SetData32(0x1018, 0x8000);
- memory_.SetData32(0x1020, 0x9000);
+ fake_memory_->SetData32(0x1000, 0x5000);
+ fake_memory_->SetData32(0x1008, 0x6000);
+ fake_memory_->SetData32(0x1010, 0x7000);
+ fake_memory_->SetData32(0x1018, 0x8000);
+ fake_memory_->SetData32(0x1020, 0x9000);
uint64_t entry_offset;
ASSERT_TRUE(interface.FindEntry(0x8100, &entry_offset));
@@ -193,24 +196,24 @@ TEST_F(ElfInterfaceArmTest, FindEntry_multiple_entries_odd) {
// To guarantee that we are using the cache on the second run,
// set the memory to a different value.
- memory_.SetData32(0x1000, 0x15000);
- memory_.SetData32(0x1008, 0x16000);
- memory_.SetData32(0x1010, 0x17000);
- memory_.SetData32(0x1018, 0x18000);
- memory_.SetData32(0x1020, 0x19000);
+ fake_memory_->SetData32(0x1000, 0x15000);
+ fake_memory_->SetData32(0x1008, 0x16000);
+ fake_memory_->SetData32(0x1010, 0x17000);
+ fake_memory_->SetData32(0x1018, 0x18000);
+ fake_memory_->SetData32(0x1020, 0x19000);
ASSERT_TRUE(interface.FindEntry(0x8100, &entry_offset));
ASSERT_EQ(0x1010U, entry_offset);
}
TEST_F(ElfInterfaceArmTest, iterate) {
- ElfInterfaceArmFake interface(&memory_);
+ ElfInterfaceArmFake interface(memory_);
interface.FakeSetStartOffset(0x1000);
interface.FakeSetTotalEntries(5);
- memory_.SetData32(0x1000, 0x5000);
- memory_.SetData32(0x1008, 0x6000);
- memory_.SetData32(0x1010, 0x7000);
- memory_.SetData32(0x1018, 0x8000);
- memory_.SetData32(0x1020, 0x9000);
+ fake_memory_->SetData32(0x1000, 0x5000);
+ fake_memory_->SetData32(0x1008, 0x6000);
+ fake_memory_->SetData32(0x1010, 0x7000);
+ fake_memory_->SetData32(0x1018, 0x8000);
+ fake_memory_->SetData32(0x1020, 0x9000);
std::vector<uint32_t> entries;
for (auto addr : interface) {
@@ -224,11 +227,11 @@ TEST_F(ElfInterfaceArmTest, iterate) {
ASSERT_EQ(0xa020U, entries[4]);
// Make sure the iterate cached the entries.
- memory_.SetData32(0x1000, 0x11000);
- memory_.SetData32(0x1008, 0x12000);
- memory_.SetData32(0x1010, 0x13000);
- memory_.SetData32(0x1018, 0x14000);
- memory_.SetData32(0x1020, 0x15000);
+ fake_memory_->SetData32(0x1000, 0x11000);
+ fake_memory_->SetData32(0x1008, 0x12000);
+ fake_memory_->SetData32(0x1010, 0x13000);
+ fake_memory_->SetData32(0x1018, 0x14000);
+ fake_memory_->SetData32(0x1020, 0x15000);
entries.clear();
for (auto addr : interface) {
@@ -243,7 +246,7 @@ TEST_F(ElfInterfaceArmTest, iterate) {
}
TEST_F(ElfInterfaceArmTest, HandleUnknownType_arm_exidx) {
- ElfInterfaceArmFake interface(&memory_);
+ ElfInterfaceArmFake interface(memory_);
interface.FakeSetStartOffset(0x1000);
interface.FakeSetTotalEntries(100);
@@ -260,7 +263,7 @@ TEST_F(ElfInterfaceArmTest, HandleUnknownType_arm_exidx) {
}
TEST_F(ElfInterfaceArmTest, StepExidx) {
- ElfInterfaceArmFake interface(&memory_);
+ ElfInterfaceArmFake interface(memory_);
// FindEntry fails.
bool finished;
@@ -270,8 +273,8 @@ TEST_F(ElfInterfaceArmTest, StepExidx) {
// ExtractEntry should fail.
interface.FakeSetStartOffset(0x1000);
interface.FakeSetTotalEntries(2);
- memory_.SetData32(0x1000, 0x6000);
- memory_.SetData32(0x1008, 0x8000);
+ fake_memory_->SetData32(0x1000, 0x6000);
+ fake_memory_->SetData32(0x1008, 0x8000);
RegsArm regs;
regs[ARM_REG_SP] = 0x1000;
@@ -283,12 +286,12 @@ TEST_F(ElfInterfaceArmTest, StepExidx) {
EXPECT_EQ(0x1004U, interface.LastErrorAddress());
// Eval should fail.
- memory_.SetData32(0x1004, 0x81000000);
+ fake_memory_->SetData32(0x1004, 0x81000000);
ASSERT_FALSE(interface.StepExidx(0x7000, &regs, &process_memory_, &finished));
EXPECT_EQ(ERROR_UNWIND_INFO, interface.LastErrorCode());
// Everything should pass.
- memory_.SetData32(0x1004, 0x80b0b0b0);
+ fake_memory_->SetData32(0x1004, 0x80b0b0b0);
ASSERT_TRUE(interface.StepExidx(0x7000, &regs, &process_memory_, &finished));
EXPECT_EQ(ERROR_UNWIND_INFO, interface.LastErrorCode());
ASSERT_FALSE(finished);
@@ -309,13 +312,13 @@ TEST_F(ElfInterfaceArmTest, StepExidx) {
}
TEST_F(ElfInterfaceArmTest, StepExidx_pc_set) {
- ElfInterfaceArmFake interface(&memory_);
+ ElfInterfaceArmFake interface(memory_);
interface.FakeSetStartOffset(0x1000);
interface.FakeSetTotalEntries(2);
- memory_.SetData32(0x1000, 0x6000);
- memory_.SetData32(0x1004, 0x808800b0);
- memory_.SetData32(0x1008, 0x8000);
+ fake_memory_->SetData32(0x1000, 0x6000);
+ fake_memory_->SetData32(0x1004, 0x808800b0);
+ fake_memory_->SetData32(0x1008, 0x8000);
process_memory_.SetData32(0x10000, 0x10);
RegsArm regs;
@@ -336,12 +339,12 @@ TEST_F(ElfInterfaceArmTest, StepExidx_pc_set) {
}
TEST_F(ElfInterfaceArmTest, StepExidx_cant_unwind) {
- ElfInterfaceArmFake interface(&memory_);
+ ElfInterfaceArmFake interface(memory_);
interface.FakeSetStartOffset(0x1000);
interface.FakeSetTotalEntries(1);
- memory_.SetData32(0x1000, 0x6000);
- memory_.SetData32(0x1004, 1);
+ fake_memory_->SetData32(0x1000, 0x6000);
+ fake_memory_->SetData32(0x1004, 1);
RegsArm regs;
regs[ARM_REG_SP] = 0x10000;
@@ -359,12 +362,12 @@ TEST_F(ElfInterfaceArmTest, StepExidx_cant_unwind) {
}
TEST_F(ElfInterfaceArmTest, StepExidx_refuse_unwind) {
- ElfInterfaceArmFake interface(&memory_);
+ ElfInterfaceArmFake interface(memory_);
interface.FakeSetStartOffset(0x1000);
interface.FakeSetTotalEntries(1);
- memory_.SetData32(0x1000, 0x6000);
- memory_.SetData32(0x1004, 0x808000b0);
+ fake_memory_->SetData32(0x1000, 0x6000);
+ fake_memory_->SetData32(0x1004, 0x808000b0);
RegsArm regs;
regs[ARM_REG_SP] = 0x10000;
@@ -382,13 +385,13 @@ TEST_F(ElfInterfaceArmTest, StepExidx_refuse_unwind) {
}
TEST_F(ElfInterfaceArmTest, StepExidx_pc_zero) {
- ElfInterfaceArmFake interface(&memory_);
+ ElfInterfaceArmFake interface(memory_);
interface.FakeSetStartOffset(0x1000);
interface.FakeSetTotalEntries(1);
- memory_.SetData32(0x1000, 0x6000);
+ fake_memory_->SetData32(0x1000, 0x6000);
// Set the pc using a pop r15 command.
- memory_.SetData32(0x1004, 0x808800b0);
+ fake_memory_->SetData32(0x1004, 0x808800b0);
// pc value of zero.
process_memory_.SetData32(0x10000, 0);
@@ -406,7 +409,7 @@ TEST_F(ElfInterfaceArmTest, StepExidx_pc_zero) {
ASSERT_EQ(0U, regs.pc());
// Now set the pc from the lr register (pop r14).
- memory_.SetData32(0x1004, 0x808400b0);
+ fake_memory_->SetData32(0x1004, 0x808400b0);
regs[ARM_REG_SP] = 0x10000;
regs[ARM_REG_LR] = 0x20000;
diff --git a/libunwindstack/tests/ElfInterfaceTest.cpp b/libunwindstack/tests/ElfInterfaceTest.cpp
index ea8c166..68a2e8d 100644
--- a/libunwindstack/tests/ElfInterfaceTest.cpp
+++ b/libunwindstack/tests/ElfInterfaceTest.cpp
@@ -49,11 +49,12 @@ namespace unwindstack {
class ElfInterfaceTest : public ::testing::Test {
protected:
void SetUp() override {
- memory_.Clear();
+ fake_memory_ = new MemoryFake;
+ memory_.reset(fake_memory_);
}
void SetStringMemory(uint64_t offset, const char* string) {
- memory_.SetMemory(offset, string, strlen(string) + 1);
+ fake_memory_->SetMemory(offset, string, strlen(string) + 1);
}
template <typename Ehdr, typename Phdr, typename Dyn, typename ElfInterfaceType>
@@ -160,7 +161,8 @@ class ElfInterfaceTest : public ::testing::Test {
template <typename Ehdr, typename Phdr, typename ElfInterfaceType>
void CheckLoadBiasInFirstExecPhdr(uint64_t offset, uint64_t vaddr, int64_t load_bias);
- MemoryFake memory_;
+ MemoryFake* fake_memory_;
+ std::shared_ptr<Memory> memory_;
};
template <typename Sym>
@@ -173,19 +175,19 @@ void ElfInterfaceTest::InitSym(uint64_t offset, uint32_t value, uint32_t size, u
sym.st_name = name_offset;
sym.st_shndx = SHN_COMMON;
- memory_.SetMemory(offset, &sym, sizeof(sym));
- memory_.SetMemory(sym_offset + name_offset, name, strlen(name) + 1);
+ fake_memory_->SetMemory(offset, &sym, sizeof(sym));
+ fake_memory_->SetMemory(sym_offset + name_offset, name, strlen(name) + 1);
}
template <typename Ehdr, typename Phdr, typename Dyn, typename ElfInterfaceType>
void ElfInterfaceTest::SinglePtLoad() {
- std::unique_ptr<ElfInterface> elf(new ElfInterfaceType(&memory_));
+ std::unique_ptr<ElfInterface> elf(new ElfInterfaceType(memory_));
Ehdr ehdr = {};
ehdr.e_phoff = 0x100;
ehdr.e_phnum = 1;
ehdr.e_phentsize = sizeof(Phdr);
- memory_.SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
Phdr phdr = {};
phdr.p_type = PT_LOAD;
@@ -193,7 +195,7 @@ void ElfInterfaceTest::SinglePtLoad() {
phdr.p_memsz = 0x10000;
phdr.p_flags = PF_R | PF_X;
phdr.p_align = 0x1000;
- memory_.SetMemory(0x100, &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(0x100, &phdr, sizeof(phdr));
int64_t load_bias = 0;
ASSERT_TRUE(elf->Init(&load_bias));
@@ -217,13 +219,13 @@ TEST_F(ElfInterfaceTest, single_pt_load_64) {
template <typename Ehdr, typename Phdr, typename Dyn, typename ElfInterfaceType>
void ElfInterfaceTest::MultipleExecutablePtLoads() {
- std::unique_ptr<ElfInterface> elf(new ElfInterfaceType(&memory_));
+ std::unique_ptr<ElfInterface> elf(new ElfInterfaceType(memory_));
Ehdr ehdr = {};
ehdr.e_phoff = 0x100;
ehdr.e_phnum = 3;
ehdr.e_phentsize = sizeof(Phdr);
- memory_.SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
Phdr phdr = {};
phdr.p_type = PT_LOAD;
@@ -231,7 +233,7 @@ void ElfInterfaceTest::MultipleExecutablePtLoads() {
phdr.p_memsz = 0x10000;
phdr.p_flags = PF_R | PF_X;
phdr.p_align = 0x1000;
- memory_.SetMemory(0x100, &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(0x100, &phdr, sizeof(phdr));
memset(&phdr, 0, sizeof(phdr));
phdr.p_type = PT_LOAD;
@@ -240,7 +242,7 @@ void ElfInterfaceTest::MultipleExecutablePtLoads() {
phdr.p_memsz = 0x10001;
phdr.p_flags = PF_R | PF_X;
phdr.p_align = 0x1001;
- memory_.SetMemory(0x100 + sizeof(phdr), &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(0x100 + sizeof(phdr), &phdr, sizeof(phdr));
memset(&phdr, 0, sizeof(phdr));
phdr.p_type = PT_LOAD;
@@ -249,7 +251,7 @@ void ElfInterfaceTest::MultipleExecutablePtLoads() {
phdr.p_memsz = 0x10002;
phdr.p_flags = PF_R | PF_X;
phdr.p_align = 0x1002;
- memory_.SetMemory(0x100 + 2 * sizeof(phdr), &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(0x100 + 2 * sizeof(phdr), &phdr, sizeof(phdr));
int64_t load_bias = 0;
ASSERT_TRUE(elf->Init(&load_bias));
@@ -284,13 +286,13 @@ TEST_F(ElfInterfaceTest, multiple_executable_pt_loads_64) {
template <typename Ehdr, typename Phdr, typename Dyn, typename ElfInterfaceType>
void ElfInterfaceTest::MultipleExecutablePtLoadsIncrementsNotSizeOfPhdr() {
- std::unique_ptr<ElfInterface> elf(new ElfInterfaceType(&memory_));
+ std::unique_ptr<ElfInterface> elf(new ElfInterfaceType(memory_));
Ehdr ehdr = {};
ehdr.e_phoff = 0x100;
ehdr.e_phnum = 3;
ehdr.e_phentsize = sizeof(Phdr) + 100;
- memory_.SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
Phdr phdr = {};
phdr.p_type = PT_LOAD;
@@ -298,7 +300,7 @@ void ElfInterfaceTest::MultipleExecutablePtLoadsIncrementsNotSizeOfPhdr() {
phdr.p_memsz = 0x10000;
phdr.p_flags = PF_R | PF_X;
phdr.p_align = 0x1000;
- memory_.SetMemory(0x100, &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(0x100, &phdr, sizeof(phdr));
memset(&phdr, 0, sizeof(phdr));
phdr.p_type = PT_LOAD;
@@ -307,7 +309,7 @@ void ElfInterfaceTest::MultipleExecutablePtLoadsIncrementsNotSizeOfPhdr() {
phdr.p_memsz = 0x10001;
phdr.p_flags = PF_R | PF_X;
phdr.p_align = 0x1001;
- memory_.SetMemory(0x100 + sizeof(phdr) + 100, &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(0x100 + sizeof(phdr) + 100, &phdr, sizeof(phdr));
memset(&phdr, 0, sizeof(phdr));
phdr.p_type = PT_LOAD;
@@ -316,7 +318,7 @@ void ElfInterfaceTest::MultipleExecutablePtLoadsIncrementsNotSizeOfPhdr() {
phdr.p_memsz = 0x10002;
phdr.p_flags = PF_R | PF_X;
phdr.p_align = 0x1002;
- memory_.SetMemory(0x100 + 2 * (sizeof(phdr) + 100), &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(0x100 + 2 * (sizeof(phdr) + 100), &phdr, sizeof(phdr));
int64_t load_bias = 0;
ASSERT_TRUE(elf->Init(&load_bias));
@@ -353,13 +355,13 @@ TEST_F(ElfInterfaceTest, multiple_executable_pt_loads_increments_not_size_of_phd
template <typename Ehdr, typename Phdr, typename Dyn, typename ElfInterfaceType>
void ElfInterfaceTest::NonExecutablePtLoads() {
- std::unique_ptr<ElfInterface> elf(new ElfInterfaceType(&memory_));
+ std::unique_ptr<ElfInterface> elf(new ElfInterfaceType(memory_));
Ehdr ehdr = {};
ehdr.e_phoff = 0x100;
ehdr.e_phnum = 3;
ehdr.e_phentsize = sizeof(Phdr);
- memory_.SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
Phdr phdr = {};
phdr.p_type = PT_LOAD;
@@ -367,7 +369,7 @@ void ElfInterfaceTest::NonExecutablePtLoads() {
phdr.p_memsz = 0x10000;
phdr.p_flags = PF_R;
phdr.p_align = 0x1000;
- memory_.SetMemory(0x100, &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(0x100, &phdr, sizeof(phdr));
memset(&phdr, 0, sizeof(phdr));
phdr.p_type = PT_LOAD;
@@ -376,7 +378,7 @@ void ElfInterfaceTest::NonExecutablePtLoads() {
phdr.p_memsz = 0x10001;
phdr.p_flags = PF_R | PF_X;
phdr.p_align = 0x1001;
- memory_.SetMemory(0x100 + sizeof(phdr), &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(0x100 + sizeof(phdr), &phdr, sizeof(phdr));
memset(&phdr, 0, sizeof(phdr));
phdr.p_type = PT_LOAD;
@@ -385,7 +387,7 @@ void ElfInterfaceTest::NonExecutablePtLoads() {
phdr.p_memsz = 0x10002;
phdr.p_flags = PF_R;
phdr.p_align = 0x1002;
- memory_.SetMemory(0x100 + 2 * sizeof(phdr), &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(0x100 + 2 * sizeof(phdr), &phdr, sizeof(phdr));
int64_t load_bias = 0;
ASSERT_TRUE(elf->Init(&load_bias));
@@ -410,13 +412,13 @@ TEST_F(ElfInterfaceTest, non_executable_pt_loads_64) {
template <typename Ehdr, typename Phdr, typename Dyn, typename ElfInterfaceType>
void ElfInterfaceTest::ManyPhdrs() {
- std::unique_ptr<ElfInterface> elf(new ElfInterfaceType(&memory_));
+ std::unique_ptr<ElfInterface> elf(new ElfInterfaceType(memory_));
Ehdr ehdr = {};
ehdr.e_phoff = 0x100;
ehdr.e_phnum = 7;
ehdr.e_phentsize = sizeof(Phdr);
- memory_.SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
uint64_t phdr_offset = 0x100;
@@ -426,37 +428,37 @@ void ElfInterfaceTest::ManyPhdrs() {
phdr.p_memsz = 0x10000;
phdr.p_flags = PF_R | PF_X;
phdr.p_align = 0x1000;
- memory_.SetMemory(phdr_offset, &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(phdr_offset, &phdr, sizeof(phdr));
phdr_offset += sizeof(phdr);
memset(&phdr, 0, sizeof(phdr));
phdr.p_type = PT_GNU_EH_FRAME;
- memory_.SetMemory(phdr_offset, &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(phdr_offset, &phdr, sizeof(phdr));
phdr_offset += sizeof(phdr);
memset(&phdr, 0, sizeof(phdr));
phdr.p_type = PT_DYNAMIC;
- memory_.SetMemory(phdr_offset, &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(phdr_offset, &phdr, sizeof(phdr));
phdr_offset += sizeof(phdr);
memset(&phdr, 0, sizeof(phdr));
phdr.p_type = PT_INTERP;
- memory_.SetMemory(phdr_offset, &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(phdr_offset, &phdr, sizeof(phdr));
phdr_offset += sizeof(phdr);
memset(&phdr, 0, sizeof(phdr));
phdr.p_type = PT_NOTE;
- memory_.SetMemory(phdr_offset, &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(phdr_offset, &phdr, sizeof(phdr));
phdr_offset += sizeof(phdr);
memset(&phdr, 0, sizeof(phdr));
phdr.p_type = PT_SHLIB;
- memory_.SetMemory(phdr_offset, &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(phdr_offset, &phdr, sizeof(phdr));
phdr_offset += sizeof(phdr);
memset(&phdr, 0, sizeof(phdr));
phdr.p_type = PT_GNU_EH_FRAME;
- memory_.SetMemory(phdr_offset, &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(phdr_offset, &phdr, sizeof(phdr));
int64_t load_bias = 0;
ASSERT_TRUE(elf->Init(&load_bias));
@@ -480,23 +482,23 @@ TEST_F(ElfInterfaceTest, many_phdrs_64) {
}
TEST_F(ElfInterfaceTest, arm32) {
- ElfInterfaceArm elf_arm(&memory_);
+ ElfInterfaceArm elf_arm(memory_);
Elf32_Ehdr ehdr = {};
ehdr.e_phoff = 0x100;
ehdr.e_phnum = 1;
ehdr.e_phentsize = sizeof(Elf32_Phdr);
- memory_.SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
Elf32_Phdr phdr = {};
phdr.p_type = PT_ARM_EXIDX;
phdr.p_offset = 0x2000;
phdr.p_filesz = 16;
- memory_.SetMemory(0x100, &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(0x100, &phdr, sizeof(phdr));
// Add arm exidx entries.
- memory_.SetData32(0x2000, 0x1000);
- memory_.SetData32(0x2008, 0x1000);
+ fake_memory_->SetData32(0x2000, 0x1000);
+ fake_memory_->SetData32(0x2008, 0x1000);
int64_t load_bias = 0;
ASSERT_TRUE(elf_arm.Init(&load_bias));
@@ -523,7 +525,7 @@ void ElfInterfaceTest::SonameInit(SonameTestEnum test_type) {
ehdr.e_phoff = 0x100;
ehdr.e_phnum = 1;
ehdr.e_phentsize = sizeof(Phdr);
- memory_.SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
Shdr shdr = {};
shdr.sh_type = SHT_STRTAB;
@@ -533,20 +535,20 @@ void ElfInterfaceTest::SonameInit(SonameTestEnum test_type) {
shdr.sh_addr = 0x10100;
}
shdr.sh_offset = 0x10000;
- memory_.SetMemory(0x200 + sizeof(shdr), &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(0x200 + sizeof(shdr), &shdr, sizeof(shdr));
Phdr phdr = {};
phdr.p_type = PT_DYNAMIC;
phdr.p_offset = 0x2000;
phdr.p_memsz = sizeof(Dyn) * 3;
- memory_.SetMemory(0x100, &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(0x100, &phdr, sizeof(phdr));
uint64_t offset = 0x2000;
Dyn dyn;
dyn.d_tag = DT_STRTAB;
dyn.d_un.d_ptr = 0x10100;
- memory_.SetMemory(offset, &dyn, sizeof(dyn));
+ fake_memory_->SetMemory(offset, &dyn, sizeof(dyn));
offset += sizeof(dyn);
dyn.d_tag = DT_STRSZ;
@@ -555,29 +557,29 @@ void ElfInterfaceTest::SonameInit(SonameTestEnum test_type) {
} else {
dyn.d_un.d_val = 0x1000;
}
- memory_.SetMemory(offset, &dyn, sizeof(dyn));
+ fake_memory_->SetMemory(offset, &dyn, sizeof(dyn));
offset += sizeof(dyn);
if (test_type == SONAME_DTNULL_AFTER) {
dyn.d_tag = DT_NULL;
- memory_.SetMemory(offset, &dyn, sizeof(dyn));
+ fake_memory_->SetMemory(offset, &dyn, sizeof(dyn));
offset += sizeof(dyn);
}
dyn.d_tag = DT_SONAME;
dyn.d_un.d_val = 0x10;
- memory_.SetMemory(offset, &dyn, sizeof(dyn));
+ fake_memory_->SetMemory(offset, &dyn, sizeof(dyn));
offset += sizeof(dyn);
dyn.d_tag = DT_NULL;
- memory_.SetMemory(offset, &dyn, sizeof(dyn));
+ fake_memory_->SetMemory(offset, &dyn, sizeof(dyn));
SetStringMemory(0x10010, "fake_soname.so");
}
template <typename ElfInterfaceType>
void ElfInterfaceTest::Soname() {
- std::unique_ptr<ElfInterface> elf(new ElfInterfaceType(&memory_));
+ std::unique_ptr<ElfInterface> elf(new ElfInterfaceType(memory_));
int64_t load_bias = 0;
ASSERT_TRUE(elf->Init(&load_bias));
@@ -598,7 +600,7 @@ TEST_F(ElfInterfaceTest, soname_64) {
template <typename ElfInterfaceType>
void ElfInterfaceTest::SonameAfterDtNull() {
- std::unique_ptr<ElfInterface> elf(new ElfInterfaceType(&memory_));
+ std::unique_ptr<ElfInterface> elf(new ElfInterfaceType(memory_));
int64_t load_bias = 0;
ASSERT_TRUE(elf->Init(&load_bias));
@@ -619,7 +621,7 @@ TEST_F(ElfInterfaceTest, soname_after_dt_null_64) {
template <typename ElfInterfaceType>
void ElfInterfaceTest::SonameSize() {
- std::unique_ptr<ElfInterface> elf(new ElfInterfaceType(&memory_));
+ std::unique_ptr<ElfInterface> elf(new ElfInterfaceType(memory_));
int64_t load_bias = 0;
ASSERT_TRUE(elf->Init(&load_bias));
@@ -642,7 +644,7 @@ TEST_F(ElfInterfaceTest, soname_size_64) {
// STRTAB entry in the section headers.
template <typename ElfInterfaceType>
void ElfInterfaceTest::SonameMissingMap() {
- std::unique_ptr<ElfInterface> elf(new ElfInterfaceType(&memory_));
+ std::unique_ptr<ElfInterface> elf(new ElfInterfaceType(memory_));
int64_t load_bias = 0;
ASSERT_TRUE(elf->Init(&load_bias));
@@ -663,15 +665,15 @@ TEST_F(ElfInterfaceTest, soname_missing_map_64) {
template <typename ElfType>
void ElfInterfaceTest::InitHeadersEhFrameTest() {
- ElfType elf(&memory_);
+ ElfType elf(memory_);
elf.FakeSetEhFrameInfo(SectionInfo{.offset = 0x10000});
elf.FakeSetDebugFrameInfo(SectionInfo{});
- memory_.SetMemory(0x10000,
- std::vector<uint8_t>{0x1, DW_EH_PE_udata2, DW_EH_PE_udata2, DW_EH_PE_udata2});
- memory_.SetData32(0x10004, 0x500);
- memory_.SetData32(0x10008, 250);
+ fake_memory_->SetMemory(
+ 0x10000, std::vector<uint8_t>{0x1, DW_EH_PE_udata2, DW_EH_PE_udata2, DW_EH_PE_udata2});
+ fake_memory_->SetData32(0x10004, 0x500);
+ fake_memory_->SetData32(0x10008, 250);
elf.InitHeaders();
@@ -689,19 +691,19 @@ TEST_F(ElfInterfaceTest, init_headers_eh_frame_64) {
template <typename ElfType>
void ElfInterfaceTest::InitHeadersDebugFrame() {
- ElfType elf(&memory_);
+ ElfType elf(memory_);
elf.FakeSetEhFrameInfo(SectionInfo{});
elf.FakeSetDebugFrameInfo(SectionInfo{.offset = 0x5000, .size = 0x200});
- memory_.SetData32(0x5000, 0xfc);
- memory_.SetData32(0x5004, 0xffffffff);
- memory_.SetMemory(0x5008, std::vector<uint8_t>{1, '\0', 4, 8, 2});
+ fake_memory_->SetData32(0x5000, 0xfc);
+ fake_memory_->SetData32(0x5004, 0xffffffff);
+ fake_memory_->SetMemory(0x5008, std::vector<uint8_t>{1, '\0', 4, 8, 2});
- memory_.SetData32(0x5100, 0xfc);
- memory_.SetData32(0x5104, 0);
- memory_.SetData32(0x5108, 0x1500);
- memory_.SetData32(0x510c, 0x200);
+ fake_memory_->SetData32(0x5100, 0xfc);
+ fake_memory_->SetData32(0x5104, 0);
+ fake_memory_->SetData32(0x5108, 0x1500);
+ fake_memory_->SetData32(0x510c, 0x200);
elf.InitHeaders();
@@ -719,13 +721,13 @@ TEST_F(ElfInterfaceTest, init_headers_debug_frame_64) {
template <typename Ehdr, typename Phdr, typename ElfInterfaceType>
void ElfInterfaceTest::InitProgramHeadersMalformed() {
- std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(&memory_));
+ std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(memory_));
Ehdr ehdr = {};
ehdr.e_phoff = 0x100;
ehdr.e_phnum = 3;
ehdr.e_phentsize = sizeof(Phdr);
- memory_.SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
int64_t load_bias = 0;
ASSERT_TRUE(elf->Init(&load_bias));
@@ -742,13 +744,13 @@ TEST_F(ElfInterfaceTest, init_program_headers_malformed_64) {
template <typename Ehdr, typename Shdr, typename ElfInterfaceType>
void ElfInterfaceTest::InitSectionHeadersMalformed() {
- std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(&memory_));
+ std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(memory_));
Ehdr ehdr = {};
ehdr.e_shoff = 0x1000;
ehdr.e_shnum = 10;
ehdr.e_shentsize = sizeof(Shdr);
- memory_.SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
int64_t load_bias = 0;
ASSERT_TRUE(elf->Init(&load_bias));
@@ -765,7 +767,7 @@ TEST_F(ElfInterfaceTest, init_section_headers_malformed_64) {
template <typename Ehdr, typename Shdr, typename ElfInterfaceType>
void ElfInterfaceTest::InitSectionHeadersMalformedSymData() {
- std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(&memory_));
+ std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(memory_));
uint64_t offset = 0x1000;
@@ -773,7 +775,7 @@ void ElfInterfaceTest::InitSectionHeadersMalformedSymData() {
ehdr.e_shoff = offset;
ehdr.e_shnum = 5;
ehdr.e_shentsize = sizeof(Shdr);
- memory_.SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
offset += ehdr.e_shentsize;
@@ -784,7 +786,7 @@ void ElfInterfaceTest::InitSectionHeadersMalformedSymData() {
shdr.sh_offset = 0x5000;
shdr.sh_entsize = 0x100;
shdr.sh_size = shdr.sh_entsize * 10;
- memory_.SetMemory(offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(offset, &shdr, sizeof(shdr));
offset += ehdr.e_shentsize;
memset(&shdr, 0, sizeof(shdr));
@@ -794,7 +796,7 @@ void ElfInterfaceTest::InitSectionHeadersMalformedSymData() {
shdr.sh_offset = 0x6000;
shdr.sh_entsize = 0x100;
shdr.sh_size = shdr.sh_entsize * 10;
- memory_.SetMemory(offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(offset, &shdr, sizeof(shdr));
offset += ehdr.e_shentsize;
memset(&shdr, 0, sizeof(shdr));
@@ -804,7 +806,7 @@ void ElfInterfaceTest::InitSectionHeadersMalformedSymData() {
shdr.sh_offset = 0x6000;
shdr.sh_entsize = 0x100;
shdr.sh_size = shdr.sh_entsize * 10;
- memory_.SetMemory(offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(offset, &shdr, sizeof(shdr));
offset += ehdr.e_shentsize;
// The string data for the entries.
@@ -813,7 +815,7 @@ void ElfInterfaceTest::InitSectionHeadersMalformedSymData() {
shdr.sh_name = 0x20000;
shdr.sh_offset = 0xf000;
shdr.sh_size = 0x1000;
- memory_.SetMemory(offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(offset, &shdr, sizeof(shdr));
int64_t load_bias = 0;
ASSERT_TRUE(elf->Init(&load_bias));
@@ -838,7 +840,7 @@ TEST_F(ElfInterfaceTest, init_section_headers_malformed_symdata_64) {
template <typename Ehdr, typename Shdr, typename Sym, typename ElfInterfaceType>
void ElfInterfaceTest::InitSectionHeaders(uint64_t entry_size) {
- std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(&memory_));
+ std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(memory_));
uint64_t offset = 0x1000;
@@ -846,7 +848,7 @@ void ElfInterfaceTest::InitSectionHeaders(uint64_t entry_size) {
ehdr.e_shoff = offset;
ehdr.e_shnum = 5;
ehdr.e_shentsize = entry_size;
- memory_.SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
offset += ehdr.e_shentsize;
@@ -857,7 +859,7 @@ void ElfInterfaceTest::InitSectionHeaders(uint64_t entry_size) {
shdr.sh_offset = 0x5000;
shdr.sh_entsize = sizeof(Sym);
shdr.sh_size = shdr.sh_entsize * 10;
- memory_.SetMemory(offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(offset, &shdr, sizeof(shdr));
offset += ehdr.e_shentsize;
memset(&shdr, 0, sizeof(shdr));
@@ -867,13 +869,13 @@ void ElfInterfaceTest::InitSectionHeaders(uint64_t entry_size) {
shdr.sh_offset = 0x6000;
shdr.sh_entsize = sizeof(Sym);
shdr.sh_size = shdr.sh_entsize * 10;
- memory_.SetMemory(offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(offset, &shdr, sizeof(shdr));
offset += ehdr.e_shentsize;
memset(&shdr, 0, sizeof(shdr));
shdr.sh_type = SHT_PROGBITS;
shdr.sh_name = 0xa000;
- memory_.SetMemory(offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(offset, &shdr, sizeof(shdr));
offset += ehdr.e_shentsize;
// The string data for the entries.
@@ -882,7 +884,7 @@ void ElfInterfaceTest::InitSectionHeaders(uint64_t entry_size) {
shdr.sh_name = 0x20000;
shdr.sh_offset = 0xf000;
shdr.sh_size = 0x1000;
- memory_.SetMemory(offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(offset, &shdr, sizeof(shdr));
InitSym<Sym>(0x5000, 0x90000, 0x1000, 0x100, 0xf000, "function_one");
InitSym<Sym>(0x6000, 0xd0000, 0x1000, 0x300, 0xf000, "function_two");
@@ -924,7 +926,7 @@ TEST_F(ElfInterfaceTest, init_section_headers_non_std_entry_size_64) {
template <typename Ehdr, typename Shdr, typename ElfInterfaceType>
void ElfInterfaceTest::InitSectionHeadersOffsets() {
- std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(&memory_));
+ std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(memory_));
uint64_t offset = 0x2000;
@@ -933,7 +935,7 @@ void ElfInterfaceTest::InitSectionHeadersOffsets() {
ehdr.e_shnum = 7;
ehdr.e_shentsize = sizeof(Shdr);
ehdr.e_shstrndx = 2;
- memory_.SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
offset += ehdr.e_shentsize;
@@ -945,7 +947,7 @@ void ElfInterfaceTest::InitSectionHeadersOffsets() {
shdr.sh_offset = 0x5000;
shdr.sh_entsize = 0x100;
shdr.sh_size = 0x800;
- memory_.SetMemory(offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(offset, &shdr, sizeof(shdr));
offset += ehdr.e_shentsize;
// The string data for section header names.
@@ -954,7 +956,7 @@ void ElfInterfaceTest::InitSectionHeadersOffsets() {
shdr.sh_name = 0x20000;
shdr.sh_offset = 0xf000;
shdr.sh_size = 0x1000;
- memory_.SetMemory(offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(offset, &shdr, sizeof(shdr));
offset += ehdr.e_shentsize;
memset(&shdr, 0, sizeof(shdr));
@@ -965,7 +967,7 @@ void ElfInterfaceTest::InitSectionHeadersOffsets() {
shdr.sh_offset = 0x6000;
shdr.sh_entsize = 0x100;
shdr.sh_size = 0x500;
- memory_.SetMemory(offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(offset, &shdr, sizeof(shdr));
offset += ehdr.e_shentsize;
memset(&shdr, 0, sizeof(shdr));
@@ -976,7 +978,7 @@ void ElfInterfaceTest::InitSectionHeadersOffsets() {
shdr.sh_offset = 0x7000;
shdr.sh_entsize = 0x100;
shdr.sh_size = 0x800;
- memory_.SetMemory(offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(offset, &shdr, sizeof(shdr));
offset += ehdr.e_shentsize;
memset(&shdr, 0, sizeof(shdr));
@@ -987,7 +989,7 @@ void ElfInterfaceTest::InitSectionHeadersOffsets() {
shdr.sh_offset = 0xa000;
shdr.sh_entsize = 0x100;
shdr.sh_size = 0xf00;
- memory_.SetMemory(offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(offset, &shdr, sizeof(shdr));
offset += ehdr.e_shentsize;
memset(&shdr, 0, sizeof(shdr));
@@ -996,13 +998,13 @@ void ElfInterfaceTest::InitSectionHeadersOffsets() {
shdr.sh_addr = 0xb000;
shdr.sh_offset = 0xb000;
shdr.sh_size = 0xf00;
- memory_.SetMemory(offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(offset, &shdr, sizeof(shdr));
- memory_.SetMemory(0xf100, ".debug_frame", sizeof(".debug_frame"));
- memory_.SetMemory(0xf200, ".gnu_debugdata", sizeof(".gnu_debugdata"));
- memory_.SetMemory(0xf300, ".eh_frame", sizeof(".eh_frame"));
- memory_.SetMemory(0xf400, ".eh_frame_hdr", sizeof(".eh_frame_hdr"));
- memory_.SetMemory(0xf500, ".note.gnu.build-id", sizeof(".note.gnu.build-id"));
+ fake_memory_->SetMemory(0xf100, ".debug_frame", sizeof(".debug_frame"));
+ fake_memory_->SetMemory(0xf200, ".gnu_debugdata", sizeof(".gnu_debugdata"));
+ fake_memory_->SetMemory(0xf300, ".eh_frame", sizeof(".eh_frame"));
+ fake_memory_->SetMemory(0xf400, ".eh_frame_hdr", sizeof(".eh_frame_hdr"));
+ fake_memory_->SetMemory(0xf500, ".note.gnu.build-id", sizeof(".note.gnu.build-id"));
int64_t load_bias = 0;
ASSERT_TRUE(elf->Init(&load_bias));
@@ -1040,7 +1042,7 @@ TEST_F(ElfInterfaceTest, init_section_headers_offsets_64) {
template <typename Ehdr, typename Shdr, typename ElfInterfaceType>
void ElfInterfaceTest::InitSectionHeadersOffsetsEhFrameSectionBias(uint64_t addr, uint64_t offset,
int64_t expected_bias) {
- std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(&memory_));
+ std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(memory_));
uint64_t elf_offset = 0x2000;
@@ -1049,7 +1051,7 @@ void ElfInterfaceTest::InitSectionHeadersOffsetsEhFrameSectionBias(uint64_t addr
ehdr.e_shnum = 4;
ehdr.e_shentsize = sizeof(Shdr);
ehdr.e_shstrndx = 2;
- memory_.SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
elf_offset += ehdr.e_shentsize;
@@ -1061,7 +1063,7 @@ void ElfInterfaceTest::InitSectionHeadersOffsetsEhFrameSectionBias(uint64_t addr
shdr.sh_offset = 0x8000;
shdr.sh_entsize = 0x100;
shdr.sh_size = 0x800;
- memory_.SetMemory(elf_offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(elf_offset, &shdr, sizeof(shdr));
elf_offset += ehdr.e_shentsize;
// The string data for section header names.
@@ -1070,7 +1072,7 @@ void ElfInterfaceTest::InitSectionHeadersOffsetsEhFrameSectionBias(uint64_t addr
shdr.sh_name = 0x20000;
shdr.sh_offset = 0xf000;
shdr.sh_size = 0x1000;
- memory_.SetMemory(elf_offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(elf_offset, &shdr, sizeof(shdr));
elf_offset += ehdr.e_shentsize;
memset(&shdr, 0, sizeof(shdr));
@@ -1081,10 +1083,10 @@ void ElfInterfaceTest::InitSectionHeadersOffsetsEhFrameSectionBias(uint64_t addr
shdr.sh_offset = offset;
shdr.sh_entsize = 0x100;
shdr.sh_size = 0x500;
- memory_.SetMemory(elf_offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(elf_offset, &shdr, sizeof(shdr));
- memory_.SetMemory(0xf100, ".eh_frame", sizeof(".eh_frame"));
- memory_.SetMemory(0xf200, ".eh_frame_hdr", sizeof(".eh_frame_hdr"));
+ fake_memory_->SetMemory(0xf100, ".eh_frame", sizeof(".eh_frame"));
+ fake_memory_->SetMemory(0xf200, ".eh_frame_hdr", sizeof(".eh_frame_hdr"));
int64_t load_bias = 0;
ASSERT_TRUE(elf->Init(&load_bias));
@@ -1134,7 +1136,7 @@ template <typename Ehdr, typename Shdr, typename ElfInterfaceType>
void ElfInterfaceTest::InitSectionHeadersOffsetsEhFrameHdrSectionBias(uint64_t addr,
uint64_t offset,
int64_t expected_bias) {
- std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(&memory_));
+ std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(memory_));
uint64_t elf_offset = 0x2000;
@@ -1143,7 +1145,7 @@ void ElfInterfaceTest::InitSectionHeadersOffsetsEhFrameHdrSectionBias(uint64_t a
ehdr.e_shnum = 4;
ehdr.e_shentsize = sizeof(Shdr);
ehdr.e_shstrndx = 2;
- memory_.SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
elf_offset += ehdr.e_shentsize;
@@ -1155,7 +1157,7 @@ void ElfInterfaceTest::InitSectionHeadersOffsetsEhFrameHdrSectionBias(uint64_t a
shdr.sh_offset = offset;
shdr.sh_entsize = 0x100;
shdr.sh_size = 0x800;
- memory_.SetMemory(elf_offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(elf_offset, &shdr, sizeof(shdr));
elf_offset += ehdr.e_shentsize;
// The string data for section header names.
@@ -1164,7 +1166,7 @@ void ElfInterfaceTest::InitSectionHeadersOffsetsEhFrameHdrSectionBias(uint64_t a
shdr.sh_name = 0x20000;
shdr.sh_offset = 0xf000;
shdr.sh_size = 0x1000;
- memory_.SetMemory(elf_offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(elf_offset, &shdr, sizeof(shdr));
elf_offset += ehdr.e_shentsize;
memset(&shdr, 0, sizeof(shdr));
@@ -1175,10 +1177,10 @@ void ElfInterfaceTest::InitSectionHeadersOffsetsEhFrameHdrSectionBias(uint64_t a
shdr.sh_offset = 0x5000;
shdr.sh_entsize = 0x100;
shdr.sh_size = 0x500;
- memory_.SetMemory(elf_offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(elf_offset, &shdr, sizeof(shdr));
- memory_.SetMemory(0xf100, ".eh_frame", sizeof(".eh_frame"));
- memory_.SetMemory(0xf200, ".eh_frame_hdr", sizeof(".eh_frame_hdr"));
+ fake_memory_->SetMemory(0xf100, ".eh_frame", sizeof(".eh_frame"));
+ fake_memory_->SetMemory(0xf200, ".eh_frame_hdr", sizeof(".eh_frame_hdr"));
int64_t load_bias = 0;
ASSERT_TRUE(elf->Init(&load_bias));
@@ -1227,7 +1229,7 @@ template <typename Ehdr, typename Shdr, typename ElfInterfaceType>
void ElfInterfaceTest::InitSectionHeadersOffsetsDebugFrameSectionBias(uint64_t addr,
uint64_t offset,
int64_t expected_bias) {
- std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(&memory_));
+ std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(memory_));
uint64_t elf_offset = 0x2000;
@@ -1236,7 +1238,7 @@ void ElfInterfaceTest::InitSectionHeadersOffsetsDebugFrameSectionBias(uint64_t a
ehdr.e_shnum = 3;
ehdr.e_shentsize = sizeof(Shdr);
ehdr.e_shstrndx = 2;
- memory_.SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
elf_offset += ehdr.e_shentsize;
@@ -1248,7 +1250,7 @@ void ElfInterfaceTest::InitSectionHeadersOffsetsDebugFrameSectionBias(uint64_t a
shdr.sh_offset = offset;
shdr.sh_entsize = 0x100;
shdr.sh_size = 0x800;
- memory_.SetMemory(elf_offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(elf_offset, &shdr, sizeof(shdr));
elf_offset += ehdr.e_shentsize;
// The string data for section header names.
@@ -1257,9 +1259,9 @@ void ElfInterfaceTest::InitSectionHeadersOffsetsDebugFrameSectionBias(uint64_t a
shdr.sh_name = 0x20000;
shdr.sh_offset = 0xf000;
shdr.sh_size = 0x1000;
- memory_.SetMemory(elf_offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(elf_offset, &shdr, sizeof(shdr));
- memory_.SetMemory(0xf100, ".debug_frame", sizeof(".debug_frame"));
+ fake_memory_->SetMemory(0xf100, ".debug_frame", sizeof(".debug_frame"));
int64_t load_bias = 0;
ASSERT_TRUE(elf->Init(&load_bias));
@@ -1301,13 +1303,13 @@ TEST_F(ElfInterfaceTest, init_section_headers_offsets_debug_frame_section_bias_n
template <typename Ehdr, typename Phdr, typename ElfInterfaceType>
void ElfInterfaceTest::CheckGnuEhFrame(uint64_t addr, uint64_t offset, int64_t expected_bias) {
- std::unique_ptr<ElfInterface> elf(new ElfInterfaceType(&memory_));
+ std::unique_ptr<ElfInterface> elf(new ElfInterfaceType(memory_));
Ehdr ehdr = {};
ehdr.e_phoff = 0x100;
ehdr.e_phnum = 2;
ehdr.e_phentsize = sizeof(Phdr);
- memory_.SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
uint64_t phdr_offset = 0x100;
@@ -1316,14 +1318,14 @@ void ElfInterfaceTest::CheckGnuEhFrame(uint64_t addr, uint64_t offset, int64_t e
phdr.p_memsz = 0x10000;
phdr.p_flags = PF_R | PF_X;
phdr.p_align = 0x1000;
- memory_.SetMemory(phdr_offset, &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(phdr_offset, &phdr, sizeof(phdr));
phdr_offset += sizeof(phdr);
memset(&phdr, 0, sizeof(phdr));
phdr.p_type = PT_GNU_EH_FRAME;
phdr.p_vaddr = addr;
phdr.p_offset = offset;
- memory_.SetMemory(phdr_offset, &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(phdr_offset, &phdr, sizeof(phdr));
int64_t load_bias = 0;
ASSERT_TRUE(elf->Init(&load_bias));
@@ -1358,13 +1360,13 @@ TEST_F(ElfInterfaceTest, eh_frame_negative_section_bias_64) {
}
TEST_F(ElfInterfaceTest, is_valid_pc_from_pt_load) {
- std::unique_ptr<ElfInterface> elf(new ElfInterface32(&memory_));
+ std::unique_ptr<ElfInterface> elf(new ElfInterface32(memory_));
Elf32_Ehdr ehdr = {};
ehdr.e_phoff = 0x100;
ehdr.e_phnum = 1;
ehdr.e_phentsize = sizeof(Elf32_Phdr);
- memory_.SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
Elf32_Phdr phdr = {};
phdr.p_type = PT_LOAD;
@@ -1372,7 +1374,7 @@ TEST_F(ElfInterfaceTest, is_valid_pc_from_pt_load) {
phdr.p_memsz = 0x10000;
phdr.p_flags = PF_R | PF_X;
phdr.p_align = 0x1000;
- memory_.SetMemory(0x100, &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(0x100, &phdr, sizeof(phdr));
int64_t load_bias = 0;
ASSERT_TRUE(elf->Init(&load_bias));
@@ -1384,13 +1386,13 @@ TEST_F(ElfInterfaceTest, is_valid_pc_from_pt_load) {
}
TEST_F(ElfInterfaceTest, is_valid_pc_from_pt_load_non_zero_load_bias) {
- std::unique_ptr<ElfInterface> elf(new ElfInterface32(&memory_));
+ std::unique_ptr<ElfInterface> elf(new ElfInterface32(memory_));
Elf32_Ehdr ehdr = {};
ehdr.e_phoff = 0x100;
ehdr.e_phnum = 1;
ehdr.e_phentsize = sizeof(Elf32_Phdr);
- memory_.SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
Elf32_Phdr phdr = {};
phdr.p_type = PT_LOAD;
@@ -1398,7 +1400,7 @@ TEST_F(ElfInterfaceTest, is_valid_pc_from_pt_load_non_zero_load_bias) {
phdr.p_memsz = 0x10000;
phdr.p_flags = PF_R | PF_X;
phdr.p_align = 0x1000;
- memory_.SetMemory(0x100, &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(0x100, &phdr, sizeof(phdr));
int64_t load_bias = 0;
ASSERT_TRUE(elf->Init(&load_bias));
@@ -1413,7 +1415,7 @@ TEST_F(ElfInterfaceTest, is_valid_pc_from_pt_load_non_zero_load_bias) {
}
TEST_F(ElfInterfaceTest, is_valid_pc_from_debug_frame) {
- std::unique_ptr<ElfInterface> elf(new ElfInterface32(&memory_));
+ std::unique_ptr<ElfInterface> elf(new ElfInterface32(memory_));
uint64_t sh_offset = 0x100;
@@ -1422,11 +1424,11 @@ TEST_F(ElfInterfaceTest, is_valid_pc_from_debug_frame) {
ehdr.e_shoff = sh_offset;
ehdr.e_shentsize = sizeof(Elf32_Shdr);
ehdr.e_shnum = 3;
- memory_.SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
Elf32_Shdr shdr = {};
shdr.sh_type = SHT_NULL;
- memory_.SetMemory(sh_offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(sh_offset, &shdr, sizeof(shdr));
sh_offset += sizeof(shdr);
memset(&shdr, 0, sizeof(shdr));
@@ -1434,8 +1436,8 @@ TEST_F(ElfInterfaceTest, is_valid_pc_from_debug_frame) {
shdr.sh_name = 1;
shdr.sh_offset = 0x500;
shdr.sh_size = 0x100;
- memory_.SetMemory(sh_offset, &shdr, sizeof(shdr));
- memory_.SetMemory(0x500, ".debug_frame");
+ fake_memory_->SetMemory(sh_offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(0x500, ".debug_frame");
sh_offset += sizeof(shdr);
memset(&shdr, 0, sizeof(shdr));
@@ -1444,18 +1446,18 @@ TEST_F(ElfInterfaceTest, is_valid_pc_from_debug_frame) {
shdr.sh_addr = 0x600;
shdr.sh_offset = 0x600;
shdr.sh_size = 0x200;
- memory_.SetMemory(sh_offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(sh_offset, &shdr, sizeof(shdr));
// CIE 32.
- memory_.SetData32(0x600, 0xfc);
- memory_.SetData32(0x604, 0xffffffff);
- memory_.SetMemory(0x608, std::vector<uint8_t>{1, '\0', 4, 4, 1});
+ fake_memory_->SetData32(0x600, 0xfc);
+ fake_memory_->SetData32(0x604, 0xffffffff);
+ fake_memory_->SetMemory(0x608, std::vector<uint8_t>{1, '\0', 4, 4, 1});
// FDE 32.
- memory_.SetData32(0x700, 0xfc);
- memory_.SetData32(0x704, 0);
- memory_.SetData32(0x708, 0x2100);
- memory_.SetData32(0x70c, 0x200);
+ fake_memory_->SetData32(0x700, 0xfc);
+ fake_memory_->SetData32(0x704, 0);
+ fake_memory_->SetData32(0x708, 0x2100);
+ fake_memory_->SetData32(0x70c, 0x200);
int64_t load_bias = 0;
ASSERT_TRUE(elf->Init(&load_bias));
@@ -1470,7 +1472,7 @@ TEST_F(ElfInterfaceTest, is_valid_pc_from_debug_frame) {
}
TEST_F(ElfInterfaceTest, is_valid_pc_from_eh_frame) {
- std::unique_ptr<ElfInterface> elf(new ElfInterface32(&memory_));
+ std::unique_ptr<ElfInterface> elf(new ElfInterface32(memory_));
uint64_t sh_offset = 0x100;
@@ -1479,11 +1481,11 @@ TEST_F(ElfInterfaceTest, is_valid_pc_from_eh_frame) {
ehdr.e_shoff = sh_offset;
ehdr.e_shentsize = sizeof(Elf32_Shdr);
ehdr.e_shnum = 3;
- memory_.SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
Elf32_Shdr shdr = {};
shdr.sh_type = SHT_NULL;
- memory_.SetMemory(sh_offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(sh_offset, &shdr, sizeof(shdr));
sh_offset += sizeof(shdr);
memset(&shdr, 0, sizeof(shdr));
@@ -1491,8 +1493,8 @@ TEST_F(ElfInterfaceTest, is_valid_pc_from_eh_frame) {
shdr.sh_name = 1;
shdr.sh_offset = 0x500;
shdr.sh_size = 0x100;
- memory_.SetMemory(sh_offset, &shdr, sizeof(shdr));
- memory_.SetMemory(0x500, ".eh_frame");
+ fake_memory_->SetMemory(sh_offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(0x500, ".eh_frame");
sh_offset += sizeof(shdr);
memset(&shdr, 0, sizeof(shdr));
@@ -1501,18 +1503,18 @@ TEST_F(ElfInterfaceTest, is_valid_pc_from_eh_frame) {
shdr.sh_addr = 0x600;
shdr.sh_offset = 0x600;
shdr.sh_size = 0x200;
- memory_.SetMemory(sh_offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(sh_offset, &shdr, sizeof(shdr));
// CIE 32.
- memory_.SetData32(0x600, 0xfc);
- memory_.SetData32(0x604, 0);
- memory_.SetMemory(0x608, std::vector<uint8_t>{1, '\0', 4, 4, 1});
+ fake_memory_->SetData32(0x600, 0xfc);
+ fake_memory_->SetData32(0x604, 0);
+ fake_memory_->SetMemory(0x608, std::vector<uint8_t>{1, '\0', 4, 4, 1});
// FDE 32.
- memory_.SetData32(0x700, 0xfc);
- memory_.SetData32(0x704, 0x104);
- memory_.SetData32(0x708, 0x20f8);
- memory_.SetData32(0x70c, 0x200);
+ fake_memory_->SetData32(0x700, 0xfc);
+ fake_memory_->SetData32(0x704, 0x104);
+ fake_memory_->SetData32(0x708, 0x20f8);
+ fake_memory_->SetData32(0x70c, 0x200);
int64_t load_bias = 0;
ASSERT_TRUE(elf->Init(&load_bias));
@@ -1528,7 +1530,7 @@ TEST_F(ElfInterfaceTest, is_valid_pc_from_eh_frame) {
template <typename Ehdr, typename Shdr, typename Nhdr, typename ElfInterfaceType>
void ElfInterfaceTest::BuildID() {
- std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(&memory_));
+ std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(memory_));
uint64_t offset = 0x2000;
@@ -1537,7 +1539,7 @@ void ElfInterfaceTest::BuildID() {
ehdr.e_shnum = 3;
ehdr.e_shentsize = sizeof(Shdr);
ehdr.e_shstrndx = 2;
- memory_.SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
offset += ehdr.e_shentsize;
@@ -1559,7 +1561,7 @@ void ElfInterfaceTest::BuildID() {
shdr.sh_name = 0x500;
shdr.sh_offset = 0xb000;
shdr.sh_size = sizeof(note_section);
- memory_.SetMemory(offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(offset, &shdr, sizeof(shdr));
offset += ehdr.e_shentsize;
// The string data for section header names.
@@ -1568,10 +1570,10 @@ void ElfInterfaceTest::BuildID() {
shdr.sh_name = 0x20000;
shdr.sh_offset = 0xf000;
shdr.sh_size = 0x1000;
- memory_.SetMemory(offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(offset, &shdr, sizeof(shdr));
- memory_.SetMemory(0xf500, ".note.gnu.build-id", sizeof(".note.gnu.build-id"));
- memory_.SetMemory(0xb000, note_section, sizeof(note_section));
+ fake_memory_->SetMemory(0xf500, ".note.gnu.build-id", sizeof(".note.gnu.build-id"));
+ fake_memory_->SetMemory(0xb000, note_section, sizeof(note_section));
int64_t load_bias = 0;
ASSERT_TRUE(elf->Init(&load_bias));
@@ -1588,7 +1590,7 @@ TEST_F(ElfInterfaceTest, build_id_64) {
template <typename Ehdr, typename Shdr, typename Nhdr, typename ElfInterfaceType>
void ElfInterfaceTest::BuildIDTwoNotes() {
- std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(&memory_));
+ std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(memory_));
uint64_t offset = 0x2000;
@@ -1597,7 +1599,7 @@ void ElfInterfaceTest::BuildIDTwoNotes() {
ehdr.e_shnum = 3;
ehdr.e_shentsize = sizeof(Shdr);
ehdr.e_shstrndx = 2;
- memory_.SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
offset += ehdr.e_shentsize;
@@ -1630,7 +1632,7 @@ void ElfInterfaceTest::BuildIDTwoNotes() {
shdr.sh_name = 0x500;
shdr.sh_offset = 0xb000;
shdr.sh_size = sizeof(note_section);
- memory_.SetMemory(offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(offset, &shdr, sizeof(shdr));
offset += ehdr.e_shentsize;
// The string data for section header names.
@@ -1639,10 +1641,10 @@ void ElfInterfaceTest::BuildIDTwoNotes() {
shdr.sh_name = 0x20000;
shdr.sh_offset = 0xf000;
shdr.sh_size = 0x1000;
- memory_.SetMemory(offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(offset, &shdr, sizeof(shdr));
- memory_.SetMemory(0xf500, ".note.gnu.build-id", sizeof(".note.gnu.build-id"));
- memory_.SetMemory(0xb000, note_section, sizeof(note_section));
+ fake_memory_->SetMemory(0xf500, ".note.gnu.build-id", sizeof(".note.gnu.build-id"));
+ fake_memory_->SetMemory(0xb000, note_section, sizeof(note_section));
int64_t load_bias = 0;
ASSERT_TRUE(elf->Init(&load_bias));
@@ -1659,7 +1661,7 @@ TEST_F(ElfInterfaceTest, build_id_two_notes_64) {
template <typename Ehdr, typename Shdr, typename Nhdr, typename ElfInterfaceType>
void ElfInterfaceTest::BuildIDSectionTooSmallForName () {
- std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(&memory_));
+ std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(memory_));
uint64_t offset = 0x2000;
@@ -1668,7 +1670,7 @@ void ElfInterfaceTest::BuildIDSectionTooSmallForName () {
ehdr.e_shnum = 3;
ehdr.e_shentsize = sizeof(Shdr);
ehdr.e_shstrndx = 2;
- memory_.SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
offset += ehdr.e_shentsize;
@@ -1690,7 +1692,7 @@ void ElfInterfaceTest::BuildIDSectionTooSmallForName () {
shdr.sh_name = 0x500;
shdr.sh_offset = 0xb000;
shdr.sh_size = sizeof(note_header) + 1;
- memory_.SetMemory(offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(offset, &shdr, sizeof(shdr));
offset += ehdr.e_shentsize;
// The string data for section header names.
@@ -1699,10 +1701,10 @@ void ElfInterfaceTest::BuildIDSectionTooSmallForName () {
shdr.sh_name = 0x20000;
shdr.sh_offset = 0xf000;
shdr.sh_size = 0x1000;
- memory_.SetMemory(offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(offset, &shdr, sizeof(shdr));
- memory_.SetMemory(0xf500, ".note.gnu.build-id", sizeof(".note.gnu.build-id"));
- memory_.SetMemory(0xb000, note_section, sizeof(note_section));
+ fake_memory_->SetMemory(0xf500, ".note.gnu.build-id", sizeof(".note.gnu.build-id"));
+ fake_memory_->SetMemory(0xb000, note_section, sizeof(note_section));
int64_t load_bias = 0;
ASSERT_TRUE(elf->Init(&load_bias));
@@ -1719,7 +1721,7 @@ TEST_F(ElfInterfaceTest, build_id_section_too_small_for_name_64) {
template <typename Ehdr, typename Shdr, typename Nhdr, typename ElfInterfaceType>
void ElfInterfaceTest::BuildIDSectionTooSmallForDesc () {
- std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(&memory_));
+ std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(memory_));
uint64_t offset = 0x2000;
@@ -1728,7 +1730,7 @@ void ElfInterfaceTest::BuildIDSectionTooSmallForDesc () {
ehdr.e_shnum = 3;
ehdr.e_shentsize = sizeof(Shdr);
ehdr.e_shstrndx = 2;
- memory_.SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
offset += ehdr.e_shentsize;
@@ -1750,7 +1752,7 @@ void ElfInterfaceTest::BuildIDSectionTooSmallForDesc () {
shdr.sh_name = 0x500;
shdr.sh_offset = 0xb000;
shdr.sh_size = sizeof(note_header) + sizeof("GNU") + 1;
- memory_.SetMemory(offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(offset, &shdr, sizeof(shdr));
offset += ehdr.e_shentsize;
// The string data for section header names.
@@ -1759,10 +1761,10 @@ void ElfInterfaceTest::BuildIDSectionTooSmallForDesc () {
shdr.sh_name = 0x20000;
shdr.sh_offset = 0xf000;
shdr.sh_size = 0x1000;
- memory_.SetMemory(offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(offset, &shdr, sizeof(shdr));
- memory_.SetMemory(0xf500, ".note.gnu.build-id", sizeof(".note.gnu.build-id"));
- memory_.SetMemory(0xb000, note_section, sizeof(note_section));
+ fake_memory_->SetMemory(0xf500, ".note.gnu.build-id", sizeof(".note.gnu.build-id"));
+ fake_memory_->SetMemory(0xb000, note_section, sizeof(note_section));
int64_t load_bias = 0;
ASSERT_TRUE(elf->Init(&load_bias));
@@ -1779,7 +1781,7 @@ TEST_F(ElfInterfaceTest, build_id_section_too_small_for_desc_64) {
template <typename Ehdr, typename Shdr, typename Nhdr, typename ElfInterfaceType>
void ElfInterfaceTest::BuildIDSectionTooSmallForHeader () {
- std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(&memory_));
+ std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(memory_));
uint64_t offset = 0x2000;
@@ -1788,7 +1790,7 @@ void ElfInterfaceTest::BuildIDSectionTooSmallForHeader () {
ehdr.e_shnum = 3;
ehdr.e_shentsize = sizeof(Shdr);
ehdr.e_shstrndx = 2;
- memory_.SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
offset += ehdr.e_shentsize;
@@ -1810,7 +1812,7 @@ void ElfInterfaceTest::BuildIDSectionTooSmallForHeader () {
shdr.sh_name = 0x500;
shdr.sh_offset = 0xb000;
shdr.sh_size = sizeof(note_header) - 1;
- memory_.SetMemory(offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(offset, &shdr, sizeof(shdr));
offset += ehdr.e_shentsize;
// The string data for section header names.
@@ -1819,10 +1821,10 @@ void ElfInterfaceTest::BuildIDSectionTooSmallForHeader () {
shdr.sh_name = 0x20000;
shdr.sh_offset = 0xf000;
shdr.sh_size = 0x1000;
- memory_.SetMemory(offset, &shdr, sizeof(shdr));
+ fake_memory_->SetMemory(offset, &shdr, sizeof(shdr));
- memory_.SetMemory(0xf500, ".note.gnu.build-id", sizeof(".note.gnu.build-id"));
- memory_.SetMemory(0xb000, note_section, sizeof(note_section));
+ fake_memory_->SetMemory(0xf500, ".note.gnu.build-id", sizeof(".note.gnu.build-id"));
+ fake_memory_->SetMemory(0xb000, note_section, sizeof(note_section));
int64_t load_bias = 0;
ASSERT_TRUE(elf->Init(&load_bias));
@@ -1843,7 +1845,7 @@ void ElfInterfaceTest::CheckLoadBiasInFirstPhdr(int64_t load_bias) {
ehdr.e_phoff = 0x100;
ehdr.e_phnum = 2;
ehdr.e_phentsize = sizeof(Phdr);
- memory_.SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
Phdr phdr = {};
phdr.p_type = PT_LOAD;
@@ -1852,7 +1854,7 @@ void ElfInterfaceTest::CheckLoadBiasInFirstPhdr(int64_t load_bias) {
phdr.p_memsz = 0x10000;
phdr.p_flags = PF_R | PF_X;
phdr.p_align = 0x1000;
- memory_.SetMemory(0x100, &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(0x100, &phdr, sizeof(phdr));
memset(&phdr, 0, sizeof(phdr));
phdr.p_type = PT_LOAD;
@@ -1860,12 +1862,12 @@ void ElfInterfaceTest::CheckLoadBiasInFirstPhdr(int64_t load_bias) {
phdr.p_memsz = 0x2000;
phdr.p_flags = PF_R | PF_X;
phdr.p_align = 0x1000;
- memory_.SetMemory(0x100 + sizeof(phdr), &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(0x100 + sizeof(phdr), &phdr, sizeof(phdr));
- int64_t static_load_bias = ElfInterface::GetLoadBias<Ehdr, Phdr>(&memory_);
+ int64_t static_load_bias = ElfInterface::GetLoadBias<Ehdr, Phdr>(memory_.get());
ASSERT_EQ(load_bias, static_load_bias);
- std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(&memory_));
+ std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(memory_));
int64_t init_load_bias = 0;
ASSERT_TRUE(elf->Init(&init_load_bias));
ASSERT_EQ(init_load_bias, static_load_bias);
@@ -1894,14 +1896,14 @@ void ElfInterfaceTest::CheckLoadBiasInFirstExecPhdr(uint64_t offset, uint64_t va
ehdr.e_phoff = 0x100;
ehdr.e_phnum = 3;
ehdr.e_phentsize = sizeof(Phdr);
- memory_.SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
Phdr phdr = {};
phdr.p_type = PT_LOAD;
phdr.p_memsz = 0x10000;
phdr.p_flags = PF_R;
phdr.p_align = 0x1000;
- memory_.SetMemory(0x100, &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(0x100, &phdr, sizeof(phdr));
memset(&phdr, 0, sizeof(phdr));
phdr.p_type = PT_LOAD;
@@ -1910,7 +1912,7 @@ void ElfInterfaceTest::CheckLoadBiasInFirstExecPhdr(uint64_t offset, uint64_t va
phdr.p_memsz = 0x2000;
phdr.p_flags = PF_R | PF_X;
phdr.p_align = 0x1000;
- memory_.SetMemory(0x100 + sizeof(phdr), &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(0x100 + sizeof(phdr), &phdr, sizeof(phdr));
// Second executable load should be ignored for load bias computation.
memset(&phdr, 0, sizeof(phdr));
@@ -1920,12 +1922,12 @@ void ElfInterfaceTest::CheckLoadBiasInFirstExecPhdr(uint64_t offset, uint64_t va
phdr.p_memsz = 0x2000;
phdr.p_flags = PF_R | PF_X;
phdr.p_align = 0x1000;
- memory_.SetMemory(0x200 + sizeof(phdr), &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(0x200 + sizeof(phdr), &phdr, sizeof(phdr));
- int64_t static_load_bias = ElfInterface::GetLoadBias<Ehdr, Phdr>(&memory_);
+ int64_t static_load_bias = ElfInterface::GetLoadBias<Ehdr, Phdr>(memory_.get());
ASSERT_EQ(load_bias, static_load_bias);
- std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(&memory_));
+ std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(memory_));
int64_t init_load_bias = 0;
ASSERT_TRUE(elf->Init(&init_load_bias));
ASSERT_EQ(init_load_bias, static_load_bias);
@@ -1956,7 +1958,8 @@ TEST_F(ElfInterfaceTest, get_load_bias_exec_negative_64) {
}
TEST_F(ElfInterfaceTest, huge_gnu_debugdata_size) {
- ElfInterfaceFake interface(nullptr);
+ std::shared_ptr<Memory> empty;
+ ElfInterfaceFake interface(empty);
interface.FakeSetGnuDebugdataOffset(0x1000);
interface.FakeSetGnuDebugdataSize(0xffffffffffffffffUL);
diff --git a/libunwindstack/tests/ElfTest.cpp b/libunwindstack/tests/ElfTest.cpp
index 7e30863..dcb4923 100644
--- a/libunwindstack/tests/ElfTest.cpp
+++ b/libunwindstack/tests/ElfTest.cpp
@@ -20,6 +20,9 @@
#include <sys/types.h>
#include <unistd.h>
+#include <memory>
+#include <string>
+
#include <gmock/gmock.h>
#include <gtest/gtest.h>
@@ -42,7 +45,8 @@ namespace unwindstack {
class ElfTest : public ::testing::Test {
protected:
void SetUp() override {
- memory_ = new MemoryFake;
+ fake_memory_ = new MemoryFake;
+ elf_memory_.reset(fake_memory_);
}
void InitElf32(uint32_t machine_type) {
@@ -58,7 +62,7 @@ class ElfTest : public ::testing::Test {
ehdr.e_flags = 0x5000200;
ehdr.e_phnum = 2;
}
- memory_->SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
Elf32_Phdr phdr;
memset(&phdr, 0, sizeof(phdr));
@@ -67,7 +71,7 @@ class ElfTest : public ::testing::Test {
phdr.p_memsz = 0x10000;
phdr.p_flags = PF_R | PF_X;
phdr.p_align = 0x1000;
- memory_->SetMemory(0x100, &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(0x100, &phdr, sizeof(phdr));
if (machine_type == EM_ARM) {
memset(&phdr, 0, sizeof(phdr));
@@ -79,7 +83,7 @@ class ElfTest : public ::testing::Test {
phdr.p_memsz = 16;
phdr.p_flags = PF_R;
phdr.p_align = 0x4;
- memory_->SetMemory(0x100 + sizeof(phdr), &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(0x100 + sizeof(phdr), &phdr, sizeof(phdr));
}
}
@@ -93,7 +97,7 @@ class ElfTest : public ::testing::Test {
ehdr.e_phentsize = sizeof(Elf64_Phdr);
ehdr.e_phnum = 1;
ehdr.e_shentsize = sizeof(Elf64_Shdr);
- memory_->SetMemory(0, &ehdr, sizeof(ehdr));
+ fake_memory_->SetMemory(0, &ehdr, sizeof(ehdr));
Elf64_Phdr phdr;
memset(&phdr, 0, sizeof(phdr));
@@ -102,28 +106,29 @@ class ElfTest : public ::testing::Test {
phdr.p_memsz = 0x10000;
phdr.p_flags = PF_R | PF_X;
phdr.p_align = 0x1000;
- memory_->SetMemory(0x100, &phdr, sizeof(phdr));
+ fake_memory_->SetMemory(0x100, &phdr, sizeof(phdr));
}
void VerifyStepIfSignalHandler(uint64_t load_bias);
- MemoryFake* memory_;
+ MemoryFake* fake_memory_;
+ std::shared_ptr<Memory> elf_memory_;
};
TEST_F(ElfTest, invalid_memory) {
- Elf elf(memory_);
+ Elf elf(elf_memory_);
ASSERT_FALSE(elf.Init());
ASSERT_FALSE(elf.valid());
}
TEST_F(ElfTest, elf_invalid) {
- Elf elf(memory_);
+ Elf elf(elf_memory_);
InitElf32(EM_386);
// Corrupt the ELF signature.
- memory_->SetData32(0, 0x7f000000);
+ fake_memory_->SetData32(0, 0x7f000000);
ASSERT_FALSE(elf.Init());
ASSERT_FALSE(elf.valid());
@@ -145,7 +150,7 @@ TEST_F(ElfTest, elf_invalid) {
}
TEST_F(ElfTest, elf_invalid_check_error_values) {
- ElfFake elf(memory_);
+ ElfFake elf(elf_memory_);
elf.FakeSetValid(false);
EXPECT_EQ(ERROR_INVALID_ELF, elf.GetLastErrorCode());
@@ -164,7 +169,7 @@ TEST_F(ElfTest, elf_invalid_check_error_values) {
}
TEST_F(ElfTest, elf32_invalid_machine) {
- Elf elf(memory_);
+ Elf elf(elf_memory_);
InitElf32(EM_PPC);
@@ -176,7 +181,7 @@ TEST_F(ElfTest, elf32_invalid_machine) {
}
TEST_F(ElfTest, elf64_invalid_machine) {
- Elf elf(memory_);
+ Elf elf(elf_memory_);
InitElf64(EM_PPC64);
@@ -188,7 +193,7 @@ TEST_F(ElfTest, elf64_invalid_machine) {
}
TEST_F(ElfTest, elf_arm) {
- Elf elf(memory_);
+ Elf elf(elf_memory_);
InitElf32(EM_ARM);
@@ -200,7 +205,7 @@ TEST_F(ElfTest, elf_arm) {
}
TEST_F(ElfTest, elf_x86) {
- Elf elf(memory_);
+ Elf elf(elf_memory_);
InitElf32(EM_386);
@@ -212,7 +217,7 @@ TEST_F(ElfTest, elf_x86) {
}
TEST_F(ElfTest, elf_arm64) {
- Elf elf(memory_);
+ Elf elf(elf_memory_);
InitElf64(EM_AARCH64);
@@ -224,7 +229,7 @@ TEST_F(ElfTest, elf_arm64) {
}
TEST_F(ElfTest, elf_riscv64) {
- Elf elf(memory_);
+ Elf elf(elf_memory_);
InitElf64(EM_RISCV);
@@ -236,7 +241,7 @@ TEST_F(ElfTest, elf_riscv64) {
}
TEST_F(ElfTest, elf_x86_64) {
- Elf elf(memory_);
+ Elf elf(elf_memory_);
InitElf64(EM_X86_64);
@@ -250,10 +255,10 @@ TEST_F(ElfTest, elf_x86_64) {
TEST_F(ElfTest, gnu_debugdata_init32) {
TestInitGnuDebugdata<Elf32_Ehdr, Elf32_Shdr>(ELFCLASS32, EM_ARM, true,
[&](uint64_t offset, const void* ptr, size_t size) {
- memory_->SetMemory(offset, ptr, size);
+ fake_memory_->SetMemory(offset, ptr, size);
});
- Elf elf(memory_);
+ Elf elf(elf_memory_);
ASSERT_TRUE(elf.Init());
ASSERT_TRUE(elf.interface() != nullptr);
ASSERT_TRUE(elf.gnu_debugdata_interface() != nullptr);
@@ -264,10 +269,10 @@ TEST_F(ElfTest, gnu_debugdata_init32) {
TEST_F(ElfTest, gnu_debugdata_init64) {
TestInitGnuDebugdata<Elf64_Ehdr, Elf64_Shdr>(ELFCLASS64, EM_AARCH64, true,
[&](uint64_t offset, const void* ptr, size_t size) {
- memory_->SetMemory(offset, ptr, size);
+ fake_memory_->SetMemory(offset, ptr, size);
});
- Elf elf(memory_);
+ Elf elf(elf_memory_);
ASSERT_TRUE(elf.Init());
ASSERT_TRUE(elf.interface() != nullptr);
ASSERT_TRUE(elf.gnu_debugdata_interface() != nullptr);
@@ -276,9 +281,9 @@ TEST_F(ElfTest, gnu_debugdata_init64) {
}
TEST_F(ElfTest, rel_pc) {
- ElfFake elf(memory_);
+ ElfFake elf(elf_memory_);
- ElfInterfaceFake* interface = new ElfInterfaceFake(memory_);
+ ElfInterfaceFake* interface = new ElfInterfaceFake(elf_memory_);
elf.FakeSetInterface(interface);
elf.FakeSetValid(true);
@@ -291,17 +296,17 @@ TEST_F(ElfTest, rel_pc) {
}
void ElfTest::VerifyStepIfSignalHandler(uint64_t load_bias) {
- ElfFake elf(memory_);
+ ElfFake elf(elf_memory_);
RegsArm regs;
regs[13] = 0x50000;
regs[15] = 0x8000;
- ElfInterfaceFake* interface = new ElfInterfaceFake(memory_);
+ ElfInterfaceFake* interface = new ElfInterfaceFake(elf_memory_);
elf.FakeSetInterface(interface);
elf.FakeSetLoadBias(load_bias);
- memory_->SetData32(0x3000, 0xdf0027ad);
+ fake_memory_->SetData32(0x3000, 0xdf0027ad);
MemoryFake process_memory;
process_memory.SetData32(0x50000, 0);
for (size_t i = 0; i < 16; i++) {
@@ -325,7 +330,7 @@ TEST_F(ElfTest, step_in_signal_map_non_zero_load_bias) {
class ElfInterfaceMock : public ElfInterface {
public:
- ElfInterfaceMock(Memory* memory) : ElfInterface(memory) {}
+ ElfInterfaceMock(std::shared_ptr<Memory>& memory) : ElfInterface(memory) {}
virtual ~ElfInterfaceMock() = default;
bool Init(int64_t*) override { return false; }
@@ -348,12 +353,12 @@ class ElfInterfaceMock : public ElfInterface {
};
TEST_F(ElfTest, step_in_interface) {
- ElfFake elf(memory_);
+ ElfFake elf(elf_memory_);
elf.FakeSetValid(true);
RegsArm regs;
- ElfInterfaceMock* interface = new ElfInterfaceMock(memory_);
+ ElfInterfaceMock* interface = new ElfInterfaceMock(elf_memory_);
elf.FakeSetInterface(interface);
MemoryFake process_memory;
@@ -366,7 +371,7 @@ TEST_F(ElfTest, step_in_interface) {
}
TEST_F(ElfTest, get_global_invalid_elf) {
- ElfFake elf(memory_);
+ ElfFake elf(elf_memory_);
elf.FakeSetValid(false);
std::string global("something");
@@ -375,10 +380,10 @@ TEST_F(ElfTest, get_global_invalid_elf) {
}
TEST_F(ElfTest, get_global_valid_not_in_interface) {
- ElfFake elf(memory_);
+ ElfFake elf(elf_memory_);
elf.FakeSetValid(true);
- ElfInterfaceMock* interface = new ElfInterfaceMock(memory_);
+ ElfInterfaceMock* interface = new ElfInterfaceMock(elf_memory_);
elf.FakeSetInterface(interface);
std::string global("something");
@@ -390,10 +395,10 @@ TEST_F(ElfTest, get_global_valid_not_in_interface) {
}
TEST_F(ElfTest, get_global_vaddr_in_no_sections) {
- ElfFake elf(memory_);
+ ElfFake elf(elf_memory_);
elf.FakeSetValid(true);
- ElfInterfaceMock* interface = new ElfInterfaceMock(memory_);
+ ElfInterfaceMock* interface = new ElfInterfaceMock(elf_memory_);
elf.FakeSetInterface(interface);
std::string global("something");
@@ -405,10 +410,10 @@ TEST_F(ElfTest, get_global_vaddr_in_no_sections) {
}
TEST_F(ElfTest, get_global_vaddr_in_data_section) {
- ElfFake elf(memory_);
+ ElfFake elf(elf_memory_);
elf.FakeSetValid(true);
- ElfInterfaceMock* interface = new ElfInterfaceMock(memory_);
+ ElfInterfaceMock* interface = new ElfInterfaceMock(elf_memory_);
elf.FakeSetInterface(interface);
interface->MockSetDataVaddrStart(0x500);
interface->MockSetDataVaddrEnd(0x600);
@@ -424,10 +429,10 @@ TEST_F(ElfTest, get_global_vaddr_in_data_section) {
}
TEST_F(ElfTest, get_global_vaddr_in_dynamic_section) {
- ElfFake elf(memory_);
+ ElfFake elf(elf_memory_);
elf.FakeSetValid(true);
- ElfInterfaceMock* interface = new ElfInterfaceMock(memory_);
+ ElfInterfaceMock* interface = new ElfInterfaceMock(elf_memory_);
elf.FakeSetInterface(interface);
interface->MockSetDataVaddrStart(0x500);
interface->MockSetDataVaddrEnd(0x600);
@@ -447,11 +452,11 @@ TEST_F(ElfTest, get_global_vaddr_in_dynamic_section) {
}
TEST_F(ElfTest, get_global_vaddr_with_tagged_pointer) {
- ElfFake elf(memory_);
+ ElfFake elf(elf_memory_);
elf.FakeSetValid(true);
elf.FakeSetArch(ARCH_ARM64);
- ElfInterfaceMock* interface = new ElfInterfaceMock(memory_);
+ ElfInterfaceMock* interface = new ElfInterfaceMock(elf_memory_);
elf.FakeSetInterface(interface);
interface->MockSetDataVaddrStart(0x500);
interface->MockSetDataVaddrEnd(0x600);
@@ -468,11 +473,11 @@ TEST_F(ElfTest, get_global_vaddr_with_tagged_pointer) {
}
TEST_F(ElfTest, get_global_vaddr_without_tagged_pointer) {
- ElfFake elf(memory_);
+ ElfFake elf(elf_memory_);
elf.FakeSetValid(true);
elf.FakeSetArch(ARCH_X86_64);
- ElfInterfaceMock* interface = new ElfInterfaceMock(memory_);
+ ElfInterfaceMock* interface = new ElfInterfaceMock(elf_memory_);
elf.FakeSetInterface(interface);
interface->MockSetDataVaddrStart(0x8800000000000500);
interface->MockSetDataVaddrEnd(0x8800000000000600);
@@ -489,7 +494,7 @@ TEST_F(ElfTest, get_global_vaddr_without_tagged_pointer) {
}
TEST_F(ElfTest, is_valid_pc_elf_invalid) {
- ElfFake elf(memory_);
+ ElfFake elf(elf_memory_);
elf.FakeSetValid(false);
EXPECT_FALSE(elf.IsValidPc(0x100));
@@ -497,10 +502,10 @@ TEST_F(ElfTest, is_valid_pc_elf_invalid) {
}
TEST_F(ElfTest, is_valid_pc_interface) {
- ElfFake elf(memory_);
+ ElfFake elf(elf_memory_);
elf.FakeSetValid(true);
- ElfInterfaceMock* interface = new ElfInterfaceMock(memory_);
+ ElfInterfaceMock* interface = new ElfInterfaceMock(elf_memory_);
elf.FakeSetInterface(interface);
EXPECT_CALL(*interface, IsValidPc(0x1500)).WillOnce(::testing::Return(true));
@@ -509,12 +514,12 @@ TEST_F(ElfTest, is_valid_pc_interface) {
}
TEST_F(ElfTest, is_valid_pc_from_gnu_debugdata) {
- ElfFake elf(memory_);
+ ElfFake elf(elf_memory_);
elf.FakeSetValid(true);
- ElfInterfaceMock* interface = new ElfInterfaceMock(memory_);
+ ElfInterfaceMock* interface = new ElfInterfaceMock(elf_memory_);
elf.FakeSetInterface(interface);
- ElfInterfaceMock* gnu_interface = new ElfInterfaceMock(memory_);
+ ElfInterfaceMock* gnu_interface = new ElfInterfaceMock(elf_memory_);
elf.FakeSetGnuDebugdataInterface(gnu_interface);
EXPECT_CALL(*interface, IsValidPc(0x1500)).WillOnce(::testing::Return(false));
@@ -524,9 +529,9 @@ TEST_F(ElfTest, is_valid_pc_from_gnu_debugdata) {
}
TEST_F(ElfTest, error_code_valid) {
- ElfFake elf(memory_);
+ ElfFake elf(elf_memory_);
elf.FakeSetValid(true);
- ElfInterfaceFake* interface = new ElfInterfaceFake(memory_);
+ ElfInterfaceFake* interface = new ElfInterfaceFake(elf_memory_);
elf.FakeSetInterface(interface);
interface->FakeSetErrorCode(ERROR_MEMORY_INVALID);
interface->FakeSetErrorAddress(0x1000);
diff --git a/libunwindstack/tests/GlobalTest.cpp b/libunwindstack/tests/GlobalTest.cpp
index b6893ba..b678196 100644
--- a/libunwindstack/tests/GlobalTest.cpp
+++ b/libunwindstack/tests/GlobalTest.cpp
@@ -73,12 +73,13 @@ class GlobalTest : public ::testing::Test {
ASSERT_TRUE(maps_->Parse());
ASSERT_EQ(11U, maps_->Total());
- elf_fakes_.push_back(new ElfInterfaceFake(nullptr));
- elf_fakes_.push_back(new ElfInterfaceFake(nullptr));
- elf_fakes_.push_back(new ElfInterfaceFake(nullptr));
- elf_fakes_.push_back(new ElfInterfaceFake(nullptr));
+ std::shared_ptr<Memory> empty;
+ elf_fakes_.push_back(new ElfInterfaceFake(empty));
+ elf_fakes_.push_back(new ElfInterfaceFake(empty));
+ elf_fakes_.push_back(new ElfInterfaceFake(empty));
+ elf_fakes_.push_back(new ElfInterfaceFake(empty));
- ElfFake* elf_fake = new ElfFake(nullptr);
+ ElfFake* elf_fake = new ElfFake(empty);
elf_fake->FakeSetValid(true);
elf_fake->FakeSetInterface(elf_fakes_[0]);
elf_fakes_[0]->FakeSetDataVaddrStart(0x2000);
@@ -87,7 +88,7 @@ class GlobalTest : public ::testing::Test {
auto map_info = maps_->Find(0x10000);
map_info->GetElfFields().elf_.reset(elf_fake);
- elf_fake = new ElfFake(nullptr);
+ elf_fake = new ElfFake(empty);
elf_fake->FakeSetValid(true);
elf_fake->FakeSetInterface(elf_fakes_[1]);
elf_fakes_[1]->FakeSetDataVaddrStart(0x2000);
@@ -96,7 +97,7 @@ class GlobalTest : public ::testing::Test {
map_info = maps_->Find(0x20000);
map_info->GetElfFields().elf_.reset(elf_fake);
- elf_fake = new ElfFake(nullptr);
+ elf_fake = new ElfFake(empty);
elf_fake->FakeSetValid(true);
elf_fake->FakeSetInterface(elf_fakes_[2]);
elf_fakes_[2]->FakeSetDataVaddrStart(0x2000);
@@ -105,7 +106,7 @@ class GlobalTest : public ::testing::Test {
map_info = maps_->Find(0x30000);
map_info->GetElfFields().elf_.reset(elf_fake);
- elf_fake = new ElfFake(nullptr);
+ elf_fake = new ElfFake(empty);
elf_fake->FakeSetValid(true);
elf_fake->FakeSetInterface(elf_fakes_[3]);
elf_fakes_[3]->FakeSetDataVaddrStart(00);
diff --git a/libunwindstack/tests/JitDebugTest.cpp b/libunwindstack/tests/JitDebugTest.cpp
index 66e220c..b727b6e 100644
--- a/libunwindstack/tests/JitDebugTest.cpp
+++ b/libunwindstack/tests/JitDebugTest.cpp
@@ -37,10 +37,10 @@ class JitDebugTest : public ::testing::Test {
protected:
void CreateFakeElf(MapInfo* map_info, uint64_t global_offset, uint64_t data_offset,
uint64_t data_vaddr, uint64_t data_size) {
- MemoryFake* memory = new MemoryFake;
- ElfFake* elf = new ElfFake(memory);
+ std::shared_ptr<Memory> fake_memory(new MemoryFake);
+ ElfFake* elf = new ElfFake(fake_memory);
elf->FakeSetValid(true);
- ElfInterfaceFake* interface = new ElfInterfaceFake(memory);
+ ElfInterfaceFake* interface = new ElfInterfaceFake(fake_memory);
elf->FakeSetInterface(interface);
interface->FakeSetGlobalVariable("__jit_debug_descriptor", global_offset);
interface->FakeSetDataOffset(data_offset);
diff --git a/libunwindstack/tests/MapInfoCreateMemoryTest.cpp b/libunwindstack/tests/MapInfoCreateMemoryTest.cpp
index 08e0d2b..cf44798 100644
--- a/libunwindstack/tests/MapInfoCreateMemoryTest.cpp
+++ b/libunwindstack/tests/MapInfoCreateMemoryTest.cpp
@@ -91,16 +91,16 @@ class MapInfoCreateMemoryTest : public ::testing::Test {
TEST_F(MapInfoCreateMemoryTest, end_le_start) {
auto info = MapInfo::Create(0x100, 0x100, 0, 0, elf_.path);
- std::unique_ptr<Memory> memory(info->CreateMemory(process_memory_));
+ auto memory = info->CreateMemory(process_memory_);
ASSERT_TRUE(memory.get() == nullptr);
info->set_end(0xff);
- memory.reset(info->CreateMemory(process_memory_));
+ memory = info->CreateMemory(process_memory_);
ASSERT_TRUE(memory.get() == nullptr);
// Make sure this test is valid.
info->set_end(0x101);
- memory.reset(info->CreateMemory(process_memory_));
+ memory = info->CreateMemory(process_memory_);
ASSERT_TRUE(memory.get() != nullptr);
EXPECT_FALSE(info->memory_backed_elf());
}
@@ -110,7 +110,7 @@ TEST_F(MapInfoCreateMemoryTest, end_le_start) {
TEST_F(MapInfoCreateMemoryTest, file_backed_non_zero_offset_full_file) {
auto info = MapInfo::Create(0x100, 0x200, 0x100, 0, elf_.path);
- std::unique_ptr<Memory> memory(info->CreateMemory(process_memory_));
+ auto memory = info->CreateMemory(process_memory_);
ASSERT_TRUE(memory.get() != nullptr);
EXPECT_FALSE(info->memory_backed_elf());
ASSERT_EQ(0x100U, info->elf_offset());
@@ -137,7 +137,7 @@ TEST_F(MapInfoCreateMemoryTest, file_backed_non_zero_offset_full_file) {
info->set_elf_offset(0);
info->set_elf_start_offset(0);
info->set_memory_backed_elf(false);
- memory.reset(info->CreateMemory(process_memory_));
+ memory = info->CreateMemory(process_memory_);
ASSERT_TRUE(memory.get() != nullptr);
EXPECT_FALSE(info->memory_backed_elf());
ASSERT_EQ(0x100U, info->elf_offset());
@@ -147,7 +147,7 @@ TEST_F(MapInfoCreateMemoryTest, file_backed_non_zero_offset_full_file) {
info->set_elf_offset(0);
info->set_elf_start_offset(0);
info->set_memory_backed_elf(false);
- memory.reset(info->CreateMemory(process_memory_));
+ memory = info->CreateMemory(process_memory_);
ASSERT_TRUE(memory.get() != nullptr);
EXPECT_FALSE(info->memory_backed_elf());
ASSERT_EQ(0x100U, info->elf_offset());
@@ -157,7 +157,7 @@ TEST_F(MapInfoCreateMemoryTest, file_backed_non_zero_offset_full_file) {
info->set_elf_offset(0);
info->set_elf_start_offset(0);
info->set_memory_backed_elf(false);
- memory.reset(info->CreateMemory(process_memory_));
+ memory = info->CreateMemory(process_memory_);
ASSERT_TRUE(memory.get() != nullptr);
EXPECT_FALSE(info->memory_backed_elf());
ASSERT_EQ(0x100U, info->elf_offset());
@@ -167,7 +167,7 @@ TEST_F(MapInfoCreateMemoryTest, file_backed_non_zero_offset_full_file) {
info->set_elf_offset(0);
info->set_elf_start_offset(0);
info->set_memory_backed_elf(false);
- memory.reset(info->CreateMemory(process_memory_));
+ memory = info->CreateMemory(process_memory_);
ASSERT_TRUE(memory.get() != nullptr);
EXPECT_FALSE(info->memory_backed_elf());
ASSERT_EQ(0x100U, info->elf_offset());
@@ -179,7 +179,7 @@ TEST_F(MapInfoCreateMemoryTest, file_backed_non_zero_offset_full_file) {
TEST_F(MapInfoCreateMemoryTest, file_backed_non_zero_offset_partial_file) {
auto info = MapInfo::Create(0x100, 0x200, 0x1000, 0, elf_at_1000_.path);
- std::unique_ptr<Memory> memory(info->CreateMemory(process_memory_));
+ auto memory = info->CreateMemory(process_memory_);
ASSERT_TRUE(memory.get() != nullptr);
EXPECT_FALSE(info->memory_backed_elf());
ASSERT_EQ(0U, info->elf_offset());
@@ -204,7 +204,7 @@ TEST_F(MapInfoCreateMemoryTest, file_backed_non_zero_offset_partial_file) {
TEST_F(MapInfoCreateMemoryTest, file_backed_non_zero_offset_partial_file_whole_elf32) {
auto info = MapInfo::Create(0x5000, 0x6000, 0x1000, 0, elf32_at_map_.path);
- std::unique_ptr<Memory> memory(info->CreateMemory(process_memory_));
+ auto memory = info->CreateMemory(process_memory_);
ASSERT_TRUE(memory.get() != nullptr);
EXPECT_FALSE(info->memory_backed_elf());
ASSERT_EQ(0U, info->elf_offset());
@@ -222,7 +222,7 @@ TEST_F(MapInfoCreateMemoryTest, file_backed_non_zero_offset_partial_file_whole_e
TEST_F(MapInfoCreateMemoryTest, file_backed_non_zero_offset_partial_file_whole_elf64) {
auto info = MapInfo::Create(0x7000, 0x8000, 0x2000, 0, elf64_at_map_.path);
- std::unique_ptr<Memory> memory(info->CreateMemory(process_memory_));
+ auto memory = info->CreateMemory(process_memory_);
ASSERT_TRUE(memory.get() != nullptr);
EXPECT_FALSE(info->memory_backed_elf());
ASSERT_EQ(0U, info->elf_offset());
@@ -245,7 +245,7 @@ TEST_F(MapInfoCreateMemoryTest, check_device_maps) {
uint64_t start = reinterpret_cast<uint64_t>(buffer.data());
auto info = MapInfo::Create(start, start + buffer.size(), 0, 0x8000, "/dev/something");
- std::unique_ptr<Memory> memory(info->CreateMemory(process_memory_));
+ auto memory = info->CreateMemory(process_memory_);
ASSERT_TRUE(memory.get() == nullptr);
}
@@ -264,7 +264,7 @@ TEST_F(MapInfoCreateMemoryTest, process_memory) {
}
memory_->SetMemory(info->start(), buffer.data(), buffer.size());
- std::unique_ptr<Memory> memory(info->CreateMemory(process_memory_));
+ auto memory = info->CreateMemory(process_memory_);
ASSERT_TRUE(memory.get() != nullptr);
EXPECT_TRUE(info->memory_backed_elf());
@@ -296,7 +296,7 @@ TEST_F(MapInfoCreateMemoryTest, valid_rosegment_zero_offset) {
auto map_info = maps.Find(0x3000).get();
ASSERT_TRUE(map_info != nullptr);
- std::unique_ptr<Memory> mem(map_info->CreateMemory(process_memory_));
+ auto mem = map_info->CreateMemory(process_memory_);
ASSERT_TRUE(mem.get() != nullptr);
EXPECT_TRUE(map_info->memory_backed_elf());
EXPECT_EQ(0x4000UL, map_info->elf_offset());
@@ -343,7 +343,7 @@ TEST_F(MapInfoCreateMemoryTest, valid_rosegment_non_zero_offset) {
auto map_info = maps.Find(0x4000).get();
ASSERT_TRUE(map_info != nullptr);
- std::unique_ptr<Memory> mem(map_info->CreateMemory(process_memory_));
+ auto mem = map_info->CreateMemory(process_memory_);
ASSERT_TRUE(mem.get() != nullptr);
EXPECT_TRUE(map_info->memory_backed_elf());
EXPECT_EQ(0x1000UL, map_info->elf_offset());
@@ -380,7 +380,7 @@ TEST_F(MapInfoCreateMemoryTest, valid_single_rx_non_zero_offset) {
auto map_info = maps.Find(0x3000);
ASSERT_TRUE(map_info != nullptr);
- std::unique_ptr<Memory> mem(map_info->CreateMemory(process_memory_));
+ auto mem = map_info->CreateMemory(process_memory_);
ASSERT_TRUE(mem.get() != nullptr);
EXPECT_TRUE(map_info->memory_backed_elf());
EXPECT_EQ(0UL, map_info->elf_offset());
@@ -413,7 +413,7 @@ TEST_F(MapInfoCreateMemoryTest, rosegment_from_file) {
// Will not give the elf memory, because the read-only entry does not
// extend over the executable segment.
- std::unique_ptr<Memory> memory(map_info->CreateMemory(process_memory_));
+ auto memory = map_info->CreateMemory(process_memory_);
ASSERT_TRUE(memory.get() != nullptr);
EXPECT_FALSE(map_info->memory_backed_elf());
std::vector<uint8_t> buffer(0x100);
@@ -431,7 +431,7 @@ TEST_F(MapInfoCreateMemoryTest, rosegment_from_file) {
ASSERT_TRUE(android::base::WriteFully(elf_at_1000_.fd, &ehdr, sizeof(ehdr)));
map_info->set_memory_backed_elf(false);
- memory.reset(map_info->CreateMemory(process_memory_));
+ memory = map_info->CreateMemory(process_memory_);
EXPECT_FALSE(map_info->memory_backed_elf());
EXPECT_EQ(0x2000U, map_info->offset());
EXPECT_EQ(0x1000U, map_info->elf_offset());
@@ -458,7 +458,7 @@ TEST_F(MapInfoCreateMemoryTest, valid_rosegment_offset_overflow) {
auto map_info = maps.Find(0x3000).get();
ASSERT_TRUE(map_info != nullptr);
- std::unique_ptr<Memory> mem(map_info->CreateMemory(process_memory_));
+ auto mem = map_info->CreateMemory(process_memory_);
ASSERT_TRUE(mem.get() != nullptr);
EXPECT_TRUE(map_info->memory_backed_elf());
EXPECT_EQ(0xfffffffffffff000UL, map_info->elf_offset());
diff --git a/libunwindstack/tests/MapInfoGetBuildIDTest.cpp b/libunwindstack/tests/MapInfoGetBuildIDTest.cpp
index 4877c68..35ba6f0 100644
--- a/libunwindstack/tests/MapInfoGetBuildIDTest.cpp
+++ b/libunwindstack/tests/MapInfoGetBuildIDTest.cpp
@@ -46,19 +46,16 @@ class MapInfoGetBuildIDTest : public ::testing::Test {
void SetUp() override {
tf_.reset(new TemporaryFile);
- memory_ = new MemoryFake;
- elf_ = new ElfFake(new MemoryFake);
- elf_interface_ = new ElfInterfaceFake(memory_);
+ std::shared_ptr<Memory> memory(new MemoryFake);
+ elf_ = new ElfFake(memory);
+ elf_interface_ = new ElfInterfaceFake(memory);
elf_->FakeSetInterface(elf_interface_);
elf_container_.reset(elf_);
map_info_ = MapInfo::Create(0x1000, 0x20000, 0, PROT_READ | PROT_WRITE, tf_->path);
}
- void TearDown() override { delete memory_; }
-
void MultipleThreadTest(std::string expected_build_id);
- MemoryFake* memory_;
ElfFake* elf_;
ElfInterfaceFake* elf_interface_;
std::unique_ptr<ElfFake> elf_container_;
diff --git a/libunwindstack/tests/MapInfoGetLoadBiasTest.cpp b/libunwindstack/tests/MapInfoGetLoadBiasTest.cpp
index a0aca4f..5c320c9 100644
--- a/libunwindstack/tests/MapInfoGetLoadBiasTest.cpp
+++ b/libunwindstack/tests/MapInfoGetLoadBiasTest.cpp
@@ -48,7 +48,8 @@ class MapInfoGetLoadBiasTest : public ::testing::Test {
void SetUp() override {
memory_ = new MemoryFake;
process_memory_.reset(memory_);
- elf_ = new ElfFake(new MemoryFake);
+ std::shared_ptr<Memory> memory(new MemoryFake);
+ elf_ = new ElfFake(memory);
elf_container_.reset(elf_);
map_info_ = MapInfo::Create(0x1000, 0x20000, 0, PROT_READ | PROT_WRITE, "");
}
diff --git a/libunwindstack/tests/MapInfoTest.cpp b/libunwindstack/tests/MapInfoTest.cpp
index 9cfbb44..d578976 100644
--- a/libunwindstack/tests/MapInfoTest.cpp
+++ b/libunwindstack/tests/MapInfoTest.cpp
@@ -124,8 +124,9 @@ TEST(MapInfoTest, real_map_check) {
}
TEST(MapInfoTest, get_function_name) {
- ElfFake* elf = new ElfFake(nullptr);
- ElfInterfaceFake* interface = new ElfInterfaceFake(nullptr);
+ std::shared_ptr<Memory> empty;
+ ElfFake* elf = new ElfFake(empty);
+ ElfInterfaceFake* interface = new ElfInterfaceFake(empty);
elf->FakeSetInterface(interface);
interface->FakePushFunctionData(FunctionData("function", 1000));
diff --git a/libunwindstack/tests/RegsStepIfSignalHandlerTest.cpp b/libunwindstack/tests/RegsStepIfSignalHandlerTest.cpp
index 1238848..a6ab89d 100644
--- a/libunwindstack/tests/RegsStepIfSignalHandlerTest.cpp
+++ b/libunwindstack/tests/RegsStepIfSignalHandlerTest.cpp
@@ -16,6 +16,8 @@
#include <stdint.h>
+#include <memory>
+
#include <gtest/gtest.h>
#include <unwindstack/Elf.h>
@@ -37,14 +39,15 @@ namespace unwindstack {
class RegsStepIfSignalHandlerTest : public ::testing::Test {
protected:
void SetUp() override {
- elf_memory_ = new MemoryFake;
- elf_.reset(new Elf(elf_memory_));
+ fake_memory_ = new MemoryFake;
+ std::shared_ptr<Memory> memory(fake_memory_);
+ elf_.reset(new Elf(memory));
}
void ArmStepIfSignalHandlerNonRt(uint32_t pc_data);
void ArmStepIfSignalHandlerRt(uint32_t pc_data);
- MemoryFake* elf_memory_;
+ MemoryFake* fake_memory_;
MemoryFake process_memory_;
std::unique_ptr<Elf> elf_;
};
@@ -55,7 +58,7 @@ void RegsStepIfSignalHandlerTest::ArmStepIfSignalHandlerNonRt(uint32_t pc_data)
regs[ARM_REG_PC] = 0x5000;
regs[ARM_REG_SP] = addr;
- elf_memory_->SetData32(0x5000, pc_data);
+ fake_memory_->SetData32(0x5000, pc_data);
for (uint64_t index = 0; index <= 30; index++) {
process_memory_.SetData32(addr + index * 4, index * 0x10);
@@ -85,7 +88,7 @@ void RegsStepIfSignalHandlerTest::ArmStepIfSignalHandlerRt(uint32_t pc_data) {
regs[ARM_REG_PC] = 0x5000;
regs[ARM_REG_SP] = addr;
- elf_memory_->SetData32(0x5000, pc_data);
+ fake_memory_->SetData32(0x5000, pc_data);
for (uint64_t index = 0; index <= 100; index++) {
process_memory_.SetData32(addr + index * 4, index * 0x10);
@@ -115,7 +118,7 @@ TEST_F(RegsStepIfSignalHandlerTest, arm64_step_if_signal_handler) {
regs[ARM64_REG_PC] = 0x8000;
regs[ARM64_REG_SP] = addr;
- elf_memory_->SetData64(0x8000, 0xd4000001d2801168ULL);
+ fake_memory_->SetData64(0x8000, 0xd4000001d2801168ULL);
for (uint64_t index = 0; index <= 100; index++) {
process_memory_.SetData64(addr + index * 8, index * 0x10);
@@ -134,7 +137,7 @@ TEST_F(RegsStepIfSignalHandlerTest, riscv64_step_if_signal_handler) {
regs[RISCV64_REG_PC] = 0x8000;
regs[RISCV64_REG_SP] = addr;
- elf_memory_->SetData64(0x8000, 0x0000007308b00893ULL);
+ fake_memory_->SetData64(0x8000, 0x0000007308b00893ULL);
for (uint64_t index = 0; index <= 100; index++) {
process_memory_.SetData64(addr + index * 8, index * 0x10);
@@ -153,7 +156,7 @@ TEST_F(RegsStepIfSignalHandlerTest, x86_step_if_signal_handler_no_siginfo) {
regs[X86_REG_EIP] = 0x4100;
regs[X86_REG_ESP] = addr;
- elf_memory_->SetData64(0x4100, 0x80cd00000077b858ULL);
+ fake_memory_->SetData64(0x4100, 0x80cd00000077b858ULL);
for (uint64_t index = 0; index <= 25; index++) {
process_memory_.SetData32(addr + index * 4, index * 0x10);
}
@@ -176,7 +179,7 @@ TEST_F(RegsStepIfSignalHandlerTest, x86_step_if_signal_handler_siginfo) {
regs[X86_REG_EIP] = 0x4100;
regs[X86_REG_ESP] = addr;
- elf_memory_->SetData64(0x4100, 0x0080cd000000adb8ULL);
+ fake_memory_->SetData64(0x4100, 0x0080cd000000adb8ULL);
addr += 8;
// Pointer to ucontext data.
process_memory_.SetData32(addr, 0x8100);
@@ -204,8 +207,8 @@ TEST_F(RegsStepIfSignalHandlerTest, x86_64_step_if_signal_handler) {
regs[X86_64_REG_RIP] = 0x7000;
regs[X86_64_REG_RSP] = addr;
- elf_memory_->SetData64(0x7000, 0x0f0000000fc0c748);
- elf_memory_->SetData16(0x7008, 0x0f05);
+ fake_memory_->SetData64(0x7000, 0x0f0000000fc0c748);
+ fake_memory_->SetData16(0x7008, 0x0f05);
for (uint64_t index = 0; index <= 30; index++) {
process_memory_.SetData64(addr + index * 8, index * 0x10);
diff --git a/libunwindstack/tests/RegsTest.cpp b/libunwindstack/tests/RegsTest.cpp
index 6fd2c2a..a2c5e30 100644
--- a/libunwindstack/tests/RegsTest.cpp
+++ b/libunwindstack/tests/RegsTest.cpp
@@ -38,14 +38,15 @@ namespace unwindstack {
class RegsTest : public ::testing::Test {
protected:
void SetUp() override {
- memory_ = new MemoryFake;
- elf_.reset(new ElfFake(memory_));
- elf_interface_ = new ElfInterfaceFake(elf_->memory());
+ fake_memory_ = new MemoryFake;
+ std::shared_ptr<Memory> memory(fake_memory_);
+ elf_.reset(new ElfFake(memory));
+ elf_interface_ = new ElfInterfaceFake(memory);
elf_->FakeSetInterface(elf_interface_);
}
ElfInterfaceFake* elf_interface_;
- MemoryFake* memory_;
+ MemoryFake* fake_memory_;
std::unique_ptr<ElfFake> elf_;
};
@@ -142,21 +143,22 @@ TEST_F(RegsTest, rel_pc_arm) {
// Check thumb instructions handling.
elf_->FakeSetLoadBias(0);
- memory_->SetData32(0x2000, 0);
+ fake_memory_->SetData32(0x2000, 0);
EXPECT_EQ(2U, GetPcAdjustment(0x2005, elf_.get(), ARCH_ARM));
- memory_->SetData32(0x2000, 0xe000f000);
+ fake_memory_->SetData32(0x2000, 0xe000f000);
EXPECT_EQ(4U, GetPcAdjustment(0x2005, elf_.get(), ARCH_ARM));
elf_->FakeSetLoadBias(0x400);
- memory_->SetData32(0x2100, 0);
+ fake_memory_->SetData32(0x2100, 0);
EXPECT_EQ(2U, GetPcAdjustment(0x2505, elf_.get(), ARCH_ARM));
- memory_->SetData32(0x2100, 0xf111f111);
+ fake_memory_->SetData32(0x2100, 0xf111f111);
EXPECT_EQ(4U, GetPcAdjustment(0x2505, elf_.get(), ARCH_ARM));
}
TEST_F(RegsTest, elf_invalid) {
auto map_info = MapInfo::Create(0x1000, 0x2000, 0, 0, "");
- Elf* invalid_elf = new Elf(nullptr);
+ std::shared_ptr<Memory> empty;
+ Elf* invalid_elf = new Elf(empty);
map_info->set_elf(invalid_elf);
EXPECT_EQ(0x500U, invalid_elf->GetRelPc(0x1500, map_info.get()));
diff --git a/libunwindstack/tests/UnwinderTest.cpp b/libunwindstack/tests/UnwinderTest.cpp
index 12d982f..598afcc 100644
--- a/libunwindstack/tests/UnwinderTest.cpp
+++ b/libunwindstack/tests/UnwinderTest.cpp
@@ -66,8 +66,11 @@ class UnwinderTest : public ::testing::Test {
ElfInterfaceFake* interface;
MapInfo* map_info;
- elf = new ElfFake(new MemoryFake);
- interface = new ElfInterfaceFake(nullptr);
+ std::shared_ptr<Memory> empty;
+ std::shared_ptr<Memory> elf_memory(new MemoryFake);
+
+ elf = new ElfFake(elf_memory);
+ interface = new ElfInterfaceFake(empty);
interface->FakeSetBuildID("FAKE");
elf->FakeSetInterface(interface);
AddMapInfo(0x1000, 0x8000, 0, PROT_READ | PROT_WRITE, "/system/fake/libc.so", elf);
@@ -77,20 +80,20 @@ class UnwinderTest : public ::testing::Test {
AddMapInfo(0x13000, 0x15000, 0, PROT_READ | PROT_WRITE | MAPS_FLAGS_DEVICE_MAP,
"/dev/fake_device");
- elf = new ElfFake(new MemoryFake);
- elf->FakeSetInterface(new ElfInterfaceFake(nullptr));
+ elf = new ElfFake(elf_memory);
+ elf->FakeSetInterface(new ElfInterfaceFake(empty));
AddMapInfo(0x20000, 0x22000, 0, PROT_READ | PROT_WRITE, "/system/fake/libunwind.so", elf);
- elf = new ElfFake(new MemoryFake);
- elf->FakeSetInterface(new ElfInterfaceFake(nullptr));
+ elf = new ElfFake(elf_memory);
+ elf->FakeSetInterface(new ElfInterfaceFake(empty));
AddMapInfo(0x23000, 0x24000, 0, PROT_READ | PROT_WRITE, "/fake/libanother.so", elf);
- elf = new ElfFake(new MemoryFake);
- elf->FakeSetInterface(new ElfInterfaceFake(nullptr));
+ elf = new ElfFake(elf_memory);
+ elf->FakeSetInterface(new ElfInterfaceFake(empty));
AddMapInfo(0x33000, 0x34000, 0, PROT_READ | PROT_WRITE, "/fake/compressed.so", elf);
- elf = new ElfFake(new MemoryFake);
- interface = new ElfInterfaceFake(nullptr);
+ elf = new ElfFake(elf_memory);
+ interface = new ElfInterfaceFake(empty);
interface->FakeSetSoname("lib_fake.so");
elf->FakeSetInterface(interface);
map_info = AddMapInfo(0x43000, 0x44000, 0x1d000, PROT_READ | PROT_WRITE, "/fake/fake.apk", elf);
@@ -100,36 +103,36 @@ class UnwinderTest : public ::testing::Test {
AddMapInfo(0xa3000, 0xa4000, 0, PROT_READ | PROT_WRITE | PROT_EXEC, "/fake/fake.vdex");
- elf = new ElfFake(new MemoryFake);
- elf->FakeSetInterface(new ElfInterfaceFake(nullptr));
+ elf = new ElfFake(elf_memory);
+ elf->FakeSetInterface(new ElfInterfaceFake(empty));
elf->FakeSetLoadBias(0x5000);
AddMapInfo(0xa5000, 0xa6000, 0, PROT_READ | PROT_WRITE | PROT_EXEC, "/fake/fake_load_bias.so",
elf);
- elf = new ElfFake(new MemoryFake);
- elf->FakeSetInterface(new ElfInterfaceFake(nullptr));
+ elf = new ElfFake(elf_memory);
+ elf->FakeSetInterface(new ElfInterfaceFake(empty));
map_info = AddMapInfo(0xa7000, 0xa8000, 0, PROT_READ | PROT_WRITE | PROT_EXEC,
"/fake/fake_offset.oat", elf);
map_info->set_elf_offset(0x8000);
- elf = new ElfFake(new MemoryFake);
- elf->FakeSetInterface(new ElfInterfaceFake(nullptr));
+ elf = new ElfFake(elf_memory);
+ elf->FakeSetInterface(new ElfInterfaceFake(empty));
map_info = AddMapInfo(0xc0000, 0xc1000, 0, PROT_READ | PROT_WRITE | PROT_EXEC,
"/fake/unreadable.so", elf);
map_info->set_memory_backed_elf(true);
- elf = new ElfFake(new MemoryFake);
- elf->FakeSetInterface(new ElfInterfaceFake(nullptr));
+ elf = new ElfFake(elf_memory);
+ elf->FakeSetInterface(new ElfInterfaceFake(empty));
map_info = AddMapInfo(0xc1000, 0xc2000, 0, PROT_READ | PROT_WRITE | PROT_EXEC, "[vdso]", elf);
map_info->set_memory_backed_elf(true);
- elf = new ElfFake(new MemoryFake);
- elf->FakeSetInterface(new ElfInterfaceFake(nullptr));
+ elf = new ElfFake(elf_memory);
+ elf->FakeSetInterface(new ElfInterfaceFake(empty));
map_info = AddMapInfo(0xc2000, 0xc3000, 0, PROT_READ | PROT_WRITE | PROT_EXEC, "", elf);
map_info->set_memory_backed_elf(true);
- elf = new ElfFake(new MemoryFake);
- elf->FakeSetInterface(new ElfInterfaceFake(nullptr));
+ elf = new ElfFake(elf_memory);
+ elf->FakeSetInterface(new ElfInterfaceFake(empty));
map_info = AddMapInfo(0xc3000, 0xc4000, 0, PROT_READ | PROT_WRITE | PROT_EXEC,
"/memfd:/jit-cache", elf);
map_info->set_memory_backed_elf(true);
@@ -138,8 +141,8 @@ class UnwinderTest : public ::testing::Test {
AddMapInfo(0xd0000, 0xd1000, 0x1000, PROT_READ | PROT_WRITE | PROT_EXEC, "/fake/fake.apk");
map_info->set_elf_start_offset(0x1000);
- elf = new ElfFake(new MemoryFake);
- interface = new ElfInterfaceFake(nullptr);
+ elf = new ElfFake(elf_memory);
+ interface = new ElfInterfaceFake(empty);
elf->FakeSetInterface(interface);
interface->FakeSetGlobalVariable("__dex_debug_descriptor", 0x1800);
interface->FakeSetGlobalVariable("__jit_debug_descriptor", 0x1900);
@@ -164,7 +167,7 @@ class UnwinderTest : public ::testing::Test {
memory_->SetData32(0xf600c, 0);
memory_->SetData64(0xf6010, 0x1000);
- elf = new ElfFake(new MemoryFake);
+ elf = new ElfFake(elf_memory);
elf->FakeSetValid(false);
elf->FakeSetLoadBias(0x300);
map_info = AddMapInfo(0x100000, 0x101000, 0x1000, PROT_READ | PROT_WRITE | PROT_EXEC,
diff --git a/libunwindstack/tests/VerifyBionicTerminationTest.cpp b/libunwindstack/tests/VerifyBionicTerminationTest.cpp
index ff105c4..4a93e2d 100644
--- a/libunwindstack/tests/VerifyBionicTerminationTest.cpp
+++ b/libunwindstack/tests/VerifyBionicTerminationTest.cpp
@@ -38,7 +38,8 @@
namespace unwindstack {
static std::string DumpFrames(const UnwinderFromPid& unwinder) {
- std::string unwind;
+ // Init this way so that the first frame of the backtrace starts on a new line.
+ std::string unwind("\n");
for (size_t i = 0; i < unwinder.NumFrames(); i++) {
unwind += unwinder.FormatFrame(i) + '\n';
}
@@ -69,7 +70,8 @@ static DwarfLocationEnum GetReturnAddressLocation(uint64_t rel_pc, DwarfSection*
static void VerifyReturnAddress(const FrameData& frame) {
// Now go and find information about the register data and verify that the relative pc results in
// an undefined register.
- Elf elf(Memory::CreateFileMemory(frame.map_info->name(), 0).release());
+ auto file_memory = Memory::CreateFileMemory(frame.map_info->name(), 0);
+ Elf elf(file_memory);
ASSERT_TRUE(frame.map_info != nullptr);
ASSERT_TRUE(elf.Init()) << "Failed to init elf object from " << frame.map_info->name().c_str();
ASSERT_TRUE(elf.valid()) << "Elf " << frame.map_info->name().c_str() << " is not valid.";
diff --git a/libunwindstack/tests/fuzz/UnwinderComponentCreator.cpp b/libunwindstack/tests/fuzz/UnwinderComponentCreator.cpp
index c73705d..9da2df2 100644
--- a/libunwindstack/tests/fuzz/UnwinderComponentCreator.cpp
+++ b/libunwindstack/tests/fuzz/UnwinderComponentCreator.cpp
@@ -86,10 +86,12 @@ void ElfPushFakeStepData(FuzzedDataProvider* data_provider) {
ElfFake* PopulateElfFake(FuzzedDataProvider* data_provider) {
// This will be passed to a smart pointer in ElfAddMapInfo.
- ElfFake* elf = new ElfFake(new MemoryFake);
+ std::shared_ptr<Memory> memory(new MemoryFake);
+ ElfFake* elf = new ElfFake(memory);
// This will be handled by a smart pointer within Elf.
- ElfInterfaceFake* interface_fake = new ElfInterfaceFake(nullptr);
+ std::shared_ptr<Memory> empty;
+ ElfInterfaceFake* interface_fake = new ElfInterfaceFake(empty);
std::string build_id = data_provider->ConsumeRandomLengthString(kMaxBuildIdLen);
interface_fake->FakeSetBuildID(build_id);
std::string so_name = data_provider->ConsumeRandomLengthString(kMaxSoNameLen);
diff --git a/libunwindstack/tools/unwind_info.cpp b/libunwindstack/tools/unwind_info.cpp
index adc93b4..668dc56 100644
--- a/libunwindstack/tools/unwind_info.cpp
+++ b/libunwindstack/tools/unwind_info.cpp
@@ -26,6 +26,8 @@
#include <sys/types.h>
#include <unistd.h>
+#include <string>
+
#include <unwindstack/DwarfSection.h>
#include <unwindstack/DwarfStructs.h>
#include <unwindstack/Elf.h>
@@ -62,7 +64,7 @@ void DumpArm(Elf* elf, ElfInterfaceArm* interface) {
printf(" Cannot find entry for address.\n");
continue;
}
- ArmExidx arm(nullptr, interface->memory(), nullptr);
+ ArmExidx arm(nullptr, interface->memory().get(), nullptr);
arm.set_log(ARM_LOG_FULL);
arm.set_log_skip_execution(true);
arm.set_log_indent(2);
@@ -103,7 +105,8 @@ void DumpDwarfSection(Elf* elf, DwarfSection* section, uint64_t) {
}
int GetElfInfo(const char* file, uint64_t offset) {
- Elf elf(Memory::CreateFileMemory(file, offset).release());
+ auto elf_memory = Memory::CreateFileMemory(file, offset);
+ Elf elf(elf_memory);
if (!elf.Init() || !elf.valid()) {
printf("%s is not a valid elf file.\n", file);
return 1;
diff --git a/libunwindstack/tools/unwind_reg_info.cpp b/libunwindstack/tools/unwind_reg_info.cpp
index da34dc8..b483759 100644
--- a/libunwindstack/tools/unwind_reg_info.cpp
+++ b/libunwindstack/tools/unwind_reg_info.cpp
@@ -26,6 +26,12 @@
#include <sys/types.h>
#include <unistd.h>
+#include <algorithm>
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
#include <unwindstack/DwarfLocation.h>
#include <unwindstack/DwarfMemory.h>
#include <unwindstack/DwarfSection.h>
@@ -49,7 +55,8 @@ void PrintSignedValue(int64_t value) {
}
}
-void PrintExpression(Memory* memory, uint8_t class_type, uint64_t end, uint64_t length) {
+void PrintExpression(std::shared_ptr<Memory>& memory, uint8_t class_type, uint64_t end,
+ uint64_t length) {
std::vector<std::string> lines;
DwarfMemory dwarf_memory(memory);
if (class_type == ELFCLASS32) {
@@ -64,8 +71,8 @@ void PrintExpression(Memory* memory, uint8_t class_type, uint64_t end, uint64_t
}
}
-void PrintRegInformation(DwarfSection* section, Memory* memory, uint64_t pc, uint8_t class_type,
- ArchEnum arch) {
+void PrintRegInformation(DwarfSection* section, std::shared_ptr<Memory>&& memory, uint64_t pc,
+ uint8_t class_type, ArchEnum arch) {
const DwarfFde* fde = section->GetFdeFromPc(pc);
if (fde == nullptr) {
printf(" No fde found.\n");
@@ -152,7 +159,7 @@ void PrintArmRegInformation(ElfInterfaceArm* interface, uint64_t pc) {
return;
}
- ArmExidx arm(nullptr, interface->memory(), nullptr);
+ ArmExidx arm(nullptr, interface->memory().get(), nullptr);
arm.set_log(ARM_LOG_BY_REG);
arm.set_log_skip_execution(true);
@@ -171,7 +178,8 @@ void PrintArmRegInformation(ElfInterfaceArm* interface, uint64_t pc) {
}
int GetInfo(const char* file, uint64_t offset, uint64_t pc) {
- Elf elf(Memory::CreateFileMemory(file, offset).release());
+ auto elf_memory = Memory::CreateFileMemory(file, offset);
+ Elf elf(elf_memory);
if (!elf.Init() || !elf.valid()) {
printf("%s is not a valid elf file.\n", file);
return 1;
diff --git a/libunwindstack/tools/unwind_symbols.cpp b/libunwindstack/tools/unwind_symbols.cpp
index a888c0f..aca8939 100644
--- a/libunwindstack/tools/unwind_symbols.cpp
+++ b/libunwindstack/tools/unwind_symbols.cpp
@@ -23,6 +23,8 @@
#include <sys/types.h>
#include <unistd.h>
+#include <string>
+
#include <unwindstack/Elf.h>
#include <unwindstack/Log.h>
#include <unwindstack/Memory.h>
@@ -56,7 +58,8 @@ int main(int argc, char** argv) {
}
}
- unwindstack::Elf elf(unwindstack::Memory::CreateFileMemory(argv[1], 0).release());
+ auto elf_memory = unwindstack::Memory::CreateFileMemory(argv[1], 0);
+ unwindstack::Elf elf(elf_memory);
if (!elf.Init() || !elf.valid()) {
printf("%s is not a valid elf file.\n", argv[1]);
return 1;
diff --git a/libunwindstack/utils/DwarfSectionImplFake.h b/libunwindstack/utils/DwarfSectionImplFake.h
index 5b9eb0d..a7d741b 100644
--- a/libunwindstack/utils/DwarfSectionImplFake.h
+++ b/libunwindstack/utils/DwarfSectionImplFake.h
@@ -16,6 +16,8 @@
#pragma once
+#include <memory>
+
#include <unwindstack/DwarfSection.h>
#include <unwindstack/ElfInterface.h>
#include <unwindstack/Memory.h>
@@ -25,7 +27,7 @@ namespace unwindstack {
template <typename TypeParam>
class DwarfSectionImplFake : public DwarfSectionImpl<TypeParam> {
public:
- DwarfSectionImplFake(Memory* memory) : DwarfSectionImpl<TypeParam>(memory) {}
+ DwarfSectionImplFake(std::shared_ptr<Memory>& memory) : DwarfSectionImpl<TypeParam>(memory) {}
virtual ~DwarfSectionImplFake() = default;
bool Init(const SectionInfo&) override { return false; }