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/CompilerType.h"
26 #include "lldb/Target/Target.h"
29 using namespace lldb_private;
32 TypeFilterImpl::AddExpressionPath (const std::string& path)
34 bool need_add_dot = true;
36 (path[0] == '-' && path[1] == '>') ||
39 // add a '.' symbol to help forgetful users
41 m_expression_paths.push_back(path);
43 m_expression_paths.push_back(std::string(".") + path);
47 TypeFilterImpl::SetExpressionPathAtIndex (size_t i, const std::string& path)
51 bool need_add_dot = true;
53 (path[0] == '-' && path[1] == '>') ||
56 // add a '.' symbol to help forgetful users
58 m_expression_paths[i] = path;
60 m_expression_paths[i] = std::string(".") + path;
65 TypeFilterImpl::FrontEnd::GetIndexOfChildWithName (const ConstString &name)
67 const char* name_cstr = name.GetCString();
70 for (size_t i = 0; i < filter->GetCount(); i++)
72 const char* expr_cstr = filter->GetExpressionPathAtIndex(i);
75 if (*expr_cstr == '.')
77 else if (*expr_cstr == '-' && *(expr_cstr+1) == '>')
82 if (!::strcmp(name_cstr, expr_cstr))
91 TypeFilterImpl::GetDescription()
94 sstr.Printf("%s%s%s {\n",
95 Cascades() ? "" : " (not cascading)",
96 SkipsPointers() ? " (skip pointers)" : "",
97 SkipsReferences() ? " (skip references)" : "");
99 for (size_t i = 0; i < GetCount(); i++)
102 GetExpressionPathAtIndex(i));
106 return sstr.GetString();
110 CXXSyntheticChildren::GetDescription()
113 sstr.Printf("%s%s%s %s",
114 Cascades() ? "" : " (not cascading)",
115 SkipsPointers() ? " (skip pointers)" : "",
116 SkipsReferences() ? " (skip references)" : "",
117 m_description.c_str());
119 return sstr.GetString();
123 SyntheticChildrenFrontEnd::CreateValueObjectFromExpression (const char* name,
124 const char* expression,
125 const ExecutionContext& exe_ctx)
127 ValueObjectSP valobj_sp(ValueObject::CreateValueObjectFromExpression(name, expression, exe_ctx));
129 valobj_sp->SetSyntheticChildrenGenerated(true);
134 SyntheticChildrenFrontEnd::CreateValueObjectFromAddress (const char* name,
136 const ExecutionContext& exe_ctx,
139 ValueObjectSP valobj_sp(ValueObject::CreateValueObjectFromAddress(name, address, exe_ctx, type));
141 valobj_sp->SetSyntheticChildrenGenerated(true);
146 SyntheticChildrenFrontEnd::CreateValueObjectFromData (const char* name,
147 const DataExtractor& data,
148 const ExecutionContext& exe_ctx,
151 ValueObjectSP valobj_sp(ValueObject::CreateValueObjectFromData(name, data, exe_ctx, type));
153 valobj_sp->SetSyntheticChildrenGenerated(true);
157 #ifndef LLDB_DISABLE_PYTHON
159 ScriptedSyntheticChildren::FrontEnd::FrontEnd(std::string pclass, ValueObject &backend) :
160 SyntheticChildrenFrontEnd(backend),
161 m_python_class(pclass),
165 if (backend == LLDB_INVALID_UID)
168 TargetSP target_sp = backend.GetTargetSP();
173 m_interpreter = target_sp->GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
175 if (m_interpreter != NULL)
176 m_wrapper_sp = m_interpreter->CreateSyntheticScriptedProvider(m_python_class.c_str(), backend.GetSP());
179 ScriptedSyntheticChildren::FrontEnd::~FrontEnd()
184 ScriptedSyntheticChildren::FrontEnd::GetChildAtIndex (size_t idx)
186 if (!m_wrapper_sp || !m_interpreter)
187 return lldb::ValueObjectSP();
189 return m_interpreter->GetChildAtIndex(m_wrapper_sp, idx);
193 ScriptedSyntheticChildren::FrontEnd::IsValid ()
195 return (m_wrapper_sp && m_wrapper_sp->IsValid() && m_interpreter);
199 ScriptedSyntheticChildren::FrontEnd::CalculateNumChildren ()
201 if (!m_wrapper_sp || m_interpreter == NULL)
203 return m_interpreter->CalculateNumChildren(m_wrapper_sp, UINT32_MAX);
207 ScriptedSyntheticChildren::FrontEnd::CalculateNumChildren (uint32_t max)
209 if (!m_wrapper_sp || m_interpreter == NULL)
211 return m_interpreter->CalculateNumChildren(m_wrapper_sp, max);
215 ScriptedSyntheticChildren::FrontEnd::Update ()
217 if (!m_wrapper_sp || m_interpreter == NULL)
220 return m_interpreter->UpdateSynthProviderInstance(m_wrapper_sp);
224 ScriptedSyntheticChildren::FrontEnd::MightHaveChildren ()
226 if (!m_wrapper_sp || m_interpreter == NULL)
229 return m_interpreter->MightHaveChildrenSynthProviderInstance(m_wrapper_sp);
233 ScriptedSyntheticChildren::FrontEnd::GetIndexOfChildWithName (const ConstString &name)
235 if (!m_wrapper_sp || m_interpreter == NULL)
237 return m_interpreter->GetIndexOfChildWithName(m_wrapper_sp, name.GetCString());
241 ScriptedSyntheticChildren::FrontEnd::GetSyntheticValue ()
243 if (!m_wrapper_sp || m_interpreter == NULL)
246 return m_interpreter->GetSyntheticValue(m_wrapper_sp);
250 ScriptedSyntheticChildren::FrontEnd::GetSyntheticTypeName ()
252 if (!m_wrapper_sp || m_interpreter == NULL)
253 return ConstString();
255 return m_interpreter->GetSyntheticTypeName(m_wrapper_sp);
259 ScriptedSyntheticChildren::GetDescription()
262 sstr.Printf("%s%s%s Python class %s",
263 Cascades() ? "" : " (not cascading)",
264 SkipsPointers() ? " (skip pointers)" : "",
265 SkipsReferences() ? " (skip references)" : "",
266 m_python_class.c_str());
268 return sstr.GetString();
271 #endif // #ifndef LLDB_DISABLE_PYTHON