LLDB mainline
FormatManager.cpp
Go to the documentation of this file.
1//===-- FormatManager.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
10
11#include "lldb/Core/Debugger.h"
18#include "lldb/Utility/Log.h"
19#include "llvm/ADT/STLExtras.h"
20
21using namespace lldb;
22using namespace lldb_private;
23using namespace lldb_private::formatters;
24
25struct FormatInfo {
27 const char format_char; // One or more format characters that can be used for
28 // this format.
29 const char *format_name; // Long format name that can be used to specify the
30 // current format
31};
32
33static constexpr FormatInfo g_format_infos[] = {
34 {eFormatDefault, '\0', "default"},
35 {eFormatBoolean, 'B', "boolean"},
36 {eFormatBinary, 'b', "binary"},
37 {eFormatBytes, 'y', "bytes"},
38 {eFormatBytesWithASCII, 'Y', "bytes with ASCII"},
39 {eFormatChar, 'c', "character"},
40 {eFormatCharPrintable, 'C', "printable character"},
41 {eFormatComplexFloat, 'F', "complex float"},
42 {eFormatCString, 's', "c-string"},
43 {eFormatDecimal, 'd', "decimal"},
44 {eFormatEnum, 'E', "enumeration"},
45 {eFormatHex, 'x', "hex"},
46 {eFormatHexUppercase, 'X', "uppercase hex"},
47 {eFormatFloat, 'f', "float"},
48 {eFormatOctal, 'o', "octal"},
49 {eFormatOSType, 'O', "OSType"},
50 {eFormatUnicode16, 'U', "unicode16"},
51 {eFormatUnicode32, '\0', "unicode32"},
52 {eFormatUnsigned, 'u', "unsigned decimal"},
53 {eFormatPointer, 'p', "pointer"},
54 {eFormatVectorOfChar, '\0', "char[]"},
55 {eFormatVectorOfSInt8, '\0', "int8_t[]"},
56 {eFormatVectorOfUInt8, '\0', "uint8_t[]"},
57 {eFormatVectorOfSInt16, '\0', "int16_t[]"},
58 {eFormatVectorOfUInt16, '\0', "uint16_t[]"},
59 {eFormatVectorOfSInt32, '\0', "int32_t[]"},
60 {eFormatVectorOfUInt32, '\0', "uint32_t[]"},
61 {eFormatVectorOfSInt64, '\0', "int64_t[]"},
62 {eFormatVectorOfUInt64, '\0', "uint64_t[]"},
63 {eFormatVectorOfFloat16, '\0', "float16[]"},
64 {eFormatVectorOfFloat32, '\0', "float32[]"},
65 {eFormatVectorOfFloat64, '\0', "float64[]"},
66 {eFormatVectorOfUInt128, '\0', "uint128_t[]"},
67 {eFormatComplexInteger, 'I', "complex integer"},
68 {eFormatCharArray, 'a', "character array"},
69 {eFormatAddressInfo, 'A', "address"},
70 {eFormatHexFloat, '\0', "hex float"},
71 {eFormatInstruction, 'i', "instruction"},
72 {eFormatVoid, 'v', "void"},
73 {eFormatUnicode8, 'u', "unicode8"},
74};
75
76static_assert((sizeof(g_format_infos) / sizeof(g_format_infos[0])) ==
78 "All formats must have a corresponding info entry.");
79
80static uint32_t g_num_format_infos = std::size(g_format_infos);
81
82static bool GetFormatFromFormatChar(char format_char, Format &format) {
83 for (uint32_t i = 0; i < g_num_format_infos; ++i) {
84 if (g_format_infos[i].format_char == format_char) {
85 format = g_format_infos[i].format;
86 return true;
87 }
88 }
89 format = eFormatInvalid;
90 return false;
91}
92
93static bool GetFormatFromFormatName(llvm::StringRef format_name,
94 Format &format) {
95 uint32_t i;
96 for (i = 0; i < g_num_format_infos; ++i) {
97 if (format_name.equals_insensitive(g_format_infos[i].format_name)) {
98 format = g_format_infos[i].format;
99 return true;
100 }
101 }
102
103 for (i = 0; i < g_num_format_infos; ++i) {
104 if (llvm::StringRef(g_format_infos[i].format_name)
105 .starts_with_insensitive(format_name)) {
106 format = g_format_infos[i].format;
107 return true;
108 }
109 }
110 format = eFormatInvalid;
111 return false;
112}
113
117 std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex);
118 for (auto &iter : m_language_categories_map) {
119 if (iter.second)
120 iter.second->GetFormatCache().Clear();
121 }
122}
123
124bool FormatManager::GetFormatFromCString(const char *format_cstr,
125 lldb::Format &format) {
126 bool success = false;
127 if (format_cstr && format_cstr[0]) {
128 if (format_cstr[1] == '\0') {
129 success = GetFormatFromFormatChar(format_cstr[0], format);
130 if (success)
131 return true;
132 }
133
134 success = GetFormatFromFormatName(format_cstr, format);
135 }
136 if (!success)
137 format = eFormatInvalid;
138 return success;
139}
140
142 for (uint32_t i = 0; i < g_num_format_infos; ++i) {
143 if (g_format_infos[i].format == format)
144 return g_format_infos[i].format_char;
145 }
146 return '\0';
147}
148
150 if (format >= eFormatDefault && format < kNumFormats)
151 return g_format_infos[format].format_name;
152 return nullptr;
153}
154
157 std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex);
158 for (auto &iter : m_language_categories_map) {
159 if (iter.second)
160 iter.second->Enable();
161 }
162}
163
166 std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex);
167 for (auto &iter : m_language_categories_map) {
168 if (iter.second)
169 iter.second->Disable();
170 }
171}
172
174 ValueObject &valobj, CompilerType compiler_type,
175 lldb::DynamicValueType use_dynamic, FormattersMatchVector &entries,
176 FormattersMatchCandidate::Flags current_flags, bool root_level) {
177 compiler_type = compiler_type.GetTypeForFormatters();
178 ConstString type_name(compiler_type.GetTypeName());
179 ScriptInterpreter *script_interpreter =
180 valobj.GetTargetSP()->GetDebugger().GetScriptInterpreter();
181 if (valobj.GetBitfieldBitSize() > 0) {
182 StreamString sstring;
183 sstring.Printf("%s:%d", type_name.AsCString(), valobj.GetBitfieldBitSize());
184 ConstString bitfieldname(sstring.GetString());
185 entries.push_back({bitfieldname, script_interpreter,
186 TypeImpl(compiler_type), current_flags});
187 }
188
189 if (!compiler_type.IsMeaninglessWithoutDynamicResolution()) {
190 entries.push_back({type_name, script_interpreter, TypeImpl(compiler_type),
191 current_flags});
192
193 ConstString display_type_name(compiler_type.GetTypeName());
194 if (display_type_name != type_name)
195 entries.push_back({display_type_name, script_interpreter,
196 TypeImpl(compiler_type), current_flags});
197 }
198
199 for (bool is_rvalue_ref = true, j = true;
200 j && compiler_type.IsReferenceType(nullptr, &is_rvalue_ref); j = false) {
201 CompilerType non_ref_type = compiler_type.GetNonReferenceType();
202 GetPossibleMatches(valobj, non_ref_type, use_dynamic, entries,
203 current_flags.WithStrippedReference());
204 if (non_ref_type.IsTypedefType()) {
205 CompilerType deffed_referenced_type = non_ref_type.GetTypedefedType();
206 deffed_referenced_type =
207 is_rvalue_ref ? deffed_referenced_type.GetRValueReferenceType()
208 : deffed_referenced_type.GetLValueReferenceType();
209 // this is not exactly the usual meaning of stripping typedefs
211 valobj, deffed_referenced_type,
212 use_dynamic, entries, current_flags.WithStrippedTypedef());
213 }
214 }
215
216 if (compiler_type.IsPointerType()) {
217 CompilerType non_ptr_type = compiler_type.GetPointeeType();
218 GetPossibleMatches(valobj, non_ptr_type, use_dynamic, entries,
219 current_flags.WithStrippedPointer());
220 if (non_ptr_type.IsTypedefType()) {
221 CompilerType deffed_pointed_type =
222 non_ptr_type.GetTypedefedType().GetPointerType();
223 // this is not exactly the usual meaning of stripping typedefs
224 GetPossibleMatches(valobj, deffed_pointed_type, use_dynamic, entries,
225 current_flags.WithStrippedTypedef());
226 }
227 }
228
229 // For arrays with typedef-ed elements, we add a candidate with the typedef
230 // stripped.
231 uint64_t array_size;
232 if (compiler_type.IsArrayType(nullptr, &array_size, nullptr)) {
234 CompilerType element_type = compiler_type.GetArrayElementType(
236 if (element_type.IsTypedefType()) {
237 // Get the stripped element type and compute the stripped array type
238 // from it.
239 CompilerType deffed_array_type =
240 element_type.GetTypedefedType().GetArrayType(array_size);
241 // this is not exactly the usual meaning of stripping typedefs
243 valobj, deffed_array_type,
244 use_dynamic, entries, current_flags.WithStrippedTypedef());
245 }
246 }
247
248 for (lldb::LanguageType language_type :
250 if (Language *language = Language::FindPlugin(language_type)) {
251 for (const FormattersMatchCandidate& candidate :
252 language->GetPossibleFormattersMatches(valobj, use_dynamic)) {
253 entries.push_back(candidate);
254 }
255 }
256 }
257
258 // try to strip typedef chains
259 if (compiler_type.IsTypedefType()) {
260 CompilerType deffed_type = compiler_type.GetTypedefedType();
261 GetPossibleMatches(valobj, deffed_type, use_dynamic, entries,
262 current_flags.WithStrippedTypedef());
263 }
264
265 if (root_level) {
266 do {
267 if (!compiler_type.IsValid())
268 break;
269
270 CompilerType unqual_compiler_ast_type =
271 compiler_type.GetFullyUnqualifiedType();
272 if (!unqual_compiler_ast_type.IsValid())
273 break;
274 if (unqual_compiler_ast_type.GetOpaqueQualType() !=
275 compiler_type.GetOpaqueQualType())
276 GetPossibleMatches(valobj, unqual_compiler_ast_type, use_dynamic,
277 entries, current_flags);
278 } while (false);
279
280 // if all else fails, go to static type
281 if (valobj.IsDynamic()) {
282 lldb::ValueObjectSP static_value_sp(valobj.GetStaticValue());
283 if (static_value_sp)
284 GetPossibleMatches(*static_value_sp.get(),
285 static_value_sp->GetCompilerType(), use_dynamic,
286 entries, current_flags, true);
287 }
288 }
289}
290
293 if (!type_sp)
294 return lldb::TypeFormatImplSP();
295 lldb::TypeFormatImplSP format_chosen_sp;
296 uint32_t num_categories = m_categories_map.GetCount();
297 lldb::TypeCategoryImplSP category_sp;
298 uint32_t prio_category = UINT32_MAX;
299 for (uint32_t category_id = 0; category_id < num_categories; category_id++) {
300 category_sp = GetCategoryAtIndex(category_id);
301 if (!category_sp->IsEnabled())
302 continue;
303 lldb::TypeFormatImplSP format_current_sp =
304 category_sp->GetFormatForType(type_sp);
305 if (format_current_sp &&
306 (format_chosen_sp.get() == nullptr ||
307 (prio_category > category_sp->GetEnabledPosition()))) {
308 prio_category = category_sp->GetEnabledPosition();
309 format_chosen_sp = format_current_sp;
310 }
311 }
312 return format_chosen_sp;
313}
314
317 if (!type_sp)
319 lldb::TypeSummaryImplSP summary_chosen_sp;
320 uint32_t num_categories = m_categories_map.GetCount();
321 lldb::TypeCategoryImplSP category_sp;
322 uint32_t prio_category = UINT32_MAX;
323 for (uint32_t category_id = 0; category_id < num_categories; category_id++) {
324 category_sp = GetCategoryAtIndex(category_id);
325 if (!category_sp->IsEnabled())
326 continue;
327 lldb::TypeSummaryImplSP summary_current_sp =
328 category_sp->GetSummaryForType(type_sp);
329 if (summary_current_sp &&
330 (summary_chosen_sp.get() == nullptr ||
331 (prio_category > category_sp->GetEnabledPosition()))) {
332 prio_category = category_sp->GetEnabledPosition();
333 summary_chosen_sp = summary_current_sp;
334 }
335 }
336 return summary_chosen_sp;
337}
338
341 if (!type_sp)
342 return lldb::TypeFilterImplSP();
343 lldb::TypeFilterImplSP filter_chosen_sp;
344 uint32_t num_categories = m_categories_map.GetCount();
345 lldb::TypeCategoryImplSP category_sp;
346 uint32_t prio_category = UINT32_MAX;
347 for (uint32_t category_id = 0; category_id < num_categories; category_id++) {
348 category_sp = GetCategoryAtIndex(category_id);
349 if (!category_sp->IsEnabled())
350 continue;
351 lldb::TypeFilterImplSP filter_current_sp(
352 (TypeFilterImpl *)category_sp->GetFilterForType(type_sp).get());
353 if (filter_current_sp &&
354 (filter_chosen_sp.get() == nullptr ||
355 (prio_category > category_sp->GetEnabledPosition()))) {
356 prio_category = category_sp->GetEnabledPosition();
357 filter_chosen_sp = filter_current_sp;
358 }
359 }
360 return filter_chosen_sp;
361}
362
365 if (!type_sp)
367 lldb::ScriptedSyntheticChildrenSP synth_chosen_sp;
368 uint32_t num_categories = m_categories_map.GetCount();
369 lldb::TypeCategoryImplSP category_sp;
370 uint32_t prio_category = UINT32_MAX;
371 for (uint32_t category_id = 0; category_id < num_categories; category_id++) {
372 category_sp = GetCategoryAtIndex(category_id);
373 if (!category_sp->IsEnabled())
374 continue;
375 lldb::ScriptedSyntheticChildrenSP synth_current_sp(
376 (ScriptedSyntheticChildren *)category_sp->GetSyntheticForType(type_sp)
377 .get());
378 if (synth_current_sp &&
379 (synth_chosen_sp.get() == nullptr ||
380 (prio_category > category_sp->GetEnabledPosition()))) {
381 prio_category = category_sp->GetEnabledPosition();
382 synth_chosen_sp = synth_current_sp;
383 }
384 }
385 return synth_chosen_sp;
386}
387
389 m_categories_map.ForEach(callback);
390 std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex);
391 for (const auto &entry : m_language_categories_map) {
392 if (auto category_sp = entry.second->GetCategory()) {
393 if (!callback(category_sp))
394 break;
395 }
396 }
397}
398
400FormatManager::GetCategory(ConstString category_name, bool can_create) {
401 if (!category_name)
404 if (m_categories_map.Get(category_name, category))
405 return category;
406
407 if (!can_create)
409
411 category_name,
412 lldb::TypeCategoryImplSP(new TypeCategoryImpl(this, category_name)));
413 return GetCategory(category_name);
414}
415
417 switch (vector_format) {
419 return eFormatCharArray;
420
425 return eFormatDecimal;
426
432 return eFormatHex;
433
437 return eFormatFloat;
438
439 default:
441 }
442}
443
445 // if settings say no oneline whatsoever
446 if (valobj.GetTargetSP().get() &&
447 !valobj.GetTargetSP()->GetDebugger().GetAutoOneLineSummaries())
448 return false; // then don't oneline
449
450 // if this object has a summary, then ask the summary
451 if (valobj.GetSummaryFormat().get() != nullptr)
452 return valobj.GetSummaryFormat()->IsOneLiner();
453
454 auto num_children = valobj.GetNumChildren();
455 if (!num_children) {
456 llvm::consumeError(num_children.takeError());
457 return true;
458 }
459 // no children, no party
460 if (*num_children == 0)
461 return false;
462
463 // ask the type if it has any opinion about this eLazyBoolCalculate == no
464 // opinion; other values should be self explanatory
465 CompilerType compiler_type(valobj.GetCompilerType());
466 if (compiler_type.IsValid()) {
467 switch (compiler_type.ShouldPrintAsOneLiner(&valobj)) {
468 case eLazyBoolNo:
469 return false;
470 case eLazyBoolYes:
471 return true;
473 break;
474 }
475 }
476
477 size_t total_children_name_len = 0;
478
479 for (size_t idx = 0; idx < *num_children; idx++) {
480 bool is_synth_val = false;
481 ValueObjectSP child_sp(valobj.GetChildAtIndex(idx));
482 // something is wrong here - bail out
483 if (!child_sp)
484 return false;
485
486 // also ask the child's type if it has any opinion
487 CompilerType child_compiler_type(child_sp->GetCompilerType());
488 if (child_compiler_type.IsValid()) {
489 switch (child_compiler_type.ShouldPrintAsOneLiner(child_sp.get())) {
490 case eLazyBoolYes:
491 // an opinion of yes is only binding for the child, so keep going
493 break;
494 case eLazyBoolNo:
495 // but if the child says no, then it's a veto on the whole thing
496 return false;
497 }
498 }
499
500 // if we decided to define synthetic children for a type, we probably care
501 // enough to show them, but avoid nesting children in children
502 if (child_sp->GetSyntheticChildren().get() != nullptr) {
503 ValueObjectSP synth_sp(child_sp->GetSyntheticValue());
504 // wait.. wat? just get out of here..
505 if (!synth_sp)
506 return false;
507 // but if we only have them to provide a value, keep going
508 if (!synth_sp->MightHaveChildren() &&
509 synth_sp->DoesProvideSyntheticValue())
510 is_synth_val = true;
511 else
512 return false;
513 }
514
515 total_children_name_len += child_sp->GetName().GetLength();
516
517 // 50 itself is a "randomly" chosen number - the idea is that
518 // overly long structs should not get this treatment
519 // FIXME: maybe make this a user-tweakable setting?
520 if (total_children_name_len > 50)
521 return false;
522
523 // if a summary is there..
524 if (child_sp->GetSummaryFormat()) {
525 // and it wants children, then bail out
526 if (child_sp->GetSummaryFormat()->DoesPrintChildren(child_sp.get()))
527 return false;
528 }
529
530 // if this child has children..
531 if (child_sp->HasChildren()) {
532 // ...and no summary...
533 // (if it had a summary and the summary wanted children, we would have
534 // bailed out anyway
535 // so this only makes us bail out if this has no summary and we would
536 // then print children)
537 if (!child_sp->GetSummaryFormat() && !is_synth_val) // but again only do
538 // that if not a
539 // synthetic valued
540 // child
541 return false; // then bail out
542 }
543 }
544 return true;
545}
546
548 lldb::DynamicValueType use_dynamic) {
550 use_dynamic, valobj.IsSynthetic());
551 if (valobj_sp && valobj_sp->GetCompilerType().IsValid()) {
552 if (!valobj_sp->GetCompilerType().IsMeaninglessWithoutDynamicResolution())
553 return valobj_sp->GetQualifiedTypeName();
554 }
555 return ConstString();
556}
557
558std::vector<lldb::LanguageType>
560 switch (lang_type) {
570 default:
571 return {lang_type};
572 }
573 llvm_unreachable("Fully covered switch");
574}
575
578 std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex);
579 auto iter = m_language_categories_map.find(lang_type),
580 end = m_language_categories_map.end();
581 if (iter != end)
582 return iter->second.get();
583 LanguageCategory *lang_category = new LanguageCategory(lang_type);
584 m_language_categories_map[lang_type] =
585 LanguageCategory::UniquePointer(lang_category);
586 return lang_category;
587}
588
589template <typename ImplSP>
591 ImplSP retval_sp;
592 for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) {
593 if (LanguageCategory *lang_category = GetCategoryForLanguage(lang_type)) {
594 if (lang_category->GetHardcoded(*this, match_data, retval_sp))
595 return retval_sp;
596 }
597 }
598 return retval_sp;
599}
600
601namespace {
602template <typename ImplSP> const char *FormatterKind;
603template <> const char *FormatterKind<lldb::TypeFormatImplSP> = "format";
604template <> const char *FormatterKind<lldb::TypeSummaryImplSP> = "summary";
605template <> const char *FormatterKind<lldb::SyntheticChildrenSP> = "synthetic";
606} // namespace
607
608#define FORMAT_LOG(Message) "[%s] " Message, FormatterKind<ImplSP>
609
610template <typename ImplSP>
612 lldb::DynamicValueType use_dynamic) {
613 FormattersMatchData match_data(valobj, use_dynamic);
614 if (ImplSP retval_sp = GetCached<ImplSP>(match_data))
615 return retval_sp;
616
618
619 LLDB_LOGF(log, FORMAT_LOG("Search failed. Giving language a chance."));
620 for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) {
621 if (LanguageCategory *lang_category = GetCategoryForLanguage(lang_type)) {
622 ImplSP retval_sp;
623 if (lang_category->Get(match_data, retval_sp))
624 if (retval_sp) {
625 LLDB_LOGF(log, FORMAT_LOG("Language search success. Returning."));
626 return retval_sp;
627 }
628 }
629 }
630
631 LLDB_LOGF(log, FORMAT_LOG("Search failed. Giving hardcoded a chance."));
632 return GetHardcoded<ImplSP>(match_data);
633}
634
635template <typename ImplSP>
637 ImplSP retval_sp;
639 if (match_data.GetTypeForCache()) {
640 LLDB_LOGF(log, "\n\n" FORMAT_LOG("Looking into cache for type %s"),
641 match_data.GetTypeForCache().AsCString("<invalid>"));
642 if (m_format_cache.Get(match_data.GetTypeForCache(), retval_sp)) {
643 if (log) {
644 LLDB_LOGF(log, FORMAT_LOG("Cache search success. Returning."));
645 LLDB_LOGV(log, "Cache hits: {0} - Cache Misses: {1}",
648 }
649 return retval_sp;
650 }
651 LLDB_LOGF(log, FORMAT_LOG("Cache search failed. Going normal route"));
652 }
653
654 m_categories_map.Get(match_data, retval_sp);
655 if (match_data.GetTypeForCache() && (!retval_sp || !retval_sp->NonCacheable())) {
656 LLDB_LOGF(log, FORMAT_LOG("Caching %p for type %s"),
657 static_cast<void *>(retval_sp.get()),
658 match_data.GetTypeForCache().AsCString("<invalid>"));
659 m_format_cache.Set(match_data.GetTypeForCache(), retval_sp);
660 }
661 LLDB_LOGV(log, "Cache hits: {0} - Cache Misses: {1}",
663 return retval_sp;
664}
665
666#undef FORMAT_LOG
667
670 lldb::DynamicValueType use_dynamic) {
671 return Get<lldb::TypeFormatImplSP>(valobj, use_dynamic);
672}
673
676 lldb::DynamicValueType use_dynamic) {
677 return Get<lldb::TypeSummaryImplSP>(valobj, use_dynamic);
678}
679
682 lldb::DynamicValueType use_dynamic) {
683 return Get<lldb::SyntheticChildrenSP>(valobj, use_dynamic);
684}
685
687 : m_last_revision(0), m_format_cache(), m_language_categories_mutex(),
688 m_language_categories_map(), m_named_summaries_map(this),
689 m_categories_map(this), m_default_category_name(ConstString("default")),
690 m_system_category_name(ConstString("system")),
691 m_vectortypes_category_name(ConstString("VectorTypes")) {
694
699}
700
702 TypeSummaryImpl::Flags string_flags;
703 string_flags.SetCascades(true)
704 .SetSkipPointers(true)
705 .SetSkipReferences(false)
707 .SetDontShowValue(false)
709 .SetHideItemNames(false);
710
711 TypeSummaryImpl::Flags string_array_flags;
712 string_array_flags.SetCascades(true)
713 .SetSkipPointers(true)
714 .SetSkipReferences(false)
716 .SetDontShowValue(true)
718 .SetHideItemNames(false);
719
720 lldb::TypeSummaryImplSP string_format(
721 new StringSummaryFormat(string_flags, "${var%s}"));
722
723 lldb::TypeSummaryImplSP string_array_format(
724 new StringSummaryFormat(string_array_flags, "${var%char[]}"));
725
726 TypeCategoryImpl::SharedPointer sys_category_sp =
728
729 sys_category_sp->AddTypeSummary(R"(^(unsigned )?char ?(\*|\[\])$)",
730 eFormatterMatchRegex, string_format);
731
732 sys_category_sp->AddTypeSummary(R"(^((un)?signed )?char ?\[[0-9]+\]$)",
733 eFormatterMatchRegex, string_array_format);
734
735 lldb::TypeSummaryImplSP ostype_summary(
737 .SetCascades(false)
738 .SetSkipPointers(true)
739 .SetSkipReferences(true)
740 .SetDontShowChildren(true)
741 .SetDontShowValue(false)
742 .SetShowMembersOneLiner(false)
743 .SetHideItemNames(false),
744 "${var%O}"));
745
746 sys_category_sp->AddTypeSummary("OSType", eFormatterMatchExact,
747 ostype_summary);
748
749 TypeFormatImpl::Flags fourchar_flags;
750 fourchar_flags.SetCascades(true).SetSkipPointers(true).SetSkipReferences(
751 true);
752
753 AddFormat(sys_category_sp, lldb::eFormatOSType, "FourCharCode",
754 fourchar_flags);
755}
756
758 TypeCategoryImpl::SharedPointer vectors_category_sp =
760
761 TypeSummaryImpl::Flags vector_flags;
762 vector_flags.SetCascades(true)
763 .SetSkipPointers(true)
764 .SetSkipReferences(false)
766 .SetDontShowValue(false)
768 .SetHideItemNames(true);
769
770 AddStringSummary(vectors_category_sp, "${var.uint128}", "builtin_type_vec128",
771 vector_flags);
772 AddStringSummary(vectors_category_sp, "", "float[4]", vector_flags);
773 AddStringSummary(vectors_category_sp, "", "int32_t[4]", vector_flags);
774 AddStringSummary(vectors_category_sp, "", "int16_t[8]", vector_flags);
775 AddStringSummary(vectors_category_sp, "", "vDouble", vector_flags);
776 AddStringSummary(vectors_category_sp, "", "vFloat", vector_flags);
777 AddStringSummary(vectors_category_sp, "", "vSInt8", vector_flags);
778 AddStringSummary(vectors_category_sp, "", "vSInt16", vector_flags);
779 AddStringSummary(vectors_category_sp, "", "vSInt32", vector_flags);
780 AddStringSummary(vectors_category_sp, "", "vUInt16", vector_flags);
781 AddStringSummary(vectors_category_sp, "", "vUInt8", vector_flags);
782 AddStringSummary(vectors_category_sp, "", "vUInt16", vector_flags);
783 AddStringSummary(vectors_category_sp, "", "vUInt32", vector_flags);
784 AddStringSummary(vectors_category_sp, "", "vBool32", vector_flags);
785}
#define FORMAT_LOG(Message)
static bool GetFormatFromFormatChar(char format_char, Format &format)
static bool GetFormatFromFormatName(llvm::StringRef format_name, Format &format)
static constexpr FormatInfo g_format_infos[]
static uint32_t g_num_format_infos
#define LLDB_LOGF(log,...)
Definition: Log.h:349
#define LLDB_LOGV(log,...)
Definition: Log.h:356
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
CompilerType GetTypeForFormatters() const
CompilerType GetArrayType(uint64_t size) const
bool IsArrayType(CompilerType *element_type=nullptr, uint64_t *size=nullptr, bool *is_incomplete=nullptr) const
CompilerType GetRValueReferenceType() const
Return a new CompilerType that is a R value reference to this type if this type is valid and the type...
CompilerType GetPointerType() const
Return a new CompilerType that is a pointer to this type.
lldb::opaque_compiler_type_t GetOpaqueQualType() const
Definition: CompilerType.h:281
CompilerType GetLValueReferenceType() const
Return a new CompilerType that is a L value reference to this type if this type is valid and the type...
CompilerType GetNonReferenceType() const
If this type is a reference to a type (L value or R value reference), return a new type with the refe...
bool IsMeaninglessWithoutDynamicResolution() const
ConstString GetTypeName(bool BaseOnly=false) const
CompilerType GetTypedefedType() const
If the current object represents a typedef type, get the underlying type.
bool IsReferenceType(CompilerType *pointee_type=nullptr, bool *is_rvalue=nullptr) const
CompilerType GetArrayElementType(ExecutionContextScope *exe_scope) const
Creating related types.
CompilerType GetFullyUnqualifiedType() const
CompilerType GetPointeeType() const
If this type is a pointer type, return the type that the pointer points to, else return an invalid ty...
LazyBool ShouldPrintAsOneLiner(ValueObject *valobj) const
bool IsPointerType(CompilerType *pointee_type=nullptr) const
A uniqued constant string class.
Definition: ConstString.h:40
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:188
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
ExecutionContextScope * GetBestExecutionContextScope() const
void Set(ConstString type, lldb::TypeFormatImplSP &format_sp)
Definition: FormatCache.cpp:94
bool Get(ConstString type, ImplSP &format_impl_sp)
Definition: FormatCache.cpp:69
ImplSP GetHardcoded(FormattersMatchData &)
void EnableCategory(ConstString category_name, TypeCategoryMap::Position pos=TypeCategoryMap::Default)
Definition: FormatManager.h:53
lldb::TypeFormatImplSP GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp)
lldb::TypeFormatImplSP GetFormat(ValueObject &valobj, lldb::DynamicValueType use_dynamic)
lldb::TypeFilterImplSP GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp)
std::recursive_mutex m_language_categories_mutex
static ConstString GetTypeForCache(ValueObject &, lldb::DynamicValueType)
bool ShouldPrintAsOneLiner(ValueObject &valobj)
ImplSP Get(ValueObject &valobj, lldb::DynamicValueType use_dynamic)
static const char * GetFormatAsCString(lldb::Format format)
static bool GetFormatFromCString(const char *format_cstr, lldb::Format &format)
lldb::TypeSummaryImplSP GetSummaryFormat(ValueObject &valobj, lldb::DynamicValueType use_dynamic)
static FormattersMatchVector GetPossibleMatches(ValueObject &valobj, lldb::DynamicValueType use_dynamic)
lldb::TypeCategoryImplSP GetCategory(const char *category_name=nullptr, bool can_create=true)
Definition: FormatManager.h:99
static std::vector< lldb::LanguageType > GetCandidateLanguages(lldb::LanguageType lang_type)
static lldb::Format GetSingleItemFormat(lldb::Format vector_format)
void ForEachCategory(TypeCategoryMap::ForEachCallback callback)
std::atomic< uint32_t > m_last_revision
ImplSP GetCached(FormattersMatchData &match_data)
lldb::ScriptedSyntheticChildrenSP GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp)
TypeCategoryMap m_categories_map
lldb::TypeSummaryImplSP GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp)
lldb::SyntheticChildrenSP GetSyntheticChildren(ValueObject &valobj, lldb::DynamicValueType use_dynamic)
static char GetFormatAsFormatChar(lldb::Format format)
lldb::TypeCategoryImplSP GetCategoryAtIndex(size_t index)
Definition: FormatManager.h:93
ConstString m_vectortypes_category_name
LanguageCategory * GetCategoryForLanguage(lldb::LanguageType lang_type)
LanguageCategories m_language_categories_map
CandidateLanguagesVector GetCandidateLanguages()
std::unique_ptr< LanguageCategory > UniquePointer
static Language * FindPlugin(lldb::LanguageType language)
Definition: Language.cpp:83
llvm::StringRef GetString() const
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:134
std::shared_ptr< TypeCategoryImpl > SharedPointer
Definition: TypeCategory.h:357
std::function< bool(const lldb::TypeCategoryImplSP &)> ForEachCallback
static const Position Last
void Add(KeyType name, const lldb::TypeCategoryImplSP &entry)
bool Get(KeyType name, lldb::TypeCategoryImplSP &entry)
void ForEach(ForEachCallback callback)
Flags & SetCascades(bool value=true)
Definition: TypeFormat.h:55
Flags & SetSkipReferences(bool value=true)
Definition: TypeFormat.h:81
Flags & SetSkipPointers(bool value=true)
Definition: TypeFormat.h:68
Flags & SetCascades(bool value=true)
Definition: TypeSummary.h:82
Flags & SetSkipPointers(bool value=true)
Definition: TypeSummary.h:95
Flags & SetHideItemNames(bool value=true)
Definition: TypeSummary.h:173
Flags & SetDontShowChildren(bool value=true)
Definition: TypeSummary.h:121
Flags & SetSkipReferences(bool value=true)
Definition: TypeSummary.h:108
Flags & SetShowMembersOneLiner(bool value=true)
Definition: TypeSummary.h:160
Flags & SetDontShowValue(bool value=true)
Definition: TypeSummary.h:147
lldb::TypeSummaryImplSP GetSummaryFormat()
Definition: ValueObject.h:712
virtual uint32_t GetBitfieldBitSize()
Definition: ValueObject.h:424
virtual lldb::ValueObjectSP GetChildAtIndex(uint32_t idx, bool can_create=true)
CompilerType GetCompilerType()
Definition: ValueObject.h:352
virtual bool IsDynamic()
Definition: ValueObject.h:633
llvm::Expected< uint32_t > GetNumChildren(uint32_t max=UINT32_MAX)
lldb::LanguageType GetObjectRuntimeLanguage()
Definition: ValueObject.h:373
lldb::ValueObjectSP GetQualifiedRepresentationIfAvailable(lldb::DynamicValueType dynValue, bool synthValue)
lldb::TargetSP GetTargetSP() const
Definition: ValueObject.h:334
virtual lldb::ValueObjectSP GetStaticValue()
Definition: ValueObject.h:580
virtual bool IsSynthetic()
Definition: ValueObject.h:588
const ExecutionContextRef & GetExecutionContextRef() const
Definition: ValueObject.h:330
#define UINT32_MAX
Definition: lldb-defines.h:19
void AddStringSummary(TypeCategoryImpl::SharedPointer category_sp, const char *string, llvm::StringRef type_name, TypeSummaryImpl::Flags flags, bool regex=false)
void AddFormat(TypeCategoryImpl::SharedPointer category_sp, lldb::Format format, llvm::StringRef type_name, TypeFormatImpl::Flags flags, bool regex=false)
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:314
template bool LanguageCategory::Get< lldb::TypeFormatImplSP >(FormattersMatchData &, lldb::TypeFormatImplSP &)
Explicit instantiations for the three types.
std::vector< FormattersMatchCandidate > FormattersMatchVector
template bool LanguageCategory::Get< lldb::SyntheticChildrenSP >(FormattersMatchData &, lldb::SyntheticChildrenSP &)
template bool LanguageCategory::Get< lldb::TypeSummaryImplSP >(FormattersMatchData &, lldb::TypeSummaryImplSP &)
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::TypeSummaryImpl > TypeSummaryImplSP
Definition: lldb-forward.h:463
std::shared_ptr< lldb_private::TypeFormatImpl > TypeFormatImplSP
Definition: lldb-forward.h:460
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Definition: lldb-forward.h:472
std::shared_ptr< lldb_private::TypeNameSpecifierImpl > TypeNameSpecifierImplSP
Definition: lldb-forward.h:462
Format
Display format definitions.
@ eFormatCString
NULL terminated C strings.
@ eFormatCharArray
Print characters with no single quotes, used for character arrays that can contain non printable char...
@ eFormatInstruction
Disassemble an opcode.
@ eFormatVectorOfChar
@ eFormatVectorOfUInt64
@ eFormatVoid
Do not print this.
@ eFormatVectorOfFloat16
@ eFormatVectorOfSInt64
@ eFormatHexFloat
ISO C99 hex float string.
@ eFormatBytesWithASCII
@ eFormatOSType
OS character codes encoded into an integer 'PICT' 'text' etc...
@ eFormatUnicode16
@ eFormatAddressInfo
Describe what an address points to (func + offset.
@ eFormatVectorOfUInt128
@ eFormatVectorOfUInt8
@ eFormatComplexFloat
@ eFormatVectorOfFloat32
@ eFormatVectorOfSInt32
@ eFormatUnicode32
@ eFormatVectorOfSInt8
@ eFormatVectorOfUInt16
@ eFormatHexUppercase
@ eFormatVectorOfFloat64
@ eFormatCharPrintable
Only printable characters, '.' if not printable.
@ eFormatComplexInteger
Integer complex type.
@ eFormatVectorOfSInt16
@ eFormatVectorOfUInt32
LanguageType
Programming language type.
@ eLanguageTypeC_plus_plus_14
ISO C++:2014.
@ eLanguageTypeC11
ISO C:2011.
@ eLanguageTypeC99
ISO C:1999.
@ eLanguageTypeC_plus_plus_03
ISO C++:2003.
@ eLanguageTypeObjC_plus_plus
Objective-C++.
@ eLanguageTypeC_plus_plus_11
ISO C++:2011.
@ eLanguageTypeC89
ISO C:1989.
@ eLanguageTypeC
Non-standardized C, such as K&R.
@ eLanguageTypeObjC
Objective-C.
@ eLanguageTypeC_plus_plus
ISO C++:1998.
@ eFormatterMatchExact
@ eFormatterMatchRegex
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
const char * format_name
const char format_char