Path: blob/main/contrib/llvm-project/lldb/source/DataFormatters/FormatManager.cpp
39587 views
//===-- FormatManager.cpp -------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/DataFormatters/FormatManager.h"910#include "lldb/Core/Debugger.h"11#include "lldb/Core/ValueObject.h"12#include "lldb/DataFormatters/FormattersHelpers.h"13#include "lldb/DataFormatters/LanguageCategory.h"14#include "lldb/Interpreter/ScriptInterpreter.h"15#include "lldb/Target/ExecutionContext.h"16#include "lldb/Target/Language.h"17#include "lldb/Utility/LLDBLog.h"18#include "lldb/Utility/Log.h"19#include "llvm/ADT/STLExtras.h"2021using namespace lldb;22using namespace lldb_private;23using namespace lldb_private::formatters;2425struct FormatInfo {26Format format;27const char format_char; // One or more format characters that can be used for28// this format.29const char *format_name; // Long format name that can be used to specify the30// current format31};3233static 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};7576static_assert((sizeof(g_format_infos) / sizeof(g_format_infos[0])) ==77kNumFormats,78"All formats must have a corresponding info entry.");7980static uint32_t g_num_format_infos = std::size(g_format_infos);8182static bool GetFormatFromFormatChar(char format_char, Format &format) {83for (uint32_t i = 0; i < g_num_format_infos; ++i) {84if (g_format_infos[i].format_char == format_char) {85format = g_format_infos[i].format;86return true;87}88}89format = eFormatInvalid;90return false;91}9293static bool GetFormatFromFormatName(llvm::StringRef format_name,94Format &format) {95uint32_t i;96for (i = 0; i < g_num_format_infos; ++i) {97if (format_name.equals_insensitive(g_format_infos[i].format_name)) {98format = g_format_infos[i].format;99return true;100}101}102103for (i = 0; i < g_num_format_infos; ++i) {104if (llvm::StringRef(g_format_infos[i].format_name)105.starts_with_insensitive(format_name)) {106format = g_format_infos[i].format;107return true;108}109}110format = eFormatInvalid;111return false;112}113114void FormatManager::Changed() {115++m_last_revision;116m_format_cache.Clear();117std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex);118for (auto &iter : m_language_categories_map) {119if (iter.second)120iter.second->GetFormatCache().Clear();121}122}123124bool FormatManager::GetFormatFromCString(const char *format_cstr,125lldb::Format &format) {126bool success = false;127if (format_cstr && format_cstr[0]) {128if (format_cstr[1] == '\0') {129success = GetFormatFromFormatChar(format_cstr[0], format);130if (success)131return true;132}133134success = GetFormatFromFormatName(format_cstr, format);135}136if (!success)137format = eFormatInvalid;138return success;139}140141char FormatManager::GetFormatAsFormatChar(lldb::Format format) {142for (uint32_t i = 0; i < g_num_format_infos; ++i) {143if (g_format_infos[i].format == format)144return g_format_infos[i].format_char;145}146return '\0';147}148149const char *FormatManager::GetFormatAsCString(Format format) {150if (format >= eFormatDefault && format < kNumFormats)151return g_format_infos[format].format_name;152return nullptr;153}154155void FormatManager::EnableAllCategories() {156m_categories_map.EnableAllCategories();157std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex);158for (auto &iter : m_language_categories_map) {159if (iter.second)160iter.second->Enable();161}162}163164void FormatManager::DisableAllCategories() {165m_categories_map.DisableAllCategories();166std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex);167for (auto &iter : m_language_categories_map) {168if (iter.second)169iter.second->Disable();170}171}172173void FormatManager::GetPossibleMatches(174ValueObject &valobj, CompilerType compiler_type,175lldb::DynamicValueType use_dynamic, FormattersMatchVector &entries,176FormattersMatchCandidate::Flags current_flags, bool root_level) {177compiler_type = compiler_type.GetTypeForFormatters();178ConstString type_name(compiler_type.GetTypeName());179// A ValueObject that couldn't be made correctly won't necessarily have a180// target. We aren't going to find a formatter in this case anyway, so we181// should just exit.182TargetSP target_sp = valobj.GetTargetSP();183if (!target_sp)184return;185ScriptInterpreter *script_interpreter =186target_sp->GetDebugger().GetScriptInterpreter();187if (valobj.GetBitfieldBitSize() > 0) {188StreamString sstring;189sstring.Printf("%s:%d", type_name.AsCString(), valobj.GetBitfieldBitSize());190ConstString bitfieldname(sstring.GetString());191entries.push_back({bitfieldname, script_interpreter,192TypeImpl(compiler_type), current_flags});193}194195if (!compiler_type.IsMeaninglessWithoutDynamicResolution()) {196entries.push_back({type_name, script_interpreter, TypeImpl(compiler_type),197current_flags});198199ConstString display_type_name(compiler_type.GetTypeName());200if (display_type_name != type_name)201entries.push_back({display_type_name, script_interpreter,202TypeImpl(compiler_type), current_flags});203}204205for (bool is_rvalue_ref = true, j = true;206j && compiler_type.IsReferenceType(nullptr, &is_rvalue_ref); j = false) {207CompilerType non_ref_type = compiler_type.GetNonReferenceType();208GetPossibleMatches(valobj, non_ref_type, use_dynamic, entries,209current_flags.WithStrippedReference());210if (non_ref_type.IsTypedefType()) {211CompilerType deffed_referenced_type = non_ref_type.GetTypedefedType();212deffed_referenced_type =213is_rvalue_ref ? deffed_referenced_type.GetRValueReferenceType()214: deffed_referenced_type.GetLValueReferenceType();215// this is not exactly the usual meaning of stripping typedefs216GetPossibleMatches(217valobj, deffed_referenced_type,218use_dynamic, entries, current_flags.WithStrippedTypedef());219}220}221222if (compiler_type.IsPointerType()) {223CompilerType non_ptr_type = compiler_type.GetPointeeType();224GetPossibleMatches(valobj, non_ptr_type, use_dynamic, entries,225current_flags.WithStrippedPointer());226if (non_ptr_type.IsTypedefType()) {227CompilerType deffed_pointed_type =228non_ptr_type.GetTypedefedType().GetPointerType();229// this is not exactly the usual meaning of stripping typedefs230GetPossibleMatches(valobj, deffed_pointed_type, use_dynamic, entries,231current_flags.WithStrippedTypedef());232}233}234235// For arrays with typedef-ed elements, we add a candidate with the typedef236// stripped.237uint64_t array_size;238if (compiler_type.IsArrayType(nullptr, &array_size, nullptr)) {239ExecutionContext exe_ctx(valobj.GetExecutionContextRef());240CompilerType element_type = compiler_type.GetArrayElementType(241exe_ctx.GetBestExecutionContextScope());242if (element_type.IsTypedefType()) {243// Get the stripped element type and compute the stripped array type244// from it.245CompilerType deffed_array_type =246element_type.GetTypedefedType().GetArrayType(array_size);247// this is not exactly the usual meaning of stripping typedefs248GetPossibleMatches(249valobj, deffed_array_type,250use_dynamic, entries, current_flags.WithStrippedTypedef());251}252}253254for (lldb::LanguageType language_type :255GetCandidateLanguages(valobj.GetObjectRuntimeLanguage())) {256if (Language *language = Language::FindPlugin(language_type)) {257for (const FormattersMatchCandidate& candidate :258language->GetPossibleFormattersMatches(valobj, use_dynamic)) {259entries.push_back(candidate);260}261}262}263264// try to strip typedef chains265if (compiler_type.IsTypedefType()) {266CompilerType deffed_type = compiler_type.GetTypedefedType();267GetPossibleMatches(valobj, deffed_type, use_dynamic, entries,268current_flags.WithStrippedTypedef());269}270271if (root_level) {272do {273if (!compiler_type.IsValid())274break;275276CompilerType unqual_compiler_ast_type =277compiler_type.GetFullyUnqualifiedType();278if (!unqual_compiler_ast_type.IsValid())279break;280if (unqual_compiler_ast_type.GetOpaqueQualType() !=281compiler_type.GetOpaqueQualType())282GetPossibleMatches(valobj, unqual_compiler_ast_type, use_dynamic,283entries, current_flags);284} while (false);285286// if all else fails, go to static type287if (valobj.IsDynamic()) {288lldb::ValueObjectSP static_value_sp(valobj.GetStaticValue());289if (static_value_sp)290GetPossibleMatches(*static_value_sp.get(),291static_value_sp->GetCompilerType(), use_dynamic,292entries, current_flags, true);293}294}295}296297lldb::TypeFormatImplSP298FormatManager::GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp) {299if (!type_sp)300return lldb::TypeFormatImplSP();301lldb::TypeFormatImplSP format_chosen_sp;302uint32_t num_categories = m_categories_map.GetCount();303lldb::TypeCategoryImplSP category_sp;304uint32_t prio_category = UINT32_MAX;305for (uint32_t category_id = 0; category_id < num_categories; category_id++) {306category_sp = GetCategoryAtIndex(category_id);307if (!category_sp->IsEnabled())308continue;309lldb::TypeFormatImplSP format_current_sp =310category_sp->GetFormatForType(type_sp);311if (format_current_sp &&312(format_chosen_sp.get() == nullptr ||313(prio_category > category_sp->GetEnabledPosition()))) {314prio_category = category_sp->GetEnabledPosition();315format_chosen_sp = format_current_sp;316}317}318return format_chosen_sp;319}320321lldb::TypeSummaryImplSP322FormatManager::GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp) {323if (!type_sp)324return lldb::TypeSummaryImplSP();325lldb::TypeSummaryImplSP summary_chosen_sp;326uint32_t num_categories = m_categories_map.GetCount();327lldb::TypeCategoryImplSP category_sp;328uint32_t prio_category = UINT32_MAX;329for (uint32_t category_id = 0; category_id < num_categories; category_id++) {330category_sp = GetCategoryAtIndex(category_id);331if (!category_sp->IsEnabled())332continue;333lldb::TypeSummaryImplSP summary_current_sp =334category_sp->GetSummaryForType(type_sp);335if (summary_current_sp &&336(summary_chosen_sp.get() == nullptr ||337(prio_category > category_sp->GetEnabledPosition()))) {338prio_category = category_sp->GetEnabledPosition();339summary_chosen_sp = summary_current_sp;340}341}342return summary_chosen_sp;343}344345lldb::TypeFilterImplSP346FormatManager::GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp) {347if (!type_sp)348return lldb::TypeFilterImplSP();349lldb::TypeFilterImplSP filter_chosen_sp;350uint32_t num_categories = m_categories_map.GetCount();351lldb::TypeCategoryImplSP category_sp;352uint32_t prio_category = UINT32_MAX;353for (uint32_t category_id = 0; category_id < num_categories; category_id++) {354category_sp = GetCategoryAtIndex(category_id);355if (!category_sp->IsEnabled())356continue;357lldb::TypeFilterImplSP filter_current_sp(358(TypeFilterImpl *)category_sp->GetFilterForType(type_sp).get());359if (filter_current_sp &&360(filter_chosen_sp.get() == nullptr ||361(prio_category > category_sp->GetEnabledPosition()))) {362prio_category = category_sp->GetEnabledPosition();363filter_chosen_sp = filter_current_sp;364}365}366return filter_chosen_sp;367}368369lldb::ScriptedSyntheticChildrenSP370FormatManager::GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp) {371if (!type_sp)372return lldb::ScriptedSyntheticChildrenSP();373lldb::ScriptedSyntheticChildrenSP synth_chosen_sp;374uint32_t num_categories = m_categories_map.GetCount();375lldb::TypeCategoryImplSP category_sp;376uint32_t prio_category = UINT32_MAX;377for (uint32_t category_id = 0; category_id < num_categories; category_id++) {378category_sp = GetCategoryAtIndex(category_id);379if (!category_sp->IsEnabled())380continue;381lldb::ScriptedSyntheticChildrenSP synth_current_sp(382(ScriptedSyntheticChildren *)category_sp->GetSyntheticForType(type_sp)383.get());384if (synth_current_sp &&385(synth_chosen_sp.get() == nullptr ||386(prio_category > category_sp->GetEnabledPosition()))) {387prio_category = category_sp->GetEnabledPosition();388synth_chosen_sp = synth_current_sp;389}390}391return synth_chosen_sp;392}393394void FormatManager::ForEachCategory(TypeCategoryMap::ForEachCallback callback) {395m_categories_map.ForEach(callback);396std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex);397for (const auto &entry : m_language_categories_map) {398if (auto category_sp = entry.second->GetCategory()) {399if (!callback(category_sp))400break;401}402}403}404405lldb::TypeCategoryImplSP406FormatManager::GetCategory(ConstString category_name, bool can_create) {407if (!category_name)408return GetCategory(m_default_category_name);409lldb::TypeCategoryImplSP category;410if (m_categories_map.Get(category_name, category))411return category;412413if (!can_create)414return lldb::TypeCategoryImplSP();415416m_categories_map.Add(417category_name,418lldb::TypeCategoryImplSP(new TypeCategoryImpl(this, category_name)));419return GetCategory(category_name);420}421422lldb::Format FormatManager::GetSingleItemFormat(lldb::Format vector_format) {423switch (vector_format) {424case eFormatVectorOfChar:425return eFormatCharArray;426427case eFormatVectorOfSInt8:428case eFormatVectorOfSInt16:429case eFormatVectorOfSInt32:430case eFormatVectorOfSInt64:431return eFormatDecimal;432433case eFormatVectorOfUInt8:434case eFormatVectorOfUInt16:435case eFormatVectorOfUInt32:436case eFormatVectorOfUInt64:437case eFormatVectorOfUInt128:438return eFormatHex;439440case eFormatVectorOfFloat16:441case eFormatVectorOfFloat32:442case eFormatVectorOfFloat64:443return eFormatFloat;444445default:446return lldb::eFormatInvalid;447}448}449450bool FormatManager::ShouldPrintAsOneLiner(ValueObject &valobj) {451TargetSP target_sp = valobj.GetTargetSP();452// if settings say no oneline whatsoever453if (target_sp && !target_sp->GetDebugger().GetAutoOneLineSummaries())454return false; // then don't oneline455456// if this object has a summary, then ask the summary457if (valobj.GetSummaryFormat().get() != nullptr)458return valobj.GetSummaryFormat()->IsOneLiner();459460const size_t max_num_children =461(target_sp ? *target_sp : Target::GetGlobalProperties())462.GetMaximumNumberOfChildrenToDisplay();463auto num_children = valobj.GetNumChildren(max_num_children);464if (!num_children) {465llvm::consumeError(num_children.takeError());466return true;467}468// no children, no party469if (*num_children == 0)470return false;471472// ask the type if it has any opinion about this eLazyBoolCalculate == no473// opinion; other values should be self explanatory474CompilerType compiler_type(valobj.GetCompilerType());475if (compiler_type.IsValid()) {476switch (compiler_type.ShouldPrintAsOneLiner(&valobj)) {477case eLazyBoolNo:478return false;479case eLazyBoolYes:480return true;481case eLazyBoolCalculate:482break;483}484}485486size_t total_children_name_len = 0;487488for (size_t idx = 0; idx < *num_children; idx++) {489bool is_synth_val = false;490ValueObjectSP child_sp(valobj.GetChildAtIndex(idx));491// something is wrong here - bail out492if (!child_sp)493return false;494495// also ask the child's type if it has any opinion496CompilerType child_compiler_type(child_sp->GetCompilerType());497if (child_compiler_type.IsValid()) {498switch (child_compiler_type.ShouldPrintAsOneLiner(child_sp.get())) {499case eLazyBoolYes:500// an opinion of yes is only binding for the child, so keep going501case eLazyBoolCalculate:502break;503case eLazyBoolNo:504// but if the child says no, then it's a veto on the whole thing505return false;506}507}508509// if we decided to define synthetic children for a type, we probably care510// enough to show them, but avoid nesting children in children511if (child_sp->GetSyntheticChildren().get() != nullptr) {512ValueObjectSP synth_sp(child_sp->GetSyntheticValue());513// wait.. wat? just get out of here..514if (!synth_sp)515return false;516// but if we only have them to provide a value, keep going517if (!synth_sp->MightHaveChildren() &&518synth_sp->DoesProvideSyntheticValue())519is_synth_val = true;520else521return false;522}523524total_children_name_len += child_sp->GetName().GetLength();525526// 50 itself is a "randomly" chosen number - the idea is that527// overly long structs should not get this treatment528// FIXME: maybe make this a user-tweakable setting?529if (total_children_name_len > 50)530return false;531532// if a summary is there..533if (child_sp->GetSummaryFormat()) {534// and it wants children, then bail out535if (child_sp->GetSummaryFormat()->DoesPrintChildren(child_sp.get()))536return false;537}538539// if this child has children..540if (child_sp->HasChildren()) {541// ...and no summary...542// (if it had a summary and the summary wanted children, we would have543// bailed out anyway544// so this only makes us bail out if this has no summary and we would545// then print children)546if (!child_sp->GetSummaryFormat() && !is_synth_val) // but again only do547// that if not a548// synthetic valued549// child550return false; // then bail out551}552}553return true;554}555556ConstString FormatManager::GetTypeForCache(ValueObject &valobj,557lldb::DynamicValueType use_dynamic) {558ValueObjectSP valobj_sp = valobj.GetQualifiedRepresentationIfAvailable(559use_dynamic, valobj.IsSynthetic());560if (valobj_sp && valobj_sp->GetCompilerType().IsValid()) {561if (!valobj_sp->GetCompilerType().IsMeaninglessWithoutDynamicResolution())562return valobj_sp->GetQualifiedTypeName();563}564return ConstString();565}566567std::vector<lldb::LanguageType>568FormatManager::GetCandidateLanguages(lldb::LanguageType lang_type) {569switch (lang_type) {570case lldb::eLanguageTypeC:571case lldb::eLanguageTypeC89:572case lldb::eLanguageTypeC99:573case lldb::eLanguageTypeC11:574case lldb::eLanguageTypeC_plus_plus:575case lldb::eLanguageTypeC_plus_plus_03:576case lldb::eLanguageTypeC_plus_plus_11:577case lldb::eLanguageTypeC_plus_plus_14:578return {lldb::eLanguageTypeC_plus_plus, lldb::eLanguageTypeObjC};579default:580return {lang_type};581}582llvm_unreachable("Fully covered switch");583}584585LanguageCategory *586FormatManager::GetCategoryForLanguage(lldb::LanguageType lang_type) {587std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex);588auto iter = m_language_categories_map.find(lang_type),589end = m_language_categories_map.end();590if (iter != end)591return iter->second.get();592LanguageCategory *lang_category = new LanguageCategory(lang_type);593m_language_categories_map[lang_type] =594LanguageCategory::UniquePointer(lang_category);595return lang_category;596}597598template <typename ImplSP>599ImplSP FormatManager::GetHardcoded(FormattersMatchData &match_data) {600ImplSP retval_sp;601for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) {602if (LanguageCategory *lang_category = GetCategoryForLanguage(lang_type)) {603if (lang_category->GetHardcoded(*this, match_data, retval_sp))604return retval_sp;605}606}607return retval_sp;608}609610namespace {611template <typename ImplSP> const char *FormatterKind;612template <> const char *FormatterKind<lldb::TypeFormatImplSP> = "format";613template <> const char *FormatterKind<lldb::TypeSummaryImplSP> = "summary";614template <> const char *FormatterKind<lldb::SyntheticChildrenSP> = "synthetic";615} // namespace616617#define FORMAT_LOG(Message) "[%s] " Message, FormatterKind<ImplSP>618619template <typename ImplSP>620ImplSP FormatManager::Get(ValueObject &valobj,621lldb::DynamicValueType use_dynamic) {622FormattersMatchData match_data(valobj, use_dynamic);623if (ImplSP retval_sp = GetCached<ImplSP>(match_data))624return retval_sp;625626Log *log = GetLog(LLDBLog::DataFormatters);627628LLDB_LOGF(log, FORMAT_LOG("Search failed. Giving language a chance."));629for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) {630if (LanguageCategory *lang_category = GetCategoryForLanguage(lang_type)) {631ImplSP retval_sp;632if (lang_category->Get(match_data, retval_sp))633if (retval_sp) {634LLDB_LOGF(log, FORMAT_LOG("Language search success. Returning."));635return retval_sp;636}637}638}639640LLDB_LOGF(log, FORMAT_LOG("Search failed. Giving hardcoded a chance."));641return GetHardcoded<ImplSP>(match_data);642}643644template <typename ImplSP>645ImplSP FormatManager::GetCached(FormattersMatchData &match_data) {646ImplSP retval_sp;647Log *log = GetLog(LLDBLog::DataFormatters);648if (match_data.GetTypeForCache()) {649LLDB_LOGF(log, "\n\n" FORMAT_LOG("Looking into cache for type %s"),650match_data.GetTypeForCache().AsCString("<invalid>"));651if (m_format_cache.Get(match_data.GetTypeForCache(), retval_sp)) {652if (log) {653LLDB_LOGF(log, FORMAT_LOG("Cache search success. Returning."));654LLDB_LOGV(log, "Cache hits: {0} - Cache Misses: {1}",655m_format_cache.GetCacheHits(),656m_format_cache.GetCacheMisses());657}658return retval_sp;659}660LLDB_LOGF(log, FORMAT_LOG("Cache search failed. Going normal route"));661}662663m_categories_map.Get(match_data, retval_sp);664if (match_data.GetTypeForCache() && (!retval_sp || !retval_sp->NonCacheable())) {665LLDB_LOGF(log, FORMAT_LOG("Caching %p for type %s"),666static_cast<void *>(retval_sp.get()),667match_data.GetTypeForCache().AsCString("<invalid>"));668m_format_cache.Set(match_data.GetTypeForCache(), retval_sp);669}670LLDB_LOGV(log, "Cache hits: {0} - Cache Misses: {1}",671m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses());672return retval_sp;673}674675#undef FORMAT_LOG676677lldb::TypeFormatImplSP678FormatManager::GetFormat(ValueObject &valobj,679lldb::DynamicValueType use_dynamic) {680return Get<lldb::TypeFormatImplSP>(valobj, use_dynamic);681}682683lldb::TypeSummaryImplSP684FormatManager::GetSummaryFormat(ValueObject &valobj,685lldb::DynamicValueType use_dynamic) {686return Get<lldb::TypeSummaryImplSP>(valobj, use_dynamic);687}688689lldb::SyntheticChildrenSP690FormatManager::GetSyntheticChildren(ValueObject &valobj,691lldb::DynamicValueType use_dynamic) {692return Get<lldb::SyntheticChildrenSP>(valobj, use_dynamic);693}694695FormatManager::FormatManager()696: m_last_revision(0), m_format_cache(), m_language_categories_mutex(),697m_language_categories_map(), m_named_summaries_map(this),698m_categories_map(this), m_default_category_name(ConstString("default")),699m_system_category_name(ConstString("system")),700m_vectortypes_category_name(ConstString("VectorTypes")) {701LoadSystemFormatters();702LoadVectorFormatters();703704EnableCategory(m_vectortypes_category_name, TypeCategoryMap::Last,705lldb::eLanguageTypeObjC_plus_plus);706EnableCategory(m_system_category_name, TypeCategoryMap::Last,707lldb::eLanguageTypeObjC_plus_plus);708}709710void FormatManager::LoadSystemFormatters() {711TypeSummaryImpl::Flags string_flags;712string_flags.SetCascades(true)713.SetSkipPointers(true)714.SetSkipReferences(false)715.SetDontShowChildren(true)716.SetDontShowValue(false)717.SetShowMembersOneLiner(false)718.SetHideItemNames(false);719720TypeSummaryImpl::Flags string_array_flags;721string_array_flags.SetCascades(true)722.SetSkipPointers(true)723.SetSkipReferences(false)724.SetDontShowChildren(true)725.SetDontShowValue(true)726.SetShowMembersOneLiner(false)727.SetHideItemNames(false);728729lldb::TypeSummaryImplSP string_format(730new StringSummaryFormat(string_flags, "${var%s}"));731732lldb::TypeSummaryImplSP string_array_format(733new StringSummaryFormat(string_array_flags, "${var%char[]}"));734735TypeCategoryImpl::SharedPointer sys_category_sp =736GetCategory(m_system_category_name);737738sys_category_sp->AddTypeSummary(R"(^(unsigned )?char ?(\*|\[\])$)",739eFormatterMatchRegex, string_format);740741sys_category_sp->AddTypeSummary(R"(^((un)?signed )?char ?\[[0-9]+\]$)",742eFormatterMatchRegex, string_array_format);743744lldb::TypeSummaryImplSP ostype_summary(745new StringSummaryFormat(TypeSummaryImpl::Flags()746.SetCascades(false)747.SetSkipPointers(true)748.SetSkipReferences(true)749.SetDontShowChildren(true)750.SetDontShowValue(false)751.SetShowMembersOneLiner(false)752.SetHideItemNames(false),753"${var%O}"));754755sys_category_sp->AddTypeSummary("OSType", eFormatterMatchExact,756ostype_summary);757758TypeFormatImpl::Flags fourchar_flags;759fourchar_flags.SetCascades(true).SetSkipPointers(true).SetSkipReferences(760true);761762AddFormat(sys_category_sp, lldb::eFormatOSType, "FourCharCode",763fourchar_flags);764}765766void FormatManager::LoadVectorFormatters() {767TypeCategoryImpl::SharedPointer vectors_category_sp =768GetCategory(m_vectortypes_category_name);769770TypeSummaryImpl::Flags vector_flags;771vector_flags.SetCascades(true)772.SetSkipPointers(true)773.SetSkipReferences(false)774.SetDontShowChildren(true)775.SetDontShowValue(false)776.SetShowMembersOneLiner(true)777.SetHideItemNames(true);778779AddStringSummary(vectors_category_sp, "${var.uint128}", "builtin_type_vec128",780vector_flags);781AddStringSummary(vectors_category_sp, "", "float[4]", vector_flags);782AddStringSummary(vectors_category_sp, "", "int32_t[4]", vector_flags);783AddStringSummary(vectors_category_sp, "", "int16_t[8]", vector_flags);784AddStringSummary(vectors_category_sp, "", "vDouble", vector_flags);785AddStringSummary(vectors_category_sp, "", "vFloat", vector_flags);786AddStringSummary(vectors_category_sp, "", "vSInt8", vector_flags);787AddStringSummary(vectors_category_sp, "", "vSInt16", vector_flags);788AddStringSummary(vectors_category_sp, "", "vSInt32", vector_flags);789AddStringSummary(vectors_category_sp, "", "vUInt16", vector_flags);790AddStringSummary(vectors_category_sp, "", "vUInt8", vector_flags);791AddStringSummary(vectors_category_sp, "", "vUInt16", vector_flags);792AddStringSummary(vectors_category_sp, "", "vUInt32", vector_flags);793AddStringSummary(vectors_category_sp, "", "vBool32", vector_flags);794}795796797