[Lldb-commits] [lldb] r115734 - in /lldb/trunk: include/lldb/ include/lldb/API/ include/lldb/Core/ scripts/ scripts/Python/ source/API/ source/Core/ source/Expression/ source/Plugins/Disassembler/llvm/
Greg Clayton
gclayton at apple.com
Tue Oct 5 20:09:58 PDT 2010
Author: gclayton
Date: Tue Oct 5 22:09:58 2010
New Revision: 115734
URL: http://llvm.org/viewvc/llvm-project?rev=115734&view=rev
Log:
Added the ability to get the disassembly instructions from the function and
symbol.
Modified:
lldb/trunk/include/lldb/API/SBAddress.h
lldb/trunk/include/lldb/API/SBFunction.h
lldb/trunk/include/lldb/API/SBInstruction.h
lldb/trunk/include/lldb/API/SBInstructionList.h
lldb/trunk/include/lldb/API/SBProcess.h
lldb/trunk/include/lldb/API/SBStream.h
lldb/trunk/include/lldb/API/SBSymbol.h
lldb/trunk/include/lldb/API/SBTarget.h
lldb/trunk/include/lldb/Core/Disassembler.h
lldb/trunk/include/lldb/lldb-forward-rtti.h
lldb/trunk/include/lldb/lldb-forward.h
lldb/trunk/scripts/Python/build-swig-Python.sh
lldb/trunk/scripts/Python/python-extensions.swig
lldb/trunk/scripts/lldb.swig
lldb/trunk/source/API/SBFunction.cpp
lldb/trunk/source/API/SBInstruction.cpp
lldb/trunk/source/API/SBInstructionList.cpp
lldb/trunk/source/API/SBProcess.cpp
lldb/trunk/source/API/SBSymbol.cpp
lldb/trunk/source/API/SBThread.cpp
lldb/trunk/source/Core/Disassembler.cpp
lldb/trunk/source/Expression/ClangExpressionParser.cpp
lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp
lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h
Modified: lldb/trunk/include/lldb/API/SBAddress.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBAddress.h?rev=115734&r1=115733&r2=115734&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBAddress.h (original)
+++ lldb/trunk/include/lldb/API/SBAddress.h Tue Oct 5 22:09:58 2010
@@ -51,6 +51,7 @@
friend class SBFrame;
friend class SBLineEntry;
+ friend class SBInstruction;
friend class SBModule;
friend class SBSymbolContext;
friend class SBThread;
Modified: lldb/trunk/include/lldb/API/SBFunction.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBFunction.h?rev=115734&r1=115733&r2=115734&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBFunction.h (original)
+++ lldb/trunk/include/lldb/API/SBFunction.h Tue Oct 5 22:09:58 2010
@@ -11,6 +11,7 @@
#define LLDB_SBFunction_h_
#include "lldb/API/SBDefines.h"
+#include "lldb/API/SBInstructionList.h"
namespace lldb {
@@ -31,6 +32,9 @@
const char *
GetMangledName () const;
+ lldb::SBInstructionList
+ GetInstructions (lldb::SBTarget target);
+
#ifndef SWIG
bool
operator == (const lldb::SBFunction &rhs) const;
Modified: lldb/trunk/include/lldb/API/SBInstruction.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBInstruction.h?rev=115734&r1=115733&r2=115734&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBInstruction.h (original)
+++ lldb/trunk/include/lldb/API/SBInstruction.h Tue Oct 5 22:09:58 2010
@@ -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;
};
Modified: lldb/trunk/include/lldb/API/SBInstructionList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBInstructionList.h?rev=115734&r1=115733&r2=115734&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBInstructionList.h (original)
+++ lldb/trunk/include/lldb/API/SBInstructionList.h Tue Oct 5 22:09:58 2010
@@ -36,17 +36,21 @@
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;
};
Modified: lldb/trunk/include/lldb/API/SBProcess.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBProcess.h?rev=115734&r1=115733&r2=115734&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBProcess.h (original)
+++ lldb/trunk/include/lldb/API/SBProcess.h Tue Oct 5 22:09:58 2010
@@ -161,6 +161,7 @@
friend class SBBreakpointLocation;
friend class SBCommandInterpreter;
friend class SBDebugger;
+ friend class SBFunction;
friend class SBTarget;
friend class SBThread;
friend class SBValue;
Modified: lldb/trunk/include/lldb/API/SBStream.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBStream.h?rev=115734&r1=115733&r2=115734&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBStream.h (original)
+++ lldb/trunk/include/lldb/API/SBStream.h Tue Oct 5 22:09:58 2010
@@ -63,6 +63,8 @@
friend class SBEvent;
friend class SBFrame;
friend class SBFunction;
+ friend class SBInstruction;
+ friend class SBInstructionList;
friend class SBModule;
friend class SBSymbol;
friend class SBSymbolContext;
Modified: lldb/trunk/include/lldb/API/SBSymbol.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBSymbol.h?rev=115734&r1=115733&r2=115734&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBSymbol.h (original)
+++ lldb/trunk/include/lldb/API/SBSymbol.h Tue Oct 5 22:09:58 2010
@@ -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 @@
const char *
GetMangledName () const;
+ lldb::SBInstructionList
+ GetInstructions (lldb::SBTarget target);
+
#ifndef SWIG
bool
operator == (const lldb::SBSymbol &rhs) const;
Modified: lldb/trunk/include/lldb/API/SBTarget.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBTarget.h?rev=115734&r1=115733&r2=115734&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBTarget.h (original)
+++ lldb/trunk/include/lldb/API/SBTarget.h Tue Oct 5 22:09:58 2010
@@ -148,7 +148,9 @@
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
Modified: lldb/trunk/include/lldb/Core/Disassembler.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Disassembler.h?rev=115734&r1=115733&r2=115734&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Disassembler.h (original)
+++ lldb/trunk/include/lldb/Core/Disassembler.h Tue Oct 5 22:09:58 2010
@@ -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
+ Instruction (const Address &addr);
+
+ virtual
+ ~Instruction();
+
+ const Address &
+ GetAddress () const
{
- public:
- typedef lldb::SharedPtr<Instruction>::Type shared_ptr;
+ return m_addr;
+ }
- Instruction();
+ void
+ SetAddress (const Address &addr)
+ {
+ m_addr = addr;
+ }
- virtual
- ~Instruction();
+ virtual size_t
+ GetByteSize() const = 0;
- virtual size_t
- GetByteSize() const = 0;
-
- 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
- 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 @@
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;
Modified: lldb/trunk/include/lldb/lldb-forward-rtti.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-forward-rtti.h?rev=115734&r1=115733&r2=115734&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-forward-rtti.h (original)
+++ lldb/trunk/include/lldb/lldb-forward-rtti.h Tue Oct 5 22:09:58 2010
@@ -34,12 +34,14 @@
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;
Modified: lldb/trunk/include/lldb/lldb-forward.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-forward.h?rev=115734&r1=115733&r2=115734&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-forward.h (original)
+++ lldb/trunk/include/lldb/lldb-forward.h Tue Oct 5 22:09:58 2010
@@ -78,6 +78,7 @@
class InlineFunctionInfo;
class InputReader;
class InstanceSettings;
+class Instruction;
class LanguageRuntime;
class LineTable;
class Listener;
Modified: lldb/trunk/scripts/Python/build-swig-Python.sh
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/build-swig-Python.sh?rev=115734&r1=115733&r2=115734&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/build-swig-Python.sh (original)
+++ lldb/trunk/scripts/Python/build-swig-Python.sh Tue Oct 5 22:09:58 2010
@@ -44,6 +44,8 @@
" ${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"\
Modified: lldb/trunk/scripts/Python/python-extensions.swig
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/python-extensions.swig?rev=115734&r1=115733&r2=115734&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/python-extensions.swig (original)
+++ lldb/trunk/scripts/Python/python-extensions.swig Tue Oct 5 22:09:58 2010
@@ -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;
Modified: lldb/trunk/scripts/lldb.swig
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/lldb.swig?rev=115734&r1=115733&r2=115734&view=diff
==============================================================================
--- lldb/trunk/scripts/lldb.swig (original)
+++ lldb/trunk/scripts/lldb.swig Tue Oct 5 22:09:58 2010
@@ -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 @@
%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"
Modified: lldb/trunk/source/API/SBFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFunction.cpp?rev=115734&r1=115733&r2=115734&view=diff
==============================================================================
--- lldb/trunk/source/API/SBFunction.cpp (original)
+++ lldb/trunk/source/API/SBFunction.cpp Tue Oct 5 22:09:58 2010
@@ -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 @@
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;
+}
+
+
Modified: lldb/trunk/source/API/SBInstruction.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBInstruction.cpp?rev=115734&r1=115733&r2=115734&view=diff
==============================================================================
--- lldb/trunk/source/API/SBInstruction.cpp (original)
+++ lldb/trunk/source/API/SBInstruction.cpp Tue Oct 5 22:09:58 2010
@@ -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);
-//}
-
-//size_t
-//SBInstruction::GetByteSize ()
-//{
-// if (IsValid())
-// {
-// return m_opaque_sp->GetByteSize();
-// }
-// return 0;
-//}
-
-//void
-//SBInstruction::SetByteSize (size_T byte_size)
-//{
-// if (IsValid ())
-// {
-// m_opaque_sp->SetByteSize (byte_size);
-// }
-//}
-
-//bool
-//SBInstruction::DoesBranch ()
-//{
-// if (IsValid ())
-// {
-// return m_opaque_sp->DoesBranch ();
-// }
-// return false;
-//}
+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;
+}
+
+bool
+SBInstruction::DoesBranch ()
+{
+ if (m_opaque_sp)
+ return m_opaque_sp->DoesBranch ();
+ return false;
+}
+
+void
+SBInstruction::SetOpaque (const lldb::InstructionSP &inst_sp)
+{
+ m_opaque_sp = inst_sp;
+}
+
+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 @@
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);
+ }
}
Modified: lldb/trunk/source/API/SBInstructionList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBInstructionList.cpp?rev=115734&r1=115733&r2=115734&view=diff
==============================================================================
--- lldb/trunk/source/API/SBInstructionList.cpp (original)
+++ lldb/trunk/source/API/SBInstructionList.cpp Tue Oct 5 22:09:58 2010
@@ -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 @@
size_t
SBInstructionList::GetSize ()
{
+ if (m_opaque_sp)
+ return m_opaque_sp->GetInstructionList().GetSize();
return 0;
}
@@ -31,12 +38,15 @@
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 @@
}
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;
+}
+
+
Modified: lldb/trunk/source/API/SBProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBProcess.cpp?rev=115734&r1=115733&r2=115734&view=diff
==============================================================================
--- lldb/trunk/source/API/SBProcess.cpp (original)
+++ lldb/trunk/source/API/SBProcess.cpp Tue Oct 5 22:09:58 2010
@@ -474,11 +474,17 @@
{
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");
Modified: lldb/trunk/source/API/SBSymbol.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBSymbol.cpp?rev=115734&r1=115733&r2=115734&view=diff
==============================================================================
--- lldb/trunk/source/API/SBSymbol.cpp (original)
+++ lldb/trunk/source/API/SBSymbol.cpp Tue Oct 5 22:09:58 2010
@@ -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 @@
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;
+}
+
Modified: lldb/trunk/source/API/SBThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBThread.cpp?rev=115734&r1=115733&r2=115734&view=diff
==============================================================================
--- lldb/trunk/source/API/SBThread.cpp (original)
+++ lldb/trunk/source/API/SBThread.cpp Tue Oct 5 22:09:58 2010
@@ -418,11 +418,7 @@
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");
Modified: lldb/trunk/source/Core/Disassembler.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Disassembler.cpp?rev=115734&r1=115733&r2=115734&view=diff
==============================================================================
--- lldb/trunk/source/Core/Disassembler.cpp (original)
+++ lldb/trunk/source/Core/Disassembler.cpp Tue Oct 5 22:09:58 2010
@@ -135,6 +135,32 @@
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 @@
{
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 @@
}
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 @@
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 @@
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 @@
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 @@
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 @@
)
{
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 @@
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::InstructionList &
+InstructionList &
Disassembler::GetInstructionList ()
{
return m_instruction_list;
}
-const Disassembler::InstructionList &
+const InstructionList &
Disassembler::GetInstructionList () const
{
return m_instruction_list;
Modified: lldb/trunk/source/Expression/ClangExpressionParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionParser.cpp?rev=115734&r1=115733&r2=115734&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionParser.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionParser.cpp Tue Oct 5 22:09:58 2010
@@ -668,9 +668,9 @@
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 @@
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();
Modified: lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp?rev=115734&r1=115733&r2=115734&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp (original)
+++ lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp Tue Oct 5 22:09:58 2010
@@ -75,13 +75,13 @@
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 @@
}
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 @@
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 @@
}
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 @@
}
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 @@
size_t
DisassemblerLLVM::DecodeInstructions
(
+ const Address &base_addr,
const DataExtractor& data,
uint32_t data_offset,
uint32_t num_instructions
@@ -402,14 +405,16 @@
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;
Modified: lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h?rev=115734&r1=115733&r2=115734&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h (original)
+++ lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h Tue Oct 5 22:09:58 2010
@@ -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 @@
~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);
More information about the lldb-commits
mailing list