Author: enrico Date: Sun May 1 19:41:24 2016 New Revision: 268208 URL: http://llvm.org/viewvc/llvm-project?rev=268208&view=rev Log: Add support for synthetic child providers to optionally return a customized typename for display
Modified: lldb/trunk/include/lldb/DataFormatters/TypeSynthetic.h lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h lldb/trunk/source/Core/ValueObjectSyntheticFilter.cpp lldb/trunk/source/DataFormatters/TypeSynthetic.cpp lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h Modified: lldb/trunk/include/lldb/DataFormatters/TypeSynthetic.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/TypeSynthetic.h?rev=268208&r1=268207&r2=268208&view=diff ============================================================================== --- lldb/trunk/include/lldb/DataFormatters/TypeSynthetic.h (original) +++ lldb/trunk/include/lldb/DataFormatters/TypeSynthetic.h Sun May 1 19:41:24 2016 @@ -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: Modified: lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h?rev=268208&r1=268207&r2=268208&view=diff ============================================================================== --- lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h (original) +++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h Sun May 1 19:41:24 2016 @@ -380,6 +380,12 @@ public: { return nullptr; } + + virtual ConstString + GetSyntheticTypeName (const StructuredData::ObjectSP &implementor) + { + return ConstString(); + } virtual bool RunScriptBasedCommand (const char* impl_function, Modified: lldb/trunk/source/Core/ValueObjectSyntheticFilter.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectSyntheticFilter.cpp?rev=268208&r1=268207&r2=268208&view=diff ============================================================================== --- lldb/trunk/source/Core/ValueObjectSyntheticFilter.cpp (original) +++ lldb/trunk/source/Core/ValueObjectSyntheticFilter.cpp Sun May 1 19:41:24 2016 @@ -99,6 +99,9 @@ ValueObjectSynthetic::GetQualifiedTypeNa ConstString ValueObjectSynthetic::GetDisplayTypeName() { + if (ConstString synth_name = m_synth_filter_ap->GetSyntheticTypeName()) + return synth_name; + return m_parent->GetDisplayTypeName(); } Modified: lldb/trunk/source/DataFormatters/TypeSynthetic.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/TypeSynthetic.cpp?rev=268208&r1=268207&r2=268208&view=diff ============================================================================== --- lldb/trunk/source/DataFormatters/TypeSynthetic.cpp (original) +++ lldb/trunk/source/DataFormatters/TypeSynthetic.cpp Sun May 1 19:41:24 2016 @@ -246,6 +246,15 @@ ScriptedSyntheticChildren::FrontEnd::Get 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() { Modified: lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp?rev=268208&r1=268207&r2=268208&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp (original) +++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp Sun May 1 19:41:24 2016 @@ -2349,6 +2349,72 @@ ScriptInterpreterPython::GetSyntheticVal 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, Modified: lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h?rev=268208&r1=268207&r2=268208&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h (original) +++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h Sun May 1 19:41:24 2016 @@ -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, _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits