diff options
author | emaste <emaste@FreeBSD.org> | 2015-07-04 01:02:43 +0000 |
---|---|---|
committer | emaste <emaste@FreeBSD.org> | 2015-07-04 01:02:43 +0000 |
commit | cea4c167517a0678c7dbf92a0324088dcbac1035 (patch) | |
tree | 02de7f7c9d5a08ae1c4d3b4c98a565ff96cd52e6 /contrib/llvm/tools/lldb/source/Interpreter/PythonDataObjects.cpp | |
parent | 1756896fd2b99ede7ebeb8019d4004bdfeed3bbe (diff) | |
parent | 8037fa4ee916fa20b3c63cbf531f4ee7e1c76138 (diff) | |
download | FreeBSD-src-cea4c167517a0678c7dbf92a0324088dcbac1035.zip FreeBSD-src-cea4c167517a0678c7dbf92a0324088dcbac1035.tar.gz |
Update LLDB snapshot to upstream r241361
Notable upstream commits (upstream revision in parens):
- Add a JSON producer to LLDB (228636)
- Don't crash on bad DWARF expression (228729)
- Add support of DWARFv3 DW_OP_form_tls_address (231342)
- Assembly profiler for MIPS64 (232619)
- Handle FreeBSD/arm64 core files (233273)
- Read/Write register for MIPS64 (233685)
- Rework LLDB system initialization (233758)
- SysV ABI for aarch64 (236098)
- MIPS software single stepping (236696)
- FreeBSD/arm live debugging support (237303)
- Assembly profiler for mips32 (237420)
- Parse function name from DWARF DW_AT_abstract_origin (238307)
- Improve LLDB prompt handling (238313)
- Add real time signals support to FreeBSDSignals (238316)
- Fix race in IOHandlerProcessSTDIO (238423)
- MIPS64 Branch instruction emulation for SW single stepping (238820)
- Improve OSType initialization in elf object file's arch_spec (239148)
- Emulation of MIPS64 floating-point branch instructions (239996)
- ABI Plugin for MIPS32 (239997)
- ABI Plugin for MIPS64 (240123)
- MIPS32 branch emulation and single stepping (240373)
- Improve instruction emulation based stack unwinding on ARM (240533)
- Add branch emulation to aarch64 instruction emulator (240769)
Diffstat (limited to 'contrib/llvm/tools/lldb/source/Interpreter/PythonDataObjects.cpp')
-rw-r--r-- | contrib/llvm/tools/lldb/source/Interpreter/PythonDataObjects.cpp | 143 |
1 files changed, 102 insertions, 41 deletions
diff --git a/contrib/llvm/tools/lldb/source/Interpreter/PythonDataObjects.cpp b/contrib/llvm/tools/lldb/source/Interpreter/PythonDataObjects.cpp index 3ea6c0d..a581a0b 100644 --- a/contrib/llvm/tools/lldb/source/Interpreter/PythonDataObjects.cpp +++ b/contrib/llvm/tools/lldb/source/Interpreter/PythonDataObjects.cpp @@ -23,19 +23,20 @@ #include "lldb/Host/File.h" #include "lldb/Interpreter/PythonDataObjects.h" #include "lldb/Interpreter/ScriptInterpreter.h" +#include "lldb/Interpreter/ScriptInterpreterPython.h" using namespace lldb_private; using namespace lldb; +void +StructuredPythonObject::Dump(Stream &s) const +{ + s << "Python Obj: 0x" << GetValue(); +} + //---------------------------------------------------------------------- // PythonObject //---------------------------------------------------------------------- -PythonObject::PythonObject (const lldb::ScriptInterpreterObjectSP &script_object_sp) : - m_py_obj (nullptr) -{ - if (script_object_sp) - Reset ((PyObject *)script_object_sp->GetObject()); -} void PythonObject::Dump (Stream &strm) const @@ -62,6 +63,23 @@ PythonObject::Dump (Stream &strm) const strm.PutCString ("NULL"); } +PyObjectType +PythonObject::GetObjectType() const +{ + if (IsNULLOrNone()) + return PyObjectType::None; + + if (PyList_Check(m_py_obj)) + return PyObjectType::List; + if (PyDict_Check(m_py_obj)) + return PyObjectType::Dictionary; + if (PyString_Check(m_py_obj)) + return PyObjectType::String; + if (PyInt_Check(m_py_obj) || PyLong_Check(m_py_obj)) + return PyObjectType::Integer; + return PyObjectType::Unknown; +} + PythonString PythonObject::Repr () { @@ -90,6 +108,26 @@ PythonObject::IsNULLOrNone () const return ((m_py_obj == nullptr) || (m_py_obj == Py_None)); } +StructuredData::ObjectSP +PythonObject::CreateStructuredObject() const +{ + switch (GetObjectType()) + { + case PyObjectType::Dictionary: + return PythonDictionary(m_py_obj).CreateStructuredDictionary(); + case PyObjectType::Integer: + return PythonInteger(m_py_obj).CreateStructuredInteger(); + case PyObjectType::List: + return PythonList(m_py_obj).CreateStructuredArray(); + case PyObjectType::String: + return PythonString(m_py_obj).CreateStructuredString(); + case PyObjectType::None: + return StructuredData::ObjectSP(); + default: + return StructuredData::ObjectSP(new StructuredPythonObject(m_py_obj)); + } +} + //---------------------------------------------------------------------- // PythonString //---------------------------------------------------------------------- @@ -106,14 +144,12 @@ PythonString::PythonString (const PythonObject &object) : Reset(object.get()); // Use "Reset()" to ensure that py_obj is a string } -PythonString::PythonString (const lldb::ScriptInterpreterObjectSP &script_object_sp) : - PythonObject() +PythonString::PythonString (llvm::StringRef string) : + PythonObject(PyString_FromStringAndSize(string.data(), string.size())) { - if (script_object_sp) - Reset((PyObject *)script_object_sp->GetObject()); // Use "Reset()" to ensure that py_obj is a string } -PythonString::PythonString (const char* string) : +PythonString::PythonString(const char *string) : PythonObject(PyString_FromString(string)) { } @@ -137,12 +173,12 @@ PythonString::Reset (PyObject *py_obj) return py_obj == nullptr; } -const char* +llvm::StringRef PythonString::GetString() const { if (m_py_obj) - return PyString_AsString(m_py_obj); - return nullptr; + return llvm::StringRef(PyString_AsString(m_py_obj), GetSize()); + return llvm::StringRef(); } size_t @@ -154,9 +190,17 @@ PythonString::GetSize() const } void -PythonString::SetString (const char* string) +PythonString::SetString (llvm::StringRef string) { - PythonObject::Reset(PyString_FromString(string)); + PythonObject::Reset(PyString_FromStringAndSize(string.data(), string.size())); +} + +StructuredData::StringSP +PythonString::CreateStructuredString() const +{ + StructuredData::StringSP result(new StructuredData::String); + result->SetValue(GetString()); + return result; } //---------------------------------------------------------------------- @@ -175,13 +219,6 @@ PythonInteger::PythonInteger (const PythonObject &object) : Reset(object.get()); // Use "Reset()" to ensure that py_obj is a integer type } -PythonInteger::PythonInteger (const lldb::ScriptInterpreterObjectSP &script_object_sp) : - PythonObject() -{ - if (script_object_sp) - Reset((PyObject *)script_object_sp->GetObject()); // Use "Reset()" to ensure that py_obj is a string -} - PythonInteger::PythonInteger (int64_t value) : PythonObject() { @@ -207,7 +244,7 @@ PythonInteger::Reset (PyObject *py_obj) } int64_t -PythonInteger::GetInteger() +PythonInteger::GetInteger() const { if (m_py_obj) { @@ -225,6 +262,14 @@ PythonInteger::SetInteger (int64_t value) PythonObject::Reset(PyLong_FromLongLong(value)); } +StructuredData::IntegerSP +PythonInteger::CreateStructuredInteger() const +{ + StructuredData::IntegerSP result(new StructuredData::Integer); + result->SetValue(GetInteger()); + return result; +} + //---------------------------------------------------------------------- // PythonList //---------------------------------------------------------------------- @@ -252,13 +297,6 @@ PythonList::PythonList (const PythonObject &object) : Reset(object.get()); // Use "Reset()" to ensure that py_obj is a list } -PythonList::PythonList (const lldb::ScriptInterpreterObjectSP &script_object_sp) : - PythonObject() -{ - if (script_object_sp) - Reset((PyObject *)script_object_sp->GetObject()); // Use "Reset()" to ensure that py_obj is a list -} - PythonList::~PythonList () { } @@ -274,7 +312,7 @@ PythonList::Reset (PyObject *py_obj) } uint32_t -PythonList::GetSize() +PythonList::GetSize() const { if (m_py_obj) return PyList_GET_SIZE(m_py_obj); @@ -282,7 +320,7 @@ PythonList::GetSize() } PythonObject -PythonList::GetItemAtIndex (uint32_t index) +PythonList::GetItemAtIndex(uint32_t index) const { if (m_py_obj) return PythonObject(PyList_GetItem(m_py_obj, index)); @@ -303,6 +341,19 @@ PythonList::AppendItem (const PythonObject &object) PyList_Append(m_py_obj, object.get()); } +StructuredData::ArraySP +PythonList::CreateStructuredArray() const +{ + StructuredData::ArraySP result(new StructuredData::Array); + uint32_t count = GetSize(); + for (uint32_t i = 0; i < count; ++i) + { + PythonObject obj = GetItemAtIndex(i); + result->AddItem(obj.CreateStructuredObject()); + } + return result; +} + //---------------------------------------------------------------------- // PythonDictionary //---------------------------------------------------------------------- @@ -325,13 +376,6 @@ PythonDictionary::PythonDictionary (const PythonObject &object) : Reset(object.get()); // Use "Reset()" to ensure that py_obj is a dictionary } -PythonDictionary::PythonDictionary (const lldb::ScriptInterpreterObjectSP &script_object_sp) : - PythonObject () -{ - if (script_object_sp) - Reset((PyObject *)script_object_sp->GetObject()); // Use "Reset()" to ensure that py_obj is a dictionary -} - PythonDictionary::~PythonDictionary () { } @@ -347,7 +391,7 @@ PythonDictionary::Reset (PyObject *py_obj) } uint32_t -PythonDictionary::GetSize() +PythonDictionary::GetSize() const { if (m_py_obj) return PyDict_Size(m_py_obj); @@ -460,4 +504,21 @@ PythonDictionary::SetItemForKey (const PythonString &key, const PythonObject &va PyDict_SetItem(m_py_obj, key.get(), value.get()); } +StructuredData::DictionarySP +PythonDictionary::CreateStructuredDictionary() const +{ + StructuredData::DictionarySP result(new StructuredData::Dictionary); + PythonList keys(GetKeys()); + uint32_t num_keys = keys.GetSize(); + for (uint32_t i = 0; i < num_keys; ++i) + { + PythonObject key = keys.GetItemAtIndex(i); + PythonString key_str = key.Str(); + PythonObject value = GetItemForKey(key); + StructuredData::ObjectSP structured_value = value.CreateStructuredObject(); + result->AddItem(key_str.GetString(), structured_value); + } + return result; +} + #endif |