From b12a136cddb5fea6e1a502bbc9fd815b7818a30c Mon Sep 17 00:00:00 2001 From: Jason Molenda Date: Sat, 20 Dec 2014 03:12:51 +0000 Subject: [PATCH] Re-enable compact unwind use on Mac platforms. When lldb has a binary with protected section contents, don't use the on-disk representation of that compact uwnind -- read it only out of live memory where it has been decrypted. llvm-svn: 224670 --- lldb/include/lldb/Symbol/CompactUnwindInfo.h | 7 +-- lldb/source/Symbol/CompactUnwindInfo.cpp | 49 ++++++++++++++------ 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/lldb/include/lldb/Symbol/CompactUnwindInfo.h b/lldb/include/lldb/Symbol/CompactUnwindInfo.h index eb0e020d1b44..911c2b45bbb1 100644 --- a/lldb/include/lldb/Symbol/CompactUnwindInfo.h +++ b/lldb/include/lldb/Symbol/CompactUnwindInfo.h @@ -42,7 +42,7 @@ public: GetUnwindPlan (Target &target, Address addr, UnwindPlan& unwind_plan); bool - IsValid (); + IsValid (const lldb::ProcessSP &process_sp); private: @@ -104,7 +104,7 @@ private: }; void - ScanIndex(); + ScanIndex(const lldb::ProcessSP &process_sp); bool GetCompactUnwindInfoForFunction (Target &target, Address address, FunctionInfo &unwind_info); @@ -126,7 +126,8 @@ private: ObjectFile &m_objfile; lldb::SectionSP m_section_sp; - + lldb::DataBufferSP m_section_contents_if_encrypted; // if the binary is encrypted, read the sect contents + // out of live memory and cache them here Mutex m_mutex; std::vector m_indexes; diff --git a/lldb/source/Symbol/CompactUnwindInfo.cpp b/lldb/source/Symbol/CompactUnwindInfo.cpp index 4635443a916d..09c0ac7083e5 100644 --- a/lldb/source/Symbol/CompactUnwindInfo.cpp +++ b/lldb/source/Symbol/CompactUnwindInfo.cpp @@ -12,14 +12,16 @@ // C++ Includes #include -#include "lldb/Core/Log.h" -#include "lldb/Core/Section.h" #include "lldb/Core/ArchSpec.h" +#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/Section.h" +#include "lldb/Core/Section.h" #include "lldb/Symbol/CompactUnwindInfo.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Symbol/UnwindPlan.h" +#include "lldb/Target/Process.h" +#include "lldb/Target/Target.h" #include "llvm/Support/MathExtras.h" @@ -124,6 +126,7 @@ namespace lldb_private { CompactUnwindInfo::CompactUnwindInfo(ObjectFile& objfile, SectionSP& section_sp) : m_objfile (objfile), m_section_sp (section_sp), + m_section_contents_if_encrypted (), m_mutex (), m_indexes (), m_indexes_computed (eLazyBoolCalculate), @@ -145,7 +148,7 @@ CompactUnwindInfo::~CompactUnwindInfo() bool CompactUnwindInfo::GetUnwindPlan (Target &target, Address addr, UnwindPlan& unwind_plan) { - if (!IsValid ()) + if (!IsValid (target.GetProcessSP())) { return false; } @@ -173,21 +176,21 @@ CompactUnwindInfo::GetUnwindPlan (Target &target, Address addr, UnwindPlan& unwi } bool -CompactUnwindInfo::IsValid () +CompactUnwindInfo::IsValid (const ProcessSP &process_sp) { - if (m_section_sp.get() == nullptr || m_section_sp->IsEncrypted()) + if (m_section_sp.get() == nullptr) return false; if (m_indexes_computed == eLazyBoolYes && m_unwindinfo_data_computed) return true; - ScanIndex (); + ScanIndex (process_sp); return m_indexes_computed == eLazyBoolYes && m_unwindinfo_data_computed; } void -CompactUnwindInfo::ScanIndex () +CompactUnwindInfo::ScanIndex (const ProcessSP &process_sp) { Mutex::Locker locker(m_mutex); if (m_indexes_computed == eLazyBoolYes && m_unwindinfo_data_computed) @@ -201,7 +204,30 @@ CompactUnwindInfo::ScanIndex () if (m_unwindinfo_data_computed == false) { - m_objfile.ReadSectionData (m_section_sp.get(), m_unwindinfo_data); + if (m_section_sp->IsEncrypted()) + { + // Can't get section contents of a protected/encrypted section until we have a live + // process and can read them out of memory. + if (process_sp.get() == nullptr) + return; + m_section_contents_if_encrypted.reset (new DataBufferHeap (m_section_sp->GetByteSize(), 0)); + Error error; + if (process_sp->ReadMemory ( + m_section_sp->GetLoadBaseAddress (&process_sp->GetTarget()), + m_section_contents_if_encrypted->GetBytes(), + m_section_sp->GetByteSize(), error) == m_section_sp->GetByteSize() && error.Success()) + { + m_unwindinfo_data.SetAddressByteSize (process_sp->GetTarget().GetArchitecture().GetAddressByteSize()); + m_unwindinfo_data.SetByteOrder (process_sp->GetTarget().GetArchitecture().GetByteOrder()); + m_unwindinfo_data.SetData (m_section_contents_if_encrypted, 0); + } + } + else + { + m_objfile.ReadSectionData (m_section_sp.get(), m_unwindinfo_data); + } + if (m_unwindinfo_data.GetByteSize() != m_section_sp->GetByteSize()) + return; m_unwindinfo_data_computed = true; } @@ -409,14 +435,9 @@ CompactUnwindInfo::GetCompactUnwindInfoForFunction (Target &target, Address addr unwind_info.lsda_address.Clear(); unwind_info.personality_ptr_address.Clear(); - if (!IsValid ()) + if (!IsValid (target.GetProcessSP())) return false; - // FIXME looking into a problem with getting the wrong compact unwind entry for - // _CFRunLoopRun from CoreFoundation in a live process; disabling the Compact - // Unwind plans until I get to the bottom of what's going on there. - return false; - addr_t text_section_file_address = LLDB_INVALID_ADDRESS; SectionList *sl = m_objfile.GetSectionList (); if (sl)