diff options
24 files changed, 399 insertions, 186 deletions
diff --git a/lldb/include/lldb/API/SBAddress.h b/lldb/include/lldb/API/SBAddress.h index ffafdf179bb..b5386cafa6d 100644 --- a/lldb/include/lldb/API/SBAddress.h +++ b/lldb/include/lldb/API/SBAddress.h @@ -51,6 +51,7 @@ protected: friend class SBFrame; friend class SBLineEntry; + friend class SBInstruction; friend class SBModule; friend class SBSymbolContext; friend class SBThread; diff --git a/lldb/include/lldb/API/SBFunction.h b/lldb/include/lldb/API/SBFunction.h index 643d5273471..eb42ded518a 100644 --- a/lldb/include/lldb/API/SBFunction.h +++ b/lldb/include/lldb/API/SBFunction.h @@ -11,6 +11,7 @@ #define LLDB_SBFunction_h_ #include "lldb/API/SBDefines.h" +#include "lldb/API/SBInstructionList.h" namespace lldb { @@ -31,6 +32,9 @@ public: const char * GetMangledName () const; + lldb::SBInstructionList + GetInstructions (lldb::SBTarget target); + #ifndef SWIG bool operator == (const lldb::SBFunction &rhs) const; diff --git a/lldb/include/lldb/API/SBInstruction.h b/lldb/include/lldb/API/SBInstruction.h index d64a4d3da0d..7ebdcfc4756 100644 --- a/lldb/include/lldb/API/SBInstruction.h +++ b/lldb/include/lldb/API/SBInstruction.h @@ -17,43 +17,45 @@ // There's a lot to be fixed here, but need to wait for underlying insn implementation // to be revised & settle down first. -//class lldb_private::Disassembler::Instruction; - namespace lldb { class SBInstruction { public: - //SBInstruction (lldb_private::Disassembler::Instruction *lldb_insn); - SBInstruction (); ~SBInstruction (); - //bool - //IsValid(); + bool + IsValid(); - //size_t - //GetByteSize (); + SBAddress + GetAddress(); - //void - //SetByteSize (size_t byte_size); + size_t + GetByteSize (); - //bool - //DoesBranch (); + bool + DoesBranch (); void Print (FILE *out); - //bool - //GetDescription (lldb::SBStream &description); + bool + GetDescription (lldb::SBStream &description); -private: +protected: + friend class SBInstructionList; - //lldb_private::Disassembler::Instruction::SharedPtr m_opaque_sp; + SBInstruction (const lldb::InstructionSP &inst_sp); + void + SetOpaque (const lldb::InstructionSP &inst_sp); + +private: + lldb::InstructionSP m_opaque_sp; }; diff --git a/lldb/include/lldb/API/SBInstructionList.h b/lldb/include/lldb/API/SBInstructionList.h index ba91420bff5..f8c0abba6df 100644 --- a/lldb/include/lldb/API/SBInstructionList.h +++ b/lldb/include/lldb/API/SBInstructionList.h @@ -36,17 +36,21 @@ public: void AppendInstruction (lldb::SBInstruction inst); - void Print (FILE *out); -private: + bool + GetDescription (lldb::SBStream &description); - // If we have an instruction list, it will need to be backed by an - // lldb_private class that contains the list, we can't inherit from - // std::vector here... - //std::vector <SBInstruction> m_insn_list; +protected: + friend class SBFunction; + friend class SBSymbol; + + void + SetDisassembler (const lldb::DisassemblerSP &opaque_sp); +private: + lldb::DisassemblerSP m_opaque_sp; }; diff --git a/lldb/include/lldb/API/SBProcess.h b/lldb/include/lldb/API/SBProcess.h index 0e462ce3e92..440622b3526 100644 --- a/lldb/include/lldb/API/SBProcess.h +++ b/lldb/include/lldb/API/SBProcess.h @@ -161,6 +161,7 @@ protected: friend class SBBreakpointLocation; friend class SBCommandInterpreter; friend class SBDebugger; + friend class SBFunction; friend class SBTarget; friend class SBThread; friend class SBValue; diff --git a/lldb/include/lldb/API/SBStream.h b/lldb/include/lldb/API/SBStream.h index 6c46c1a0482..206fbbb658d 100644 --- a/lldb/include/lldb/API/SBStream.h +++ b/lldb/include/lldb/API/SBStream.h @@ -63,6 +63,8 @@ protected: friend class SBEvent; friend class SBFrame; friend class SBFunction; + friend class SBInstruction; + friend class SBInstructionList; friend class SBModule; friend class SBSymbol; friend class SBSymbolContext; diff --git a/lldb/include/lldb/API/SBSymbol.h b/lldb/include/lldb/API/SBSymbol.h index 08dcad1d325..f4d1b93d69d 100644 --- a/lldb/include/lldb/API/SBSymbol.h +++ b/lldb/include/lldb/API/SBSymbol.h @@ -11,6 +11,8 @@ #define LLDB_SBSymbol_h_ #include "lldb/API/SBDefines.h" +#include "lldb/API/SBInstructionList.h" +#include "lldb/API/SBTarget.h" namespace lldb { @@ -32,6 +34,9 @@ public: const char * GetMangledName () const; + lldb::SBInstructionList + GetInstructions (lldb::SBTarget target); + #ifndef SWIG bool operator == (const lldb::SBSymbol &rhs) const; diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h index 1f9d0ce1b25..0cde443dd11 100644 --- a/lldb/include/lldb/API/SBTarget.h +++ b/lldb/include/lldb/API/SBTarget.h @@ -148,7 +148,9 @@ public: protected: friend class SBAddress; friend class SBDebugger; + friend class SBFunction; friend class SBProcess; + friend class SBSymbol; //------------------------------------------------------------------ // Constructors are private, use static Target::Create function to diff --git a/lldb/include/lldb/Core/Disassembler.h b/lldb/include/lldb/Core/Disassembler.h index 80de7b3af8c..1fb70daf03c 100644 --- a/lldb/include/lldb/Core/Disassembler.h +++ b/lldb/include/lldb/Core/Disassembler.h @@ -17,79 +17,95 @@ // Other libraries and framework includes // Project includes #include "lldb/lldb-private.h" +#include "lldb/Core/Address.h" #include "lldb/Core/ArchSpec.h" #include "lldb/Core/PluginInterface.h" namespace lldb_private { -class ExecutionContext; - -class Disassembler : - public PluginInterface +class Instruction { public: - class Instruction - { - public: - typedef lldb::SharedPtr<Instruction>::Type shared_ptr; + Instruction (const Address &addr); - Instruction(); + virtual + ~Instruction(); - virtual - ~Instruction(); + const Address & + GetAddress () const + { + return m_addr; + } - virtual size_t - GetByteSize() const = 0; + void + SetAddress (const Address &addr) + { + m_addr = addr; + } - virtual void - Dump (Stream *s, - Address *address, - const DataExtractor *bytes, - uint32_t bytes_offset, - const ExecutionContext &exe_ctx, - bool raw) = 0; - - virtual bool - DoesBranch () const = 0; + virtual size_t + GetByteSize() const = 0; - virtual size_t - Extract (const DataExtractor& data, uint32_t data_offset) = 0; - }; + + virtual void + Dump (Stream *s, + bool show_address, + const DataExtractor *bytes, + uint32_t bytes_offset, + const ExecutionContext *exe_ctx, + bool raw) = 0; + + virtual bool + DoesBranch () const = 0; + virtual size_t + Extract (const DataExtractor& data, uint32_t data_offset) = 0; - class InstructionList - { - public: - InstructionList(); - ~InstructionList(); +protected: + Address m_addr; // The section offset address of this instruction +}; - size_t - GetSize() const; - Instruction * - GetInstructionAtIndex (uint32_t idx); +class InstructionList +{ +public: + InstructionList(); + ~InstructionList(); - const Instruction * - GetInstructionAtIndex (uint32_t idx) const; + size_t + GetSize() const; + + lldb::InstructionSP + GetInstructionAtIndex (uint32_t idx) const; void Clear(); void - AppendInstruction (Instruction::shared_ptr &inst_sp); + Append (lldb::InstructionSP &inst_sp); - private: - typedef std::vector<Instruction::shared_ptr> collection; - typedef collection::iterator iterator; - typedef collection::const_iterator const_iterator; +private: + typedef std::vector<lldb::InstructionSP> collection; + typedef collection::iterator iterator; + typedef collection::const_iterator const_iterator; - collection m_instructions; - }; + collection m_instructions; +}; + +class Disassembler : + public PluginInterface +{ +public: static Disassembler* FindPlugin (const ArchSpec &arch); + static lldb::DisassemblerSP + DisassembleRange (const ArchSpec &arch, + const ExecutionContext &exe_ctx, + const AddressRange &disasm_range); + static bool Disassemble (Debugger &debugger, const ArchSpec &arch, @@ -140,7 +156,8 @@ public: DataExtractor& data); virtual size_t - DecodeInstructions (const DataExtractor& data, + DecodeInstructions (const Address &base_addr, + const DataExtractor& data, uint32_t data_offset, uint32_t num_instructions) = 0; diff --git a/lldb/include/lldb/lldb-forward-rtti.h b/lldb/include/lldb/lldb-forward-rtti.h index 469c33972a3..b7e7ee3a6de 100644 --- a/lldb/include/lldb/lldb-forward-rtti.h +++ b/lldb/include/lldb/lldb-forward-rtti.h @@ -34,12 +34,14 @@ namespace lldb { typedef SharedPtr<lldb_private::CompileUnit>::Type CompUnitSP; typedef SharedPtr<lldb_private::DataBuffer>::Type DataBufferSP; typedef SharedPtr<lldb_private::Debugger>::Type DebuggerSP; + typedef SharedPtr<lldb_private::Disassembler>::Type DisassemblerSP; typedef SharedPtr<lldb_private::DynamicLoader>::Type DynamicLoaderSP; typedef SharedPtr<lldb_private::Event>::Type EventSP; typedef SharedPtr<lldb_private::Function>::Type FunctionSP; typedef SharedPtr<lldb_private::InlineFunctionInfo>::Type InlineFunctionInfoSP; typedef SharedPtr<lldb_private::InputReader>::Type InputReaderSP; typedef SharedPtr<lldb_private::InstanceSettings>::Type InstanceSettingsSP; + typedef SharedPtr<lldb_private::Instruction>::Type InstructionSP; typedef SharedPtr<lldb_private::LanguageRuntime>::Type LanguageRuntimeSP; typedef SharedPtr<lldb_private::LineTable>::Type LineTableSP; typedef SharedPtr<lldb_private::Listener>::Type ListenerSP; diff --git a/lldb/include/lldb/lldb-forward.h b/lldb/include/lldb/lldb-forward.h index 61137098ab8..fbed196c1aa 100644 --- a/lldb/include/lldb/lldb-forward.h +++ b/lldb/include/lldb/lldb-forward.h @@ -78,6 +78,7 @@ class FunctionInfo; class InlineFunctionInfo; class InputReader; class InstanceSettings; +class Instruction; class LanguageRuntime; class LineTable; class Listener; diff --git a/lldb/scripts/Python/build-swig-Python.sh b/lldb/scripts/Python/build-swig-Python.sh index dffc466c02f..13df2062796 100755 --- a/lldb/scripts/Python/build-swig-Python.sh +++ b/lldb/scripts/Python/build-swig-Python.sh @@ -44,6 +44,8 @@ HEADER_FILES="${SRC_ROOT}/include/lldb/lldb-types.h"\ " ${SRC_ROOT}/include/lldb/API/SBFileSpec.h"\ " ${SRC_ROOT}/include/lldb/API/SBFrame.h"\ " ${SRC_ROOT}/include/lldb/API/SBFunction.h"\ +" ${SRC_ROOT}/include/lldb/API/SBInstruction.h"\ +" ${SRC_ROOT}/include/lldb/API/SBInstructionList.h"\ " ${SRC_ROOT}/include/lldb/API/SBLineEntry.h"\ " ${SRC_ROOT}/include/lldb/API/SBListener.h"\ " ${SRC_ROOT}/include/lldb/API/SBModule.h"\ diff --git a/lldb/scripts/Python/python-extensions.swig b/lldb/scripts/Python/python-extensions.swig index 7d706fd0d63..e92ecf6428e 100644 --- a/lldb/scripts/Python/python-extensions.swig +++ b/lldb/scripts/Python/python-extensions.swig @@ -76,6 +76,20 @@ return PyString_FromString (description.GetData()); } } +%extend lldb::SBInstruction { + PyObject *lldb::SBInstruction::__repr__ (){ + lldb::SBStream description; + $self->GetDescription (description); + return PyString_FromString (description.GetData()); + } +} +%extend lldb::SBInstructionList { + PyObject *lldb::SBInstructionList::__repr__ (){ + lldb::SBStream description; + $self->GetDescription (description); + return PyString_FromString (description.GetData()); + } +} %extend lldb::SBLineEntry { PyObject *lldb::SBLineEntry::__repr__ (){ lldb::SBStream description; diff --git a/lldb/scripts/lldb.swig b/lldb/scripts/lldb.swig index e144944458c..a02bd65c56f 100644 --- a/lldb/scripts/lldb.swig +++ b/lldb/scripts/lldb.swig @@ -85,6 +85,8 @@ #include "lldb/API/SBFileSpec.h" #include "lldb/API/SBFrame.h" #include "lldb/API/SBFunction.h" +#include "lldb/API/SBInstruction.h" +#include "lldb/API/SBInstructionList.h" #include "lldb/API/SBLineEntry.h" #include "lldb/API/SBListener.h" #include "lldb/API/SBModule.h" @@ -149,6 +151,8 @@ typedef int StopReason; %include "lldb/API/SBFileSpec.h" %include "lldb/API/SBFrame.h" %include "lldb/API/SBFunction.h" +%include "lldb/API/SBInstruction.h" +%include "lldb/API/SBInstructionList.h" %include "lldb/API/SBLineEntry.h" %include "lldb/API/SBListener.h" %include "lldb/API/SBModule.h" diff --git a/lldb/source/API/SBFunction.cpp b/lldb/source/API/SBFunction.cpp index 38e349bd3f9..f1426e787cd 100644 --- a/lldb/source/API/SBFunction.cpp +++ b/lldb/source/API/SBFunction.cpp @@ -10,10 +10,15 @@ #include "lldb/API/SBFunction.h" #include "lldb/API/SBProcess.h" #include "lldb/API/SBStream.h" +#include "lldb/Core/Disassembler.h" +#include "lldb/Core/Module.h" +#include "lldb/Symbol/CompileUnit.h" #include "lldb/Symbol/Function.h" +#include "lldb/Target/ExecutionContext.h" +#include "lldb/Target/Target.h" using namespace lldb; - +using namespace lldb_private; SBFunction::SBFunction () : m_opaque_ptr (NULL) @@ -77,3 +82,28 @@ SBFunction::GetDescription (SBStream &description) return true; } + +SBInstructionList +SBFunction::GetInstructions (SBTarget target) +{ + SBInstructionList sb_instructions; + if (m_opaque_ptr) + { + ExecutionContext exe_ctx; + if (target.IsValid()) + { + target->CalculateExecutionContext (exe_ctx); + exe_ctx.process = target->GetProcessSP().get(); + } + Module *module = m_opaque_ptr->GetAddressRange().GetBaseAddress().GetModule(); + if (module) + { + sb_instructions.SetDisassembler (Disassembler::DisassembleRange (module->GetArchitecture(), + exe_ctx, + m_opaque_ptr->GetAddressRange())); + } + } + return sb_instructions; +} + + diff --git a/lldb/source/API/SBInstruction.cpp b/lldb/source/API/SBInstruction.cpp index 181b6b0c5e9..13d68a1cd34 100644 --- a/lldb/source/API/SBInstruction.cpp +++ b/lldb/source/API/SBInstruction.cpp @@ -9,58 +9,78 @@ #include "lldb/API/SBInstruction.h" +#include "lldb/API/SBAddress.h" +#include "lldb/API/SBInstruction.h" +#include "lldb/API/SBStream.h" + #include "lldb/Core/Disassembler.h" +#include "lldb/Core/StreamFile.h" using namespace lldb; using namespace lldb_private; -//SBInstruction::SBInstruction (lldb_private::Disassembler::Instruction *lldb_insn) : -// m_opaque_sp (lldb_insn); -//{ -//} - SBInstruction::SBInstruction () { } +SBInstruction::SBInstruction (const lldb::InstructionSP& inst_sp) : + m_opaque_sp (inst_sp) +{ +} + SBInstruction::~SBInstruction () { } -//bool -//SBInstruction::IsValid() -//{ -// return (m_opaque_sp.get() != NULL); -//} +bool +SBInstruction::IsValid() +{ + return (m_opaque_sp.get() != NULL); +} + +SBAddress +SBInstruction::GetAddress() +{ + SBAddress sb_addr; + if (m_opaque_sp && m_opaque_sp->GetAddress().IsValid()) + sb_addr.SetAddress(&m_opaque_sp->GetAddress()); + return sb_addr; +} + +size_t +SBInstruction::GetByteSize () +{ + if (m_opaque_sp) + return m_opaque_sp->GetByteSize(); + return 0; +} -//size_t -//SBInstruction::GetByteSize () -//{ -// if (IsValid()) -// { -// return m_opaque_sp->GetByteSize(); -// } -// return 0; -//} +bool +SBInstruction::DoesBranch () +{ + if (m_opaque_sp) + return m_opaque_sp->DoesBranch (); + return false; +} -//void -//SBInstruction::SetByteSize (size_T byte_size) -//{ -// if (IsValid ()) -// { -// m_opaque_sp->SetByteSize (byte_size); -// } -//} +void +SBInstruction::SetOpaque (const lldb::InstructionSP &inst_sp) +{ + m_opaque_sp = inst_sp; +} -//bool -//SBInstruction::DoesBranch () -//{ -// if (IsValid ()) -// { -// return m_opaque_sp->DoesBranch (); -// } -// return false; -//} +bool +SBInstruction::GetDescription (lldb::SBStream &s) +{ + if (m_opaque_sp) + { + // Use the "ref()" instead of the "get()" accessor in case the SBStream + // didn't have a stream already created, one will get created... + m_opaque_sp->Dump (&s.ref(), true, NULL, 0, NULL, false); + return true; + } + return false; +} void SBInstruction::Print (FILE *out) @@ -68,7 +88,9 @@ SBInstruction::Print (FILE *out) if (out == NULL) return; - //StreamFile out_strem (out); - - //m_opaque_sp->Dump (out, LLDB_INVALID_ADDRESS, NULL, 0); + if (m_opaque_sp) + { + StreamFile out_stream (out); + m_opaque_sp->Dump (&out_stream, true, NULL, 0, NULL, false); + } } diff --git a/lldb/source/API/SBInstructionList.cpp b/lldb/source/API/SBInstructionList.cpp index d34e9d100a9..b27ddfa5011 100644 --- a/lldb/source/API/SBInstructionList.cpp +++ b/lldb/source/API/SBInstructionList.cpp @@ -9,11 +9,16 @@ #include "lldb/API/SBInstructionList.h" #include "lldb/API/SBInstruction.h" +#include "lldb/API/SBStream.h" +#include "lldb/Core/Disassembler.h" +#include "lldb/Core/Stream.h" using namespace lldb; +using namespace lldb_private; -SBInstructionList::SBInstructionList () +SBInstructionList::SBInstructionList () : + m_opaque_sp() { } @@ -24,6 +29,8 @@ SBInstructionList::~SBInstructionList () size_t SBInstructionList::GetSize () { + if (m_opaque_sp) + return m_opaque_sp->GetInstructionList().GetSize(); return 0; } @@ -31,12 +38,15 @@ SBInstruction SBInstructionList::GetInstructionAtIndex (uint32_t idx) { SBInstruction inst; + if (m_opaque_sp && idx < m_opaque_sp->GetInstructionList().GetSize()) + inst.SetOpaque (m_opaque_sp->GetInstructionList().GetInstructionAtIndex (idx)); return inst; } void SBInstructionList::Clear () { + m_opaque_sp.reset(); } void @@ -45,9 +55,42 @@ SBInstructionList::AppendInstruction (SBInstruction insn) } void +SBInstructionList::SetDisassembler (const lldb::DisassemblerSP &opaque_sp) +{ + m_opaque_sp = opaque_sp; +} + +void SBInstructionList::Print (FILE *out) { if (out == NULL) return; } + +bool +SBInstructionList::GetDescription (lldb::SBStream &description) +{ + if (m_opaque_sp) + { + size_t num_instructions = GetSize (); + if (num_instructions) + { + // Call the ref() to make sure a stream is created if one deesn't + // exist already inside description... + Stream &sref = description.ref(); + for (size_t i=0; i<num_instructions; ++i) + { + Instruction *inst = m_opaque_sp->GetInstructionList().GetInstructionAtIndex (i).get(); + if (inst == NULL) + break; + inst->Dump (&sref, true, NULL, 0, NULL, false); + sref.EOL(); + } + return true; + } + } + return false; +} + + diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp index 2d6e6b03a92..1a72f589c6a 100644 --- a/lldb/source/API/SBProcess.cpp +++ b/lldb/source/API/SBProcess.cpp @@ -474,11 +474,17 @@ SBProcess::GetDescription (SBStream &description) { char path[PATH_MAX]; GetTarget().GetExecutable().GetPath (path, sizeof(path)); - description.Printf ("Process {pid: %d, executable %s\n", (int) GetProcessID(), path); - description.Printf (" instance name: %s, state: %s, thread cnt: %d}", - m_opaque_sp->GetInstanceName().AsCString(), + Module *exe_module = m_opaque_sp->GetTarget().GetExecutableModule ().get(); + const char *exe_name = NULL; + if (exe_module) + exe_name = exe_module->GetFileSpec().GetFilename().AsCString(); + + description.Printf ("Process {pid: %d, state: %s, threads: %d%s%s}", + m_opaque_sp->GetID(), SBDebugger::StateAsCString (GetState()), - GetNumThreads()); + GetNumThreads(), + exe_name ? ", executable: " : "", + exe_name ? exe_name : ""); } else description.Printf ("No value"); diff --git a/lldb/source/API/SBSymbol.cpp b/lldb/source/API/SBSymbol.cpp index 017df4394ca..eed84d5c608 100644 --- a/lldb/source/API/SBSymbol.cpp +++ b/lldb/source/API/SBSymbol.cpp @@ -9,10 +9,14 @@ #include "lldb/API/SBSymbol.h" #include "lldb/API/SBStream.h" +#include "lldb/Core/Disassembler.h" +#include "lldb/Core/Module.h" #include "lldb/Symbol/Symbol.h" +#include "lldb/Target/ExecutionContext.h" +#include "lldb/Target/Target.h" using namespace lldb; - +using namespace lldb_private; SBSymbol::SBSymbol () : m_opaque_ptr (NULL) @@ -78,3 +82,30 @@ SBSymbol::GetDescription (SBStream &description) return true; } + + + +SBInstructionList +SBSymbol::GetInstructions (SBTarget target) +{ + SBInstructionList sb_instructions; + if (m_opaque_ptr) + { + ExecutionContext exe_ctx; + if (target.IsValid()) + target->CalculateExecutionContext (exe_ctx); + const AddressRange *symbol_range = m_opaque_ptr->GetAddressRangePtr(); + if (symbol_range) + { + Module *module = symbol_range->GetBaseAddress().GetModule(); + if (module) + { + sb_instructions.SetDisassembler (Disassembler::DisassembleRange (module->GetArchitecture (), + exe_ctx, + *symbol_range)); + } + } + } + return sb_instructions; +} + diff --git a/lldb/source/API/SBThread.cpp b/lldb/source/API/SBThread.cpp index 216fa127816..7bf7dd29542 100644 --- a/lldb/source/API/SBThread.cpp +++ b/lldb/source/API/SBThread.cpp @@ -418,11 +418,7 @@ bool SBThread::GetDescription (SBStream &description) { if (m_opaque_sp) - { - m_opaque_sp->DumpUsingSettingsFormat (description.ref(), LLDB_INVALID_INDEX32); - description.Printf (" %d frames, (instance name: %s)", GetNumFrames(), - m_opaque_sp->GetInstanceName().AsCString()); - } + m_opaque_sp->DumpUsingSettingsFormat (description.ref(), 0); else description.Printf ("No value"); diff --git a/lldb/source/Core/Disassembler.cpp b/lldb/source/Core/Disassembler.cpp index c2d36ef5b16..65380493082 100644 --- a/lldb/source/Core/Disassembler.cpp +++ b/lldb/source/Core/Disassembler.cpp @@ -135,6 +135,32 @@ Disassembler::Disassemble return false; } + +lldb::DisassemblerSP +Disassembler::DisassembleRange +( + const ArchSpec &arch, + const ExecutionContext &exe_ctx, + const AddressRange &range +) +{ + lldb::DisassemblerSP disasm_sp; + if (range.GetByteSize() > 0 && range.GetBaseAddress().IsValid()) + { + disasm_sp.reset (Disassembler::FindPlugin(arch)); + + if (disasm_sp) + { + DataExtractor data; + size_t bytes_disassembled = disasm_sp->ParseInstructions (&exe_ctx, range, data); + if (bytes_disassembled == 0) + disasm_sp.reset(); + } + } + return disasm_sp; +} + + bool Disassembler::Disassemble ( @@ -149,9 +175,9 @@ Disassembler::Disassemble { if (disasm_range.GetByteSize()) { - Disassembler *disassembler = Disassembler::FindPlugin(arch); + std::auto_ptr<Disassembler> disasm_ap (Disassembler::FindPlugin(arch)); - if (disassembler) + if (disasm_ap.get()) { AddressRange range(disasm_range); @@ -175,7 +201,7 @@ Disassembler::Disassemble } DataExtractor data; - size_t bytes_disassembled = disassembler->ParseInstructions (&exe_ctx, range, data); + size_t bytes_disassembled = disasm_ap->ParseInstructions (&exe_ctx, range, data); if (bytes_disassembled == 0) { return false; @@ -183,7 +209,7 @@ Disassembler::Disassemble else { // We got some things disassembled... - size_t num_instructions = disassembler->GetInstructionList().GetSize(); + size_t num_instructions = disasm_ap->GetInstructionList().GetSize(); uint32_t offset = 0; SymbolContext sc; SymbolContext prev_sc; @@ -201,7 +227,7 @@ Disassembler::Disassemble for (size_t i=0; i<num_instructions; ++i) { - Disassembler::Instruction *inst = disassembler->GetInstructionList().GetInstructionAtIndex (i); + Instruction *inst = disasm_ap->GetInstructionList().GetInstructionAtIndex (i).get(); if (inst) { addr_t file_addr = addr.GetFileAddress(); @@ -270,7 +296,7 @@ Disassembler::Disassemble strm.IndentMore (); strm.Indent(); size_t inst_byte_size = inst->GetByteSize(); - inst->Dump(&strm, &addr, show_bytes ? &data : NULL, offset, exe_ctx, show_bytes); + inst->Dump(&strm, true, show_bytes ? &data : NULL, offset, &exe_ctx, show_bytes); strm.EOL(); offset += inst_byte_size; @@ -330,55 +356,49 @@ Disassembler::Disassemble return Disassemble(debugger, arch, exe_ctx, range, num_mixed_context_lines, show_bytes, strm); } -Disassembler::Instruction::Instruction() +Instruction::Instruction(const Address &addr) : + m_addr (addr) { } -Disassembler::Instruction::~Instruction() +Instruction::~Instruction() { } -Disassembler::InstructionList::InstructionList() : +InstructionList::InstructionList() : m_instructions() { } -Disassembler::InstructionList::~InstructionList() +InstructionList::~InstructionList() { } size_t -Disassembler::InstructionList::GetSize() const +InstructionList::GetSize() const { return m_instructions.size(); } -Disassembler::Instruction * -Disassembler::InstructionList::GetInstructionAtIndex (uint32_t idx) +InstructionSP +InstructionList::GetInstructionAtIndex (uint32_t idx) const { + InstructionSP inst_sp; if (idx < m_instructions.size()) - return m_instructions[idx].get(); - return NULL; -} - -const Disassembler::Instruction * -Disassembler::InstructionList::GetInstructionAtIndex (uint32_t idx) const -{ - if (idx < m_instructions.size()) - return m_instructions[idx].get(); - return NULL; + inst_sp = m_instructions[idx]; + return inst_sp; } void -Disassembler::InstructionList::Clear() +InstructionList::Clear() { m_instructions.clear(); } void -Disassembler::InstructionList::AppendInstruction (Instruction::shared_ptr &inst_sp) +InstructionList::Append (lldb::InstructionSP &inst_sp) { if (inst_sp) m_instructions.push_back(inst_sp); @@ -394,7 +414,6 @@ Disassembler::ParseInstructions ) { Target *target = exe_ctx->target; - const addr_t byte_size = range.GetByteSize(); if (target == NULL || byte_size == 0 || !range.GetBaseAddress().IsValid()) return 0; @@ -421,7 +440,7 @@ Disassembler::ParseInstructions data.SetByteOrder(target->GetArchitecture().GetDefaultEndian()); data.SetAddressByteSize(target->GetArchitecture().GetAddressByteSize()); } - return DecodeInstructions (data, 0, UINT32_MAX); + return DecodeInstructions (range.GetBaseAddress(), data, 0, UINT32_MAX); } return 0; @@ -445,13 +464,13 @@ Disassembler::~Disassembler() { } -Disassembler::InstructionList & +InstructionList & Disassembler::GetInstructionList () { return m_instruction_list; } -const Disassembler::InstructionList & +const InstructionList & Disassembler::GetInstructionList () const { return m_instruction_list; diff --git a/lldb/source/Expression/ClangExpressionParser.cpp b/lldb/source/Expression/ClangExpressionParser.cpp index 194a90d22bd..60b0f7afef4 100644 --- a/lldb/source/Expression/ClangExpressionParser.cpp +++ b/lldb/source/Expression/ClangExpressionParser.cpp @@ -668,9 +668,9 @@ ClangExpressionParser::DisassembleFunction (Stream &stream, ExecutionContext &ex DataExtractor::TypeUInt8); } - disassembler->DecodeInstructions(extractor, 0, UINT32_MAX); + disassembler->DecodeInstructions (Address (NULL, func_remote_addr), extractor, 0, UINT32_MAX); - Disassembler::InstructionList &instruction_list = disassembler->GetInstructionList(); + InstructionList &instruction_list = disassembler->GetInstructionList(); uint32_t bytes_offset = 0; @@ -678,13 +678,12 @@ ClangExpressionParser::DisassembleFunction (Stream &stream, ExecutionContext &ex instruction_index < num_instructions; ++instruction_index) { - Disassembler::Instruction *instruction = instruction_list.GetInstructionAtIndex(instruction_index); - Address addr(NULL, func_remote_addr + bytes_offset); + Instruction *instruction = instruction_list.GetInstructionAtIndex(instruction_index).get(); instruction->Dump (&stream, - &addr, + true, &extractor, bytes_offset, - exe_ctx, + &exe_ctx, true); stream.PutChar('\n'); bytes_offset += instruction->GetByteSize(); diff --git a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp b/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp index 963b1f3ea67..e0fc02c3bec 100644 --- a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp +++ b/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp @@ -75,13 +75,13 @@ static int IPRegisterReader(uint64_t *value, unsigned regID, void* arg) return -1; } -DisassemblerLLVM::Instruction::Instruction(EDDisassemblerRef disassembler) : - Disassembler::Instruction (), +DisassemblerLLVM::InstructionLLVM::InstructionLLVM (EDDisassemblerRef disassembler, const Address &addr) : + Instruction (addr), m_disassembler (disassembler) { } -DisassemblerLLVM::Instruction::~Instruction() +DisassemblerLLVM::InstructionLLVM::~InstructionLLVM() { } @@ -97,28 +97,31 @@ PadString(Stream *s, const std::string &str, size_t width) } void -DisassemblerLLVM::Instruction::Dump +DisassemblerLLVM::InstructionLLVM::Dump ( Stream *s, - lldb_private::Address *inst_addr_ptr, + bool show_address, const DataExtractor *bytes, uint32_t bytes_offset, - const lldb_private::ExecutionContext& exe_ctx, + const lldb_private::ExecutionContext* exe_ctx, bool raw ) { const size_t opcodeColumnWidth = 7; const size_t operandColumnWidth = 25; - ExecutionContextScope *exe_scope = exe_ctx.GetBestExecutionContextScope(); + ExecutionContextScope *exe_scope = NULL; + if (exe_ctx) + exe_scope = exe_ctx->GetBestExecutionContextScope(); + // If we have an address, print it out - if (inst_addr_ptr) + if (GetAddress().IsValid()) { - if (inst_addr_ptr->Dump (s, - exe_scope, - Address::DumpStyleLoadAddress, - Address::DumpStyleModuleWithFileAddress, - 0)) + if (GetAddress().Dump (s, + exe_scope, + Address::DumpStyleLoadAddress, + Address::DumpStyleModuleWithFileAddress, + 0)) s->PutCString(": "); } @@ -139,16 +142,15 @@ DisassemblerLLVM::Instruction::Dump int currentOpIndex = -1; - //lldb_private::Process *process = exe_ctx.process; std::auto_ptr<RegisterReaderArg> rra; if (!raw) { addr_t base_addr = LLDB_INVALID_ADDRESS; - if (exe_ctx.target && !exe_ctx.target->GetSectionLoadList().IsEmpty()) - base_addr = inst_addr_ptr->GetLoadAddress (exe_ctx.target); + if (exe_ctx && exe_ctx->target && !exe_ctx->target->GetSectionLoadList().IsEmpty()) + base_addr = GetAddress().GetLoadAddress (exe_ctx->target); if (base_addr == LLDB_INVALID_ADDRESS) - base_addr = inst_addr_ptr->GetFileAddress (); + base_addr = GetAddress().GetFileAddress (); rra.reset(new RegisterReaderArg(base_addr + EDInstByteSize(m_inst), m_disassembler)); } @@ -246,14 +248,14 @@ DisassemblerLLVM::Instruction::Dump } lldb_private::Address so_addr; - if (exe_ctx.target && !exe_ctx.target->GetSectionLoadList().IsEmpty()) + if (exe_ctx && exe_ctx->target && !exe_ctx->target->GetSectionLoadList().IsEmpty()) { - if (exe_ctx.target->GetSectionLoadList().ResolveLoadAddress (operand_value, so_addr)) + if (exe_ctx->target->GetSectionLoadList().ResolveLoadAddress (operand_value, so_addr)) so_addr.Dump(&comment, exe_scope, Address::DumpStyleResolvedDescriptionNoModule, Address::DumpStyleSectionNameOffset); } - else if (inst_addr_ptr) + else { - Module *module = inst_addr_ptr->GetModule(); + Module *module = GetAddress().GetModule(); if (module) { if (module->ResolveFileAddress (operand_value, so_addr)) @@ -318,19 +320,19 @@ DisassemblerLLVM::Instruction::Dump } bool -DisassemblerLLVM::Instruction::DoesBranch() const +DisassemblerLLVM::InstructionLLVM::DoesBranch() const { return EDInstIsBranch(m_inst); } size_t -DisassemblerLLVM::Instruction::GetByteSize() const +DisassemblerLLVM::InstructionLLVM::GetByteSize() const { return EDInstByteSize(m_inst); } size_t -DisassemblerLLVM::Instruction::Extract(const DataExtractor &data, uint32_t data_offset) +DisassemblerLLVM::InstructionLLVM::Extract(const DataExtractor &data, uint32_t data_offset) { if (EDCreateInsts(&m_inst, 1, m_disassembler, DataExtractorByteReader, data_offset, (void*)(&data))) return EDInstByteSize(m_inst); @@ -391,6 +393,7 @@ DisassemblerLLVM::~DisassemblerLLVM() size_t DisassemblerLLVM::DecodeInstructions ( + const Address &base_addr, const DataExtractor& data, uint32_t data_offset, uint32_t num_instructions @@ -402,14 +405,16 @@ DisassemblerLLVM::DecodeInstructions while (data.ValidOffset(data_offset) && num_instructions) { - Instruction::shared_ptr inst_sp (new Instruction(m_disassembler)); + Address inst_addr (base_addr); + inst_addr.Slide(data_offset); + InstructionSP inst_sp (new InstructionLLVM(m_disassembler, inst_addr)); - size_t inst_byte_size = inst_sp->Extract(data, data_offset); + size_t inst_byte_size = inst_sp->Extract (data, data_offset); if (inst_byte_size == 0) break; - m_instruction_list.AppendInstruction(inst_sp); + m_instruction_list.Append (inst_sp); total_inst_byte_size += inst_byte_size; data_offset += inst_byte_size; diff --git a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h b/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h index 181710c5ffe..3d76670e383 100644 --- a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h +++ b/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h @@ -19,20 +19,20 @@ class DisassemblerLLVM : public lldb_private::Disassembler { public: - class Instruction : public lldb_private::Disassembler::Instruction + class InstructionLLVM : public lldb_private::Instruction { public: - Instruction(EDDisassemblerRef disassembler); + InstructionLLVM(EDDisassemblerRef disassembler, const lldb_private::Address &addr); virtual - ~Instruction(); + ~InstructionLLVM(); void Dump (lldb_private::Stream *s, - lldb_private::Address *instr_addr_ptr, + bool show_address, const lldb_private::DataExtractor *bytes, uint32_t bytes_offset, - const lldb_private::ExecutionContext& exe_ctx, + const lldb_private::ExecutionContext* exe_ctx, bool raw); bool @@ -75,7 +75,8 @@ public: ~DisassemblerLLVM(); size_t - DecodeInstructions (const lldb_private::DataExtractor& data, + DecodeInstructions (const lldb_private::Address &base_addr, + const lldb_private::DataExtractor& data, uint32_t data_offset, uint32_t num_instructions); |