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
11
12#include "lldb/API/SBStream.h"
18
19#include "lldb/Core/Debugger.h"
23
24using namespace lldb;
25using namespace lldb_private;
26
27typedef std::pair<lldb::TypeCategoryImplSP, user_id_t> ImplType;
28
30
33}
34
36 : m_opaque_sp(rhs.m_opaque_sp) {
37 LLDB_INSTRUMENT_VA(this, rhs);
38}
39
41
44 return this->operator bool();
45}
46SBTypeCategory::operator bool() const {
48
49 return (m_opaque_sp.get() != nullptr);
50}
51
54
55 if (!IsValid())
56 return false;
57 return m_opaque_sp->IsEnabled();
58}
59
60void SBTypeCategory::SetEnabled(bool enabled) {
61 LLDB_INSTRUMENT_VA(this, enabled);
62
63 if (!IsValid())
64 return;
65 if (enabled)
67 else
69}
70
73
74 if (!IsValid())
75 return nullptr;
76 return ConstString(m_opaque_sp->GetName()).GetCString();
77}
78
80 LLDB_INSTRUMENT_VA(this, idx);
81
82 if (IsValid())
83 return m_opaque_sp->GetLanguageAtIndex(idx);
85}
86
89
90 if (IsValid())
91 return m_opaque_sp->GetNumLanguages();
92 return 0;
93}
94
96 LLDB_INSTRUMENT_VA(this, language);
97
98 if (IsValid())
99 m_opaque_sp->AddLanguage(language);
100}
101
103 LLDB_INSTRUMENT_VA(this);
104
105 if (!IsValid())
106 return 0;
107
108 return m_opaque_sp->GetNumFormats();
109}
110
112 LLDB_INSTRUMENT_VA(this);
113
114 if (!IsValid())
115 return 0;
116 return m_opaque_sp->GetNumSummaries();
117}
118
120 LLDB_INSTRUMENT_VA(this);
121
122 if (!IsValid())
123 return 0;
124 return m_opaque_sp->GetNumFilters();
125}
126
128 LLDB_INSTRUMENT_VA(this);
129
130 if (!IsValid())
131 return 0;
132 return m_opaque_sp->GetNumSynthetics();
133}
134
137 LLDB_INSTRUMENT_VA(this, index);
138
139 if (!IsValid())
140 return SBTypeNameSpecifier();
141 return SBTypeNameSpecifier(
142 m_opaque_sp->GetTypeNameSpecifierForFilterAtIndex(index));
143}
144
147 LLDB_INSTRUMENT_VA(this, index);
148
149 if (!IsValid())
150 return SBTypeNameSpecifier();
151 return SBTypeNameSpecifier(
152 m_opaque_sp->GetTypeNameSpecifierForFormatAtIndex(index));
153}
154
157 LLDB_INSTRUMENT_VA(this, index);
158
159 if (!IsValid())
160 return SBTypeNameSpecifier();
161 return SBTypeNameSpecifier(
162 m_opaque_sp->GetTypeNameSpecifierForSummaryAtIndex(index));
163}
164
167 LLDB_INSTRUMENT_VA(this, index);
168
169 if (!IsValid())
170 return SBTypeNameSpecifier();
171 return SBTypeNameSpecifier(
172 m_opaque_sp->GetTypeNameSpecifierForSyntheticAtIndex(index));
173}
174
176 LLDB_INSTRUMENT_VA(this, spec);
177
178 if (!IsValid())
179 return SBTypeFilter();
180
181 if (!spec.IsValid())
182 return SBTypeFilter();
183
184 lldb::TypeFilterImplSP children_sp =
185 m_opaque_sp->GetFilterForType(spec.GetSP());
186
187 if (!children_sp)
188 return lldb::SBTypeFilter();
189
190 TypeFilterImplSP filter_sp =
191 std::static_pointer_cast<TypeFilterImpl>(children_sp);
192
193 return lldb::SBTypeFilter(filter_sp);
194}
196 LLDB_INSTRUMENT_VA(this, spec);
197
198 if (!IsValid())
199 return SBTypeFormat();
200
201 if (!spec.IsValid())
202 return SBTypeFormat();
203
204 lldb::TypeFormatImplSP format_sp =
205 m_opaque_sp->GetFormatForType(spec.GetSP());
206
207 if (!format_sp)
208 return lldb::SBTypeFormat();
209
210 return lldb::SBTypeFormat(format_sp);
211}
212
214 LLDB_INSTRUMENT_VA(this, spec);
215
216 if (!IsValid())
217 return SBTypeSummary();
218
219 if (!spec.IsValid())
220 return SBTypeSummary();
221
222 lldb::TypeSummaryImplSP summary_sp =
223 m_opaque_sp->GetSummaryForType(spec.GetSP());
224
225 if (!summary_sp)
226 return lldb::SBTypeSummary();
227
228 return lldb::SBTypeSummary(summary_sp);
229}
230
232 LLDB_INSTRUMENT_VA(this, spec);
233
234 if (!IsValid())
235 return SBTypeSynthetic();
236
237 if (!spec.IsValid())
238 return SBTypeSynthetic();
239
240 lldb::SyntheticChildrenSP children_sp =
241 m_opaque_sp->GetSyntheticForType(spec.GetSP());
242
243 if (!children_sp)
244 return lldb::SBTypeSynthetic();
245
247 std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp);
248
249 return lldb::SBTypeSynthetic(synth_sp);
250}
251
253 LLDB_INSTRUMENT_VA(this, index);
254
255 if (!IsValid())
256 return SBTypeFilter();
257 lldb::SyntheticChildrenSP children_sp =
258 m_opaque_sp->GetSyntheticAtIndex((index));
259
260 if (!children_sp.get())
261 return lldb::SBTypeFilter();
262
263 TypeFilterImplSP filter_sp =
264 std::static_pointer_cast<TypeFilterImpl>(children_sp);
265
266 return lldb::SBTypeFilter(filter_sp);
267}
268
270 LLDB_INSTRUMENT_VA(this, index);
271
272 if (!IsValid())
273 return SBTypeFormat();
274 return SBTypeFormat(m_opaque_sp->GetFormatAtIndex((index)));
275}
276
278 LLDB_INSTRUMENT_VA(this, index);
279
280 if (!IsValid())
281 return SBTypeSummary();
282 return SBTypeSummary(m_opaque_sp->GetSummaryAtIndex((index)));
283}
284
286 LLDB_INSTRUMENT_VA(this, index);
287
288 if (!IsValid())
289 return SBTypeSynthetic();
290 lldb::SyntheticChildrenSP children_sp =
291 m_opaque_sp->GetSyntheticAtIndex((index));
292
293 if (!children_sp.get())
294 return lldb::SBTypeSynthetic();
295
297 std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp);
298
299 return lldb::SBTypeSynthetic(synth_sp);
300}
301
303 SBTypeFormat format) {
304 LLDB_INSTRUMENT_VA(this, type_name, format);
305
306 if (!IsValid())
307 return false;
308
309 if (!type_name.IsValid())
310 return false;
311
312 if (!format.IsValid())
313 return false;
314
315 m_opaque_sp->AddTypeFormat(type_name.GetSP(), format.GetSP());
316 return true;
317}
318
320 LLDB_INSTRUMENT_VA(this, type_name);
321
322 if (!IsValid())
323 return false;
324
325 if (!type_name.IsValid())
326 return false;
327
328 return m_opaque_sp->DeleteTypeFormat(type_name.GetSP());
329}
330
332 SBTypeSummary summary) {
333 LLDB_INSTRUMENT_VA(this, type_name, summary);
334
335 if (!IsValid())
336 return false;
337
338 if (!type_name.IsValid())
339 return false;
340
341 if (!summary.IsValid())
342 return false;
343
344 // FIXME: we need to iterate over all the Debugger objects and have each of
345 // them contain a copy of the function
346 // since we currently have formatters live in a global space, while Python
347 // code lives in a specific Debugger-related environment this should
348 // eventually be fixed by deciding a final location in the LLDB object space
349 // for formatters
350 if (summary.IsFunctionCode()) {
351 const void *name_token =
352 (const void *)ConstString(type_name.GetName()).GetCString();
353 const char *script = summary.GetData();
354 StringList input;
355 input.SplitIntoLines(script, strlen(script));
356 uint32_t num_debuggers = lldb_private::Debugger::GetNumDebuggers();
357 bool need_set = true;
358 for (uint32_t j = 0; j < num_debuggers; j++) {
360 if (debugger_sp) {
361 ScriptInterpreter *interpreter_ptr =
362 debugger_sp->GetScriptInterpreter();
363 if (interpreter_ptr) {
364 std::string output;
365 if (interpreter_ptr->GenerateTypeScriptFunction(input, output,
366 name_token) &&
367 !output.empty()) {
368 if (need_set) {
369 need_set = false;
370 summary.SetFunctionName(output.c_str());
371 }
372 }
373 }
374 }
375 }
376 }
377
378 m_opaque_sp->AddTypeSummary(type_name.GetSP(), summary.GetSP());
379 return true;
380}
381
383 LLDB_INSTRUMENT_VA(this, type_name);
384
385 if (!IsValid())
386 return false;
387
388 if (!type_name.IsValid())
389 return false;
390
391 return m_opaque_sp->DeleteTypeSummary(type_name.GetSP());
392}
393
395 SBTypeFilter filter) {
396 LLDB_INSTRUMENT_VA(this, type_name, filter);
397
398 if (!IsValid())
399 return false;
400
401 if (!type_name.IsValid())
402 return false;
403
404 if (!filter.IsValid())
405 return false;
406
407 m_opaque_sp->AddTypeFilter(type_name.GetSP(), filter.GetSP());
408 return true;
409}
410
412 LLDB_INSTRUMENT_VA(this, type_name);
413
414 if (!IsValid())
415 return false;
416
417 if (!type_name.IsValid())
418 return false;
419
420 return m_opaque_sp->DeleteTypeFilter(type_name.GetSP());
421}
422
424 SBTypeSynthetic synth) {
425 LLDB_INSTRUMENT_VA(this, type_name, synth);
426
427 if (!IsValid())
428 return false;
429
430 if (!type_name.IsValid())
431 return false;
432
433 if (!synth.IsValid())
434 return false;
435
436 // FIXME: we need to iterate over all the Debugger objects and have each of
437 // them contain a copy of the function
438 // since we currently have formatters live in a global space, while Python
439 // code lives in a specific Debugger-related environment this should
440 // eventually be fixed by deciding a final location in the LLDB object space
441 // for formatters
442 if (synth.IsClassCode()) {
443 const void *name_token =
444 (const void *)ConstString(type_name.GetName()).GetCString();
445 const char *script = synth.GetData();
446 StringList input;
447 input.SplitIntoLines(script, strlen(script));
448 uint32_t num_debuggers = lldb_private::Debugger::GetNumDebuggers();
449 bool need_set = true;
450 for (uint32_t j = 0; j < num_debuggers; j++) {
452 if (debugger_sp) {
453 ScriptInterpreter *interpreter_ptr =
454 debugger_sp->GetScriptInterpreter();
455 if (interpreter_ptr) {
456 std::string output;
457 if (interpreter_ptr->GenerateTypeSynthClass(input, output,
458 name_token) &&
459 !output.empty()) {
460 if (need_set) {
461 need_set = false;
462 synth.SetClassName(output.c_str());
463 }
464 }
465 }
466 }
467 }
468 }
469
470 m_opaque_sp->AddTypeSynthetic(type_name.GetSP(), synth.GetSP());
471 return true;
472}
473
475 LLDB_INSTRUMENT_VA(this, type_name);
476
477 if (!IsValid())
478 return false;
479
480 if (!type_name.IsValid())
481 return false;
482
483 return m_opaque_sp->DeleteTypeSynthetic(type_name.GetSP());
484}
485
487 lldb::DescriptionLevel description_level) {
488 LLDB_INSTRUMENT_VA(this, description, description_level);
489
490 if (!IsValid())
491 return false;
492 description.Printf("Category name: %s\n", GetName());
493 return true;
494}
495
498 LLDB_INSTRUMENT_VA(this, rhs);
499
500 if (this != &rhs) {
502 }
503 return *this;
504}
505
507 LLDB_INSTRUMENT_VA(this, rhs);
508
509 if (!IsValid())
510 return !rhs.IsValid();
511
512 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
513}
514
516 LLDB_INSTRUMENT_VA(this, rhs);
517
518 if (!IsValid())
519 return rhs.IsValid();
520
521 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
522}
523
525 if (!IsValid())
527 return m_opaque_sp;
528}
529
531 const lldb::TypeCategoryImplSP &typecategory_impl_sp) {
532 m_opaque_sp = typecategory_impl_sp;
533}
534
536 const lldb::TypeCategoryImplSP &typecategory_impl_sp)
537 : m_opaque_sp(typecategory_impl_sp) {}
538
540 if (!IsValid())
541 return false;
542
543 return (strcmp(m_opaque_sp->GetName(), "default") == 0);
544}
#define LLDB_INSTRUMENT_VA(...)
std::pair< lldb::TypeCategoryImplSP, user_id_t > ImplType
SBTypeSynthetic GetSyntheticForType(SBTypeNameSpecifier)
bool AddTypeFilter(SBTypeNameSpecifier, SBTypeFilter)
const char * GetName()
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.
Definition: ConstString.h:214
static void Disable(ConstString category)
static void Enable(ConstString category, TypeCategoryMap::Position=TypeCategoryMap::Default)
static bool GetCategory(ConstString category, lldb::TypeCategoryImplSP &entry, bool allow_create=true)
static lldb::DebuggerSP GetDebuggerAtIndex(size_t index)
Definition: Debugger.cpp:1342
static size_t GetNumDebuggers()
Definition: Debugger.cpp:1334
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)
Definition: StringList.cpp:152
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::TypeSummaryImpl > TypeSummaryImplSP
Definition: lldb-forward.h:463
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
std::shared_ptr< lldb_private::TypeFormatImpl > TypeFormatImplSP
Definition: lldb-forward.h:460
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
std::shared_ptr< lldb_private::Debugger > DebuggerSP
Definition: lldb-forward.h:331
std::shared_ptr< lldb_private::SyntheticChildren > SyntheticChildrenSP
Definition: lldb-forward.h:433
std::shared_ptr< lldb_private::TypeCategoryImpl > TypeCategoryImplSP
Definition: lldb-forward.h:451
std::shared_ptr< lldb_private::ScriptedSyntheticChildren > ScriptedSyntheticChildrenSP
Definition: lldb-forward.h:466
std::shared_ptr< lldb_private::TypeFilterImpl > TypeFilterImplSP
Definition: lldb-forward.h:456