diff options
| author | Caroline Tice <ctice@apple.com> | 2010-09-20 05:20:02 +0000 |
|---|---|---|
| committer | Caroline Tice <ctice@apple.com> | 2010-09-20 05:20:02 +0000 |
| commit | dde9cff32aee03e98a5ed91fc8425f241058c771 (patch) | |
| tree | d207dc97f063865b8addf9c4b01d6cbed2386f9e /lldb/source/API/SBValue.cpp | |
| parent | fd02aa84dc5e5b96e44e1f93b4f57b206e6180b2 (diff) | |
| download | bcm5719-llvm-dde9cff32aee03e98a5ed91fc8425f241058c771.tar.gz bcm5719-llvm-dde9cff32aee03e98a5ed91fc8425f241058c771.zip | |
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
Diffstat (limited to 'lldb/source/API/SBValue.cpp')
| -rw-r--r-- | lldb/source/API/SBValue.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp index e9d970baf34..e2fdffab592 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 : "<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()); +} |

