]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/DataFormatters/TypeSynthetic.cpp
Vendor import of lldb release_39 branch r276489:
[FreeBSD/FreeBSD.git] / source / DataFormatters / TypeSynthetic.cpp
1 //===-- TypeSynthetic.cpp ----------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // C Includes
11
12 // C++ Includes
13
14 // Other libraries and framework includes
15
16 // Project includes
17 #include "lldb/lldb-public.h"
18 #include "lldb/lldb-enumerations.h"
19
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"
27
28 using namespace lldb;
29 using namespace lldb_private;
30
31 void
32 TypeFilterImpl::AddExpressionPath (const std::string& path)
33 {
34     bool need_add_dot = true;
35     if (path[0] == '.' ||
36         (path[0] == '-' && path[1] == '>') ||
37         path[0] == '[')
38         need_add_dot = false;
39     // add a '.' symbol to help forgetful users
40     if(!need_add_dot)
41         m_expression_paths.push_back(path);
42     else
43         m_expression_paths.push_back(std::string(".") + path);
44 }
45
46 bool
47 TypeFilterImpl::SetExpressionPathAtIndex (size_t i, const std::string& path)
48 {
49     if (i >= GetCount())
50         return false;
51     bool need_add_dot = true;
52     if (path[0] == '.' ||
53         (path[0] == '-' && path[1] == '>') ||
54         path[0] == '[')
55         need_add_dot = false;
56     // add a '.' symbol to help forgetful users
57     if(!need_add_dot)
58         m_expression_paths[i] = path;
59     else
60         m_expression_paths[i] = std::string(".") + path;
61     return true;
62 }
63
64 size_t
65 TypeFilterImpl::FrontEnd::GetIndexOfChildWithName (const ConstString &name)
66 {
67     const char* name_cstr = name.GetCString();
68     if (name_cstr)
69     {
70         for (size_t i = 0; i < filter->GetCount(); i++)
71         {
72             const char* expr_cstr = filter->GetExpressionPathAtIndex(i);
73             if (expr_cstr)
74             {
75                 if (*expr_cstr == '.')
76                     expr_cstr++;
77                 else if (*expr_cstr == '-' && *(expr_cstr+1) == '>')
78                     expr_cstr += 2;
79             }
80             if (expr_cstr)
81             {
82                 if (!::strcmp(name_cstr, expr_cstr))
83                     return i;
84             }
85         }
86     }
87     return UINT32_MAX;
88 }
89
90 std::string
91 TypeFilterImpl::GetDescription()
92 {
93     StreamString sstr;
94     sstr.Printf("%s%s%s {\n",
95                 Cascades() ? "" : " (not cascading)",
96                 SkipsPointers() ? " (skip pointers)" : "",
97                 SkipsReferences() ? " (skip references)" : "");
98     
99     for (size_t i = 0; i < GetCount(); i++)
100     {
101         sstr.Printf("    %s\n",
102                     GetExpressionPathAtIndex(i));
103     }
104     
105     sstr.Printf("}");
106     return sstr.GetString();
107 }
108
109 std::string
110 CXXSyntheticChildren::GetDescription()
111 {
112     StreamString sstr;
113     sstr.Printf("%s%s%s %s",
114                 Cascades() ? "" : " (not cascading)",
115                 SkipsPointers() ? " (skip pointers)" : "",
116                 SkipsReferences() ? " (skip references)" : "",
117                 m_description.c_str());
118
119     return sstr.GetString();
120 }
121
122 lldb::ValueObjectSP
123 SyntheticChildrenFrontEnd::CreateValueObjectFromExpression (const char* name,
124                                                             const char* expression,
125                                                             const ExecutionContext& exe_ctx)
126 {
127     ValueObjectSP valobj_sp(ValueObject::CreateValueObjectFromExpression(name, expression, exe_ctx));
128     if (valobj_sp)
129         valobj_sp->SetSyntheticChildrenGenerated(true);
130     return valobj_sp;
131 }
132
133 lldb::ValueObjectSP
134 SyntheticChildrenFrontEnd::CreateValueObjectFromAddress (const char* name,
135                                                          uint64_t address,
136                                                          const ExecutionContext& exe_ctx,
137                                                          CompilerType type)
138 {
139     ValueObjectSP valobj_sp(ValueObject::CreateValueObjectFromAddress(name, address, exe_ctx, type));
140     if (valobj_sp)
141         valobj_sp->SetSyntheticChildrenGenerated(true);
142     return valobj_sp;
143 }
144
145 lldb::ValueObjectSP
146 SyntheticChildrenFrontEnd::CreateValueObjectFromData (const char* name,
147                                                       const DataExtractor& data,
148                                                       const ExecutionContext& exe_ctx,
149                                                       CompilerType type)
150 {
151     ValueObjectSP valobj_sp(ValueObject::CreateValueObjectFromData(name, data, exe_ctx, type));
152     if (valobj_sp)
153         valobj_sp->SetSyntheticChildrenGenerated(true);
154     return valobj_sp;
155 }
156
157 #ifndef LLDB_DISABLE_PYTHON
158
159 ScriptedSyntheticChildren::FrontEnd::FrontEnd(std::string pclass, ValueObject &backend) :
160 SyntheticChildrenFrontEnd(backend),
161 m_python_class(pclass),
162 m_wrapper_sp(),
163 m_interpreter(NULL)
164 {
165     if (backend == LLDB_INVALID_UID)
166         return;
167     
168     TargetSP target_sp = backend.GetTargetSP();
169     
170     if (!target_sp)
171         return;
172     
173     m_interpreter = target_sp->GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
174     
175     if (m_interpreter != NULL)
176         m_wrapper_sp = m_interpreter->CreateSyntheticScriptedProvider(m_python_class.c_str(), backend.GetSP());
177 }
178
179 ScriptedSyntheticChildren::FrontEnd::~FrontEnd()
180 {
181 }
182
183 lldb::ValueObjectSP
184 ScriptedSyntheticChildren::FrontEnd::GetChildAtIndex (size_t idx)
185 {
186     if (!m_wrapper_sp || !m_interpreter)
187         return lldb::ValueObjectSP();
188     
189     return m_interpreter->GetChildAtIndex(m_wrapper_sp, idx);
190 }
191
192 bool
193 ScriptedSyntheticChildren::FrontEnd::IsValid ()
194 {
195     return (m_wrapper_sp && m_wrapper_sp->IsValid() && m_interpreter);
196 }
197
198 size_t
199 ScriptedSyntheticChildren::FrontEnd::CalculateNumChildren ()
200 {
201     if (!m_wrapper_sp || m_interpreter == NULL)
202         return 0;
203     return m_interpreter->CalculateNumChildren(m_wrapper_sp, UINT32_MAX);
204 }
205
206 size_t
207 ScriptedSyntheticChildren::FrontEnd::CalculateNumChildren (uint32_t max)
208 {
209     if (!m_wrapper_sp || m_interpreter == NULL)
210         return 0;
211     return m_interpreter->CalculateNumChildren(m_wrapper_sp, max);
212 }
213
214 bool
215 ScriptedSyntheticChildren::FrontEnd::Update ()
216 {
217     if (!m_wrapper_sp || m_interpreter == NULL)
218         return false;
219     
220     return m_interpreter->UpdateSynthProviderInstance(m_wrapper_sp);
221 }
222
223 bool
224 ScriptedSyntheticChildren::FrontEnd::MightHaveChildren ()
225 {
226     if (!m_wrapper_sp || m_interpreter == NULL)
227         return false;
228     
229     return m_interpreter->MightHaveChildrenSynthProviderInstance(m_wrapper_sp);
230 }
231
232 size_t
233 ScriptedSyntheticChildren::FrontEnd::GetIndexOfChildWithName (const ConstString &name)
234 {
235     if (!m_wrapper_sp || m_interpreter == NULL)
236         return UINT32_MAX;
237     return m_interpreter->GetIndexOfChildWithName(m_wrapper_sp, name.GetCString());
238 }
239
240 lldb::ValueObjectSP
241 ScriptedSyntheticChildren::FrontEnd::GetSyntheticValue ()
242 {
243     if (!m_wrapper_sp || m_interpreter == NULL)
244         return nullptr;
245     
246     return m_interpreter->GetSyntheticValue(m_wrapper_sp);
247 }
248
249 ConstString
250 ScriptedSyntheticChildren::FrontEnd::GetSyntheticTypeName ()
251 {
252     if (!m_wrapper_sp || m_interpreter == NULL)
253         return ConstString();
254     
255     return m_interpreter->GetSyntheticTypeName(m_wrapper_sp);
256 }
257
258 std::string
259 ScriptedSyntheticChildren::GetDescription()
260 {
261     StreamString sstr;
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());
267     
268     return sstr.GetString();
269 }
270
271 #endif // #ifndef LLDB_DISABLE_PYTHON