forked from OSchip/llvm-project
Add support for synthetic child providers to optionally return a customized typename for display
llvm-svn: 268208
This commit is contained in:
parent
4f277763cf
commit
6eec8d6c6f
|
@ -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:
|
||||
|
|
|
@ -380,6 +380,12 @@ public:
|
|||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
virtual ConstString
|
||||
GetSyntheticTypeName (const StructuredData::ObjectSP &implementor)
|
||||
{
|
||||
return ConstString();
|
||||
}
|
||||
|
||||
virtual bool
|
||||
RunScriptBasedCommand (const char* impl_function,
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue