Add GetDescription() and __repr__ () methods to most API classes, to allow

"print" from inside Python to print out the objects in a more useful
manner.

llvm-svn: 114321
This commit is contained in:
Caroline Tice 2010-09-20 05:20:02 +00:00
parent fd02aa84dc
commit dde9cff32a
49 changed files with 822 additions and 28 deletions

View File

@ -44,6 +44,16 @@ public:
bool
OffsetAddress (addr_t offset);
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
protected:
friend class SBFrame;

View File

@ -49,6 +49,16 @@ public:
lldb::SBBlock
GetFirstChild ();
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject *, which contains a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
private:
friend class SBFrame;
friend class SBSymbolContext;

View File

@ -104,8 +104,8 @@ public:
size_t
GetNumLocations() const;
void
GetDescription (FILE *, const char *description_level);
bool
GetDescription (const char *description_level, lldb::SBStream &description);
static lldb::BreakpointEventType
GetBreakpointEventTypeFromEvent (const lldb::SBEvent& event);
@ -116,6 +116,13 @@ public:
static lldb::SBBreakpointLocation
GetBreakpointLocationAtIndexFromEvent (const lldb::SBEvent& event, uint32_t loc_idx);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
private:
friend class SBBreakpointLocation;
friend class SBTarget;

View File

@ -68,12 +68,19 @@ public:
bool
IsResolved ();
void
GetDescription (FILE *f, const char *description_level);
bool
GetDescription (const char *description_level, lldb::SBStream &description);
SBBreakpoint
GetBreakpoint ();
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
private:
friend class SBBreakpoint;

View File

@ -58,6 +58,16 @@ public:
void
AppendMessage (const char *message);
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
protected:
friend class SBCommandInterpreter;
friend class SBOptions;

View File

@ -50,6 +50,16 @@ public:
#endif
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
private:
friend class SBFrame;
friend class SBSymbolContext;

View File

@ -154,6 +154,16 @@ public:
static lldb::SBStringList
GetInternalVariableValue (const char *var_name, const char *debugger_instance_name);
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
uint32_t
GetTerminalWidth () const;

View File

@ -10,6 +10,11 @@
#ifndef LLDB_SBDefines_h_
#define LLDB_SBDefines_h_
// In order to guarantee correct working with Python, Python.h *MUST* be
// the *FIRST* header file included:
#include <Python.h>
// C Includes
// C++ Includes
// Other libraries and framework includes
@ -49,6 +54,7 @@ class SBListener;
class SBModule;
class SBProcess;
class SBSourceManager;
class SBStream;
class SBStringList;
class SBSymbol;
class SBSymbolContext;

View File

@ -65,6 +65,16 @@ public:
bool
IsValid () const;
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
protected:
friend class SBArguments;
friend class SBDebugger;

View File

@ -10,10 +10,11 @@
#ifndef LLDB_SBEvent_h_
#define LLDB_SBEvent_h_
#include "lldb/API/SBDefines.h"
#include <stdio.h>
#include <vector>
#include "lldb/API/SBDefines.h"
namespace lldb {
@ -53,6 +54,16 @@ public:
static const char *
GetCStringFromEvent (const lldb::SBEvent &event);
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
protected:
friend class SBListener;
friend class SBBroadcaster;

View File

@ -51,6 +51,16 @@ public:
static int
ResolvePath (const char *src_path, char *dst_path, size_t dst_len);
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
private:
friend class SBBlock;
friend class SBCompileUnit;

View File

@ -112,6 +112,16 @@ public:
lldb::SBValue
LookupVarInScope (const char *var_name, const char *scope);
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
protected:
friend class SBValue;

View File

@ -39,6 +39,16 @@ public:
operator != (const lldb::SBFunction &rhs) const;
#endif
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
private:
friend class SBFrame;
friend class SBSymbolContext;

View File

@ -46,6 +46,16 @@ public:
void
Print (FILE *out);
//bool
//GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
//PyObject *
//__repr__ ();
private:
//lldb_private::Disassembler::Instruction::SharedPtr m_opaque_sp;

View File

@ -58,6 +58,16 @@ public:
#endif
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
private:
friend class SBCompileUnit;
friend class SBFrame;

View File

@ -49,6 +49,16 @@ public:
ResolveSymbolContextForAddress (const lldb::SBAddress& addr,
uint32_t resolve_scope);
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
private:
friend class SBSymbolContext;
friend class SBTarget;

View File

@ -152,6 +152,16 @@ public:
lldb::SBBroadcaster
GetBroadcaster () const;
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It take no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
protected:
friend class SBAddress;
friend class SBBreakpoint;

View File

@ -55,6 +55,19 @@ public:
Clear ();
protected:
friend class SBAddress;
friend class SBBlock;
friend class SBBreakpoint;
friend class SBBreakpointLocation;
friend class SBCompileUnit;
friend class SBEvent;
friend class SBFrame;
friend class SBFunction;
friend class SBModule;
friend class SBSymbol;
friend class SBSymbolContext;
friend class SBTarget;
friend class SBThread;
#ifndef SWIG

View File

@ -40,6 +40,15 @@ public:
operator != (const lldb::SBSymbol &rhs) const;
#endif
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
private:
friend class SBSymbolContext;

View File

@ -71,6 +71,16 @@ protected:
void
SetSymbolContext (const lldb_private::SymbolContext *sc_ptr);
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
private:
std::auto_ptr<lldb_private::SymbolContext> m_opaque_ap;
};

