LLDB mainline
SBTypeCategory.cpp
Go to the documentation of this file.
1//===-- SBTypeCategory.cpp ------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
12
13#include "lldb/API/SBStream.h"
19
20#include "lldb/Core/Debugger.h"
24
25using namespace lldb;
26using namespace lldb_private;
27
28typedef std::pair<lldb::TypeCategoryImplSP, user_id_t> ImplType;
29
31
35
40
42
45 return this->operator bool();
46}
47SBTypeCategory::operator bool() const {
49
50 return (m_opaque_sp.get() != nullptr);
51}
52
55
56 if (!IsValid())
57 return false;
58 return m_opaque_sp->IsEnabled();
59}
60
61void SBTypeCategory::SetEnabled(bool enabled) {
62 LLDB_INSTRUMENT_VA(this, enabled);
63
64 if (!IsValid())
65 return;
66 if (enabled)
68 else
70}
71
74
75 if (!IsValid())
76 return nullptr;
77 return StringPool::GetSystemPool().Intern(m_opaque_sp->GetName());
78}
79
81 LLDB_INSTRUMENT_VA(this, idx);
82
83 if (IsValid())
84 return m_opaque_sp->GetLanguageAtIndex(idx);
86}
87
90
91 if (IsValid())
92 return m_opaque_sp->GetNumLanguages();
93 return 0;
94}
95
97 LLDB_INSTRUMENT_VA(this, language);
98
99 if (IsValid())
100 m_opaque_sp->AddLanguage(language);
101}
102
104 LLDB_INSTRUMENT_VA(this);
105
106 if (!IsValid())
107 return 0;
108
109 return m_opaque_sp->GetNumFormats();
110}
111
113 LLDB_INSTRUMENT_VA(this);
114
115 if (!IsValid())
116 return 0;
117 return m_opaque_sp->GetNumSummaries();
118}
119
121 LLDB_INSTRUMENT_VA(this);
122
123 if (!IsValid())
124 return 0;
125 return m_opaque_sp->GetNumFilters();
126}
127
129 LLDB_INSTRUMENT_VA(this);
130
131 if (!IsValid())
132 return 0;
133 return m_opaque_sp->GetNumSynthetics();
134}
135
138 LLDB_INSTRUMENT_VA(this, index);
139
140 if (!IsValid())
141 return SBTypeNameSpecifier();
142 return SBTypeNameSpecifier(
143 m_opaque_sp->GetTypeNameSpecifierForFilterAtIndex(index));
144}
145
148 LLDB_INSTRUMENT_VA(this, index);
149
150 if (!IsValid())
151 return SBTypeNameSpecifier();
152 return SBTypeNameSpecifier(
153 m_opaque_sp->GetTypeNameSpecifierForFormatAtIndex(index));
154}
155
158 LLDB_INSTRUMENT_VA(this, index);
159
160 if (!IsValid())
161 return SBTypeNameSpecifier();
162 return SBTypeNameSpecifier(
163 m_opaque_sp->GetTypeNameSpecifierForSummaryAtIndex(index));
164}
165
168 LLDB_INSTRUMENT_VA(this, index);
169
170 if (!IsValid())
171 return SBTypeNameSpecifier();
172 return SBTypeNameSpecifier(
173 m_opaque_sp->GetTypeNameSpecifierForSyntheticAtIndex(index));
174}
175
177 LLDB_INSTRUMENT_VA(this, spec);
178
179 if (!IsValid())
180 return SBTypeFilter();
181
182 if (!spec.IsValid())
183 return SBTypeFilter();
184
185 lldb::TypeFilterImplSP children_sp =
186 m_opaque_sp->GetFilterForType(spec.GetSP());
187
188 if (!children_sp)
189 return lldb::SBTypeFilter();
190
191 TypeFilterImplSP filter_sp =
192 std::static_pointer_cast<TypeFilterImpl>(children_sp);
193
194 return lldb::SBTypeFilter(filter_sp);
195}
197 LLDB_INSTRUMENT_VA(this, spec);
198
199 if (!IsValid())
200 return SBTypeFormat();
201
202 if (!spec.IsValid())
203 return SBTypeFormat();
204
205 lldb::TypeFormatImplSP format_sp =
206 m_opaque_sp->GetFormatForType(spec.GetSP());
207
208 if (!format_sp)
209 return lldb::SBTypeFormat();
210
211 return lldb::SBTypeFormat(format_sp);
212}
213
215 LLDB_INSTRUMENT_VA(this, spec);
216
217 if (!IsValid())
218 return SBTypeSummary();
219
220 if (!spec.IsValid())
221 return SBTypeSummary();
222
223 lldb::TypeSummaryImplSP summary_sp =
224 m_opaque_sp->GetSummaryForType(spec.GetSP());
225
226 if (!summary_sp)
227 return lldb::SBTypeSummary();
228
229 return lldb::SBTypeSummary(summary_sp);
230}
231
233 LLDB_INSTRUMENT_VA(this, spec);
234
235 if (!IsValid())
236 return SBTypeSynthetic();
237
238 if (!spec.IsValid())
239 return SBTypeSynthetic();
240
241 lldb::SyntheticChildrenSP children_sp =
242 m_opaque_sp->GetSyntheticForType(spec.GetSP());
243
244 if (!children_sp)
245 return lldb::SBTypeSynthetic();
246
248 std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp);
249
250 return lldb::SBTypeSynthetic(synth_sp);
251}
252
254 LLDB_INSTRUMENT_VA(this, index);
255
256 if (!IsValid())
257 return SBTypeFilter();
258 return SBTypeFilter(m_opaque_sp->GetFilterAtIndex(index));
259}
260
262 LLDB_INSTRUMENT_VA(this, index);
263
264 if (!IsValid())
265 return SBTypeFormat();
266 return SBTypeFormat(m_opaque_sp->GetFormatAtIndex((index)));
267}
268
270 LLDB_INSTRUMENT_VA(this, index);
271
272 if (!IsValid())
273 return SBTypeSummary();
274 return SBTypeSummary(m_opaque_sp->GetSummaryAtIndex((index)));
275}
276
278 LLDB_INSTRUMENT_VA(this, index);
279
280 if (!IsValid())
281 return SBTypeSynthetic();
282 lldb::SyntheticChildrenSP children_sp =
283 m_opaque_sp->GetSyntheticAtIndex((index));
284
285 if (!children_sp.get())
286 return lldb::SBTypeSynthetic();
287
289 std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp);
290
291 return lldb::SBTypeSynthetic(synth_sp);
292}
293
295 SBTypeFormat format) {
296 LLDB_INSTRUMENT_VA(this, type_name, format);
297
298 if (!IsValid())
299 return false;
300
301 if (!type_name.IsValid())
302 return false;
303
304 if (!format.IsValid())
305 return false;
306
307 m_opaque_sp->AddTypeFormat(type_name.GetSP(), format.GetSP());
308 return true;
309}
310
312 LLDB_INSTRUMENT_VA(this, type_name);
313
314 if (!IsValid())
315 return false;
316
317 if (!type_name.IsValid())
318 return false;
319
320 return m_opaque_sp->DeleteTypeFormat(type_name.GetSP());
321}
322
324 SBTypeSummary summary) {
325 LLDB_INSTRUMENT_VA(this, type_name, summary);
326
327 if (!IsValid())
328 return false;
329
330 if (!type_name.IsValid())
331 return false;
332
333 if (!summary.IsValid())
334 return false;
335
336 // FIXME: we need to iterate over all the Debugger objects and have each of
337 // them contain a copy of the function
338 // since we currently have formatters live in a global space, while Python
339 // code lives in a specific Debugger-related environment this should
340 // eventually be fixed by deciding a final location in the LLDB object space
341 // for formatters
342 if (summary.IsFunctionCode()) {
343 const void *name_token =
344 (const void *)ConstString(type_name.GetName()).GetCString();
345 const char *script = summary.GetData();
346 StringList input;
347 input.SplitIntoLines(script, strlen(script));
348 uint32_t num_debuggers = lldb_private::Debugger::GetNumDebuggers();
349 bool need_set = true;
350 for (uint32_t j = 0; j < num_debuggers; j++) {
352 if (debugger_sp) {
353 ScriptInterpreter *interpreter_ptr =
354 debugger_sp->GetScriptInterpreter();
355 if (interpreter_ptr) {
356 std::string output;
357 if (interpreter_ptr->GenerateTypeScriptFunction(input, output,
358 name_token) &&
359 !output.empty()) {
360 if (need_set) {
361 need_set = false;
362 summary.SetFunctionName(output.c_str());
363 }
364 }
365 }
366 }
367 }
368 }
369
370 m_opaque_sp->AddTypeSummary(type_name.GetSP(), summary.GetSP());
371 return true;
372}
373
375 LLDB_INSTRUMENT_VA(this, type_name);
376
377 if (!IsValid())
378 return false;
379
380 if (!type_name.IsValid())
381 return false;
382
383 return m_opaque_sp->DeleteTypeSummary(type_name.GetSP());
384}
385
387 SBTypeFilter filter) {
388 LLDB_INSTRUMENT_VA(this, type_name, filter);
389
390 if (!IsValid())
391 return false;
392
393 if (!type_name.IsValid())
394 return false;
395
396 if (!filter.IsValid())
397 return false;
398
399 m_opaque_sp->AddTypeFilter(type_name.GetSP(), filter.GetSP());
400 return true;
401}
402
404 LLDB_INSTRUMENT_VA(this, type_name);
405
406 if (!IsValid())
407 return false;
408
409 if (!type_name.IsValid())
410 return false;
411
412 return m_opaque_sp->DeleteTypeFilter(type_name.GetSP());
413}
414
416 SBTypeSynthetic synth) {
417 LLDB_INSTRUMENT_VA(this, type_name, synth);
418
419 if (!IsValid())
420 return false;
421
422 if (!type_name.IsValid())
423 return false;
424
425 if (!synth.IsValid())
426 return false;
427
428 // FIXME: we need to iterate over all the Debugger objects and have each of
429 // them contain a copy of the function
430 // since we currently have formatters live in a global space, while Python
431 // code lives in a specific Debugger-related environment this should
432 // eventually be fixed by deciding a final location in the LLDB object space
433 // for formatters
434 if (synth.IsClassCode()) {
435 const void *name_token =
436 (const void *)ConstString(type_name.GetName()).GetCString();
437 const char *script = synth.GetData();
438 StringList input;
439 input.SplitIntoLines(script, strlen(script));
440 uint32_t num_debuggers = lldb_private::Debugger::GetNumDebuggers();
441 bool need_set = true;
442 for (uint32_t j = 0; j < num_debuggers; j++) {
444 if (debugger_sp) {
445 ScriptInterpreter *interpreter_ptr =
446 debugger_sp->GetScriptInterpreter();
447 if (interpreter_ptr) {
448 std::string output;
449 if (interpreter_ptr->GenerateTypeSynthClass(input, output,
450 name_token) &&
451 !output.empty()) {
452 if (need_set) {
453 need_set = false;
454 synth.SetClassName(output.c_str());
455 }
456 }
457 }
458 }
459 }
460 }
461
462 m_opaque_sp->AddTypeSynthetic(type_name.GetSP(), synth.GetSP());
463 return true;
464}
465
467 LLDB_INSTRUMENT_VA(this, type_name);
468
469 if (!IsValid())
470 return false;
471
472 if (!type_name.IsValid())
473 return false;
474
475 return m_opaque_sp->DeleteTypeSynthetic(type_name.GetSP());
476}
477
479 lldb::DescriptionLevel description_level) {
480 LLDB_INSTRUMENT_VA(this, description, description_level);
481
482 if (!IsValid())
483 return false;
484 description.Printf("Category name: %s\n", GetName());
485 return true;
486}
487
490 LLDB_INSTRUMENT_VA(this, rhs);
491
492 if (this != &rhs) {
494 }
495 return *this;
496}
497
499 LLDB_INSTRUMENT_VA(this, rhs);
500
501 if (!IsValid())
502 return !rhs.IsValid();
503
504 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
505}
506
508 LLDB_INSTRUMENT_VA(this, rhs);
509
510 if (!IsValid())
511 return rhs.IsValid();
512
513 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
514}
515
521
523 const lldb::TypeCategoryImplSP &typecategory_impl_sp) {
524 m_opaque_sp = typecategory_impl_sp;
525}
526
528 const lldb::TypeCategoryImplSP &typecategory_impl_sp)
529 : m_opaque_sp(typecategory_impl_sp) {}
530
532 if (!IsValid())
533 return false;
534
535 return (strcmp(m_opaque_sp->GetName(), "default") == 0);
536}
#define LLDB_INSTRUMENT_VA(...)
std::pair< lldb::TypeCategoryImplSP, user_id_t > ImplType
SBTypeSynthetic GetSyntheticForType(SBTypeNameSpecifier)
bool AddTypeFilter(SBTypeNameSpecifier, SBTypeFilter)
lldb::SBTypeCategory & operator=(const lldb::SBTypeCategory &rhs)
SBTypeFormat GetFormatAtIndex(uint32_t)
lldb::LanguageType GetLanguageAtIndex(uint32_t idx)
TypeCategoryImplSP m_opaque_sp
bool DeleteTypeFilter(SBTypeNameSpecifier)
SBTypeSynthetic GetSyntheticAtIndex(uint32_t)
SBTypeNameSpecifier GetTypeNameSpecifierForSyntheticAtIndex(uint32_t)
SBTypeFormat GetFormatForType(SBTypeNameSpecifier)
bool DeleteTypeFormat(SBTypeNameSpecifier)
bool operator==(lldb::SBTypeCategory &rhs)
bool AddTypeSynthetic(SBTypeNameSpecifier, SBTypeSynthetic)
void SetSP(const lldb::TypeCategoryImplSP &typecategory_impl_sp)
SBTypeFilter GetFilterForType(SBTypeNameSpecifier)
bool DeleteTypeSummary(SBTypeNameSpecifier)
SBTypeNameSpecifier GetTypeNameSpecifierForFilterAtIndex(uint32_t)
bool GetDescription(lldb::SBStream &description, lldb::DescriptionLevel description_level)
bool AddTypeFormat(SBTypeNameSpecifier, SBTypeFormat)
bool DeleteTypeSynthetic(SBTypeNameSpecifier)
void AddLanguage(lldb::LanguageType language)
lldb::TypeCategoryImplSP GetSP()
SBTypeSummary GetSummaryAtIndex(uint32_t)
SBTypeSummary GetSummaryForType(SBTypeNameSpecifier)
SBTypeFilter GetFilterAtIndex(uint32_t)
SBTypeNameSpecifier GetTypeNameSpecifierForFormatAtIndex(uint32_t)
bool operator!=(lldb::SBTypeCategory &rhs)
SBTypeNameSpecifier GetTypeNameSpecifierForSummaryAtIndex(uint32_t)
bool AddTypeSummary(SBTypeNameSpecifier, SBTypeSummary)
bool IsValid() const
lldb::TypeFilterImplSP GetSP()
bool IsValid() const
lldb::TypeFormatImplSP GetSP()
lldb::TypeNameSpecifierImplSP GetSP()
const char * GetData()
void SetFunctionName(const char *data)
lldb::TypeSummaryImplSP GetSP()
lldb::ScriptedSyntheticChildrenSP GetSP()
void SetClassName(const char *data)
A uniqued constant string class.
Definition ConstString.h:40
const char * GetCString() const
Get the string value as a C string.
static bool GetCategory(llvm::StringRef category, lldb::TypeCategoryImplSP &entry, bool allow_create=true)
static void Disable(llvm::StringRef category)
static void Enable(llvm::StringRef category, TypeCategoryMap::Position=TypeCategoryMap::Default)
static lldb::DebuggerSP GetDebuggerAtIndex(size_t index)
static size_t GetNumDebuggers()
virtual bool GenerateTypeScriptFunction(const char *oneliner, std::string &output, const void *name_token=nullptr)
virtual bool GenerateTypeSynthClass(StringList &input, std::string &output, const void *name_token=nullptr)
size_t SplitIntoLines(const std::string &lines)
const char * Intern(llvm::StringRef str) const
Definition StringPool.h:78
static StringPoolRef GetSystemPool()
The system pool. Only valid between Initialize and Terminate.
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::TypeSummaryImpl > TypeSummaryImplSP
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
std::shared_ptr< lldb_private::TypeFormatImpl > TypeFormatImplSP
class LLDB_API SBTypeNameSpecifier
Definition SBDefines.h:132
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
class LLDB_API SBTypeFilter
Definition SBDefines.h:128
class LLDB_API SBTypeFormat
Definition SBDefines.h:129
std::shared_ptr< lldb_private::Debugger > DebuggerSP
std::shared_ptr< lldb_private::SyntheticChildren > SyntheticChildrenSP
std::shared_ptr< lldb_private::TypeCategoryImpl > TypeCategoryImplSP
std::shared_ptr< lldb_private::ScriptedSyntheticChildren > ScriptedSyntheticChildrenSP
std::shared_ptr< lldb_private::TypeFilterImpl > TypeFilterImplSP
class LLDB_API SBTypeSynthetic
Definition SBDefines.h:136
class LLDB_API SBTypeSummary
Definition SBDefines.h:134