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
9 #include "lldb/API/SBTypeCategory.h"
10 #include "SBReproducerPrivate.h"
11
12 #include "lldb/API/SBStream.h"
13 #include "lldb/API/SBTypeFilter.h"
14 #include "lldb/API/SBTypeFormat.h"
15 #include "lldb/API/SBTypeNameSpecifier.h"
16 #include "lldb/API/SBTypeSummary.h"
17 #include "lldb/API/SBTypeSynthetic.h"
18
19 #include "lldb/Core/Debugger.h"
20 #include "lldb/DataFormatters/DataVisualization.h"
21 #include "lldb/Interpreter/CommandInterpreter.h"
22 #include "lldb/Interpreter/ScriptInterpreter.h"
23
24 using namespace lldb;
25 using namespace lldb_private;
26
27 typedef std::pair<lldb::TypeCategoryImplSP, user_id_t> ImplType;
28
SBTypeCategory()29 SBTypeCategory::SBTypeCategory() : m_opaque_sp() {
30 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTypeCategory);
31 }
32
SBTypeCategory(const char * name)33 SBTypeCategory::SBTypeCategory(const char *name) : m_opaque_sp() {
34 DataVisualization::Categories::GetCategory(ConstString(name), m_opaque_sp);
35 }
36
SBTypeCategory(const lldb::SBTypeCategory & rhs)37 SBTypeCategory::SBTypeCategory(const lldb::SBTypeCategory &rhs)
38 : m_opaque_sp(rhs.m_opaque_sp) {
39 LLDB_RECORD_CONSTRUCTOR(SBTypeCategory, (const lldb::SBTypeCategory &), rhs);
40 }
41
42 SBTypeCategory::~SBTypeCategory() = default;
43
IsValid() const44 bool SBTypeCategory::IsValid() const {
45 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeCategory, IsValid);
46 return this->operator bool();
47 }
operator bool() const48 SBTypeCategory::operator bool() const {
49 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeCategory, operator bool);
50
51 return (m_opaque_sp.get() != nullptr);
52 }
53
GetEnabled()54 bool SBTypeCategory::GetEnabled() {
55 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTypeCategory, GetEnabled);
56
57 if (!IsValid())
58 return false;
59 return m_opaque_sp->IsEnabled();
60 }
61
SetEnabled(bool enabled)62 void SBTypeCategory::SetEnabled(bool enabled) {
63 LLDB_RECORD_METHOD(void, SBTypeCategory, SetEnabled, (bool), enabled);
64
65 if (!IsValid())
66 return;
67 if (enabled)
68 DataVisualization::Categories::Enable(m_opaque_sp);
69 else
70 DataVisualization::Categories::Disable(m_opaque_sp);
71 }
72
GetName()73 const char *SBTypeCategory::GetName() {
74 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTypeCategory, GetName);
75
76 if (!IsValid())
77 return nullptr;
78 return m_opaque_sp->GetName();
79 }
80
GetLanguageAtIndex(uint32_t idx)81 lldb::LanguageType SBTypeCategory::GetLanguageAtIndex(uint32_t idx) {
82 LLDB_RECORD_METHOD(lldb::LanguageType, SBTypeCategory, GetLanguageAtIndex,
83 (uint32_t), idx);
84
85 if (IsValid())
86 return m_opaque_sp->GetLanguageAtIndex(idx);
87 return lldb::eLanguageTypeUnknown;
88 }
89
GetNumLanguages()90 uint32_t SBTypeCategory::GetNumLanguages() {
91 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTypeCategory, GetNumLanguages);
92
93 if (IsValid())
94 return m_opaque_sp->GetNumLanguages();
95 return 0;
96 }
97
AddLanguage(lldb::LanguageType language)98 void SBTypeCategory::AddLanguage(lldb::LanguageType language) {
99 LLDB_RECORD_METHOD(void, SBTypeCategory, AddLanguage, (lldb::LanguageType),
100 language);
101
102 if (IsValid())
103 m_opaque_sp->AddLanguage(language);
104 }
105
GetNumFormats()106 uint32_t SBTypeCategory::GetNumFormats() {
107 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTypeCategory, GetNumFormats);
108
109 if (!IsValid())
110 return 0;
111
112 return m_opaque_sp->GetTypeFormatsContainer()->GetCount() +
113 m_opaque_sp->GetRegexTypeFormatsContainer()->GetCount();
114 }
115
GetNumSummaries()116 uint32_t SBTypeCategory::GetNumSummaries() {
117 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTypeCategory, GetNumSummaries);
118
119 if (!IsValid())
120 return 0;
121 return m_opaque_sp->GetTypeSummariesContainer()->GetCount() +
122 m_opaque_sp->GetRegexTypeSummariesContainer()->GetCount();
123 }
124
GetNumFilters()125 uint32_t SBTypeCategory::GetNumFilters() {
126 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTypeCategory, GetNumFilters);
127
128 if (!IsValid())
129 return 0;
130 return m_opaque_sp->GetTypeFiltersContainer()->GetCount() +
131 m_opaque_sp->GetRegexTypeFiltersContainer()->GetCount();
132 }
133
GetNumSynthetics()134 uint32_t SBTypeCategory::GetNumSynthetics() {
135 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTypeCategory, GetNumSynthetics);
136
137 if (!IsValid())
138 return 0;
139 return m_opaque_sp->GetTypeSyntheticsContainer()->GetCount() +
140 m_opaque_sp->GetRegexTypeSyntheticsContainer()->GetCount();
141 }
142
143 lldb::SBTypeNameSpecifier
GetTypeNameSpecifierForFilterAtIndex(uint32_t index)144 SBTypeCategory::GetTypeNameSpecifierForFilterAtIndex(uint32_t index) {
145 LLDB_RECORD_METHOD(lldb::SBTypeNameSpecifier, SBTypeCategory,
146 GetTypeNameSpecifierForFilterAtIndex, (uint32_t), index);
147
148 if (!IsValid())
149 return LLDB_RECORD_RESULT(SBTypeNameSpecifier());
150 return LLDB_RECORD_RESULT(SBTypeNameSpecifier(
151 m_opaque_sp->GetTypeNameSpecifierForFilterAtIndex(index)));
152 }
153
154 lldb::SBTypeNameSpecifier
GetTypeNameSpecifierForFormatAtIndex(uint32_t index)155 SBTypeCategory::GetTypeNameSpecifierForFormatAtIndex(uint32_t index) {
156 LLDB_RECORD_METHOD(lldb::SBTypeNameSpecifier, SBTypeCategory,
157 GetTypeNameSpecifierForFormatAtIndex, (uint32_t), index);
158
159 if (!IsValid())
160 return LLDB_RECORD_RESULT(SBTypeNameSpecifier());
161 return LLDB_RECORD_RESULT(SBTypeNameSpecifier(
162 m_opaque_sp->GetTypeNameSpecifierForFormatAtIndex(index)));
163 }
164
165 lldb::SBTypeNameSpecifier
GetTypeNameSpecifierForSummaryAtIndex(uint32_t index)166 SBTypeCategory::GetTypeNameSpecifierForSummaryAtIndex(uint32_t index) {
167 LLDB_RECORD_METHOD(lldb::SBTypeNameSpecifier, SBTypeCategory,
168 GetTypeNameSpecifierForSummaryAtIndex, (uint32_t), index);
169
170 if (!IsValid())
171 return LLDB_RECORD_RESULT(SBTypeNameSpecifier());
172 return LLDB_RECORD_RESULT(SBTypeNameSpecifier(
173 m_opaque_sp->GetTypeNameSpecifierForSummaryAtIndex(index)));
174 }
175
176 lldb::SBTypeNameSpecifier
GetTypeNameSpecifierForSyntheticAtIndex(uint32_t index)177 SBTypeCategory::GetTypeNameSpecifierForSyntheticAtIndex(uint32_t index) {
178 LLDB_RECORD_METHOD(lldb::SBTypeNameSpecifier, SBTypeCategory,
179 GetTypeNameSpecifierForSyntheticAtIndex, (uint32_t),
180 index);
181
182 if (!IsValid())
183 return LLDB_RECORD_RESULT(SBTypeNameSpecifier());
184 return LLDB_RECORD_RESULT(SBTypeNameSpecifier(
185 m_opaque_sp->GetTypeNameSpecifierForSyntheticAtIndex(index)));
186 }
187
GetFilterForType(SBTypeNameSpecifier spec)188 SBTypeFilter SBTypeCategory::GetFilterForType(SBTypeNameSpecifier spec) {
189 LLDB_RECORD_METHOD(lldb::SBTypeFilter, SBTypeCategory, GetFilterForType,
190 (lldb::SBTypeNameSpecifier), spec);
191
192 if (!IsValid())
193 return LLDB_RECORD_RESULT(SBTypeFilter());
194
195 if (!spec.IsValid())
196 return LLDB_RECORD_RESULT(SBTypeFilter());
197
198 lldb::TypeFilterImplSP children_sp;
199
200 if (spec.IsRegex())
201 m_opaque_sp->GetRegexTypeFiltersContainer()->GetExact(
202 ConstString(spec.GetName()), children_sp);
203 else
204 m_opaque_sp->GetTypeFiltersContainer()->GetExact(
205 ConstString(spec.GetName()), children_sp);
206
207 if (!children_sp)
208 return LLDB_RECORD_RESULT(lldb::SBTypeFilter());
209
210 TypeFilterImplSP filter_sp =
211 std::static_pointer_cast<TypeFilterImpl>(children_sp);
212
213 return LLDB_RECORD_RESULT(lldb::SBTypeFilter(filter_sp));
214 }
GetFormatForType(SBTypeNameSpecifier spec)215 SBTypeFormat SBTypeCategory::GetFormatForType(SBTypeNameSpecifier spec) {
216 LLDB_RECORD_METHOD(lldb::SBTypeFormat, SBTypeCategory, GetFormatForType,
217 (lldb::SBTypeNameSpecifier), spec);
218
219 if (!IsValid())
220 return LLDB_RECORD_RESULT(SBTypeFormat());
221
222 if (!spec.IsValid())
223 return LLDB_RECORD_RESULT(SBTypeFormat());
224
225 lldb::TypeFormatImplSP format_sp;
226
227 if (spec.IsRegex())
228 m_opaque_sp->GetRegexTypeFormatsContainer()->GetExact(
229 ConstString(spec.GetName()), format_sp);
230 else
231 m_opaque_sp->GetTypeFormatsContainer()->GetExact(
232 ConstString(spec.GetName()), format_sp);
233
234 if (!format_sp)
235 return LLDB_RECORD_RESULT(lldb::SBTypeFormat());
236
237 return LLDB_RECORD_RESULT(lldb::SBTypeFormat(format_sp));
238 }
239
GetSummaryForType(SBTypeNameSpecifier spec)240 SBTypeSummary SBTypeCategory::GetSummaryForType(SBTypeNameSpecifier spec) {
241 LLDB_RECORD_METHOD(lldb::SBTypeSummary, SBTypeCategory, GetSummaryForType,
242 (lldb::SBTypeNameSpecifier), spec);
243
244 if (!IsValid())
245 return LLDB_RECORD_RESULT(SBTypeSummary());
246
247 if (!spec.IsValid())
248 return LLDB_RECORD_RESULT(SBTypeSummary());
249
250 lldb::TypeSummaryImplSP summary_sp;
251
252 if (spec.IsRegex())
253 m_opaque_sp->GetRegexTypeSummariesContainer()->GetExact(
254 ConstString(spec.GetName()), summary_sp);
255 else
256 m_opaque_sp->GetTypeSummariesContainer()->GetExact(
257 ConstString(spec.GetName()), summary_sp);
258
259 if (!summary_sp)
260 return LLDB_RECORD_RESULT(lldb::SBTypeSummary());
261
262 return LLDB_RECORD_RESULT(lldb::SBTypeSummary(summary_sp));
263 }
264
GetSyntheticForType(SBTypeNameSpecifier spec)265 SBTypeSynthetic SBTypeCategory::GetSyntheticForType(SBTypeNameSpecifier spec) {
266 LLDB_RECORD_METHOD(lldb::SBTypeSynthetic, SBTypeCategory, GetSyntheticForType,
267 (lldb::SBTypeNameSpecifier), spec);
268
269 if (!IsValid())
270 return LLDB_RECORD_RESULT(SBTypeSynthetic());
271
272 if (!spec.IsValid())
273 return LLDB_RECORD_RESULT(SBTypeSynthetic());
274
275 lldb::SyntheticChildrenSP children_sp;
276
277 if (spec.IsRegex())
278 m_opaque_sp->GetRegexTypeSyntheticsContainer()->GetExact(
279 ConstString(spec.GetName()), children_sp);
280 else
281 m_opaque_sp->GetTypeSyntheticsContainer()->GetExact(
282 ConstString(spec.GetName()), children_sp);
283
284 if (!children_sp)
285 return LLDB_RECORD_RESULT(lldb::SBTypeSynthetic());
286
287 ScriptedSyntheticChildrenSP synth_sp =
288 std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp);
289
290 return LLDB_RECORD_RESULT(lldb::SBTypeSynthetic(synth_sp));
291 }
292
GetFilterAtIndex(uint32_t index)293 SBTypeFilter SBTypeCategory::GetFilterAtIndex(uint32_t index) {
294 LLDB_RECORD_METHOD(lldb::SBTypeFilter, SBTypeCategory, GetFilterAtIndex,
295 (uint32_t), index);
296
297 if (!IsValid())
298 return LLDB_RECORD_RESULT(SBTypeFilter());
299 lldb::SyntheticChildrenSP children_sp =
300 m_opaque_sp->GetSyntheticAtIndex((index));
301
302 if (!children_sp.get())
303 return LLDB_RECORD_RESULT(lldb::SBTypeFilter());
304
305 TypeFilterImplSP filter_sp =
306 std::static_pointer_cast<TypeFilterImpl>(children_sp);
307
308 return LLDB_RECORD_RESULT(lldb::SBTypeFilter(filter_sp));
309 }
310
GetFormatAtIndex(uint32_t index)311 SBTypeFormat SBTypeCategory::GetFormatAtIndex(uint32_t index) {
312 LLDB_RECORD_METHOD(lldb::SBTypeFormat, SBTypeCategory, GetFormatAtIndex,
313 (uint32_t), index);
314
315 if (!IsValid())
316 return LLDB_RECORD_RESULT(SBTypeFormat());
317 return LLDB_RECORD_RESULT(
318 SBTypeFormat(m_opaque_sp->GetFormatAtIndex((index))));
319 }
320
GetSummaryAtIndex(uint32_t index)321 SBTypeSummary SBTypeCategory::GetSummaryAtIndex(uint32_t index) {
322 LLDB_RECORD_METHOD(lldb::SBTypeSummary, SBTypeCategory, GetSummaryAtIndex,
323 (uint32_t), index);
324
325 if (!IsValid())
326 return LLDB_RECORD_RESULT(SBTypeSummary());
327 return LLDB_RECORD_RESULT(
328 SBTypeSummary(m_opaque_sp->GetSummaryAtIndex((index))));
329 }
330
GetSyntheticAtIndex(uint32_t index)331 SBTypeSynthetic SBTypeCategory::GetSyntheticAtIndex(uint32_t index) {
332 LLDB_RECORD_METHOD(lldb::SBTypeSynthetic, SBTypeCategory, GetSyntheticAtIndex,
333 (uint32_t), index);
334
335 if (!IsValid())
336 return LLDB_RECORD_RESULT(SBTypeSynthetic());
337 lldb::SyntheticChildrenSP children_sp =
338 m_opaque_sp->GetSyntheticAtIndex((index));
339
340 if (!children_sp.get())
341 return LLDB_RECORD_RESULT(lldb::SBTypeSynthetic());
342
343 ScriptedSyntheticChildrenSP synth_sp =
344 std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp);
345
346 return LLDB_RECORD_RESULT(lldb::SBTypeSynthetic(synth_sp));
347 }
348
AddTypeFormat(SBTypeNameSpecifier type_name,SBTypeFormat format)349 bool SBTypeCategory::AddTypeFormat(SBTypeNameSpecifier type_name,
350 SBTypeFormat format) {
351 LLDB_RECORD_METHOD(bool, SBTypeCategory, AddTypeFormat,
352 (lldb::SBTypeNameSpecifier, lldb::SBTypeFormat), type_name,
353 format);
354
355 if (!IsValid())
356 return false;
357
358 if (!type_name.IsValid())
359 return false;
360
361 if (!format.IsValid())
362 return false;
363
364 if (type_name.IsRegex())
365 m_opaque_sp->GetRegexTypeFormatsContainer()->Add(
366 RegularExpression(type_name.GetName()), format.GetSP());
367 else
368 m_opaque_sp->GetTypeFormatsContainer()->Add(
369 ConstString(type_name.GetName()), format.GetSP());
370
371 return true;
372 }
373
DeleteTypeFormat(SBTypeNameSpecifier type_name)374 bool SBTypeCategory::DeleteTypeFormat(SBTypeNameSpecifier type_name) {
375 LLDB_RECORD_METHOD(bool, SBTypeCategory, DeleteTypeFormat,
376 (lldb::SBTypeNameSpecifier), type_name);
377
378 if (!IsValid())
379 return false;
380
381 if (!type_name.IsValid())
382 return false;
383
384 if (type_name.IsRegex())
385 return m_opaque_sp->GetRegexTypeFormatsContainer()->Delete(
386 ConstString(type_name.GetName()));
387 else
388 return m_opaque_sp->GetTypeFormatsContainer()->Delete(
389 ConstString(type_name.GetName()));
390 }
391
AddTypeSummary(SBTypeNameSpecifier type_name,SBTypeSummary summary)392 bool SBTypeCategory::AddTypeSummary(SBTypeNameSpecifier type_name,
393 SBTypeSummary summary) {
394 LLDB_RECORD_METHOD(bool, SBTypeCategory, AddTypeSummary,
395 (lldb::SBTypeNameSpecifier, lldb::SBTypeSummary),
396 type_name, summary);
397
398 if (!IsValid())
399 return false;
400
401 if (!type_name.IsValid())
402 return false;
403
404 if (!summary.IsValid())
405 return false;
406
407 // FIXME: we need to iterate over all the Debugger objects and have each of
408 // them contain a copy of the function
409 // since we currently have formatters live in a global space, while Python
410 // code lives in a specific Debugger-related environment this should
411 // eventually be fixed by deciding a final location in the LLDB object space
412 // for formatters
413 if (summary.IsFunctionCode()) {
414 const void *name_token =
415 (const void *)ConstString(type_name.GetName()).GetCString();
416 const char *script = summary.GetData();
417 StringList input;
418 input.SplitIntoLines(script, strlen(script));
419 uint32_t num_debuggers = lldb_private::Debugger::GetNumDebuggers();
420 bool need_set = true;
421 for (uint32_t j = 0; j < num_debuggers; j++) {
422 DebuggerSP debugger_sp = lldb_private::Debugger::GetDebuggerAtIndex(j);
423 if (debugger_sp) {
424 ScriptInterpreter *interpreter_ptr =
425 debugger_sp->GetScriptInterpreter();
426 if (interpreter_ptr) {
427 std::string output;
428 if (interpreter_ptr->GenerateTypeScriptFunction(input, output,
429 name_token) &&
430 !output.empty()) {
431 if (need_set) {
432 need_set = false;
433 summary.SetFunctionName(output.c_str());
434 }
435 }
436 }
437 }
438 }
439 }
440
441 if (type_name.IsRegex())
442 m_opaque_sp->GetRegexTypeSummariesContainer()->Add(
443 RegularExpression(type_name.GetName()), summary.GetSP());
444 else
445 m_opaque_sp->GetTypeSummariesContainer()->Add(
446 ConstString(type_name.GetName()), summary.GetSP());
447
448 return true;
449 }
450
DeleteTypeSummary(SBTypeNameSpecifier type_name)451 bool SBTypeCategory::DeleteTypeSummary(SBTypeNameSpecifier type_name) {
452 LLDB_RECORD_METHOD(bool, SBTypeCategory, DeleteTypeSummary,
453 (lldb::SBTypeNameSpecifier), type_name);
454
455 if (!IsValid())
456 return false;
457
458 if (!type_name.IsValid())
459 return false;
460
461 if (type_name.IsRegex())
462 return m_opaque_sp->GetRegexTypeSummariesContainer()->Delete(
463 ConstString(type_name.GetName()));
464 else
465 return m_opaque_sp->GetTypeSummariesContainer()->Delete(
466 ConstString(type_name.GetName()));
467 }
468
AddTypeFilter(SBTypeNameSpecifier type_name,SBTypeFilter filter)469 bool SBTypeCategory::AddTypeFilter(SBTypeNameSpecifier type_name,
470 SBTypeFilter filter) {
471 LLDB_RECORD_METHOD(bool, SBTypeCategory, AddTypeFilter,
472 (lldb::SBTypeNameSpecifier, lldb::SBTypeFilter), type_name,
473 filter);
474
475 if (!IsValid())
476 return false;
477
478 if (!type_name.IsValid())
479 return false;
480
481 if (!filter.IsValid())
482 return false;
483
484 if (type_name.IsRegex())
485 m_opaque_sp->GetRegexTypeFiltersContainer()->Add(
486 RegularExpression(type_name.GetName()), filter.GetSP());
487 else
488 m_opaque_sp->GetTypeFiltersContainer()->Add(
489 ConstString(type_name.GetName()), filter.GetSP());
490
491 return true;
492 }
493
DeleteTypeFilter(SBTypeNameSpecifier type_name)494 bool SBTypeCategory::DeleteTypeFilter(SBTypeNameSpecifier type_name) {
495 LLDB_RECORD_METHOD(bool, SBTypeCategory, DeleteTypeFilter,
496 (lldb::SBTypeNameSpecifier), type_name);
497
498 if (!IsValid())
499 return false;
500
501 if (!type_name.IsValid())
502 return false;
503
504 if (type_name.IsRegex())
505 return m_opaque_sp->GetRegexTypeFiltersContainer()->Delete(
506 ConstString(type_name.GetName()));
507 else
508 return m_opaque_sp->GetTypeFiltersContainer()->Delete(
509 ConstString(type_name.GetName()));
510 }
511
AddTypeSynthetic(SBTypeNameSpecifier type_name,SBTypeSynthetic synth)512 bool SBTypeCategory::AddTypeSynthetic(SBTypeNameSpecifier type_name,
513 SBTypeSynthetic synth) {
514 LLDB_RECORD_METHOD(bool, SBTypeCategory, AddTypeSynthetic,
515 (lldb::SBTypeNameSpecifier, lldb::SBTypeSynthetic),
516 type_name, synth);
517
518 if (!IsValid())
519 return false;
520
521 if (!type_name.IsValid())
522 return false;
523
524 if (!synth.IsValid())
525 return false;
526
527 // FIXME: we need to iterate over all the Debugger objects and have each of
528 // them contain a copy of the function
529 // since we currently have formatters live in a global space, while Python
530 // code lives in a specific Debugger-related environment this should
531 // eventually be fixed by deciding a final location in the LLDB object space
532 // for formatters
533 if (synth.IsClassCode()) {
534 const void *name_token =
535 (const void *)ConstString(type_name.GetName()).GetCString();
536 const char *script = synth.GetData();
537 StringList input;
538 input.SplitIntoLines(script, strlen(script));
539 uint32_t num_debuggers = lldb_private::Debugger::GetNumDebuggers();
540 bool need_set = true;
541 for (uint32_t j = 0; j < num_debuggers; j++) {
542 DebuggerSP debugger_sp = lldb_private::Debugger::GetDebuggerAtIndex(j);
543 if (debugger_sp) {
544 ScriptInterpreter *interpreter_ptr =
545 debugger_sp->GetScriptInterpreter();
546 if (interpreter_ptr) {
547 std::string output;
548 if (interpreter_ptr->GenerateTypeSynthClass(input, output,
549 name_token) &&
550 !output.empty()) {
551 if (need_set) {
552 need_set = false;
553 synth.SetClassName(output.c_str());
554 }
555 }
556 }
557 }
558 }
559 }
560
561 if (type_name.IsRegex())
562 m_opaque_sp->GetRegexTypeSyntheticsContainer()->Add(
563 RegularExpression(type_name.GetName()), synth.GetSP());
564 else
565 m_opaque_sp->GetTypeSyntheticsContainer()->Add(
566 ConstString(type_name.GetName()), synth.GetSP());
567
568 return true;
569 }
570
DeleteTypeSynthetic(SBTypeNameSpecifier type_name)571 bool SBTypeCategory::DeleteTypeSynthetic(SBTypeNameSpecifier type_name) {
572 LLDB_RECORD_METHOD(bool, SBTypeCategory, DeleteTypeSynthetic,
573 (lldb::SBTypeNameSpecifier), type_name);
574
575 if (!IsValid())
576 return false;
577
578 if (!type_name.IsValid())
579 return false;
580
581 if (type_name.IsRegex())
582 return m_opaque_sp->GetRegexTypeSyntheticsContainer()->Delete(
583 ConstString(type_name.GetName()));
584 else
585 return m_opaque_sp->GetTypeSyntheticsContainer()->Delete(
586 ConstString(type_name.GetName()));
587 }
588
GetDescription(lldb::SBStream & description,lldb::DescriptionLevel description_level)589 bool SBTypeCategory::GetDescription(lldb::SBStream &description,
590 lldb::DescriptionLevel description_level) {
591 LLDB_RECORD_METHOD(bool, SBTypeCategory, GetDescription,
592 (lldb::SBStream &, lldb::DescriptionLevel), description,
593 description_level);
594
595 if (!IsValid())
596 return false;
597 description.Printf("Category name: %s\n", GetName());
598 return true;
599 }
600
601 lldb::SBTypeCategory &SBTypeCategory::
operator =(const lldb::SBTypeCategory & rhs)602 operator=(const lldb::SBTypeCategory &rhs) {
603 LLDB_RECORD_METHOD(lldb::SBTypeCategory &,
604 SBTypeCategory, operator=,(const lldb::SBTypeCategory &),
605 rhs);
606
607 if (this != &rhs) {
608 m_opaque_sp = rhs.m_opaque_sp;
609 }
610 return LLDB_RECORD_RESULT(*this);
611 }
612
operator ==(lldb::SBTypeCategory & rhs)613 bool SBTypeCategory::operator==(lldb::SBTypeCategory &rhs) {
614 LLDB_RECORD_METHOD(bool, SBTypeCategory, operator==,(lldb::SBTypeCategory &),
615 rhs);
616
617 if (!IsValid())
618 return !rhs.IsValid();
619
620 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
621 }
622
operator !=(lldb::SBTypeCategory & rhs)623 bool SBTypeCategory::operator!=(lldb::SBTypeCategory &rhs) {
624 LLDB_RECORD_METHOD(bool, SBTypeCategory, operator!=,(lldb::SBTypeCategory &),
625 rhs);
626
627 if (!IsValid())
628 return rhs.IsValid();
629
630 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
631 }
632
GetSP()633 lldb::TypeCategoryImplSP SBTypeCategory::GetSP() {
634 if (!IsValid())
635 return lldb::TypeCategoryImplSP();
636 return m_opaque_sp;
637 }
638
SetSP(const lldb::TypeCategoryImplSP & typecategory_impl_sp)639 void SBTypeCategory::SetSP(
640 const lldb::TypeCategoryImplSP &typecategory_impl_sp) {
641 m_opaque_sp = typecategory_impl_sp;
642 }
643
SBTypeCategory(const lldb::TypeCategoryImplSP & typecategory_impl_sp)644 SBTypeCategory::SBTypeCategory(
645 const lldb::TypeCategoryImplSP &typecategory_impl_sp)
646 : m_opaque_sp(typecategory_impl_sp) {}
647
IsDefaultCategory()648 bool SBTypeCategory::IsDefaultCategory() {
649 if (!IsValid())
650 return false;
651
652 return (strcmp(m_opaque_sp->GetName(), "default") == 0);
653 }
654
655 namespace lldb_private {
656 namespace repro {
657
658 template <>
RegisterMethods(Registry & R)659 void RegisterMethods<SBTypeCategory>(Registry &R) {
660 LLDB_REGISTER_CONSTRUCTOR(SBTypeCategory, ());
661 LLDB_REGISTER_CONSTRUCTOR(SBTypeCategory, (const lldb::SBTypeCategory &));
662 LLDB_REGISTER_METHOD_CONST(bool, SBTypeCategory, IsValid, ());
663 LLDB_REGISTER_METHOD_CONST(bool, SBTypeCategory, operator bool, ());
664 LLDB_REGISTER_METHOD(bool, SBTypeCategory, GetEnabled, ());
665 LLDB_REGISTER_METHOD(void, SBTypeCategory, SetEnabled, (bool));
666 LLDB_REGISTER_METHOD(const char *, SBTypeCategory, GetName, ());
667 LLDB_REGISTER_METHOD(lldb::LanguageType, SBTypeCategory, GetLanguageAtIndex,
668 (uint32_t));
669 LLDB_REGISTER_METHOD(uint32_t, SBTypeCategory, GetNumLanguages, ());
670 LLDB_REGISTER_METHOD(void, SBTypeCategory, AddLanguage,
671 (lldb::LanguageType));
672 LLDB_REGISTER_METHOD(uint32_t, SBTypeCategory, GetNumFormats, ());
673 LLDB_REGISTER_METHOD(uint32_t, SBTypeCategory, GetNumSummaries, ());
674 LLDB_REGISTER_METHOD(uint32_t, SBTypeCategory, GetNumFilters, ());
675 LLDB_REGISTER_METHOD(uint32_t, SBTypeCategory, GetNumSynthetics, ());
676 LLDB_REGISTER_METHOD(lldb::SBTypeNameSpecifier, SBTypeCategory,
677 GetTypeNameSpecifierForSyntheticAtIndex, (uint32_t));
678 LLDB_REGISTER_METHOD(lldb::SBTypeSummary, SBTypeCategory, GetSummaryForType,
679 (lldb::SBTypeNameSpecifier));
680 LLDB_REGISTER_METHOD(lldb::SBTypeSynthetic, SBTypeCategory,
681 GetSyntheticForType, (lldb::SBTypeNameSpecifier));
682 LLDB_REGISTER_METHOD(lldb::SBTypeFilter, SBTypeCategory, GetFilterAtIndex,
683 (uint32_t));
684 LLDB_REGISTER_METHOD(lldb::SBTypeSummary, SBTypeCategory, GetSummaryAtIndex,
685 (uint32_t));
686 LLDB_REGISTER_METHOD(lldb::SBTypeSynthetic, SBTypeCategory,
687 GetSyntheticAtIndex, (uint32_t));
688 LLDB_REGISTER_METHOD(bool, SBTypeCategory, AddTypeSummary,
689 (lldb::SBTypeNameSpecifier, lldb::SBTypeSummary));
690 LLDB_REGISTER_METHOD(bool, SBTypeCategory, AddTypeSynthetic,
691 (lldb::SBTypeNameSpecifier, lldb::SBTypeSynthetic));
692 LLDB_REGISTER_METHOD(bool, SBTypeCategory, DeleteTypeSynthetic,
693 (lldb::SBTypeNameSpecifier));
694 LLDB_REGISTER_METHOD(lldb::SBTypeNameSpecifier, SBTypeCategory,
695 GetTypeNameSpecifierForFilterAtIndex, (uint32_t));
696 LLDB_REGISTER_METHOD(lldb::SBTypeNameSpecifier, SBTypeCategory,
697 GetTypeNameSpecifierForFormatAtIndex, (uint32_t));
698 LLDB_REGISTER_METHOD(lldb::SBTypeNameSpecifier, SBTypeCategory,
699 GetTypeNameSpecifierForSummaryAtIndex, (uint32_t));
700 LLDB_REGISTER_METHOD(lldb::SBTypeFilter, SBTypeCategory, GetFilterForType,
701 (lldb::SBTypeNameSpecifier));
702 LLDB_REGISTER_METHOD(lldb::SBTypeFormat, SBTypeCategory, GetFormatForType,
703 (lldb::SBTypeNameSpecifier));
704 LLDB_REGISTER_METHOD(lldb::SBTypeFormat, SBTypeCategory, GetFormatAtIndex,
705 (uint32_t));
706 LLDB_REGISTER_METHOD(bool, SBTypeCategory, AddTypeFormat,
707 (lldb::SBTypeNameSpecifier, lldb::SBTypeFormat));
708 LLDB_REGISTER_METHOD(bool, SBTypeCategory, DeleteTypeFormat,
709 (lldb::SBTypeNameSpecifier));
710 LLDB_REGISTER_METHOD(bool, SBTypeCategory, DeleteTypeSummary,
711 (lldb::SBTypeNameSpecifier));
712 LLDB_REGISTER_METHOD(bool, SBTypeCategory, AddTypeFilter,
713 (lldb::SBTypeNameSpecifier, lldb::SBTypeFilter));
714 LLDB_REGISTER_METHOD(bool, SBTypeCategory, DeleteTypeFilter,
715 (lldb::SBTypeNameSpecifier));
716 LLDB_REGISTER_METHOD(bool, SBTypeCategory, GetDescription,
717 (lldb::SBStream &, lldb::DescriptionLevel));
718 LLDB_REGISTER_METHOD(
719 lldb::SBTypeCategory &,
720 SBTypeCategory, operator=,(const lldb::SBTypeCategory &));
721 LLDB_REGISTER_METHOD(bool,
722 SBTypeCategory, operator==,(lldb::SBTypeCategory &));
723 LLDB_REGISTER_METHOD(bool,
724 SBTypeCategory, operator!=,(lldb::SBTypeCategory &));
725 }
726
727 }
728 }
729