View File

@ -142,6 +142,16 @@ public:
#endif
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
protected:
friend class SBAddress;
friend class SBDebugger;

View File

@ -88,6 +88,15 @@ public:
#endif
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
protected:
friend class SBBreakpoint;

View File

@ -54,6 +54,16 @@ public:
static bool
IsPointerType (void *opaque_type);
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It takes no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
protected:
void *m_ast;
void *m_type;

View File

@ -85,6 +85,15 @@ public:
bool
TypeIsPtrType ();
bool
GetDescription (lldb::SBStream &description);
// The following function gets called by Python when a user tries to print
// an object of this class. It take no arguments and returns a
// PyObject * representing a char * (and it must be named "__repr__");
PyObject *
__repr__ ();
protected:
friend class SBValueList;

View File

@ -184,6 +184,10 @@ public:
virtual void
DumpSymbolContext(Stream *s);
void
DumpAddressRanges (Stream *s,
lldb::addr_t base_addr);
void
GetDescription (Stream *s,
Function *function,

View File

@ -2974,6 +2974,7 @@
GCC_MODEL_TUNING = G5;
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_VERSION = 4.2;
HEADER_SEARCH_PATHS = /usr/include/python2.6;
INFOPLIST_FILE = "lldb-Info.plist";
INSTALL_PATH = /Developer/usr/bin;
LIBRARY_SEARCH_PATHS = "$(inherited)";
@ -3063,6 +3064,7 @@
GCC_OPTIMIZATION_LEVEL = 0;
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_VERSION = 4.2;
HEADER_SEARCH_PATHS = /usr/include/python2.6;
INFOPLIST_FILE = "lldb-Info.plist";
INSTALL_PATH = /Developer/usr/bin;
LIBRARY_SEARCH_PATHS = "$(inherited)";
@ -3102,6 +3104,7 @@
GCC_MODEL_TUNING = G5;
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_VERSION = 4.2;
HEADER_SEARCH_PATHS = /usr/include/python2.6;
INFOPLIST_FILE = "lldb-Info.plist";
INSTALL_PATH = /Developer/usr/bin;
LIBRARY_SEARCH_PATHS = "$(inherited)";

View File

@ -90,6 +90,7 @@
#include "lldb/API/SBModule.h"
#include "lldb/API/SBProcess.h"
#include "lldb/API/SBSourceManager.h"
#include "lldb/API/SBStream.h"
#include "lldb/API/SBStringList.h"
#include "lldb/API/SBSymbol.h"
#include "lldb/API/SBSymbolContext.h"
@ -143,6 +144,7 @@ typedef int StopReason;
%include "lldb/API/SBModule.h"
%include "lldb/API/SBProcess.h"
%include "lldb/API/SBSourceManager.h"
%include "lldb/API/SBStream.h"
%include "lldb/API/SBStringList.h"
%include "lldb/API/SBSymbol.h"
%include "lldb/API/SBSymbolContext.h"

View File

@ -9,6 +9,7 @@
#include "lldb/API/SBAddress.h"
#include "lldb/API/SBProcess.h"
#include "lldb/API/SBStream.h"
#include "lldb/Core/Address.h"
using namespace lldb;
@ -136,3 +137,24 @@ SBAddress::operator*() const
}
bool
SBAddress::GetDescription (SBStream &description)
{
if (m_opaque_ap.get())
{
m_opaque_ap->DumpDebug (description.get());
}
else
description.Printf ("No value");
return true;
}
PyObject *
SBAddress::__repr__ ()
{
SBStream description;
description.ref(); // Make sure it contains a valid StreamString.
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -9,8 +9,10 @@
#include "lldb/API/SBBlock.h"
#include "lldb/API/SBFileSpec.h"
#include "lldb/API/SBStream.h"
#include "lldb/Symbol/Block.h"
#include "lldb/Symbol/Function.h"
#include "lldb/Symbol/SymbolContext.h"
using namespace lldb;
using namespace lldb_private;
@ -132,4 +134,36 @@ SBBlock::GetFirstChild ()
}
bool
SBBlock::GetDescription (SBStream &description)
{
if (m_opaque_ptr)
{
lldb::user_id_t id = m_opaque_ptr->GetID();
description.Printf ("Block: {id: %d} ", id);
if (IsInlined())
{
description.Printf (" (inlined, '%s') ", GetInlinedName());
}
lldb_private::SymbolContext sc;
m_opaque_ptr->CalculateSymbolContext (&sc);
if (sc.function)
{
m_opaque_ptr->DumpAddressRanges (description.get(),
sc.function->GetAddressRange().GetBaseAddress().GetFileAddress());
}
}
else
description.Printf ("No value");
return true;
}
PyObject *
SBBlock::__repr__ ()
{
SBStream description;
description.ref();
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -12,6 +12,7 @@
#include "lldb/API/SBDebugger.h"
#include "lldb/API/SBEvent.h"
#include "lldb/API/SBProcess.h"
#include "lldb/API/SBStream.h"
#include "lldb/API/SBThread.h"
#include "lldb/Breakpoint/Breakpoint.h"
@ -321,12 +322,9 @@ SBBreakpoint::GetNumLocations() const
return 0;
}
void
SBBreakpoint::GetDescription (FILE *f, const char *description_level)
bool
SBBreakpoint::GetDescription (const char *description_level, SBStream &description)
{
if (f == NULL)
return;
if (m_opaque_sp)
{
DescriptionLevel level;
@ -339,11 +337,23 @@ SBBreakpoint::GetDescription (FILE *f, const char *description_level)
else
level = eDescriptionLevelBrief;
StreamFile str (f);
m_opaque_sp->GetDescription (&str, level);
str.EOL();
m_opaque_sp->GetDescription (description.get(), level);
description.get()->EOL();
}
else
description.Printf ("No value");
return true;
}
PyObject *
SBBreakpoint::__repr__ ()
{
SBStream description;
description.ref();
GetDescription ("full", description);
return PyString_FromString (description.GetData());
}
bool

