diff --git a/lldb/include/lldb/API/SBAddress.h b/lldb/include/lldb/API/SBAddress.h index 9032d2046a38..d9d4ace706b6 100644 --- a/lldb/include/lldb/API/SBAddress.h +++ b/lldb/include/lldb/API/SBAddress.h @@ -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; diff --git a/lldb/include/lldb/API/SBBlock.h b/lldb/include/lldb/API/SBBlock.h index efab6429561d..c49c9a17a954 100644 --- a/lldb/include/lldb/API/SBBlock.h +++ b/lldb/include/lldb/API/SBBlock.h @@ -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; diff --git a/lldb/include/lldb/API/SBBreakpoint.h b/lldb/include/lldb/API/SBBreakpoint.h index de2d478ca8fd..b24515b6adca 100644 --- a/lldb/include/lldb/API/SBBreakpoint.h +++ b/lldb/include/lldb/API/SBBreakpoint.h @@ -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; diff --git a/lldb/include/lldb/API/SBBreakpointLocation.h b/lldb/include/lldb/API/SBBreakpointLocation.h index fc866546f6ce..32e83f245bd2 100644 --- a/lldb/include/lldb/API/SBBreakpointLocation.h +++ b/lldb/include/lldb/API/SBBreakpointLocation.h @@ -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; diff --git a/lldb/include/lldb/API/SBCommandReturnObject.h b/lldb/include/lldb/API/SBCommandReturnObject.h index 6ce8bfbee9e9..5d52dc1c2116 100644 --- a/lldb/include/lldb/API/SBCommandReturnObject.h +++ b/lldb/include/lldb/API/SBCommandReturnObject.h @@ -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; diff --git a/lldb/include/lldb/API/SBCompileUnit.h b/lldb/include/lldb/API/SBCompileUnit.h index 43be8192ea3b..5c7d6a45f288 100644 --- a/lldb/include/lldb/API/SBCompileUnit.h +++ b/lldb/include/lldb/API/SBCompileUnit.h @@ -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; diff --git a/lldb/include/lldb/API/SBDebugger.h b/lldb/include/lldb/API/SBDebugger.h index ff14931fd9c8..3f119073e5d1 100644 --- a/lldb/include/lldb/API/SBDebugger.h +++ b/lldb/include/lldb/API/SBDebugger.h @@ -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; diff --git a/lldb/include/lldb/API/SBDefines.h b/lldb/include/lldb/API/SBDefines.h index 703b111b7408..3a2ad79b704a 100644 --- a/lldb/include/lldb/API/SBDefines.h +++ b/lldb/include/lldb/API/SBDefines.h @@ -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 + // 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; diff --git a/lldb/include/lldb/API/SBError.h b/lldb/include/lldb/API/SBError.h index 12a4de1b1efd..3fedd13ff87c 100644 --- a/lldb/include/lldb/API/SBError.h +++ b/lldb/include/lldb/API/SBError.h @@ -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; diff --git a/lldb/include/lldb/API/SBEvent.h b/lldb/include/lldb/API/SBEvent.h index 0ae23dde1cd9..9f6a425058c3 100644 --- a/lldb/include/lldb/API/SBEvent.h +++ b/lldb/include/lldb/API/SBEvent.h @@ -10,10 +10,11 @@ #ifndef LLDB_SBEvent_h_ #define LLDB_SBEvent_h_ +#include "lldb/API/SBDefines.h" + #include #include -#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; diff --git a/lldb/include/lldb/API/SBFileSpec.h b/lldb/include/lldb/API/SBFileSpec.h index ffbeba87a81f..fa8564df2b2c 100644 --- a/lldb/include/lldb/API/SBFileSpec.h +++ b/lldb/include/lldb/API/SBFileSpec.h @@ -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; diff --git a/lldb/include/lldb/API/SBFrame.h b/lldb/include/lldb/API/SBFrame.h index edafcfb97f8c..ae12452e6f3a 100644 --- a/lldb/include/lldb/API/SBFrame.h +++ b/lldb/include/lldb/API/SBFrame.h @@ -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; diff --git a/lldb/include/lldb/API/SBFunction.h b/lldb/include/lldb/API/SBFunction.h index 6f4a90a2dcde..4e7ae8081a43 100644 --- a/lldb/include/lldb/API/SBFunction.h +++ b/lldb/include/lldb/API/SBFunction.h @@ -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; diff --git a/lldb/include/lldb/API/SBInstruction.h b/lldb/include/lldb/API/SBInstruction.h index 4d3af965bc1b..0461ce34e420 100644 --- a/lldb/include/lldb/API/SBInstruction.h +++ b/lldb/include/lldb/API/SBInstruction.h @@ -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; diff --git a/lldb/include/lldb/API/SBLineEntry.h b/lldb/include/lldb/API/SBLineEntry.h index 68fba3e19e44..619884ed3100 100644 --- a/lldb/include/lldb/API/SBLineEntry.h +++ b/lldb/include/lldb/API/SBLineEntry.h @@ -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; diff --git a/lldb/include/lldb/API/SBModule.h b/lldb/include/lldb/API/SBModule.h index 559e94bd26b5..6231d13a319b 100644 --- a/lldb/include/lldb/API/SBModule.h +++ b/lldb/include/lldb/API/SBModule.h @@ -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; diff --git a/lldb/include/lldb/API/SBProcess.h b/lldb/include/lldb/API/SBProcess.h index 98962717d08d..3543ee1e9e80 100644 --- a/lldb/include/lldb/API/SBProcess.h +++ b/lldb/include/lldb/API/SBProcess.h @@ -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; diff --git a/lldb/include/lldb/API/SBStream.h b/lldb/include/lldb/API/SBStream.h index abc4afdd0389..6c46c1a0482d 100644 --- a/lldb/include/lldb/API/SBStream.h +++ b/lldb/include/lldb/API/SBStream.h @@ -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 diff --git a/lldb/include/lldb/API/SBSymbol.h b/lldb/include/lldb/API/SBSymbol.h index f939bfa4aa71..a51cb424c62c 100644 --- a/lldb/include/lldb/API/SBSymbol.h +++ b/lldb/include/lldb/API/SBSymbol.h @@ -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; diff --git a/lldb/include/lldb/API/SBSymbolContext.h b/lldb/include/lldb/API/SBSymbolContext.h index db6555e082fc..659683f91483 100644 --- a/lldb/include/lldb/API/SBSymbolContext.h +++ b/lldb/include/lldb/API/SBSymbolContext.h @@ -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 m_opaque_ap; }; diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h index 97ddcccd039f..1b4c09ab38c1 100644 --- a/lldb/include/lldb/API/SBTarget.h +++ b/lldb/include/lldb/API/SBTarget.h @@ -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; diff --git a/lldb/include/lldb/API/SBThread.h b/lldb/include/lldb/API/SBThread.h index 2a9dd2a4dcca..ead395ae5290 100644 --- a/lldb/include/lldb/API/SBThread.h +++ b/lldb/include/lldb/API/SBThread.h @@ -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; diff --git a/lldb/include/lldb/API/SBType.h b/lldb/include/lldb/API/SBType.h index 0008c487f7c8..c745989364b8 100644 --- a/lldb/include/lldb/API/SBType.h +++ b/lldb/include/lldb/API/SBType.h @@ -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; diff --git a/lldb/include/lldb/API/SBValue.h b/lldb/include/lldb/API/SBValue.h index 2c817fff53f6..78b4ea9bbf04 100644 --- a/lldb/include/lldb/API/SBValue.h +++ b/lldb/include/lldb/API/SBValue.h @@ -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; diff --git a/lldb/include/lldb/Symbol/Block.h b/lldb/include/lldb/Symbol/Block.h index 53fb741dae0f..ff1d503b294d 100644 --- a/lldb/include/lldb/Symbol/Block.h +++ b/lldb/include/lldb/Symbol/Block.h @@ -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, diff --git a/lldb/lldb.xcodeproj/project.pbxproj b/lldb/lldb.xcodeproj/project.pbxproj index b491e4224893..23839b5ff4d7 100644 --- a/lldb/lldb.xcodeproj/project.pbxproj +++ b/lldb/lldb.xcodeproj/project.pbxproj @@ -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)"; diff --git a/lldb/scripts/lldb.swig b/lldb/scripts/lldb.swig index 32b387e089e7..adaa09484e8b 100644 --- a/lldb/scripts/lldb.swig +++ b/lldb/scripts/lldb.swig @@ -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" diff --git a/lldb/source/API/SBAddress.cpp b/lldb/source/API/SBAddress.cpp index 61e1ec1524f2..bcf387f709fe 100644 --- a/lldb/source/API/SBAddress.cpp +++ b/lldb/source/API/SBAddress.cpp @@ -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()); +} diff --git a/lldb/source/API/SBBlock.cpp b/lldb/source/API/SBBlock.cpp index 961e8d84663d..5d6172b6122a 100644 --- a/lldb/source/API/SBBlock.cpp +++ b/lldb/source/API/SBBlock.cpp @@ -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()); +} diff --git a/lldb/source/API/SBBreakpoint.cpp b/lldb/source/API/SBBreakpoint.cpp index 1e3c71238267..aa84575be2e9 100644 --- a/lldb/source/API/SBBreakpoint.cpp +++ b/lldb/source/API/SBBreakpoint.cpp @@ -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 diff --git a/lldb/source/API/SBBreakpointLocation.cpp b/lldb/source/API/SBBreakpointLocation.cpp index 948b78f0c29a..f7e059ba9677 100644 --- a/lldb/source/API/SBBreakpointLocation.cpp +++ b/lldb/source/API/SBBreakpointLocation.cpp @@ -7,9 +7,15 @@ // //===----------------------------------------------------------------------===// +// In order to guarantee correct working with Python, Python.h *MUST* be +// the *FIRST* header file included: + +#include + #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 diff --git a/lldb/source/API/SBCommandReturnObject.cpp b/lldb/source/API/SBCommandReturnObject.cpp index 5742c5c93da6..458ce504e3d3 100644 --- a/lldb/source/API/SBCommandReturnObject.cpp +++ b/lldb/source/API/SBCommandReturnObject.cpp @@ -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()); +} diff --git a/lldb/source/API/SBCompileUnit.cpp b/lldb/source/API/SBCompileUnit.cpp index dc873e365359..24a686d889e1 100644 --- a/lldb/source/API/SBCompileUnit.cpp +++ b/lldb/source/API/SBCompileUnit.cpp @@ -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()); +} diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp index 0f12890aa384..acf98dd8fa1b 100644 --- a/lldb/source/API/SBDebugger.cpp +++ b/lldb/source/API/SBDebugger.cpp @@ -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()); +} diff --git a/lldb/source/API/SBError.cpp b/lldb/source/API/SBError.cpp index e91c94d2c8fc..136561981b6e 100644 --- a/lldb/source/API/SBError.cpp +++ b/lldb/source/API/SBError.cpp @@ -8,7 +8,9 @@ //===----------------------------------------------------------------------===// #include "lldb/API/SBError.h" +#include "lldb/API/SBStream.h" #include "lldb/Core/Error.h" + #include 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()); +} diff --git a/lldb/source/API/SBEvent.cpp b/lldb/source/API/SBEvent.cpp index 543383b1ade5..0799b8bad57a 100644 --- a/lldb/source/API/SBEvent.cpp +++ b/lldb/source/API/SBEvent.cpp @@ -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()); +} diff --git a/lldb/source/API/SBFileSpec.cpp b/lldb/source/API/SBFileSpec.cpp index 5ec93f3b4fff..1edd9468b505 100644 --- a/lldb/source/API/SBFileSpec.cpp +++ b/lldb/source/API/SBFileSpec.cpp @@ -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()); +} diff --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp index 5d9bd6e016f9..90952691df0e 100644 --- a/lldb/source/API/SBFrame.cpp +++ b/lldb/source/API/SBFrame.cpp @@ -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()); +} diff --git a/lldb/source/API/SBFunction.cpp b/lldb/source/API/SBFunction.cpp index c4beff1a14e2..210340ef2498 100644 --- a/lldb/source/API/SBFunction.cpp +++ b/lldb/source/API/SBFunction.cpp @@ -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()); +} diff --git a/lldb/source/API/SBLineEntry.cpp b/lldb/source/API/SBLineEntry.cpp index a35f94a8b541..27f01d5a2da9 100644 --- a/lldb/source/API/SBLineEntry.cpp +++ b/lldb/source/API/SBLineEntry.cpp @@ -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: - + 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()); +} diff --git a/lldb/source/API/SBModule.cpp b/lldb/source/API/SBModule.cpp index e338101c4e9f..a0b340a9cb7d 100644 --- a/lldb/source/API/SBModule.cpp +++ b/lldb/source/API/SBModule.cpp @@ -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()); +} diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp index 0cae975de40c..d2c85ba90312 100644 --- a/lldb/source/API/SBProcess.cpp +++ b/lldb/source/API/SBProcess.cpp @@ -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()); +} diff --git a/lldb/source/API/SBSymbol.cpp b/lldb/source/API/SBSymbol.cpp index 502efaa09dce..3c700e170354 100644 --- a/lldb/source/API/SBSymbol.cpp +++ b/lldb/source/API/SBSymbol.cpp @@ -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()); +} diff --git a/lldb/source/API/SBSymbolContext.cpp b/lldb/source/API/SBSymbolContext.cpp index 1c2b52c6a7da..4381994c70f1 100644 --- a/lldb/source/API/SBSymbolContext.cpp +++ b/lldb/source/API/SBSymbolContext.cpp @@ -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()); +} diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index 9e5c1ab27d5a..f779c33b89de 100644 --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -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()); +} diff --git a/lldb/source/API/SBThread.cpp b/lldb/source/API/SBThread.cpp index 3c75e4d682a1..aa621fb13c03 100644 --- a/lldb/source/API/SBThread.cpp +++ b/lldb/source/API/SBThread.cpp @@ -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()); +} diff --git a/lldb/source/API/SBType.cpp b/lldb/source/API/SBType.cpp index 1a44633d16b8..d34e94a14607 100644 --- a/lldb/source/API/SBType.cpp +++ b/lldb/source/API/SBType.cpp @@ -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 : ""), byte_size); + if (is_ptr) + { + SBType pointee_type = GetPointeeType(); + const char *pointee_name = pointee_type.GetName(); + description.Printf (", (* %s)", (pointee_name != NULL ? pointee_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 : ""), + (field_type_name != NULL ? field_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), diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp index e9d970baf349..e2fdffab5929 100644 --- a/lldb/source/API/SBValue.cpp +++ b/lldb/source/API/SBValue.cpp @@ -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 : ""), + (type_name != NULL ? 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()); +} diff --git a/lldb/source/Symbol/Block.cpp b/lldb/source/Symbol/Block.cpp index a2193891cf70..1731bf46634e 100644 --- a/lldb/source/Symbol/Block.cpp +++ b/lldb/source/Symbol/Block.cpp @@ -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::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 {