diff options
6 files changed, 94 insertions, 0 deletions
diff --git a/lldb/include/lldb/DataFormatters/TypeSynthetic.h b/lldb/include/lldb/DataFormatters/TypeSynthetic.h index 90e5730288c..ceb600aed69 100644 --- a/lldb/include/lldb/DataFormatters/TypeSynthetic.h +++ b/lldb/include/lldb/DataFormatters/TypeSynthetic.h @@ -91,6 +91,11 @@ namespace lldb_private { virtual lldb::ValueObjectSP GetSyntheticValue () { return nullptr; } + // if this function returns a non-empty ConstString, then clients are expected to use the return + // as the name of the type of this ValueObject for display purposes + virtual ConstString + GetSyntheticTypeName () { return ConstString(); } + typedef std::shared_ptr<SyntheticChildrenFrontEnd> SharedPointer; typedef std::unique_ptr<SyntheticChildrenFrontEnd> AutoPointer; @@ -607,6 +612,9 @@ namespace lldb_private { lldb::ValueObjectSP GetSyntheticValue() override; + ConstString + GetSyntheticTypeName () override; + typedef std::shared_ptr<SyntheticChildrenFrontEnd> SharedPointer; private: diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h b/lldb/include/lldb/Interpreter/ScriptInterpreter.h index eafc03a00cc..8cfb3cea44b 100644 --- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h +++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h @@ -380,6 +380,12 @@ public: { return nullptr; } + + virtual ConstString + GetSyntheticTypeName (const StructuredData::ObjectSP &implementor) + { + return ConstString(); + } virtual bool RunScriptBasedCommand (const char* impl_function, diff --git a/lldb/source/Core/ValueObjectSyntheticFilter.cpp b/lldb/source/Core/ValueObjectSyntheticFilter.cpp index 0ccc4385e3c..cf1e107dd86 100644 --- a/lldb/source/Core/ValueObjectSyntheticFilter.cpp +++ b/lldb/source/Core/ValueObjectSyntheticFilter.cpp @@ -99,6 +99,9 @@ ValueObjectSynthetic::GetQualifiedTypeName() ConstString ValueObjectSynthetic::GetDisplayTypeName() { + if (ConstString synth_name = m_synth_filter_ap->GetSyntheticTypeName()) + return synth_name; + return m_parent->GetDisplayTypeName(); } diff --git a/lldb/source/DataFormatters/TypeSynthetic.cpp b/lldb/source/DataFormatters/TypeSynthetic.cpp index e49cd99b02e..c8de1759c91 100644 --- a/lldb/source/DataFormatters/TypeSynthetic.cpp +++ b/lldb/source/DataFormatters/TypeSynthetic.cpp @@ -246,6 +246,15 @@ ScriptedSyntheticChildren::FrontEnd::GetSyntheticValue () return m_interpreter->GetSyntheticValue(m_wrapper_sp); } +ConstString +ScriptedSyntheticChildren::FrontEnd::GetSyntheticTypeName () +{ + if (!m_wrapper_sp || m_interpreter == NULL) + return ConstString(); + + return m_interpreter->GetSyntheticTypeName(m_wrapper_sp); +} + std::string ScriptedSyntheticChildren::GetDescription() { 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, diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h index 83702a02554..263bb527d83 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h @@ -228,6 +228,8 @@ public: lldb::ValueObjectSP GetSyntheticValue(const StructuredData::ObjectSP &implementor) override; + ConstString GetSyntheticTypeName (const StructuredData::ObjectSP &implementor) override; + bool RunScriptBasedCommand(const char* impl_function, const char* args, |