View File

@ -7,9 +7,15 @@
//
//===----------------------------------------------------------------------===//
// In order to guarantee correct working with Python, Python.h *MUST* be
// the *FIRST* header file included:
#include <Python.h>
#include "lldb/API/SBBreakpointLocation.h"
#include "lldb/API/SBDefines.h"
#include "lldb/API/SBDebugger.h"
#include "lldb/API/SBStream.h"
#include "lldb/lldb-types.h"
#include "lldb/lldb-defines.h"
@ -191,12 +197,9 @@ SBBreakpointLocation::SetLocation (const lldb::BreakpointLocationSP &break_loc_s
m_opaque_sp = break_loc_sp;
}
void
SBBreakpointLocation::GetDescription (FILE *f, const char *description_level)
bool
SBBreakpointLocation::GetDescription (const char *description_level, SBStream &description)
{
if (f == NULL)
return;
if (m_opaque_sp)
{
DescriptionLevel level;
@ -209,11 +212,22 @@ SBBreakpointLocation::GetDescription (FILE *f, const char *description_level)
else
level = eDescriptionLevelBrief;
StreamFile str (f);
m_opaque_sp->GetDescription (&str, level);
str.EOL();
m_opaque_sp->GetDescription (description.get(), level);
description.get()->EOL();
}
else
description.Printf ("No value");
return true;
}
PyObject *
SBBreakpointLocation::__repr__ ()
{
SBStream description;
description.ref();
GetDescription ("full", description);
return PyString_FromString (description.GetData());
}
SBBreakpoint

