From 456df6929f6957e03428327060f4ab25b873c655 Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Wed, 20 Nov 2019 14:46:10 -0800 Subject: [PATCH] Move the dexfile support to implementation. No longer require that NO_LIBDEXFILE_SUPPORT be defined or not defined when including the header files. Move all of the different behavior to the implementation, and keep all of the classes the exact same whether dexfiles are supported or not. Bug: 144470551 Test: Ran libunwindstack unit tests, libbacktrace unit tests, and Test: debuggerd unit tests. Test: Ran host art 137-cfi tests. Change-Id: I4a04cfbc5d4f1bf765ef154881046c85057006c8 --- libunwindstack/Android.bp | 7 +++---- libunwindstack/DexFiles.cpp | 21 +++++++++++++++++++ libunwindstack/Unwinder.cpp | 8 ++----- libunwindstack/include/unwindstack/Unwinder.h | 6 ------ 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/libunwindstack/Android.bp b/libunwindstack/Android.bp index 2573b1cbc..512c96227 100644 --- a/libunwindstack/Android.bp +++ b/libunwindstack/Android.bp @@ -77,6 +77,7 @@ cc_library { ], cflags: [ + "-DDEXFILE_SUPPORT", "-Wexit-time-destructors", ], @@ -89,20 +90,18 @@ cc_library { ], }, vendor: { - cflags: ["-DNO_LIBDEXFILE_SUPPORT"], + cflags: ["-UDEXFILE_SUPPORT"], exclude_srcs: [ "DexFile.cpp", - "DexFiles.cpp", ], exclude_shared_libs: [ "libdexfile_support", ], }, recovery: { - cflags: ["-DNO_LIBDEXFILE_SUPPORT"], + cflags: ["-UDEXFILE_SUPPORT"], exclude_srcs: [ "DexFile.cpp", - "DexFiles.cpp", ], exclude_shared_libs: [ "libdexfile_support", diff --git a/libunwindstack/DexFiles.cpp b/libunwindstack/DexFiles.cpp index 63a77e50f..2057fad19 100644 --- a/libunwindstack/DexFiles.cpp +++ b/libunwindstack/DexFiles.cpp @@ -27,10 +27,21 @@ #include #include +#if defined(DEXFILE_SUPPORT) #include "DexFile.h" +#endif namespace unwindstack { +#if !defined(DEXFILE_SUPPORT) +// Empty class definition. +class DexFile { + public: + DexFile() = default; + virtual ~DexFile() = default; +}; +#endif + struct DEXFileEntry32 { uint32_t next; uint32_t prev; @@ -128,6 +139,7 @@ void DexFiles::Init(Maps* maps) { FindAndReadVariable(maps, "__dex_debug_descriptor"); } +#if defined(DEXFILE_SUPPORT) DexFile* DexFiles::GetDexFile(uint64_t dex_file_offset, MapInfo* info) { // Lock while processing the data. DexFile* dex_file; @@ -141,6 +153,11 @@ DexFile* DexFiles::GetDexFile(uint64_t dex_file_offset, MapInfo* info) { } return dex_file; } +#else +DexFile* DexFiles::GetDexFile(uint64_t, MapInfo*) { + return nullptr; +} +#endif bool DexFiles::GetAddr(size_t index, uint64_t* addr) { if (index < addrs_.size()) { @@ -154,6 +171,7 @@ bool DexFiles::GetAddr(size_t index, uint64_t* addr) { return false; } +#if defined(DEXFILE_SUPPORT) void DexFiles::GetMethodInformation(Maps* maps, MapInfo* info, uint64_t dex_pc, std::string* method_name, uint64_t* method_offset) { std::lock_guard guard(lock_); @@ -175,5 +193,8 @@ void DexFiles::GetMethodInformation(Maps* maps, MapInfo* info, uint64_t dex_pc, } } } +#else +void DexFiles::GetMethodInformation(Maps*, MapInfo*, uint64_t, std::string*, uint64_t*) {} +#endif } // namespace unwindstack diff --git a/libunwindstack/Unwinder.cpp b/libunwindstack/Unwinder.cpp index 0b9b85c65..1bb031947 100644 --- a/libunwindstack/Unwinder.cpp +++ b/libunwindstack/Unwinder.cpp @@ -34,9 +34,7 @@ #include #include -#if !defined(NO_LIBDEXFILE_SUPPORT) #include -#endif // Use the demangler from libc++. extern "C" char* __cxa_demangle(const char*, char*, size_t*, int* status); @@ -84,7 +82,7 @@ void Unwinder::FillInDexFrame() { return; } -#if !defined(NO_LIBDEXFILE_SUPPORT) +#if defined(DEXFILE_SUPPORT) if (dex_files_ == nullptr) { return; } @@ -367,12 +365,10 @@ void Unwinder::SetJitDebug(JitDebug* jit_debug, ArchEnum arch) { jit_debug_ = jit_debug; } -#if !defined(NO_LIBDEXFILE_SUPPORT) void Unwinder::SetDexFiles(DexFiles* dex_files, ArchEnum arch) { dex_files->SetArch(arch); dex_files_ = dex_files; } -#endif bool UnwinderFromPid::Init(ArchEnum arch) { if (pid_ == getpid()) { @@ -390,7 +386,7 @@ bool UnwinderFromPid::Init(ArchEnum arch) { jit_debug_ptr_.reset(new JitDebug(process_memory_)); jit_debug_ = jit_debug_ptr_.get(); SetJitDebug(jit_debug_, arch); -#if !defined(NO_LIBDEXFILE_SUPPORT) +#if defined(DEXFILE_SUPPORT) dex_files_ptr_.reset(new DexFiles(process_memory_)); dex_files_ = dex_files_ptr_.get(); SetDexFiles(dex_files_, arch); diff --git a/libunwindstack/include/unwindstack/Unwinder.h b/libunwindstack/include/unwindstack/Unwinder.h index 11ad9de6f..67762c0bd 100644 --- a/libunwindstack/include/unwindstack/Unwinder.h +++ b/libunwindstack/include/unwindstack/Unwinder.h @@ -107,9 +107,7 @@ class Unwinder { void SetDisplayBuildID(bool display_build_id) { display_build_id_ = display_build_id; } -#if !defined(NO_LIBDEXFILE_SUPPORT) void SetDexFiles(DexFiles* dex_files, ArchEnum arch); -#endif bool elf_from_memory_not_file() { return elf_from_memory_not_file_; } @@ -128,9 +126,7 @@ class Unwinder { std::vector frames_; std::shared_ptr process_memory_; JitDebug* jit_debug_ = nullptr; -#if !defined(NO_LIBDEXFILE_SUPPORT) DexFiles* dex_files_ = nullptr; -#endif bool resolve_names_ = true; bool embedded_soname_ = true; bool display_build_id_ = false; @@ -151,9 +147,7 @@ class UnwinderFromPid : public Unwinder { pid_t pid_; std::unique_ptr maps_ptr_; std::unique_ptr jit_debug_ptr_; -#if !defined(NO_LIBDEXFILE_SUPPORT) std::unique_ptr dex_files_ptr_; -#endif }; } // namespace unwindstack