1 //===-- TypeSynthetic.cpp ----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/lldb-python.h"
16 // Other libraries and framework includes
19 #include "lldb/lldb-public.h"
20 #include "lldb/lldb-enumerations.h"
22 #include "lldb/Core/Debugger.h"
23 #include "lldb/Core/StreamString.h"
24 #include "lldb/DataFormatters/TypeSynthetic.h"
25 #include "lldb/Interpreter/CommandInterpreter.h"
26 #include "lldb/Interpreter/ScriptInterpreterPython.h"
27 #include "lldb/Symbol/ClangASTType.h"
28 #include "lldb/Target/StackFrame.h"
29 #include "lldb/Target/Target.h"
32 using namespace lldb_private;
35 TypeFilterImpl::AddExpressionPath (const std::string& path)
37 bool need_add_dot = true;
39 (path[0] == '-' && path[1] == '>') ||
42 // add a '.' symbol to help forgetful users
44 m_expression_paths.push_back(path);
46 m_expression_paths.push_back(std::string(".") + path);
50 TypeFilterImpl::SetExpressionPathAtIndex (size_t i, const std::string& path)
54 bool need_add_dot = true;
56 (path[0] == '-' && path[1] == '>') ||
59 // add a '.' symbol to help forgetful users
61 m_expression_paths[i] = path;
63 m_expression_paths[i] = std::string(".") + path;
68 TypeFilterImpl::FrontEnd::GetIndexOfChildWithName (const ConstString &name)
70 const char* name_cstr = name.GetCString();
71 for (size_t i = 0; i < filter->GetCount(); i++)
73 const char* expr_cstr = filter->GetExpressionPathAtIndex(i);
76 if (*expr_cstr == '.')
78 else if (*expr_cstr == '-' && *(expr_cstr+1) == '>')
81 if (!::strcmp(name_cstr, expr_cstr))
88 TypeFilterImpl::GetDescription()
91 sstr.Printf("%s%s%s {\n",
92 Cascades() ? "" : " (not cascading)",
93 SkipsPointers() ? " (skip pointers)" : "",
94 SkipsReferences() ? " (skip references)" : "");
96 for (size_t i = 0; i < GetCount(); i++)
99 GetExpressionPathAtIndex(i));
103 return sstr.GetString();
107 CXXSyntheticChildren::GetDescription()
110 sstr.Printf("%s%s%s Generator at %p - %s",
111 Cascades() ? "" : " (not cascading)",
112 SkipsPointers() ? " (skip pointers)" : "",
113 SkipsReferences() ? " (skip references)" : "",
114 reinterpret_cast<void*>(reinterpret_cast<intptr_t>(m_create_callback)),
115 m_description.c_str());
117 return sstr.GetString();
121 SyntheticChildrenFrontEnd::CreateValueObjectFromExpression (const char* name,
122 const char* expression,
123 const ExecutionContext& exe_ctx)
125 ValueObjectSP valobj_sp(ValueObject::CreateValueObjectFromExpression(name, expression, exe_ctx));
127 valobj_sp->SetSyntheticChildrenGenerated(true);
132 SyntheticChildrenFrontEnd::CreateValueObjectFromAddress (const char* name,
134 const ExecutionContext& exe_ctx,
137 ValueObjectSP valobj_sp(ValueObject::CreateValueObjectFromAddress(name, address, exe_ctx, type));
139 valobj_sp->SetSyntheticChildrenGenerated(true);
144 SyntheticChildrenFrontEnd::CreateValueObjectFromData (const char* name,
145 const DataExtractor& data,
146 const ExecutionContext& exe_ctx,
149 ValueObjectSP valobj_sp(ValueObject::CreateValueObjectFromData(name, data, exe_ctx, type));
151 valobj_sp->SetSyntheticChildrenGenerated(true);
155 #ifndef LLDB_DISABLE_PYTHON
157 ScriptedSyntheticChildren::FrontEnd::FrontEnd(std::string pclass, ValueObject &backend) :
158 SyntheticChildrenFrontEnd(backend),
159 m_python_class(pclass),
163 if (backend == LLDB_INVALID_UID)
166 TargetSP target_sp = backend.GetTargetSP();
171 m_interpreter = target_sp->GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
173 if (m_interpreter != NULL)
174 m_wrapper_sp = m_interpreter->CreateSyntheticScriptedProvider(m_python_class.c_str(), backend.GetSP());
177 ScriptedSyntheticChildren::FrontEnd::~FrontEnd()
182 ScriptedSyntheticChildren::FrontEnd::GetChildAtIndex (size_t idx)
184 if (!m_wrapper_sp || !m_interpreter)
185 return lldb::ValueObjectSP();
187 return m_interpreter->GetChildAtIndex(m_wrapper_sp, idx);
191 ScriptedSyntheticChildren::FrontEnd::IsValid ()
193 return m_wrapper_sp.get() != nullptr && m_wrapper_sp->operator bool() && m_interpreter != nullptr;
197 ScriptedSyntheticChildren::FrontEnd::CalculateNumChildren ()
199 if (!m_wrapper_sp || m_interpreter == NULL)
201 return m_interpreter->CalculateNumChildren(m_wrapper_sp);
205 ScriptedSyntheticChildren::FrontEnd::Update ()
207 if (!m_wrapper_sp || m_interpreter == NULL)
210 return m_interpreter->UpdateSynthProviderInstance(m_wrapper_sp);
214 ScriptedSyntheticChildren::FrontEnd::MightHaveChildren ()
216 if (!m_wrapper_sp || m_interpreter == NULL)
219 return m_interpreter->MightHaveChildrenSynthProviderInstance(m_wrapper_sp);
223 ScriptedSyntheticChildren::FrontEnd::GetIndexOfChildWithName (const ConstString &name)
225 if (!m_wrapper_sp || m_interpreter == NULL)
227 return m_interpreter->GetIndexOfChildWithName(m_wrapper_sp, name.GetCString());
231 ScriptedSyntheticChildren::FrontEnd::GetSyntheticValue ()
233 if (!m_wrapper_sp || m_interpreter == NULL)
236 return m_interpreter->GetSyntheticValue(m_wrapper_sp);
240 ScriptedSyntheticChildren::GetDescription()
243 sstr.Printf("%s%s%s Python class %s",
244 Cascades() ? "" : " (not cascading)",
245 SkipsPointers() ? " (skip pointers)" : "",
246 SkipsReferences() ? " (skip references)" : "",
247 m_python_class.c_str());
249 return sstr.GetString();
252 #endif // #ifndef LLDB_DISABLE_PYTHON