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 //===----------------------------------------------------------------------===//
14 #include "lldb/lldb-enumerations.h"
15 #include "lldb/lldb-public.h"
17 #include "lldb/Core/Debugger.h"
18 #include "lldb/DataFormatters/TypeSynthetic.h"
19 #include "lldb/Interpreter/CommandInterpreter.h"
20 #include "lldb/Interpreter/ScriptInterpreter.h"
21 #include "lldb/Symbol/CompilerType.h"
22 #include "lldb/Target/Target.h"
23 #include "lldb/Utility/StreamString.h"
26 using namespace lldb_private;
28 void TypeFilterImpl::AddExpressionPath(const std::string &path) {
29 bool need_add_dot = true;
30 if (path[0] == '.' || (path[0] == '-' && path[1] == '>') || path[0] == '[')
32 // add a '.' symbol to help forgetful users
34 m_expression_paths.push_back(path);
36 m_expression_paths.push_back(std::string(".") + path);
39 bool TypeFilterImpl::SetExpressionPathAtIndex(size_t i,
40 const std::string &path) {
43 bool need_add_dot = true;
44 if (path[0] == '.' || (path[0] == '-' && path[1] == '>') || path[0] == '[')
46 // add a '.' symbol to help forgetful users
48 m_expression_paths[i] = path;
50 m_expression_paths[i] = std::string(".") + path;
55 TypeFilterImpl::FrontEnd::GetIndexOfChildWithName(const ConstString &name) {
56 const char *name_cstr = name.GetCString();
58 for (size_t i = 0; i < filter->GetCount(); i++) {
59 const char *expr_cstr = filter->GetExpressionPathAtIndex(i);
61 if (*expr_cstr == '.')
63 else if (*expr_cstr == '-' && *(expr_cstr + 1) == '>')
67 if (!::strcmp(name_cstr, expr_cstr))
75 std::string TypeFilterImpl::GetDescription() {
77 sstr.Printf("%s%s%s {\n", Cascades() ? "" : " (not cascading)",
78 SkipsPointers() ? " (skip pointers)" : "",
79 SkipsReferences() ? " (skip references)" : "");
81 for (size_t i = 0; i < GetCount(); i++) {
82 sstr.Printf(" %s\n", GetExpressionPathAtIndex(i));
86 return sstr.GetString();
89 std::string CXXSyntheticChildren::GetDescription() {
91 sstr.Printf("%s%s%s %s", Cascades() ? "" : " (not cascading)",
92 SkipsPointers() ? " (skip pointers)" : "",
93 SkipsReferences() ? " (skip references)" : "",
94 m_description.c_str());
96 return sstr.GetString();
99 lldb::ValueObjectSP SyntheticChildrenFrontEnd::CreateValueObjectFromExpression(
100 llvm::StringRef name, llvm::StringRef expression,
101 const ExecutionContext &exe_ctx) {
102 ValueObjectSP valobj_sp(
103 ValueObject::CreateValueObjectFromExpression(name, expression, exe_ctx));
105 valobj_sp->SetSyntheticChildrenGenerated(true);
109 lldb::ValueObjectSP SyntheticChildrenFrontEnd::CreateValueObjectFromAddress(
110 llvm::StringRef name, uint64_t address, const ExecutionContext &exe_ctx,
112 ValueObjectSP valobj_sp(
113 ValueObject::CreateValueObjectFromAddress(name, address, exe_ctx, type));
115 valobj_sp->SetSyntheticChildrenGenerated(true);
119 lldb::ValueObjectSP SyntheticChildrenFrontEnd::CreateValueObjectFromData(
120 llvm::StringRef name, const DataExtractor &data,
121 const ExecutionContext &exe_ctx, CompilerType type) {
122 ValueObjectSP valobj_sp(
123 ValueObject::CreateValueObjectFromData(name, data, exe_ctx, type));
125 valobj_sp->SetSyntheticChildrenGenerated(true);
129 #ifndef LLDB_DISABLE_PYTHON
131 ScriptedSyntheticChildren::FrontEnd::FrontEnd(std::string pclass,
132 ValueObject &backend)
133 : SyntheticChildrenFrontEnd(backend), m_python_class(pclass),
134 m_wrapper_sp(), m_interpreter(NULL) {
135 if (backend == LLDB_INVALID_UID)
138 TargetSP target_sp = backend.GetTargetSP();
144 target_sp->GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
146 if (m_interpreter != NULL)
147 m_wrapper_sp = m_interpreter->CreateSyntheticScriptedProvider(
148 m_python_class.c_str(), backend.GetSP());
151 ScriptedSyntheticChildren::FrontEnd::~FrontEnd() {}
154 ScriptedSyntheticChildren::FrontEnd::GetChildAtIndex(size_t idx) {
155 if (!m_wrapper_sp || !m_interpreter)
156 return lldb::ValueObjectSP();
158 return m_interpreter->GetChildAtIndex(m_wrapper_sp, idx);
161 bool ScriptedSyntheticChildren::FrontEnd::IsValid() {
162 return (m_wrapper_sp && m_wrapper_sp->IsValid() && m_interpreter);
165 size_t ScriptedSyntheticChildren::FrontEnd::CalculateNumChildren() {
166 if (!m_wrapper_sp || m_interpreter == NULL)
168 return m_interpreter->CalculateNumChildren(m_wrapper_sp, UINT32_MAX);
171 size_t ScriptedSyntheticChildren::FrontEnd::CalculateNumChildren(uint32_t max) {
172 if (!m_wrapper_sp || m_interpreter == NULL)
174 return m_interpreter->CalculateNumChildren(m_wrapper_sp, max);
177 bool ScriptedSyntheticChildren::FrontEnd::Update() {
178 if (!m_wrapper_sp || m_interpreter == NULL)
181 return m_interpreter->UpdateSynthProviderInstance(m_wrapper_sp);
184 bool ScriptedSyntheticChildren::FrontEnd::MightHaveChildren() {
185 if (!m_wrapper_sp || m_interpreter == NULL)
188 return m_interpreter->MightHaveChildrenSynthProviderInstance(m_wrapper_sp);
191 size_t ScriptedSyntheticChildren::FrontEnd::GetIndexOfChildWithName(
192 const ConstString &name) {
193 if (!m_wrapper_sp || m_interpreter == NULL)
195 return m_interpreter->GetIndexOfChildWithName(m_wrapper_sp,
199 lldb::ValueObjectSP ScriptedSyntheticChildren::FrontEnd::GetSyntheticValue() {
200 if (!m_wrapper_sp || m_interpreter == NULL)
203 return m_interpreter->GetSyntheticValue(m_wrapper_sp);
206 ConstString ScriptedSyntheticChildren::FrontEnd::GetSyntheticTypeName() {
207 if (!m_wrapper_sp || m_interpreter == NULL)
208 return ConstString();
210 return m_interpreter->GetSyntheticTypeName(m_wrapper_sp);
213 std::string ScriptedSyntheticChildren::GetDescription() {
215 sstr.Printf("%s%s%s Python class %s", Cascades() ? "" : " (not cascading)",
216 SkipsPointers() ? " (skip pointers)" : "",
217 SkipsReferences() ? " (skip references)" : "",
218 m_python_class.c_str());
220 return sstr.GetString();
223 #endif // #ifndef LLDB_DISABLE_PYTHON