diff options
author | Enrico Granata <egranata@apple.com> | 2016-05-02 00:41:24 +0000 |
---|---|---|
committer | Enrico Granata <egranata@apple.com> | 2016-05-02 00:41:24 +0000 |
commit | 6eec8d6c6f2c179ecea70087bf5f5dff3052dd4b (patch) | |
tree | f29ac8c15a6cd8f73c229a3f41dff68b271240d3 /lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp | |
parent | 4f277763cf7daacb7f91478c04454da046c70545 (diff) | |
download | bcm5719-llvm-6eec8d6c6f2c179ecea70087bf5f5dff3052dd4b.tar.gz bcm5719-llvm-6eec8d6c6f2c179ecea70087bf5f5dff3052dd4b.zip |
Add support for synthetic child providers to optionally return a customized typename for display
llvm-svn: 268208
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp')
-rw-r--r-- | lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp index 4cf42598d32..ff811e1f5de 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -2349,6 +2349,72 @@ ScriptInterpreterPython::GetSyntheticValue(const StructuredData::ObjectSP &imple return ret_val; } +ConstString +ScriptInterpreterPython::GetSyntheticTypeName (const StructuredData::ObjectSP &implementor_sp) +{ + Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); + + static char callee_name[] = "get_type_name"; + + ConstString ret_val; + bool got_string = false; + std::string buffer; + + if (!implementor_sp) + return ret_val; + + StructuredData::Generic *generic = implementor_sp->GetAsGeneric(); + if (!generic) + return ret_val; + PythonObject implementor(PyRefType::Borrowed, (PyObject *)generic->GetValue()); + if (!implementor.IsAllocated()) + return ret_val; + + PythonObject pmeth(PyRefType::Owned, PyObject_GetAttrString(implementor.get(), callee_name)); + + if (PyErr_Occurred()) + PyErr_Clear(); + + if (!pmeth.IsAllocated()) + return ret_val; + + if (PyCallable_Check(pmeth.get()) == 0) + { + if (PyErr_Occurred()) + PyErr_Clear(); + return ret_val; + } + + if (PyErr_Occurred()) + PyErr_Clear(); + + // right now we know this function exists and is callable.. + PythonObject py_return(PyRefType::Owned, PyObject_CallMethod(implementor.get(), callee_name, nullptr)); + + // if it fails, print the error but otherwise go on + if (PyErr_Occurred()) + { + PyErr_Print(); + PyErr_Clear(); + } + + if (py_return.IsAllocated() && PythonString::Check(py_return.get())) + { + PythonString py_string(PyRefType::Borrowed, py_return.get()); + llvm::StringRef return_data(py_string.GetString()); + if (!return_data.empty()) + { + buffer.assign(return_data.data(), return_data.size()); + got_string = true; + } + } + + if (got_string) + ret_val.SetCStringWithLength(buffer.c_str(), buffer.size()); + + return ret_val; +} + bool ScriptInterpreterPython::RunScriptFormatKeyword (const char* impl_function, Process* process, |