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"
20#include "llvm/ADT/STLExtras.h"
21
22using namespace lldb;
23using namespace lldb_private;
24using namespace lldb_private::formatters;
25
26struct FormatInfo {
28 const char format_char; // One or more format characters that can be used for
29 // this format.
30 const char *format_name; // Long format name that can be used to specify the
31 // current format
32};
33
34static constexpr FormatInfo g_format_infos[] = {
35 {eFormatDefault, '\0', "default"},
36 {eFormatBoolean, 'B', "boolean"},
37 {eFormatBinary, 'b', "binary"},
38 {eFormatBytes, 'y', "bytes"},
39 {eFormatBytesWithASCII, 'Y', "bytes with ASCII"},
40 {eFormatChar, 'c', "character"},
41 {eFormatCharPrintable, 'C', "printable character"},
42 {eFormatComplexFloat, 'F', "complex float"},
43 {eFormatCString, 's', "c-string"},
44 {eFormatDecimal, 'd', "decimal"},
45 {eFormatEnum, 'E', "enumeration"},
46 {eFormatHex, 'x', "hex"},
47 {eFormatHexUppercase, 'X', "uppercase hex"},
48 {eFormatFloat, 'f', "float"},
49 {eFormatOctal, 'o', "octal"},
50 {eFormatOSType, 'O', "OSType"},
51 {eFormatUnicode16, 'U', "unicode16"},
52 {eFormatUnicode32, '\0', "unicode32"},
53 {eFormatUnsigned, 'u', "unsigned decimal"},
54 {eFormatPointer, 'p', "pointer"},
55 {eFormatVectorOfChar, '\0', "char[]"},
56 {eFormatVectorOfSInt8, '\0', "int8_t[]"},
57 {eFormatVectorOfUInt8, '\0', "uint8_t[]"},
58 {eFormatVectorOfSInt16, '\0', "int16_t[]"},
59 {eFormatVectorOfUInt16, '\0', "uint16_t[]"},
60 {eFormatVectorOfSInt32, '\0', "int32_t[]"},
61 {eFormatVectorOfUInt32, '\0', "uint32_t[]"},
62 {eFormatVectorOfSInt64, '\0', "int64_t[]"},
63 {eFormatVectorOfUInt64, '\0', "uint64_t[]"},
64 {eFormatVectorOfFloat16, '\0', "float16[]"},
65 {eFormatVectorOfFloat32, '\0', "float32[]"},
66 {eFormatVectorOfFloat64, '\0', "float64[]"},
67 {eFormatVectorOfUInt128, '\0', "uint128_t[]"},
68 {eFormatComplexInteger, 'I', "complex integer"},
69 {eFormatCharArray, 'a', "character array"},
70 {eFormatAddressInfo, 'A', "address"},
71 {eFormatHexFloat, '\0', "hex float"},
72 {eFormatInstruction, 'i', "instruction"},
73 {eFormatVoid, 'v', "void"},
74 {eFormatUnicode8, 'u', "unicode8"},
75 {eFormatFloat128, '\0', "float128"},
76};
77
78static_assert((sizeof(g_format_infos) / sizeof(g_format_infos[0])) ==
80 "All formats must have a corresponding info entry.");
81
82static uint32_t g_num_format_infos = std::size(g_format_infos);
83
84static bool GetFormatFromFormatChar(char format_char, Format &format) {
85 for (uint32_t i = 0; i < g_num_format_infos; ++i) {
86 if (g_format_infos[i].format_char == format_char) {
87 format = g_format_infos[i].format;
88 return true;
89 }
90 }
91 format = eFormatInvalid;
92 return false;
93}
94
95static bool GetFormatFromFormatName(llvm::StringRef format_name,
96 Format &format) {
97 uint32_t i;
98 for (i = 0; i < g_num_format_infos; ++i) {
99 if (format_name.equals_insensitive(g_format_infos[i].format_name)) {
100 format = g_format_infos[i].format;
101 return true;
102 }
103 }
104
105 for (i = 0; i < g_num_format_infos; ++i) {
106 if (llvm::StringRef(g_format_infos[i].format_name)
107 .starts_with_insensitive(format_name)) {
108 format = g_format_infos[i].format;
109 return true;
110 }
111 }
112 format = eFormatInvalid;
113 return false;
114}
115
118 m_format_cache.Clear();
119 std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex);
120 for (auto &iter : m_language_categories_map) {
121 if (iter.second)
122 iter.second->GetFormatCache().Clear();
123 }
124}
125
126bool FormatManager::GetFormatFromCString(const char *format_cstr,
127 lldb::Format &format) {
128 bool success = false;
129 if (format_cstr && format_cstr[0]) {
130 if (format_cstr[1] == '\0') {
131 success = GetFormatFromFormatChar(format_cstr[0], format);
132 if (success)
133 return true;
134 }
135
136 success = GetFormatFromFormatName(format_cstr, format);
137 }
138 if (!success)
139 format = eFormatInvalid;
140 return success;
141}
142
144 for (uint32_t i = 0; i < g_num_format_infos; ++i) {
145 if (g_format_infos[i].format == format)
146 return g_format_infos[i].format_char;
147 }
148 return '\0';
149}
150
152 if (format >= eFormatDefault && format < kNumFormats)
153 return g_format_infos[format].format_name;
154 return nullptr;
155}
156
158 m_categories_map.EnableAllCategories();
159 std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex);
160 for (auto &iter : m_language_categories_map) {
161 if (iter.second)
162 iter.second->Enable();
163 }
164}
165
167 m_categories_map.DisableAllCategories();
168 std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex);
169 for (auto &iter : m_language_categories_map) {
170 if (iter.second)
171 iter.second->Disable();
172 }
173}
174
176 ValueObject &valobj, CompilerType compiler_type,
177 lldb::DynamicValueType use_dynamic, FormattersMatchVector &entries,
178 FormattersMatchCandidate::Flags current_flags, bool root_level,
179 uint32_t ptr_stripped_depth) {
180 compiler_type = compiler_type.GetTypeForFormatters();
181 llvm::StringRef type_name(compiler_type.GetTypeName().GetStringRef());
182 // A ValueObject that couldn't be made correctly won't necessarily have a
183 // target. We aren't going to find a formatter in this case anyway, so we
184 // should just exit.
185 TargetSP target_sp = valobj.GetTargetSP();
186 if (!target_sp)
187 return;
188 ScriptInterpreter *script_interpreter =
189 target_sp->GetDebugger().GetScriptInterpreter();
190 if (valobj.GetBitfieldBitSize() > 0) {
191 StreamString sstring;
192 sstring.Format("{0}:{1}", type_name, valobj.GetBitfieldBitSize());
193 llvm::StringRef bitfieldname(sstring.GetString());
194 entries.push_back({bitfieldname.str(), script_interpreter,
195 TypeImpl(compiler_type), current_flags,
196 ptr_stripped_depth});
197 }
198
199 if (!compiler_type.IsMeaninglessWithoutDynamicResolution()) {
200 entries.push_back({type_name.str(), script_interpreter,
201 TypeImpl(compiler_type), current_flags,
202 ptr_stripped_depth});
203
204 llvm::StringRef display_type_name(compiler_type.GetTypeName());
205 if (display_type_name != type_name)
206 entries.push_back({display_type_name.str(), script_interpreter,
207 TypeImpl(compiler_type), current_flags,
208 ptr_stripped_depth});
209 }
210
211 for (bool is_rvalue_ref = true, j = true;
212 j && compiler_type.IsReferenceType(nullptr, &is_rvalue_ref); j = false) {
213 CompilerType non_ref_type = compiler_type.GetNonReferenceType();
214 GetPossibleMatches(valobj, non_ref_type, use_dynamic, entries,
215 current_flags.WithStrippedReference(), root_level,
216 ptr_stripped_depth);
217 if (non_ref_type.IsTypedefType()) {
218 CompilerType deffed_referenced_type = non_ref_type.GetTypedefedType();
219 deffed_referenced_type =
220 is_rvalue_ref ? deffed_referenced_type.GetRValueReferenceType()
221 : deffed_referenced_type.GetLValueReferenceType();
222 // this is not exactly the usual meaning of stripping typedefs
223 GetPossibleMatches(valobj, deffed_referenced_type, use_dynamic, entries,
224 current_flags.WithStrippedTypedef(), root_level,
225 ptr_stripped_depth);
226 }
227 }
228
229 if (compiler_type.IsPointerType()) {
230 CompilerType non_ptr_type = compiler_type.GetPointeeType();
231 GetPossibleMatches(valobj, non_ptr_type, use_dynamic, entries,
232 current_flags.WithStrippedPointer(), root_level,
233 ptr_stripped_depth + 1);
234 if (non_ptr_type.IsTypedefType()) {
235 CompilerType deffed_pointed_type =
236 non_ptr_type.GetTypedefedType().GetPointerType();
237 // this is not exactly the usual meaning of stripping typedefs
238 GetPossibleMatches(valobj, deffed_pointed_type, use_dynamic, entries,
239 current_flags.WithStrippedTypedef(), root_level,
240 ptr_stripped_depth + 1);
241 }
242 }
243
244 // For arrays with typedef-ed elements, we add a candidate with the typedef
245 // stripped.
246 uint64_t array_size;
247 if (compiler_type.IsArrayType(nullptr, &array_size, nullptr)) {
249 CompilerType element_type = compiler_type.GetArrayElementType(
251 if (element_type.IsTypedefType()) {
252 // Get the stripped element type and compute the stripped array type
253 // from it.
254 CompilerType deffed_array_type =
255 element_type.GetTypedefedType().GetArrayType(array_size);
256 // this is not exactly the usual meaning of stripping typedefs
257 GetPossibleMatches(valobj, deffed_array_type, use_dynamic, entries,
258 current_flags.WithStrippedTypedef(), root_level,
259 ptr_stripped_depth);
260 }
261 }
262
263 for (lldb::LanguageType language_type :
265 if (Language *language = Language::FindPlugin(language_type)) {
266 for (const FormattersMatchCandidate& candidate :
267 language->GetPossibleFormattersMatches(valobj, use_dynamic)) {
268 entries.push_back(candidate);
269 }
270 }
271 }
272
273 // try to strip typedef chains
274 if (compiler_type.IsTypedefType()) {
275 CompilerType deffed_type = compiler_type.GetTypedefedType();
276 GetPossibleMatches(valobj, deffed_type, use_dynamic, entries,
277 current_flags.WithStrippedTypedef(), root_level,
278 ptr_stripped_depth);
279 }
280
281 if (root_level) {
282 do {
283 if (!compiler_type.IsValid())
284 break;
285
286 CompilerType unqual_compiler_ast_type =
287 compiler_type.GetFullyUnqualifiedType();
288 if (!unqual_compiler_ast_type.IsValid())
289 break;
290 if (unqual_compiler_ast_type.GetOpaqueQualType() !=
291 compiler_type.GetOpaqueQualType())
292 GetPossibleMatches(valobj, unqual_compiler_ast_type, use_dynamic,
293 entries, current_flags, root_level,
294 ptr_stripped_depth);
295 } while (false);
296
297 // if all else fails, go to static type
298 if (valobj.IsDynamic()) {
299 lldb::ValueObjectSP static_value_sp(valobj.GetStaticValue());
300 if (static_value_sp)
301 GetPossibleMatches(*static_value_sp.get(),
302 static_value_sp->GetCompilerType(), use_dynamic,
303 entries, current_flags, true, ptr_stripped_depth);
304 }
305 }
306}
307
310 if (!type_sp)
311 return lldb::TypeFormatImplSP();
312 lldb::TypeFormatImplSP format_chosen_sp;
313 uint32_t num_categories = m_categories_map.GetCount();
314 lldb::TypeCategoryImplSP category_sp;
315 uint32_t prio_category = UINT32_MAX;
316 for (uint32_t category_id = 0; category_id < num_categories; category_id++) {
317 category_sp = GetCategoryAtIndex(category_id);
318 if (!category_sp->IsEnabled())
319 continue;
320 lldb::TypeFormatImplSP format_current_sp =
321 category_sp->GetFormatForType(type_sp);
322 if (format_current_sp &&
323 (format_chosen_sp.get() == nullptr ||
324 (prio_category > category_sp->GetEnabledPosition()))) {
325 prio_category = category_sp->GetEnabledPosition();
326 format_chosen_sp = format_current_sp;
327 }
328 }
329 return format_chosen_sp;
330}
331
334 if (!type_sp)
336 lldb::TypeSummaryImplSP summary_chosen_sp;
337 uint32_t num_categories = m_categories_map.GetCount();
338 lldb::TypeCategoryImplSP category_sp;
339 uint32_t prio_category = UINT32_MAX;
340 for (uint32_t category_id = 0; category_id < num_categories; category_id++) {
341 category_sp = GetCategoryAtIndex(category_id);
342 if (!category_sp->IsEnabled())
343 continue;
344 lldb::TypeSummaryImplSP summary_current_sp =
345 category_sp->GetSummaryForType(type_sp);
346 if (summary_current_sp &&
347 (summary_chosen_sp.get() == nullptr ||
348 (prio_category > category_sp->GetEnabledPosition()))) {
349 prio_category = category_sp->GetEnabledPosition();
350 summary_chosen_sp = summary_current_sp;
351 }
352 }
353 return summary_chosen_sp;
354}
355
358 if (!type_sp)
359 return lldb::TypeFilterImplSP();
360 lldb::TypeFilterImplSP filter_chosen_sp;
361 uint32_t num_categories = m_categories_map.GetCount();
362 lldb::TypeCategoryImplSP category_sp;
363 uint32_t prio_category = UINT32_MAX;
364 for (uint32_t category_id = 0; category_id < num_categories; category_id++) {
365 category_sp = GetCategoryAtIndex(category_id);
366 if (!category_sp->IsEnabled())
367 continue;
368 lldb::TypeFilterImplSP filter_current_sp(
369 (TypeFilterImpl *)category_sp->GetFilterForType(type_sp).get());
370 if (filter_current_sp &&
371 (filter_chosen_sp.get() == nullptr ||
372 (prio_category > category_sp->GetEnabledPosition()))) {
373 prio_category = category_sp->GetEnabledPosition();
374 filter_chosen_sp = filter_current_sp;
375 }
376 }
377 return filter_chosen_sp;
378}
379
382 if (!type_sp)
384 lldb::ScriptedSyntheticChildrenSP synth_chosen_sp;
385 uint32_t num_categories = m_categories_map.GetCount();
386 lldb::TypeCategoryImplSP category_sp;
387 uint32_t prio_category = UINT32_MAX;
388 for (uint32_t category_id = 0; category_id < num_categories; category_id++) {
389 category_sp = GetCategoryAtIndex(category_id);
390 if (!category_sp->IsEnabled())
391 continue;
392 auto synth_current_sp = category_sp->GetSyntheticForType(type_sp);
393
394 if (synth_current_sp && synth_current_sp->IsScripted() &&
395 (synth_chosen_sp.get() == nullptr ||
396 (prio_category > category_sp->GetEnabledPosition()))) {
397 prio_category = category_sp->GetEnabledPosition();
398 synth_chosen_sp =
399 std::static_pointer_cast<ScriptedSyntheticChildren>(synth_current_sp);
400 }
401 }
402 return synth_chosen_sp;
403}
404
406 m_categories_map.ForEach(callback);
407 std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex);
408 for (const auto &entry : m_language_categories_map) {
409 if (auto category_sp = entry.second->GetCategory()) {
410 if (!callback(category_sp))
411 break;
412 }
413 }
414}
415
417FormatManager::GetCategory(llvm::StringRef category_name, bool can_create) {
418 if (category_name.empty())
421 if (m_categories_map.Get(category_name, category))
422 return category;
423
424 if (!can_create)
426
427 m_categories_map.Add(category_name, std::make_shared<TypeCategoryImpl>(
428 this, category_name.str()));
429 return GetCategory(category_name);
430}
431
433 switch (vector_format) {
435 return eFormatCharArray;
436
441 return eFormatDecimal;
442
448 return eFormatHex;
449
453 return eFormatFloat;
454
455 default:
457 }
458}
459
461 TargetSP target_sp = valobj.GetTargetSP();
462 // If settings say no oneline whatsoever then don't oneline.
463 if (target_sp && !target_sp->GetDebugger().GetAutoOneLineSummaries())
464 return false;
465
466 // If this object has a summary, then ask the summary.
467 if (valobj.GetSummaryFormat().get() != nullptr)
468 return valobj.GetSummaryFormat()->IsOneLiner();
469
470 const size_t max_num_children =
471 (target_sp ? *target_sp : Target::GetGlobalProperties())
472 .GetMaximumNumberOfChildrenToDisplay();
473 auto num_children = valobj.GetNumChildren(max_num_children);
474 if (!num_children) {
475 llvm::consumeError(num_children.takeError());
476 return true;
477 }
478 // No children, no party.
479 if (*num_children == 0)
480 return false;
481
482 // Ask the type if it has any opinion about this:
483 // eLazyBoolCalculate == no opinion
484 CompilerType compiler_type(valobj.GetCompilerType());
485 if (compiler_type.IsValid()) {
486 switch (compiler_type.ShouldPrintAsOneLiner(&valobj)) {
487 case eLazyBoolNo:
488 return false;
489 case eLazyBoolYes:
490 return true;
492 break;
493 }
494 }
495
496 size_t total_children_name_len = 0;
497
498 for (size_t idx = 0; idx < *num_children; idx++) {
499 bool is_synth_val = false;
500 ValueObjectSP child_sp(valobj.GetChildAtIndex(idx));
501 // Something is wrong here - bail out.
502 if (!child_sp)
503 return false;
504
505 // Also ask the child's type if it has any opinion.
506 CompilerType child_compiler_type(child_sp->GetCompilerType());
507 if (child_compiler_type.IsValid()) {
508 switch (child_compiler_type.ShouldPrintAsOneLiner(child_sp.get())) {
509 case eLazyBoolYes:
510 // An opinion of yes is only binding for the child, so keep going,
512 break;
513 case eLazyBoolNo:
514 // but if the child says no, then it's a veto on the whole thing.
515 return false;
516 }
517 }
518
519 // If we decided to define synthetic children for a type, we probably care
520 // enough to show them, but avoid nesting children in children.
521 if (child_sp->GetSyntheticChildren().get() != nullptr) {
522 ValueObjectSP synth_sp(child_sp->GetSyntheticValue());
523 // Bail out if there was an error.
524 if (!synth_sp)
525 return false;
526 // If we only have them to provide a value, keep going.
527 if (!synth_sp->MightHaveChildren() &&
528 synth_sp->DoesProvideSyntheticValue())
529 is_synth_val = true;
530 // If there are synthetic children, the user probably wants to see them.
531 else if (synth_sp->MightHaveChildren())
532 return false;
533 }
534
535 total_children_name_len += child_sp->GetName().GetLength();
536
537 // 50 itself is a "randomly" chosen number - the idea is that
538 // overly long structs should not get this treatment.
539 // FIXME: maybe make this a user-tweakable setting?
540 if (total_children_name_len > 50)
541 return false;
542
543 // If a summary is there,
544 if (child_sp->GetSummaryFormat()) {
545 // and it wants children, then bail out.
546 if (child_sp->GetSummaryFormat()->DoesPrintChildren(child_sp.get()))
547 return false;
548 }
549
550 // If this child has children,
551 if (child_sp->HasChildren()) {
552 // and no summary, bail out.
553 //
554 // Note that if it had a summary and the summary wanted
555 // children, we would have bailed out anyway so this only makes
556 // us bail out if this has no summary and we would then print
557 // children.
558 if (!child_sp->GetSummaryFormat() && !is_synth_val)
559 // But again only do that if not a synthetic valued child.
560 return false;
561 }
562 }
563 return true;
564}
565
566llvm::StringRef
568 lldb::DynamicValueType use_dynamic) {
570 use_dynamic, valobj.IsSynthetic());
571 if (valobj_sp && valobj_sp->GetCompilerType().IsValid()) {
572 if (!valobj_sp->GetCompilerType().IsMeaninglessWithoutDynamicResolution())
573 return valobj_sp->GetQualifiedTypeName();
574 }
575 return llvm::StringRef();
576}
577
578std::vector<lldb::LanguageType>
580 switch (lang_type) {
590 default:
591 return {lang_type};
592 }
593 llvm_unreachable("Fully covered switch");
594}
595
598 std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex);
599 auto iter = m_language_categories_map.find(lang_type),
600 end = m_language_categories_map.end();
601 if (iter != end)
602 return iter->second.get();
603 LanguageCategory *lang_category = new LanguageCategory(lang_type);
604 m_language_categories_map[lang_type] =
605 LanguageCategory::UniquePointer(lang_category);
606 return lang_category;
607}
608
609template <typename ImplSP>
611 ImplSP retval_sp;
612 for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) {
613 if (LanguageCategory *lang_category = GetCategoryForLanguage(lang_type)) {
614 if (lang_category->GetHardcoded(*this, match_data, retval_sp))
615 return retval_sp;
616 }
617 }
618 return retval_sp;
619}
620
621namespace {
622template <typename ImplSP> const char *FormatterKind;
623template <> const char *FormatterKind<lldb::TypeFormatImplSP> = "format";
624template <> const char *FormatterKind<lldb::TypeSummaryImplSP> = "summary";
625template <> const char *FormatterKind<lldb::SyntheticChildrenSP> = "synthetic";
626} // namespace
627
628#define FORMAT_LOG(Message) "[{0}] " Message, FormatterKind<ImplSP>
629
630template <typename ImplSP>
632 lldb::DynamicValueType use_dynamic) {
633 FormattersMatchData match_data(valobj, use_dynamic);
634 if (ImplSP retval_sp = GetCached<ImplSP>(match_data))
635 return retval_sp;
636
638
639 LLDB_LOG(log, FORMAT_LOG("Search failed. Giving language a chance."));
640 for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) {
641 if (LanguageCategory *lang_category = GetCategoryForLanguage(lang_type)) {
642 ImplSP retval_sp;
643 if (lang_category->Get(match_data, retval_sp))
644 if (retval_sp) {
645 LLDB_LOG(log, FORMAT_LOG("Language search success. Returning."));
646 return retval_sp;
647 }
648 }
649 }
650
651 LLDB_LOG(log, FORMAT_LOG("Search failed. Giving hardcoded a chance."));
652 return GetHardcoded<ImplSP>(match_data);
653}
654
655template <typename ImplSP>
657 ImplSP retval_sp;
659 llvm::StringRef match_data_name(match_data.GetTypeForCache());
660 if (!match_data_name.empty()) {
661 LLDB_LOG(log, "\n\n" FORMAT_LOG("Looking into cache for type {1}"),
662 match_data_name.nonEmptyOr("<invalid>"));
663 if (m_format_cache.Get(match_data_name, retval_sp)) {
664 LLDB_LOG(log, FORMAT_LOG("Cache search success. Returning."));
665 LLDB_LOG_VERBOSE(log, "Cache hits: {0} - Cache Misses: {1}",
666 m_format_cache.GetCacheHits(),
667 m_format_cache.GetCacheMisses());
668 return retval_sp;
669 }
670 LLDB_LOG(log, FORMAT_LOG("Cache search failed. Going normal route"));
671 }
672
673 m_categories_map.Get(match_data, retval_sp);
674 if (!match_data_name.empty() && (!retval_sp || !retval_sp->NonCacheable())) {
675 LLDB_LOG(log, FORMAT_LOG("Caching {1} for type {2}"),
676 static_cast<void *>(retval_sp.get()),
677 match_data_name.nonEmptyOr("<invalid>"));
678 m_format_cache.Set(match_data_name, retval_sp);
679 }
680 LLDB_LOG_VERBOSE(log, "Cache hits: {0} - Cache Misses: {1}",
681 m_format_cache.GetCacheHits(),
682 m_format_cache.GetCacheMisses());
683 return retval_sp;
684}
685
686#undef FORMAT_LOG
687
690 lldb::DynamicValueType use_dynamic) {
691 return Get<lldb::TypeFormatImplSP>(valobj, use_dynamic);
692}
693
696 lldb::DynamicValueType use_dynamic) {
697 return Get<lldb::TypeSummaryImplSP>(valobj, use_dynamic);
698}
699
702 lldb::DynamicValueType use_dynamic) {
703 return Get<lldb::SyntheticChildrenSP>(valobj, use_dynamic);
704}
705
720
722 TypeSummaryImpl::Flags string_flags;
723 string_flags.SetCascades(true)
724 .SetSkipPointers(true)
725 .SetSkipReferences(true)
727 .SetDontShowValue(false)
729 .SetHideItemNames(false);
730
731 TypeSummaryImpl::Flags string_array_flags;
732 string_array_flags.SetCascades(true)
733 .SetSkipPointers(true)
734 .SetSkipReferences(false)
736 .SetDontShowValue(true)
738 .SetHideItemNames(false);
739
740 lldb::TypeSummaryImplSP string_format(
741 new StringSummaryFormat(string_flags, "${var%s}"));
742
743 lldb::TypeSummaryImplSP string_array_format(
744 new StringSummaryFormat(string_array_flags, "${var%char[]}"));
745
746 TypeCategoryImpl::SharedPointer sys_category_sp =
748
749 sys_category_sp->AddTypeSummary(R"(^(unsigned )?char ?(\*|\[\])$)",
750 eFormatterMatchRegex, string_format);
751
752 sys_category_sp->AddTypeSummary(R"(^((un)?signed )?char ?\[[0-9]+\]$)",
753 eFormatterMatchRegex, string_array_format);
754
755 lldb::TypeSummaryImplSP ostype_summary(
757 .SetCascades(false)
758 .SetSkipPointers(true)
759 .SetSkipReferences(true)
760 .SetDontShowChildren(true)
761 .SetDontShowValue(false)
762 .SetShowMembersOneLiner(false)
763 .SetHideItemNames(false),
764 "${var%O}"));
765
766 sys_category_sp->AddTypeSummary("OSType", eFormatterMatchExact,
767 ostype_summary);
768
769 TypeFormatImpl::Flags fourchar_flags;
770 fourchar_flags.SetCascades(true).SetSkipPointers(true).SetSkipReferences(
771 true);
772
773 AddFormat(sys_category_sp, lldb::eFormatOSType, "FourCharCode",
774 fourchar_flags);
775}
776
778 TypeCategoryImpl::SharedPointer vectors_category_sp =
780
781 TypeSummaryImpl::Flags vector_flags;
782 vector_flags.SetCascades(true)
783 .SetSkipPointers(true)
784 .SetSkipReferences(false)
786 .SetDontShowValue(false)
788 .SetHideItemNames(true);
789
790 AddStringSummary(vectors_category_sp, "${var.uint128}", "builtin_type_vec128",
791 vector_flags);
792 AddStringSummary(vectors_category_sp, "", "float[4]", vector_flags);
793 AddStringSummary(vectors_category_sp, "", "int32_t[4]", vector_flags);
794 AddStringSummary(vectors_category_sp, "", "int16_t[8]", vector_flags);
795 AddStringSummary(vectors_category_sp, "", "vDouble", vector_flags);
796 AddStringSummary(vectors_category_sp, "", "vFloat", vector_flags);
797 AddStringSummary(vectors_category_sp, "", "vSInt8", vector_flags);
798 AddStringSummary(vectors_category_sp, "", "vSInt16", vector_flags);
799 AddStringSummary(vectors_category_sp, "", "vSInt32", vector_flags);
800 AddStringSummary(vectors_category_sp, "", "vUInt16", vector_flags);
801 AddStringSummary(vectors_category_sp, "", "vUInt8", vector_flags);
802 AddStringSummary(vectors_category_sp, "", "vUInt16", vector_flags);
803 AddStringSummary(vectors_category_sp, "", "vUInt32", vector_flags);
804 AddStringSummary(vectors_category_sp, "", "vBool32", vector_flags);
805}
#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_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:375
#define LLDB_LOG_VERBOSE(log,...)
Definition Log.h:382
Generic representation of a type in a programming language.
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
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
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
ExecutionContextScope * GetBestExecutionContextScope() const
ImplSP GetHardcoded(FormattersMatchData &)
lldb::TypeFormatImplSP GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp)
lldb::TypeCategoryImplSP GetCategory(llvm::StringRef category_name, bool can_create=true)
lldb::TypeFormatImplSP GetFormat(ValueObject &valobj, lldb::DynamicValueType use_dynamic)
lldb::TypeFilterImplSP GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp)
std::recursive_mutex m_language_categories_mutex
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)
static std::vector< lldb::LanguageType > GetCandidateLanguages(lldb::LanguageType lang_type)
static lldb::Format GetSingleItemFormat(lldb::Format vector_format)
void ForEachCategory(TypeCategoryMap::ForEachCallback callback)
NamedSummariesMap m_named_summaries_map
std::atomic< uint32_t > m_last_revision
static llvm::StringRef GetTypeForCache(ValueObject &, lldb::DynamicValueType)
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)
void EnableCategory(llvm::StringRef category_name, TypeCategoryMap::Position pos=TypeCategoryMap::Default)
static char GetFormatAsFormatChar(lldb::Format format)
lldb::TypeCategoryImplSP GetCategoryAtIndex(size_t index)
LanguageCategory * GetCategoryForLanguage(lldb::LanguageType lang_type)
LanguageCategories m_language_categories_map
std::string m_vectortypes_category_name
CandidateLanguagesVector GetCandidateLanguages()
std::unique_ptr< LanguageCategory > UniquePointer
static Language * FindPlugin(lldb::LanguageType language)
Definition Language.cpp:86
llvm::StringRef GetString() const
void Format(const char *format, Args &&... args)
Forwards the arguments to llvm::formatv and writes to the stream.
Definition Stream.h:370
static TargetProperties & GetGlobalProperties()
Definition Target.cpp:3489
std::shared_ptr< TypeCategoryImpl > SharedPointer
std::function< bool(const lldb::TypeCategoryImplSP &)> ForEachCallback
static const Position Last
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:93
Flags & SetSkipPointers(bool value=true)
Flags & SetHideItemNames(bool value=true)
Flags & SetDontShowChildren(bool value=true)
Flags & SetSkipReferences(bool value=true)
Flags & SetShowMembersOneLiner(bool value=true)
Flags & SetDontShowValue(bool value=true)
lldb::TypeSummaryImplSP GetSummaryFormat()
virtual uint32_t GetBitfieldBitSize()
virtual lldb::ValueObjectSP GetChildAtIndex(uint32_t idx, bool can_create=true)
llvm::Expected< uint32_t > GetNumChildren(uint32_t max=UINT32_MAX)
lldb::LanguageType GetObjectRuntimeLanguage()
lldb::ValueObjectSP GetQualifiedRepresentationIfAvailable(lldb::DynamicValueType dynValue, bool synthValue)
lldb::TargetSP GetTargetSP() const
CompilerType GetCompilerType()
virtual lldb::ValueObjectSP GetStaticValue()
virtual bool IsSynthetic()
const ExecutionContextRef & GetExecutionContextRef() const
#define UINT32_MAX
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.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:338
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 &)
std::shared_ptr< lldb_private::TypeSummaryImpl > TypeSummaryImplSP
std::shared_ptr< lldb_private::TypeFormatImpl > TypeFormatImplSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::TypeNameSpecifierImpl > TypeNameSpecifierImplSP
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...
@ eFormatAddressInfo
Describe what an address points to (func + offset with file/line, symbol + offset,...
@ eFormatVectorOfUInt128
@ eFormatVectorOfUInt8
@ eFormatComplexFloat
@ eFormatVectorOfFloat32
@ eFormatVectorOfSInt32
@ eFormatVectorOfSInt8
@ eFormatVectorOfUInt16
@ eFormatHexUppercase
@ eFormatVectorOfFloat64
@ eFormatCharPrintable
Only printable characters, '.' if not printable.
@ eFormatComplexInteger
Integer complex type.
@ eFormatVectorOfSInt16
@ eFormatFloat128
Disambiguate between 128-bit long double (which uses eFormatFloat) and __float128 (which uses eFormat...
@ 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.
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
std::shared_ptr< lldb_private::Target > TargetSP
const char * format_name
const char format_char