]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/DataFormatters/TypeSynthetic.cpp
Upgrade to OpenSSH 6.7p1, retaining libwrap support (which has been removed
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / 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/ClangASTType.h"
26 #include "lldb/Target/StackFrame.h"
27 #include "lldb/Target/Target.h"
28
29 using namespace lldb;
30 using namespace lldb_private;
31
32 void
33 TypeFilterImpl::AddExpressionPath (const std::string& path)
34 {
35     bool need_add_dot = true;
36     if (path[0] == '.' ||
37         (path[0] == '-' && path[1] == '>') ||
38         path[0] == '[')
39         need_add_dot = false;
40     // add a '.' symbol to help forgetful users
41     if(!need_add_dot)
42         m_expression_paths.push_back(path);
43     else
44         m_expression_paths.push_back(std::string(".") + path);
45 }
46
47 bool
48 TypeFilterImpl::SetExpressionPathAtIndex (size_t i, const std::string& path)
49 {
50     if (i >= GetCount())
51         return false;
52     bool need_add_dot = true;
53     if (path[0] == '.' ||
54         (path[0] == '-' && path[1] == '>') ||
55         path[0] == '[')
56         need_add_dot = false;
57     // add a '.' symbol to help forgetful users
58     if(!need_add_dot)
59         m_expression_paths[i] = path;
60     else
61         m_expression_paths[i] = std::string(".") + path;
62     return true;
63 }
64
65 size_t
66 TypeFilterImpl::FrontEnd::GetIndexOfChildWithName (const ConstString &name)
67 {
68     const char* name_cstr = name.GetCString();
69     if (name_cstr)
70     {
71         for (size_t i = 0; i < filter->GetCount(); i++)
72         {
73             const char* expr_cstr = filter->GetExpressionPathAtIndex(i);
74             if (expr_cstr)
75             {
76                 if (*expr_cstr == '.')
77                     expr_cstr++;
78                 else if (*expr_cstr == '-' && *(expr_cstr+1) == '>')
79                     expr_cstr += 2;
80             }
81             if (expr_cstr)
82             {
83                 if (!::strcmp(name_cstr, expr_cstr))
84                     return i;
85             }
86         }
87     }
88     return UINT32_MAX;
89 }
90
91 std::string
92 TypeFilterImpl::GetDescription()
93 {
94     StreamString sstr;
95     sstr.Printf("%s%s%s {\n",
96                 Cascades() ? "" : " (not cascading)",
97                 SkipsPointers() ? " (skip pointers)" : "",
98                 SkipsReferences() ? " (skip references)" : "");
99     
100     for (size_t i = 0; i < GetCount(); i++)
101     {
102         sstr.Printf("    %s\n",
103                     GetExpressionPathAtIndex(i));
104     }
105     
106     sstr.Printf("}");
107     return sstr.GetString();
108 }
109
110 std::string
111 CXXSyntheticChildren::GetDescription()
112 {
113     StreamString sstr;
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());
120
121     return sstr.GetString();
122 }
123
124 lldb::ValueObjectSP
125 SyntheticChildrenFrontEnd::CreateValueObjectFromExpression (const char* name,
126                                                             const char* expression,
127                                                             const ExecutionContext& exe_ctx)
128 {
129     ValueObjectSP valobj_sp(ValueObject::CreateValueObjectFromExpression(name, expression, exe_ctx));
130     if (valobj_sp)
131         valobj_sp->SetSyntheticChildrenGenerated(true);
132     return valobj_sp;
133 }
134
135 lldb::ValueObjectSP
136 SyntheticChildrenFrontEnd::CreateValueObjectFromAddress (const char* name,
137                                                          uint64_t address,
138                                                          const ExecutionContext& exe_ctx,
139                                                          ClangASTType type)
140 {
141     ValueObjectSP valobj_sp(ValueObject::CreateValueObjectFromAddress(name, address, exe_ctx, type));
142     if (valobj_sp)
143         valobj_sp->SetSyntheticChildrenGenerated(true);
144     return valobj_sp;
145 }
146
147 lldb::ValueObjectSP
148 SyntheticChildrenFrontEnd::CreateValueObjectFromData (const char* name,
149                                                       const DataExtractor& data,
150                                                       const ExecutionContext& exe_ctx,
151                                                       ClangASTType type)
152 {
153     ValueObjectSP valobj_sp(ValueObject::CreateValueObjectFromData(name, data, exe_ctx, type));
154     if (valobj_sp)
155         valobj_sp->SetSyntheticChildrenGenerated(true);
156     return valobj_sp;
157 }
158
159 #ifndef LLDB_DISABLE_PYTHON
160
161 ScriptedSyntheticChildren::FrontEnd::FrontEnd(std::string pclass, ValueObject &backend) :
162 SyntheticChildrenFrontEnd(backend),
163 m_python_class(pclass),
164 m_wrapper_sp(),
165 m_interpreter(NULL)
166 {
167     if (backend == LLDB_INVALID_UID)
168         return;
169     
170     TargetSP target_sp = backend.GetTargetSP();
171     
172     if (!target_sp)
173         return;
174     
175     m_interpreter = target_sp->GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
176     
177     if (m_interpreter != NULL)
178         m_wrapper_sp = m_interpreter->CreateSyntheticScriptedProvider(m_python_class.c_str(), backend.GetSP());
179 }
180
181 ScriptedSyntheticChildren::FrontEnd::~FrontEnd()
182 {
183 }
184
185 lldb::ValueObjectSP
186 ScriptedSyntheticChildren::FrontEnd::GetChildAtIndex (size_t idx)
187 {
188     if (!m_wrapper_sp || !m_interpreter)
189         return lldb::ValueObjectSP();
190     
191     return m_interpreter->GetChildAtIndex(m_wrapper_sp, idx);
192 }
193
194 bool
195 ScriptedSyntheticChildren::FrontEnd::IsValid ()
196 {
197     return (m_wrapper_sp && m_wrapper_sp->IsValid() && m_interpreter);
198 }
199
200 size_t
201 ScriptedSyntheticChildren::FrontEnd::CalculateNumChildren ()
202 {
203     if (!m_wrapper_sp || m_interpreter == NULL)
204         return 0;
205     return m_interpreter->CalculateNumChildren(m_wrapper_sp);
206 }
207
208 bool
209 ScriptedSyntheticChildren::FrontEnd::Update ()
210 {
211     if (!m_wrapper_sp || m_interpreter == NULL)
212         return false;
213     
214     return m_interpreter->UpdateSynthProviderInstance(m_wrapper_sp);
215 }
216
217 bool
218 ScriptedSyntheticChildren::FrontEnd::MightHaveChildren ()
219 {
220     if (!m_wrapper_sp || m_interpreter == NULL)
221         return false;
222     
223     return m_interpreter->MightHaveChildrenSynthProviderInstance(m_wrapper_sp);
224 }
225
226 size_t
227 ScriptedSyntheticChildren::FrontEnd::GetIndexOfChildWithName (const ConstString &name)
228 {
229     if (!m_wrapper_sp || m_interpreter == NULL)
230         return UINT32_MAX;
231     return m_interpreter->GetIndexOfChildWithName(m_wrapper_sp, name.GetCString());
232 }
233
234 lldb::ValueObjectSP
235 ScriptedSyntheticChildren::FrontEnd::GetSyntheticValue ()
236 {
237     if (!m_wrapper_sp || m_interpreter == NULL)
238         return nullptr;
239     
240     return m_interpreter->GetSyntheticValue(m_wrapper_sp);
241 }
242
243 std::string
244 ScriptedSyntheticChildren::GetDescription()
245 {
246     StreamString sstr;
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());
252     
253     return sstr.GetString();
254 }
255
256 #endif // #ifndef LLDB_DISABLE_PYTHON