1 //===-- TypeSynthetic.cpp ----------------------------------------*- C++
4 // The LLVM Compiler Infrastructure
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
15 // Other libraries and framework includes
18 #include "lldb/lldb-enumerations.h"
19 #include "lldb/lldb-public.h"
21 #include "lldb/Core/Debugger.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"
27 #include "lldb/Utility/StreamString.h"
30 using namespace lldb_private;
32 void TypeFilterImpl::AddExpressionPath(const std::string &path) {
33 bool need_add_dot = true;
34 if (path[0] == '.' || (path[0] == '-' && path[1] == '>') || path[0] == '[')
36 // add a '.' symbol to help forgetful users
38 m_expression_paths.push_back(path);
40 m_expression_paths.push_back(std::string(".") + path);
43 bool TypeFilterImpl::SetExpressionPathAtIndex(size_t i,
44 const std::string &path) {
47 bool need_add_dot = true;
48 if (path[0] == '.' || (path[0] == '-' && path[1] == '>') || path[0] == '[')
50 // add a '.' symbol to help forgetful users
52 m_expression_paths[i] = path;
54 m_expression_paths[i] = std::string(".") + path;
59 TypeFilterImpl::FrontEnd::GetIndexOfChildWithName(const ConstString &name) {
60 const char *name_cstr = name.GetCString();
62 for (size_t i = 0; i < filter->GetCount(); i++) {
63 const char *expr_cstr = filter->GetExpressionPathAtIndex(i);
65 if (*expr_cstr == '.')
67 else if (*expr_cstr == '-' && *(expr_cstr + 1) == '>')
71 if (!::strcmp(name_cstr, expr_cstr))
79 std::string TypeFilterImpl::GetDescription() {
81 sstr.Printf("%s%s%s {\n", Cascades() ? "" : " (not cascading)",
82 SkipsPointers() ? " (skip pointers)" : "",
83 SkipsReferences() ? " (skip references)" : "");
85 for (size_t i = 0; i < GetCount(); i++) {
86 sstr.Printf(" %s\n", GetExpressionPathAtIndex(i));
90 return sstr.GetString();
93 std::string CXXSyntheticChildren::GetDescription() {
95 sstr.Printf("%s%s%s %s", Cascades() ? "" : " (not cascading)",
96 SkipsPointers() ? " (skip pointers)" : "",
97 SkipsReferences() ? " (skip references)" : "",
98 m_description.c_str());
100 return sstr.GetString();
103 lldb::ValueObjectSP SyntheticChildrenFrontEnd::CreateValueObjectFromExpression(
104 llvm::StringRef name, llvm::StringRef expression,
105 const ExecutionContext &exe_ctx) {
106 ValueObjectSP valobj_sp(
107 ValueObject::CreateValueObjectFromExpression(name, expression, exe_ctx));
109 valobj_sp->SetSyntheticChildrenGenerated(true);
113 lldb::ValueObjectSP SyntheticChildrenFrontEnd::CreateValueObjectFromAddress(
114 llvm::StringRef name, uint64_t address, const ExecutionContext &exe_ctx,
116 ValueObjectSP valobj_sp(
117 ValueObject::CreateValueObjectFromAddress(name, address, exe_ctx, type));
119 valobj_sp->SetSyntheticChildrenGenerated(true);
123 lldb::ValueObjectSP SyntheticChildrenFrontEnd::CreateValueObjectFromData(
124 llvm::StringRef name, const DataExtractor &data,
125 const ExecutionContext &exe_ctx, CompilerType type) {
126 ValueObjectSP valobj_sp(
127 ValueObject::CreateValueObjectFromData(name, data, exe_ctx, type));
129 valobj_sp->SetSyntheticChildrenGenerated(true);
133 #ifndef LLDB_DISABLE_PYTHON
135 ScriptedSyntheticChildren::FrontEnd::FrontEnd(std::string pclass,
136 ValueObject &backend)
137 : SyntheticChildrenFrontEnd(backend), m_python_class(pclass),
138 m_wrapper_sp(), m_interpreter(NULL) {
139 if (backend == LLDB_INVALID_UID)
142 TargetSP target_sp = backend.GetTargetSP();
148 target_sp->GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
150 if (m_interpreter != NULL)
151 m_wrapper_sp = m_interpreter->CreateSyntheticScriptedProvider(
152 m_python_class.c_str(), backend.GetSP());
155 ScriptedSyntheticChildren::FrontEnd::~FrontEnd() {}
158 ScriptedSyntheticChildren::FrontEnd::GetChildAtIndex(size_t idx) {
159 if (!m_wrapper_sp || !m_interpreter)
160 return lldb::ValueObjectSP();
162 return m_interpreter->GetChildAtIndex(m_wrapper_sp, idx);
165 bool ScriptedSyntheticChildren::FrontEnd::IsValid() {
166 return (m_wrapper_sp && m_wrapper_sp->IsValid() && m_interpreter);
169 size_t ScriptedSyntheticChildren::FrontEnd::CalculateNumChildren() {
170 if (!m_wrapper_sp || m_interpreter == NULL)
172 return m_interpreter->CalculateNumChildren(m_wrapper_sp, UINT32_MAX);
175 size_t ScriptedSyntheticChildren::FrontEnd::CalculateNumChildren(uint32_t max) {
176 if (!m_wrapper_sp || m_interpreter == NULL)
178 return m_interpreter->CalculateNumChildren(m_wrapper_sp, max);
181 bool ScriptedSyntheticChildren::FrontEnd::Update() {
182 if (!m_wrapper_sp || m_interpreter == NULL)
185 return m_interpreter->UpdateSynthProviderInstance(m_wrapper_sp);
188 bool ScriptedSyntheticChildren::FrontEnd::MightHaveChildren() {
189 if (!m_wrapper_sp || m_interpreter == NULL)
192 return m_interpreter->MightHaveChildrenSynthProviderInstance(m_wrapper_sp);
195 size_t ScriptedSyntheticChildren::FrontEnd::GetIndexOfChildWithName(
196 const ConstString &name) {
197 if (!m_wrapper_sp || m_interpreter == NULL)
199 return m_interpreter->GetIndexOfChildWithName(m_wrapper_sp,
203 lldb::ValueObjectSP ScriptedSyntheticChildren::FrontEnd::GetSyntheticValue() {
204 if (!m_wrapper_sp || m_interpreter == NULL)
207 return m_interpreter->GetSyntheticValue(m_wrapper_sp);
210 ConstString ScriptedSyntheticChildren::FrontEnd::GetSyntheticTypeName() {
211 if (!m_wrapper_sp || m_interpreter == NULL)
212 return ConstString();
214 return m_interpreter->GetSyntheticTypeName(m_wrapper_sp);
217 std::string ScriptedSyntheticChildren::GetDescription() {
219 sstr.Printf("%s%s%s Python class %s", Cascades() ? "" : " (not cascading)",
220 SkipsPointers() ? " (skip pointers)" : "",
221 SkipsReferences() ? " (skip references)" : "",
222 m_python_class.c_str());
224 return sstr.GetString();
227 #endif // #ifndef LLDB_DISABLE_PYTHON