Merge "Doxygen format <android/log.h>."
diff --git a/debuggerd/Android.bp b/debuggerd/Android.bp
index fb8a205..5323524 100644
--- a/debuggerd/Android.bp
+++ b/debuggerd/Android.bp
@@ -114,6 +114,7 @@
"libbacktrace",
"libunwind",
"libunwindstack",
+ "libdexfile",
"liblzma",
"libcutils",
],
diff --git a/init/init.cpp b/init/init.cpp
index 95f272b..79623c3 100644
--- a/init/init.cpp
+++ b/init/init.cpp
@@ -110,12 +110,15 @@
if (!parser.ParseConfig("/system/etc/init")) {
late_import_paths.emplace_back("/system/etc/init");
}
- if (!parser.ParseConfig("/vendor/etc/init")) {
- late_import_paths.emplace_back("/vendor/etc/init");
+ if (!parser.ParseConfig("/product/etc/init")) {
+ late_import_paths.emplace_back("/product/etc/init");
}
if (!parser.ParseConfig("/odm/etc/init")) {
late_import_paths.emplace_back("/odm/etc/init");
}
+ if (!parser.ParseConfig("/vendor/etc/init")) {
+ late_import_paths.emplace_back("/vendor/etc/init");
+ }
} else {
parser.ParseConfig(bootscript);
}
diff --git a/init/property_service.cpp b/init/property_service.cpp
index 0cb9e63..fa28fa3 100644
--- a/init/property_service.cpp
+++ b/init/property_service.cpp
@@ -641,6 +641,7 @@
load_properties_from_file("/default.prop", NULL);
}
}
+ load_properties_from_file("/product/build.prop", NULL);
load_properties_from_file("/odm/default.prop", NULL);
load_properties_from_file("/vendor/default.prop", NULL);
diff --git a/libbacktrace/Android.bp b/libbacktrace/Android.bp
index d9eed76..94b1935 100644
--- a/libbacktrace/Android.bp
+++ b/libbacktrace/Android.bp
@@ -50,6 +50,7 @@
"BacktracePtrace.cpp",
"thread_utils.c",
"ThreadEntry.cpp",
+ "UnwindDexFile.cpp",
"UnwindStack.cpp",
"UnwindStackMap.cpp",
]
@@ -92,13 +93,27 @@
"liblog",
"libunwind",
"libunwindstack",
+ "libdexfile",
],
static_libs: ["libcutils"],
+
+ // libdexfile will eventually properly export headers, for now
+ // include these directly.
+ include_dirs: [
+ "art/runtime",
+ ],
+
+ header_libs: [ "jni_headers", ],
},
android: {
static_libs: ["libasync_safe"],
},
+ vendor: {
+ cflags: ["-DNO_LIBDEXFILE"],
+ exclude_srcs: ["UnwindDexFile.cpp"],
+ exclude_shared_libs: ["libdexfile"],
+ },
},
whole_static_libs: ["libdemangle"],
}
@@ -161,6 +176,8 @@
"backtrace_test.cpp",
"GetPss.cpp",
"thread_utils.c",
+
+ "unwind_dex_test.cpp",
],
cflags: [
@@ -172,6 +189,7 @@
shared_libs: [
"libbacktrace_test",
"libbacktrace",
+ "libdexfile",
"libbase",
"libcutils",
"liblog",
@@ -212,6 +230,12 @@
},
},
+ // libdexfile will eventually properly export headers, for now
+ // include these directly.
+ include_dirs: [
+ "art/runtime",
+ ],
+
data: [
"testdata/arm/*",
"testdata/arm64/*",
diff --git a/libbacktrace/UnwindDexFile.cpp b/libbacktrace/UnwindDexFile.cpp
new file mode 100644
index 0000000..5780fbb
--- /dev/null
+++ b/libbacktrace/UnwindDexFile.cpp
@@ -0,0 +1,162 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdint.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <memory>
+
+#include <android-base/unique_fd.h>
+
+#include <dex/code_item_accessors-no_art-inl.h>
+#include <dex/compact_dex_file.h>
+#include <dex/dex_file-inl.h>
+#include <dex/dex_file_loader.h>
+#include <dex/standard_dex_file.h>
+
+#include <unwindstack/MapInfo.h>
+#include <unwindstack/Memory.h>
+
+#include "UnwindDexFile.h"
+
+UnwindDexFile* UnwindDexFile::Create(uint64_t dex_file_offset_in_memory,
+ unwindstack::Memory* memory, unwindstack::MapInfo* info) {
+ if (!info->name.empty()) {
+ std::unique_ptr<UnwindDexFileFromFile> dex_file(new UnwindDexFileFromFile);
+ if (dex_file->Open(dex_file_offset_in_memory - info->start + info->offset, info->name)) {
+ return dex_file.release();
+ }
+ }
+
+ std::unique_ptr<UnwindDexFileFromMemory> dex_file(new UnwindDexFileFromMemory);
+ if (dex_file->Open(dex_file_offset_in_memory, memory)) {
+ return dex_file.release();
+ }
+ return nullptr;
+}
+
+void UnwindDexFile::GetMethodInformation(uint64_t dex_offset, std::string* method_name,
+ uint64_t* method_offset) {
+ if (dex_file_ == nullptr) {
+ return;
+ }
+
+ for (uint32_t i = 0; i < dex_file_->NumClassDefs(); ++i) {
+ const art::DexFile::ClassDef& class_def = dex_file_->GetClassDef(i);
+ const uint8_t* class_data = dex_file_->GetClassData(class_def);
+ if (class_data == nullptr) {
+ continue;
+ }
+ for (art::ClassDataItemIterator it(*dex_file_.get(), class_data); it.HasNext(); it.Next()) {
+ if (!it.IsAtMethod()) {
+ continue;
+ }
+ const art::DexFile::CodeItem* code_item = it.GetMethodCodeItem();
+ if (code_item == nullptr) {
+ continue;
+ }
+ art::CodeItemInstructionAccessor code(*dex_file_.get(), code_item);
+ if (!code.HasCodeItem()) {
+ continue;
+ }
+
+ uint64_t offset = reinterpret_cast<const uint8_t*>(code.Insns()) - dex_file_->Begin();
+ size_t size = code.InsnsSizeInCodeUnits() * sizeof(uint16_t);
+ if (offset <= dex_offset && dex_offset < offset + size) {
+ *method_name = dex_file_->PrettyMethod(it.GetMemberIndex(), false);
+ *method_offset = dex_offset - offset;
+ return;
+ }
+ }
+ }
+}
+
+UnwindDexFileFromFile::~UnwindDexFileFromFile() {
+ if (size_ != 0) {
+ munmap(mapped_memory_, size_);
+ }
+}
+
+bool UnwindDexFileFromFile::Open(uint64_t dex_file_offset_in_file, const std::string& file) {
+ android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(file.c_str(), O_RDONLY | O_CLOEXEC)));
+ if (fd == -1) {
+ return false;
+ }
+ struct stat buf;
+ if (fstat(fd, &buf) == -1) {
+ return false;
+ }
+ uint64_t length;
+ if (buf.st_size < 0 ||
+ __builtin_add_overflow(dex_file_offset_in_file, sizeof(art::DexFile::Header), &length) ||
+ static_cast<uint64_t>(buf.st_size) < length) {
+ return false;
+ }
+
+ mapped_memory_ = mmap(nullptr, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+ if (mapped_memory_ == MAP_FAILED) {
+ return false;
+ }
+ size_ = buf.st_size;
+
+ uint8_t* memory = reinterpret_cast<uint8_t*>(mapped_memory_);
+
+ art::DexFile::Header* header =
+ reinterpret_cast<art::DexFile::Header*>(&memory[dex_file_offset_in_file]);
+ if (!art::StandardDexFile::IsMagicValid(header->magic_) &&
+ !art::CompactDexFile::IsMagicValid(header->magic_)) {
+ return false;
+ }
+
+ if (__builtin_add_overflow(dex_file_offset_in_file, header->file_size_, &length) ||
+ static_cast<uint64_t>(buf.st_size) < length) {
+ return false;
+ }
+
+ art::DexFileLoader loader;
+ std::string error_msg;
+ auto dex = loader.Open(&memory[dex_file_offset_in_file], header->file_size_, "", 0, nullptr,
+ false, false, &error_msg);
+ dex_file_.reset(dex.release());
+ return dex_file_ != nullptr;
+}
+
+bool UnwindDexFileFromMemory::Open(uint64_t dex_file_offset_in_memory, unwindstack::Memory* memory) {
+ art::DexFile::Header header;
+ if (!memory->ReadFully(dex_file_offset_in_memory, &header, sizeof(header))) {
+ return false;
+ }
+
+ if (!art::StandardDexFile::IsMagicValid(header.magic_) &&
+ !art::CompactDexFile::IsMagicValid(header.magic_)) {
+ return false;
+ }
+
+ memory_.resize(header.file_size_);
+ if (!memory->ReadFully(dex_file_offset_in_memory, memory_.data(), header.file_size_)) {
+ return false;
+ }
+
+ art::DexFileLoader loader;
+ std::string error_msg;
+ auto dex =
+ loader.Open(memory_.data(), header.file_size_, "", 0, nullptr, false, false, &error_msg);
+ dex_file_.reset(dex.release());
+ return dex_file_ != nullptr;
+}
diff --git a/libbacktrace/UnwindDexFile.h b/libbacktrace/UnwindDexFile.h
new file mode 100644
index 0000000..dd70aba
--- /dev/null
+++ b/libbacktrace/UnwindDexFile.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _LIBBACKTRACE_UNWIND_DEX_FILE_H
+#define _LIBBACKTRACE_UNWIND_DEX_FILE_H
+
+#include <stdint.h>
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include <dex/dex_file-inl.h>
+
+namespace unwindstack {
+class Memory;
+struct MapInfo;
+} // namespace unwindstack
+
+class UnwindDexFile {
+ public:
+ UnwindDexFile() = default;
+ virtual ~UnwindDexFile() = default;
+
+ void GetMethodInformation(uint64_t dex_offset, std::string* method_name, uint64_t* method_offset);
+
+ static UnwindDexFile* Create(uint64_t dex_file_offset_in_memory, unwindstack::Memory* memory,
+ unwindstack::MapInfo* info);
+
+ protected:
+ std::unique_ptr<const art::DexFile> dex_file_;
+};
+
+class UnwindDexFileFromFile : public UnwindDexFile {
+ public:
+ UnwindDexFileFromFile() = default;
+ virtual ~UnwindDexFileFromFile();
+
+ bool Open(uint64_t dex_file_offset_in_file, const std::string& name);
+
+ private:
+ void* mapped_memory_ = nullptr;
+ size_t size_ = 0;
+};
+
+class UnwindDexFileFromMemory : public UnwindDexFile {
+ public:
+ UnwindDexFileFromMemory() = default;
+ virtual ~UnwindDexFileFromMemory() = default;
+
+ bool Open(uint64_t dex_file_offset_in_memory, unwindstack::Memory* memory);
+
+ private:
+ std::vector<uint8_t> memory_;
+};
+
+#endif // _LIBBACKTRACE_UNWIND_DEX_FILE_H
diff --git a/libbacktrace/UnwindStack.cpp b/libbacktrace/UnwindStack.cpp
index a748d1b..c5dd45b 100644
--- a/libbacktrace/UnwindStack.cpp
+++ b/libbacktrace/UnwindStack.cpp
@@ -40,9 +40,67 @@
#include <unwindstack/Unwinder.h>
#include "BacktraceLog.h"
+#ifndef NO_LIBDEXFILE
+#include "UnwindDexFile.h"
+#endif
#include "UnwindStack.h"
#include "UnwindStackMap.h"
+static void FillInDexFrame(UnwindStackMap* stack_map, uint64_t dex_pc,
+ backtrace_frame_data_t* frame) {
+ // The DEX PC points into the .dex section within an ELF file.
+ // However, this is a BBS section manually mmaped to a .vdex file,
+ // so we need to get the following map to find the ELF data.
+ unwindstack::Maps* maps = stack_map->stack_maps();
+ auto it = maps->begin();
+ uint64_t rel_dex_pc;
+ unwindstack::MapInfo* info;
+ for (; it != maps->end(); ++it) {
+ auto entry = *it;
+ if (dex_pc >= entry->start && dex_pc < entry->end) {
+ info = entry;
+ rel_dex_pc = dex_pc - entry->start;
+ frame->map.start = entry->start;
+ frame->map.end = entry->end;
+ frame->map.offset = entry->offset;
+ frame->map.load_bias = entry->load_bias;
+ frame->map.flags = entry->flags;
+ frame->map.name = entry->name;
+ frame->rel_pc = rel_dex_pc;
+ break;
+ }
+ }
+ if (it == maps->end() || ++it == maps->end()) {
+ return;
+ }
+
+ auto entry = *it;
+ auto process_memory = stack_map->process_memory();
+ unwindstack::Elf* elf = entry->GetElf(process_memory, true);
+ if (!elf->valid()) {
+ return;
+ }
+
+ // Adjust the relative dex by the offset.
+ rel_dex_pc += entry->elf_offset;
+
+ uint64_t dex_offset;
+ if (!elf->GetFunctionName(rel_dex_pc, &frame->func_name, &dex_offset)) {
+ return;
+ }
+ frame->func_offset = dex_offset;
+ if (frame->func_name != "$dexfile") {
+ return;
+ }
+
+#ifndef NO_LIBDEXFILE
+ UnwindDexFile* dex_file = stack_map->GetDexFile(dex_pc - dex_offset, info);
+ if (dex_file != nullptr) {
+ dex_file->GetMethodInformation(dex_offset, &frame->func_name, &frame->func_offset);
+ }
+#endif
+}
+
bool Backtrace::Unwind(unwindstack::Regs* regs, BacktraceMap* back_map,
std::vector<backtrace_frame_data_t>* frames, size_t num_ignore_frames,
std::vector<std::string>* skip_names) {
@@ -60,19 +118,44 @@
return true;
}
- frames->resize(unwinder.NumFrames() - num_ignore_frames);
auto unwinder_frames = unwinder.frames();
+ // Get the real number of frames we'll need.
+ size_t total_frames = 0;
+ for (size_t i = num_ignore_frames; i < unwinder.NumFrames(); i++, total_frames++) {
+ if (unwinder_frames[i].dex_pc != 0) {
+ total_frames++;
+ }
+ }
+ frames->resize(total_frames);
size_t cur_frame = 0;
- for (size_t i = num_ignore_frames; i < unwinder.NumFrames(); i++, cur_frame++) {
+ for (size_t i = num_ignore_frames; i < unwinder.NumFrames(); i++) {
auto frame = &unwinder_frames[i];
- backtrace_frame_data_t* back_frame = &frames->at(cur_frame);
- back_frame->num = frame->num - num_ignore_frames;
+ // Inject extra 'virtual' frame that represents the dex pc data.
+ // The dex pc is magic register defined in the Mterp interpreter,
+ // and thus it will be restored/observed in the frame after it.
+ // Adding the dex frame first here will create something like:
+ // #7 pc 006b1ba1 libartd.so ExecuteMterpImpl+14625
+ // #8 pc 0015fa20 core.vdex java.util.Arrays.binarySearch+8
+ // #9 pc 0039a1ef libartd.so art::interpreter::Execute+719
+ if (frame->dex_pc != 0) {
+ backtrace_frame_data_t* dex_frame = &frames->at(cur_frame++);
+ dex_frame->num = cur_frame;
+ dex_frame->pc = frame->dex_pc;
+ dex_frame->rel_pc = frame->dex_pc;
+ dex_frame->sp = frame->sp;
+ dex_frame->stack_size = 0;
+ dex_frame->func_offset = 0;
+ FillInDexFrame(stack_map, frame->dex_pc, dex_frame);
+ }
+
+ backtrace_frame_data_t* back_frame = &frames->at(cur_frame++);
+
+ back_frame->num = cur_frame;
back_frame->rel_pc = frame->rel_pc;
back_frame->pc = frame->pc;
back_frame->sp = frame->sp;
- back_frame->dex_pc = frame->dex_pc;
back_frame->func_name = demangle(frame->function_name.c_str());
back_frame->func_offset = frame->function_offset;
diff --git a/libbacktrace/UnwindStackMap.cpp b/libbacktrace/UnwindStackMap.cpp
index 60c7952..11ff84a 100644
--- a/libbacktrace/UnwindStackMap.cpp
+++ b/libbacktrace/UnwindStackMap.cpp
@@ -26,11 +26,20 @@
#include <unwindstack/MapInfo.h>
#include <unwindstack/Maps.h>
+#include "UnwindDexFile.h"
#include "UnwindStackMap.h"
//-------------------------------------------------------------------------
UnwindStackMap::UnwindStackMap(pid_t pid) : BacktraceMap(pid) {}
+UnwindStackMap::~UnwindStackMap() {
+#ifndef NO_LIBDEXFILE
+ for (auto& entry : dex_files_) {
+ delete entry.second;
+ }
+#endif
+}
+
bool UnwindStackMap::Build() {
if (pid_ == 0) {
pid_ = getpid();
@@ -118,6 +127,26 @@
return process_memory_;
}
+#ifdef NO_LIBDEXFILE
+UnwindDexFile* UnwindStackMap::GetDexFile(uint64_t, unwindstack::MapInfo*) {
+ return nullptr;
+}
+#else
+UnwindDexFile* UnwindStackMap::GetDexFile(uint64_t dex_file_offset, unwindstack::MapInfo* info) {
+ // Lock while we get the data.
+ std::lock_guard<std::mutex> guard(dex_lock_);
+ UnwindDexFile* dex_file;
+ auto entry = dex_files_.find(dex_file_offset);
+ if (entry == dex_files_.end()) {
+ dex_file = UnwindDexFile::Create(dex_file_offset, process_memory_.get(), info);
+ dex_files_[dex_file_offset] = dex_file;
+ } else {
+ dex_file = entry->second;
+ }
+ return dex_file;
+}
+#endif
+
//-------------------------------------------------------------------------
// BacktraceMap create function.
//-------------------------------------------------------------------------
diff --git a/libbacktrace/UnwindStackMap.h b/libbacktrace/UnwindStackMap.h
index 6b98809..a815aae 100644
--- a/libbacktrace/UnwindStackMap.h
+++ b/libbacktrace/UnwindStackMap.h
@@ -21,15 +21,20 @@
#include <sys/types.h>
#include <memory>
+#include <mutex>
+#include <unordered_map>
#include <backtrace/BacktraceMap.h>
#include <unwindstack/JitDebug.h>
#include <unwindstack/Maps.h>
+// Forward declarations.
+class UnwindDexFile;
+
class UnwindStackMap : public BacktraceMap {
public:
explicit UnwindStackMap(pid_t pid);
- ~UnwindStackMap() = default;
+ ~UnwindStackMap();
bool Build() override;
@@ -44,12 +49,18 @@
unwindstack::JitDebug* GetJitDebug() { return jit_debug_.get(); }
+ UnwindDexFile* GetDexFile(uint64_t dex_file_offset, unwindstack::MapInfo* info);
+
protected:
uint64_t GetLoadBias(size_t index) override;
std::unique_ptr<unwindstack::Maps> stack_maps_;
std::shared_ptr<unwindstack::Memory> process_memory_;
std::unique_ptr<unwindstack::JitDebug> jit_debug_;
+#ifndef NO_LIBDEXFILE
+ std::mutex dex_lock_;
+ std::unordered_map<uint64_t, UnwindDexFile*> dex_files_;
+#endif
};
#endif // _LIBBACKTRACE_UNWINDSTACK_MAP_H
diff --git a/libbacktrace/include/backtrace/Backtrace.h b/libbacktrace/include/backtrace/Backtrace.h
index 1b8ad19..18e9f61 100644
--- a/libbacktrace/include/backtrace/Backtrace.h
+++ b/libbacktrace/include/backtrace/Backtrace.h
@@ -81,7 +81,6 @@
uint64_t rel_pc; // The relative pc.
uint64_t sp; // The top of the stack.
size_t stack_size; // The size of the stack, zero indicate an unknown stack size.
- uint64_t dex_pc; // If non-zero, the Dex PC for the ART interpreter.
backtrace_map_t map; // The map associated with the given pc.
std::string func_name; // The function name associated with this pc, NULL if not found.
uint64_t func_offset; // pc relative to the start of the function, only valid if func_name is not
diff --git a/libbacktrace/unwind_dex_test.cpp b/libbacktrace/unwind_dex_test.cpp
new file mode 100644
index 0000000..449e662
--- /dev/null
+++ b/libbacktrace/unwind_dex_test.cpp
@@ -0,0 +1,273 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <unordered_map>
+
+#include <android-base/test_utils.h>
+
+#include <unwindstack/MapInfo.h>
+#include <unwindstack/Memory.h>
+
+#include <dex/code_item_accessors-no_art-inl.h>
+#include <dex/standard_dex_file.h>
+
+#include <gtest/gtest.h>
+
+#include "UnwindDexFile.h"
+
+class MemoryFake : public unwindstack::Memory {
+ public:
+ MemoryFake() = default;
+ virtual ~MemoryFake() = default;
+
+ size_t Read(uint64_t addr, void* buffer, size_t size) override;
+
+ void SetMemory(uint64_t addr, const void* memory, size_t length);
+
+ void Clear() { data_.clear(); }
+
+ private:
+ std::unordered_map<uint64_t, uint8_t> data_;
+};
+
+void MemoryFake::SetMemory(uint64_t addr, const void* memory, size_t length) {
+ const uint8_t* src = reinterpret_cast<const uint8_t*>(memory);
+ for (size_t i = 0; i < length; i++, addr++) {
+ auto value = data_.find(addr);
+ if (value != data_.end()) {
+ value->second = src[i];
+ } else {
+ data_.insert({addr, src[i]});
+ }
+ }
+}
+
+size_t MemoryFake::Read(uint64_t addr, void* memory, size_t size) {
+ uint8_t* dst = reinterpret_cast<uint8_t*>(memory);
+ for (size_t i = 0; i < size; i++, addr++) {
+ auto value = data_.find(addr);
+ if (value == data_.end()) {
+ return i;
+ }
+ dst[i] = value->second;
+ }
+ return size;
+}
+
+// Borrowed from art/dex/dex_file_test.cc.
+static constexpr uint32_t kDexData[] = {
+ 0x0a786564, 0x00383330, 0xc98b3ab8, 0xf3749d94, 0xaecca4d8, 0xffc7b09a, 0xdca9ca7f, 0x5be5deab,
+ 0x00000220, 0x00000070, 0x12345678, 0x00000000, 0x00000000, 0x0000018c, 0x00000008, 0x00000070,
+ 0x00000004, 0x00000090, 0x00000002, 0x000000a0, 0x00000000, 0x00000000, 0x00000003, 0x000000b8,
+ 0x00000001, 0x000000d0, 0x00000130, 0x000000f0, 0x00000122, 0x0000012a, 0x00000132, 0x00000146,
+ 0x00000151, 0x00000154, 0x00000158, 0x0000016d, 0x00000001, 0x00000002, 0x00000004, 0x00000006,
+ 0x00000004, 0x00000002, 0x00000000, 0x00000005, 0x00000002, 0x0000011c, 0x00000000, 0x00000000,
+ 0x00010000, 0x00000007, 0x00000001, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x00000000,
+ 0x00000003, 0x00000000, 0x0000017e, 0x00000000, 0x00010001, 0x00000001, 0x00000173, 0x00000004,
+ 0x00021070, 0x000e0000, 0x00010001, 0x00000000, 0x00000178, 0x00000001, 0x0000000e, 0x00000001,
+ 0x3c060003, 0x74696e69, 0x4c06003e, 0x6e69614d, 0x4c12003b, 0x6176616a, 0x6e616c2f, 0x624f2f67,
+ 0x7463656a, 0x4d09003b, 0x2e6e6961, 0x6176616a, 0x00560100, 0x004c5602, 0x6a4c5b13, 0x2f617661,
+ 0x676e616c, 0x7274532f, 0x3b676e69, 0x616d0400, 0x01006e69, 0x000e0700, 0x07000103, 0x0000000e,
+ 0x81000002, 0x01f00480, 0x02880901, 0x0000000c, 0x00000000, 0x00000001, 0x00000000, 0x00000001,
+ 0x00000008, 0x00000070, 0x00000002, 0x00000004, 0x00000090, 0x00000003, 0x00000002, 0x000000a0,
+ 0x00000005, 0x00000003, 0x000000b8, 0x00000006, 0x00000001, 0x000000d0, 0x00002001, 0x00000002,
+ 0x000000f0, 0x00001001, 0x00000001, 0x0000011c, 0x00002002, 0x00000008, 0x00000122, 0x00002003,
+ 0x00000002, 0x00000173, 0x00002000, 0x00000001, 0x0000017e, 0x00001000, 0x00000001, 0x0000018c,
+};
+
+TEST(UnwindDexTest, from_file_open_non_exist) {
+ UnwindDexFileFromFile dex_file;
+ ASSERT_FALSE(dex_file.Open(0, "/file/does/not/exist"));
+}
+
+TEST(UnwindDexTest, from_file_open_too_small) {
+ TemporaryFile tf;
+ ASSERT_TRUE(tf.fd != -1);
+
+ ASSERT_EQ(sizeof(art::DexFile::Header) - 2,
+ static_cast<size_t>(
+ TEMP_FAILURE_RETRY(write(tf.fd, kDexData, sizeof(art::DexFile::Header)) - 2)));
+
+ // Header too small.
+ UnwindDexFileFromFile dex_file;
+ ASSERT_FALSE(dex_file.Open(0, tf.path));
+
+ // Header correct, file too small.
+ ASSERT_EQ(0, lseek(tf.fd, 0, SEEK_SET));
+ ASSERT_EQ(sizeof(art::DexFile::Header), static_cast<size_t>(TEMP_FAILURE_RETRY(write(
+ tf.fd, kDexData, sizeof(art::DexFile::Header)))));
+ ASSERT_FALSE(dex_file.Open(0, tf.path));
+}
+
+TEST(UnwindDexTest, from_file_open) {
+ TemporaryFile tf;
+ ASSERT_TRUE(tf.fd != -1);
+
+ ASSERT_EQ(sizeof(kDexData),
+ static_cast<size_t>(TEMP_FAILURE_RETRY(write(tf.fd, kDexData, sizeof(kDexData)))));
+
+ UnwindDexFileFromFile dex_file;
+ ASSERT_TRUE(dex_file.Open(0, tf.path));
+}
+
+TEST(UnwindDexTest, from_file_open_non_zero_offset) {
+ TemporaryFile tf;
+ ASSERT_TRUE(tf.fd != -1);
+
+ ASSERT_EQ(0x100, lseek(tf.fd, 0x100, SEEK_SET));
+ ASSERT_EQ(sizeof(kDexData),
+ static_cast<size_t>(TEMP_FAILURE_RETRY(write(tf.fd, kDexData, sizeof(kDexData)))));
+
+ UnwindDexFileFromFile dex_file;
+ ASSERT_TRUE(dex_file.Open(0x100, tf.path));
+}
+
+TEST(UnwindDexTest, from_memory_fail_too_small_for_header) {
+ MemoryFake memory;
+
+ memory.SetMemory(0x1000, kDexData, sizeof(art::DexFile::Header) - 1);
+ UnwindDexFileFromMemory dex_file;
+
+ ASSERT_FALSE(dex_file.Open(0x1000, &memory));
+}
+
+TEST(UnwindDexTest, from_memory_fail_too_small_for_data) {
+ MemoryFake memory;
+
+ memory.SetMemory(0x1000, kDexData, sizeof(kDexData) - 2);
+ UnwindDexFileFromMemory dex_file;
+
+ ASSERT_FALSE(dex_file.Open(0x1000, &memory));
+}
+
+TEST(UnwindDexTest, from_memory_open) {
+ MemoryFake memory;
+
+ memory.SetMemory(0x1000, kDexData, sizeof(kDexData));
+ UnwindDexFileFromMemory dex_file;
+
+ ASSERT_TRUE(dex_file.Open(0x1000, &memory));
+}
+
+TEST(UnwindDexTest, create_using_file) {
+ TemporaryFile tf;
+ ASSERT_TRUE(tf.fd != -1);
+
+ ASSERT_EQ(0x500, lseek(tf.fd, 0x500, SEEK_SET));
+ ASSERT_EQ(sizeof(kDexData),
+ static_cast<size_t>(TEMP_FAILURE_RETRY(write(tf.fd, kDexData, sizeof(kDexData)))));
+
+ MemoryFake memory;
+ unwindstack::MapInfo info(0, 0x10000, 0, 0x5, tf.path);
+ std::unique_ptr<UnwindDexFile> dex_file(UnwindDexFile::Create(0x500, &memory, &info));
+ ASSERT_TRUE(dex_file != nullptr);
+}
+
+TEST(UnwindDexTest, create_using_file_non_zero_start) {
+ TemporaryFile tf;
+ ASSERT_TRUE(tf.fd != -1);
+
+ ASSERT_EQ(0x500, lseek(tf.fd, 0x500, SEEK_SET));
+ ASSERT_EQ(sizeof(kDexData),
+ static_cast<size_t>(TEMP_FAILURE_RETRY(write(tf.fd, kDexData, sizeof(kDexData)))));
+
+ MemoryFake memory;
+ unwindstack::MapInfo info(0x100, 0x10000, 0, 0x5, tf.path);
+ std::unique_ptr<UnwindDexFile> dex_file(UnwindDexFile::Create(0x600, &memory, &info));
+ ASSERT_TRUE(dex_file != nullptr);
+}
+
+TEST(UnwindDexTest, create_using_file_non_zero_offset) {
+ TemporaryFile tf;
+ ASSERT_TRUE(tf.fd != -1);
+
+ ASSERT_EQ(0x500, lseek(tf.fd, 0x500, SEEK_SET));
+ ASSERT_EQ(sizeof(kDexData),
+ static_cast<size_t>(TEMP_FAILURE_RETRY(write(tf.fd, kDexData, sizeof(kDexData)))));
+
+ MemoryFake memory;
+ unwindstack::MapInfo info(0x100, 0x10000, 0x200, 0x5, tf.path);
+ std::unique_ptr<UnwindDexFile> dex_file(UnwindDexFile::Create(0x400, &memory, &info));
+ ASSERT_TRUE(dex_file != nullptr);
+}
+
+TEST(UnwindDexTest, create_using_memory_empty_file) {
+ MemoryFake memory;
+ memory.SetMemory(0x4000, kDexData, sizeof(kDexData));
+ unwindstack::MapInfo info(0x100, 0x10000, 0x200, 0x5, "");
+ std::unique_ptr<UnwindDexFile> dex_file(UnwindDexFile::Create(0x4000, &memory, &info));
+ ASSERT_TRUE(dex_file != nullptr);
+}
+
+TEST(UnwindDexTest, create_using_memory_file_does_not_exist) {
+ MemoryFake memory;
+ memory.SetMemory(0x4000, kDexData, sizeof(kDexData));
+ unwindstack::MapInfo info(0x100, 0x10000, 0x200, 0x5, "/does/not/exist");
+ std::unique_ptr<UnwindDexFile> dex_file(UnwindDexFile::Create(0x4000, &memory, &info));
+ ASSERT_TRUE(dex_file != nullptr);
+}
+
+TEST(UnwindDexTest, create_using_memory_file_is_malformed) {
+ TemporaryFile tf;
+ ASSERT_TRUE(tf.fd != -1);
+
+ ASSERT_EQ(sizeof(kDexData) - 10,
+ static_cast<size_t>(TEMP_FAILURE_RETRY(write(tf.fd, kDexData, sizeof(kDexData) - 10))));
+
+ MemoryFake memory;
+ memory.SetMemory(0x4000, kDexData, sizeof(kDexData));
+ unwindstack::MapInfo info(0x4000, 0x10000, 0x200, 0x5, "/does/not/exist");
+ std::unique_ptr<UnwindDexFile> dex_file(UnwindDexFile::Create(0x4000, &memory, &info));
+ ASSERT_TRUE(dex_file != nullptr);
+
+ // Check it came from memory by clearing memory and verifying it fails.
+ memory.Clear();
+ dex_file.reset(UnwindDexFile::Create(0x4000, &memory, &info));
+ ASSERT_TRUE(dex_file == nullptr);
+}
+
+TEST(UnwindDexTest, get_method_not_opened) {
+ std::string method("something");
+ uint64_t method_offset = 100;
+ UnwindDexFile dex_file;
+ dex_file.GetMethodInformation(0x100, &method, &method_offset);
+ EXPECT_EQ("something", method);
+ EXPECT_EQ(100U, method_offset);
+}
+
+TEST(UnwindDexTest, get_method) {
+ MemoryFake memory;
+ memory.SetMemory(0x4000, kDexData, sizeof(kDexData));
+ unwindstack::MapInfo info(0x100, 0x10000, 0x200, 0x5, "");
+ std::unique_ptr<UnwindDexFile> dex_file(UnwindDexFile::Create(0x4000, &memory, &info));
+ ASSERT_TRUE(dex_file != nullptr);
+
+ std::string method;
+ uint64_t method_offset;
+ dex_file->GetMethodInformation(0x102, &method, &method_offset);
+ EXPECT_EQ("Main.<init>", method);
+ EXPECT_EQ(2U, method_offset);
+
+ method = "not_in_a_method";
+ method_offset = 0x123;
+ dex_file->GetMethodInformation(0x100000, &method, &method_offset);
+ EXPECT_EQ("not_in_a_method", method);
+ EXPECT_EQ(0x123U, method_offset);
+}
diff --git a/libcutils/fs_config.cpp b/libcutils/fs_config.cpp
index f45472e..a993d41 100644
--- a/libcutils/fs_config.cpp
+++ b/libcutils/fs_config.cpp
@@ -141,6 +141,7 @@
{ 00444, AID_ROOT, AID_ROOT, 0, odm_conf_file + 1 },
{ 00444, AID_ROOT, AID_ROOT, 0, oem_conf_dir + 1 },
{ 00444, AID_ROOT, AID_ROOT, 0, oem_conf_file + 1 },
+ { 00600, AID_ROOT, AID_ROOT, 0, "product/build.prop" },
{ 00750, AID_ROOT, AID_SHELL, 0, "sbin/fs_mgr" },
{ 00755, AID_ROOT, AID_SHELL, 0, "system/bin/crash_dump32" },
{ 00755, AID_ROOT, AID_SHELL, 0, "system/bin/crash_dump64" },
diff --git a/libcutils/include/private/android_filesystem_config.h b/libcutils/include/private/android_filesystem_config.h
index 5753e49..fc354f1 100644
--- a/libcutils/include/private/android_filesystem_config.h
+++ b/libcutils/include/private/android_filesystem_config.h
@@ -125,6 +125,7 @@
#define AID_RESERVED_DISK 1065 /* GID that has access to reserved disk space */
#define AID_STATSD 1066 /* statsd daemon */
#define AID_INCIDENTD 1067 /* incidentd daemon */
+#define AID_SECURE_ELEMENT 1068 /* secure element subsystem */
/* Changes to this file must be made in AOSP, *not* in internal branches. */
#define AID_SHELL 2000 /* adb and debug shell user */
diff --git a/libnativeloader/native_loader.cpp b/libnativeloader/native_loader.cpp
index 6ddec4d..0ebb226 100644
--- a/libnativeloader/native_loader.cpp
+++ b/libnativeloader/native_loader.cpp
@@ -236,6 +236,10 @@
// Different name is useful for debugging
namespace_name = kVendorClassloaderNamespaceName;
ALOGD("classloader namespace configured for unbundled vendor apk. library_path=%s", library_path.c_str());
+ } else if (!oem_public_libraries_.empty()) {
+ // oem_public_libraries are NOT available to vendor apks, otherwise it
+ // would be system->vendor violation.
+ system_exposed_libraries = system_exposed_libraries + ":" + oem_public_libraries_.c_str();
}
NativeLoaderNamespace native_loader_ns;
@@ -353,9 +357,36 @@
"Error reading public native library list from \"%s\": %s",
public_native_libraries_system_config.c_str(), error_msg.c_str());
+ // For debuggable platform builds use ANDROID_ADDITIONAL_PUBLIC_LIBRARIES environment
+ // variable to add libraries to the list. This is intended for platform tests only.
+ if (is_debuggable()) {
+ const char* additional_libs = getenv("ANDROID_ADDITIONAL_PUBLIC_LIBRARIES");
+ if (additional_libs != nullptr && additional_libs[0] != '\0') {
+ std::vector<std::string> additional_libs_vector = base::Split(additional_libs, ":");
+ std::copy(additional_libs_vector.begin(), additional_libs_vector.end(),
+ std::back_inserter(sonames));
+ }
+ }
+
+ // android_init_namespaces() expects all the public libraries
+ // to be loaded so that they can be found by soname alone.
+ //
+ // TODO(dimitry): this is a bit misleading since we do not know
+ // if the vendor public library is going to be opened from /vendor/lib
+ // we might as well end up loading them from /system/lib
+ // For now we rely on CTS test to catch things like this but
+ // it should probably be addressed in the future.
+ for (const auto& soname : sonames) {
+ LOG_ALWAYS_FATAL_IF(dlopen(soname.c_str(), RTLD_NOW | RTLD_NODELETE) == nullptr,
+ "Error preloading public library %s: %s", soname.c_str(), dlerror());
+ }
+
+ system_public_libraries_ = base::Join(sonames, ':');
+
// read /system/etc/public.libraries-<companyname>.txt which contain partner defined
// system libs that are exposed to apps. The libs in the txt files must be
// named as lib<name>.<companyname>.so.
+ sonames.clear();
std::string dirname = base::Dirname(public_native_libraries_system_config);
std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(dirname.c_str()), closedir);
if (dir != nullptr) {
@@ -396,39 +427,12 @@
}
}
}
+ oem_public_libraries_ = base::Join(sonames, ':');
// Insert VNDK version to llndk and vndksp config file names.
insert_vndk_version_str(&llndk_native_libraries_system_config);
insert_vndk_version_str(&vndksp_native_libraries_system_config);
- // For debuggable platform builds use ANDROID_ADDITIONAL_PUBLIC_LIBRARIES environment
- // variable to add libraries to the list. This is intended for platform tests only.
- if (is_debuggable()) {
- const char* additional_libs = getenv("ANDROID_ADDITIONAL_PUBLIC_LIBRARIES");
- if (additional_libs != nullptr && additional_libs[0] != '\0') {
- std::vector<std::string> additional_libs_vector = base::Split(additional_libs, ":");
- std::copy(additional_libs_vector.begin(),
- additional_libs_vector.end(),
- std::back_inserter(sonames));
- }
- }
-
- // android_init_namespaces() expects all the public libraries
- // to be loaded so that they can be found by soname alone.
- //
- // TODO(dimitry): this is a bit misleading since we do not know
- // if the vendor public library is going to be opened from /vendor/lib
- // we might as well end up loading them from /system/lib
- // For now we rely on CTS test to catch things like this but
- // it should probably be addressed in the future.
- for (const auto& soname : sonames) {
- LOG_ALWAYS_FATAL_IF(dlopen(soname.c_str(), RTLD_NOW | RTLD_NODELETE) == nullptr,
- "Error preloading public library %s: %s",
- soname.c_str(), dlerror());
- }
-
- system_public_libraries_ = base::Join(sonames, ':');
-
sonames.clear();
ReadConfig(llndk_native_libraries_system_config, &sonames, always_true);
system_llndk_libraries_ = base::Join(sonames, ':');
@@ -554,6 +558,7 @@
std::vector<std::pair<jweak, NativeLoaderNamespace>> namespaces_;
std::string system_public_libraries_;
std::string vendor_public_libraries_;
+ std::string oem_public_libraries_;
std::string system_llndk_libraries_;
std::string system_vndksp_libraries_;
diff --git a/libnativeloader/test/Android.mk b/libnativeloader/test/Android.mk
index 4c3da4a..e625454 100644
--- a/libnativeloader/test/Android.mk
+++ b/libnativeloader/test/Android.mk
@@ -28,3 +28,23 @@
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)
include $(BUILD_PREBUILT)
+
+include $(CLEAR_VARS)
+LOCAL_PACKAGE_NAME := oemlibrarytest-system
+LOCAL_MODULE_TAGS := tests
+LOCAL_MANIFEST_FILE := system/AndroidManifest.xml
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+LOCAL_SDK_VERSION := current
+LOCAL_PROGUARD_ENABLED := disabled
+LOCAL_MODULE_PATH := $(TARGET_OUT_APPS)
+include $(BUILD_PACKAGE)
+
+include $(CLEAR_VARS)
+LOCAL_PACKAGE_NAME := oemlibrarytest-vendor
+LOCAL_MODULE_TAGS := tests
+LOCAL_MANIFEST_FILE := vendor/AndroidManifest.xml
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+LOCAL_SDK_VERSION := current
+LOCAL_PROGUARD_ENABLED := disabled
+LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_APPS)
+include $(BUILD_PACKAGE)
diff --git a/libnativeloader/test/runtest.sh b/libnativeloader/test/runtest.sh
new file mode 100755
index 0000000..40beb5b
--- /dev/null
+++ b/libnativeloader/test/runtest.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+adb root
+adb remount
+adb sync
+adb shell stop
+adb shell start
+sleep 5 # wait until device reboots
+adb logcat -c;
+adb shell am start -n android.test.app.system/android.test.app.TestActivity
+adb shell am start -n android.test.app.vendor/android.test.app.TestActivity
+adb logcat | grep android.test.app
diff --git a/libnativeloader/test/src/android/test/app/TestActivity.java b/libnativeloader/test/src/android/test/app/TestActivity.java
new file mode 100644
index 0000000..214892d
--- /dev/null
+++ b/libnativeloader/test/src/android/test/app/TestActivity.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.test.app;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.util.Log;
+
+public class TestActivity extends Activity {
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ tryLoadingLib("foo.oem1");
+ tryLoadingLib("bar.oem1");
+ tryLoadingLib("foo.oem2");
+ tryLoadingLib("bar.oem2");
+ }
+
+ private void tryLoadingLib(String name) {
+ try {
+ System.loadLibrary(name);
+ Log.d(getPackageName(), "library " + name + " is successfully loaded");
+ } catch (UnsatisfiedLinkError e) {
+ Log.d(getPackageName(), "failed to load libarary " + name, e);
+ }
+ }
+}
diff --git a/libnativeloader/test/system/AndroidManifest.xml b/libnativeloader/test/system/AndroidManifest.xml
new file mode 100644
index 0000000..c304889
--- /dev/null
+++ b/libnativeloader/test/system/AndroidManifest.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="android.test.app.system">
+
+ <application>
+ <activity android:name="android.test.app.TestActivity" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
+
diff --git a/libnativeloader/test/vendor/AndroidManifest.xml b/libnativeloader/test/vendor/AndroidManifest.xml
new file mode 100644
index 0000000..c4c1a9c
--- /dev/null
+++ b/libnativeloader/test/vendor/AndroidManifest.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="android.test.app.vendor">
+
+ <application>
+ <activity android:name="android.test.app.TestActivity" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
+
diff --git a/libsystem/OWNERS b/libsystem/OWNERS
new file mode 100644
index 0000000..aeb160c
--- /dev/null
+++ b/libsystem/OWNERS
@@ -0,0 +1,2 @@
+jessehall@google.com
+olv@google.com
diff --git a/libunwindstack/Android.bp b/libunwindstack/Android.bp
index 9389b40..28d7e64 100644
--- a/libunwindstack/Android.bp
+++ b/libunwindstack/Android.bp
@@ -124,6 +124,7 @@
"tests/DwarfOpTest.cpp",
"tests/DwarfSectionTest.cpp",
"tests/DwarfSectionImplTest.cpp",
+ "tests/ElfCacheTest.cpp",
"tests/ElfFake.cpp",
"tests/ElfInterfaceArmTest.cpp",
"tests/ElfInterfaceTest.cpp",
@@ -170,6 +171,8 @@
data: [
"tests/files/elf32.xz",
"tests/files/elf64.xz",
+ "tests/files/offline/bad_eh_frame_hdr_arm64/*",
+ "tests/files/offline/debug_frame_first_x86/*",
"tests/files/offline/jit_debug_arm32/*",
"tests/files/offline/jit_debug_x86_32/*",
"tests/files/offline/gnu_debugdata_arm32/*",
diff --git a/libunwindstack/ArmExidx.cpp b/libunwindstack/ArmExidx.cpp
index 6b0646f..65638ae 100644
--- a/libunwindstack/ArmExidx.cpp
+++ b/libunwindstack/ArmExidx.cpp
@@ -57,6 +57,7 @@
uint32_t data;
if (!elf_memory_->Read32(entry_offset + 4, &data)) {
status_ = ARM_STATUS_READ_FAILED;
+ status_address_ = entry_offset + 4;
return false;
}
if (data == 1) {
@@ -97,6 +98,7 @@
uint32_t addr = (entry_offset + 4) + signed_data;
if (!elf_memory_->Read32(addr, &data)) {
status_ = ARM_STATUS_READ_FAILED;
+ status_address_ = addr;
return false;
}
@@ -128,6 +130,7 @@
addr += 4;
if (!elf_memory_->Read32(addr, &data)) {
status_ = ARM_STATUS_READ_FAILED;
+ status_address_ = addr;
return false;
}
num_table_words = (data >> 24) & 0xff;
@@ -145,6 +148,7 @@
for (size_t i = 0; i < num_table_words; i++) {
if (!elf_memory_->Read32(addr, &data)) {
status_ = ARM_STATUS_READ_FAILED;
+ status_address_ = addr;
return false;
}
data_.push_back((data >> 24) & 0xff);
@@ -216,6 +220,7 @@
if (registers & (1 << reg)) {
if (!process_memory_->Read32(cfa_, &(*regs_)[reg])) {
status_ = ARM_STATUS_READ_FAILED;
+ status_address_ = cfa_;
return false;
}
cfa_ += 4;
@@ -284,6 +289,7 @@
for (size_t i = 4; i <= 4 + (byte & 0x7); i++) {
if (!process_memory_->Read32(cfa_, &(*regs_)[i])) {
status_ = ARM_STATUS_READ_FAILED;
+ status_address_ = cfa_;
return false;
}
cfa_ += 4;
@@ -291,6 +297,7 @@
if (byte & 0x8) {
if (!process_memory_->Read32(cfa_, &(*regs_)[ARM_REG_R14])) {
status_ = ARM_STATUS_READ_FAILED;
+ status_address_ = cfa_;
return false;
}
cfa_ += 4;
@@ -357,6 +364,7 @@
if (byte & (1 << reg)) {
if (!process_memory_->Read32(cfa_, &(*regs_)[reg])) {
status_ = ARM_STATUS_READ_FAILED;
+ status_address_ = cfa_;
return false;
}
cfa_ += 4;
diff --git a/libunwindstack/ArmExidx.h b/libunwindstack/ArmExidx.h
index f4361d4..96756a0 100644
--- a/libunwindstack/ArmExidx.h
+++ b/libunwindstack/ArmExidx.h
@@ -61,6 +61,7 @@
std::deque<uint8_t>* data() { return &data_; }
ArmStatus status() { return status_; }
+ uint64_t status_address() { return status_address_; }
RegsArm* regs() { return regs_; }
@@ -97,6 +98,7 @@
uint32_t cfa_ = 0;
std::deque<uint8_t> data_;
ArmStatus status_ = ARM_STATUS_NONE;
+ uint64_t status_address_ = 0;
Memory* elf_memory_;
Memory* process_memory_;
diff --git a/libunwindstack/AsmGetRegsX86.S b/libunwindstack/AsmGetRegsX86.S
index 14927a3..021e628 100644
--- a/libunwindstack/AsmGetRegsX86.S
+++ b/libunwindstack/AsmGetRegsX86.S
@@ -50,12 +50,12 @@
movl (%esp), %ecx
movl %ecx, 32(%eax)
- movl %cs, 36(%eax)
- movl %ss, 40(%eax)
- movl %ds, 44(%eax)
- movl %es, 48(%eax)
- movl %fs, 52(%eax)
- movl %gs, 56(%eax)
+ mov %cs, 36(%eax)
+ mov %ss, 40(%eax)
+ mov %ds, 44(%eax)
+ mov %es, 48(%eax)
+ mov %fs, 52(%eax)
+ mov %gs, 56(%eax)
ret
.cfi_endproc
diff --git a/libunwindstack/Check.h b/libunwindstack/Check.h
index 2d216d7..9643d76 100644
--- a/libunwindstack/Check.h
+++ b/libunwindstack/Check.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef _LIBUNWINDSTACK_ERROR_H
-#define _LIBUNWINDSTACK_ERROR_H
+#ifndef _LIBUNWINDSTACK_CHECK_H
+#define _LIBUNWINDSTACK_CHECK_H
#include <stdlib.h>
@@ -31,4 +31,4 @@
} // namespace unwindstack
-#endif // _LIBUNWINDSTACK_ERROR_H
+#endif // _LIBUNWINDSTACK_CHECK_H
diff --git a/libunwindstack/DwarfCfa.cpp b/libunwindstack/DwarfCfa.cpp
index b1d55ba..4fc95c7 100644
--- a/libunwindstack/DwarfCfa.cpp
+++ b/libunwindstack/DwarfCfa.cpp
@@ -23,12 +23,12 @@
#include <android-base/stringprintf.h>
+#include <unwindstack/DwarfError.h>
#include <unwindstack/DwarfLocation.h>
#include <unwindstack/Log.h>
#include "DwarfCfa.h"
#include "DwarfEncoding.h"
-#include "DwarfError.h"
#include "DwarfOp.h"
namespace unwindstack {
@@ -44,7 +44,8 @@
(*loc_regs)[entry.first] = entry.second;
}
}
- last_error_ = DWARF_ERROR_NONE;
+ last_error_.code = DWARF_ERROR_NONE;
+ last_error_.address = 0;
memory_->set_cur_offset(start_offset);
uint64_t cfa_offset;
@@ -54,7 +55,8 @@
// Read the cfa information.
uint8_t cfa_value;
if (!memory_->ReadBytes(&cfa_value, 1)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_->cur_offset();
return false;
}
uint8_t cfa_low = cfa_value & 0x3f;
@@ -66,7 +68,8 @@
case 2: {
uint64_t offset;
if (!memory_->ReadULEB128(&offset)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_->cur_offset();
return false;
}
SignedType signed_offset =
@@ -78,7 +81,7 @@
case 3: {
if (cie_loc_regs_ == nullptr) {
log(0, "restore while processing cie");
- last_error_ = DWARF_ERROR_ILLEGAL_STATE;
+ last_error_.code = DWARF_ERROR_ILLEGAL_STATE;
return false;
}
@@ -93,7 +96,7 @@
case 0: {
const auto handle_func = DwarfCfa<AddressType>::kCallbackTable[cfa_low];
if (handle_func == nullptr) {
- last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
+ last_error_.code = DWARF_ERROR_ILLEGAL_VALUE;
return false;
}
@@ -102,7 +105,8 @@
if (cfa->operands[i] == DW_EH_PE_block) {
uint64_t block_length;
if (!memory_->ReadULEB128(&block_length)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_->cur_offset();
return false;
}
operands_.push_back(block_length);
@@ -111,7 +115,8 @@
}
uint64_t value;
if (!memory_->ReadEncodedValue<AddressType>(cfa->operands[i], &value)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_->cur_offset();
return false;
}
operands_.push_back(value);
@@ -334,7 +339,7 @@
AddressType reg = operands_[0];
if (cie_loc_regs_ == nullptr) {
log(0, "restore while processing cie");
- last_error_ = DWARF_ERROR_ILLEGAL_STATE;
+ last_error_.code = DWARF_ERROR_ILLEGAL_STATE;
return false;
}
auto reg_entry = cie_loc_regs_->find(reg);
@@ -396,7 +401,7 @@
auto cfa_location = loc_regs->find(CFA_REG);
if (cfa_location == loc_regs->end() || cfa_location->second.type != DWARF_LOCATION_REGISTER) {
log(0, "Attempt to set new register, but cfa is not already set to a register.");
- last_error_ = DWARF_ERROR_ILLEGAL_STATE;
+ last_error_.code = DWARF_ERROR_ILLEGAL_STATE;
return false;
}
@@ -410,7 +415,7 @@
auto cfa_location = loc_regs->find(CFA_REG);
if (cfa_location == loc_regs->end() || cfa_location->second.type != DWARF_LOCATION_REGISTER) {
log(0, "Attempt to set offset, but cfa is not set to a register.");
- last_error_ = DWARF_ERROR_ILLEGAL_STATE;
+ last_error_.code = DWARF_ERROR_ILLEGAL_STATE;
return false;
}
cfa_location->second.values[1] = operands_[0];
@@ -454,7 +459,7 @@
auto cfa_location = loc_regs->find(CFA_REG);
if (cfa_location == loc_regs->end() || cfa_location->second.type != DWARF_LOCATION_REGISTER) {
log(0, "Attempt to set offset, but cfa is not set to a register.");
- last_error_ = DWARF_ERROR_ILLEGAL_STATE;
+ last_error_.code = DWARF_ERROR_ILLEGAL_STATE;
return false;
}
SignedType offset = static_cast<SignedType>(operands_[0]) * fde_->cie->data_alignment_factor;
diff --git a/libunwindstack/DwarfCfa.h b/libunwindstack/DwarfCfa.h
index 62b9b7a..16c66e2 100644
--- a/libunwindstack/DwarfCfa.h
+++ b/libunwindstack/DwarfCfa.h
@@ -24,12 +24,11 @@
#include <type_traits>
#include <vector>
+#include <unwindstack/DwarfError.h>
#include <unwindstack/DwarfLocation.h>
#include <unwindstack/DwarfMemory.h>
#include <unwindstack/DwarfStructs.h>
-#include "DwarfError.h"
-
namespace unwindstack {
// DWARF Standard home: http://dwarfstd.org/
@@ -75,7 +74,9 @@
bool Log(uint32_t indent, uint64_t pc, uint64_t load_bias, uint64_t start_offset,
uint64_t end_offset);
- DwarfError last_error() { return last_error_; }
+ const DwarfErrorData& last_error() { return last_error_; }
+ DwarfErrorCode LastErrorCode() { return last_error_.code; }
+ uint64_t LastErrorAddress() { return last_error_.address; }
AddressType cur_pc() { return cur_pc_; }
@@ -89,7 +90,7 @@
bool LogInstruction(uint32_t indent, uint64_t cfa_offset, uint8_t op, uint64_t* cur_pc);
private:
- DwarfError last_error_;
+ DwarfErrorData last_error_;
DwarfMemory* memory_;
const DwarfFde* fde_;
diff --git a/libunwindstack/DwarfEhFrameWithHdr.cpp b/libunwindstack/DwarfEhFrameWithHdr.cpp
index 0337dba..a131abe 100644
--- a/libunwindstack/DwarfEhFrameWithHdr.cpp
+++ b/libunwindstack/DwarfEhFrameWithHdr.cpp
@@ -16,12 +16,12 @@
#include <stdint.h>
+#include <unwindstack/DwarfError.h>
#include <unwindstack/DwarfStructs.h>
#include <unwindstack/Memory.h>
#include "Check.h"
#include "DwarfEhFrameWithHdr.h"
-#include "DwarfError.h"
namespace unwindstack {
@@ -36,14 +36,15 @@
// Read the first four bytes all at once.
if (!memory_.ReadBytes(data, 4)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
version_ = data[0];
if (version_ != 1) {
// Unknown version.
- last_error_ = DWARF_ERROR_UNSUPPORTED_VERSION;
+ last_error_.code = DWARF_ERROR_UNSUPPORTED_VERSION;
return false;
}
@@ -54,13 +55,20 @@
memory_.set_pc_offset(memory_.cur_offset());
if (!memory_.template ReadEncodedValue<AddressType>(ptr_encoding_, &ptr_offset_)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
memory_.set_pc_offset(memory_.cur_offset());
if (!memory_.template ReadEncodedValue<AddressType>(fde_count_encoding, &fde_count_)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
+ return false;
+ }
+
+ if (fde_count_ == 0) {
+ last_error_.code = DWARF_ERROR_NO_FDES;
return false;
}
@@ -96,7 +104,8 @@
uint64_t value;
if (!memory_.template ReadEncodedValue<AddressType>(table_encoding_, &value) ||
!memory_.template ReadEncodedValue<AddressType>(table_encoding_, &info->offset)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
fde_info_.erase(index);
return nullptr;
}
@@ -142,7 +151,9 @@
template <typename AddressType>
bool DwarfEhFrameWithHdr<AddressType>::GetFdeOffsetSequential(uint64_t pc, uint64_t* fde_offset) {
CHECK(fde_count_ != 0);
- last_error_ = DWARF_ERROR_NONE;
+ last_error_.code = DWARF_ERROR_NONE;
+ last_error_.address = 0;
+
// We can do a binary search if the pc is in the range of the elements
// that have already been cached.
if (!fde_info_.empty()) {
@@ -171,14 +182,16 @@
memory_.set_pc_offset(memory_.cur_offset());
uint64_t value;
if (!memory_.template ReadEncodedValue<AddressType>(table_encoding_, &value)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
FdeInfo* info = &fde_info_[current];
if (!memory_.template ReadEncodedValue<AddressType>(table_encoding_, &info->offset)) {
fde_info_.erase(current);
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
info->pc = value + 4;
diff --git a/libunwindstack/DwarfOp.cpp b/libunwindstack/DwarfOp.cpp
index 3b3d340..dcf04e6 100644
--- a/libunwindstack/DwarfOp.cpp
+++ b/libunwindstack/DwarfOp.cpp
@@ -22,12 +22,12 @@
#include <android-base/stringprintf.h>
+#include <unwindstack/DwarfError.h>
#include <unwindstack/DwarfMemory.h>
#include <unwindstack/Log.h>
#include <unwindstack/Memory.h>
#include <unwindstack/Regs.h>
-#include "DwarfError.h"
#include "DwarfOp.h"
namespace unwindstack {
@@ -48,7 +48,7 @@
// To protect against a branch that creates an infinite loop,
// terminate if the number of iterations gets too high.
if (iterations++ == 1000) {
- last_error_ = DWARF_ERROR_TOO_MANY_ITERATIONS;
+ last_error_.code = DWARF_ERROR_TOO_MANY_ITERATIONS;
return false;
}
}
@@ -57,28 +57,29 @@
template <typename AddressType>
bool DwarfOp<AddressType>::Decode(uint8_t dwarf_version) {
- last_error_ = DWARF_ERROR_NONE;
+ last_error_.code = DWARF_ERROR_NONE;
if (!memory_->ReadBytes(&cur_op_, 1)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_->cur_offset();
return false;
}
const auto* op = &kCallbackTable[cur_op_];
const auto handle_func = op->handle_func;
if (handle_func == nullptr) {
- last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
+ last_error_.code = DWARF_ERROR_ILLEGAL_VALUE;
return false;
}
// Check for an unsupported opcode.
if (dwarf_version < op->supported_version) {
- last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
+ last_error_.code = DWARF_ERROR_ILLEGAL_VALUE;
return false;
}
// Make sure that the required number of stack elements is available.
if (stack_.size() < op->num_required_stack_values) {
- last_error_ = DWARF_ERROR_STACK_INDEX_NOT_VALID;
+ last_error_.code = DWARF_ERROR_STACK_INDEX_NOT_VALID;
return false;
}
@@ -86,7 +87,8 @@
for (size_t i = 0; i < op->num_operands; i++) {
uint64_t value;
if (!memory_->ReadEncodedValue<AddressType>(op->operands[i], &value)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_->cur_offset();
return false;
}
operands_.push_back(value);
@@ -142,7 +144,8 @@
AddressType addr = StackPop();
AddressType value;
if (!regular_memory()->ReadFully(addr, &value, sizeof(value))) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = addr;
return false;
}
stack_.push_front(value);
@@ -153,14 +156,15 @@
bool DwarfOp<AddressType>::op_deref_size() {
AddressType bytes_to_read = OperandAt(0);
if (bytes_to_read > sizeof(AddressType) || bytes_to_read == 0) {
- last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
+ last_error_.code = DWARF_ERROR_ILLEGAL_VALUE;
return false;
}
// Read the address and dereference it.
AddressType addr = StackPop();
AddressType value = 0;
if (!regular_memory()->ReadFully(addr, &value, bytes_to_read)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = addr;
return false;
}
stack_.push_front(value);
@@ -198,7 +202,7 @@
bool DwarfOp<AddressType>::op_pick() {
AddressType index = OperandAt(0);
if (index > StackSize()) {
- last_error_ = DWARF_ERROR_STACK_INDEX_NOT_VALID;
+ last_error_.code = DWARF_ERROR_STACK_INDEX_NOT_VALID;
return false;
}
stack_.push_front(StackAt(index));
@@ -243,7 +247,7 @@
bool DwarfOp<AddressType>::op_div() {
AddressType top = StackPop();
if (top == 0) {
- last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
+ last_error_.code = DWARF_ERROR_ILLEGAL_VALUE;
return false;
}
SignedType signed_divisor = static_cast<SignedType>(top);
@@ -263,7 +267,7 @@
bool DwarfOp<AddressType>::op_mod() {
AddressType top = StackPop();
if (top == 0) {
- last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
+ last_error_.code = DWARF_ERROR_ILLEGAL_VALUE;
return false;
}
stack_[0] %= top;
@@ -431,7 +435,7 @@
bool DwarfOp<AddressType>::op_breg() {
uint16_t reg = cur_op() - 0x70;
if (reg >= regs_->total_regs()) {
- last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
+ last_error_.code = DWARF_ERROR_ILLEGAL_VALUE;
return false;
}
stack_.push_front((*regs_)[reg] + OperandAt(0));
@@ -442,7 +446,7 @@
bool DwarfOp<AddressType>::op_bregx() {
AddressType reg = OperandAt(0);
if (reg >= regs_->total_regs()) {
- last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
+ last_error_.code = DWARF_ERROR_ILLEGAL_VALUE;
return false;
}
stack_.push_front((*regs_)[reg] + OperandAt(1));
@@ -456,7 +460,7 @@
template <typename AddressType>
bool DwarfOp<AddressType>::op_not_implemented() {
- last_error_ = DWARF_ERROR_NOT_IMPLEMENTED;
+ last_error_.code = DWARF_ERROR_NOT_IMPLEMENTED;
return false;
}
diff --git a/libunwindstack/DwarfOp.h b/libunwindstack/DwarfOp.h
index c29bf35..40b7b23 100644
--- a/libunwindstack/DwarfOp.h
+++ b/libunwindstack/DwarfOp.h
@@ -24,8 +24,9 @@
#include <type_traits>
#include <vector>
+#include <unwindstack/DwarfError.h>
+
#include "DwarfEncoding.h"
-#include "DwarfError.h"
namespace unwindstack {
@@ -72,7 +73,9 @@
void set_regs(RegsImpl<AddressType>* regs) { regs_ = regs; }
- DwarfError last_error() { return last_error_; }
+ const DwarfErrorData& last_error() { return last_error_; }
+ DwarfErrorCode LastErrorCode() { return last_error_.code; }
+ uint64_t LastErrorAddress() { return last_error_.address; }
bool is_register() { return is_register_; }
@@ -96,7 +99,7 @@
RegsImpl<AddressType>* regs_;
bool is_register_ = false;
- DwarfError last_error_ = DWARF_ERROR_NONE;
+ DwarfErrorData last_error_{DWARF_ERROR_NONE, 0};
uint8_t cur_op_;
std::vector<AddressType> operands_;
std::deque<AddressType> stack_;
diff --git a/libunwindstack/DwarfSection.cpp b/libunwindstack/DwarfSection.cpp
index 91d855b..4e94f88 100644
--- a/libunwindstack/DwarfSection.cpp
+++ b/libunwindstack/DwarfSection.cpp
@@ -16,6 +16,7 @@
#include <stdint.h>
+#include <unwindstack/DwarfError.h>
#include <unwindstack/DwarfLocation.h>
#include <unwindstack/DwarfMemory.h>
#include <unwindstack/DwarfSection.h>
@@ -26,7 +27,6 @@
#include "DwarfCfa.h"
#include "DwarfEncoding.h"
-#include "DwarfError.h"
#include "DwarfOp.h"
#include "DwarfDebugFrame.h"
@@ -36,7 +36,7 @@
constexpr uint64_t DEX_PC_REG = 0x20444558;
-DwarfSection::DwarfSection(Memory* memory) : memory_(memory), last_error_(DWARF_ERROR_NONE) {}
+DwarfSection::DwarfSection(Memory* memory) : memory_(memory) {}
const DwarfFde* DwarfSection::GetFdeFromPc(uint64_t pc) {
uint64_t fde_offset;
@@ -52,15 +52,15 @@
if (pc < fde->pc_end) {
return fde;
}
- last_error_ = DWARF_ERROR_ILLEGAL_STATE;
+ last_error_.code = DWARF_ERROR_ILLEGAL_STATE;
return nullptr;
}
bool DwarfSection::Step(uint64_t pc, Regs* regs, Memory* process_memory, bool* finished) {
- last_error_ = DWARF_ERROR_NONE;
+ last_error_.code = DWARF_ERROR_NONE;
const DwarfFde* fde = GetFdeFromPc(pc);
if (fde == nullptr || fde->cie == nullptr) {
- last_error_ = DWARF_ERROR_ILLEGAL_STATE;
+ last_error_.code = DWARF_ERROR_ILLEGAL_STATE;
return false;
}
@@ -87,12 +87,12 @@
return false;
}
if (op.StackSize() == 0) {
- last_error_ = DWARF_ERROR_ILLEGAL_STATE;
+ last_error_.code = DWARF_ERROR_ILLEGAL_STATE;
return false;
}
// We don't support an expression that evaluates to a register number.
if (op.is_register()) {
- last_error_ = DWARF_ERROR_NOT_IMPLEMENTED;
+ last_error_.code = DWARF_ERROR_NOT_IMPLEMENTED;
return false;
}
*value = op.StackAt(0);
@@ -119,7 +119,8 @@
switch (loc->type) {
case DWARF_LOCATION_OFFSET:
if (!regular_memory->ReadFully(eval_info->cfa + loc->values[0], reg_ptr, sizeof(AddressType))) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = eval_info->cfa + loc->values[0];
return false;
}
break;
@@ -129,7 +130,7 @@
case DWARF_LOCATION_REGISTER: {
uint32_t cur_reg = loc->values[0];
if (cur_reg >= eval_info->cur_regs->total_regs()) {
- last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
+ last_error_.code = DWARF_ERROR_ILLEGAL_VALUE;
return false;
}
AddressType* cur_reg_ptr = &(*eval_info->cur_regs)[cur_reg];
@@ -158,7 +159,8 @@
}
if (loc->type == DWARF_LOCATION_EXPRESSION) {
if (!regular_memory->ReadFully(value, reg_ptr, sizeof(AddressType))) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = value;
return false;
}
} else {
@@ -183,14 +185,14 @@
bool* finished) {
RegsImpl<AddressType>* cur_regs = reinterpret_cast<RegsImpl<AddressType>*>(regs);
if (cie->return_address_register >= cur_regs->total_regs()) {
- last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
+ last_error_.code = DWARF_ERROR_ILLEGAL_VALUE;
return false;
}
// Get the cfa value;
auto cfa_entry = loc_regs.find(CFA_REG);
if (cfa_entry == loc_regs.end()) {
- last_error_ = DWARF_ERROR_CFA_NOT_DEFINED;
+ last_error_.code = DWARF_ERROR_CFA_NOT_DEFINED;
return false;
}
@@ -206,7 +208,7 @@
switch (loc->type) {
case DWARF_LOCATION_REGISTER:
if (loc->values[0] >= cur_regs->total_regs()) {
- last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
+ last_error_.code = DWARF_ERROR_ILLEGAL_VALUE;
return false;
}
// If the stack pointer register is the CFA, and the stack
@@ -227,7 +229,8 @@
}
if (loc->type == DWARF_LOCATION_EXPRESSION) {
if (!regular_memory->ReadFully(value, &eval_info.cfa, sizeof(AddressType))) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = value;
return false;
}
} else {
@@ -236,7 +239,7 @@
break;
}
default:
- last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
+ last_error_.code = DWARF_ERROR_ILLEGAL_VALUE;
return false;
}
@@ -305,7 +308,8 @@
bool DwarfSectionImpl<AddressType>::FillInCie(DwarfCie* cie) {
uint32_t length32;
if (!memory_.ReadBytes(&length32, sizeof(length32))) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
// Set the default for the lsda encoding.
@@ -315,7 +319,8 @@
// 64 bit Cie
uint64_t length64;
if (!memory_.ReadBytes(&length64, sizeof(length64))) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
@@ -324,12 +329,13 @@
uint64_t cie_id;
if (!memory_.ReadBytes(&cie_id, sizeof(cie_id))) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
if (cie_id != cie64_value_) {
// This is not a Cie, something has gone horribly wrong.
- last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
+ last_error_.code = DWARF_ERROR_ILLEGAL_VALUE;
return false;
}
} else {
@@ -339,24 +345,26 @@
uint32_t cie_id;
if (!memory_.ReadBytes(&cie_id, sizeof(cie_id))) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
if (cie_id != cie32_value_) {
// This is not a Cie, something has gone horribly wrong.
- last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
+ last_error_.code = DWARF_ERROR_ILLEGAL_VALUE;
return false;
}
}
if (!memory_.ReadBytes(&cie->version, sizeof(cie->version))) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
if (cie->version != 1 && cie->version != 3 && cie->version != 4) {
// Unrecognized version.
- last_error_ = DWARF_ERROR_UNSUPPORTED_VERSION;
+ last_error_.code = DWARF_ERROR_UNSUPPORTED_VERSION;
return false;
}
@@ -364,7 +372,8 @@
char aug_value;
do {
if (!memory_.ReadBytes(&aug_value, 1)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
cie->augmentation_string.push_back(aug_value);
@@ -376,20 +385,23 @@
// Segment Size
if (!memory_.ReadBytes(&cie->segment_size, 1)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
}
// Code Alignment Factor
if (!memory_.ReadULEB128(&cie->code_alignment_factor)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
// Data Alignment Factor
if (!memory_.ReadSLEB128(&cie->data_alignment_factor)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
@@ -397,12 +409,14 @@
// Return Address is a single byte.
uint8_t return_address_register;
if (!memory_.ReadBytes(&return_address_register, 1)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
cie->return_address_register = return_address_register;
} else if (!memory_.ReadULEB128(&cie->return_address_register)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
@@ -413,7 +427,8 @@
uint64_t aug_length;
if (!memory_.ReadULEB128(&aug_length)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
cie->cfa_instructions_offset = memory_.cur_offset() + aug_length;
@@ -422,24 +437,28 @@
switch (cie->augmentation_string[i]) {
case 'L':
if (!memory_.ReadBytes(&cie->lsda_encoding, 1)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
break;
case 'P': {
uint8_t encoding;
if (!memory_.ReadBytes(&encoding, 1)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
if (!memory_.ReadEncodedValue<AddressType>(encoding, &cie->personality_handler)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
} break;
case 'R':
if (!memory_.ReadBytes(&cie->fde_address_encoding, 1)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
break;
@@ -467,7 +486,8 @@
bool DwarfSectionImpl<AddressType>::FillInFde(DwarfFde* fde) {
uint32_t length32;
if (!memory_.ReadBytes(&length32, sizeof(length32))) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
@@ -475,19 +495,21 @@
// 64 bit Fde.
uint64_t length64;
if (!memory_.ReadBytes(&length64, sizeof(length64))) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
fde->cfa_instructions_end = memory_.cur_offset() + length64;
uint64_t value64;
if (!memory_.ReadBytes(&value64, sizeof(value64))) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
if (value64 == cie64_value_) {
// This is a Cie, this means something has gone wrong.
- last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
+ last_error_.code = DWARF_ERROR_ILLEGAL_VALUE;
return false;
}
@@ -500,12 +522,13 @@
uint32_t value32;
if (!memory_.ReadBytes(&value32, sizeof(value32))) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
if (value32 == cie32_value_) {
// This is a Cie, this means something has gone wrong.
- last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
+ last_error_.code = DWARF_ERROR_ILLEGAL_VALUE;
return false;
}
@@ -528,13 +551,15 @@
memory_.set_cur_offset(cur_offset);
if (!memory_.ReadEncodedValue<AddressType>(cie->fde_address_encoding & 0xf, &fde->pc_start)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
fde->pc_start = AdjustPcFromFde(fde->pc_start);
if (!memory_.ReadEncodedValue<AddressType>(cie->fde_address_encoding & 0xf, &fde->pc_end)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
fde->pc_end += fde->pc_start;
@@ -542,13 +567,15 @@
// Augmentation Size
uint64_t aug_length;
if (!memory_.ReadULEB128(&aug_length)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
uint64_t cur_offset = memory_.cur_offset();
if (!memory_.ReadEncodedValue<AddressType>(cie->lsda_encoding, &fde->lsda_address)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
@@ -619,7 +646,8 @@
bool DwarfSectionImpl<AddressType>::GetCieInfo(uint8_t* segment_size, uint8_t* encoding) {
uint8_t version;
if (!memory_.ReadBytes(&version, 1)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
// Read the augmentation string.
@@ -628,7 +656,8 @@
bool get_encoding = false;
do {
if (!memory_.ReadBytes(&aug_value, 1)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
if (aug_value == 'R') {
@@ -643,7 +672,8 @@
// Read the segment size.
if (!memory_.ReadBytes(segment_size, 1)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
} else {
@@ -659,7 +689,8 @@
uint8_t value;
do {
if (!memory_.ReadBytes(&value, 1)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
} while (value & 0x80);
@@ -667,7 +698,8 @@
// Skip data alignment factor
do {
if (!memory_.ReadBytes(&value, 1)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
} while (value & 0x80);
@@ -679,7 +711,8 @@
// Skip return address register.
do {
if (!memory_.ReadBytes(&value, 1)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
} while (value & 0x80);
@@ -688,7 +721,8 @@
// Skip the augmentation length.
do {
if (!memory_.ReadBytes(&value, 1)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
} while (value & 0x80);
@@ -696,7 +730,8 @@
for (size_t i = 1; i < aug_string.size(); i++) {
if (aug_string[i] == 'R') {
if (!memory_.ReadBytes(encoding, 1)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
// Got the encoding, that's all we are looking for.
@@ -706,12 +741,14 @@
} else if (aug_string[i] == 'P') {
uint8_t encoding;
if (!memory_.ReadBytes(&encoding, 1)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
uint64_t value;
if (!memory_.template ReadEncodedValue<AddressType>(encoding, &value)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
}
@@ -730,14 +767,16 @@
uint64_t start;
if (!memory_.template ReadEncodedValue<AddressType>(encoding & 0xf, &start)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
start = AdjustPcFromFde(start);
uint64_t length;
if (!memory_.template ReadEncodedValue<AddressType>(encoding & 0xf, &length)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
if (length != 0) {
@@ -764,7 +803,8 @@
// Figure out the entry length and type.
uint32_t value32;
if (!memory_.ReadBytes(&value32, sizeof(value32))) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
@@ -772,14 +812,16 @@
if (value32 == static_cast<uint32_t>(-1)) {
uint64_t value64;
if (!memory_.ReadBytes(&value64, sizeof(value64))) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
next_entry_offset = memory_.cur_offset() + value64;
// Read the Cie Id of a Cie or the pointer of the Fde.
if (!memory_.ReadBytes(&value64, sizeof(value64))) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
@@ -794,7 +836,7 @@
uint64_t last_cie_offset = GetCieOffsetFromFde64(value64);
if (last_cie_offset != cie_offset) {
// This means that this Fde is not following the Cie.
- last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
+ last_error_.code = DWARF_ERROR_ILLEGAL_VALUE;
return false;
}
@@ -808,7 +850,8 @@
// Read the Cie Id of a Cie or the pointer of the Fde.
if (!memory_.ReadBytes(&value32, sizeof(value32))) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.code = DWARF_ERROR_MEMORY_INVALID;
+ last_error_.address = memory_.cur_offset();
return false;
}
@@ -823,7 +866,7 @@
uint64_t last_cie_offset = GetCieOffsetFromFde32(value32);
if (last_cie_offset != cie_offset) {
// This means that this Fde is not following the Cie.
- last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
+ last_error_.code = DWARF_ERROR_ILLEGAL_VALUE;
return false;
}
@@ -835,9 +878,8 @@
}
if (next_entry_offset < memory_.cur_offset()) {
- // This indicates some kind of corruption, or malformed section data.
- last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
- return false;
+ // Simply consider the processing done in this case.
+ break;
}
memory_.set_cur_offset(next_entry_offset);
}
diff --git a/libunwindstack/Elf.cpp b/libunwindstack/Elf.cpp
index 220e549..dbf772e 100644
--- a/libunwindstack/Elf.cpp
+++ b/libunwindstack/Elf.cpp
@@ -35,6 +35,10 @@
namespace unwindstack {
+bool Elf::cache_enabled_;
+std::unordered_map<std::string, std::shared_ptr<Elf>>* Elf::cache_;
+std::mutex* Elf::cache_lock_;
+
bool Elf::Init(bool init_gnu_debugdata) {
load_bias_ = 0;
if (!memory_) {
@@ -134,6 +138,26 @@
return true;
}
+void Elf::GetLastError(ErrorData* data) {
+ if (valid_) {
+ *data = interface_->last_error();
+ }
+}
+
+ErrorCode Elf::GetLastErrorCode() {
+ if (valid_) {
+ return interface_->LastErrorCode();
+ }
+ return ERROR_NONE;
+}
+
+uint64_t Elf::GetLastErrorAddress() {
+ if (valid_) {
+ return interface_->LastErrorAddress();
+ }
+ return 0;
+}
+
// The relative pc is always relative to the start of the map from which it comes.
bool Elf::Step(uint64_t rel_pc, uint64_t adjusted_rel_pc, uint64_t elf_offset, Regs* regs,
Memory* process_memory, bool* finished) {
@@ -281,4 +305,42 @@
return 0;
}
+void Elf::SetCachingEnabled(bool enable) {
+ if (!cache_enabled_ && enable) {
+ cache_enabled_ = true;
+ cache_ = new std::unordered_map<std::string, std::shared_ptr<Elf>>;
+ cache_lock_ = new std::mutex;
+ } else if (cache_enabled_ && !enable) {
+ cache_enabled_ = false;
+ delete cache_;
+ delete cache_lock_;
+ }
+}
+
+void Elf::CacheLock() {
+ cache_lock_->lock();
+}
+
+void Elf::CacheUnlock() {
+ cache_lock_->unlock();
+}
+
+void Elf::CacheAdd(MapInfo* info) {
+ if (info->offset == 0) {
+ (*cache_)[info->name] = info->elf;
+ } else {
+ std::string name(info->name + ':' + std::to_string(info->offset));
+ (*cache_)[name] = info->elf;
+ }
+}
+
+bool Elf::CacheGet(const std::string& name, std::shared_ptr<Elf>* elf) {
+ auto entry = cache_->find(name);
+ if (entry != cache_->end()) {
+ *elf = entry->second;
+ return true;
+ }
+ return false;
+}
+
} // namespace unwindstack
diff --git a/libunwindstack/ElfInterface.cpp b/libunwindstack/ElfInterface.cpp
index 0e3ab2c..e413081 100644
--- a/libunwindstack/ElfInterface.cpp
+++ b/libunwindstack/ElfInterface.cpp
@@ -24,6 +24,7 @@
#include <Xz.h>
#include <XzCrc64.h>
+#include <unwindstack/DwarfError.h>
#include <unwindstack/DwarfSection.h>
#include <unwindstack/ElfInterface.h>
#include <unwindstack/Log.h>
@@ -126,22 +127,26 @@
if (eh_frame_hdr_offset_ != 0) {
eh_frame_.reset(new DwarfEhFrameWithHdr<AddressType>(memory_));
if (!eh_frame_->Init(eh_frame_hdr_offset_, eh_frame_hdr_size_)) {
- // Even if the eh_frame_offset_ is non-zero, do not bother
- // trying to read that since something has gone wrong.
eh_frame_.reset(nullptr);
- eh_frame_hdr_offset_ = 0;
- eh_frame_hdr_size_ = static_cast<uint64_t>(-1);
}
- } else if (eh_frame_offset_ != 0) {
- // If there is a eh_frame section without a eh_frame_hdr section.
+ }
+
+ if (eh_frame_.get() == nullptr && eh_frame_offset_ != 0) {
+ // If there is an eh_frame section without an eh_frame_hdr section,
+ // or using the frame hdr object failed to init.
eh_frame_.reset(new DwarfEhFrame<AddressType>(memory_));
if (!eh_frame_->Init(eh_frame_offset_, eh_frame_size_)) {
eh_frame_.reset(nullptr);
- eh_frame_offset_ = 0;
- eh_frame_size_ = static_cast<uint64_t>(-1);
}
}
+ if (eh_frame_.get() == nullptr) {
+ eh_frame_hdr_offset_ = 0;
+ eh_frame_hdr_size_ = static_cast<uint64_t>(-1);
+ eh_frame_offset_ = 0;
+ eh_frame_size_ = static_cast<uint64_t>(-1);
+ }
+
if (debug_frame_offset_ != 0) {
debug_frame_.reset(new DwarfDebugFrame<AddressType>(memory_));
if (!debug_frame_->Init(debug_frame_offset_, debug_frame_size_)) {
@@ -156,6 +161,8 @@
bool ElfInterface::ReadAllHeaders(uint64_t* load_bias) {
EhdrType ehdr;
if (!memory_->ReadFully(0, &ehdr, sizeof(ehdr))) {
+ last_error_.code = ERROR_MEMORY_INVALID;
+ last_error_.address = 0;
return false;
}
@@ -197,6 +204,9 @@
for (size_t i = 0; i < ehdr.e_phnum; i++, offset += ehdr.e_phentsize) {
PhdrType phdr;
if (!memory_->ReadField(offset, &phdr, &phdr.p_type, sizeof(phdr.p_type))) {
+ last_error_.code = ERROR_MEMORY_INVALID;
+ last_error_.address =
+ offset + reinterpret_cast<uintptr_t>(&phdr.p_type) - reinterpret_cast<uintptr_t>(&phdr);
return false;
}
@@ -209,6 +219,9 @@
{
// Get the flags first, if this isn't an executable header, ignore it.
if (!memory_->ReadField(offset, &phdr, &phdr.p_flags, sizeof(phdr.p_flags))) {
+ last_error_.code = ERROR_MEMORY_INVALID;
+ last_error_.address = offset + reinterpret_cast<uintptr_t>(&phdr.p_flags) -
+ reinterpret_cast<uintptr_t>(&phdr);
return false;
}
if ((phdr.p_flags & PF_X) == 0) {
@@ -216,12 +229,21 @@
}
if (!memory_->ReadField(offset, &phdr, &phdr.p_vaddr, sizeof(phdr.p_vaddr))) {
+ last_error_.code = ERROR_MEMORY_INVALID;
+ last_error_.address = offset + reinterpret_cast<uintptr_t>(&phdr.p_vaddr) -
+ reinterpret_cast<uintptr_t>(&phdr);
return false;
}
if (!memory_->ReadField(offset, &phdr, &phdr.p_offset, sizeof(phdr.p_offset))) {
+ last_error_.code = ERROR_MEMORY_INVALID;
+ last_error_.address = offset + reinterpret_cast<uintptr_t>(&phdr.p_offset) -
+ reinterpret_cast<uintptr_t>(&phdr);
return false;
}
if (!memory_->ReadField(offset, &phdr, &phdr.p_memsz, sizeof(phdr.p_memsz))) {
+ last_error_.code = ERROR_MEMORY_INVALID;
+ last_error_.address = offset + reinterpret_cast<uintptr_t>(&phdr.p_memsz) -
+ reinterpret_cast<uintptr_t>(&phdr);
return false;
}
pt_loads_[phdr.p_offset] = LoadInfo{phdr.p_offset, phdr.p_vaddr,
@@ -234,11 +256,17 @@
case PT_GNU_EH_FRAME:
if (!memory_->ReadField(offset, &phdr, &phdr.p_offset, sizeof(phdr.p_offset))) {
+ last_error_.code = ERROR_MEMORY_INVALID;
+ last_error_.address = offset + reinterpret_cast<uintptr_t>(&phdr.p_offset) -
+ reinterpret_cast<uintptr_t>(&phdr);
return false;
}
// This is really the pointer to the .eh_frame_hdr section.
eh_frame_hdr_offset_ = phdr.p_offset;
if (!memory_->ReadField(offset, &phdr, &phdr.p_memsz, sizeof(phdr.p_memsz))) {
+ last_error_.code = ERROR_MEMORY_INVALID;
+ last_error_.address = offset + reinterpret_cast<uintptr_t>(&phdr.p_memsz) -
+ reinterpret_cast<uintptr_t>(&phdr);
return false;
}
eh_frame_hdr_size_ = phdr.p_memsz;
@@ -246,14 +274,23 @@
case PT_DYNAMIC:
if (!memory_->ReadField(offset, &phdr, &phdr.p_offset, sizeof(phdr.p_offset))) {
+ last_error_.code = ERROR_MEMORY_INVALID;
+ last_error_.address = offset + reinterpret_cast<uintptr_t>(&phdr.p_offset) -
+ reinterpret_cast<uintptr_t>(&phdr);
return false;
}
dynamic_offset_ = phdr.p_offset;
if (!memory_->ReadField(offset, &phdr, &phdr.p_vaddr, sizeof(phdr.p_vaddr))) {
+ last_error_.code = ERROR_MEMORY_INVALID;
+ last_error_.address = offset + reinterpret_cast<uintptr_t>(&phdr.p_vaddr) -
+ reinterpret_cast<uintptr_t>(&phdr);
return false;
}
dynamic_vaddr_ = phdr.p_vaddr;
if (!memory_->ReadField(offset, &phdr, &phdr.p_memsz, sizeof(phdr.p_memsz))) {
+ last_error_.code = ERROR_MEMORY_INVALID;
+ last_error_.address = offset + reinterpret_cast<uintptr_t>(&phdr.p_memsz) -
+ reinterpret_cast<uintptr_t>(&phdr);
return false;
}
dynamic_size_ = phdr.p_memsz;
@@ -286,31 +323,47 @@
offset += ehdr.e_shentsize;
for (size_t i = 1; i < ehdr.e_shnum; i++, offset += ehdr.e_shentsize) {
if (!memory_->ReadField(offset, &shdr, &shdr.sh_type, sizeof(shdr.sh_type))) {
+ last_error_.code = ERROR_MEMORY_INVALID;
+ last_error_.address =
+ offset + reinterpret_cast<uintptr_t>(&shdr.sh_type) - reinterpret_cast<uintptr_t>(&shdr);
return false;
}
if (shdr.sh_type == SHT_SYMTAB || shdr.sh_type == SHT_DYNSYM) {
if (!memory_->ReadFully(offset, &shdr, sizeof(shdr))) {
+ last_error_.code = ERROR_MEMORY_INVALID;
+ last_error_.address = offset;
return false;
}
// Need to go get the information about the section that contains
// the string terminated names.
ShdrType str_shdr;
if (shdr.sh_link >= ehdr.e_shnum) {
+ last_error_.code = ERROR_UNWIND_INFO;
return false;
}
uint64_t str_offset = ehdr.e_shoff + shdr.sh_link * ehdr.e_shentsize;
if (!memory_->ReadField(str_offset, &str_shdr, &str_shdr.sh_type, sizeof(str_shdr.sh_type))) {
+ last_error_.code = ERROR_MEMORY_INVALID;
+ last_error_.address = str_offset + reinterpret_cast<uintptr_t>(&str_shdr.sh_type) -
+ reinterpret_cast<uintptr_t>(&str_shdr);
return false;
}
if (str_shdr.sh_type != SHT_STRTAB) {
+ last_error_.code = ERROR_UNWIND_INFO;
return false;
}
if (!memory_->ReadField(str_offset, &str_shdr, &str_shdr.sh_offset,
sizeof(str_shdr.sh_offset))) {
+ last_error_.code = ERROR_MEMORY_INVALID;
+ last_error_.address = str_offset + reinterpret_cast<uintptr_t>(&str_shdr.sh_offset) -
+ reinterpret_cast<uintptr_t>(&str_shdr);
return false;
}
if (!memory_->ReadField(str_offset, &str_shdr, &str_shdr.sh_size, sizeof(str_shdr.sh_size))) {
+ last_error_.code = ERROR_MEMORY_INVALID;
+ last_error_.address = str_offset + reinterpret_cast<uintptr_t>(&str_shdr.sh_size) -
+ reinterpret_cast<uintptr_t>(&str_shdr);
return false;
}
symbols_.push_back(new Symbols(shdr.sh_offset, shdr.sh_size, shdr.sh_entsize,
@@ -318,6 +371,9 @@
} else if (shdr.sh_type == SHT_PROGBITS && sec_size != 0) {
// Look for the .debug_frame and .gnu_debugdata.
if (!memory_->ReadField(offset, &shdr, &shdr.sh_name, sizeof(shdr.sh_name))) {
+ last_error_.code = ERROR_MEMORY_INVALID;
+ last_error_.address = offset + reinterpret_cast<uintptr_t>(&shdr.sh_name) -
+ reinterpret_cast<uintptr_t>(&shdr);
return false;
}
if (shdr.sh_name < sec_size) {
@@ -373,6 +429,8 @@
uint64_t max_offset = offset + dynamic_size_;
for (uint64_t offset = dynamic_offset_; offset < max_offset; offset += sizeof(DynType)) {
if (!memory_->ReadFully(offset, &dyn, sizeof(dyn))) {
+ last_error_.code = ERROR_MEMORY_INVALID;
+ last_error_.address = offset;
return false;
}
@@ -430,21 +488,26 @@
bool ElfInterface::Step(uint64_t pc, uint64_t load_bias, Regs* regs, Memory* process_memory,
bool* finished) {
+ last_error_.code = ERROR_NONE;
+ last_error_.address = 0;
+
// Adjust the load bias to get the real relative pc.
if (pc < load_bias) {
+ last_error_.code = ERROR_UNWIND_INFO;
return false;
}
uint64_t adjusted_pc = pc - load_bias;
- // Try the eh_frame first.
- DwarfSection* eh_frame = eh_frame_.get();
- if (eh_frame != nullptr && eh_frame->Step(adjusted_pc, regs, process_memory, finished)) {
+ // Try the debug_frame first since it contains the most specific unwind
+ // information.
+ DwarfSection* debug_frame = debug_frame_.get();
+ if (debug_frame != nullptr && debug_frame->Step(adjusted_pc, regs, process_memory, finished)) {
return true;
}
- // Try the debug_frame next.
- DwarfSection* debug_frame = debug_frame_.get();
- if (debug_frame != nullptr && debug_frame->Step(adjusted_pc, regs, process_memory, finished)) {
+ // Try the eh_frame next.
+ DwarfSection* eh_frame = eh_frame_.get();
+ if (eh_frame != nullptr && eh_frame->Step(adjusted_pc, regs, process_memory, finished)) {
return true;
}
@@ -453,6 +516,46 @@
gnu_debugdata_interface_->Step(pc, 0, regs, process_memory, finished)) {
return true;
}
+
+ // Set the error code based on the first error encountered.
+ DwarfSection* section = nullptr;
+ if (debug_frame_ != nullptr) {
+ section = debug_frame_.get();
+ } else if (eh_frame_ != nullptr) {
+ section = eh_frame_.get();
+ } else if (gnu_debugdata_interface_ != nullptr) {
+ last_error_ = gnu_debugdata_interface_->last_error();
+ return false;
+ } else {
+ return false;
+ }
+
+ // Convert the DWARF ERROR to an external error.
+ DwarfErrorCode code = section->LastErrorCode();
+ switch (code) {
+ case DWARF_ERROR_NONE:
+ last_error_.code = ERROR_NONE;
+ break;
+
+ case DWARF_ERROR_MEMORY_INVALID:
+ last_error_.code = ERROR_MEMORY_INVALID;
+ last_error_.address = section->LastErrorAddress();
+ break;
+
+ case DWARF_ERROR_ILLEGAL_VALUE:
+ case DWARF_ERROR_ILLEGAL_STATE:
+ case DWARF_ERROR_STACK_INDEX_NOT_VALID:
+ case DWARF_ERROR_TOO_MANY_ITERATIONS:
+ case DWARF_ERROR_CFA_NOT_DEFINED:
+ case DWARF_ERROR_NO_FDES:
+ last_error_.code = ERROR_UNWIND_INFO;
+ break;
+
+ case DWARF_ERROR_NOT_IMPLEMENTED:
+ case DWARF_ERROR_UNSUPPORTED_VERSION:
+ last_error_.code = ERROR_UNSUPPORTED;
+ break;
+ }
return false;
}
diff --git a/libunwindstack/ElfInterfaceArm.cpp b/libunwindstack/ElfInterfaceArm.cpp
index 5d99bd7..616d1b1 100644
--- a/libunwindstack/ElfInterfaceArm.cpp
+++ b/libunwindstack/ElfInterfaceArm.cpp
@@ -28,6 +28,7 @@
bool ElfInterfaceArm::FindEntry(uint32_t pc, uint64_t* entry_offset) {
if (start_offset_ == 0 || total_entries_ == 0) {
+ last_error_.code = ERROR_UNWIND_INFO;
return false;
}
@@ -56,12 +57,15 @@
*entry_offset = start_offset_ + (last - 1) * 8;
return true;
}
+ last_error_.code = ERROR_UNWIND_INFO;
return false;
}
bool ElfInterfaceArm::GetPrel31Addr(uint32_t offset, uint32_t* addr) {
uint32_t data;
if (!memory_->Read32(offset, &data)) {
+ last_error_.code = ERROR_MEMORY_INVALID;
+ last_error_.address = offset;
return false;
}
@@ -106,6 +110,7 @@
bool* finished) {
// Adjust the load bias to get the real relative pc.
if (pc < load_bias) {
+ last_error_.code = ERROR_UNWIND_INFO;
return false;
}
pc -= load_bias;
@@ -139,6 +144,30 @@
*finished = true;
return true;
}
+
+ if (!return_value) {
+ switch (arm.status()) {
+ case ARM_STATUS_NONE:
+ case ARM_STATUS_NO_UNWIND:
+ case ARM_STATUS_FINISH:
+ last_error_.code = ERROR_NONE;
+ break;
+
+ case ARM_STATUS_RESERVED:
+ case ARM_STATUS_SPARE:
+ case ARM_STATUS_TRUNCATED:
+ case ARM_STATUS_MALFORMED:
+ case ARM_STATUS_INVALID_ALIGNMENT:
+ case ARM_STATUS_INVALID_PERSONALITY:
+ last_error_.code = ERROR_UNWIND_INFO;
+ break;
+
+ case ARM_STATUS_READ_FAILED:
+ last_error_.code = ERROR_MEMORY_INVALID;
+ last_error_.address = arm.status_address();
+ break;
+ }
+ }
return return_value;
}
diff --git a/libunwindstack/MapInfo.cpp b/libunwindstack/MapInfo.cpp
index 89fe038..0c15335 100644
--- a/libunwindstack/MapInfo.cpp
+++ b/libunwindstack/MapInfo.cpp
@@ -109,16 +109,46 @@
// Make sure no other thread is trying to add the elf to this map.
std::lock_guard<std::mutex> guard(mutex_);
- if (elf) {
- return elf;
+ if (elf.get() != nullptr) {
+ return elf.get();
}
- elf = new Elf(CreateMemory(process_memory));
- elf->Init(init_gnu_debugdata);
+ bool locked = false;
+ if (Elf::CachingEnabled() && !name.empty()) {
+ Elf::CacheLock();
+ locked = true;
+ if (offset != 0) {
+ std::string hash(name + ':' + std::to_string(offset));
+ if (Elf::CacheGet(hash, &elf)) {
+ Elf::CacheUnlock();
+ return elf.get();
+ }
+ } else if (Elf::CacheGet(name, &elf)) {
+ Elf::CacheUnlock();
+ return elf.get();
+ }
+ }
+ Memory* memory = CreateMemory(process_memory);
+ if (locked && offset != 0 && elf_offset != 0) {
+ // In this case, the whole file is the elf, need to see if the elf
+ // data was cached.
+ if (Elf::CacheGet(name, &elf)) {
+ delete memory;
+ Elf::CacheUnlock();
+ return elf.get();
+ }
+ }
+ elf.reset(new Elf(memory));
// If the init fails, keep the elf around as an invalid object so we
// don't try to reinit the object.
- return elf;
+ elf->Init(init_gnu_debugdata);
+
+ if (locked) {
+ Elf::CacheAdd(this);
+ Elf::CacheUnlock();
+ }
+ return elf.get();
}
uint64_t MapInfo::GetLoadBias(const std::shared_ptr<Memory>& process_memory) {
diff --git a/libunwindstack/Unwinder.cpp b/libunwindstack/Unwinder.cpp
index d711772..f70ed7b 100644
--- a/libunwindstack/Unwinder.cpp
+++ b/libunwindstack/Unwinder.cpp
@@ -78,6 +78,8 @@
void Unwinder::Unwind(const std::vector<std::string>* initial_map_names_to_skip,
const std::vector<std::string>* map_suffixes_to_ignore) {
frames_.clear();
+ last_error_.code = ERROR_NONE;
+ last_error_.address = 0;
bool return_address_attempt = false;
bool adjust_pc = false;
@@ -95,6 +97,7 @@
rel_pc = regs_->pc();
adjusted_rel_pc = rel_pc;
adjusted_pc = rel_pc;
+ last_error_.code = ERROR_INVALID_MAP;
} else {
if (ShouldStop(map_suffixes_to_ignore, map_info->name)) {
break;
@@ -155,6 +158,7 @@
bool finished;
stepped = elf->Step(rel_pc, adjusted_pc, map_info->elf_offset, regs_,
process_memory_.get(), &finished);
+ elf->GetLastError(&last_error_);
if (stepped && finished) {
break;
}
@@ -180,10 +184,14 @@
}
} else {
return_address_attempt = false;
+ if (max_frames_ == frames_.size()) {
+ last_error_.code = ERROR_MAX_FRAMES_EXCEEDED;
+ }
}
// If the pc and sp didn't change, then consider everything stopped.
if (cur_pc == regs_->pc() && cur_sp == regs_->sp()) {
+ last_error_.code = ERROR_REPEATED_FRAME;
break;
}
}
diff --git a/libunwindstack/DwarfError.h b/libunwindstack/include/unwindstack/DwarfError.h
similarity index 89%
rename from libunwindstack/DwarfError.h
rename to libunwindstack/include/unwindstack/DwarfError.h
index 54199b8..763e2cb 100644
--- a/libunwindstack/DwarfError.h
+++ b/libunwindstack/include/unwindstack/DwarfError.h
@@ -21,7 +21,7 @@
namespace unwindstack {
-enum DwarfError : uint8_t {
+enum DwarfErrorCode : uint8_t {
DWARF_ERROR_NONE,
DWARF_ERROR_MEMORY_INVALID,
DWARF_ERROR_ILLEGAL_VALUE,
@@ -31,6 +31,12 @@
DWARF_ERROR_TOO_MANY_ITERATIONS,
DWARF_ERROR_CFA_NOT_DEFINED,
DWARF_ERROR_UNSUPPORTED_VERSION,
+ DWARF_ERROR_NO_FDES,
+};
+
+struct DwarfErrorData {
+ DwarfErrorCode code;
+ uint64_t address;
};
} // namespace unwindstack
diff --git a/libunwindstack/include/unwindstack/DwarfSection.h b/libunwindstack/include/unwindstack/DwarfSection.h
index e0004aa..03f40d6 100644
--- a/libunwindstack/include/unwindstack/DwarfSection.h
+++ b/libunwindstack/include/unwindstack/DwarfSection.h
@@ -22,6 +22,7 @@
#include <iterator>
#include <unordered_map>
+#include <unwindstack/DwarfError.h>
#include <unwindstack/DwarfLocation.h>
#include <unwindstack/DwarfMemory.h>
#include <unwindstack/DwarfStructs.h>
@@ -29,7 +30,6 @@
namespace unwindstack {
// Forward declarations.
-enum DwarfError : uint8_t;
class Memory;
class Regs;
@@ -72,7 +72,8 @@
iterator begin() { return iterator(this, 0); }
iterator end() { return iterator(this, fde_count_); }
- DwarfError last_error() { return last_error_; }
+ DwarfErrorCode LastErrorCode() { return last_error_.code; }
+ uint64_t LastErrorAddress() { return last_error_.address; }
virtual bool Init(uint64_t offset, uint64_t size) = 0;
@@ -100,7 +101,7 @@
protected:
DwarfMemory memory_;
- DwarfError last_error_;
+ DwarfErrorData last_error_{DWARF_ERROR_NONE, 0};
uint32_t cie32_value_ = 0;
uint64_t cie64_value_ = 0;
diff --git a/libunwindstack/include/unwindstack/Elf.h b/libunwindstack/include/unwindstack/Elf.h
index 5f34391..a874709 100644
--- a/libunwindstack/include/unwindstack/Elf.h
+++ b/libunwindstack/include/unwindstack/Elf.h
@@ -22,6 +22,7 @@
#include <memory>
#include <mutex>
#include <string>
+#include <unordered_map>
#include <unwindstack/ElfInterface.h>
#include <unwindstack/Memory.h>
@@ -72,6 +73,10 @@
bool IsValidPc(uint64_t pc);
+ void GetLastError(ErrorData* data);
+ ErrorCode GetLastErrorCode();
+ uint64_t GetLastErrorAddress();
+
bool valid() { return valid_; }
uint32_t machine_type() { return machine_type_; }
@@ -92,6 +97,14 @@
static uint64_t GetLoadBias(Memory* memory);
+ static void SetCachingEnabled(bool enable);
+ static bool CachingEnabled() { return cache_enabled_; }
+
+ static void CacheLock();
+ static void CacheUnlock();
+ static void CacheAdd(MapInfo* info);
+ static bool CacheGet(const std::string& name, std::shared_ptr<Elf>* elf);
+
protected:
bool valid_ = false;
uint64_t load_bias_ = 0;
@@ -105,6 +118,10 @@
std::unique_ptr<Memory> gnu_debugdata_memory_;
std::unique_ptr<ElfInterface> gnu_debugdata_interface_;
+
+ static bool cache_enabled_;
+ static std::unordered_map<std::string, std::shared_ptr<Elf>>* cache_;
+ static std::mutex* cache_lock_;
};
} // namespace unwindstack
diff --git a/libunwindstack/include/unwindstack/ElfInterface.h b/libunwindstack/include/unwindstack/ElfInterface.h
index faa61ee..ea9ec9d 100644
--- a/libunwindstack/include/unwindstack/ElfInterface.h
+++ b/libunwindstack/include/unwindstack/ElfInterface.h
@@ -26,6 +26,7 @@
#include <vector>
#include <unwindstack/DwarfSection.h>
+#include <unwindstack/Error.h>
namespace unwindstack {
@@ -90,6 +91,10 @@
DwarfSection* eh_frame() { return eh_frame_.get(); }
DwarfSection* debug_frame() { return debug_frame_.get(); }
+ const ErrorData& last_error() { return last_error_; }
+ ErrorCode LastErrorCode() { return last_error_.code; }
+ uint64_t LastErrorAddress() { return last_error_.address; }
+
template <typename EhdrType, typename PhdrType>
static uint64_t GetLoadBias(Memory* memory);
@@ -144,6 +149,8 @@
uint8_t soname_type_ = SONAME_UNKNOWN;
std::string soname_;
+ ErrorData last_error_{ERROR_NONE, 0};
+
std::unique_ptr<DwarfSection> eh_frame_;
std::unique_ptr<DwarfSection> debug_frame_;
// The Elf object owns the gnu_debugdata interface object.
diff --git a/libunwindstack/include/unwindstack/Error.h b/libunwindstack/include/unwindstack/Error.h
new file mode 100644
index 0000000..6ed0e0f
--- /dev/null
+++ b/libunwindstack/include/unwindstack/Error.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _LIBUNWINDSTACK_ERROR_H
+#define _LIBUNWINDSTACK_ERROR_H
+
+#include <stdint.h>
+
+namespace unwindstack {
+
+enum ErrorCode : uint8_t {
+ ERROR_NONE, // No error.
+ ERROR_MEMORY_INVALID, // Memory read failed.
+ ERROR_UNWIND_INFO, // Unable to use unwind information to unwind.
+ ERROR_UNSUPPORTED, // Encountered unsupported feature.
+ ERROR_INVALID_MAP, // Unwind in an invalid map.
+ ERROR_MAX_FRAMES_EXCEEDED, // The number of frames exceed the total allowed.
+ ERROR_REPEATED_FRAME, // The last frame has the same pc/sp as the next.
+};
+
+struct ErrorData {
+ ErrorCode code;
+ uint64_t address; // Only valid when code is ERROR_MEMORY_INVALID.
+ // Indicates the failing address.
+};
+
+} // namespace unwindstack
+
+#endif // _LIBUNWINDSTACK_ERROR_H
diff --git a/libunwindstack/include/unwindstack/MapInfo.h b/libunwindstack/include/unwindstack/MapInfo.h
index 22e48f7..a57fe68 100644
--- a/libunwindstack/include/unwindstack/MapInfo.h
+++ b/libunwindstack/include/unwindstack/MapInfo.h
@@ -20,6 +20,7 @@
#include <stdint.h>
#include <atomic>
+#include <memory>
#include <mutex>
#include <string>
@@ -40,14 +41,14 @@
flags(flags),
name(name),
load_bias(static_cast<uint64_t>(-1)) {}
- ~MapInfo() { delete elf; }
+ ~MapInfo() = default;
uint64_t start = 0;
uint64_t end = 0;
uint64_t offset = 0;
uint16_t flags = 0;
std::string name;
- Elf* elf = nullptr;
+ std::shared_ptr<Elf> elf;
// This value is only non-zero if the offset is non-zero but there is
// no elf signature found at that offset. This indicates that the
// entire file is represented by the Memory object returned by CreateMemory,
diff --git a/libunwindstack/include/unwindstack/Unwinder.h b/libunwindstack/include/unwindstack/Unwinder.h
index 32858ae..a7b57e6 100644
--- a/libunwindstack/include/unwindstack/Unwinder.h
+++ b/libunwindstack/include/unwindstack/Unwinder.h
@@ -24,6 +24,7 @@
#include <string>
#include <vector>
+#include <unwindstack/Error.h>
#include <unwindstack/Maps.h>
#include <unwindstack/Memory.h>
#include <unwindstack/Regs.h>
@@ -74,6 +75,9 @@
void SetJitDebug(JitDebug* jit_debug, ArchEnum arch);
+ ErrorCode LastErrorCode() { return last_error_.code; }
+ uint64_t LastErrorAddress() { return last_error_.address; }
+
private:
void FillInFrame(MapInfo* map_info, Elf* elf, uint64_t adjusted_rel_pc, uint64_t adjusted_pc);
@@ -83,6 +87,7 @@
std::vector<FrameData> frames_;
std::shared_ptr<Memory> process_memory_;
JitDebug* jit_debug_ = nullptr;
+ ErrorData last_error_;
};
} // namespace unwindstack
diff --git a/libunwindstack/tests/ArmExidxExtractTest.cpp b/libunwindstack/tests/ArmExidxExtractTest.cpp
index caad131..8d0f0e5 100644
--- a/libunwindstack/tests/ArmExidxExtractTest.cpp
+++ b/libunwindstack/tests/ArmExidxExtractTest.cpp
@@ -257,22 +257,27 @@
TEST_F(ArmExidxExtractTest, read_failures) {
ASSERT_FALSE(exidx_->ExtractEntryData(0x5000));
ASSERT_EQ(ARM_STATUS_READ_FAILED, exidx_->status());
+ EXPECT_EQ(0x5004U, exidx_->status_address());
elf_memory_.SetData32(0x5000, 0x100);
ASSERT_FALSE(exidx_->ExtractEntryData(0x5000));
ASSERT_EQ(ARM_STATUS_READ_FAILED, exidx_->status());
+ EXPECT_EQ(0x5004U, exidx_->status_address());
elf_memory_.SetData32(0x5004, 0x100);
ASSERT_FALSE(exidx_->ExtractEntryData(0x5000));
ASSERT_EQ(ARM_STATUS_READ_FAILED, exidx_->status());
+ EXPECT_EQ(0x5104U, exidx_->status_address());
elf_memory_.SetData32(0x5104, 0x1);
ASSERT_FALSE(exidx_->ExtractEntryData(0x5000));
ASSERT_EQ(ARM_STATUS_READ_FAILED, exidx_->status());
+ EXPECT_EQ(0x5108U, exidx_->status_address());
elf_memory_.SetData32(0x5108, 0x01010203);
ASSERT_FALSE(exidx_->ExtractEntryData(0x5000));
ASSERT_EQ(ARM_STATUS_READ_FAILED, exidx_->status());
+ EXPECT_EQ(0x510cU, exidx_->status_address());
}
TEST_F(ArmExidxExtractTest, malformed) {
diff --git a/libunwindstack/tests/DwarfCfaTest.cpp b/libunwindstack/tests/DwarfCfaTest.cpp
index 73a67ac..68dc30c 100644
--- a/libunwindstack/tests/DwarfCfaTest.cpp
+++ b/libunwindstack/tests/DwarfCfaTest.cpp
@@ -21,13 +21,13 @@
#include <gtest/gtest.h>
+#include <unwindstack/DwarfError.h>
#include <unwindstack/DwarfLocation.h>
#include <unwindstack/DwarfMemory.h>
#include <unwindstack/DwarfStructs.h>
#include <unwindstack/Log.h>
#include "DwarfCfa.h"
-#include "DwarfError.h"
#include "LogFake.h"
#include "MemoryFake.h"
@@ -78,7 +78,7 @@
dwarf_loc_regs_t loc_regs;
ASSERT_FALSE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x2000, 0x2001, &loc_regs));
- ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->cfa_->last_error());
+ ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->cfa_->LastErrorCode());
ASSERT_EQ(0x2001U, this->dmem_->cur_offset());
ASSERT_EQ("", GetFakeLogPrint());
@@ -198,7 +198,7 @@
dwarf_loc_regs_t loc_regs;
ASSERT_FALSE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x2000, 0x2001, &loc_regs));
- ASSERT_EQ(DWARF_ERROR_ILLEGAL_STATE, this->cfa_->last_error());
+ ASSERT_EQ(DWARF_ERROR_ILLEGAL_STATE, this->cfa_->LastErrorCode());
ASSERT_EQ(0x2001U, this->dmem_->cur_offset());
ASSERT_EQ(0U, loc_regs.size());
@@ -227,7 +227,7 @@
dwarf_loc_regs_t loc_regs;
ASSERT_FALSE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x4000, 0x4002, &loc_regs));
- ASSERT_EQ(DWARF_ERROR_ILLEGAL_STATE, this->cfa_->last_error());
+ ASSERT_EQ(DWARF_ERROR_ILLEGAL_STATE, this->cfa_->LastErrorCode());
ASSERT_EQ(0x4002U, this->dmem_->cur_offset());
ASSERT_EQ(0U, loc_regs.size());
@@ -594,7 +594,7 @@
// This fails because the cfa is not defined as a register.
ASSERT_FALSE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x100, 0x102, &loc_regs));
ASSERT_EQ(0U, loc_regs.size());
- ASSERT_EQ(DWARF_ERROR_ILLEGAL_STATE, this->cfa_->last_error());
+ ASSERT_EQ(DWARF_ERROR_ILLEGAL_STATE, this->cfa_->LastErrorCode());
ASSERT_EQ("4 unwind Attempt to set new register, but cfa is not already set to a register.\n",
GetFakeLogPrint());
@@ -637,7 +637,7 @@
// This fails because the cfa is not defined as a register.
ASSERT_FALSE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x100, 0x102, &loc_regs));
ASSERT_EQ(0U, loc_regs.size());
- ASSERT_EQ(DWARF_ERROR_ILLEGAL_STATE, this->cfa_->last_error());
+ ASSERT_EQ(DWARF_ERROR_ILLEGAL_STATE, this->cfa_->LastErrorCode());
ASSERT_EQ("4 unwind Attempt to set offset, but cfa is not set to a register.\n",
GetFakeLogPrint());
@@ -679,7 +679,7 @@
// This fails because the cfa is not defined as a register.
ASSERT_FALSE(this->cfa_->GetLocationInfo(this->fde_.pc_start, 0x100, 0x102, &loc_regs));
- ASSERT_EQ(DWARF_ERROR_ILLEGAL_STATE, this->cfa_->last_error());
+ ASSERT_EQ(DWARF_ERROR_ILLEGAL_STATE, this->cfa_->LastErrorCode());
ASSERT_EQ("4 unwind Attempt to set offset, but cfa is not set to a register.\n",
GetFakeLogPrint());
diff --git a/libunwindstack/tests/DwarfDebugFrameTest.cpp b/libunwindstack/tests/DwarfDebugFrameTest.cpp
index 07204bc..c28a41e 100644
--- a/libunwindstack/tests/DwarfDebugFrameTest.cpp
+++ b/libunwindstack/tests/DwarfDebugFrameTest.cpp
@@ -19,9 +19,10 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
+#include <unwindstack/DwarfError.h>
+
#include "DwarfDebugFrame.h"
#include "DwarfEncoding.h"
-#include "DwarfError.h"
#include "LogFake.h"
#include "MemoryFake.h"
@@ -142,7 +143,46 @@
this->memory_.SetData32(0x510c, 0x200);
ASSERT_FALSE(this->debug_frame_->Init(0x5000, 0x600));
- ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->debug_frame_->last_error());
+ ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->debug_frame_->LastErrorCode());
+}
+
+TYPED_TEST_P(DwarfDebugFrameTest, Init32_do_not_fail_on_bad_next_entry) {
+ // CIE 32 information.
+ this->memory_.SetData32(0x5000, 0xfc);
+ this->memory_.SetData32(0x5004, 0xffffffff);
+ this->memory_.SetData8(0x5008, 1);
+ this->memory_.SetData8(0x5009, '\0');
+
+ // FDE 32 information.
+ this->memory_.SetData32(0x5100, 0xfc);
+ this->memory_.SetData32(0x5104, 0);
+ this->memory_.SetData32(0x5108, 0x1500);
+ this->memory_.SetData32(0x510c, 0x200);
+
+ this->memory_.SetData32(0x5200, 0xfc);
+ this->memory_.SetData32(0x5204, 0);
+ this->memory_.SetData32(0x5208, 0x2500);
+ this->memory_.SetData32(0x520c, 0x300);
+
+ // CIE 32 information.
+ this->memory_.SetData32(0x5300, 0);
+ this->memory_.SetData32(0x5304, 0xffffffff);
+ this->memory_.SetData8(0x5308, 1);
+ this->memory_.SetData8(0x5309, '\0');
+
+ // FDE 32 information.
+ this->memory_.SetData32(0x5400, 0xfc);
+ this->memory_.SetData32(0x5404, 0x300);
+ this->memory_.SetData32(0x5408, 0x3500);
+ this->memory_.SetData32(0x540c, 0x400);
+
+ this->memory_.SetData32(0x5500, 0xfc);
+ this->memory_.SetData32(0x5504, 0x300);
+ this->memory_.SetData32(0x5508, 0x4500);
+ this->memory_.SetData32(0x550c, 0x500);
+
+ ASSERT_TRUE(this->debug_frame_->Init(0x5000, 0x600));
+ ASSERT_EQ(2U, this->debug_frame_->TestGetFdeCount());
}
TYPED_TEST_P(DwarfDebugFrameTest, Init64) {
@@ -228,7 +268,52 @@
this->memory_.SetData64(0x511c, 0x200);
ASSERT_FALSE(this->debug_frame_->Init(0x5000, 0x600));
- ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->debug_frame_->last_error());
+ ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->debug_frame_->LastErrorCode());
+}
+
+TYPED_TEST_P(DwarfDebugFrameTest, Init64_do_not_fail_on_bad_next_entry) {
+ // CIE 64 information.
+ this->memory_.SetData32(0x5000, 0xffffffff);
+ this->memory_.SetData64(0x5004, 0xf4);
+ this->memory_.SetData64(0x500c, 0xffffffffffffffffULL);
+ this->memory_.SetData8(0x5014, 1);
+ this->memory_.SetData8(0x5015, '\0');
+
+ // FDE 64 information.
+ this->memory_.SetData32(0x5100, 0xffffffff);
+ this->memory_.SetData64(0x5104, 0xf4);
+ this->memory_.SetData64(0x510c, 0);
+ this->memory_.SetData64(0x5114, 0x1500);
+ this->memory_.SetData64(0x511c, 0x200);
+
+ this->memory_.SetData32(0x5200, 0xffffffff);
+ this->memory_.SetData64(0x5204, 0xf4);
+ this->memory_.SetData64(0x520c, 0);
+ this->memory_.SetData64(0x5214, 0x2500);
+ this->memory_.SetData64(0x521c, 0x300);
+
+ // CIE 64 information.
+ this->memory_.SetData32(0x5300, 0xffffffff);
+ this->memory_.SetData64(0x5304, 0);
+ this->memory_.SetData64(0x530c, 0xffffffffffffffffULL);
+ this->memory_.SetData8(0x5314, 1);
+ this->memory_.SetData8(0x5315, '\0');
+
+ // FDE 64 information.
+ this->memory_.SetData32(0x5400, 0xffffffff);
+ this->memory_.SetData64(0x5404, 0xf4);
+ this->memory_.SetData64(0x540c, 0x300);
+ this->memory_.SetData64(0x5414, 0x3500);
+ this->memory_.SetData64(0x541c, 0x400);
+
+ this->memory_.SetData32(0x5500, 0xffffffff);
+ this->memory_.SetData64(0x5504, 0xf4);
+ this->memory_.SetData64(0x550c, 0x300);
+ this->memory_.SetData64(0x5514, 0x4500);
+ this->memory_.SetData64(0x551c, 0x500);
+
+ ASSERT_TRUE(this->debug_frame_->Init(0x5000, 0x600));
+ ASSERT_EQ(2U, this->debug_frame_->TestGetFdeCount());
}
TYPED_TEST_P(DwarfDebugFrameTest, Init_version1) {
@@ -320,11 +405,11 @@
this->debug_frame_->TestSetFdeCount(0);
uint64_t fde_offset;
ASSERT_FALSE(this->debug_frame_->GetFdeOffsetFromPc(0x1000, &fde_offset));
- ASSERT_EQ(DWARF_ERROR_NONE, this->debug_frame_->last_error());
+ ASSERT_EQ(DWARF_ERROR_NONE, this->debug_frame_->LastErrorCode());
this->debug_frame_->TestSetFdeCount(9);
ASSERT_FALSE(this->debug_frame_->GetFdeOffsetFromPc(0x100, &fde_offset));
- ASSERT_EQ(DWARF_ERROR_NONE, this->debug_frame_->last_error());
+ ASSERT_EQ(DWARF_ERROR_NONE, this->debug_frame_->LastErrorCode());
// Odd number of elements.
for (size_t i = 0; i < 9; i++) {
TypeParam pc = 0x1000 * (i + 1);
@@ -338,7 +423,7 @@
EXPECT_EQ(0x5000 + i * 0x20, fde_offset) << "Failed at index " << i;
ASSERT_FALSE(this->debug_frame_->GetFdeOffsetFromPc(pc + 0xfff, &fde_offset))
<< "Failed at index " << i;
- ASSERT_EQ(DWARF_ERROR_NONE, this->debug_frame_->last_error());
+ ASSERT_EQ(DWARF_ERROR_NONE, this->debug_frame_->LastErrorCode());
}
// Even number of elements.
@@ -360,7 +445,7 @@
EXPECT_EQ(0x5000 + i * 0x20, fde_offset) << "Failed at index " << i;
ASSERT_FALSE(this->debug_frame_->GetFdeOffsetFromPc(pc + 0xfff, &fde_offset))
<< "Failed at index " << i;
- ASSERT_EQ(DWARF_ERROR_NONE, this->debug_frame_->last_error());
+ ASSERT_EQ(DWARF_ERROR_NONE, this->debug_frame_->LastErrorCode());
}
}
@@ -450,9 +535,11 @@
EXPECT_EQ(0x20U, fde->cie->return_address_register);
}
-REGISTER_TYPED_TEST_CASE_P(DwarfDebugFrameTest, Init32, Init32_fde_not_following_cie, Init64,
- Init64_fde_not_following_cie, Init_version1, Init_version4,
- GetFdeOffsetFromPc, GetCieFde32, GetCieFde64);
+REGISTER_TYPED_TEST_CASE_P(DwarfDebugFrameTest, Init32, Init32_fde_not_following_cie,
+ Init32_do_not_fail_on_bad_next_entry, Init64,
+ Init64_do_not_fail_on_bad_next_entry, Init64_fde_not_following_cie,
+ Init_version1, Init_version4, GetFdeOffsetFromPc, GetCieFde32,
+ GetCieFde64);
typedef ::testing::Types<uint32_t, uint64_t> DwarfDebugFrameTestTypes;
INSTANTIATE_TYPED_TEST_CASE_P(, DwarfDebugFrameTest, DwarfDebugFrameTestTypes);
diff --git a/libunwindstack/tests/DwarfEhFrameTest.cpp b/libunwindstack/tests/DwarfEhFrameTest.cpp
index 3a629f8..a73db65 100644
--- a/libunwindstack/tests/DwarfEhFrameTest.cpp
+++ b/libunwindstack/tests/DwarfEhFrameTest.cpp
@@ -19,9 +19,10 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
+#include <unwindstack/DwarfError.h>
+
#include "DwarfEhFrame.h"
#include "DwarfEncoding.h"
-#include "DwarfError.h"
#include "LogFake.h"
#include "MemoryFake.h"
@@ -142,7 +143,7 @@
this->memory_.SetData32(0x510c, 0x200);
ASSERT_FALSE(this->eh_frame_->Init(0x5000, 0x600));
- ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->eh_frame_->last_error());
+ ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->eh_frame_->LastErrorCode());
}
TYPED_TEST_P(DwarfEhFrameTest, Init64) {
@@ -228,7 +229,7 @@
this->memory_.SetData64(0x511c, 0x200);
ASSERT_FALSE(this->eh_frame_->Init(0x5000, 0x600));
- ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->eh_frame_->last_error());
+ ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->eh_frame_->LastErrorCode());
}
TYPED_TEST_P(DwarfEhFrameTest, Init_version1) {
@@ -320,11 +321,11 @@
this->eh_frame_->TestSetFdeCount(0);
uint64_t fde_offset;
ASSERT_FALSE(this->eh_frame_->GetFdeOffsetFromPc(0x1000, &fde_offset));
- ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->last_error());
+ ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->LastErrorCode());
this->eh_frame_->TestSetFdeCount(9);
ASSERT_FALSE(this->eh_frame_->GetFdeOffsetFromPc(0x100, &fde_offset));
- ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->last_error());
+ ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->LastErrorCode());
// Odd number of elements.
for (size_t i = 0; i < 9; i++) {
TypeParam pc = 0x1000 * (i + 1);
@@ -337,7 +338,7 @@
EXPECT_EQ(0x5000 + i * 0x20, fde_offset) << "Failed at index " << i;
ASSERT_FALSE(this->eh_frame_->GetFdeOffsetFromPc(pc + 0xfff, &fde_offset))
<< "Failed at index " << i;
- ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->last_error());
+ ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->LastErrorCode());
}
// Even number of elements.
@@ -358,7 +359,7 @@
EXPECT_EQ(0x5000 + i * 0x20, fde_offset) << "Failed at index " << i;
ASSERT_FALSE(this->eh_frame_->GetFdeOffsetFromPc(pc + 0xfff, &fde_offset))
<< "Failed at index " << i;
- ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->last_error());
+ ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->LastErrorCode());
}
}
diff --git a/libunwindstack/tests/DwarfEhFrameWithHdrTest.cpp b/libunwindstack/tests/DwarfEhFrameWithHdrTest.cpp
index 64b325b..a2ae5eb 100644
--- a/libunwindstack/tests/DwarfEhFrameWithHdrTest.cpp
+++ b/libunwindstack/tests/DwarfEhFrameWithHdrTest.cpp
@@ -19,9 +19,10 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
+#include <unwindstack/DwarfError.h>
+
#include "DwarfEhFrameWithHdr.h"
#include "DwarfEncoding.h"
-#include "DwarfError.h"
#include "LogFake.h"
#include "MemoryFake.h"
@@ -94,22 +95,32 @@
EXPECT_EQ(0x1000U, this->eh_frame_->TestGetEntriesDataOffset());
EXPECT_EQ(0x100aU, this->eh_frame_->TestGetCurEntriesOffset());
+ // Verify a zero fde count fails to init.
+ this->memory_.SetData32(0x1006, 0);
+ ASSERT_FALSE(this->eh_frame_->Init(0x1000, 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);
ASSERT_FALSE(this->eh_frame_->Init(0x1000, 0x100));
- ASSERT_EQ(DWARF_ERROR_UNSUPPORTED_VERSION, this->eh_frame_->last_error());
+ ASSERT_EQ(DWARF_ERROR_UNSUPPORTED_VERSION, this->eh_frame_->LastErrorCode());
this->memory_.SetData8(0x1000, 2);
ASSERT_FALSE(this->eh_frame_->Init(0x1000, 0x100));
- ASSERT_EQ(DWARF_ERROR_UNSUPPORTED_VERSION, this->eh_frame_->last_error());
+ ASSERT_EQ(DWARF_ERROR_UNSUPPORTED_VERSION, this->eh_frame_->LastErrorCode());
}
TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeInfoFromIndex_expect_cache_fail) {
this->eh_frame_->TestSetTableEntrySize(0x10);
this->eh_frame_->TestSetTableEncoding(DW_EH_PE_udata4);
+ this->eh_frame_->TestSetEntriesOffset(0x1000);
+
ASSERT_TRUE(this->eh_frame_->GetFdeInfoFromIndex(0) == nullptr);
- ASSERT_EQ(DWARF_ERROR_MEMORY_INVALID, this->eh_frame_->last_error());
+ ASSERT_EQ(DWARF_ERROR_MEMORY_INVALID, this->eh_frame_->LastErrorCode());
+ EXPECT_EQ(0x1000U, this->eh_frame_->LastErrorAddress());
ASSERT_TRUE(this->eh_frame_->GetFdeInfoFromIndex(0) == nullptr);
- ASSERT_EQ(DWARF_ERROR_MEMORY_INVALID, this->eh_frame_->last_error());
+ ASSERT_EQ(DWARF_ERROR_MEMORY_INVALID, this->eh_frame_->LastErrorCode());
+ EXPECT_EQ(0x1000U, this->eh_frame_->LastErrorAddress());
}
TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeInfoFromIndex_read_pcrel) {
@@ -178,7 +189,7 @@
uint64_t fde_offset;
EXPECT_FALSE(this->eh_frame_->GetFdeOffsetBinary(0x100, &fde_offset, 10));
// Not an error, just not found.
- ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->last_error());
+ ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->LastErrorCode());
// Even number of elements.
for (size_t i = 0; i < 10; i++) {
TypeParam pc = 0x1000 * (i + 1);
@@ -274,7 +285,7 @@
uint64_t fde_offset;
ASSERT_FALSE(this->eh_frame_->GetFdeOffsetSequential(0x540, &fde_offset));
- ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->last_error());
+ ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->LastErrorCode());
}
TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeOffsetFromPc_fail_fde_count) {
@@ -282,7 +293,7 @@
uint64_t fde_offset;
ASSERT_FALSE(this->eh_frame_->GetFdeOffsetFromPc(0x100, &fde_offset));
- ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->last_error());
+ ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->LastErrorCode());
}
TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeOffsetFromPc_binary_search) {
diff --git a/libunwindstack/tests/DwarfOpLogTest.cpp b/libunwindstack/tests/DwarfOpLogTest.cpp
index 234d1c9..3f09dd8 100644
--- a/libunwindstack/tests/DwarfOpLogTest.cpp
+++ b/libunwindstack/tests/DwarfOpLogTest.cpp
@@ -21,11 +21,11 @@
#include <gtest/gtest.h>
+#include <unwindstack/DwarfError.h>
#include <unwindstack/DwarfMemory.h>
#include <unwindstack/Log.h>
#include <unwindstack/Regs.h>
-#include "DwarfError.h"
#include "DwarfOp.h"
#include "MemoryFake.h"
diff --git a/libunwindstack/tests/DwarfOpTest.cpp b/libunwindstack/tests/DwarfOpTest.cpp
index 2d5007b..036226d 100644
--- a/libunwindstack/tests/DwarfOpTest.cpp
+++ b/libunwindstack/tests/DwarfOpTest.cpp
@@ -21,10 +21,10 @@
#include <gtest/gtest.h>
+#include <unwindstack/DwarfError.h>
#include <unwindstack/DwarfMemory.h>
#include <unwindstack/Log.h>
-#include "DwarfError.h"
#include "DwarfOp.h"
#include "MemoryFake.h"
@@ -53,13 +53,14 @@
TYPED_TEST_P(DwarfOpTest, decode) {
// Memory error.
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_MEMORY_INVALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_MEMORY_INVALID, this->op_->LastErrorCode());
+ EXPECT_EQ(0U, this->op_->LastErrorAddress());
// No error.
this->op_memory_.SetMemory(0, std::vector<uint8_t>{0x96});
this->mem_->set_cur_offset(0);
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_NONE, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_NONE, this->op_->LastErrorCode());
ASSERT_EQ(0x96U, this->op_->cur_op());
ASSERT_EQ(1U, this->mem_->cur_offset());
}
@@ -67,7 +68,8 @@
TYPED_TEST_P(DwarfOpTest, eval) {
// Memory error.
ASSERT_FALSE(this->op_->Eval(0, 2, DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_MEMORY_INVALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_MEMORY_INVALID, this->op_->LastErrorCode());
+ EXPECT_EQ(0U, this->op_->LastErrorAddress());
// Register set.
// Do this first, to verify that subsequent calls reset the value.
@@ -84,7 +86,7 @@
this->op_memory_.SetMemory(0, opcode_buffer);
ASSERT_TRUE(this->op_->Eval(0, 8, DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_NONE, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_NONE, this->op_->LastErrorCode());
ASSERT_FALSE(this->op_->is_register());
ASSERT_EQ(8U, this->mem_->cur_offset());
ASSERT_EQ(4U, this->op_->StackSize());
@@ -96,7 +98,7 @@
// Infinite loop.
this->op_memory_.SetMemory(0, std::vector<uint8_t>{0x2f, 0xfd, 0xff});
ASSERT_FALSE(this->op_->Eval(0, 4, DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_TOO_MANY_ITERATIONS, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_TOO_MANY_ITERATIONS, this->op_->LastErrorCode());
ASSERT_FALSE(this->op_->is_register());
ASSERT_EQ(0U, this->op_->StackSize());
}
@@ -111,7 +113,7 @@
for (size_t i = 0; i < opcode_buffer.size(); i++) {
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->op_->LastErrorCode());
ASSERT_EQ(opcode_buffer[i], this->op_->cur_op());
}
}
@@ -122,7 +124,7 @@
for (size_t i = 0; i < opcode_buffer.size(); i++) {
ASSERT_FALSE(this->op_->Decode(2));
- ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->op_->LastErrorCode());
ASSERT_EQ(opcode_buffer[i], this->op_->cur_op());
}
}
@@ -133,7 +135,7 @@
for (size_t i = 0; i < opcode_buffer.size(); i++) {
ASSERT_FALSE(this->op_->Decode(3));
- ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->op_->LastErrorCode());
ASSERT_EQ(opcode_buffer[i], this->op_->cur_op());
}
}
@@ -178,7 +180,7 @@
while (this->mem_->cur_offset() < opcode_buffer.size()) {
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_NOT_IMPLEMENTED, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_NOT_IMPLEMENTED, this->op_->LastErrorCode());
}
}
@@ -216,7 +218,7 @@
this->regular_memory_.SetMemory(0x2010, &value, sizeof(value));
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(1U, this->op_->StackSize());
@@ -226,7 +228,8 @@
ASSERT_EQ(value, this->op_->StackAt(0));
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_MEMORY_INVALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_MEMORY_INVALID, this->op_->LastErrorCode());
+ ASSERT_EQ(0x12345678U, this->op_->LastErrorAddress());
}
TYPED_TEST_P(DwarfOpTest, op_deref_size) {
@@ -235,7 +238,7 @@
this->regular_memory_.SetMemory(0x2010, &value, sizeof(value));
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
// Read all byte sizes up to the sizeof the type.
for (size_t i = 1; i < sizeof(TypeParam); i++) {
@@ -252,17 +255,18 @@
// Zero byte read.
this->op_memory_.SetMemory(0, std::vector<uint8_t>{0x0a, 0x10, 0x20, 0x94, 0x00});
ASSERT_FALSE(this->op_->Eval(0, 5, DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->op_->last_error());
+ 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});
ASSERT_FALSE(this->op_->Eval(0, 5, DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->op_->last_error());
+ 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});
ASSERT_FALSE(this->op_->Eval(0, 5, DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_MEMORY_INVALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_MEMORY_INVALID, this->op_->LastErrorCode());
+ EXPECT_EQ(0x4010U, this->op_->LastErrorAddress());
}
TYPED_TEST_P(DwarfOpTest, const_unsigned) {
@@ -529,7 +533,7 @@
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(0x12, this->op_->cur_op());
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(1U, this->op_->StackSize());
@@ -577,7 +581,7 @@
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(0x13, this->op_->cur_op());
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
}
TYPED_TEST_P(DwarfOpTest, op_over) {
@@ -612,7 +616,7 @@
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(0x14, this->op_->cur_op());
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
}
TYPED_TEST_P(DwarfOpTest, op_pick) {
@@ -654,7 +658,7 @@
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(0x15, this->op_->cur_op());
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
}
TYPED_TEST_P(DwarfOpTest, op_swap) {
@@ -686,7 +690,7 @@
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(0x16, this->op_->cur_op());
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
}
TYPED_TEST_P(DwarfOpTest, op_rot) {
@@ -703,19 +707,19 @@
this->op_memory_.SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(1U, this->op_->StackSize());
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(2U, this->op_->StackSize());
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(3U, this->op_->StackSize());
@@ -753,7 +757,7 @@
this->op_memory_.SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(1U, this->op_->StackSize());
@@ -805,13 +809,13 @@
this->op_memory_.SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(1U, this->op_->StackSize());
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
// Two positive values.
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
@@ -854,7 +858,7 @@
ASSERT_EQ(5U, this->op_->StackSize());
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->op_->LastErrorCode());
}
TYPED_TEST_P(DwarfOpTest, op_div) {
@@ -871,13 +875,13 @@
this->op_memory_.SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(1U, this->op_->StackSize());
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(2U, this->op_->StackSize());
@@ -902,13 +906,13 @@
this->op_memory_.SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(1U, this->op_->StackSize());
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(2U, this->op_->StackSize());
@@ -935,13 +939,13 @@
this->op_memory_.SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(1U, this->op_->StackSize());
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(2U, this->op_->StackSize());
@@ -957,7 +961,7 @@
ASSERT_EQ(3U, this->op_->StackSize());
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->op_->LastErrorCode());
}
TYPED_TEST_P(DwarfOpTest, op_mul) {
@@ -974,13 +978,13 @@
this->op_memory_.SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(1U, this->op_->StackSize());
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(2U, this->op_->StackSize());
@@ -1003,7 +1007,7 @@
this->op_memory_.SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(1U, this->op_->StackSize());
@@ -1034,7 +1038,7 @@
this->op_memory_.SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(1U, this->op_->StackSize());
@@ -1067,13 +1071,13 @@
this->op_memory_.SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(1U, this->op_->StackSize());
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(2U, this->op_->StackSize());
@@ -1098,13 +1102,13 @@
this->op_memory_.SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(1U, this->op_->StackSize());
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(2U, this->op_->StackSize());
@@ -1125,7 +1129,7 @@
this->op_memory_.SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(1U, this->op_->StackSize());
@@ -1150,13 +1154,13 @@
this->op_memory_.SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(1U, this->op_->StackSize());
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(2U, this->op_->StackSize());
@@ -1181,13 +1185,13 @@
this->op_memory_.SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(1U, this->op_->StackSize());
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(2U, this->op_->StackSize());
@@ -1216,13 +1220,13 @@
this->op_memory_.SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(1U, this->op_->StackSize());
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(2U, this->op_->StackSize());
@@ -1247,13 +1251,13 @@
this->op_memory_.SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(1U, this->op_->StackSize());
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
ASSERT_EQ(2U, this->op_->StackSize());
@@ -1280,7 +1284,7 @@
this->op_memory_.SetMemory(0, opcode_buffer);
ASSERT_FALSE(this->op_->Decode(DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
// Push on a non-zero value with a positive branch.
ASSERT_TRUE(this->op_->Decode(DWARF_VERSION_MAX));
@@ -1342,12 +1346,12 @@
ASSERT_FALSE(this->op_->Eval(0, 1, DWARF_VERSION_MAX));
ASSERT_EQ(opcode, this->op_->cur_op());
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
ASSERT_FALSE(this->op_->Eval(1, 4, DWARF_VERSION_MAX));
ASSERT_EQ(opcode, this->op_->cur_op());
ASSERT_EQ(1U, this->op_->StackSize());
- ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_STACK_INDEX_NOT_VALID, this->op_->LastErrorCode());
}
}
@@ -1532,7 +1536,7 @@
// Should fail since this references a non-existent register.
ASSERT_FALSE(this->op_->Eval(2, 4, DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->op_->LastErrorCode());
}
TYPED_TEST_P(DwarfOpTest, op_bregx) {
@@ -1560,7 +1564,7 @@
ASSERT_EQ(0x90U, this->op_->StackAt(0));
ASSERT_FALSE(this->op_->Eval(7, 12, DWARF_VERSION_MAX));
- ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->op_->last_error());
+ ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->op_->LastErrorCode());
}
TYPED_TEST_P(DwarfOpTest, op_nop) {
diff --git a/libunwindstack/tests/DwarfSectionImplTest.cpp b/libunwindstack/tests/DwarfSectionImplTest.cpp
index dfd2ce0..7e10935 100644
--- a/libunwindstack/tests/DwarfSectionImplTest.cpp
+++ b/libunwindstack/tests/DwarfSectionImplTest.cpp
@@ -19,10 +19,10 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
+#include <unwindstack/DwarfError.h>
#include <unwindstack/DwarfSection.h>
#include "DwarfEncoding.h"
-#include "DwarfError.h"
#include "LogFake.h"
#include "MemoryFake.h"
@@ -67,7 +67,7 @@
}
void TestClearCachedCieLocRegs() { this->cie_loc_regs_.clear(); }
- void TestClearError() { this->last_error_ = DWARF_ERROR_NONE; }
+ void TestClearError() { this->last_error_.code = DWARF_ERROR_NONE; }
};
template <typename TypeParam>
@@ -102,7 +102,8 @@
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_EXPRESSION, {0x2, 0x5000}};
bool finished;
ASSERT_FALSE(this->section_->Eval(&cie, &this->memory_, loc_regs, ®s, &finished));
- EXPECT_EQ(DWARF_ERROR_MEMORY_INVALID, this->section_->last_error());
+ EXPECT_EQ(DWARF_ERROR_MEMORY_INVALID, this->section_->LastErrorCode());
+ EXPECT_EQ(0x5000U, this->section_->LastErrorAddress());
}
TYPED_TEST_P(DwarfSectionImplTest, Eval_cfa_expr_no_stack) {
@@ -118,7 +119,7 @@
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_EXPRESSION, {0x2, 0x5000}};
bool finished;
ASSERT_FALSE(this->section_->Eval(&cie, &this->memory_, loc_regs, ®s, &finished));
- EXPECT_EQ(DWARF_ERROR_ILLEGAL_STATE, this->section_->last_error());
+ EXPECT_EQ(DWARF_ERROR_ILLEGAL_STATE, this->section_->LastErrorCode());
}
TYPED_TEST_P(DwarfSectionImplTest, Eval_cfa_expr) {
@@ -172,7 +173,7 @@
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_EXPRESSION, {0x2, 0x5000}};
bool finished;
ASSERT_FALSE(this->section_->Eval(&cie, &this->memory_, loc_regs, ®s, &finished));
- EXPECT_EQ(DWARF_ERROR_NOT_IMPLEMENTED, this->section_->last_error());
+ EXPECT_EQ(DWARF_ERROR_NOT_IMPLEMENTED, this->section_->LastErrorCode());
}
TYPED_TEST_P(DwarfSectionImplTest, Eval_bad_regs) {
@@ -182,7 +183,7 @@
bool finished;
ASSERT_FALSE(this->section_->Eval(&cie, &this->memory_, loc_regs, ®s, &finished));
- EXPECT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->section_->last_error());
+ EXPECT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->section_->LastErrorCode());
}
TYPED_TEST_P(DwarfSectionImplTest, Eval_no_cfa) {
@@ -192,7 +193,7 @@
bool finished;
ASSERT_FALSE(this->section_->Eval(&cie, &this->memory_, loc_regs, ®s, &finished));
- EXPECT_EQ(DWARF_ERROR_CFA_NOT_DEFINED, this->section_->last_error());
+ EXPECT_EQ(DWARF_ERROR_CFA_NOT_DEFINED, this->section_->LastErrorCode());
}
TYPED_TEST_P(DwarfSectionImplTest, Eval_cfa_bad) {
@@ -203,25 +204,25 @@
loc_regs[CFA_REG] = DwarfLocation{DWARF_LOCATION_REGISTER, {20, 0}};
bool finished;
ASSERT_FALSE(this->section_->Eval(&cie, &this->memory_, loc_regs, ®s, &finished));
- EXPECT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->section_->last_error());
+ EXPECT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->section_->LastErrorCode());
this->section_->TestClearError();
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, ®s, &finished));
- EXPECT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->section_->last_error());
+ EXPECT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->section_->LastErrorCode());
this->section_->TestClearError();
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, ®s, &finished));
- EXPECT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->section_->last_error());
+ EXPECT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->section_->LastErrorCode());
this->section_->TestClearError();
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, ®s, &finished));
- EXPECT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->section_->last_error());
+ EXPECT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->section_->LastErrorCode());
}
TYPED_TEST_P(DwarfSectionImplTest, Eval_cfa_register_prev) {
@@ -341,7 +342,7 @@
loc_regs[1] = DwarfLocation{DWARF_LOCATION_REGISTER, {10, 0}};
bool finished;
ASSERT_FALSE(this->section_->Eval(&cie, &this->memory_, loc_regs, ®s, &finished));
- EXPECT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->section_->last_error());
+ EXPECT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->section_->LastErrorCode());
}
TYPED_TEST_P(DwarfSectionImplTest, Eval_different_reg_locations) {
@@ -489,10 +490,12 @@
TYPED_TEST_P(DwarfSectionImplTest, GetCie_fail_should_not_cache) {
ASSERT_TRUE(this->section_->GetCie(0x4000) == nullptr);
- EXPECT_EQ(DWARF_ERROR_MEMORY_INVALID, this->section_->last_error());
+ EXPECT_EQ(DWARF_ERROR_MEMORY_INVALID, this->section_->LastErrorCode());
+ EXPECT_EQ(0x4000U, this->section_->LastErrorAddress());
this->section_->TestClearError();
ASSERT_TRUE(this->section_->GetCie(0x4000) == nullptr);
- EXPECT_EQ(DWARF_ERROR_MEMORY_INVALID, this->section_->last_error());
+ EXPECT_EQ(DWARF_ERROR_MEMORY_INVALID, this->section_->LastErrorCode());
+ EXPECT_EQ(0x4000U, this->section_->LastErrorAddress());
}
TYPED_TEST_P(DwarfSectionImplTest, GetCie_32_version_check) {
@@ -518,24 +521,24 @@
EXPECT_EQ(4U, cie->code_alignment_factor);
EXPECT_EQ(8, cie->data_alignment_factor);
EXPECT_EQ(0x20U, cie->return_address_register);
- EXPECT_EQ(DWARF_ERROR_NONE, this->section_->last_error());
+ EXPECT_EQ(DWARF_ERROR_NONE, this->section_->LastErrorCode());
this->section_->TestClearCachedCieEntry();
// Set version to 0, 2, 5 and verify we fail.
this->memory_.SetData8(0x5008, 0x0);
this->section_->TestClearError();
ASSERT_TRUE(this->section_->GetCie(0x5000) == nullptr);
- EXPECT_EQ(DWARF_ERROR_UNSUPPORTED_VERSION, this->section_->last_error());
+ EXPECT_EQ(DWARF_ERROR_UNSUPPORTED_VERSION, this->section_->LastErrorCode());
this->memory_.SetData8(0x5008, 0x2);
this->section_->TestClearError();
ASSERT_TRUE(this->section_->GetCie(0x5000) == nullptr);
- EXPECT_EQ(DWARF_ERROR_UNSUPPORTED_VERSION, this->section_->last_error());
+ EXPECT_EQ(DWARF_ERROR_UNSUPPORTED_VERSION, this->section_->LastErrorCode());
this->memory_.SetData8(0x5008, 0x5);
this->section_->TestClearError();
ASSERT_TRUE(this->section_->GetCie(0x5000) == nullptr);
- EXPECT_EQ(DWARF_ERROR_UNSUPPORTED_VERSION, this->section_->last_error());
+ EXPECT_EQ(DWARF_ERROR_UNSUPPORTED_VERSION, this->section_->LastErrorCode());
}
TYPED_TEST_P(DwarfSectionImplTest, GetCie_negative_data_alignment_factor) {
@@ -681,10 +684,12 @@
TYPED_TEST_P(DwarfSectionImplTest, GetFdeFromOffset_fail_should_not_cache) {
ASSERT_TRUE(this->section_->GetFdeFromOffset(0x4000) == nullptr);
- EXPECT_EQ(DWARF_ERROR_MEMORY_INVALID, this->section_->last_error());
+ EXPECT_EQ(DWARF_ERROR_MEMORY_INVALID, this->section_->LastErrorCode());
+ EXPECT_EQ(0x4000U, this->section_->LastErrorAddress());
this->section_->TestClearError();
ASSERT_TRUE(this->section_->GetFdeFromOffset(0x4000) == nullptr);
- EXPECT_EQ(DWARF_ERROR_MEMORY_INVALID, this->section_->last_error());
+ EXPECT_EQ(DWARF_ERROR_MEMORY_INVALID, this->section_->LastErrorCode());
+ EXPECT_EQ(0x4000U, this->section_->LastErrorAddress());
}
TYPED_TEST_P(DwarfSectionImplTest, GetFdeFromOffset_32_no_augment) {
diff --git a/libunwindstack/tests/ElfCacheTest.cpp b/libunwindstack/tests/ElfCacheTest.cpp
new file mode 100644
index 0000000..0086c9e
--- /dev/null
+++ b/libunwindstack/tests/ElfCacheTest.cpp
@@ -0,0 +1,201 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <elf.h>
+#include <unistd.h>
+
+#include <android-base/file.h>
+#include <android-base/test_utils.h>
+
+#include <gtest/gtest.h>
+
+#include <unwindstack/Elf.h>
+#include <unwindstack/MapInfo.h>
+
+#include "ElfTestUtils.h"
+#include "MemoryFake.h"
+
+namespace unwindstack {
+
+class ElfCacheTest : public ::testing::Test {
+ protected:
+ static void SetUpTestCase() { memory_.reset(new MemoryFake); }
+
+ void SetUp() override { Elf::SetCachingEnabled(true); }
+
+ void TearDown() override { Elf::SetCachingEnabled(false); }
+
+ void WriteElfFile(uint64_t offset, TemporaryFile* tf, uint32_t type) {
+ ASSERT_TRUE(type == EM_ARM || type == EM_386 || type == EM_X86_64);
+ size_t ehdr_size;
+ Elf32_Ehdr ehdr32;
+ Elf64_Ehdr ehdr64;
+ void* ptr;
+ if (type == EM_ARM || type == EM_386) {
+ ehdr_size = sizeof(ehdr32);
+ ptr = &ehdr32;
+ TestInitEhdr(&ehdr32, ELFCLASS32, type);
+ } else {
+ ehdr_size = sizeof(ehdr64);
+ ptr = &ehdr64;
+ TestInitEhdr(&ehdr64, ELFCLASS64, type);
+ }
+
+ ASSERT_EQ(offset, static_cast<uint64_t>(lseek(tf->fd, offset, SEEK_SET)));
+ ASSERT_TRUE(android::base::WriteFully(tf->fd, ptr, ehdr_size));
+ }
+
+ void VerifyWithinSameMap(bool cache_enabled);
+ void VerifySameMap(bool cache_enabled);
+
+ static std::shared_ptr<Memory> memory_;
+};
+
+std::shared_ptr<Memory> ElfCacheTest::memory_;
+
+void ElfCacheTest::VerifySameMap(bool cache_enabled) {
+ if (!cache_enabled) {
+ Elf::SetCachingEnabled(false);
+ }
+
+ TemporaryFile tf;
+ ASSERT_TRUE(tf.fd != -1);
+ WriteElfFile(0, &tf, EM_ARM);
+ close(tf.fd);
+
+ uint64_t start = 0x1000;
+ uint64_t end = 0x20000;
+ MapInfo info1(start, end, 0, 0x5, tf.path);
+ MapInfo info2(start, end, 0, 0x5, tf.path);
+
+ Elf* elf1 = info1.GetElf(memory_, true);
+ ASSERT_TRUE(elf1->valid());
+ Elf* elf2 = info2.GetElf(memory_, true);
+ ASSERT_TRUE(elf2->valid());
+
+ if (cache_enabled) {
+ EXPECT_EQ(elf1, elf2);
+ } else {
+ EXPECT_NE(elf1, elf2);
+ }
+}
+
+TEST_F(ElfCacheTest, no_caching) {
+ VerifySameMap(false);
+}
+
+TEST_F(ElfCacheTest, caching_invalid_elf) {
+ VerifySameMap(true);
+}
+
+void ElfCacheTest::VerifyWithinSameMap(bool cache_enabled) {
+ if (!cache_enabled) {
+ Elf::SetCachingEnabled(false);
+ }
+
+ TemporaryFile tf;
+ ASSERT_TRUE(tf.fd != -1);
+ WriteElfFile(0, &tf, EM_ARM);
+ WriteElfFile(0x100, &tf, EM_386);
+ WriteElfFile(0x200, &tf, EM_X86_64);
+ lseek(tf.fd, 0x500, SEEK_SET);
+ uint8_t value = 0;
+ write(tf.fd, &value, 1);
+ close(tf.fd);
+
+ uint64_t start = 0x1000;
+ uint64_t end = 0x20000;
+ // Will have an elf at offset 0 in file.
+ MapInfo info0_1(start, end, 0, 0x5, tf.path);
+ MapInfo info0_2(start, end, 0, 0x5, tf.path);
+ // Will have an elf at offset 0x100 in file.
+ MapInfo info100_1(start, end, 0x100, 0x5, tf.path);
+ MapInfo info100_2(start, end, 0x100, 0x5, tf.path);
+ // Will have an elf at offset 0x200 in file.
+ MapInfo info200_1(start, end, 0x200, 0x5, tf.path);
+ MapInfo info200_2(start, end, 0x200, 0x5, tf.path);
+ // Will have an elf at offset 0 in file.
+ MapInfo info300_1(start, end, 0x300, 0x5, tf.path);
+ MapInfo info300_2(start, end, 0x300, 0x5, tf.path);
+
+ Elf* elf0_1 = info0_1.GetElf(memory_, true);
+ ASSERT_TRUE(elf0_1->valid());
+ EXPECT_EQ(ARCH_ARM, elf0_1->arch());
+ Elf* elf0_2 = info0_2.GetElf(memory_, true);
+ ASSERT_TRUE(elf0_2->valid());
+ EXPECT_EQ(ARCH_ARM, elf0_2->arch());
+ EXPECT_EQ(0U, info0_1.elf_offset);
+ EXPECT_EQ(0U, info0_2.elf_offset);
+ if (cache_enabled) {
+ EXPECT_EQ(elf0_1, elf0_2);
+ } else {
+ EXPECT_NE(elf0_1, elf0_2);
+ }
+
+ Elf* elf100_1 = info100_1.GetElf(memory_, true);
+ ASSERT_TRUE(elf100_1->valid());
+ EXPECT_EQ(ARCH_X86, elf100_1->arch());
+ Elf* elf100_2 = info100_2.GetElf(memory_, true);
+ ASSERT_TRUE(elf100_2->valid());
+ EXPECT_EQ(ARCH_X86, elf100_2->arch());
+ EXPECT_EQ(0U, info100_1.elf_offset);
+ EXPECT_EQ(0U, info100_2.elf_offset);
+ if (cache_enabled) {
+ EXPECT_EQ(elf100_1, elf100_2);
+ } else {
+ EXPECT_NE(elf100_1, elf100_2);
+ }
+
+ Elf* elf200_1 = info200_1.GetElf(memory_, true);
+ ASSERT_TRUE(elf200_1->valid());
+ EXPECT_EQ(ARCH_X86_64, elf200_1->arch());
+ Elf* elf200_2 = info200_2.GetElf(memory_, true);
+ ASSERT_TRUE(elf200_2->valid());
+ EXPECT_EQ(ARCH_X86_64, elf200_2->arch());
+ EXPECT_EQ(0U, info200_1.elf_offset);
+ EXPECT_EQ(0U, info200_2.elf_offset);
+ if (cache_enabled) {
+ EXPECT_EQ(elf200_1, elf200_2);
+ } else {
+ EXPECT_NE(elf200_1, elf200_2);
+ }
+
+ Elf* elf300_1 = info300_1.GetElf(memory_, true);
+ ASSERT_TRUE(elf300_1->valid());
+ EXPECT_EQ(ARCH_ARM, elf300_1->arch());
+ Elf* elf300_2 = info300_2.GetElf(memory_, true);
+ ASSERT_TRUE(elf300_2->valid());
+ EXPECT_EQ(ARCH_ARM, elf300_2->arch());
+ EXPECT_EQ(0x300U, info300_1.elf_offset);
+ EXPECT_EQ(0x300U, info300_2.elf_offset);
+ if (cache_enabled) {
+ EXPECT_EQ(elf300_1, elf300_2);
+ EXPECT_EQ(elf0_1, elf300_1);
+ } else {
+ EXPECT_NE(elf300_1, elf300_2);
+ EXPECT_NE(elf0_1, elf300_1);
+ }
+}
+
+TEST_F(ElfCacheTest, no_caching_valid_elf_offset_non_zero) {
+ VerifyWithinSameMap(false);
+}
+
+TEST_F(ElfCacheTest, caching_valid_elf_offset_non_zero) {
+ VerifyWithinSameMap(true);
+}
+
+} // namespace unwindstack
diff --git a/libunwindstack/tests/ElfFake.h b/libunwindstack/tests/ElfFake.h
index 099026c..e232986 100644
--- a/libunwindstack/tests/ElfFake.h
+++ b/libunwindstack/tests/ElfFake.h
@@ -87,6 +87,10 @@
steps_.clear();
}
+ void FakeSetErrorCode(ErrorCode code) { last_error_.code = code; }
+
+ void FakeSetErrorAddress(uint64_t address) { last_error_.address = address; }
+
private:
std::unordered_map<std::string, uint64_t> globals_;
diff --git a/libunwindstack/tests/ElfInterfaceArmTest.cpp b/libunwindstack/tests/ElfInterfaceArmTest.cpp
index e6763ab..31d6a63 100644
--- a/libunwindstack/tests/ElfInterfaceArmTest.cpp
+++ b/libunwindstack/tests/ElfInterfaceArmTest.cpp
@@ -303,6 +303,7 @@
// FindEntry fails.
bool finished;
ASSERT_FALSE(interface.StepExidx(0x7000, 0, nullptr, nullptr, &finished));
+ EXPECT_EQ(ERROR_UNWIND_INFO, interface.LastErrorCode());
// ExtractEntry should fail.
interface.FakeSetStartOffset(0x1000);
@@ -316,14 +317,18 @@
regs.set_sp(regs[ARM_REG_SP]);
regs.set_pc(0x1234);
ASSERT_FALSE(interface.StepExidx(0x7000, 0, ®s, &process_memory_, &finished));
+ EXPECT_EQ(ERROR_MEMORY_INVALID, interface.LastErrorCode());
+ EXPECT_EQ(0x1004U, interface.LastErrorAddress());
// Eval should fail.
memory_.SetData32(0x1004, 0x81000000);
ASSERT_FALSE(interface.StepExidx(0x7000, 0, ®s, &process_memory_, &finished));
+ EXPECT_EQ(ERROR_UNWIND_INFO, interface.LastErrorCode());
// Everything should pass.
memory_.SetData32(0x1004, 0x80b0b0b0);
ASSERT_TRUE(interface.StepExidx(0x7000, 0, ®s, &process_memory_, &finished));
+ EXPECT_EQ(ERROR_UNWIND_INFO, interface.LastErrorCode());
ASSERT_FALSE(finished);
ASSERT_EQ(0x1000U, regs.sp());
ASSERT_EQ(0x1000U, regs[ARM_REG_SP]);
@@ -332,9 +337,11 @@
// Load bias is non-zero.
ASSERT_TRUE(interface.StepExidx(0x8000, 0x1000, ®s, &process_memory_, &finished));
+ EXPECT_EQ(ERROR_UNWIND_INFO, interface.LastErrorCode());
// Pc too small.
ASSERT_FALSE(interface.StepExidx(0x8000, 0x9000, ®s, &process_memory_, &finished));
+ EXPECT_EQ(ERROR_UNWIND_INFO, interface.LastErrorCode());
}
TEST_F(ElfInterfaceArmTest, StepExidx_pc_set) {
@@ -356,6 +363,7 @@
// Everything should pass.
bool finished;
ASSERT_TRUE(interface.StepExidx(0x7000, 0, ®s, &process_memory_, &finished));
+ EXPECT_EQ(ERROR_NONE, interface.LastErrorCode());
ASSERT_FALSE(finished);
ASSERT_EQ(0x10004U, regs.sp());
ASSERT_EQ(0x10004U, regs[ARM_REG_SP]);
@@ -379,6 +387,7 @@
bool finished;
ASSERT_TRUE(interface.StepExidx(0x7000, 0, ®s, &process_memory_, &finished));
+ EXPECT_EQ(ERROR_NONE, interface.LastErrorCode());
ASSERT_TRUE(finished);
ASSERT_EQ(0x10000U, regs.sp());
ASSERT_EQ(0x10000U, regs[ARM_REG_SP]);
@@ -401,6 +410,7 @@
bool finished;
ASSERT_TRUE(interface.StepExidx(0x7000, 0, ®s, &process_memory_, &finished));
+ EXPECT_EQ(ERROR_NONE, interface.LastErrorCode());
ASSERT_TRUE(finished);
ASSERT_EQ(0x10000U, regs.sp());
ASSERT_EQ(0x10000U, regs[ARM_REG_SP]);
@@ -427,6 +437,7 @@
bool finished;
ASSERT_TRUE(interface.StepExidx(0x7000, 0, ®s, &process_memory_, &finished));
+ EXPECT_EQ(ERROR_NONE, interface.LastErrorCode());
ASSERT_TRUE(finished);
ASSERT_EQ(0U, regs.pc());
@@ -439,6 +450,7 @@
regs.set_pc(0x1234);
ASSERT_TRUE(interface.StepExidx(0x7000, 0, ®s, &process_memory_, &finished));
+ EXPECT_EQ(ERROR_NONE, interface.LastErrorCode());
ASSERT_TRUE(finished);
ASSERT_EQ(0U, regs.pc());
}
diff --git a/libunwindstack/tests/ElfTest.cpp b/libunwindstack/tests/ElfTest.cpp
index 7e6a62a..eb85033 100644
--- a/libunwindstack/tests/ElfTest.cpp
+++ b/libunwindstack/tests/ElfTest.cpp
@@ -581,4 +581,30 @@
EXPECT_TRUE(elf.IsValidPc(0x1500));
}
+TEST_F(ElfTest, error_code_not_valid) {
+ ElfFake elf(memory_);
+ elf.FakeSetValid(false);
+
+ ErrorData error{ERROR_MEMORY_INVALID, 0x100};
+ elf.GetLastError(&error);
+ EXPECT_EQ(ERROR_MEMORY_INVALID, error.code);
+ EXPECT_EQ(0x100U, error.address);
+}
+
+TEST_F(ElfTest, error_code_valid) {
+ ElfFake elf(memory_);
+ elf.FakeSetValid(true);
+ ElfInterfaceFake* interface = new ElfInterfaceFake(memory_);
+ elf.FakeSetInterface(interface);
+ interface->FakeSetErrorCode(ERROR_MEMORY_INVALID);
+ interface->FakeSetErrorAddress(0x1000);
+
+ ErrorData error{ERROR_NONE, 0};
+ elf.GetLastError(&error);
+ EXPECT_EQ(ERROR_MEMORY_INVALID, error.code);
+ EXPECT_EQ(0x1000U, error.address);
+ EXPECT_EQ(ERROR_MEMORY_INVALID, elf.GetLastErrorCode());
+ EXPECT_EQ(0x1000U, elf.GetLastErrorAddress());
+}
+
} // namespace unwindstack
diff --git a/libunwindstack/tests/JitDebugTest.cpp b/libunwindstack/tests/JitDebugTest.cpp
index 1a50989..37628f8 100644
--- a/libunwindstack/tests/JitDebugTest.cpp
+++ b/libunwindstack/tests/JitDebugTest.cpp
@@ -62,7 +62,7 @@
ElfInterfaceFake* interface = new ElfInterfaceFake(elf_memories_.back());
elf->FakeSetInterface(interface);
interface->FakeSetGlobalVariable("__jit_debug_descriptor", 0x800);
- map_info->elf = elf;
+ map_info->elf.reset(elf);
map_info = maps_->Get(5);
ASSERT_TRUE(map_info != nullptr);
@@ -72,7 +72,7 @@
interface = new ElfInterfaceFake(elf_memories_.back());
elf->FakeSetInterface(interface);
interface->FakeSetGlobalVariable("__jit_debug_descriptor", 0x800);
- map_info->elf = elf;
+ map_info->elf.reset(elf);
map_info = maps_->Get(6);
ASSERT_TRUE(map_info != nullptr);
@@ -82,7 +82,7 @@
interface = new ElfInterfaceFake(elf_memories_.back());
elf->FakeSetInterface(interface);
interface->FakeSetGlobalVariable("__jit_debug_descriptor", 0x800);
- map_info->elf = elf;
+ map_info->elf.reset(elf);
}
template <typename EhdrType, typename ShdrType>
diff --git a/libunwindstack/tests/MapInfoGetElfTest.cpp b/libunwindstack/tests/MapInfoGetElfTest.cpp
index 948597b..f599503 100644
--- a/libunwindstack/tests/MapInfoGetElfTest.cpp
+++ b/libunwindstack/tests/MapInfoGetElfTest.cpp
@@ -180,16 +180,14 @@
ASSERT_TRUE(elf != nullptr);
ASSERT_FALSE(elf->valid());
- delete info.elf;
- info.elf = nullptr;
+ info.elf.reset();
info.end = 0xfff;
elf = info.GetElf(process_memory_, false);
ASSERT_TRUE(elf != nullptr);
ASSERT_FALSE(elf->valid());
// Make sure this test is valid.
- delete info.elf;
- info.elf = nullptr;
+ info.elf.reset();
info.end = 0x2000;
elf = info.GetElf(process_memory_, false);
ASSERT_TRUE(elf != nullptr);
@@ -328,8 +326,7 @@
ASSERT_TRUE(elf != nullptr);
ASSERT_FALSE(elf->valid());
- delete info.elf;
- info.elf = nullptr;
+ info.elf.reset();
info.flags = PROT_READ;
elf = info.GetElf(process_memory_, false);
ASSERT_TRUE(elf->valid());
@@ -352,15 +349,13 @@
ASSERT_FALSE(elf->valid());
// Set the name to nothing to verify that it still fails.
- delete info.elf;
- info.elf = nullptr;
+ info.elf.reset();
info.name = "";
elf = info.GetElf(process_memory_, false);
ASSERT_FALSE(elf->valid());
// Change the flags and verify the elf is valid now.
- delete info.elf;
- info.elf = nullptr;
+ info.elf.reset();
info.flags = PROT_READ;
elf = info.GetElf(process_memory_, false);
ASSERT_TRUE(elf->valid());
@@ -403,7 +398,7 @@
}
// Now verify that all of the elf files are exactly the same and valid.
- Elf* elf = info.elf;
+ Elf* elf = info.elf.get();
ASSERT_TRUE(elf != nullptr);
EXPECT_TRUE(elf->valid());
for (size_t i = 0; i < kNumConcurrentThreads; i++) {
diff --git a/libunwindstack/tests/MapInfoGetLoadBiasTest.cpp b/libunwindstack/tests/MapInfoGetLoadBiasTest.cpp
index 631036b..7e64a8a 100644
--- a/libunwindstack/tests/MapInfoGetLoadBiasTest.cpp
+++ b/libunwindstack/tests/MapInfoGetLoadBiasTest.cpp
@@ -69,7 +69,7 @@
}
TEST_F(MapInfoGetLoadBiasTest, load_bias_cached_from_elf) {
- map_info_->elf = elf_container_.release();
+ map_info_->elf.reset(elf_container_.release());
elf_->FakeSetLoadBias(0);
EXPECT_EQ(0U, map_info_->GetLoadBias(process_memory_));
@@ -79,7 +79,7 @@
}
TEST_F(MapInfoGetLoadBiasTest, elf_exists) {
- map_info_->elf = elf_container_.release();
+ map_info_->elf.reset(elf_container_.release());
elf_->FakeSetLoadBias(0);
EXPECT_EQ(0U, map_info_->GetLoadBias(process_memory_));
@@ -122,7 +122,7 @@
}
TEST_F(MapInfoGetLoadBiasTest, multiple_thread_elf_exists) {
- map_info_->elf = elf_container_.release();
+ map_info_->elf.reset(elf_container_.release());
elf_->FakeSetLoadBias(0x1000);
MultipleThreadTest(0x1000);
diff --git a/libunwindstack/tests/RegsTest.cpp b/libunwindstack/tests/RegsTest.cpp
index 15d5458..7c06373 100644
--- a/libunwindstack/tests/RegsTest.cpp
+++ b/libunwindstack/tests/RegsTest.cpp
@@ -184,7 +184,7 @@
RegsMips64 regs_mips64;
MapInfo map_info(0x1000, 0x2000);
Elf* invalid_elf = new Elf(new MemoryFake);
- map_info.elf = invalid_elf;
+ map_info.elf.reset(invalid_elf);
regs_arm.set_pc(0x1500);
EXPECT_EQ(0x500U, invalid_elf->GetRelPc(regs_arm.pc(), &map_info));
diff --git a/libunwindstack/tests/UnwindOfflineTest.cpp b/libunwindstack/tests/UnwindOfflineTest.cpp
index 582ac18..09376ab 100644
--- a/libunwindstack/tests/UnwindOfflineTest.cpp
+++ b/libunwindstack/tests/UnwindOfflineTest.cpp
@@ -625,4 +625,127 @@
frame_info);
}
+// The eh_frame_hdr data is present but set to zero fdes. This should
+// fallback to iterating over the cies/fdes and ignore the eh_frame_hdr.
+// No .gnu_debugdata section in the elf file, so no symbols.
+TEST(UnwindOfflineTest, bad_eh_frame_hdr_arm64) {
+ std::string dir(TestGetFileDirectory() + "offline/bad_eh_frame_hdr_arm64/");
+
+ MemoryOffline* memory = new MemoryOffline;
+ ASSERT_TRUE(memory->Init((dir + "stack.data").c_str(), 0));
+
+ FILE* fp = fopen((dir + "regs.txt").c_str(), "r");
+ ASSERT_TRUE(fp != nullptr);
+ RegsArm64 regs;
+ uint64_t reg_value;
+ ASSERT_EQ(1, fscanf(fp, "pc: %" SCNx64 "\n", ®_value));
+ regs[ARM64_REG_PC] = reg_value;
+ ASSERT_EQ(1, fscanf(fp, "sp: %" SCNx64 "\n", ®_value));
+ regs[ARM64_REG_SP] = reg_value;
+ ASSERT_EQ(1, fscanf(fp, "lr: %" SCNx64 "\n", ®_value));
+ regs[ARM64_REG_LR] = reg_value;
+ ASSERT_EQ(1, fscanf(fp, "x29: %" SCNx64 "\n", ®_value));
+ regs[ARM64_REG_R29] = reg_value;
+ regs.SetFromRaw();
+ fclose(fp);
+
+ fp = fopen((dir + "maps.txt").c_str(), "r");
+ ASSERT_TRUE(fp != nullptr);
+ // The file is guaranteed to be less than 4096 bytes.
+ std::vector<char> buffer(4096);
+ ASSERT_NE(0U, fread(buffer.data(), 1, buffer.size(), fp));
+ fclose(fp);
+
+ BufferMaps maps(buffer.data());
+ ASSERT_TRUE(maps.Parse());
+
+ ASSERT_EQ(ARCH_ARM64, regs.Arch());
+
+ std::shared_ptr<Memory> process_memory(memory);
+
+ char* cwd = getcwd(nullptr, 0);
+ ASSERT_EQ(0, chdir(dir.c_str()));
+ Unwinder unwinder(128, &maps, ®s, process_memory);
+ unwinder.Unwind();
+ ASSERT_EQ(0, chdir(cwd));
+ free(cwd);
+
+ std::string frame_info(DumpFrames(unwinder));
+ ASSERT_EQ(5U, unwinder.NumFrames()) << "Unwind:\n" << frame_info;
+ EXPECT_EQ(
+ " #00 pc 0000000000000550 waiter64\n"
+ " #01 pc 0000000000000568 waiter64\n"
+ " #02 pc 000000000000057c waiter64\n"
+ " #03 pc 0000000000000590 waiter64\n"
+ " #04 pc 00000000000a8e98 libc.so (__libc_init+88)\n",
+ frame_info);
+}
+
+// The elf has bad eh_frame unwind information for the pcs. If eh_frame
+// is used first, the unwind will not match the expected output.
+TEST(UnwindOfflineTest, debug_frame_first_x86) {
+ std::string dir(TestGetFileDirectory() + "offline/debug_frame_first_x86/");
+
+ MemoryOffline* memory = new MemoryOffline;
+ ASSERT_TRUE(memory->Init((dir + "stack.data").c_str(), 0));
+
+ FILE* fp = fopen((dir + "regs.txt").c_str(), "r");
+ ASSERT_TRUE(fp != nullptr);
+ RegsX86 regs;
+ uint64_t reg_value;
+ ASSERT_EQ(1, fscanf(fp, "eax: %" SCNx64 "\n", ®_value));
+ regs[X86_REG_EAX] = reg_value;
+ ASSERT_EQ(1, fscanf(fp, "ebx: %" SCNx64 "\n", ®_value));
+ regs[X86_REG_EBX] = reg_value;
+ ASSERT_EQ(1, fscanf(fp, "ecx: %" SCNx64 "\n", ®_value));
+ regs[X86_REG_ECX] = reg_value;
+ ASSERT_EQ(1, fscanf(fp, "edx: %" SCNx64 "\n", ®_value));
+ regs[X86_REG_EDX] = reg_value;
+ ASSERT_EQ(1, fscanf(fp, "ebp: %" SCNx64 "\n", ®_value));
+ regs[X86_REG_EBP] = reg_value;
+ ASSERT_EQ(1, fscanf(fp, "edi: %" SCNx64 "\n", ®_value));
+ regs[X86_REG_EDI] = reg_value;
+ ASSERT_EQ(1, fscanf(fp, "esi: %" SCNx64 "\n", ®_value));
+ regs[X86_REG_ESI] = reg_value;
+ ASSERT_EQ(1, fscanf(fp, "esp: %" SCNx64 "\n", ®_value));
+ regs[X86_REG_ESP] = reg_value;
+ ASSERT_EQ(1, fscanf(fp, "eip: %" SCNx64 "\n", ®_value));
+ regs[X86_REG_EIP] = reg_value;
+ regs.SetFromRaw();
+ fclose(fp);
+
+ fp = fopen((dir + "maps.txt").c_str(), "r");
+ ASSERT_TRUE(fp != nullptr);
+ // The file is guaranteed to be less than 4096 bytes.
+ std::vector<char> buffer(4096);
+ ASSERT_NE(0U, fread(buffer.data(), 1, buffer.size(), fp));
+ fclose(fp);
+
+ BufferMaps maps(buffer.data());
+ ASSERT_TRUE(maps.Parse());
+
+ ASSERT_EQ(ARCH_X86, regs.Arch());
+
+ std::shared_ptr<Memory> process_memory(memory);
+
+ char* cwd = getcwd(nullptr, 0);
+ ASSERT_EQ(0, chdir(dir.c_str()));
+ JitDebug jit_debug(process_memory);
+ Unwinder unwinder(128, &maps, ®s, process_memory);
+ unwinder.SetJitDebug(&jit_debug, regs.Arch());
+ unwinder.Unwind();
+ ASSERT_EQ(0, chdir(cwd));
+ free(cwd);
+
+ std::string frame_info(DumpFrames(unwinder));
+ ASSERT_EQ(5U, unwinder.NumFrames()) << "Unwind:\n" << frame_info;
+ EXPECT_EQ(
+ " #00 pc 00000685 waiter (call_level3+53)\n"
+ " #01 pc 000006b7 waiter (call_level2+23)\n"
+ " #02 pc 000006d7 waiter (call_level1+23)\n"
+ " #03 pc 000006f7 waiter (main+23)\n"
+ " #04 pc 00018275 libc.so\n",
+ frame_info);
+}
+
} // namespace unwindstack
diff --git a/libunwindstack/tests/UnwinderTest.cpp b/libunwindstack/tests/UnwinderTest.cpp
index cd46807..45cf907 100644
--- a/libunwindstack/tests/UnwinderTest.cpp
+++ b/libunwindstack/tests/UnwinderTest.cpp
@@ -60,7 +60,7 @@
maps_.FakeClear();
MapInfo* info = new MapInfo(0x1000, 0x8000, 0, PROT_READ | PROT_WRITE, "/system/fake/libc.so");
ElfFake* elf = new ElfFake(new MemoryFake);
- info->elf = elf;
+ info->elf.reset(elf);
elf->FakeSetInterface(new ElfInterfaceFake(nullptr));
maps_.FakeAddMapInfo(info);
@@ -73,25 +73,25 @@
info = new MapInfo(0x20000, 0x22000, 0, PROT_READ | PROT_WRITE, "/system/fake/libunwind.so");
elf = new ElfFake(new MemoryFake);
- info->elf = elf;
+ info->elf.reset(elf);
elf->FakeSetInterface(new ElfInterfaceFake(nullptr));
maps_.FakeAddMapInfo(info);
info = new MapInfo(0x23000, 0x24000, 0, PROT_READ | PROT_WRITE, "/fake/libanother.so");
elf = new ElfFake(new MemoryFake);
- info->elf = elf;
+ info->elf.reset(elf);
elf->FakeSetInterface(new ElfInterfaceFake(nullptr));
maps_.FakeAddMapInfo(info);
info = new MapInfo(0x33000, 0x34000, 0, PROT_READ | PROT_WRITE, "/fake/compressed.so");
elf = new ElfFake(new MemoryFake);
- info->elf = elf;
+ info->elf.reset(elf);
elf->FakeSetInterface(new ElfInterfaceFake(nullptr));
maps_.FakeAddMapInfo(info);
info = new MapInfo(0x43000, 0x44000, 0x1d000, PROT_READ | PROT_WRITE, "/fake/fake.apk");
elf = new ElfFake(new MemoryFake);
- info->elf = elf;
+ info->elf.reset(elf);
elf->FakeSetInterface(new ElfInterfaceFake(nullptr));
maps_.FakeAddMapInfo(info);
@@ -129,6 +129,7 @@
Unwinder unwinder(64, &maps_, ®s_, process_memory_);
unwinder.Unwind();
+ EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode());
ASSERT_EQ(3U, unwinder.NumFrames());
@@ -184,6 +185,7 @@
Unwinder unwinder(64, &maps_, ®s_, process_memory_);
unwinder.Unwind();
+ EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode());
ASSERT_EQ(1U, unwinder.NumFrames());
@@ -218,6 +220,7 @@
Unwinder unwinder(64, &maps_, ®s_, process_memory_);
unwinder.Unwind();
+ EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode());
ASSERT_EQ(1U, unwinder.NumFrames());
@@ -248,6 +251,7 @@
Unwinder unwinder(20, &maps_, ®s_, process_memory_);
unwinder.Unwind();
+ EXPECT_EQ(ERROR_MAX_FRAMES_EXCEEDED, unwinder.LastErrorCode());
ASSERT_EQ(20U, unwinder.NumFrames());
@@ -288,6 +292,7 @@
Unwinder unwinder(64, &maps_, ®s_, process_memory_);
std::vector<std::string> skip_libs{"libunwind.so", "libanother.so"};
unwinder.Unwind(&skip_libs);
+ EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode());
ASSERT_EQ(3U, unwinder.NumFrames());
@@ -346,6 +351,7 @@
Unwinder unwinder(64, &maps_, ®s_, process_memory_);
unwinder.Unwind();
+ EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode());
ASSERT_EQ(2U, unwinder.NumFrames());
@@ -392,6 +398,7 @@
Unwinder unwinder(64, &maps_, ®s_, process_memory_);
unwinder.Unwind();
+ EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode());
ASSERT_EQ(1U, unwinder.NumFrames());
}
@@ -410,6 +417,7 @@
Unwinder unwinder(64, &maps_, ®s_, process_memory_);
unwinder.Unwind();
+ EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode());
ASSERT_EQ(1U, unwinder.NumFrames());
}
@@ -423,6 +431,7 @@
Unwinder unwinder(64, &maps_, ®s_, process_memory_);
unwinder.Unwind();
+ EXPECT_EQ(ERROR_INVALID_MAP, unwinder.LastErrorCode());
ASSERT_EQ(1U, unwinder.NumFrames());
@@ -457,6 +466,7 @@
Unwinder unwinder(64, &maps_, ®s_, process_memory_);
unwinder.Unwind();
+ EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode());
ASSERT_EQ(3U, unwinder.NumFrames());
@@ -517,6 +527,7 @@
Unwinder unwinder(64, &maps_, ®s_, process_memory_);
unwinder.Unwind();
+ EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode());
ASSERT_EQ(1U, unwinder.NumFrames());
@@ -552,6 +563,7 @@
Unwinder unwinder(64, &maps_, ®s_, process_memory_);
std::vector<std::string> suffixes{"oat"};
unwinder.Unwind(nullptr, &suffixes);
+ EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode());
ASSERT_EQ(2U, unwinder.NumFrames());
// Make sure the elf was not initialized.
@@ -607,6 +619,7 @@
Unwinder unwinder(64, &maps_, ®s_, process_memory_);
unwinder.Unwind();
+ EXPECT_EQ(ERROR_REPEATED_FRAME, unwinder.LastErrorCode());
ASSERT_EQ(3U, unwinder.NumFrames());
diff --git a/libunwindstack/tests/files/offline/bad_eh_frame_hdr_arm64/libc.so b/libunwindstack/tests/files/offline/bad_eh_frame_hdr_arm64/libc.so
new file mode 100644
index 0000000..78449bf
--- /dev/null
+++ b/libunwindstack/tests/files/offline/bad_eh_frame_hdr_arm64/libc.so
Binary files differ
diff --git a/libunwindstack/tests/files/offline/bad_eh_frame_hdr_arm64/maps.txt b/libunwindstack/tests/files/offline/bad_eh_frame_hdr_arm64/maps.txt
new file mode 100644
index 0000000..7cada15
--- /dev/null
+++ b/libunwindstack/tests/files/offline/bad_eh_frame_hdr_arm64/maps.txt
@@ -0,0 +1,2 @@
+60a9fdf000-60a9fe0000 r-xp 0 00:00 0 waiter64
+7542cc0000-7542d8e000 r-xp 0 00:00 0 libc.so
diff --git a/libunwindstack/tests/files/offline/bad_eh_frame_hdr_arm64/regs.txt b/libunwindstack/tests/files/offline/bad_eh_frame_hdr_arm64/regs.txt
new file mode 100644
index 0000000..c24adbe
--- /dev/null
+++ b/libunwindstack/tests/files/offline/bad_eh_frame_hdr_arm64/regs.txt
@@ -0,0 +1,4 @@
+pc: 60a9fdf550
+sp: 7fdd141990
+lr: 60a9fdf56c
+x29: 7fdd1419a0
diff --git a/libunwindstack/tests/files/offline/bad_eh_frame_hdr_arm64/stack.data b/libunwindstack/tests/files/offline/bad_eh_frame_hdr_arm64/stack.data
new file mode 100644
index 0000000..b56d420
--- /dev/null
+++ b/libunwindstack/tests/files/offline/bad_eh_frame_hdr_arm64/stack.data
Binary files differ
diff --git a/libunwindstack/tests/files/offline/bad_eh_frame_hdr_arm64/waiter64 b/libunwindstack/tests/files/offline/bad_eh_frame_hdr_arm64/waiter64
new file mode 100644
index 0000000..81bda1d
--- /dev/null
+++ b/libunwindstack/tests/files/offline/bad_eh_frame_hdr_arm64/waiter64
Binary files differ
diff --git a/libunwindstack/tests/files/offline/debug_frame_first_x86/libc.so b/libunwindstack/tests/files/offline/debug_frame_first_x86/libc.so
new file mode 100644
index 0000000..9c78790
--- /dev/null
+++ b/libunwindstack/tests/files/offline/debug_frame_first_x86/libc.so
Binary files differ
diff --git a/libunwindstack/tests/files/offline/debug_frame_first_x86/maps.txt b/libunwindstack/tests/files/offline/debug_frame_first_x86/maps.txt
new file mode 100644
index 0000000..74fc89f
--- /dev/null
+++ b/libunwindstack/tests/files/offline/debug_frame_first_x86/maps.txt
@@ -0,0 +1,2 @@
+56598000-56599000 r-xp 0 00:00 0 waiter
+f7432000-f75e3000 r-xp 0 00:00 0 libc.so
diff --git a/libunwindstack/tests/files/offline/debug_frame_first_x86/regs.txt b/libunwindstack/tests/files/offline/debug_frame_first_x86/regs.txt
new file mode 100644
index 0000000..48f4440
--- /dev/null
+++ b/libunwindstack/tests/files/offline/debug_frame_first_x86/regs.txt
@@ -0,0 +1,9 @@
+eax: 1d88ef8c
+ebx: 56599fe8
+ecx: 3
+edx: ffcf9ea4
+ebp: ffcf9e48
+edi: f75e5000
+esi: 1
+esp: ffcf9e38
+eip: 56598685
diff --git a/libunwindstack/tests/files/offline/debug_frame_first_x86/stack.data b/libunwindstack/tests/files/offline/debug_frame_first_x86/stack.data
new file mode 100644
index 0000000..0cf7d55
--- /dev/null
+++ b/libunwindstack/tests/files/offline/debug_frame_first_x86/stack.data
Binary files differ
diff --git a/libunwindstack/tests/files/offline/debug_frame_first_x86/waiter b/libunwindstack/tests/files/offline/debug_frame_first_x86/waiter
new file mode 100644
index 0000000..b1fc024
--- /dev/null
+++ b/libunwindstack/tests/files/offline/debug_frame_first_x86/waiter
Binary files differ
diff --git a/libutils/Android.bp b/libutils/Android.bp
index 3bca6c8..2be5d98 100644
--- a/libutils/Android.bp
+++ b/libutils/Android.bp
@@ -157,6 +157,7 @@
cc_library {
name: "libutilscallstack",
defaults: ["libutils_defaults"],
+ vendor_available: false,
srcs: [
"CallStack.cpp",
diff --git a/lmkd/lmkd.c b/lmkd/lmkd.c
index fd83ecc..b486a17 100644
--- a/lmkd/lmkd.c
+++ b/lmkd/lmkd.c
@@ -900,7 +900,16 @@
downgrade_pressure = (int64_t)property_get_int32("ro.lmk.downgrade_pressure", 60);
is_go_device = property_get_bool("ro.config.low_ram", false);
- if (mlockall(MCL_CURRENT | MCL_FUTURE))
+ // MCL_ONFAULT pins pages as they fault instead of loading
+ // everything immediately all at once. (Which would be bad,
+ // because as of this writing, we have a lot of mapped pages we
+ // never use.) Old kernels will see MCL_ONFAULT and fail with
+ // EINVAL; we ignore this failure.
+ //
+ // N.B. read the man page for mlockall. MCL_CURRENT | MCL_ONFAULT
+ // pins ⊆ MCL_CURRENT, converging to just MCL_CURRENT as we fault
+ // in pages.
+ if (mlockall(MCL_CURRENT | MCL_FUTURE | MCL_ONFAULT) && errno != EINVAL)
ALOGW("mlockall failed: errno=%d", errno);
sched_setscheduler(0, SCHED_FIFO, ¶m);
diff --git a/rootdir/Android.mk b/rootdir/Android.mk
index ca992d6..d8163ab 100644
--- a/rootdir/Android.mk
+++ b/rootdir/Android.mk
@@ -88,6 +88,11 @@
else
LOCAL_POST_INSTALL_CMD += ; ln -sf /system/vendor $(TARGET_ROOT_OUT)/vendor
endif
+ifdef BOARD_USES_PRODUCTIMAGE
+ LOCAL_POST_INSTALL_CMD += ; mkdir -p $(TARGET_ROOT_OUT)/product
+else
+ LOCAL_POST_INSTALL_CMD += ; ln -sf /system/product $(TARGET_ROOT_OUT)/product
+endif
ifdef BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE
LOCAL_POST_INSTALL_CMD += ; mkdir -p $(TARGET_ROOT_OUT)/cache
else
diff --git a/rootdir/etc/ld.config.txt.in b/rootdir/etc/ld.config.txt.in
index 2a801fa..c8d87c8 100644
--- a/rootdir/etc/ld.config.txt.in
+++ b/rootdir/etc/ld.config.txt.in
@@ -55,6 +55,9 @@
namespace.default.permitted.paths += /vendor/app
namespace.default.permitted.paths += /vendor/priv-app
namespace.default.permitted.paths += /oem/app
+namespace.default.permitted.paths += /product/framework
+namespace.default.permitted.paths += /product/app
+namespace.default.permitted.paths += /product/priv-app
namespace.default.permitted.paths += /data
namespace.default.permitted.paths += /mnt/expand
@@ -72,6 +75,9 @@
namespace.default.asan.permitted.paths += /vendor/app
namespace.default.asan.permitted.paths += /vendor/priv-app
namespace.default.asan.permitted.paths += /oem/app
+namespace.default.asan.permitted.paths += /product/framework
+namespace.default.asan.permitted.paths += /product/app
+namespace.default.asan.permitted.paths += /product/priv-app
namespace.default.asan.permitted.paths += /mnt/expand
###############################################################################
@@ -285,10 +291,12 @@
# When these NDK libs are required inside this namespace, then it is redirected
# to the system namespace. This is possible since their ABI is stable across
# Android releases.
-namespace.vndk.links = system
+namespace.vndk.links = system,default
namespace.vndk.link.system.shared_libs = %LLNDK_LIBRARIES%
namespace.vndk.link.system.shared_libs += %SANITIZER_RUNTIME_LIBRARIES%
+namespace.vndk.link.default.allow_all_shared_libs = true
+
###############################################################################
# "system" namespace
#
diff --git a/usbd/usbd.rc b/usbd/usbd.rc
index c7838e8..809044a 100644
--- a/usbd/usbd.rc
+++ b/usbd/usbd.rc
@@ -2,4 +2,4 @@
class late_start
oneshot
user root
- group root usb
+ group root usb system