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 //===----------------------------------------------------------------------===//
14 // Other libraries and framework includes
17 #include "lldb/lldb-public.h"
18 #include "lldb/lldb-enumerations.h"
20 #include "lldb/Core/Debugger.h"
21 #include "lldb/Core/StreamString.h"
22 #include "lldb/DataFormatters/TypeSynthetic.h"
23 #include "lldb/Interpreter/CommandInterpreter.h"
24 #include "lldb/Interpreter/ScriptInterpreter.h"
25 #include "lldb/Symbol/ClangASTType.h"
26 #include "lldb/Target/StackFrame.h"
27 #include "lldb/Target/Target.h"
30 using namespace lldb_private;
33 TypeFilterImpl::AddExpressionPath (const std::string& path)
35 bool need_add_dot = true;
37 (path[0] == '-' && path[1] == '>') ||
40 // add a '.' symbol to help forgetful users
42 m_expression_paths.push_back(path);
44 m_expression_paths.push_back(std::string(".") + path);
48 TypeFilterImpl::SetExpressionPathAtIndex (size_t i, const std::string& path)
52 bool need_add_dot = true;
54 (path[0] == '-' && path[1] == '>') ||
57 // add a '.' symbol to help forgetful users
59 m_expression_paths[i] = path;
61 m_expression_paths[i] = std::string(".") + path;
66 TypeFilterImpl::FrontEnd::GetIndexOfChildWithName (const ConstString &name)
68 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) == '>')
83 if (!::strcmp(name_cstr, expr_cstr))
92 TypeFilterImpl::GetDescription()
95 sstr.Printf("%s%s%s {\n",
96 Cascades() ? "" : " (not cascading)",
97 SkipsPointers() ? " (skip pointers)" : "",
98 SkipsReferences() ? " (skip references)" : "");
100 for (size_t i = 0; i < GetCount(); i++)
103 GetExpressionPathAtIndex(i));
107 return sstr.GetString();
111 CXXSyntheticChildren::GetDescription()
114 sstr.Printf("%s%s%s Generator at %p - %s",
115 Cascades() ? "" : " (not cascading)",
116 SkipsPointers() ? " (skip pointers)" : "",
117 SkipsReferences() ? " (skip references)" : "",
118 reinterpret_cast<void*>(reinterpret_cast<intptr_t>(m_create_callback)),
119 m_description.c_str());
121 return sstr.GetString();
125 SyntheticChildrenFrontEnd::CreateValueObjectFromExpression (const char* name,
126 const char* expression,
127 const ExecutionContext& exe_ctx)
129 ValueObjectSP valobj_sp(ValueObject::CreateValueObjectFromExpression(name, expression, exe_ctx));
131 valobj_sp->SetSyntheticChildrenGenerated(true);
136 SyntheticChildrenFrontEnd::CreateValueObjectFromAddress (const char* name,
138 const ExecutionContext& exe_ctx,
141 ValueObjectSP valobj_sp(ValueObject::CreateValueObjectFromAddress(name, address, exe_ctx, type));
143 valobj_sp->SetSyntheticChildrenGenerated(true);
148 SyntheticChildrenFrontEnd::CreateValueObjectFromData (const char* name,
149 const DataExtractor& data,
150 const ExecutionContext& exe_ctx,
153 ValueObjectSP valobj_sp(ValueObject::CreateValueObjectFromData(name, data, exe_ctx, type));
155 valobj_sp->SetSyntheticChildrenGenerated(true);
159 #ifndef LLDB_DISABLE_PYTHON
161 ScriptedSyntheticChildren::FrontEnd::FrontEnd(std::string pclass, ValueObject &backend) :
162 SyntheticChildrenFrontEnd(backend),
163 m_python_class(pclass),
167 if (backend == LLDB_INVALID_UID)
170 TargetSP target_sp = backend.GetTargetSP();
175 m_interpreter = target_sp->GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
177 if (m_interpreter != NULL)
178 m_wrapper_sp = m_interpreter->CreateSyntheticScriptedProvider(m_python_class.c_str(), backend.GetSP());
181 ScriptedSyntheticChildren::FrontEnd::~FrontEnd()
186 ScriptedSyntheticChildren::FrontEnd::GetChildAtIndex (size_t idx)
188 if (!m_wrapper_sp || !m_interpreter)
189 return lldb::ValueObjectSP();
191 return m_interpreter->GetChildAtIndex(m_wrapper_sp, idx);
195 ScriptedSyntheticChildren::FrontEnd::IsValid ()
197 return (m_wrapper_sp && m_wrapper_sp->IsValid() && m_interpreter);
201 ScriptedSyntheticChildren::FrontEnd::CalculateNumChildren ()
203 if (!m_wrapper_sp || m_interpreter == NULL)
205 return m_interpreter->CalculateNumChildren(m_wrapper_sp);
209 ScriptedSyntheticChildren::FrontEnd::Update ()
211 if (!m_wrapper_sp || m_interpreter == NULL)
214 return m_interpreter->UpdateSynthProviderInstance(m_wrapper_sp);
218 ScriptedSyntheticChildren::FrontEnd::MightHaveChildren ()
220 if (!m_wrapper_sp || m_interpreter == NULL)
223 return m_interpreter->MightHaveChildrenSynthProviderInstance(m_wrapper_sp);
227 ScriptedSyntheticChildren::FrontEnd::GetIndexOfChildWithName (const ConstString &name)
229 if (!m_wrapper_sp || m_interpreter == NULL)
231 return m_interpreter->GetIndexOfChildWithName(m_wrapper_sp, name.GetCString());
235 ScriptedSyntheticChildren::FrontEnd::GetSyntheticValue ()
237 if (!m_wrapper_sp || m_interpreter == NULL)
240 return m_interpreter->GetSyntheticValue(m_wrapper_sp);
244 ScriptedSyntheticChildren::GetDescription()
247 sstr.Printf("%s%s%s Python class %s",
248 Cascades() ? "" : " (not cascading)",
249 SkipsPointers() ? " (skip pointers)" : "",
250 SkipsReferences() ? " (skip references)" : "",
251 m_python_class.c_str());
253 return sstr.GetString();
256 #endif // #ifndef LLDB_DISABLE_PYTHON