View File

@ -7,9 +7,10 @@
//
//===----------------------------------------------------------------------===//
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/API/SBCommandReturnObject.h"
#include "lldb/API/SBStream.h"
#include "lldb/Interpreter/CommandReturnObject.h"
using namespace lldb;
using namespace lldb_private;
@ -160,3 +161,38 @@ SBCommandReturnObject::SetLLDBObjectPtr (CommandReturnObject *ptr)
m_opaque_ap.reset (ptr);
}
bool
SBCommandReturnObject::GetDescription (SBStream &description)
{
if (m_opaque_ap.get())
{
description.Printf ("Status: ");
lldb::ReturnStatus status = m_opaque_ap->GetStatus();
if (status == lldb::eReturnStatusStarted)
description.Printf ("Started");
else if (status == lldb::eReturnStatusInvalid)
description.Printf ("Invalid");
else if (m_opaque_ap->Succeeded())
description.Printf ("Success");
else
description.Printf ("Fail");
if (GetOutputSize() > 0)
description.Printf ("\nOutput Message:\n%s", GetOutput());
if (GetErrorSize() > 0)
description.Printf ("\nError Message:\n%s", GetError());
}
else
description.Printf ("No value");
return true;
}
PyObject *
SBCommandReturnObject::__repr__ ()
{
SBStream description;
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -9,6 +9,7 @@
#include "lldb/API/SBCompileUnit.h"
#include "lldb/API/SBLineEntry.h"
#include "lldb/API/SBStream.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/LineEntry.h"
#include "lldb/Symbol/LineTable.h"
@ -118,3 +119,25 @@ SBCompileUnit::operator*() const
{
return *m_opaque_ptr;
}
bool
SBCompileUnit::GetDescription (SBStream &description)
{
if (m_opaque_ptr)
{
m_opaque_ptr->Dump (description.get(), false);
}
else
description.Printf ("No Value");
return true;
}
PyObject *
SBCompileUnit::__repr__ ()
{
SBStream description;
description.ref();
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -25,6 +25,7 @@
#include "lldb/API/SBInputReader.h"
#include "lldb/API/SBProcess.h"
#include "lldb/API/SBSourceManager.h"
#include "lldb/API/SBStream.h"
#include "lldb/API/SBStringList.h"
#include "lldb/API/SBTarget.h"
#include "lldb/API/SBThread.h"
@ -669,3 +670,26 @@ SBDebugger::UseExternalEditor ()
return false;
}
bool
SBDebugger::GetDescription (SBStream &description)
{
if (m_opaque_sp)
{
const char *name = m_opaque_sp->GetInstanceName().AsCString();
lldb::user_id_t id = m_opaque_sp->GetID();
description.Printf ("Debugger (instance: '%s', id: %d)", name, id);
}
else
description.Printf ("No value");
return true;
}
PyObject *
SBDebugger::__repr__ ()
{
SBStream description;
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -8,7 +8,9 @@
//===----------------------------------------------------------------------===//
#include "lldb/API/SBError.h"
#include "lldb/API/SBStream.h"
#include "lldb/Core/Error.h"
#include <stdarg.h>
using namespace lldb;
@ -178,3 +180,29 @@ SBError::operator*() const
return *m_opaque_ap;
}
bool
SBError::GetDescription (SBStream &description)
{
if (m_opaque_ap.get())
{
if (Success())
description.Printf ("Status: Success");
else
{
const char * err_string = GetCString();
description.Printf ("Status: Error: %s", (err_string != NULL ? err_string : ""));
}
}
else
description.Printf ("No value");
return true;
}
PyObject *
SBError::__repr__ ()
{
SBStream description;
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -9,6 +9,7 @@
#include "lldb/API/SBEvent.h"
#include "lldb/API/SBBroadcaster.h"
#include "lldb/API/SBStream.h"
#include "lldb/Core/Event.h"
#include "lldb/Core/Stream.h"
@ -150,3 +151,24 @@ SBEvent::GetCStringFromEvent (const SBEvent &event)
}
bool
SBEvent::GetDescription (SBStream &description)
{
if (m_opaque)
{
m_opaque->Dump (description.get());
}
else
description.Printf ("No value");
return true;
}
PyObject *
SBEvent::__repr__ ()
{
SBStream description;
description.ref();
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "lldb/API/SBFileSpec.h"
#include "lldb/API/SBStream.h"
#include "lldb/Core/FileSpec.h"
using namespace lldb;
@ -138,3 +139,30 @@ SBFileSpec::SetFileSpec (const lldb_private::FileSpec& fs)
m_opaque_ap.reset (new FileSpec (fs));
}
bool
SBFileSpec::GetDescription (SBStream &description)
{
if (m_opaque_ap.get())
{
const char *filename = GetFilename();
const char *dir_name = GetDirectory();
if (!filename && !dir_name)
description.Printf ("No value");
else if (!dir_name)
description.Printf ("%s", filename);
else
description.Printf ("%s/%s", dir_name, filename);
}
else
description.Printf ("No value");
return true;
}
PyObject *
SBFileSpec::__repr__ ()
{
SBStream description;
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -34,6 +34,7 @@
#include "lldb/API/SBDebugger.h"
#include "lldb/API/SBValue.h"
#include "lldb/API/SBAddress.h"
#include "lldb/API/SBStream.h"
#include "lldb/API/SBSymbolContext.h"
#include "lldb/API/SBThread.h"
@ -203,7 +204,13 @@ SBFrame::LookupVar (const char *var_name)
if (!found)
var_sp.reset();
}
SBValue sb_value (ValueObjectSP (new ValueObjectVariable (var_sp)));
if (var_sp)
{
SBValue sb_value (ValueObjectSP (new ValueObjectVariable (var_sp)));
return sb_value;
}
SBValue sb_value;
return sb_value;
}
@ -249,7 +256,14 @@ SBFrame::LookupVarInScope (const char *var_name, const char *scope)
var_sp.reset();
}
}
SBValue sb_value (ValueObjectSP (new ValueObjectVariable (var_sp)));
if (var_sp)
{
SBValue sb_value (ValueObjectSP (new ValueObjectVariable (var_sp)));
return sb_value;
}
SBValue sb_value;
return sb_value;
}
@ -375,3 +389,24 @@ SBFrame::GetRegisters ()
return value_list;
}
bool
SBFrame::GetDescription (SBStream &description)
{
if (m_opaque_sp)
{
m_opaque_sp->Dump (description.get(), true, false);
}
else
description.Printf ("No value");
return true;
}
PyObject *
SBFrame::__repr__ ()
{
SBStream description;
description.ref();
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -9,6 +9,7 @@
#include "lldb/API/SBFunction.h"
#include "lldb/API/SBProcess.h"
#include "lldb/API/SBStream.h"
#include "lldb/Symbol/Function.h"
using namespace lldb;
@ -62,3 +63,25 @@ SBFunction::operator != (const SBFunction &rhs) const
{
return m_opaque_ptr != rhs.m_opaque_ptr;
}
bool
SBFunction::GetDescription (SBStream &description)
{
if (m_opaque_ptr)
{
m_opaque_ptr->Dump (description.get(), false);
}
else
description.Printf ("No value");
return true;
}
PyObject *
SBFunction::__repr__ ()
{
SBStream description;
description.ref();
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "lldb/API/SBLineEntry.h"
#include "lldb/API/SBStream.h"
#include "lldb/Symbol/LineEntry.h"
using namespace lldb;
@ -152,7 +153,30 @@ SBLineEntry::operator*() const
return *m_opaque_ap;
}
bool
SBLineEntry::GetDescription (SBStream &description)
{
if (m_opaque_ap.get())
{
// Line entry: File, line x {, column y}: Addresses: <start_addr> - <end_addr>
char file_path[PATH_MAX*2];
m_opaque_ap->file.GetPath (file_path, sizeof (file_path));
description.Printf ("Line entry: %s, line %d", file_path, GetLine());
if (GetColumn() > 0)
description.Printf (", column %d", GetColumn());
description.Printf (": Addresses: 0x%p - 0x%p", GetStartAddress().GetFileAddress() ,
GetEndAddress().GetFileAddress());
}
else
description.Printf ("No value");
return true;
}
PyObject *
SBLineEntry::__repr__ ()
{
SBStream description;
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -11,6 +11,7 @@
#include "lldb/API/SBAddress.h"
#include "lldb/API/SBFileSpec.h"
#include "lldb/API/SBFileSpec.h"
#include "lldb/API/SBStream.h"
#include "lldb/Core/Module.h"
using namespace lldb;
@ -127,3 +128,24 @@ SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolv
return sb_sc;
}
bool
SBModule::GetDescription (SBStream &description)
{
if (m_opaque_sp)
{
m_opaque_sp->Dump (description.get());
}
else
description.Printf ("No value");
return true;
}
PyObject *
SBModule::__repr__ ()
{
SBStream description;
description.ref();
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -30,6 +30,7 @@
#include "lldb/API/SBCommandReturnObject.h"
#include "lldb/API/SBEvent.h"
#include "lldb/API/SBThread.h"
#include "lldb/API/SBStream.h"
#include "lldb/API/SBStringList.h"
using namespace lldb;
@ -466,3 +467,29 @@ SBProcess::get() const
return m_opaque_sp.get();
}
bool
SBProcess::GetDescription (SBStream &description)
{
if (m_opaque_sp)
{
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(),
SBDebugger::StateAsCString (GetState()),
GetNumThreads());
}
else
description.Printf ("No value");
return true;
}
PyObject *
SBProcess::__repr__ ()
{
SBStream description;
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "lldb/API/SBSymbol.h"
#include "lldb/API/SBStream.h"
#include "lldb/Symbol/Symbol.h"
using namespace lldb;
@ -62,3 +63,25 @@ SBSymbol::operator != (const SBSymbol &rhs) const
{
return m_opaque_ptr != rhs.m_opaque_ptr;
}
bool
SBSymbol::GetDescription (SBStream &description)
{
if (m_opaque_ptr)
{
m_opaque_ptr->GetDescription (description.get(), lldb::eDescriptionLevelFull, NULL);
}
else
description.Printf ("No value");
return true;
}
PyObject *
SBSymbol::__repr__ ()
{
SBStream description;
description.ref();
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "lldb/API/SBSymbolContext.h"
#include "lldb/API/SBStream.h"
#include "lldb/Symbol/SymbolContext.h"
using namespace lldb;
@ -146,5 +147,24 @@ SBSymbolContext::get() const
return m_opaque_ap.get();
}
bool
SBSymbolContext::GetDescription (SBStream &description)
{
if (m_opaque_ap.get())
{
m_opaque_ap->GetDescription (description.get(), lldb::eDescriptionLevelFull, NULL);
}
else
description.Printf ("No value");
return true;
}
PyObject *
SBSymbolContext::__repr__ ()
{
SBStream description;
description.ref();
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -13,6 +13,7 @@
#include "lldb/API/SBFileSpec.h"
#include "lldb/API/SBModule.h"
#include "lldb/API/SBStream.h"
#include "lldb/Breakpoint/BreakpointID.h"
#include "lldb/Breakpoint/BreakpointIDList.h"
#include "lldb/Breakpoint/BreakpointList.h"
@ -500,3 +501,25 @@ SBTarget::Disassemble (const char *function_name, const char *module_name)
out_stream);
}
}
bool
SBTarget::GetDescription (SBStream &description)
{
if (m_opaque_sp)
{
m_opaque_sp->Dump (description.get());
}
else
description.Printf ("No value");
return true;
}
PyObject *
SBTarget::__repr__ ()
{
SBStream description;
description.ref();
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -11,6 +11,7 @@
#include "lldb/API/SBSymbolContext.h"
#include "lldb/API/SBFileSpec.h"
#include "lldb/API/SBStream.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/Stream.h"
#include "lldb/Core/StreamFile.h"
@ -412,3 +413,26 @@ SBThread::operator*()
{
return *m_opaque_sp;
}
bool
SBThread::GetDescription (SBStream &description)
{
if (m_opaque_sp)
{
m_opaque_sp->DumpInfo (description.ref(), true, true, true, LLDB_INVALID_INDEX32);
description.Printf (" %d frames, (instance name: %s)", GetNumFrames(),
m_opaque_sp->GetInstanceName().AsCString());
}
else
description.Printf ("No value");
return true;
}
PyObject *
SBThread::__repr__ ()
{
SBStream description;
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "lldb/API/SBType.h"
#include "lldb/API/SBStream.h"
#include "lldb/Core/ConstString.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/ClangASTType.h"
@ -144,6 +145,53 @@ SBType::GetPointeeType ()
return SBType (pointee_type ? m_ast : NULL, pointee_type);
}
bool
SBType::GetDescription (SBStream &description)
{
const char *name = GetName();
uint64_t byte_size = GetByteSize();
uint64_t num_children = GetNumberChildren (true);
bool is_ptr = IsPointerType ();
description.Printf ("type_name: %s, size: %d bytes", (name != NULL ? name : "<unknown type name>"), byte_size);
if (is_ptr)
{
SBType pointee_type = GetPointeeType();
const char *pointee_name = pointee_type.GetName();
description.Printf (", (* %s)", (pointee_name != NULL ? pointee_name : "<unknown type name>"));
}
else if (num_children > 0)
{
description.Printf (", %d members:\n", num_children);
for (uint32_t i = 0; i < num_children; ++i)
{
SBTypeMember field;
GetChildAtIndex (true, i, field);
const char *field_name = field.GetName();
SBType field_type = field.GetType();
const char *field_type_name = field_type.GetName();
description.Printf (" %s (type: %s", (field_name != NULL ? field_name : "<unknown member name>"),
(field_type_name != NULL ? field_type_name : "<unknown type name>"));
if (field.IsBitfield())
{
size_t width = field.GetBitfieldWidth ();
description.Printf (" , %d bits", (int) width);
}
description.Printf (")\n");
}
}
return true;
}
PyObject *
SBType::__repr__ ()
{
SBStream description;
GetDescription (description);
return PyString_FromString (description.GetData());
}
SBTypeMember::SBTypeMember () :
m_ast (NULL),

View File

@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "lldb/API/SBValue.h"
#include "lldb/API/SBStream.h"
#include "lldb/Core/DataExtractor.h"
#include "lldb/Core/Module.h"
@ -268,3 +269,35 @@ SBValue::operator*() const
{
return m_opaque_sp;
}
bool
SBValue::GetDescription (SBStream &description)
{
if (m_opaque_sp)
{
const char *name = GetName();
const char *type_name = GetTypeName ();
size_t byte_size = GetByteSize ();
uint32_t num_children = GetNumChildren ();
bool is_stale = ValueIsStale ();
description.Printf ("name: '%s', type: %s, size: %d", (name != NULL ? name : "<unknown name>"),
(type_name != NULL ? type_name : "<unknown type name>"), (int) byte_size);
if (num_children > 0)
description.Printf (", num_children: %d", num_children);
if (is_stale)
description.Printf (" [value is stale]");
}
else
description.Printf ("No value");
return true;
}
PyObject *
SBValue::__repr__ ()
{
SBStream description;
GetDescription (description);
return PyString_FromString (description.GetData());
}

View File

@ -236,6 +236,17 @@ Block::DumpSymbolContext(Stream *s)
s->Printf(", Block{0x%8.8x}", GetID());
}
void
Block::DumpAddressRanges (Stream *s, lldb::addr_t base_addr)
{
if (!m_ranges.empty())
{
std::vector<VMRange>::const_iterator pos, end = m_ranges.end();
for (pos = m_ranges.begin(); pos != end; ++pos)
pos->Dump (s, base_addr);
}
}
bool
Block::Contains (addr_t range_offset) const
{