diff options
Diffstat (limited to 'lldb/source/DataFormatters')
17 files changed, 4552 insertions, 5356 deletions
diff --git a/lldb/source/DataFormatters/CXXFunctionPointer.cpp b/lldb/source/DataFormatters/CXXFunctionPointer.cpp index c9e0ccb2969..88e44440944 100644 --- a/lldb/source/DataFormatters/CXXFunctionPointer.cpp +++ b/lldb/source/DataFormatters/CXXFunctionPointer.cpp @@ -1,4 +1,5 @@ -//===-- CXXFormatterFunctions.cpp---------------------------------*- C++ -*-===// +//===-- CXXFormatterFunctions.cpp---------------------------------*- C++ +//-*-===// // // The LLVM Compiler Infrastructure // @@ -20,47 +21,38 @@ using namespace lldb; using namespace lldb_private; using namespace lldb_private::formatters; -bool -lldb_private::formatters::CXXFunctionPointerSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options) -{ - std::string destination; - StreamString sstr; - AddressType func_ptr_address_type = eAddressTypeInvalid; - addr_t func_ptr_address = valobj.GetPointerValue (&func_ptr_address_type); - if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS) - { - switch (func_ptr_address_type) - { - case eAddressTypeInvalid: - case eAddressTypeFile: - case eAddressTypeHost: - break; - - case eAddressTypeLoad: - { - ExecutionContext exe_ctx (valobj.GetExecutionContextRef()); - - Address so_addr; - Target *target = exe_ctx.GetTargetPtr(); - if (target && target->GetSectionLoadList().IsEmpty() == false) - { - if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr)) - { - so_addr.Dump (&sstr, - exe_ctx.GetBestExecutionContextScope(), - Address::DumpStyleResolvedDescription, - Address::DumpStyleSectionNameOffset); - } - } - } - break; +bool lldb_private::formatters::CXXFunctionPointerSummaryProvider( + ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) { + std::string destination; + StreamString sstr; + AddressType func_ptr_address_type = eAddressTypeInvalid; + addr_t func_ptr_address = valobj.GetPointerValue(&func_ptr_address_type); + if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS) { + switch (func_ptr_address_type) { + case eAddressTypeInvalid: + case eAddressTypeFile: + case eAddressTypeHost: + break; + + case eAddressTypeLoad: { + ExecutionContext exe_ctx(valobj.GetExecutionContextRef()); + + Address so_addr; + Target *target = exe_ctx.GetTargetPtr(); + if (target && target->GetSectionLoadList().IsEmpty() == false) { + if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, + so_addr)) { + so_addr.Dump(&sstr, exe_ctx.GetBestExecutionContextScope(), + Address::DumpStyleResolvedDescription, + Address::DumpStyleSectionNameOffset); } + } + } break; } - if (sstr.GetSize() > 0) - { - stream.Printf("(%s)", sstr.GetData()); - return true; - } - else - return false; + } + if (sstr.GetSize() > 0) { + stream.Printf("(%s)", sstr.GetData()); + return true; + } else + return false; } diff --git a/lldb/source/DataFormatters/DataVisualization.cpp b/lldb/source/DataFormatters/DataVisualization.cpp index 14cf13d2f18..2a2d4b8b553 100644 --- a/lldb/source/DataFormatters/DataVisualization.cpp +++ b/lldb/source/DataFormatters/DataVisualization.cpp @@ -1,4 +1,5 @@ -//===-- DataVisualization.cpp ---------------------------------------*- C++ -*-===// +//===-- DataVisualization.cpp ---------------------------------------*- C++ +//-*-===// // // The LLVM Compiler Infrastructure // @@ -17,264 +18,209 @@ using namespace lldb; using namespace lldb_private; -static FormatManager& -GetFormatManager() -{ - static FormatManager g_format_manager; - return g_format_manager; +static FormatManager &GetFormatManager() { + static FormatManager g_format_manager; + return g_format_manager; } -void -DataVisualization::ForceUpdate () -{ - GetFormatManager().Changed(); -} +void DataVisualization::ForceUpdate() { GetFormatManager().Changed(); } -uint32_t -DataVisualization::GetCurrentRevision () -{ - return GetFormatManager().GetCurrentRevision(); +uint32_t DataVisualization::GetCurrentRevision() { + return GetFormatManager().GetCurrentRevision(); } -bool -DataVisualization::ShouldPrintAsOneLiner (ValueObject& valobj) -{ - return GetFormatManager().ShouldPrintAsOneLiner(valobj); +bool DataVisualization::ShouldPrintAsOneLiner(ValueObject &valobj) { + return GetFormatManager().ShouldPrintAsOneLiner(valobj); } lldb::TypeFormatImplSP -DataVisualization::GetFormat (ValueObject& valobj, lldb::DynamicValueType use_dynamic) -{ - return GetFormatManager().GetFormat(valobj, use_dynamic); +DataVisualization::GetFormat(ValueObject &valobj, + lldb::DynamicValueType use_dynamic) { + return GetFormatManager().GetFormat(valobj, use_dynamic); } lldb::TypeFormatImplSP -DataVisualization::GetFormatForType (lldb::TypeNameSpecifierImplSP type_sp) -{ - return GetFormatManager().GetFormatForType(type_sp); +DataVisualization::GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp) { + return GetFormatManager().GetFormatForType(type_sp); } lldb::TypeSummaryImplSP -DataVisualization::GetSummaryFormat (ValueObject& valobj, lldb::DynamicValueType use_dynamic) -{ - return GetFormatManager().GetSummaryFormat(valobj, use_dynamic); +DataVisualization::GetSummaryFormat(ValueObject &valobj, + lldb::DynamicValueType use_dynamic) { + return GetFormatManager().GetSummaryFormat(valobj, use_dynamic); } lldb::TypeSummaryImplSP -DataVisualization::GetSummaryForType (lldb::TypeNameSpecifierImplSP type_sp) -{ - return GetFormatManager().GetSummaryForType(type_sp); +DataVisualization::GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp) { + return GetFormatManager().GetSummaryForType(type_sp); } #ifndef LLDB_DISABLE_PYTHON lldb::SyntheticChildrenSP -DataVisualization::GetSyntheticChildren (ValueObject& valobj, - lldb::DynamicValueType use_dynamic) -{ - return GetFormatManager().GetSyntheticChildren(valobj, use_dynamic); +DataVisualization::GetSyntheticChildren(ValueObject &valobj, + lldb::DynamicValueType use_dynamic) { + return GetFormatManager().GetSyntheticChildren(valobj, use_dynamic); } #endif #ifndef LLDB_DISABLE_PYTHON -lldb::SyntheticChildrenSP -DataVisualization::GetSyntheticChildrenForType (lldb::TypeNameSpecifierImplSP type_sp) -{ - return GetFormatManager().GetSyntheticChildrenForType(type_sp); +lldb::SyntheticChildrenSP DataVisualization::GetSyntheticChildrenForType( + lldb::TypeNameSpecifierImplSP type_sp) { + return GetFormatManager().GetSyntheticChildrenForType(type_sp); } #endif lldb::TypeFilterImplSP -DataVisualization::GetFilterForType (lldb::TypeNameSpecifierImplSP type_sp) -{ - return GetFormatManager().GetFilterForType(type_sp); +DataVisualization::GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp) { + return GetFormatManager().GetFilterForType(type_sp); } #ifndef LLDB_DISABLE_PYTHON lldb::ScriptedSyntheticChildrenSP -DataVisualization::GetSyntheticForType (lldb::TypeNameSpecifierImplSP type_sp) -{ - return GetFormatManager().GetSyntheticForType(type_sp); +DataVisualization::GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp) { + return GetFormatManager().GetSyntheticForType(type_sp); } #endif lldb::TypeValidatorImplSP -DataVisualization::GetValidator (ValueObject& valobj, lldb::DynamicValueType use_dynamic) -{ - return GetFormatManager().GetValidator(valobj, use_dynamic); +DataVisualization::GetValidator(ValueObject &valobj, + lldb::DynamicValueType use_dynamic) { + return GetFormatManager().GetValidator(valobj, use_dynamic); } lldb::TypeValidatorImplSP -DataVisualization::GetValidatorForType (lldb::TypeNameSpecifierImplSP type_sp) -{ - return GetFormatManager().GetValidatorForType(type_sp); -} - -bool -DataVisualization::AnyMatches (ConstString type_name, - TypeCategoryImpl::FormatCategoryItems items, - bool only_enabled, - const char** matching_category, - TypeCategoryImpl::FormatCategoryItems* matching_type) -{ - return GetFormatManager().AnyMatches(type_name, - items, - only_enabled, - matching_category, - matching_type); -} - -bool -DataVisualization::Categories::GetCategory (const ConstString &category, lldb::TypeCategoryImplSP &entry, - bool allow_create) -{ - entry = GetFormatManager().GetCategory(category, allow_create); - return (entry.get() != NULL); -} - -bool -DataVisualization::Categories::GetCategory (lldb::LanguageType language, lldb::TypeCategoryImplSP &entry) -{ - if (LanguageCategory *lang_category = GetFormatManager().GetCategoryForLanguage(language)) - entry = lang_category->GetCategory(); - return (entry.get() != nullptr); -} - -void -DataVisualization::Categories::Add (const ConstString &category) -{ - GetFormatManager().GetCategory(category); -} - -bool -DataVisualization::Categories::Delete (const ConstString &category) -{ - GetFormatManager().DisableCategory(category); - return GetFormatManager().DeleteCategory(category); +DataVisualization::GetValidatorForType(lldb::TypeNameSpecifierImplSP type_sp) { + return GetFormatManager().GetValidatorForType(type_sp); +} + +bool DataVisualization::AnyMatches( + ConstString type_name, TypeCategoryImpl::FormatCategoryItems items, + bool only_enabled, const char **matching_category, + TypeCategoryImpl::FormatCategoryItems *matching_type) { + return GetFormatManager().AnyMatches(type_name, items, only_enabled, + matching_category, matching_type); +} + +bool DataVisualization::Categories::GetCategory(const ConstString &category, + lldb::TypeCategoryImplSP &entry, + bool allow_create) { + entry = GetFormatManager().GetCategory(category, allow_create); + return (entry.get() != NULL); +} + +bool DataVisualization::Categories::GetCategory( + lldb::LanguageType language, lldb::TypeCategoryImplSP &entry) { + if (LanguageCategory *lang_category = + GetFormatManager().GetCategoryForLanguage(language)) + entry = lang_category->GetCategory(); + return (entry.get() != nullptr); +} + +void DataVisualization::Categories::Add(const ConstString &category) { + GetFormatManager().GetCategory(category); +} + +bool DataVisualization::Categories::Delete(const ConstString &category) { + GetFormatManager().DisableCategory(category); + return GetFormatManager().DeleteCategory(category); } -void -DataVisualization::Categories::Clear () -{ - GetFormatManager().ClearCategories(); +void DataVisualization::Categories::Clear() { + GetFormatManager().ClearCategories(); } -void -DataVisualization::Categories::Clear (const ConstString &category) -{ - GetFormatManager().GetCategory(category)->Clear(eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary); +void DataVisualization::Categories::Clear(const ConstString &category) { + GetFormatManager().GetCategory(category)->Clear( + eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary); } -void -DataVisualization::Categories::Enable (const ConstString& category, - TypeCategoryMap::Position pos) -{ - if (GetFormatManager().GetCategory(category)->IsEnabled()) - GetFormatManager().DisableCategory(category); - GetFormatManager().EnableCategory(category, pos, std::initializer_list<lldb::LanguageType>()); +void DataVisualization::Categories::Enable(const ConstString &category, + TypeCategoryMap::Position pos) { + if (GetFormatManager().GetCategory(category)->IsEnabled()) + GetFormatManager().DisableCategory(category); + GetFormatManager().EnableCategory( + category, pos, std::initializer_list<lldb::LanguageType>()); } -void -DataVisualization::Categories::Enable (lldb::LanguageType lang_type) -{ - if (LanguageCategory* lang_category = GetFormatManager().GetCategoryForLanguage(lang_type)) - lang_category->Enable(); +void DataVisualization::Categories::Enable(lldb::LanguageType lang_type) { + if (LanguageCategory *lang_category = + GetFormatManager().GetCategoryForLanguage(lang_type)) + lang_category->Enable(); } -void -DataVisualization::Categories::Disable (const ConstString& category) -{ - if (GetFormatManager().GetCategory(category)->IsEnabled() == true) - GetFormatManager().DisableCategory(category); +void DataVisualization::Categories::Disable(const ConstString &category) { + if (GetFormatManager().GetCategory(category)->IsEnabled() == true) + GetFormatManager().DisableCategory(category); } -void -DataVisualization::Categories::Disable (lldb::LanguageType lang_type) -{ - if (LanguageCategory* lang_category = GetFormatManager().GetCategoryForLanguage(lang_type)) - lang_category->Disable(); +void DataVisualization::Categories::Disable(lldb::LanguageType lang_type) { + if (LanguageCategory *lang_category = + GetFormatManager().GetCategoryForLanguage(lang_type)) + lang_category->Disable(); } -void -DataVisualization::Categories::Enable (const lldb::TypeCategoryImplSP& category, - TypeCategoryMap::Position pos) -{ - if (category.get()) - { - if (category->IsEnabled()) - GetFormatManager().DisableCategory(category); - GetFormatManager().EnableCategory(category, pos); - } +void DataVisualization::Categories::Enable( + const lldb::TypeCategoryImplSP &category, TypeCategoryMap::Position pos) { + if (category.get()) { + if (category->IsEnabled()) + GetFormatManager().DisableCategory(category); + GetFormatManager().EnableCategory(category, pos); + } } -void -DataVisualization::Categories::Disable (const lldb::TypeCategoryImplSP& category) -{ - if (category.get() && category->IsEnabled() == true) - GetFormatManager().DisableCategory(category); +void DataVisualization::Categories::Disable( + const lldb::TypeCategoryImplSP &category) { + if (category.get() && category->IsEnabled() == true) + GetFormatManager().DisableCategory(category); } -void -DataVisualization::Categories::EnableStar () -{ - GetFormatManager().EnableAllCategories (); +void DataVisualization::Categories::EnableStar() { + GetFormatManager().EnableAllCategories(); } -void -DataVisualization::Categories::DisableStar () -{ - GetFormatManager().DisableAllCategories(); +void DataVisualization::Categories::DisableStar() { + GetFormatManager().DisableAllCategories(); } -void -DataVisualization::Categories::ForEach (TypeCategoryMap::ForEachCallback callback) -{ - GetFormatManager().ForEachCategory(callback); +void DataVisualization::Categories::ForEach( + TypeCategoryMap::ForEachCallback callback) { + GetFormatManager().ForEachCategory(callback); } -uint32_t -DataVisualization::Categories::GetCount () -{ - return GetFormatManager().GetCategoriesCount(); +uint32_t DataVisualization::Categories::GetCount() { + return GetFormatManager().GetCategoriesCount(); } lldb::TypeCategoryImplSP -DataVisualization::Categories::GetCategoryAtIndex (size_t index) -{ - return GetFormatManager().GetCategoryAtIndex(index); +DataVisualization::Categories::GetCategoryAtIndex(size_t index) { + return GetFormatManager().GetCategoryAtIndex(index); } -bool -DataVisualization::NamedSummaryFormats::GetSummaryFormat (const ConstString &type, lldb::TypeSummaryImplSP &entry) -{ - return GetFormatManager().GetNamedSummaryContainer().Get(type,entry); +bool DataVisualization::NamedSummaryFormats::GetSummaryFormat( + const ConstString &type, lldb::TypeSummaryImplSP &entry) { + return GetFormatManager().GetNamedSummaryContainer().Get(type, entry); } -void -DataVisualization::NamedSummaryFormats::Add (const ConstString &type, const lldb::TypeSummaryImplSP &entry) -{ - GetFormatManager().GetNamedSummaryContainer().Add(FormatManager::GetValidTypeName(type),entry); +void DataVisualization::NamedSummaryFormats::Add( + const ConstString &type, const lldb::TypeSummaryImplSP &entry) { + GetFormatManager().GetNamedSummaryContainer().Add( + FormatManager::GetValidTypeName(type), entry); } -bool -DataVisualization::NamedSummaryFormats::Delete (const ConstString &type) -{ - return GetFormatManager().GetNamedSummaryContainer().Delete(type); +bool DataVisualization::NamedSummaryFormats::Delete(const ConstString &type) { + return GetFormatManager().GetNamedSummaryContainer().Delete(type); } -void -DataVisualization::NamedSummaryFormats::Clear () -{ - GetFormatManager().GetNamedSummaryContainer().Clear(); +void DataVisualization::NamedSummaryFormats::Clear() { + GetFormatManager().GetNamedSummaryContainer().Clear(); } -void -DataVisualization::NamedSummaryFormats::ForEach (std::function<bool(ConstString, const lldb::TypeSummaryImplSP&)> callback) -{ - GetFormatManager().GetNamedSummaryContainer().ForEach(callback); +void DataVisualization::NamedSummaryFormats::ForEach( + std::function<bool(ConstString, const lldb::TypeSummaryImplSP &)> + callback) { + GetFormatManager().GetNamedSummaryContainer().ForEach(callback); } -uint32_t -DataVisualization::NamedSummaryFormats::GetCount () -{ - return GetFormatManager().GetNamedSummaryContainer().GetCount(); +uint32_t DataVisualization::NamedSummaryFormats::GetCount() { + return GetFormatManager().GetNamedSummaryContainer().GetCount(); } diff --git a/lldb/source/DataFormatters/DumpValueObjectOptions.cpp b/lldb/source/DataFormatters/DumpValueObjectOptions.cpp index e1f5320feee..1f5569b6ad6 100644 --- a/lldb/source/DataFormatters/DumpValueObjectOptions.cpp +++ b/lldb/source/DataFormatters/DumpValueObjectOptions.cpp @@ -1,4 +1,5 @@ -//===-- DumpValueObjectOptions.cpp -----------------------------------*- C++ -*-===// +//===-- DumpValueObjectOptions.cpp -----------------------------------*- C++ +//-*-===// // // The LLVM Compiler Infrastructure // @@ -18,234 +19,182 @@ using namespace lldb; using namespace lldb_private; -DumpValueObjectOptions::DumpValueObjectOptions() : - m_summary_sp(), - m_root_valobj_name(), - m_max_ptr_depth(PointerDepth{PointerDepth::Mode::Default,0}), - m_decl_printing_helper(), - m_use_synthetic(true), - m_scope_already_checked(false), - m_flat_output(false), - m_ignore_cap(false), - m_show_types(false), - m_show_location(false), - m_use_objc(false), - m_hide_root_type(false), - m_hide_name(false), - m_hide_value(false), - m_run_validator(false), - m_use_type_display_name(true), - m_allow_oneliner_mode(true), - m_hide_pointer_value(false), - m_reveal_empty_aggregates(true) -{} - - -DumpValueObjectOptions::DumpValueObjectOptions (ValueObject& valobj) : - DumpValueObjectOptions() -{ - m_use_dynamic = valobj.GetDynamicValueType(); - m_use_synthetic = valobj.IsSynthetic(); - m_varformat_language = valobj.GetPreferredDisplayLanguage(); -} - -DumpValueObjectOptions& -DumpValueObjectOptions::SetMaximumPointerDepth(PointerDepth depth) -{ - m_max_ptr_depth = depth; - return *this; -} - -DumpValueObjectOptions& -DumpValueObjectOptions::SetMaximumDepth(uint32_t depth) -{ - m_max_depth = depth; - return *this; -} - -DumpValueObjectOptions& -DumpValueObjectOptions::SetDeclPrintingHelper(DeclPrintingHelper helper) -{ - m_decl_printing_helper = helper; - return *this; -} - -DumpValueObjectOptions& -DumpValueObjectOptions::SetShowTypes(bool show) -{ - m_show_types = show; - return *this; -} - -DumpValueObjectOptions& -DumpValueObjectOptions::SetShowLocation(bool show) -{ - m_show_location = show; - return *this; -} - -DumpValueObjectOptions& -DumpValueObjectOptions::SetUseObjectiveC(bool use) -{ - m_use_objc = use; - return *this; -} - -DumpValueObjectOptions& -DumpValueObjectOptions::SetShowSummary(bool show) -{ - if (show == false) - SetOmitSummaryDepth(UINT32_MAX); - else - SetOmitSummaryDepth(0); - return *this; -} - -DumpValueObjectOptions& -DumpValueObjectOptions::SetUseDynamicType(lldb::DynamicValueType dyn) -{ - m_use_dynamic = dyn; - return *this; -} - -DumpValueObjectOptions& -DumpValueObjectOptions::SetUseSyntheticValue(bool use_synthetic) -{ - m_use_synthetic = use_synthetic; - return *this; -} - -DumpValueObjectOptions& -DumpValueObjectOptions::SetScopeChecked(bool check) -{ - m_scope_already_checked = check; - return *this; -} - -DumpValueObjectOptions& -DumpValueObjectOptions::SetFlatOutput(bool flat) -{ - m_flat_output = flat; - return *this; +DumpValueObjectOptions::DumpValueObjectOptions() + : m_summary_sp(), m_root_valobj_name(), + m_max_ptr_depth(PointerDepth{PointerDepth::Mode::Default, 0}), + m_decl_printing_helper(), m_use_synthetic(true), + m_scope_already_checked(false), m_flat_output(false), m_ignore_cap(false), + m_show_types(false), m_show_location(false), m_use_objc(false), + m_hide_root_type(false), m_hide_name(false), m_hide_value(false), + m_run_validator(false), m_use_type_display_name(true), + m_allow_oneliner_mode(true), m_hide_pointer_value(false), + m_reveal_empty_aggregates(true) {} + +DumpValueObjectOptions::DumpValueObjectOptions(ValueObject &valobj) + : DumpValueObjectOptions() { + m_use_dynamic = valobj.GetDynamicValueType(); + m_use_synthetic = valobj.IsSynthetic(); + m_varformat_language = valobj.GetPreferredDisplayLanguage(); +} + +DumpValueObjectOptions & +DumpValueObjectOptions::SetMaximumPointerDepth(PointerDepth depth) { + m_max_ptr_depth = depth; + return *this; +} + +DumpValueObjectOptions & +DumpValueObjectOptions::SetMaximumDepth(uint32_t depth) { + m_max_depth = depth; + return *this; +} + +DumpValueObjectOptions & +DumpValueObjectOptions::SetDeclPrintingHelper(DeclPrintingHelper helper) { + m_decl_printing_helper = helper; + return *this; +} + +DumpValueObjectOptions &DumpValueObjectOptions::SetShowTypes(bool show) { + m_show_types = show; + return *this; } -DumpValueObjectOptions& -DumpValueObjectOptions::SetOmitSummaryDepth(uint32_t depth) -{ - m_omit_summary_depth = depth; - return *this; +DumpValueObjectOptions &DumpValueObjectOptions::SetShowLocation(bool show) { + m_show_location = show; + return *this; } -DumpValueObjectOptions& -DumpValueObjectOptions::SetIgnoreCap(bool ignore) -{ - m_ignore_cap = ignore; - return *this; +DumpValueObjectOptions &DumpValueObjectOptions::SetUseObjectiveC(bool use) { + m_use_objc = use; + return *this; } -DumpValueObjectOptions& -DumpValueObjectOptions::SetRawDisplay() -{ - SetUseSyntheticValue(false); +DumpValueObjectOptions &DumpValueObjectOptions::SetShowSummary(bool show) { + if (show == false) SetOmitSummaryDepth(UINT32_MAX); - SetIgnoreCap(true); - SetHideName(false); - SetHideValue(false); - SetUseTypeDisplayName(false); - SetAllowOnelinerMode(false); - return *this; + else + SetOmitSummaryDepth(0); + return *this; +} + +DumpValueObjectOptions & +DumpValueObjectOptions::SetUseDynamicType(lldb::DynamicValueType dyn) { + m_use_dynamic = dyn; + return *this; +} + +DumpValueObjectOptions & +DumpValueObjectOptions::SetUseSyntheticValue(bool use_synthetic) { + m_use_synthetic = use_synthetic; + return *this; +} + +DumpValueObjectOptions &DumpValueObjectOptions::SetScopeChecked(bool check) { + m_scope_already_checked = check; + return *this; +} + +DumpValueObjectOptions &DumpValueObjectOptions::SetFlatOutput(bool flat) { + m_flat_output = flat; + return *this; +} + +DumpValueObjectOptions & +DumpValueObjectOptions::SetOmitSummaryDepth(uint32_t depth) { + m_omit_summary_depth = depth; + return *this; +} + +DumpValueObjectOptions &DumpValueObjectOptions::SetIgnoreCap(bool ignore) { + m_ignore_cap = ignore; + return *this; +} + +DumpValueObjectOptions &DumpValueObjectOptions::SetRawDisplay() { + SetUseSyntheticValue(false); + SetOmitSummaryDepth(UINT32_MAX); + SetIgnoreCap(true); + SetHideName(false); + SetHideValue(false); + SetUseTypeDisplayName(false); + SetAllowOnelinerMode(false); + return *this; } -DumpValueObjectOptions& -DumpValueObjectOptions::SetFormat (lldb::Format format) -{ - m_format = format; - return *this; +DumpValueObjectOptions &DumpValueObjectOptions::SetFormat(lldb::Format format) { + m_format = format; + return *this; } -DumpValueObjectOptions& -DumpValueObjectOptions::SetSummary (lldb::TypeSummaryImplSP summary) -{ - m_summary_sp = summary; - return *this; +DumpValueObjectOptions & +DumpValueObjectOptions::SetSummary(lldb::TypeSummaryImplSP summary) { + m_summary_sp = summary; + return *this; } -DumpValueObjectOptions& -DumpValueObjectOptions::SetRootValueObjectName (const char* name) -{ - if (name) - m_root_valobj_name.assign(name); - else - m_root_valobj_name.clear(); - return *this; +DumpValueObjectOptions & +DumpValueObjectOptions::SetRootValueObjectName(const char *name) { + if (name) + m_root_valobj_name.assign(name); + else + m_root_valobj_name.clear(); + return *this; } -DumpValueObjectOptions& -DumpValueObjectOptions::SetHideRootType (bool hide_root_type) -{ - m_hide_root_type = hide_root_type; - return *this; +DumpValueObjectOptions & +DumpValueObjectOptions::SetHideRootType(bool hide_root_type) { + m_hide_root_type = hide_root_type; + return *this; } -DumpValueObjectOptions& -DumpValueObjectOptions::SetHideName (bool hide_name) -{ - m_hide_name = hide_name; - return *this; +DumpValueObjectOptions &DumpValueObjectOptions::SetHideName(bool hide_name) { + m_hide_name = hide_name; + return *this; } -DumpValueObjectOptions& -DumpValueObjectOptions::SetHideValue (bool hide_value) -{ - m_hide_value = hide_value; - return *this; +DumpValueObjectOptions &DumpValueObjectOptions::SetHideValue(bool hide_value) { + m_hide_value = hide_value; + return *this; } -DumpValueObjectOptions& -DumpValueObjectOptions::SetHidePointerValue (bool hide) -{ - m_hide_pointer_value = hide; - return *this; +DumpValueObjectOptions &DumpValueObjectOptions::SetHidePointerValue(bool hide) { + m_hide_pointer_value = hide; + return *this; } -DumpValueObjectOptions& -DumpValueObjectOptions::SetVariableFormatDisplayLanguage (lldb::LanguageType lang) -{ - m_varformat_language = lang; - return *this; +DumpValueObjectOptions & +DumpValueObjectOptions::SetVariableFormatDisplayLanguage( + lldb::LanguageType lang) { + m_varformat_language = lang; + return *this; } -DumpValueObjectOptions& -DumpValueObjectOptions::SetRunValidator (bool run) -{ - m_run_validator = run; - return *this; +DumpValueObjectOptions &DumpValueObjectOptions::SetRunValidator(bool run) { + m_run_validator = run; + return *this; } -DumpValueObjectOptions& -DumpValueObjectOptions::SetUseTypeDisplayName (bool dis) -{ - m_use_type_display_name = dis; - return *this; +DumpValueObjectOptions & +DumpValueObjectOptions::SetUseTypeDisplayName(bool dis) { + m_use_type_display_name = dis; + return *this; } -DumpValueObjectOptions& -DumpValueObjectOptions::SetAllowOnelinerMode (bool oneliner) -{ - m_allow_oneliner_mode = oneliner; - return *this; +DumpValueObjectOptions & +DumpValueObjectOptions::SetAllowOnelinerMode(bool oneliner) { + m_allow_oneliner_mode = oneliner; + return *this; } -DumpValueObjectOptions& -DumpValueObjectOptions::SetRevealEmptyAggregates (bool reveal) -{ - m_reveal_empty_aggregates = reveal; - return *this; +DumpValueObjectOptions & +DumpValueObjectOptions::SetRevealEmptyAggregates(bool reveal) { + m_reveal_empty_aggregates = reveal; + return *this; } -DumpValueObjectOptions& -DumpValueObjectOptions::SetElementCount (uint32_t element_count) -{ - m_element_count = element_count; - return *this; +DumpValueObjectOptions & +DumpValueObjectOptions::SetElementCount(uint32_t element_count) { + m_element_count = element_count; + return *this; } diff --git a/lldb/source/DataFormatters/FormatCache.cpp b/lldb/source/DataFormatters/FormatCache.cpp index fc5becbf200..0f1b29f1b47 100644 --- a/lldb/source/DataFormatters/FormatCache.cpp +++ b/lldb/source/DataFormatters/FormatCache.cpp @@ -1,4 +1,5 @@ -//===-- FormatCache.cpp ------------------------------------------*- C++ -*-===// +//===-- FormatCache.cpp ------------------------------------------*- C++ +//-*-===// // // The LLVM Compiler Infrastructure // @@ -19,279 +20,205 @@ using namespace lldb; using namespace lldb_private; -FormatCache::Entry::Entry () : -m_format_cached(false), -m_summary_cached(false), -m_synthetic_cached(false), -m_validator_cached(false), -m_format_sp(), -m_summary_sp(), -m_synthetic_sp(), -m_validator_sp() -{} - -FormatCache::Entry::Entry (lldb::TypeFormatImplSP format_sp) : -m_summary_cached(false), -m_synthetic_cached(false), -m_validator_cached(false), -m_summary_sp(), -m_synthetic_sp(), -m_validator_sp() -{ - SetFormat (format_sp); -} +FormatCache::Entry::Entry() + : m_format_cached(false), m_summary_cached(false), + m_synthetic_cached(false), m_validator_cached(false), m_format_sp(), + m_summary_sp(), m_synthetic_sp(), m_validator_sp() {} -FormatCache::Entry::Entry (lldb::TypeSummaryImplSP summary_sp) : -m_format_cached(false), -m_synthetic_cached(false), -m_validator_cached(false), -m_format_sp(), -m_synthetic_sp(), -m_validator_sp() -{ - SetSummary (summary_sp); +FormatCache::Entry::Entry(lldb::TypeFormatImplSP format_sp) + : m_summary_cached(false), m_synthetic_cached(false), + m_validator_cached(false), m_summary_sp(), m_synthetic_sp(), + m_validator_sp() { + SetFormat(format_sp); } -FormatCache::Entry::Entry (lldb::SyntheticChildrenSP synthetic_sp) : -m_format_cached(false), -m_summary_cached(false), -m_validator_cached(false), -m_format_sp(), -m_summary_sp(), -m_validator_sp() -{ - SetSynthetic (synthetic_sp); +FormatCache::Entry::Entry(lldb::TypeSummaryImplSP summary_sp) + : m_format_cached(false), m_synthetic_cached(false), + m_validator_cached(false), m_format_sp(), m_synthetic_sp(), + m_validator_sp() { + SetSummary(summary_sp); } -FormatCache::Entry::Entry (lldb::TypeValidatorImplSP validator_sp) : -m_format_cached(false), -m_summary_cached(false), -m_synthetic_cached(false), -m_format_sp(), -m_summary_sp(), -m_synthetic_sp() -{ - SetValidator (validator_sp); +FormatCache::Entry::Entry(lldb::SyntheticChildrenSP synthetic_sp) + : m_format_cached(false), m_summary_cached(false), + m_validator_cached(false), m_format_sp(), m_summary_sp(), + m_validator_sp() { + SetSynthetic(synthetic_sp); } -FormatCache::Entry::Entry (lldb::TypeFormatImplSP format_sp, lldb::TypeSummaryImplSP summary_sp, lldb::SyntheticChildrenSP synthetic_sp, lldb::TypeValidatorImplSP validator_sp) -{ - SetFormat (format_sp); - SetSummary (summary_sp); - SetSynthetic (synthetic_sp); - SetValidator (validator_sp); +FormatCache::Entry::Entry(lldb::TypeValidatorImplSP validator_sp) + : m_format_cached(false), m_summary_cached(false), + m_synthetic_cached(false), m_format_sp(), m_summary_sp(), + m_synthetic_sp() { + SetValidator(validator_sp); } -bool -FormatCache::Entry::IsFormatCached () -{ - return m_format_cached; +FormatCache::Entry::Entry(lldb::TypeFormatImplSP format_sp, + lldb::TypeSummaryImplSP summary_sp, + lldb::SyntheticChildrenSP synthetic_sp, + lldb::TypeValidatorImplSP validator_sp) { + SetFormat(format_sp); + SetSummary(summary_sp); + SetSynthetic(synthetic_sp); + SetValidator(validator_sp); } -bool -FormatCache::Entry::IsSummaryCached () -{ - return m_summary_cached; -} +bool FormatCache::Entry::IsFormatCached() { return m_format_cached; } -bool -FormatCache::Entry::IsSyntheticCached () -{ - return m_synthetic_cached; -} +bool FormatCache::Entry::IsSummaryCached() { return m_summary_cached; } -bool -FormatCache::Entry::IsValidatorCached () -{ - return m_validator_cached; -} +bool FormatCache::Entry::IsSyntheticCached() { return m_synthetic_cached; } -lldb::TypeFormatImplSP -FormatCache::Entry::GetFormat () -{ - return m_format_sp; -} +bool FormatCache::Entry::IsValidatorCached() { return m_validator_cached; } -lldb::TypeSummaryImplSP -FormatCache::Entry::GetSummary () -{ - return m_summary_sp; +lldb::TypeFormatImplSP FormatCache::Entry::GetFormat() { return m_format_sp; } + +lldb::TypeSummaryImplSP FormatCache::Entry::GetSummary() { + return m_summary_sp; } -lldb::SyntheticChildrenSP -FormatCache::Entry::GetSynthetic () -{ - return m_synthetic_sp; +lldb::SyntheticChildrenSP FormatCache::Entry::GetSynthetic() { + return m_synthetic_sp; } -lldb::TypeValidatorImplSP -FormatCache::Entry::GetValidator () -{ - return m_validator_sp; +lldb::TypeValidatorImplSP FormatCache::Entry::GetValidator() { + return m_validator_sp; } -void -FormatCache::Entry::SetFormat (lldb::TypeFormatImplSP format_sp) -{ - m_format_cached = true; - m_format_sp = format_sp; +void FormatCache::Entry::SetFormat(lldb::TypeFormatImplSP format_sp) { + m_format_cached = true; + m_format_sp = format_sp; } -void -FormatCache::Entry::SetSummary (lldb::TypeSummaryImplSP summary_sp) -{ - m_summary_cached = true; - m_summary_sp = summary_sp; +void FormatCache::Entry::SetSummary(lldb::TypeSummaryImplSP summary_sp) { + m_summary_cached = true; + m_summary_sp = summary_sp; } -void -FormatCache::Entry::SetSynthetic (lldb::SyntheticChildrenSP synthetic_sp) -{ - m_synthetic_cached = true; - m_synthetic_sp = synthetic_sp; +void FormatCache::Entry::SetSynthetic(lldb::SyntheticChildrenSP synthetic_sp) { + m_synthetic_cached = true; + m_synthetic_sp = synthetic_sp; } -void -FormatCache::Entry::SetValidator (lldb::TypeValidatorImplSP validator_sp) -{ - m_validator_cached = true; - m_validator_sp = validator_sp; +void FormatCache::Entry::SetValidator(lldb::TypeValidatorImplSP validator_sp) { + m_validator_cached = true; + m_validator_sp = validator_sp; } FormatCache::FormatCache() - : m_map(), - m_mutex() + : m_map(), m_mutex() #ifdef LLDB_CONFIGURATION_DEBUG , - m_cache_hits(0), - m_cache_misses(0) + m_cache_hits(0), m_cache_misses(0) #endif { } -FormatCache::Entry& -FormatCache::GetEntry (const ConstString& type) -{ - auto i = m_map.find(type), - e = m_map.end(); - if (i != e) - return i->second; - m_map[type] = FormatCache::Entry(); - return m_map[type]; +FormatCache::Entry &FormatCache::GetEntry(const ConstString &type) { + auto i = m_map.find(type), e = m_map.end(); + if (i != e) + return i->second; + m_map[type] = FormatCache::Entry(); + return m_map[type]; } -bool -FormatCache::GetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_sp) -{ - std::lock_guard<std::recursive_mutex> guard(m_mutex); - auto entry = GetEntry(type); - if (entry.IsFormatCached()) - { +bool FormatCache::GetFormat(const ConstString &type, + lldb::TypeFormatImplSP &format_sp) { + std::lock_guard<std::recursive_mutex> guard(m_mutex); + auto entry = GetEntry(type); + if (entry.IsFormatCached()) { #ifdef LLDB_CONFIGURATION_DEBUG - m_cache_hits++; + m_cache_hits++; #endif - format_sp = entry.GetFormat(); - return true; - } + format_sp = entry.GetFormat(); + return true; + } #ifdef LLDB_CONFIGURATION_DEBUG - m_cache_misses++; + m_cache_misses++; #endif - format_sp.reset(); - return false; + format_sp.reset(); + return false; } -bool -FormatCache::GetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp) -{ - std::lock_guard<std::recursive_mutex> guard(m_mutex); - auto entry = GetEntry(type); - if (entry.IsSummaryCached()) - { +bool FormatCache::GetSummary(const ConstString &type, + lldb::TypeSummaryImplSP &summary_sp) { + std::lock_guard<std::recursive_mutex> guard(m_mutex); + auto entry = GetEntry(type); + if (entry.IsSummaryCached()) { #ifdef LLDB_CONFIGURATION_DEBUG - m_cache_hits++; + m_cache_hits++; #endif - summary_sp = entry.GetSummary(); - return true; - } + summary_sp = entry.GetSummary(); + return true; + } #ifdef LLDB_CONFIGURATION_DEBUG - m_cache_misses++; + m_cache_misses++; #endif - summary_sp.reset(); - return false; + summary_sp.reset(); + return false; } -bool -FormatCache::GetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp) -{ - std::lock_guard<std::recursive_mutex> guard(m_mutex); - auto entry = GetEntry(type); - if (entry.IsSyntheticCached()) - { +bool FormatCache::GetSynthetic(const ConstString &type, + lldb::SyntheticChildrenSP &synthetic_sp) { + std::lock_guard<std::recursive_mutex> guard(m_mutex); + auto entry = GetEntry(type); + if (entry.IsSyntheticCached()) { #ifdef LLDB_CONFIGURATION_DEBUG - m_cache_hits++; + m_cache_hits++; #endif - synthetic_sp = entry.GetSynthetic(); - return true; - } + synthetic_sp = entry.GetSynthetic(); + return true; + } #ifdef LLDB_CONFIGURATION_DEBUG - m_cache_misses++; + m_cache_misses++; #endif - synthetic_sp.reset(); - return false; + synthetic_sp.reset(); + return false; } -bool -FormatCache::GetValidator (const ConstString& type,lldb::TypeValidatorImplSP& validator_sp) -{ - std::lock_guard<std::recursive_mutex> guard(m_mutex); - auto entry = GetEntry(type); - if (entry.IsValidatorCached()) - { +bool FormatCache::GetValidator(const ConstString &type, + lldb::TypeValidatorImplSP &validator_sp) { + std::lock_guard<std::recursive_mutex> guard(m_mutex); + auto entry = GetEntry(type); + if (entry.IsValidatorCached()) { #ifdef LLDB_CONFIGURATION_DEBUG - m_cache_hits++; + m_cache_hits++; #endif - validator_sp = entry.GetValidator(); - return true; - } + validator_sp = entry.GetValidator(); + return true; + } #ifdef LLDB_CONFIGURATION_DEBUG - m_cache_misses++; + m_cache_misses++; #endif - validator_sp.reset(); - return false; + validator_sp.reset(); + return false; } -void -FormatCache::SetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_sp) -{ - std::lock_guard<std::recursive_mutex> guard(m_mutex); - GetEntry(type).SetFormat(format_sp); +void FormatCache::SetFormat(const ConstString &type, + lldb::TypeFormatImplSP &format_sp) { + std::lock_guard<std::recursive_mutex> guard(m_mutex); + GetEntry(type).SetFormat(format_sp); } -void -FormatCache::SetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp) -{ - std::lock_guard<std::recursive_mutex> guard(m_mutex); - GetEntry(type).SetSummary(summary_sp); +void FormatCache::SetSummary(const ConstString &type, + lldb::TypeSummaryImplSP &summary_sp) { + std::lock_guard<std::recursive_mutex> guard(m_mutex); + GetEntry(type).SetSummary(summary_sp); } -void -FormatCache::SetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp) -{ - std::lock_guard<std::recursive_mutex> guard(m_mutex); - GetEntry(type).SetSynthetic(synthetic_sp); +void FormatCache::SetSynthetic(const ConstString &type, + lldb::SyntheticChildrenSP &synthetic_sp) { + std::lock_guard<std::recursive_mutex> guard(m_mutex); + GetEntry(type).SetSynthetic(synthetic_sp); } -void -FormatCache::SetValidator (const ConstString& type,lldb::TypeValidatorImplSP& validator_sp) -{ - std::lock_guard<std::recursive_mutex> guard(m_mutex); - GetEntry(type).SetValidator(validator_sp); +void FormatCache::SetValidator(const ConstString &type, + lldb::TypeValidatorImplSP &validator_sp) { + std::lock_guard<std::recursive_mutex> guard(m_mutex); + GetEntry(type).SetValidator(validator_sp); } -void -FormatCache::Clear () -{ - std::lock_guard<std::recursive_mutex> guard(m_mutex); - m_map.clear(); +void FormatCache::Clear() { + std::lock_guard<std::recursive_mutex> guard(m_mutex); + m_map.clear(); } - diff --git a/lldb/source/DataFormatters/FormatClasses.cpp b/lldb/source/DataFormatters/FormatClasses.cpp index 2e4acd175f1..f657361d3d5 100644 --- a/lldb/source/DataFormatters/FormatClasses.cpp +++ b/lldb/source/DataFormatters/FormatClasses.cpp @@ -1,4 +1,5 @@ -//===-- FormatClasses.cpp ----------------------------------------*- C++ -*-===// +//===-- FormatClasses.cpp ----------------------------------------*- C++ +//-*-===// // // The LLVM Compiler Infrastructure // @@ -22,48 +23,32 @@ using namespace lldb; using namespace lldb_private; -FormattersMatchData::FormattersMatchData (ValueObject& valobj, lldb::DynamicValueType use_dynamic) : - m_valobj(valobj), - m_dynamic_value_type(use_dynamic), - m_formatters_match_vector({},false), - m_type_for_cache(), - m_candidate_languages() -{ - m_type_for_cache = FormatManager::GetTypeForCache(valobj, use_dynamic); - m_candidate_languages = FormatManager::GetCandidateLanguages(valobj); +FormattersMatchData::FormattersMatchData(ValueObject &valobj, + lldb::DynamicValueType use_dynamic) + : m_valobj(valobj), m_dynamic_value_type(use_dynamic), + m_formatters_match_vector({}, false), m_type_for_cache(), + m_candidate_languages() { + m_type_for_cache = FormatManager::GetTypeForCache(valobj, use_dynamic); + m_candidate_languages = FormatManager::GetCandidateLanguages(valobj); } -FormattersMatchVector -FormattersMatchData::GetMatchesVector () -{ - if (!m_formatters_match_vector.second) - { - m_formatters_match_vector.second = true; - m_formatters_match_vector.first = FormatManager::GetPossibleMatches(m_valobj, m_dynamic_value_type); - } - return m_formatters_match_vector.first; +FormattersMatchVector FormattersMatchData::GetMatchesVector() { + if (!m_formatters_match_vector.second) { + m_formatters_match_vector.second = true; + m_formatters_match_vector.first = + FormatManager::GetPossibleMatches(m_valobj, m_dynamic_value_type); + } + return m_formatters_match_vector.first; } -ConstString -FormattersMatchData::GetTypeForCache () -{ - return m_type_for_cache; -} +ConstString FormattersMatchData::GetTypeForCache() { return m_type_for_cache; } -CandidateLanguagesVector -FormattersMatchData::GetCandidateLanguages () -{ - return m_candidate_languages; +CandidateLanguagesVector FormattersMatchData::GetCandidateLanguages() { + return m_candidate_languages; } -ValueObject& -FormattersMatchData::GetValueObject () -{ - return m_valobj; -} +ValueObject &FormattersMatchData::GetValueObject() { return m_valobj; } -lldb::DynamicValueType -FormattersMatchData::GetDynamicValueType () -{ - return m_dynamic_value_type; +lldb::DynamicValueType FormattersMatchData::GetDynamicValueType() { + return m_dynamic_value_type; } diff --git a/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp index f51243f841e..aa6e7a27b5c 100644 --- a/lldb/source/DataFormatters/FormatManager.cpp +++ b/lldb/source/DataFormatters/FormatManager.cpp @@ -1,4 +1,5 @@ -//===-- FormatManager.cpp -------------------------------------------*- C++ -*-===// +//===-- FormatManager.cpp -------------------------------------------*- C++ +//-*-===// // // The LLVM Compiler Infrastructure // @@ -27,1176 +28,1059 @@ using namespace lldb; using namespace lldb_private; using namespace lldb_private::formatters; -struct FormatInfo -{ - Format format; - const char format_char; // One or more format characters that can be used for this format. - const char *format_name; // Long format name that can be used to specify the current format +struct FormatInfo { + Format format; + const char format_char; // One or more format characters that can be used for + // this format. + const char *format_name; // Long format name that can be used to specify the + // current format }; -static FormatInfo -g_format_infos[] = -{ - { eFormatDefault , '\0' , "default" }, - { eFormatBoolean , 'B' , "boolean" }, - { eFormatBinary , 'b' , "binary" }, - { eFormatBytes , 'y' , "bytes" }, - { eFormatBytesWithASCII , 'Y' , "bytes with ASCII" }, - { eFormatChar , 'c' , "character" }, - { eFormatCharPrintable , 'C' , "printable character" }, - { eFormatComplexFloat , 'F' , "complex float" }, - { eFormatCString , 's' , "c-string" }, - { eFormatDecimal , 'd' , "decimal" }, - { eFormatEnum , 'E' , "enumeration" }, - { eFormatHex , 'x' , "hex" }, - { eFormatHexUppercase , 'X' , "uppercase hex" }, - { eFormatFloat , 'f' , "float" }, - { eFormatOctal , 'o' , "octal" }, - { eFormatOSType , 'O' , "OSType" }, - { eFormatUnicode16 , 'U' , "unicode16" }, - { eFormatUnicode32 , '\0' , "unicode32" }, - { eFormatUnsigned , 'u' , "unsigned decimal" }, - { eFormatPointer , 'p' , "pointer" }, - { eFormatVectorOfChar , '\0' , "char[]" }, - { eFormatVectorOfSInt8 , '\0' , "int8_t[]" }, - { eFormatVectorOfUInt8 , '\0' , "uint8_t[]" }, - { eFormatVectorOfSInt16 , '\0' , "int16_t[]" }, - { eFormatVectorOfUInt16 , '\0' , "uint16_t[]" }, - { eFormatVectorOfSInt32 , '\0' , "int32_t[]" }, - { eFormatVectorOfUInt32 , '\0' , "uint32_t[]" }, - { eFormatVectorOfSInt64 , '\0' , "int64_t[]" }, - { eFormatVectorOfUInt64 , '\0' , "uint64_t[]" }, - { eFormatVectorOfFloat16, '\0' , "float16[]" }, - { eFormatVectorOfFloat32, '\0' , "float32[]" }, - { eFormatVectorOfFloat64, '\0' , "float64[]" }, - { eFormatVectorOfUInt128, '\0' , "uint128_t[]" }, - { eFormatComplexInteger , 'I' , "complex integer" }, - { eFormatCharArray , 'a' , "character array" }, - { eFormatAddressInfo , 'A' , "address" }, - { eFormatHexFloat , '\0' , "hex float" }, - { eFormatInstruction , 'i' , "instruction" }, - { eFormatVoid , 'v' , "void" } -}; +static FormatInfo g_format_infos[] = { + {eFormatDefault, '\0', "default"}, + {eFormatBoolean, 'B', "boolean"}, + {eFormatBinary, 'b', "binary"}, + {eFormatBytes, 'y', "bytes"}, + {eFormatBytesWithASCII, 'Y', "bytes with ASCII"}, + {eFormatChar, 'c', "character"}, + {eFormatCharPrintable, 'C', "printable character"}, + {eFormatComplexFloat, 'F', "complex float"}, + {eFormatCString, 's', "c-string"}, + {eFormatDecimal, 'd', "decimal"}, + {eFormatEnum, 'E', "enumeration"}, + {eFormatHex, 'x', "hex"}, + {eFormatHexUppercase, 'X', "uppercase hex"}, + {eFormatFloat, 'f', "float"}, + {eFormatOctal, 'o', "octal"}, + {eFormatOSType, 'O', "OSType"}, + {eFormatUnicode16, 'U', "unicode16"}, + {eFormatUnicode32, '\0', "unicode32"}, + {eFormatUnsigned, 'u', "unsigned decimal"}, + {eFormatPointer, 'p', "pointer"}, + {eFormatVectorOfChar, '\0', "char[]"}, + {eFormatVectorOfSInt8, '\0', "int8_t[]"}, + {eFormatVectorOfUInt8, '\0', "uint8_t[]"}, + {eFormatVectorOfSInt16, '\0', "int16_t[]"}, + {eFormatVectorOfUInt16, '\0', "uint16_t[]"}, + {eFormatVectorOfSInt32, '\0', "int32_t[]"}, + {eFormatVectorOfUInt32, '\0', "uint32_t[]"}, + {eFormatVectorOfSInt64, '\0', "int64_t[]"}, + {eFormatVectorOfUInt64, '\0', "uint64_t[]"}, + {eFormatVectorOfFloat16, '\0', "float16[]"}, + {eFormatVectorOfFloat32, '\0', "float32[]"}, + {eFormatVectorOfFloat64, '\0', "float64[]"}, + {eFormatVectorOfUInt128, '\0', "uint128_t[]"}, + {eFormatComplexInteger, 'I', "complex integer"}, + {eFormatCharArray, 'a', "character array"}, + {eFormatAddressInfo, 'A', "address"}, + {eFormatHexFloat, '\0', "hex float"}, + {eFormatInstruction, 'i', "instruction"}, + {eFormatVoid, 'v', "void"}}; static uint32_t g_num_format_infos = llvm::array_lengthof(g_format_infos); -static bool -GetFormatFromFormatChar (char format_char, Format &format) -{ - for (uint32_t i=0; i<g_num_format_infos; ++i) - { - if (g_format_infos[i].format_char == format_char) - { - format = g_format_infos[i].format; - return true; - } +static bool GetFormatFromFormatChar(char format_char, Format &format) { + for (uint32_t i = 0; i < g_num_format_infos; ++i) { + if (g_format_infos[i].format_char == format_char) { + format = g_format_infos[i].format; + return true; } - format = eFormatInvalid; - return false; + } + format = eFormatInvalid; + return false; } -static bool -GetFormatFromFormatName (const char *format_name, bool partial_match_ok, Format &format) -{ - uint32_t i; - for (i=0; i<g_num_format_infos; ++i) - { - if (strcasecmp (g_format_infos[i].format_name, format_name) == 0) - { - format = g_format_infos[i].format; - return true; - } +static bool GetFormatFromFormatName(const char *format_name, + bool partial_match_ok, Format &format) { + uint32_t i; + for (i = 0; i < g_num_format_infos; ++i) { + if (strcasecmp(g_format_infos[i].format_name, format_name) == 0) { + format = g_format_infos[i].format; + return true; } - - if (partial_match_ok) - { - for (i=0; i<g_num_format_infos; ++i) - { - if (strcasestr (g_format_infos[i].format_name, format_name) == g_format_infos[i].format_name) - { - format = g_format_infos[i].format; - return true; - } - } + } + + if (partial_match_ok) { + for (i = 0; i < g_num_format_infos; ++i) { + if (strcasestr(g_format_infos[i].format_name, format_name) == + g_format_infos[i].format_name) { + format = g_format_infos[i].format; + return true; + } } - format = eFormatInvalid; - return false; + } + format = eFormatInvalid; + return false; } -void -FormatManager::Changed () -{ - ++m_last_revision; - m_format_cache.Clear (); - std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex); - for (auto& iter : m_language_categories_map) - { - if (iter.second) - iter.second->GetFormatCache().Clear(); - } +void FormatManager::Changed() { + ++m_last_revision; + m_format_cache.Clear(); + std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex); + for (auto &iter : m_language_categories_map) { + if (iter.second) + iter.second->GetFormatCache().Clear(); + } } -bool -FormatManager::GetFormatFromCString (const char *format_cstr, - bool partial_match_ok, - lldb::Format &format) -{ - bool success = false; - if (format_cstr && format_cstr[0]) - { - if (format_cstr[1] == '\0') - { - success = GetFormatFromFormatChar (format_cstr[0], format); - if (success) - return true; - } - - success = GetFormatFromFormatName (format_cstr, partial_match_ok, format); +bool FormatManager::GetFormatFromCString(const char *format_cstr, + bool partial_match_ok, + lldb::Format &format) { + bool success = false; + if (format_cstr && format_cstr[0]) { + if (format_cstr[1] == '\0') { + success = GetFormatFromFormatChar(format_cstr[0], format); + if (success) + return true; } - if (!success) - format = eFormatInvalid; - return success; + + success = GetFormatFromFormatName(format_cstr, partial_match_ok, format); + } + if (!success) + format = eFormatInvalid; + return success; } -char -FormatManager::GetFormatAsFormatChar (lldb::Format format) -{ - for (uint32_t i=0; i<g_num_format_infos; ++i) - { - if (g_format_infos[i].format == format) - return g_format_infos[i].format_char; - } - return '\0'; +char FormatManager::GetFormatAsFormatChar(lldb::Format format) { + for (uint32_t i = 0; i < g_num_format_infos; ++i) { + if (g_format_infos[i].format == format) + return g_format_infos[i].format_char; + } + return '\0'; } -const char * -FormatManager::GetFormatAsCString (Format format) -{ - if (format >= eFormatDefault && format < kNumFormats) - return g_format_infos[format].format_name; - return NULL; +const char *FormatManager::GetFormatAsCString(Format format) { + if (format >= eFormatDefault && format < kNumFormats) + return g_format_infos[format].format_name; + return NULL; } -void -FormatManager::EnableAllCategories () -{ - m_categories_map.EnableAllCategories (); - std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex); - for (auto& iter : m_language_categories_map) - { - if (iter.second) - iter.second->Enable(); - } +void FormatManager::EnableAllCategories() { + m_categories_map.EnableAllCategories(); + std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex); + for (auto &iter : m_language_categories_map) { + if (iter.second) + iter.second->Enable(); + } } -void -FormatManager::DisableAllCategories () -{ - m_categories_map.DisableAllCategories (); - std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex); - for (auto& iter : m_language_categories_map) - { - if (iter.second) - iter.second->Disable(); - } +void FormatManager::DisableAllCategories() { + m_categories_map.DisableAllCategories(); + std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex); + for (auto &iter : m_language_categories_map) { + if (iter.second) + iter.second->Disable(); + } } -void -FormatManager::GetPossibleMatches (ValueObject& valobj, - CompilerType compiler_type, - uint32_t reason, - lldb::DynamicValueType use_dynamic, - FormattersMatchVector& entries, - bool did_strip_ptr, - bool did_strip_ref, - bool did_strip_typedef, - bool root_level) -{ - compiler_type = compiler_type.GetTypeForFormatters(); - ConstString type_name(compiler_type.GetConstTypeName()); - if (valobj.GetBitfieldBitSize() > 0) - { - StreamString sstring; - sstring.Printf("%s:%d",type_name.AsCString(),valobj.GetBitfieldBitSize()); - ConstString bitfieldname = ConstString(sstring.GetData()); - entries.push_back({bitfieldname,0,did_strip_ptr,did_strip_ref,did_strip_typedef}); - reason |= lldb_private::eFormatterChoiceCriterionStrippedBitField; - } +void FormatManager::GetPossibleMatches( + ValueObject &valobj, CompilerType compiler_type, uint32_t reason, + lldb::DynamicValueType use_dynamic, FormattersMatchVector &entries, + bool did_strip_ptr, bool did_strip_ref, bool did_strip_typedef, + bool root_level) { + compiler_type = compiler_type.GetTypeForFormatters(); + ConstString type_name(compiler_type.GetConstTypeName()); + if (valobj.GetBitfieldBitSize() > 0) { + StreamString sstring; + sstring.Printf("%s:%d", type_name.AsCString(), valobj.GetBitfieldBitSize()); + ConstString bitfieldname = ConstString(sstring.GetData()); + entries.push_back( + {bitfieldname, 0, did_strip_ptr, did_strip_ref, did_strip_typedef}); + reason |= lldb_private::eFormatterChoiceCriterionStrippedBitField; + } - if (!compiler_type.IsMeaninglessWithoutDynamicResolution()) - { - entries.push_back({type_name,reason,did_strip_ptr,did_strip_ref,did_strip_typedef}); + if (!compiler_type.IsMeaninglessWithoutDynamicResolution()) { + entries.push_back( + {type_name, reason, did_strip_ptr, did_strip_ref, did_strip_typedef}); - ConstString display_type_name(compiler_type.GetDisplayTypeName()); - if (display_type_name != type_name) - entries.push_back({display_type_name,reason,did_strip_ptr,did_strip_ref,did_strip_typedef}); - } + ConstString display_type_name(compiler_type.GetDisplayTypeName()); + if (display_type_name != type_name) + entries.push_back({display_type_name, reason, did_strip_ptr, + did_strip_ref, did_strip_typedef}); + } - for (bool is_rvalue_ref = true, j = true; j && compiler_type.IsReferenceType(nullptr, &is_rvalue_ref); j = false) - { - CompilerType non_ref_type = compiler_type.GetNonReferenceType(); - GetPossibleMatches(valobj, - non_ref_type, - reason | lldb_private::eFormatterChoiceCriterionStrippedPointerReference, - use_dynamic, - entries, - did_strip_ptr, - true, - did_strip_typedef); - if (non_ref_type.IsTypedefType()) - { - CompilerType deffed_referenced_type = non_ref_type.GetTypedefedType(); - deffed_referenced_type = is_rvalue_ref ? deffed_referenced_type.GetRValueReferenceType() : deffed_referenced_type.GetLValueReferenceType(); - GetPossibleMatches(valobj, - deffed_referenced_type, - reason | lldb_private::eFormatterChoiceCriterionNavigatedTypedefs, - use_dynamic, - entries, - did_strip_ptr, - did_strip_ref, - true); // this is not exactly the usual meaning of stripping typedefs - } - } - - if (compiler_type.IsPointerType()) - { - CompilerType non_ptr_type = compiler_type.GetPointeeType(); - GetPossibleMatches(valobj, - non_ptr_type, - reason | lldb_private::eFormatterChoiceCriterionStrippedPointerReference, - use_dynamic, - entries, - true, - did_strip_ref, - did_strip_typedef); - if (non_ptr_type.IsTypedefType()) - { - CompilerType deffed_pointed_type = non_ptr_type.GetTypedefedType().GetPointerType(); - GetPossibleMatches(valobj, - deffed_pointed_type, - reason | lldb_private::eFormatterChoiceCriterionNavigatedTypedefs, - use_dynamic, - entries, - did_strip_ptr, - did_strip_ref, - true); // this is not exactly the usual meaning of stripping typedefs - } + for (bool is_rvalue_ref = true, j = true; + j && compiler_type.IsReferenceType(nullptr, &is_rvalue_ref); j = false) { + CompilerType non_ref_type = compiler_type.GetNonReferenceType(); + GetPossibleMatches( + valobj, non_ref_type, + reason | + lldb_private::eFormatterChoiceCriterionStrippedPointerReference, + use_dynamic, entries, did_strip_ptr, true, did_strip_typedef); + if (non_ref_type.IsTypedefType()) { + CompilerType deffed_referenced_type = non_ref_type.GetTypedefedType(); + deffed_referenced_type = + is_rvalue_ref ? deffed_referenced_type.GetRValueReferenceType() + : deffed_referenced_type.GetLValueReferenceType(); + GetPossibleMatches( + valobj, deffed_referenced_type, + reason | lldb_private::eFormatterChoiceCriterionNavigatedTypedefs, + use_dynamic, entries, did_strip_ptr, did_strip_ref, + true); // this is not exactly the usual meaning of stripping typedefs } - - for (lldb::LanguageType language_type : GetCandidateLanguages(valobj)) - { - if (Language* language = Language::FindPlugin(language_type)) - { - for (ConstString candidate : language->GetPossibleFormattersMatches(valobj, use_dynamic)) - { - entries.push_back({candidate, - reason | lldb_private::eFormatterChoiceCriterionLanguagePlugin, - did_strip_ptr, - did_strip_ref, - did_strip_typedef}); - } - } + } + + if (compiler_type.IsPointerType()) { + CompilerType non_ptr_type = compiler_type.GetPointeeType(); + GetPossibleMatches( + valobj, non_ptr_type, + reason | + lldb_private::eFormatterChoiceCriterionStrippedPointerReference, + use_dynamic, entries, true, did_strip_ref, did_strip_typedef); + if (non_ptr_type.IsTypedefType()) { + CompilerType deffed_pointed_type = + non_ptr_type.GetTypedefedType().GetPointerType(); + GetPossibleMatches( + valobj, deffed_pointed_type, + reason | lldb_private::eFormatterChoiceCriterionNavigatedTypedefs, + use_dynamic, entries, did_strip_ptr, did_strip_ref, + true); // this is not exactly the usual meaning of stripping typedefs } - - // try to strip typedef chains - if (compiler_type.IsTypedefType()) - { - CompilerType deffed_type = compiler_type.GetTypedefedType(); - GetPossibleMatches(valobj, - deffed_type, - reason | lldb_private::eFormatterChoiceCriterionNavigatedTypedefs, - use_dynamic, - entries, - did_strip_ptr, - did_strip_ref, - true); + } + + for (lldb::LanguageType language_type : GetCandidateLanguages(valobj)) { + if (Language *language = Language::FindPlugin(language_type)) { + for (ConstString candidate : + language->GetPossibleFormattersMatches(valobj, use_dynamic)) { + entries.push_back( + {candidate, + reason | lldb_private::eFormatterChoiceCriterionLanguagePlugin, + did_strip_ptr, did_strip_ref, did_strip_typedef}); + } } - - if (root_level) - { - do { - if (!compiler_type.IsValid()) - break; - - CompilerType unqual_compiler_ast_type = compiler_type.GetFullyUnqualifiedType(); - if (!unqual_compiler_ast_type.IsValid()) - break; - if (unqual_compiler_ast_type.GetOpaqueQualType() != compiler_type.GetOpaqueQualType()) - GetPossibleMatches (valobj, - unqual_compiler_ast_type, - reason, - use_dynamic, - entries, - did_strip_ptr, - did_strip_ref, - did_strip_typedef); - } while(false); - - - // if all else fails, go to static type - if (valobj.IsDynamic()) - { - lldb::ValueObjectSP static_value_sp(valobj.GetStaticValue()); - if (static_value_sp) - GetPossibleMatches(*static_value_sp.get(), - static_value_sp->GetCompilerType(), - reason | lldb_private::eFormatterChoiceCriterionWentToStaticValue, - use_dynamic, - entries, - did_strip_ptr, - did_strip_ref, - did_strip_typedef, - true); - } + } + + // try to strip typedef chains + if (compiler_type.IsTypedefType()) { + CompilerType deffed_type = compiler_type.GetTypedefedType(); + GetPossibleMatches( + valobj, deffed_type, + reason | lldb_private::eFormatterChoiceCriterionNavigatedTypedefs, + use_dynamic, entries, did_strip_ptr, did_strip_ref, true); + } + + if (root_level) { + do { + if (!compiler_type.IsValid()) + break; + + CompilerType unqual_compiler_ast_type = + compiler_type.GetFullyUnqualifiedType(); + if (!unqual_compiler_ast_type.IsValid()) + break; + if (unqual_compiler_ast_type.GetOpaqueQualType() != + compiler_type.GetOpaqueQualType()) + GetPossibleMatches(valobj, unqual_compiler_ast_type, reason, + use_dynamic, entries, did_strip_ptr, did_strip_ref, + did_strip_typedef); + } while (false); + + // if all else fails, go to static type + if (valobj.IsDynamic()) { + lldb::ValueObjectSP static_value_sp(valobj.GetStaticValue()); + if (static_value_sp) + GetPossibleMatches( + *static_value_sp.get(), static_value_sp->GetCompilerType(), + reason | lldb_private::eFormatterChoiceCriterionWentToStaticValue, + use_dynamic, entries, did_strip_ptr, did_strip_ref, + did_strip_typedef, true); } + } } lldb::TypeFormatImplSP -FormatManager::GetFormatForType (lldb::TypeNameSpecifierImplSP type_sp) -{ - if (!type_sp) - return lldb::TypeFormatImplSP(); - lldb::TypeFormatImplSP format_chosen_sp; - uint32_t num_categories = m_categories_map.GetCount(); - lldb::TypeCategoryImplSP category_sp; - uint32_t prio_category = UINT32_MAX; - for (uint32_t category_id = 0; - category_id < num_categories; - category_id++) - { - category_sp = GetCategoryAtIndex(category_id); - if (category_sp->IsEnabled() == false) - continue; - lldb::TypeFormatImplSP format_current_sp = category_sp->GetFormatForType(type_sp); - if (format_current_sp && (format_chosen_sp.get() == NULL || (prio_category > category_sp->GetEnabledPosition()))) - { - prio_category = category_sp->GetEnabledPosition(); - format_chosen_sp = format_current_sp; - } +FormatManager::GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp) { + if (!type_sp) + return lldb::TypeFormatImplSP(); + lldb::TypeFormatImplSP format_chosen_sp; + uint32_t num_categories = m_categories_map.GetCount(); + lldb::TypeCategoryImplSP category_sp; + uint32_t prio_category = UINT32_MAX; + for (uint32_t category_id = 0; category_id < num_categories; category_id++) { + category_sp = GetCategoryAtIndex(category_id); + if (category_sp->IsEnabled() == false) + continue; + lldb::TypeFormatImplSP format_current_sp = + category_sp->GetFormatForType(type_sp); + if (format_current_sp && + (format_chosen_sp.get() == NULL || + (prio_category > category_sp->GetEnabledPosition()))) { + prio_category = category_sp->GetEnabledPosition(); + format_chosen_sp = format_current_sp; } - return format_chosen_sp; + } + return format_chosen_sp; } lldb::TypeSummaryImplSP -FormatManager::GetSummaryForType (lldb::TypeNameSpecifierImplSP type_sp) -{ - if (!type_sp) - return lldb::TypeSummaryImplSP(); - lldb::TypeSummaryImplSP summary_chosen_sp; - uint32_t num_categories = m_categories_map.GetCount(); - lldb::TypeCategoryImplSP category_sp; - uint32_t prio_category = UINT32_MAX; - for (uint32_t category_id = 0; - category_id < num_categories; - category_id++) - { - category_sp = GetCategoryAtIndex(category_id); - if (category_sp->IsEnabled() == false) - continue; - lldb::TypeSummaryImplSP summary_current_sp = category_sp->GetSummaryForType(type_sp); - if (summary_current_sp && (summary_chosen_sp.get() == NULL || (prio_category > category_sp->GetEnabledPosition()))) - { - prio_category = category_sp->GetEnabledPosition(); - summary_chosen_sp = summary_current_sp; - } +FormatManager::GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp) { + if (!type_sp) + return lldb::TypeSummaryImplSP(); + lldb::TypeSummaryImplSP summary_chosen_sp; + uint32_t num_categories = m_categories_map.GetCount(); + lldb::TypeCategoryImplSP category_sp; + uint32_t prio_category = UINT32_MAX; + for (uint32_t category_id = 0; category_id < num_categories; category_id++) { + category_sp = GetCategoryAtIndex(category_id); + if (category_sp->IsEnabled() == false) + continue; + lldb::TypeSummaryImplSP summary_current_sp = + category_sp->GetSummaryForType(type_sp); + if (summary_current_sp && + (summary_chosen_sp.get() == NULL || + (prio_category > category_sp->GetEnabledPosition()))) { + prio_category = category_sp->GetEnabledPosition(); + summary_chosen_sp = summary_current_sp; } - return summary_chosen_sp; + } + return summary_chosen_sp; } lldb::TypeFilterImplSP -FormatManager::GetFilterForType (lldb::TypeNameSpecifierImplSP type_sp) -{ - if (!type_sp) - return lldb::TypeFilterImplSP(); - lldb::TypeFilterImplSP filter_chosen_sp; - uint32_t num_categories = m_categories_map.GetCount(); - lldb::TypeCategoryImplSP category_sp; - uint32_t prio_category = UINT32_MAX; - for (uint32_t category_id = 0; - category_id < num_categories; - category_id++) - { - category_sp = GetCategoryAtIndex(category_id); - if (category_sp->IsEnabled() == false) - continue; - lldb::TypeFilterImplSP filter_current_sp((TypeFilterImpl*)category_sp->GetFilterForType(type_sp).get()); - if (filter_current_sp && (filter_chosen_sp.get() == NULL || (prio_category > category_sp->GetEnabledPosition()))) - { - prio_category = category_sp->GetEnabledPosition(); - filter_chosen_sp = filter_current_sp; - } +FormatManager::GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp) { + if (!type_sp) + return lldb::TypeFilterImplSP(); + lldb::TypeFilterImplSP filter_chosen_sp; + uint32_t num_categories = m_categories_map.GetCount(); + lldb::TypeCategoryImplSP category_sp; + uint32_t prio_category = UINT32_MAX; + for (uint32_t category_id = 0; category_id < num_categories; category_id++) { + category_sp = GetCategoryAtIndex(category_id); + if (category_sp->IsEnabled() == false) + continue; + lldb::TypeFilterImplSP filter_current_sp( + (TypeFilterImpl *)category_sp->GetFilterForType(type_sp).get()); + if (filter_current_sp && + (filter_chosen_sp.get() == NULL || + (prio_category > category_sp->GetEnabledPosition()))) { + prio_category = category_sp->GetEnabledPosition(); + filter_chosen_sp = filter_current_sp; } - return filter_chosen_sp; + } + return filter_chosen_sp; } #ifndef LLDB_DISABLE_PYTHON lldb::ScriptedSyntheticChildrenSP -FormatManager::GetSyntheticForType (lldb::TypeNameSpecifierImplSP type_sp) -{ - if (!type_sp) - return lldb::ScriptedSyntheticChildrenSP(); - lldb::ScriptedSyntheticChildrenSP synth_chosen_sp; - uint32_t num_categories = m_categories_map.GetCount(); - lldb::TypeCategoryImplSP category_sp; - uint32_t prio_category = UINT32_MAX; - for (uint32_t category_id = 0; - category_id < num_categories; - category_id++) - { - category_sp = GetCategoryAtIndex(category_id); - if (category_sp->IsEnabled() == false) - continue; - lldb::ScriptedSyntheticChildrenSP synth_current_sp((ScriptedSyntheticChildren*)category_sp->GetSyntheticForType(type_sp).get()); - if (synth_current_sp && (synth_chosen_sp.get() == NULL || (prio_category > category_sp->GetEnabledPosition()))) - { - prio_category = category_sp->GetEnabledPosition(); - synth_chosen_sp = synth_current_sp; - } +FormatManager::GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp) { + if (!type_sp) + return lldb::ScriptedSyntheticChildrenSP(); + lldb::ScriptedSyntheticChildrenSP synth_chosen_sp; + uint32_t num_categories = m_categories_map.GetCount(); + lldb::TypeCategoryImplSP category_sp; + uint32_t prio_category = UINT32_MAX; + for (uint32_t category_id = 0; category_id < num_categories; category_id++) { + category_sp = GetCategoryAtIndex(category_id); + if (category_sp->IsEnabled() == false) + continue; + lldb::ScriptedSyntheticChildrenSP synth_current_sp( + (ScriptedSyntheticChildren *)category_sp->GetSyntheticForType(type_sp) + .get()); + if (synth_current_sp && + (synth_chosen_sp.get() == NULL || + (prio_category > category_sp->GetEnabledPosition()))) { + prio_category = category_sp->GetEnabledPosition(); + synth_chosen_sp = synth_current_sp; } - return synth_chosen_sp; + } + return synth_chosen_sp; } #endif #ifndef LLDB_DISABLE_PYTHON -lldb::SyntheticChildrenSP -FormatManager::GetSyntheticChildrenForType (lldb::TypeNameSpecifierImplSP type_sp) -{ - if (!type_sp) - return lldb::SyntheticChildrenSP(); - lldb::TypeFilterImplSP filter_sp = GetFilterForType(type_sp); - lldb::ScriptedSyntheticChildrenSP synth_sp = GetSyntheticForType(type_sp); - if (filter_sp->GetRevision() > synth_sp->GetRevision()) - return lldb::SyntheticChildrenSP(filter_sp.get()); - else - return lldb::SyntheticChildrenSP(synth_sp.get()); +lldb::SyntheticChildrenSP FormatManager::GetSyntheticChildrenForType( + lldb::TypeNameSpecifierImplSP type_sp) { + if (!type_sp) + return lldb::SyntheticChildrenSP(); + lldb::TypeFilterImplSP filter_sp = GetFilterForType(type_sp); + lldb::ScriptedSyntheticChildrenSP synth_sp = GetSyntheticForType(type_sp); + if (filter_sp->GetRevision() > synth_sp->GetRevision()) + return lldb::SyntheticChildrenSP(filter_sp.get()); + else + return lldb::SyntheticChildrenSP(synth_sp.get()); } #endif lldb::TypeValidatorImplSP -FormatManager::GetValidatorForType (lldb::TypeNameSpecifierImplSP type_sp) -{ - if (!type_sp) - return lldb::TypeValidatorImplSP(); - lldb::TypeValidatorImplSP validator_chosen_sp; - uint32_t num_categories = m_categories_map.GetCount(); - lldb::TypeCategoryImplSP category_sp; - uint32_t prio_category = UINT32_MAX; - for (uint32_t category_id = 0; - category_id < num_categories; - category_id++) - { - category_sp = GetCategoryAtIndex(category_id); - if (category_sp->IsEnabled() == false) - continue; - lldb::TypeValidatorImplSP validator_current_sp(category_sp->GetValidatorForType(type_sp).get()); - if (validator_current_sp && (validator_chosen_sp.get() == NULL || (prio_category > category_sp->GetEnabledPosition()))) - { - prio_category = category_sp->GetEnabledPosition(); - validator_chosen_sp = validator_current_sp; - } +FormatManager::GetValidatorForType(lldb::TypeNameSpecifierImplSP type_sp) { + if (!type_sp) + return lldb::TypeValidatorImplSP(); + lldb::TypeValidatorImplSP validator_chosen_sp; + uint32_t num_categories = m_categories_map.GetCount(); + lldb::TypeCategoryImplSP category_sp; + uint32_t prio_category = UINT32_MAX; + for (uint32_t category_id = 0; category_id < num_categories; category_id++) { + category_sp = GetCategoryAtIndex(category_id); + if (category_sp->IsEnabled() == false) + continue; + lldb::TypeValidatorImplSP validator_current_sp( + category_sp->GetValidatorForType(type_sp).get()); + if (validator_current_sp && + (validator_chosen_sp.get() == NULL || + (prio_category > category_sp->GetEnabledPosition()))) { + prio_category = category_sp->GetEnabledPosition(); + validator_chosen_sp = validator_current_sp; } - return validator_chosen_sp; + } + return validator_chosen_sp; } -void -FormatManager::ForEachCategory(TypeCategoryMap::ForEachCallback callback) -{ - m_categories_map.ForEach(callback); - std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex); - for (const auto& entry : m_language_categories_map) - { - if (auto category_sp = entry.second->GetCategory()) - { - if (!callback(category_sp)) - break; - } +void FormatManager::ForEachCategory(TypeCategoryMap::ForEachCallback callback) { + m_categories_map.ForEach(callback); + std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex); + for (const auto &entry : m_language_categories_map) { + if (auto category_sp = entry.second->GetCategory()) { + if (!callback(category_sp)) + break; } + } } lldb::TypeCategoryImplSP -FormatManager::GetCategory (const ConstString& category_name, - bool can_create) -{ - if (!category_name) - return GetCategory(m_default_category_name); - lldb::TypeCategoryImplSP category; - if (m_categories_map.Get(category_name, category)) - return category; - - if (!can_create) - return lldb::TypeCategoryImplSP(); - - m_categories_map.Add(category_name,lldb::TypeCategoryImplSP(new TypeCategoryImpl(this, category_name))); - return GetCategory(category_name); +FormatManager::GetCategory(const ConstString &category_name, bool can_create) { + if (!category_name) + return GetCategory(m_default_category_name); + lldb::TypeCategoryImplSP category; + if (m_categories_map.Get(category_name, category)) + return category; + + if (!can_create) + return lldb::TypeCategoryImplSP(); + + m_categories_map.Add( + category_name, + lldb::TypeCategoryImplSP(new TypeCategoryImpl(this, category_name))); + return GetCategory(category_name); } -lldb::Format -FormatManager::GetSingleItemFormat(lldb::Format vector_format) -{ - switch(vector_format) - { - case eFormatVectorOfChar: - return eFormatCharArray; - - case eFormatVectorOfSInt8: - case eFormatVectorOfSInt16: - case eFormatVectorOfSInt32: - case eFormatVectorOfSInt64: - return eFormatDecimal; - - case eFormatVectorOfUInt8: - case eFormatVectorOfUInt16: - case eFormatVectorOfUInt32: - case eFormatVectorOfUInt64: - case eFormatVectorOfUInt128: - return eFormatHex; - - case eFormatVectorOfFloat16: - case eFormatVectorOfFloat32: - case eFormatVectorOfFloat64: - return eFormatFloat; - - default: - return lldb::eFormatInvalid; - } +lldb::Format FormatManager::GetSingleItemFormat(lldb::Format vector_format) { + switch (vector_format) { + case eFormatVectorOfChar: + return eFormatCharArray; + + case eFormatVectorOfSInt8: + case eFormatVectorOfSInt16: + case eFormatVectorOfSInt32: + case eFormatVectorOfSInt64: + return eFormatDecimal; + + case eFormatVectorOfUInt8: + case eFormatVectorOfUInt16: + case eFormatVectorOfUInt32: + case eFormatVectorOfUInt64: + case eFormatVectorOfUInt128: + return eFormatHex; + + case eFormatVectorOfFloat16: + case eFormatVectorOfFloat32: + case eFormatVectorOfFloat64: + return eFormatFloat; + + default: + return lldb::eFormatInvalid; + } } -bool -FormatManager::ShouldPrintAsOneLiner (ValueObject& valobj) -{ - // if settings say no oneline whatsoever - if (valobj.GetTargetSP().get() && valobj.GetTargetSP()->GetDebugger().GetAutoOneLineSummaries() == false) - return false; // then don't oneline - - // if this object has a summary, then ask the summary - if (valobj.GetSummaryFormat().get() != nullptr) - return valobj.GetSummaryFormat()->IsOneLiner(); - - // no children, no party - if (valobj.GetNumChildren() == 0) +bool FormatManager::ShouldPrintAsOneLiner(ValueObject &valobj) { + // if settings say no oneline whatsoever + if (valobj.GetTargetSP().get() && + valobj.GetTargetSP()->GetDebugger().GetAutoOneLineSummaries() == false) + return false; // then don't oneline + + // if this object has a summary, then ask the summary + if (valobj.GetSummaryFormat().get() != nullptr) + return valobj.GetSummaryFormat()->IsOneLiner(); + + // no children, no party + if (valobj.GetNumChildren() == 0) + return false; + + // ask the type if it has any opinion about this + // eLazyBoolCalculate == no opinion; other values should be self explanatory + CompilerType compiler_type(valobj.GetCompilerType()); + if (compiler_type.IsValid()) { + switch (compiler_type.ShouldPrintAsOneLiner(&valobj)) { + case eLazyBoolNo: + return false; + case eLazyBoolYes: + return true; + case eLazyBoolCalculate: + break; + } + } + + size_t total_children_name_len = 0; + + for (size_t idx = 0; idx < valobj.GetNumChildren(); idx++) { + bool is_synth_val = false; + ValueObjectSP child_sp(valobj.GetChildAtIndex(idx, true)); + // something is wrong here - bail out + if (!child_sp) + return false; + + // also ask the child's type if it has any opinion + CompilerType child_compiler_type(child_sp->GetCompilerType()); + if (child_compiler_type.IsValid()) { + switch (child_compiler_type.ShouldPrintAsOneLiner(child_sp.get())) { + case eLazyBoolYes: + // an opinion of yes is only binding for the child, so keep going + case eLazyBoolCalculate: + break; + case eLazyBoolNo: + // but if the child says no, then it's a veto on the whole thing + return false; + } + } + + // if we decided to define synthetic children for a type, we probably care + // enough + // to show them, but avoid nesting children in children + if (child_sp->GetSyntheticChildren().get() != nullptr) { + ValueObjectSP synth_sp(child_sp->GetSyntheticValue()); + // wait.. wat? just get out of here.. + if (!synth_sp) + return false; + // but if we only have them to provide a value, keep going + if (synth_sp->MightHaveChildren() == false && + synth_sp->DoesProvideSyntheticValue()) + is_synth_val = true; + else + return false; + } + + total_children_name_len += child_sp->GetName().GetLength(); + + // 50 itself is a "randomly" chosen number - the idea is that + // overly long structs should not get this treatment + // FIXME: maybe make this a user-tweakable setting? + if (total_children_name_len > 50) + return false; + + // if a summary is there.. + if (child_sp->GetSummaryFormat()) { + // and it wants children, then bail out + if (child_sp->GetSummaryFormat()->DoesPrintChildren(child_sp.get())) return false; - - // ask the type if it has any opinion about this - // eLazyBoolCalculate == no opinion; other values should be self explanatory - CompilerType compiler_type(valobj.GetCompilerType()); - if (compiler_type.IsValid()) - { - switch (compiler_type.ShouldPrintAsOneLiner(&valobj)) - { - case eLazyBoolNo: - return false; - case eLazyBoolYes: - return true; - case eLazyBoolCalculate: - break; - } } - - size_t total_children_name_len = 0; - - for (size_t idx = 0; - idx < valobj.GetNumChildren(); - idx++) - { - bool is_synth_val = false; - ValueObjectSP child_sp(valobj.GetChildAtIndex(idx, true)); - // something is wrong here - bail out - if (!child_sp) - return false; - - // also ask the child's type if it has any opinion - CompilerType child_compiler_type(child_sp->GetCompilerType()); - if (child_compiler_type.IsValid()) - { - switch (child_compiler_type.ShouldPrintAsOneLiner(child_sp.get())) - { - case eLazyBoolYes: - // an opinion of yes is only binding for the child, so keep going - case eLazyBoolCalculate: - break; - case eLazyBoolNo: - // but if the child says no, then it's a veto on the whole thing - return false; - } - } - - // if we decided to define synthetic children for a type, we probably care enough - // to show them, but avoid nesting children in children - if (child_sp->GetSyntheticChildren().get() != nullptr) - { - ValueObjectSP synth_sp(child_sp->GetSyntheticValue()); - // wait.. wat? just get out of here.. - if (!synth_sp) - return false; - // but if we only have them to provide a value, keep going - if (synth_sp->MightHaveChildren() == false && synth_sp->DoesProvideSyntheticValue()) - is_synth_val = true; - else - return false; - } - - total_children_name_len += child_sp->GetName().GetLength(); - - // 50 itself is a "randomly" chosen number - the idea is that - // overly long structs should not get this treatment - // FIXME: maybe make this a user-tweakable setting? - if (total_children_name_len > 50) - return false; - - // if a summary is there.. - if (child_sp->GetSummaryFormat()) - { - // and it wants children, then bail out - if (child_sp->GetSummaryFormat()->DoesPrintChildren(child_sp.get())) - return false; - } - - // if this child has children.. - if (child_sp->GetNumChildren()) - { - // ...and no summary... - // (if it had a summary and the summary wanted children, we would have bailed out anyway - // so this only makes us bail out if this has no summary and we would then print children) - if (!child_sp->GetSummaryFormat() && !is_synth_val) // but again only do that if not a synthetic valued child - return false; // then bail out - } + + // if this child has children.. + if (child_sp->GetNumChildren()) { + // ...and no summary... + // (if it had a summary and the summary wanted children, we would have + // bailed out anyway + // so this only makes us bail out if this has no summary and we would + // then print children) + if (!child_sp->GetSummaryFormat() && !is_synth_val) // but again only do + // that if not a + // synthetic valued + // child + return false; // then bail out } - return true; + } + return true; } -ConstString -FormatManager::GetValidTypeName (const ConstString& type) -{ - return ::GetValidTypeName_Impl(type); +ConstString FormatManager::GetValidTypeName(const ConstString &type) { + return ::GetValidTypeName_Impl(type); } -ConstString -FormatManager::GetTypeForCache (ValueObject& valobj, - lldb::DynamicValueType use_dynamic) -{ - ValueObjectSP valobj_sp = valobj.GetQualifiedRepresentationIfAvailable(use_dynamic, valobj.IsSynthetic()); - if (valobj_sp && valobj_sp->GetCompilerType().IsValid()) - { - if (!valobj_sp->GetCompilerType().IsMeaninglessWithoutDynamicResolution()) - return valobj_sp->GetQualifiedTypeName(); - } - return ConstString(); +ConstString FormatManager::GetTypeForCache(ValueObject &valobj, + lldb::DynamicValueType use_dynamic) { + ValueObjectSP valobj_sp = valobj.GetQualifiedRepresentationIfAvailable( + use_dynamic, valobj.IsSynthetic()); + if (valobj_sp && valobj_sp->GetCompilerType().IsValid()) { + if (!valobj_sp->GetCompilerType().IsMeaninglessWithoutDynamicResolution()) + return valobj_sp->GetQualifiedTypeName(); + } + return ConstString(); } std::vector<lldb::LanguageType> -FormatManager::GetCandidateLanguages (ValueObject& valobj) -{ - lldb::LanguageType lang_type = valobj.GetObjectRuntimeLanguage(); - return GetCandidateLanguages(lang_type); +FormatManager::GetCandidateLanguages(ValueObject &valobj) { + lldb::LanguageType lang_type = valobj.GetObjectRuntimeLanguage(); + return GetCandidateLanguages(lang_type); } std::vector<lldb::LanguageType> -FormatManager::GetCandidateLanguages (lldb::LanguageType lang_type) -{ - switch (lang_type) - { - case lldb::eLanguageTypeC: - case lldb::eLanguageTypeC89: - case lldb::eLanguageTypeC99: - case lldb::eLanguageTypeC11: - case lldb::eLanguageTypeC_plus_plus: - case lldb::eLanguageTypeC_plus_plus_03: - case lldb::eLanguageTypeC_plus_plus_11: - case lldb::eLanguageTypeC_plus_plus_14: - return {lldb::eLanguageTypeC_plus_plus, lldb::eLanguageTypeObjC}; - default: - return {lang_type}; - } +FormatManager::GetCandidateLanguages(lldb::LanguageType lang_type) { + switch (lang_type) { + case lldb::eLanguageTypeC: + case lldb::eLanguageTypeC89: + case lldb::eLanguageTypeC99: + case lldb::eLanguageTypeC11: + case lldb::eLanguageTypeC_plus_plus: + case lldb::eLanguageTypeC_plus_plus_03: + case lldb::eLanguageTypeC_plus_plus_11: + case lldb::eLanguageTypeC_plus_plus_14: + return {lldb::eLanguageTypeC_plus_plus, lldb::eLanguageTypeObjC}; + default: + return {lang_type}; + } } -LanguageCategory* -FormatManager::GetCategoryForLanguage (lldb::LanguageType lang_type) -{ - std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex); - auto iter = m_language_categories_map.find(lang_type), end = m_language_categories_map.end(); - if (iter != end) - return iter->second.get(); - LanguageCategory* lang_category = new LanguageCategory(lang_type); - m_language_categories_map[lang_type] = LanguageCategory::UniquePointer(lang_category); - return lang_category; +LanguageCategory * +FormatManager::GetCategoryForLanguage(lldb::LanguageType lang_type) { + std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex); + auto iter = m_language_categories_map.find(lang_type), + end = m_language_categories_map.end(); + if (iter != end) + return iter->second.get(); + LanguageCategory *lang_category = new LanguageCategory(lang_type); + m_language_categories_map[lang_type] = + LanguageCategory::UniquePointer(lang_category); + return lang_category; } lldb::TypeFormatImplSP -FormatManager::GetHardcodedFormat (FormattersMatchData& match_data) -{ - TypeFormatImplSP retval_sp; - - for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) - { - if (LanguageCategory* lang_category = GetCategoryForLanguage(lang_type)) - { - if (lang_category->GetHardcoded(*this, match_data, retval_sp)) - break; - } +FormatManager::GetHardcodedFormat(FormattersMatchData &match_data) { + TypeFormatImplSP retval_sp; + + for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) { + if (LanguageCategory *lang_category = GetCategoryForLanguage(lang_type)) { + if (lang_category->GetHardcoded(*this, match_data, retval_sp)) + break; } + } - return retval_sp; + return retval_sp; } lldb::TypeFormatImplSP -FormatManager::GetFormat (ValueObject& valobj, - lldb::DynamicValueType use_dynamic) -{ - FormattersMatchData match_data(valobj, use_dynamic); - - TypeFormatImplSP retval; - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_DATAFORMATTERS)); - if (match_data.GetTypeForCache()) - { - if (log) - log->Printf("\n\n[FormatManager::GetFormat] Looking into cache for type %s", match_data.GetTypeForCache().AsCString("<invalid>")); - if (m_format_cache.GetFormat(match_data.GetTypeForCache(),retval)) - { - if (log) - { - log->Printf("[FormatManager::GetFormat] Cache search success. Returning."); - if (log->GetDebug()) - log->Printf("[FormatManager::GetFormat] Cache hits: %" PRIu64 " - Cache Misses: %" PRIu64, m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses()); - } - return retval; - } - if (log) - log->Printf("[FormatManager::GetFormat] Cache search failed. Going normal route"); - } - - retval = m_categories_map.GetFormat(match_data); - if (!retval) - { - if (log) - log->Printf("[FormatManager::GetFormat] Search failed. Giving language a chance."); - for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) - { - if (LanguageCategory* lang_category = GetCategoryForLanguage(lang_type)) - { - if (lang_category->Get(match_data, retval)) - break; - } - } - if (retval) - { - if (log) - log->Printf("[FormatManager::GetFormat] Language search success. Returning."); - return retval; - } +FormatManager::GetFormat(ValueObject &valobj, + lldb::DynamicValueType use_dynamic) { + FormattersMatchData match_data(valobj, use_dynamic); + + TypeFormatImplSP retval; + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DATAFORMATTERS)); + if (match_data.GetTypeForCache()) { + if (log) + log->Printf( + "\n\n[FormatManager::GetFormat] Looking into cache for type %s", + match_data.GetTypeForCache().AsCString("<invalid>")); + if (m_format_cache.GetFormat(match_data.GetTypeForCache(), retval)) { + if (log) { + log->Printf( + "[FormatManager::GetFormat] Cache search success. Returning."); + if (log->GetDebug()) + log->Printf("[FormatManager::GetFormat] Cache hits: %" PRIu64 + " - Cache Misses: %" PRIu64, + m_format_cache.GetCacheHits(), + m_format_cache.GetCacheMisses()); + } + return retval; } - if (!retval) - { - if (log) - log->Printf("[FormatManager::GetFormat] Search failed. Giving hardcoded a chance."); - retval = GetHardcodedFormat(match_data); + if (log) + log->Printf( + "[FormatManager::GetFormat] Cache search failed. Going normal route"); + } + + retval = m_categories_map.GetFormat(match_data); + if (!retval) { + if (log) + log->Printf("[FormatManager::GetFormat] Search failed. Giving language a " + "chance."); + for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) { + if (LanguageCategory *lang_category = GetCategoryForLanguage(lang_type)) { + if (lang_category->Get(match_data, retval)) + break; + } } - - if (match_data.GetTypeForCache() && (!retval || !retval->NonCacheable())) - { - if (log) - log->Printf("[FormatManager::GetFormat] Caching %p for type %s", - static_cast<void*>(retval.get()), - match_data.GetTypeForCache().AsCString("<invalid>")); - m_format_cache.SetFormat(match_data.GetTypeForCache(),retval); + if (retval) { + if (log) + log->Printf( + "[FormatManager::GetFormat] Language search success. Returning."); + return retval; } - if (log && log->GetDebug()) - log->Printf("[FormatManager::GetFormat] Cache hits: %" PRIu64 " - Cache Misses: %" PRIu64, m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses()); - return retval; + } + if (!retval) { + if (log) + log->Printf("[FormatManager::GetFormat] Search failed. Giving hardcoded " + "a chance."); + retval = GetHardcodedFormat(match_data); + } + + if (match_data.GetTypeForCache() && (!retval || !retval->NonCacheable())) { + if (log) + log->Printf("[FormatManager::GetFormat] Caching %p for type %s", + static_cast<void *>(retval.get()), + match_data.GetTypeForCache().AsCString("<invalid>")); + m_format_cache.SetFormat(match_data.GetTypeForCache(), retval); + } + if (log && log->GetDebug()) + log->Printf("[FormatManager::GetFormat] Cache hits: %" PRIu64 + " - Cache Misses: %" PRIu64, + m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses()); + return retval; } lldb::TypeSummaryImplSP -FormatManager::GetHardcodedSummaryFormat (FormattersMatchData& match_data) -{ - TypeSummaryImplSP retval_sp; - - for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) - { - if (LanguageCategory* lang_category = GetCategoryForLanguage(lang_type)) - { - if (lang_category->GetHardcoded(*this, match_data, retval_sp)) - break; - } +FormatManager::GetHardcodedSummaryFormat(FormattersMatchData &match_data) { + TypeSummaryImplSP retval_sp; + + for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) { + if (LanguageCategory *lang_category = GetCategoryForLanguage(lang_type)) { + if (lang_category->GetHardcoded(*this, match_data, retval_sp)) + break; } - - return retval_sp; + } + + return retval_sp; } lldb::TypeSummaryImplSP -FormatManager::GetSummaryFormat (ValueObject& valobj, - lldb::DynamicValueType use_dynamic) -{ - FormattersMatchData match_data(valobj, use_dynamic); - - TypeSummaryImplSP retval; - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_DATAFORMATTERS)); - if (match_data.GetTypeForCache()) - { - if (log) - log->Printf("\n\n[FormatManager::GetSummaryFormat] Looking into cache for type %s", match_data.GetTypeForCache().AsCString("<invalid>")); - if (m_format_cache.GetSummary(match_data.GetTypeForCache(),retval)) - { - if (log) - { - log->Printf("[FormatManager::GetSummaryFormat] Cache search success. Returning."); - if (log->GetDebug()) - log->Printf("[FormatManager::GetSummaryFormat] Cache hits: %" PRIu64 " - Cache Misses: %" PRIu64, m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses()); - } - return retval; - } - if (log) - log->Printf("[FormatManager::GetSummaryFormat] Cache search failed. Going normal route"); - } - - retval = m_categories_map.GetSummaryFormat(match_data); - if (!retval) - { - if (log) - log->Printf("[FormatManager::GetSummaryFormat] Search failed. Giving language a chance."); - for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) - { - if (LanguageCategory* lang_category = GetCategoryForLanguage(lang_type)) - { - if (lang_category->Get(match_data, retval)) - break; - } - } - if (retval) - { - if (log) - log->Printf("[FormatManager::GetSummaryFormat] Language search success. Returning."); - return retval; - } +FormatManager::GetSummaryFormat(ValueObject &valobj, + lldb::DynamicValueType use_dynamic) { + FormattersMatchData match_data(valobj, use_dynamic); + + TypeSummaryImplSP retval; + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DATAFORMATTERS)); + if (match_data.GetTypeForCache()) { + if (log) + log->Printf("\n\n[FormatManager::GetSummaryFormat] Looking into cache " + "for type %s", + match_data.GetTypeForCache().AsCString("<invalid>")); + if (m_format_cache.GetSummary(match_data.GetTypeForCache(), retval)) { + if (log) { + log->Printf("[FormatManager::GetSummaryFormat] Cache search success. " + "Returning."); + if (log->GetDebug()) + log->Printf("[FormatManager::GetSummaryFormat] Cache hits: %" PRIu64 + " - Cache Misses: %" PRIu64, + m_format_cache.GetCacheHits(), + m_format_cache.GetCacheMisses()); + } + return retval; } - if (!retval) - { - if (log) - log->Printf("[FormatManager::GetSummaryFormat] Search failed. Giving hardcoded a chance."); - retval = GetHardcodedSummaryFormat(match_data); + if (log) + log->Printf("[FormatManager::GetSummaryFormat] Cache search failed. " + "Going normal route"); + } + + retval = m_categories_map.GetSummaryFormat(match_data); + if (!retval) { + if (log) + log->Printf("[FormatManager::GetSummaryFormat] Search failed. Giving " + "language a chance."); + for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) { + if (LanguageCategory *lang_category = GetCategoryForLanguage(lang_type)) { + if (lang_category->Get(match_data, retval)) + break; + } } - - if (match_data.GetTypeForCache() && (!retval || !retval->NonCacheable())) - { - if (log) - log->Printf("[FormatManager::GetSummaryFormat] Caching %p for type %s", - static_cast<void*>(retval.get()), - match_data.GetTypeForCache().AsCString("<invalid>")); - m_format_cache.SetSummary(match_data.GetTypeForCache(),retval); + if (retval) { + if (log) + log->Printf("[FormatManager::GetSummaryFormat] Language search " + "success. Returning."); + return retval; } - if (log && log->GetDebug()) - log->Printf("[FormatManager::GetSummaryFormat] Cache hits: %" PRIu64 " - Cache Misses: %" PRIu64, m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses()); - return retval; + } + if (!retval) { + if (log) + log->Printf("[FormatManager::GetSummaryFormat] Search failed. Giving " + "hardcoded a chance."); + retval = GetHardcodedSummaryFormat(match_data); + } + + if (match_data.GetTypeForCache() && (!retval || !retval->NonCacheable())) { + if (log) + log->Printf("[FormatManager::GetSummaryFormat] Caching %p for type %s", + static_cast<void *>(retval.get()), + match_data.GetTypeForCache().AsCString("<invalid>")); + m_format_cache.SetSummary(match_data.GetTypeForCache(), retval); + } + if (log && log->GetDebug()) + log->Printf("[FormatManager::GetSummaryFormat] Cache hits: %" PRIu64 + " - Cache Misses: %" PRIu64, + m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses()); + return retval; } #ifndef LLDB_DISABLE_PYTHON lldb::SyntheticChildrenSP -FormatManager::GetHardcodedSyntheticChildren (FormattersMatchData& match_data) -{ - SyntheticChildrenSP retval_sp; - - for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) - { - if (LanguageCategory* lang_category = GetCategoryForLanguage(lang_type)) - { - if (lang_category->GetHardcoded(*this, match_data, retval_sp)) - break; - } +FormatManager::GetHardcodedSyntheticChildren(FormattersMatchData &match_data) { + SyntheticChildrenSP retval_sp; + + for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) { + if (LanguageCategory *lang_category = GetCategoryForLanguage(lang_type)) { + if (lang_category->GetHardcoded(*this, match_data, retval_sp)) + break; } - - return retval_sp; + } + + return retval_sp; } lldb::SyntheticChildrenSP -FormatManager::GetSyntheticChildren (ValueObject& valobj, - lldb::DynamicValueType use_dynamic) -{ - FormattersMatchData match_data(valobj, use_dynamic); - - SyntheticChildrenSP retval; - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_DATAFORMATTERS)); - if (match_data.GetTypeForCache()) - { - if (log) - log->Printf("\n\n[FormatManager::GetSyntheticChildren] Looking into cache for type %s", match_data.GetTypeForCache().AsCString("<invalid>")); - if (m_format_cache.GetSynthetic(match_data.GetTypeForCache(),retval)) - { - if (log) - { - log->Printf("[FormatManager::GetSyntheticChildren] Cache search success. Returning."); - if (log->GetDebug()) - log->Printf("[FormatManager::GetSyntheticChildren] Cache hits: %" PRIu64 " - Cache Misses: %" PRIu64, m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses()); - } - return retval; - } - if (log) - log->Printf("[FormatManager::GetSyntheticChildren] Cache search failed. Going normal route"); - } - - retval = m_categories_map.GetSyntheticChildren(match_data); - if (!retval) - { - if (log) - log->Printf("[FormatManager::GetSyntheticChildren] Search failed. Giving language a chance."); - for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) - { - if (LanguageCategory* lang_category = GetCategoryForLanguage(lang_type)) - { - if (lang_category->Get(match_data, retval)) - break; - } - } - if (retval) - { - if (log) - log->Printf("[FormatManager::GetSyntheticChildren] Language search success. Returning."); - return retval; - } +FormatManager::GetSyntheticChildren(ValueObject &valobj, + lldb::DynamicValueType use_dynamic) { + FormattersMatchData match_data(valobj, use_dynamic); + + SyntheticChildrenSP retval; + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DATAFORMATTERS)); + if (match_data.GetTypeForCache()) { + if (log) + log->Printf("\n\n[FormatManager::GetSyntheticChildren] Looking into " + "cache for type %s", + match_data.GetTypeForCache().AsCString("<invalid>")); + if (m_format_cache.GetSynthetic(match_data.GetTypeForCache(), retval)) { + if (log) { + log->Printf("[FormatManager::GetSyntheticChildren] Cache search " + "success. Returning."); + if (log->GetDebug()) + log->Printf( + "[FormatManager::GetSyntheticChildren] Cache hits: %" PRIu64 + " - Cache Misses: %" PRIu64, + m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses()); + } + return retval; } - if (!retval) - { - if (log) - log->Printf("[FormatManager::GetSyntheticChildren] Search failed. Giving hardcoded a chance."); - retval = GetHardcodedSyntheticChildren(match_data); + if (log) + log->Printf("[FormatManager::GetSyntheticChildren] Cache search failed. " + "Going normal route"); + } + + retval = m_categories_map.GetSyntheticChildren(match_data); + if (!retval) { + if (log) + log->Printf("[FormatManager::GetSyntheticChildren] Search failed. Giving " + "language a chance."); + for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) { + if (LanguageCategory *lang_category = GetCategoryForLanguage(lang_type)) { + if (lang_category->Get(match_data, retval)) + break; + } } - - if (match_data.GetTypeForCache() && (!retval || !retval->NonCacheable())) - { - if (log) - log->Printf("[FormatManager::GetSyntheticChildren] Caching %p for type %s", - static_cast<void*>(retval.get()), - match_data.GetTypeForCache().AsCString("<invalid>")); - m_format_cache.SetSynthetic(match_data.GetTypeForCache(),retval); + if (retval) { + if (log) + log->Printf("[FormatManager::GetSyntheticChildren] Language search " + "success. Returning."); + return retval; } - if (log && log->GetDebug()) - log->Printf("[FormatManager::GetSyntheticChildren] Cache hits: %" PRIu64 " - Cache Misses: %" PRIu64, m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses()); - return retval; + } + if (!retval) { + if (log) + log->Printf("[FormatManager::GetSyntheticChildren] Search failed. Giving " + "hardcoded a chance."); + retval = GetHardcodedSyntheticChildren(match_data); + } + + if (match_data.GetTypeForCache() && (!retval || !retval->NonCacheable())) { + if (log) + log->Printf( + "[FormatManager::GetSyntheticChildren] Caching %p for type %s", + static_cast<void *>(retval.get()), + match_data.GetTypeForCache().AsCString("<invalid>")); + m_format_cache.SetSynthetic(match_data.GetTypeForCache(), retval); + } + if (log && log->GetDebug()) + log->Printf("[FormatManager::GetSyntheticChildren] Cache hits: %" PRIu64 + " - Cache Misses: %" PRIu64, + m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses()); + return retval; } #endif lldb::TypeValidatorImplSP -FormatManager::GetValidator (ValueObject& valobj, - lldb::DynamicValueType use_dynamic) -{ - FormattersMatchData match_data(valobj, use_dynamic); - - TypeValidatorImplSP retval; - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_DATAFORMATTERS)); - if (match_data.GetTypeForCache()) - { - if (log) - log->Printf("\n\n[FormatManager::GetValidator] Looking into cache for type %s", match_data.GetTypeForCache().AsCString("<invalid>")); - if (m_format_cache.GetValidator(match_data.GetTypeForCache(),retval)) - { - if (log) - { - log->Printf("[FormatManager::GetValidator] Cache search success. Returning."); - if (log->GetDebug()) - log->Printf("[FormatManager::GetValidator] Cache hits: %" PRIu64 " - Cache Misses: %" PRIu64, m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses()); - } - return retval; - } - if (log) - log->Printf("[FormatManager::GetValidator] Cache search failed. Going normal route"); - } - - retval = m_categories_map.GetValidator(match_data); - if (!retval) - { - if (log) - log->Printf("[FormatManager::GetValidator] Search failed. Giving language a chance."); - for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) - { - if (LanguageCategory* lang_category = GetCategoryForLanguage(lang_type)) - { - if (lang_category->Get(match_data, retval)) - break; - } - } - if (retval) - { - if (log) - log->Printf("[FormatManager::GetValidator] Language search success. Returning."); - return retval; - } +FormatManager::GetValidator(ValueObject &valobj, + lldb::DynamicValueType use_dynamic) { + FormattersMatchData match_data(valobj, use_dynamic); + + TypeValidatorImplSP retval; + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DATAFORMATTERS)); + if (match_data.GetTypeForCache()) { + if (log) + log->Printf( + "\n\n[FormatManager::GetValidator] Looking into cache for type %s", + match_data.GetTypeForCache().AsCString("<invalid>")); + if (m_format_cache.GetValidator(match_data.GetTypeForCache(), retval)) { + if (log) { + log->Printf( + "[FormatManager::GetValidator] Cache search success. Returning."); + if (log->GetDebug()) + log->Printf("[FormatManager::GetValidator] Cache hits: %" PRIu64 + " - Cache Misses: %" PRIu64, + m_format_cache.GetCacheHits(), + m_format_cache.GetCacheMisses()); + } + return retval; } - if (!retval) - { - if (log) - log->Printf("[FormatManager::GetValidator] Search failed. Giving hardcoded a chance."); - retval = GetHardcodedValidator(match_data); + if (log) + log->Printf("[FormatManager::GetValidator] Cache search failed. Going " + "normal route"); + } + + retval = m_categories_map.GetValidator(match_data); + if (!retval) { + if (log) + log->Printf("[FormatManager::GetValidator] Search failed. Giving " + "language a chance."); + for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) { + if (LanguageCategory *lang_category = GetCategoryForLanguage(lang_type)) { + if (lang_category->Get(match_data, retval)) + break; + } } - - if (match_data.GetTypeForCache() && (!retval || !retval->NonCacheable())) - { - if (log) - log->Printf("[FormatManager::GetValidator] Caching %p for type %s", - static_cast<void*>(retval.get()), - match_data.GetTypeForCache().AsCString("<invalid>")); - m_format_cache.SetValidator(match_data.GetTypeForCache(),retval); + if (retval) { + if (log) + log->Printf("[FormatManager::GetValidator] Language search success. " + "Returning."); + return retval; } - if (log && log->GetDebug()) - log->Printf("[FormatManager::GetValidator] Cache hits: %" PRIu64 " - Cache Misses: %" PRIu64, m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses()); - return retval; + } + if (!retval) { + if (log) + log->Printf("[FormatManager::GetValidator] Search failed. Giving " + "hardcoded a chance."); + retval = GetHardcodedValidator(match_data); + } + + if (match_data.GetTypeForCache() && (!retval || !retval->NonCacheable())) { + if (log) + log->Printf("[FormatManager::GetValidator] Caching %p for type %s", + static_cast<void *>(retval.get()), + match_data.GetTypeForCache().AsCString("<invalid>")); + m_format_cache.SetValidator(match_data.GetTypeForCache(), retval); + } + if (log && log->GetDebug()) + log->Printf("[FormatManager::GetValidator] Cache hits: %" PRIu64 + " - Cache Misses: %" PRIu64, + m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses()); + return retval; } lldb::TypeValidatorImplSP -FormatManager::GetHardcodedValidator (FormattersMatchData& match_data) -{ - TypeValidatorImplSP retval_sp; - - for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) - { - if (LanguageCategory* lang_category = GetCategoryForLanguage(lang_type)) - { - if (lang_category->GetHardcoded(*this, match_data, retval_sp)) - break; - } +FormatManager::GetHardcodedValidator(FormattersMatchData &match_data) { + TypeValidatorImplSP retval_sp; + + for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) { + if (LanguageCategory *lang_category = GetCategoryForLanguage(lang_type)) { + if (lang_category->GetHardcoded(*this, match_data, retval_sp)) + break; } - - return retval_sp; + } + + return retval_sp; } FormatManager::FormatManager() - : m_last_revision(0), - m_format_cache(), - m_language_categories_mutex(), - m_language_categories_map(), - m_named_summaries_map(this), - m_categories_map(this), - m_default_category_name(ConstString("default")), + : m_last_revision(0), m_format_cache(), m_language_categories_mutex(), + m_language_categories_map(), m_named_summaries_map(this), + m_categories_map(this), m_default_category_name(ConstString("default")), m_system_category_name(ConstString("system")), - m_vectortypes_category_name(ConstString("VectorTypes")) -{ - LoadSystemFormatters(); - LoadVectorFormatters(); + m_vectortypes_category_name(ConstString("VectorTypes")) { + LoadSystemFormatters(); + LoadVectorFormatters(); - EnableCategory(m_vectortypes_category_name, TypeCategoryMap::Last, lldb::eLanguageTypeObjC_plus_plus); - EnableCategory(m_system_category_name, TypeCategoryMap::Last, lldb::eLanguageTypeObjC_plus_plus); + EnableCategory(m_vectortypes_category_name, TypeCategoryMap::Last, + lldb::eLanguageTypeObjC_plus_plus); + EnableCategory(m_system_category_name, TypeCategoryMap::Last, + lldb::eLanguageTypeObjC_plus_plus); } -void -FormatManager::LoadSystemFormatters() -{ - TypeSummaryImpl::Flags string_flags; - string_flags.SetCascades(true) - .SetSkipPointers(true) - .SetSkipReferences(false) - .SetDontShowChildren(true) - .SetDontShowValue(false) - .SetShowMembersOneLiner(false) - .SetHideItemNames(false); - - TypeSummaryImpl::Flags string_array_flags; - string_array_flags.SetCascades(true) - .SetSkipPointers(true) - .SetSkipReferences(false) - .SetDontShowChildren(true) - .SetDontShowValue(true) - .SetShowMembersOneLiner(false) - .SetHideItemNames(false); - - lldb::TypeSummaryImplSP string_format(new StringSummaryFormat(string_flags, "${var%s}")); - - - lldb::TypeSummaryImplSP string_array_format(new StringSummaryFormat(string_array_flags, - "${var%s}")); - - lldb::RegularExpressionSP any_size_char_arr(new RegularExpression("char \\[[0-9]+\\]")); - lldb::RegularExpressionSP any_size_wchar_arr(new RegularExpression("wchar_t \\[[0-9]+\\]")); - - TypeCategoryImpl::SharedPointer sys_category_sp = GetCategory(m_system_category_name); - - sys_category_sp->GetTypeSummariesContainer()->Add(ConstString("char *"), string_format); - sys_category_sp->GetTypeSummariesContainer()->Add(ConstString("unsigned char *"), string_format); - sys_category_sp->GetRegexTypeSummariesContainer()->Add(any_size_char_arr, string_array_format); - - lldb::TypeSummaryImplSP ostype_summary(new StringSummaryFormat(TypeSummaryImpl::Flags().SetCascades(false) - .SetSkipPointers(true) - .SetSkipReferences(true) - .SetDontShowChildren(true) - .SetDontShowValue(false) - .SetShowMembersOneLiner(false) - .SetHideItemNames(false), - "${var%O}")); - - sys_category_sp->GetTypeSummariesContainer()->Add(ConstString("OSType"), ostype_summary); - +void FormatManager::LoadSystemFormatters() { + TypeSummaryImpl::Flags string_flags; + string_flags.SetCascades(true) + .SetSkipPointers(true) + .SetSkipReferences(false) + .SetDontShowChildren(true) + .SetDontShowValue(false) + .SetShowMembersOneLiner(false) + .SetHideItemNames(false); + + TypeSummaryImpl::Flags string_array_flags; + string_array_flags.SetCascades(true) + .SetSkipPointers(true) + .SetSkipReferences(false) + .SetDontShowChildren(true) + .SetDontShowValue(true) + .SetShowMembersOneLiner(false) + .SetHideItemNames(false); + + lldb::TypeSummaryImplSP string_format( + new StringSummaryFormat(string_flags, "${var%s}")); + + lldb::TypeSummaryImplSP string_array_format( + new StringSummaryFormat(string_array_flags, "${var%s}")); + + lldb::RegularExpressionSP any_size_char_arr( + new RegularExpression("char \\[[0-9]+\\]")); + lldb::RegularExpressionSP any_size_wchar_arr( + new RegularExpression("wchar_t \\[[0-9]+\\]")); + + TypeCategoryImpl::SharedPointer sys_category_sp = + GetCategory(m_system_category_name); + + sys_category_sp->GetTypeSummariesContainer()->Add(ConstString("char *"), + string_format); + sys_category_sp->GetTypeSummariesContainer()->Add( + ConstString("unsigned char *"), string_format); + sys_category_sp->GetRegexTypeSummariesContainer()->Add(any_size_char_arr, + string_array_format); + + lldb::TypeSummaryImplSP ostype_summary( + new StringSummaryFormat(TypeSummaryImpl::Flags() + .SetCascades(false) + .SetSkipPointers(true) + .SetSkipReferences(true) + .SetDontShowChildren(true) + .SetDontShowValue(false) + .SetShowMembersOneLiner(false) + .SetHideItemNames(false), + "${var%O}")); + + sys_category_sp->GetTypeSummariesContainer()->Add(ConstString("OSType"), + ostype_summary); + #ifndef LLDB_DISABLE_PYTHON - TypeFormatImpl::Flags fourchar_flags; - fourchar_flags.SetCascades(true).SetSkipPointers(true).SetSkipReferences(true); - - AddFormat(sys_category_sp, lldb::eFormatOSType, ConstString("FourCharCode"), fourchar_flags); + TypeFormatImpl::Flags fourchar_flags; + fourchar_flags.SetCascades(true).SetSkipPointers(true).SetSkipReferences( + true); + + AddFormat(sys_category_sp, lldb::eFormatOSType, ConstString("FourCharCode"), + fourchar_flags); #endif } -void -FormatManager::LoadVectorFormatters() -{ - TypeCategoryImpl::SharedPointer vectors_category_sp = GetCategory(m_vectortypes_category_name); - - TypeSummaryImpl::Flags vector_flags; - vector_flags.SetCascades(true) - .SetSkipPointers(true) - .SetSkipReferences(false) - .SetDontShowChildren(true) - .SetDontShowValue(false) - .SetShowMembersOneLiner(true) - .SetHideItemNames(true); - - AddStringSummary(vectors_category_sp, - "${var.uint128}", - ConstString("builtin_type_vec128"), - vector_flags); - - AddStringSummary(vectors_category_sp, - "", - ConstString("float [4]"), - vector_flags); - AddStringSummary(vectors_category_sp, - "", - ConstString("int32_t [4]"), - vector_flags); - AddStringSummary(vectors_category_sp, - "", - ConstString("int16_t [8]"), - vector_flags); - AddStringSummary(vectors_category_sp, - "", - ConstString("vDouble"), - vector_flags); - AddStringSummary(vectors_category_sp, - "", - ConstString("vFloat"), - vector_flags); - AddStringSummary(vectors_category_sp, - "", - ConstString("vSInt8"), - vector_flags); - AddStringSummary(vectors_category_sp, - "", - ConstString("vSInt16"), - vector_flags); - AddStringSummary(vectors_category_sp, - "", - ConstString("vSInt32"), - vector_flags); - AddStringSummary(vectors_category_sp, - "", - ConstString("vUInt16"), - vector_flags); - AddStringSummary(vectors_category_sp, - "", - ConstString("vUInt8"), - vector_flags); - AddStringSummary(vectors_category_sp, - "", - ConstString("vUInt16"), - vector_flags); - AddStringSummary(vectors_category_sp, - "", - ConstString("vUInt32"), - vector_flags); - AddStringSummary(vectors_category_sp, - "", - ConstString("vBool32"), - vector_flags); +void FormatManager::LoadVectorFormatters() { + TypeCategoryImpl::SharedPointer vectors_category_sp = + GetCategory(m_vectortypes_category_name); + + TypeSummaryImpl::Flags vector_flags; + vector_flags.SetCascades(true) + .SetSkipPointers(true) + .SetSkipReferences(false) + .SetDontShowChildren(true) + .SetDontShowValue(false) + .SetShowMembersOneLiner(true) + .SetHideItemNames(true); + + AddStringSummary(vectors_category_sp, "${var.uint128}", + ConstString("builtin_type_vec128"), vector_flags); + + AddStringSummary(vectors_category_sp, "", ConstString("float [4]"), + vector_flags); + AddStringSummary(vectors_category_sp, "", ConstString("int32_t [4]"), + vector_flags); + AddStringSummary(vectors_category_sp, "", ConstString("int16_t [8]"), + vector_flags); + AddStringSummary(vectors_category_sp, "", ConstString("vDouble"), + vector_flags); + AddStringSummary(vectors_category_sp, "", ConstString("vFloat"), + vector_flags); + AddStringSummary(vectors_category_sp, "", ConstString("vSInt8"), + vector_flags); + AddStringSummary(vectors_category_sp, "", ConstString("vSInt16"), + vector_flags); + AddStringSummary(vectors_category_sp, "", ConstString("vSInt32"), + vector_flags); + AddStringSummary(vectors_category_sp, "", ConstString("vUInt16"), + vector_flags); + AddStringSummary(vectors_category_sp, "", ConstString("vUInt8"), + vector_flags); + AddStringSummary(vectors_category_sp, "", ConstString("vUInt16"), + vector_flags); + AddStringSummary(vectors_category_sp, "", ConstString("vUInt32"), + vector_flags); + AddStringSummary(vectors_category_sp, "", ConstString("vBool32"), + vector_flags); } diff --git a/lldb/source/DataFormatters/FormattersHelpers.cpp b/lldb/source/DataFormatters/FormattersHelpers.cpp index c4ff75cffdd..842237fc91b 100644 --- a/lldb/source/DataFormatters/FormattersHelpers.cpp +++ b/lldb/source/DataFormatters/FormattersHelpers.cpp @@ -1,4 +1,5 @@ -//===-- FormattersHelpers.cpp -------------------------------------*- C++ -*-===// +//===-- FormattersHelpers.cpp -------------------------------------*- C++ +//-*-===// // // The LLVM Compiler Infrastructure // @@ -26,139 +27,126 @@ using namespace lldb; using namespace lldb_private; using namespace lldb_private::formatters; -void -lldb_private::formatters::AddFormat (TypeCategoryImpl::SharedPointer category_sp, - lldb::Format format, - ConstString type_name, - TypeFormatImpl::Flags flags, - bool regex) -{ - lldb::TypeFormatImplSP format_sp(new TypeFormatImpl_Format(format, flags)); - - if (regex) - category_sp->GetRegexTypeFormatsContainer()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())),format_sp); - else - category_sp->GetTypeFormatsContainer()->Add(type_name, format_sp); +void lldb_private::formatters::AddFormat( + TypeCategoryImpl::SharedPointer category_sp, lldb::Format format, + ConstString type_name, TypeFormatImpl::Flags flags, bool regex) { + lldb::TypeFormatImplSP format_sp(new TypeFormatImpl_Format(format, flags)); + + if (regex) + category_sp->GetRegexTypeFormatsContainer()->Add( + RegularExpressionSP(new RegularExpression(type_name.AsCString())), + format_sp); + else + category_sp->GetTypeFormatsContainer()->Add(type_name, format_sp); } -void -lldb_private::formatters::AddSummary(TypeCategoryImpl::SharedPointer category_sp, - TypeSummaryImplSP summary_sp, - ConstString type_name, - bool regex) -{ - if (regex) - category_sp->GetRegexTypeSummariesContainer()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())),summary_sp); - else - category_sp->GetTypeSummariesContainer()->Add(type_name, summary_sp); +void lldb_private::formatters::AddSummary( + TypeCategoryImpl::SharedPointer category_sp, TypeSummaryImplSP summary_sp, + ConstString type_name, bool regex) { + if (regex) + category_sp->GetRegexTypeSummariesContainer()->Add( + RegularExpressionSP(new RegularExpression(type_name.AsCString())), + summary_sp); + else + category_sp->GetTypeSummariesContainer()->Add(type_name, summary_sp); } -void -lldb_private::formatters::AddStringSummary(TypeCategoryImpl::SharedPointer category_sp, - const char* string, - ConstString type_name, - TypeSummaryImpl::Flags flags, - bool regex) -{ - lldb::TypeSummaryImplSP summary_sp(new StringSummaryFormat(flags, - string)); - - if (regex) - category_sp->GetRegexTypeSummariesContainer()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())),summary_sp); - else - category_sp->GetTypeSummariesContainer()->Add(type_name, summary_sp); +void lldb_private::formatters::AddStringSummary( + TypeCategoryImpl::SharedPointer category_sp, const char *string, + ConstString type_name, TypeSummaryImpl::Flags flags, bool regex) { + lldb::TypeSummaryImplSP summary_sp(new StringSummaryFormat(flags, string)); + + if (regex) + category_sp->GetRegexTypeSummariesContainer()->Add( + RegularExpressionSP(new RegularExpression(type_name.AsCString())), + summary_sp); + else + category_sp->GetTypeSummariesContainer()->Add(type_name, summary_sp); } -void -lldb_private::formatters::AddOneLineSummary (TypeCategoryImpl::SharedPointer category_sp, - ConstString type_name, - TypeSummaryImpl::Flags flags, - bool regex) -{ - flags.SetShowMembersOneLiner(true); - lldb::TypeSummaryImplSP summary_sp(new StringSummaryFormat(flags, "")); - - if (regex) - category_sp->GetRegexTypeSummariesContainer()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())),summary_sp); - else - category_sp->GetTypeSummariesContainer()->Add(type_name, summary_sp); +void lldb_private::formatters::AddOneLineSummary( + TypeCategoryImpl::SharedPointer category_sp, ConstString type_name, + TypeSummaryImpl::Flags flags, bool regex) { + flags.SetShowMembersOneLiner(true); + lldb::TypeSummaryImplSP summary_sp(new StringSummaryFormat(flags, "")); + + if (regex) + category_sp->GetRegexTypeSummariesContainer()->Add( + RegularExpressionSP(new RegularExpression(type_name.AsCString())), + summary_sp); + else + category_sp->GetTypeSummariesContainer()->Add(type_name, summary_sp); } #ifndef LLDB_DISABLE_PYTHON -void -lldb_private::formatters::AddCXXSummary (TypeCategoryImpl::SharedPointer category_sp, - CXXFunctionSummaryFormat::Callback funct, - const char* description, - ConstString type_name, - TypeSummaryImpl::Flags flags, - bool regex) -{ - lldb::TypeSummaryImplSP summary_sp(new CXXFunctionSummaryFormat(flags,funct,description)); - if (regex) - category_sp->GetRegexTypeSummariesContainer()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())),summary_sp); - else - category_sp->GetTypeSummariesContainer()->Add(type_name, summary_sp); +void lldb_private::formatters::AddCXXSummary( + TypeCategoryImpl::SharedPointer category_sp, + CXXFunctionSummaryFormat::Callback funct, const char *description, + ConstString type_name, TypeSummaryImpl::Flags flags, bool regex) { + lldb::TypeSummaryImplSP summary_sp( + new CXXFunctionSummaryFormat(flags, funct, description)); + if (regex) + category_sp->GetRegexTypeSummariesContainer()->Add( + RegularExpressionSP(new RegularExpression(type_name.AsCString())), + summary_sp); + else + category_sp->GetTypeSummariesContainer()->Add(type_name, summary_sp); } -void -lldb_private::formatters::AddCXXSynthetic (TypeCategoryImpl::SharedPointer category_sp, - CXXSyntheticChildren::CreateFrontEndCallback generator, - const char* description, - ConstString type_name, - ScriptedSyntheticChildren::Flags flags, - bool regex) -{ - lldb::SyntheticChildrenSP synth_sp(new CXXSyntheticChildren(flags,description,generator)); - if (regex) - category_sp->GetRegexTypeSyntheticsContainer()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())), synth_sp); - else - category_sp->GetTypeSyntheticsContainer()->Add(type_name,synth_sp); +void lldb_private::formatters::AddCXXSynthetic( + TypeCategoryImpl::SharedPointer category_sp, + CXXSyntheticChildren::CreateFrontEndCallback generator, + const char *description, ConstString type_name, + ScriptedSyntheticChildren::Flags flags, bool regex) { + lldb::SyntheticChildrenSP synth_sp( + new CXXSyntheticChildren(flags, description, generator)); + if (regex) + category_sp->GetRegexTypeSyntheticsContainer()->Add( + RegularExpressionSP(new RegularExpression(type_name.AsCString())), + synth_sp); + else + category_sp->GetTypeSyntheticsContainer()->Add(type_name, synth_sp); } -void -lldb_private::formatters::AddFilter (TypeCategoryImpl::SharedPointer category_sp, - std::vector<std::string> children, - const char* description, - ConstString type_name, - ScriptedSyntheticChildren::Flags flags, - bool regex) -{ - TypeFilterImplSP filter_sp(new TypeFilterImpl(flags)); - for (auto child : children) - filter_sp->AddExpressionPath(child); - if (regex) - category_sp->GetRegexTypeFiltersContainer()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())), filter_sp); - else - category_sp->GetTypeFiltersContainer()->Add(type_name,filter_sp); +void lldb_private::formatters::AddFilter( + TypeCategoryImpl::SharedPointer category_sp, + std::vector<std::string> children, const char *description, + ConstString type_name, ScriptedSyntheticChildren::Flags flags, bool regex) { + TypeFilterImplSP filter_sp(new TypeFilterImpl(flags)); + for (auto child : children) + filter_sp->AddExpressionPath(child); + if (regex) + category_sp->GetRegexTypeFiltersContainer()->Add( + RegularExpressionSP(new RegularExpression(type_name.AsCString())), + filter_sp); + else + category_sp->GetTypeFiltersContainer()->Add(type_name, filter_sp); } #endif -size_t -lldb_private::formatters::ExtractIndexFromString (const char* item_name) -{ - if (!item_name || !*item_name) - return UINT32_MAX; - if (*item_name != '[') - return UINT32_MAX; - item_name++; - char* endptr = NULL; - unsigned long int idx = ::strtoul(item_name, &endptr, 0); - if (idx == 0 && endptr == item_name) - return UINT32_MAX; - if (idx == ULONG_MAX) - return UINT32_MAX; - return idx; +size_t lldb_private::formatters::ExtractIndexFromString(const char *item_name) { + if (!item_name || !*item_name) + return UINT32_MAX; + if (*item_name != '[') + return UINT32_MAX; + item_name++; + char *endptr = NULL; + unsigned long int idx = ::strtoul(item_name, &endptr, 0); + if (idx == 0 && endptr == item_name) + return UINT32_MAX; + if (idx == ULONG_MAX) + return UINT32_MAX; + return idx; } lldb::addr_t -lldb_private::formatters::GetArrayAddressOrPointerValue (ValueObject& valobj) -{ - lldb::addr_t data_addr = LLDB_INVALID_ADDRESS; +lldb_private::formatters::GetArrayAddressOrPointerValue(ValueObject &valobj) { + lldb::addr_t data_addr = LLDB_INVALID_ADDRESS; - if (valobj.IsPointerType()) - data_addr = valobj.GetValueAsUnsigned(0); - else if (valobj.IsArrayType()) - data_addr = valobj.GetAddressOf(); + if (valobj.IsPointerType()) + data_addr = valobj.GetValueAsUnsigned(0); + else if (valobj.IsArrayType()) + data_addr = valobj.GetAddressOf(); - return data_addr; + return data_addr; } diff --git a/lldb/source/DataFormatters/LanguageCategory.cpp b/lldb/source/DataFormatters/LanguageCategory.cpp index 261c3e6302e..251f0c368e0 100644 --- a/lldb/source/DataFormatters/LanguageCategory.cpp +++ b/lldb/source/DataFormatters/LanguageCategory.cpp @@ -1,4 +1,5 @@ -//===-- LanguageCategory.cpp ---------------------------------------*- C++ -*-===// +//===-- LanguageCategory.cpp ---------------------------------------*- C++ +//-*-===// // // The LLVM Compiler Infrastructure // @@ -24,248 +25,208 @@ using namespace lldb; using namespace lldb_private; -LanguageCategory::LanguageCategory (lldb::LanguageType lang_type) : - m_category_sp(), - m_hardcoded_formats(), - m_hardcoded_summaries(), - m_hardcoded_synthetics(), - m_hardcoded_validators(), - m_format_cache(), - m_enabled(false) -{ - if (Language* language_plugin = Language::FindPlugin(lang_type)) - { - m_category_sp = language_plugin->GetFormatters(); - m_hardcoded_formats = language_plugin->GetHardcodedFormats(); - m_hardcoded_summaries = language_plugin->GetHardcodedSummaries(); - m_hardcoded_synthetics = language_plugin->GetHardcodedSynthetics(); - m_hardcoded_validators = language_plugin->GetHardcodedValidators(); - } - Enable(); +LanguageCategory::LanguageCategory(lldb::LanguageType lang_type) + : m_category_sp(), m_hardcoded_formats(), m_hardcoded_summaries(), + m_hardcoded_synthetics(), m_hardcoded_validators(), m_format_cache(), + m_enabled(false) { + if (Language *language_plugin = Language::FindPlugin(lang_type)) { + m_category_sp = language_plugin->GetFormatters(); + m_hardcoded_formats = language_plugin->GetHardcodedFormats(); + m_hardcoded_summaries = language_plugin->GetHardcodedSummaries(); + m_hardcoded_synthetics = language_plugin->GetHardcodedSynthetics(); + m_hardcoded_validators = language_plugin->GetHardcodedValidators(); + } + Enable(); } -bool -LanguageCategory::Get (FormattersMatchData& match_data, - lldb::TypeFormatImplSP& format_sp) -{ - if (!m_category_sp) - return false; - - if (!IsEnabled()) - return false; - - if (match_data.GetTypeForCache()) - { - if (m_format_cache.GetFormat(match_data.GetTypeForCache(), format_sp)) - return format_sp.get() != nullptr; - } - - ValueObject& valobj(match_data.GetValueObject()); - bool result = m_category_sp->Get(valobj, match_data.GetMatchesVector(), format_sp); - if (match_data.GetTypeForCache() && (!format_sp || !format_sp->NonCacheable())) - { - m_format_cache.SetFormat(match_data.GetTypeForCache(), format_sp); - } - return result; +bool LanguageCategory::Get(FormattersMatchData &match_data, + lldb::TypeFormatImplSP &format_sp) { + if (!m_category_sp) + return false; + + if (!IsEnabled()) + return false; + + if (match_data.GetTypeForCache()) { + if (m_format_cache.GetFormat(match_data.GetTypeForCache(), format_sp)) + return format_sp.get() != nullptr; + } + + ValueObject &valobj(match_data.GetValueObject()); + bool result = + m_category_sp->Get(valobj, match_data.GetMatchesVector(), format_sp); + if (match_data.GetTypeForCache() && + (!format_sp || !format_sp->NonCacheable())) { + m_format_cache.SetFormat(match_data.GetTypeForCache(), format_sp); + } + return result; } -bool -LanguageCategory::Get (FormattersMatchData& match_data, - lldb::TypeSummaryImplSP& format_sp) -{ - if (!m_category_sp) - return false; - - if (!IsEnabled()) - return false; - - if (match_data.GetTypeForCache()) - { - if (m_format_cache.GetSummary(match_data.GetTypeForCache(), format_sp)) - return format_sp.get() != nullptr; - } - - ValueObject& valobj(match_data.GetValueObject()); - bool result = m_category_sp->Get(valobj, match_data.GetMatchesVector(), format_sp); - if (match_data.GetTypeForCache() && (!format_sp || !format_sp->NonCacheable())) - { - m_format_cache.SetSummary(match_data.GetTypeForCache(), format_sp); - } - return result; +bool LanguageCategory::Get(FormattersMatchData &match_data, + lldb::TypeSummaryImplSP &format_sp) { + if (!m_category_sp) + return false; + + if (!IsEnabled()) + return false; + + if (match_data.GetTypeForCache()) { + if (m_format_cache.GetSummary(match_data.GetTypeForCache(), format_sp)) + return format_sp.get() != nullptr; + } + + ValueObject &valobj(match_data.GetValueObject()); + bool result = + m_category_sp->Get(valobj, match_data.GetMatchesVector(), format_sp); + if (match_data.GetTypeForCache() && + (!format_sp || !format_sp->NonCacheable())) { + m_format_cache.SetSummary(match_data.GetTypeForCache(), format_sp); + } + return result; } -bool -LanguageCategory::Get (FormattersMatchData& match_data, - lldb::SyntheticChildrenSP& format_sp) -{ - if (!m_category_sp) - return false; - - if (!IsEnabled()) - return false; - - if (match_data.GetTypeForCache()) - { - if (m_format_cache.GetSynthetic(match_data.GetTypeForCache(), format_sp)) - return format_sp.get() != nullptr; - } - - ValueObject& valobj(match_data.GetValueObject()); - bool result = m_category_sp->Get(valobj, match_data.GetMatchesVector(), format_sp); - if (match_data.GetTypeForCache() && (!format_sp || !format_sp->NonCacheable())) - { - m_format_cache.SetSynthetic(match_data.GetTypeForCache(), format_sp); - } - return result; +bool LanguageCategory::Get(FormattersMatchData &match_data, + lldb::SyntheticChildrenSP &format_sp) { + if (!m_category_sp) + return false; + + if (!IsEnabled()) + return false; + + if (match_data.GetTypeForCache()) { + if (m_format_cache.GetSynthetic(match_data.GetTypeForCache(), format_sp)) + return format_sp.get() != nullptr; + } + + ValueObject &valobj(match_data.GetValueObject()); + bool result = + m_category_sp->Get(valobj, match_data.GetMatchesVector(), format_sp); + if (match_data.GetTypeForCache() && + (!format_sp || !format_sp->NonCacheable())) { + m_format_cache.SetSynthetic(match_data.GetTypeForCache(), format_sp); + } + return result; } -bool -LanguageCategory::Get (FormattersMatchData& match_data, - lldb::TypeValidatorImplSP& format_sp) -{ - if (!m_category_sp) - return false; - - if (!IsEnabled()) - return false; - - if (match_data.GetTypeForCache()) - { - if (m_format_cache.GetValidator(match_data.GetTypeForCache(), format_sp)) - return format_sp.get() != nullptr; - } - - ValueObject& valobj(match_data.GetValueObject()); - bool result = m_category_sp->Get(valobj, match_data.GetMatchesVector(), format_sp); - if (match_data.GetTypeForCache() && (!format_sp || !format_sp->NonCacheable())) - { - m_format_cache.SetValidator(match_data.GetTypeForCache(), format_sp); - } - return result; +bool LanguageCategory::Get(FormattersMatchData &match_data, + lldb::TypeValidatorImplSP &format_sp) { + if (!m_category_sp) + return false; + + if (!IsEnabled()) + return false; + + if (match_data.GetTypeForCache()) { + if (m_format_cache.GetValidator(match_data.GetTypeForCache(), format_sp)) + return format_sp.get() != nullptr; + } + + ValueObject &valobj(match_data.GetValueObject()); + bool result = + m_category_sp->Get(valobj, match_data.GetMatchesVector(), format_sp); + if (match_data.GetTypeForCache() && + (!format_sp || !format_sp->NonCacheable())) { + m_format_cache.SetValidator(match_data.GetTypeForCache(), format_sp); + } + return result; } -bool -LanguageCategory::GetHardcoded (FormatManager& fmt_mgr, - FormattersMatchData& match_data, - lldb::TypeFormatImplSP& format_sp) -{ - if (!IsEnabled()) - return false; - - ValueObject& valobj(match_data.GetValueObject()); - lldb::DynamicValueType use_dynamic(match_data.GetDynamicValueType()); - - for (auto& candidate : m_hardcoded_formats) - { - if ((format_sp = candidate(valobj, use_dynamic, fmt_mgr))) - break; - } - if (match_data.GetTypeForCache() && (!format_sp || !format_sp->NonCacheable())) - { - m_format_cache.SetFormat(match_data.GetTypeForCache(), format_sp); - } - return format_sp.get() != nullptr; +bool LanguageCategory::GetHardcoded(FormatManager &fmt_mgr, + FormattersMatchData &match_data, + lldb::TypeFormatImplSP &format_sp) { + if (!IsEnabled()) + return false; + + ValueObject &valobj(match_data.GetValueObject()); + lldb::DynamicValueType use_dynamic(match_data.GetDynamicValueType()); + + for (auto &candidate : m_hardcoded_formats) { + if ((format_sp = candidate(valobj, use_dynamic, fmt_mgr))) + break; + } + if (match_data.GetTypeForCache() && + (!format_sp || !format_sp->NonCacheable())) { + m_format_cache.SetFormat(match_data.GetTypeForCache(), format_sp); + } + return format_sp.get() != nullptr; } -bool -LanguageCategory::GetHardcoded (FormatManager& fmt_mgr, - FormattersMatchData& match_data, - lldb::TypeSummaryImplSP& format_sp) -{ - if (!IsEnabled()) - return false; - - ValueObject& valobj(match_data.GetValueObject()); - lldb::DynamicValueType use_dynamic(match_data.GetDynamicValueType()); - - for (auto& candidate : m_hardcoded_summaries) - { - if ((format_sp = candidate(valobj, use_dynamic, fmt_mgr))) - break; - } - if (match_data.GetTypeForCache() && (!format_sp || !format_sp->NonCacheable())) - { - m_format_cache.SetSummary(match_data.GetTypeForCache(), format_sp); - } - return format_sp.get() != nullptr; +bool LanguageCategory::GetHardcoded(FormatManager &fmt_mgr, + FormattersMatchData &match_data, + lldb::TypeSummaryImplSP &format_sp) { + if (!IsEnabled()) + return false; + + ValueObject &valobj(match_data.GetValueObject()); + lldb::DynamicValueType use_dynamic(match_data.GetDynamicValueType()); + + for (auto &candidate : m_hardcoded_summaries) { + if ((format_sp = candidate(valobj, use_dynamic, fmt_mgr))) + break; + } + if (match_data.GetTypeForCache() && + (!format_sp || !format_sp->NonCacheable())) { + m_format_cache.SetSummary(match_data.GetTypeForCache(), format_sp); + } + return format_sp.get() != nullptr; } -bool -LanguageCategory::GetHardcoded (FormatManager& fmt_mgr, - FormattersMatchData& match_data, - lldb::SyntheticChildrenSP& format_sp) -{ - if (!IsEnabled()) - return false; - - ValueObject& valobj(match_data.GetValueObject()); - lldb::DynamicValueType use_dynamic(match_data.GetDynamicValueType()); - - for (auto& candidate : m_hardcoded_synthetics) - { - if ((format_sp = candidate(valobj, use_dynamic, fmt_mgr))) - break; - } - if (match_data.GetTypeForCache() && (!format_sp || !format_sp->NonCacheable())) - { - m_format_cache.SetSynthetic(match_data.GetTypeForCache(), format_sp); - } - return format_sp.get() != nullptr; +bool LanguageCategory::GetHardcoded(FormatManager &fmt_mgr, + FormattersMatchData &match_data, + lldb::SyntheticChildrenSP &format_sp) { + if (!IsEnabled()) + return false; + + ValueObject &valobj(match_data.GetValueObject()); + lldb::DynamicValueType use_dynamic(match_data.GetDynamicValueType()); + + for (auto &candidate : m_hardcoded_synthetics) { + if ((format_sp = candidate(valobj, use_dynamic, fmt_mgr))) + break; + } + if (match_data.GetTypeForCache() && + (!format_sp || !format_sp->NonCacheable())) { + m_format_cache.SetSynthetic(match_data.GetTypeForCache(), format_sp); + } + return format_sp.get() != nullptr; } -bool -LanguageCategory::GetHardcoded (FormatManager& fmt_mgr, - FormattersMatchData& match_data, - lldb::TypeValidatorImplSP& format_sp) -{ - if (!IsEnabled()) - return false; - - ValueObject& valobj(match_data.GetValueObject()); - lldb::DynamicValueType use_dynamic(match_data.GetDynamicValueType()); - - for (auto& candidate : m_hardcoded_validators) - { - if ((format_sp = candidate(valobj, use_dynamic, fmt_mgr))) - break; - } - if (match_data.GetTypeForCache() && (!format_sp || !format_sp->NonCacheable())) - { - m_format_cache.SetValidator(match_data.GetTypeForCache(), format_sp); - } - return format_sp.get() != nullptr; +bool LanguageCategory::GetHardcoded(FormatManager &fmt_mgr, + FormattersMatchData &match_data, + lldb::TypeValidatorImplSP &format_sp) { + if (!IsEnabled()) + return false; + + ValueObject &valobj(match_data.GetValueObject()); + lldb::DynamicValueType use_dynamic(match_data.GetDynamicValueType()); + + for (auto &candidate : m_hardcoded_validators) { + if ((format_sp = candidate(valobj, use_dynamic, fmt_mgr))) + break; + } + if (match_data.GetTypeForCache() && + (!format_sp || !format_sp->NonCacheable())) { + m_format_cache.SetValidator(match_data.GetTypeForCache(), format_sp); + } + return format_sp.get() != nullptr; } -lldb::TypeCategoryImplSP -LanguageCategory::GetCategory () const -{ - return m_category_sp; +lldb::TypeCategoryImplSP LanguageCategory::GetCategory() const { + return m_category_sp; } -FormatCache& -LanguageCategory::GetFormatCache () -{ - return m_format_cache; -} +FormatCache &LanguageCategory::GetFormatCache() { return m_format_cache; } -void -LanguageCategory::Enable () -{ - if (m_category_sp) - m_category_sp->Enable(true, TypeCategoryMap::Default); - m_enabled = true; +void LanguageCategory::Enable() { + if (m_category_sp) + m_category_sp->Enable(true, TypeCategoryMap::Default); + m_enabled = true; } -void -LanguageCategory::Disable () -{ - if (m_category_sp) - m_category_sp->Disable(); - m_enabled = false; +void LanguageCategory::Disable() { + if (m_category_sp) + m_category_sp->Disable(); + m_enabled = false; } -bool -LanguageCategory::IsEnabled () -{ - return m_enabled; -} +bool LanguageCategory::IsEnabled() { return m_enabled; } diff --git a/lldb/source/DataFormatters/StringPrinter.cpp b/lldb/source/DataFormatters/StringPrinter.cpp index 8cdbb53eaa8..d373b34381e 100644 --- a/lldb/source/DataFormatters/StringPrinter.cpp +++ b/lldb/source/DataFormatters/StringPrinter.cpp @@ -1,4 +1,5 @@ -//===-- StringPrinter.cpp ----------------------------------------*- C++ -*-===// +//===-- StringPrinter.cpp ----------------------------------------*- C++ +//-*-===// // // The LLVM Compiler Infrastructure // @@ -25,629 +26,622 @@ using namespace lldb; using namespace lldb_private; using namespace lldb_private::formatters; -// we define this for all values of type but only implement it for those we care about +// we define this for all values of type but only implement it for those we care +// about // that's good because we get linker errors for any unsupported type template <lldb_private::formatters::StringPrinter::StringElementType type> static StringPrinter::StringPrinterBufferPointer<> -GetPrintableImpl(uint8_t* buffer, uint8_t* buffer_end, uint8_t*& next); +GetPrintableImpl(uint8_t *buffer, uint8_t *buffer_end, uint8_t *&next); // mimic isprint() for Unicode codepoints -static bool -isprint(char32_t codepoint) -{ - if (codepoint <= 0x1F || codepoint == 0x7F) // C0 - { - return false; - } - if (codepoint >= 0x80 && codepoint <= 0x9F) // C1 - { - return false; - } - if (codepoint == 0x2028 || codepoint == 0x2029) // line/paragraph separators - { - return false; - } - if (codepoint == 0x200E || codepoint == 0x200F || (codepoint >= 0x202A && codepoint <= 0x202E)) // bidirectional text control - { - return false; - } - if (codepoint >= 0xFFF9 && codepoint <= 0xFFFF) // interlinears and generally specials - { - return false; - } - return true; +static bool isprint(char32_t codepoint) { + if (codepoint <= 0x1F || codepoint == 0x7F) // C0 + { + return false; + } + if (codepoint >= 0x80 && codepoint <= 0x9F) // C1 + { + return false; + } + if (codepoint == 0x2028 || codepoint == 0x2029) // line/paragraph separators + { + return false; + } + if (codepoint == 0x200E || codepoint == 0x200F || + (codepoint >= 0x202A && + codepoint <= 0x202E)) // bidirectional text control + { + return false; + } + if (codepoint >= 0xFFF9 && + codepoint <= 0xFFFF) // interlinears and generally specials + { + return false; + } + return true; } template <> StringPrinter::StringPrinterBufferPointer<> -GetPrintableImpl<StringPrinter::StringElementType::ASCII> (uint8_t* buffer, uint8_t* buffer_end, uint8_t*& next) -{ - StringPrinter::StringPrinterBufferPointer<> retval = {nullptr}; - - switch (*buffer) - { - case 0: - retval = {"\\0",2}; - break; - case '\a': - retval = {"\\a",2}; - break; - case '\b': - retval = {"\\b",2}; - break; - case '\f': - retval = {"\\f",2}; - break; - case '\n': - retval = {"\\n",2}; - break; - case '\r': - retval = {"\\r",2}; - break; - case '\t': - retval = {"\\t",2}; - break; - case '\v': - retval = {"\\v",2}; - break; - case '\"': - retval = {"\\\"",2}; - break; - case '\\': - retval = {"\\\\",2}; - break; - default: - if (isprint(*buffer)) - retval = {buffer,1}; - else - { - uint8_t* data = new uint8_t[5]; - sprintf((char*)data,"\\x%02x",*buffer); - retval = {data, 4, [] (const uint8_t* c) {delete[] c;} }; - break; - } +GetPrintableImpl<StringPrinter::StringElementType::ASCII>(uint8_t *buffer, + uint8_t *buffer_end, + uint8_t *&next) { + StringPrinter::StringPrinterBufferPointer<> retval = {nullptr}; + + switch (*buffer) { + case 0: + retval = {"\\0", 2}; + break; + case '\a': + retval = {"\\a", 2}; + break; + case '\b': + retval = {"\\b", 2}; + break; + case '\f': + retval = {"\\f", 2}; + break; + case '\n': + retval = {"\\n", 2}; + break; + case '\r': + retval = {"\\r", 2}; + break; + case '\t': + retval = {"\\t", 2}; + break; + case '\v': + retval = {"\\v", 2}; + break; + case '\"': + retval = {"\\\"", 2}; + break; + case '\\': + retval = {"\\\\", 2}; + break; + default: + if (isprint(*buffer)) + retval = {buffer, 1}; + else { + uint8_t *data = new uint8_t[5]; + sprintf((char *)data, "\\x%02x", *buffer); + retval = {data, 4, [](const uint8_t *c) { delete[] c; }}; + break; } - - next = buffer + 1; - return retval; + } + + next = buffer + 1; + return retval; } -static char32_t -ConvertUTF8ToCodePoint (unsigned char c0, unsigned char c1) -{ - return (c0-192)*64+(c1-128); +static char32_t ConvertUTF8ToCodePoint(unsigned char c0, unsigned char c1) { + return (c0 - 192) * 64 + (c1 - 128); } -static char32_t -ConvertUTF8ToCodePoint (unsigned char c0, unsigned char c1, unsigned char c2) -{ - return (c0-224)*4096+(c1-128)*64+(c2-128); +static char32_t ConvertUTF8ToCodePoint(unsigned char c0, unsigned char c1, + unsigned char c2) { + return (c0 - 224) * 4096 + (c1 - 128) * 64 + (c2 - 128); } -static char32_t -ConvertUTF8ToCodePoint (unsigned char c0, unsigned char c1, unsigned char c2, unsigned char c3) -{ - return (c0-240)*262144+(c2-128)*4096+(c2-128)*64+(c3-128); +static char32_t ConvertUTF8ToCodePoint(unsigned char c0, unsigned char c1, + unsigned char c2, unsigned char c3) { + return (c0 - 240) * 262144 + (c2 - 128) * 4096 + (c2 - 128) * 64 + (c3 - 128); } template <> StringPrinter::StringPrinterBufferPointer<> -GetPrintableImpl<StringPrinter::StringElementType::UTF8> (uint8_t* buffer, uint8_t* buffer_end, uint8_t*& next) -{ - StringPrinter::StringPrinterBufferPointer<> retval {nullptr}; - - unsigned utf8_encoded_len = getNumBytesForUTF8(*buffer); - - if (1+buffer_end-buffer < utf8_encoded_len) - { - // I don't have enough bytes - print whatever I have left - retval = {buffer,static_cast<size_t>(1+buffer_end-buffer)}; - next = buffer_end+1; - return retval; - } - - char32_t codepoint = 0; - switch (utf8_encoded_len) - { - case 1: - // this is just an ASCII byte - ask ASCII - return GetPrintableImpl<StringPrinter::StringElementType::ASCII>(buffer, buffer_end, next); - case 2: - codepoint = ConvertUTF8ToCodePoint((unsigned char)*buffer, (unsigned char)*(buffer+1)); - break; - case 3: - codepoint = ConvertUTF8ToCodePoint((unsigned char)*buffer, (unsigned char)*(buffer+1), (unsigned char)*(buffer+2)); - break; - case 4: - codepoint = ConvertUTF8ToCodePoint((unsigned char)*buffer, (unsigned char)*(buffer+1), (unsigned char)*(buffer+2), (unsigned char)*(buffer+3)); - break; - default: - // this is probably some bogus non-character thing - // just print it as-is and hope to sync up again soon - retval = {buffer,1}; - next = buffer+1; - return retval; - } - - if (codepoint) - { - switch (codepoint) - { - case 0: - retval = {"\\0",2}; - break; - case '\a': - retval = {"\\a",2}; - break; - case '\b': - retval = {"\\b",2}; - break; - case '\f': - retval = {"\\f",2}; - break; - case '\n': - retval = {"\\n",2}; - break; - case '\r': - retval = {"\\r",2}; - break; - case '\t': - retval = {"\\t",2}; - break; - case '\v': - retval = {"\\v",2}; - break; - case '\"': - retval = {"\\\"",2}; - break; - case '\\': - retval = {"\\\\",2}; - break; - default: - if (isprint(codepoint)) - retval = {buffer,utf8_encoded_len}; - else - { - uint8_t* data = new uint8_t[11]; - sprintf((char *)data, "\\U%08x", (unsigned)codepoint); - retval = { data,10,[] (const uint8_t* c) {delete[] c;} }; - break; - } - } - - next = buffer + utf8_encoded_len; - return retval; +GetPrintableImpl<StringPrinter::StringElementType::UTF8>(uint8_t *buffer, + uint8_t *buffer_end, + uint8_t *&next) { + StringPrinter::StringPrinterBufferPointer<> retval{nullptr}; + + unsigned utf8_encoded_len = getNumBytesForUTF8(*buffer); + + if (1 + buffer_end - buffer < utf8_encoded_len) { + // I don't have enough bytes - print whatever I have left + retval = {buffer, static_cast<size_t>(1 + buffer_end - buffer)}; + next = buffer_end + 1; + return retval; + } + + char32_t codepoint = 0; + switch (utf8_encoded_len) { + case 1: + // this is just an ASCII byte - ask ASCII + return GetPrintableImpl<StringPrinter::StringElementType::ASCII>( + buffer, buffer_end, next); + case 2: + codepoint = ConvertUTF8ToCodePoint((unsigned char)*buffer, + (unsigned char)*(buffer + 1)); + break; + case 3: + codepoint = ConvertUTF8ToCodePoint((unsigned char)*buffer, + (unsigned char)*(buffer + 1), + (unsigned char)*(buffer + 2)); + break; + case 4: + codepoint = ConvertUTF8ToCodePoint( + (unsigned char)*buffer, (unsigned char)*(buffer + 1), + (unsigned char)*(buffer + 2), (unsigned char)*(buffer + 3)); + break; + default: + // this is probably some bogus non-character thing + // just print it as-is and hope to sync up again soon + retval = {buffer, 1}; + next = buffer + 1; + return retval; + } + + if (codepoint) { + switch (codepoint) { + case 0: + retval = {"\\0", 2}; + break; + case '\a': + retval = {"\\a", 2}; + break; + case '\b': + retval = {"\\b", 2}; + break; + case '\f': + retval = {"\\f", 2}; + break; + case '\n': + retval = {"\\n", 2}; + break; + case '\r': + retval = {"\\r", 2}; + break; + case '\t': + retval = {"\\t", 2}; + break; + case '\v': + retval = {"\\v", 2}; + break; + case '\"': + retval = {"\\\"", 2}; + break; + case '\\': + retval = {"\\\\", 2}; + break; + default: + if (isprint(codepoint)) + retval = {buffer, utf8_encoded_len}; + else { + uint8_t *data = new uint8_t[11]; + sprintf((char *)data, "\\U%08x", (unsigned)codepoint); + retval = {data, 10, [](const uint8_t *c) { delete[] c; }}; + break; + } } - - // this should not happen - but just in case.. try to resync at some point - retval = {buffer,1}; - next = buffer+1; + + next = buffer + utf8_encoded_len; return retval; + } + + // this should not happen - but just in case.. try to resync at some point + retval = {buffer, 1}; + next = buffer + 1; + return retval; } // Given a sequence of bytes, this function returns: // a sequence of bytes to actually print out + a length // the following unscanned position of the buffer is in next static StringPrinter::StringPrinterBufferPointer<> -GetPrintable(StringPrinter::StringElementType type, uint8_t* buffer, uint8_t* buffer_end, uint8_t*& next) -{ - if (!buffer) - return {nullptr}; - - switch (type) - { - case StringPrinter::StringElementType::ASCII: - return GetPrintableImpl<StringPrinter::StringElementType::ASCII>(buffer, buffer_end, next); - case StringPrinter::StringElementType::UTF8: - return GetPrintableImpl<StringPrinter::StringElementType::UTF8>(buffer, buffer_end, next); - default: - return {nullptr}; - } +GetPrintable(StringPrinter::StringElementType type, uint8_t *buffer, + uint8_t *buffer_end, uint8_t *&next) { + if (!buffer) + return {nullptr}; + + switch (type) { + case StringPrinter::StringElementType::ASCII: + return GetPrintableImpl<StringPrinter::StringElementType::ASCII>( + buffer, buffer_end, next); + case StringPrinter::StringElementType::UTF8: + return GetPrintableImpl<StringPrinter::StringElementType::UTF8>( + buffer, buffer_end, next); + default: + return {nullptr}; + } } StringPrinter::EscapingHelper -StringPrinter::GetDefaultEscapingHelper (GetPrintableElementType elem_type) -{ - switch (elem_type) - { - case GetPrintableElementType::UTF8: - return [] (uint8_t* buffer, uint8_t* buffer_end, uint8_t*& next) -> StringPrinter::StringPrinterBufferPointer<> { - return GetPrintable(StringPrinter::StringElementType::UTF8, buffer, buffer_end, next); - }; - case GetPrintableElementType::ASCII: - return [] (uint8_t* buffer, uint8_t* buffer_end, uint8_t*& next) -> StringPrinter::StringPrinterBufferPointer<> { - return GetPrintable(StringPrinter::StringElementType::ASCII, buffer, buffer_end, next); - }; - } - llvm_unreachable("bad element type"); +StringPrinter::GetDefaultEscapingHelper(GetPrintableElementType elem_type) { + switch (elem_type) { + case GetPrintableElementType::UTF8: + return [](uint8_t *buffer, uint8_t *buffer_end, + uint8_t *&next) -> StringPrinter::StringPrinterBufferPointer<> { + return GetPrintable(StringPrinter::StringElementType::UTF8, buffer, + buffer_end, next); + }; + case GetPrintableElementType::ASCII: + return [](uint8_t *buffer, uint8_t *buffer_end, + uint8_t *&next) -> StringPrinter::StringPrinterBufferPointer<> { + return GetPrintable(StringPrinter::StringElementType::ASCII, buffer, + buffer_end, next); + }; + } + llvm_unreachable("bad element type"); } // use this call if you already have an LLDB-side buffer for the data -template<typename SourceDataType> -static bool -DumpUTFBufferToStream (ConversionResult (*ConvertFunction) (const SourceDataType**, - const SourceDataType*, - UTF8**, - UTF8*, - ConversionFlags), - const StringPrinter::ReadBufferAndDumpToStreamOptions& dump_options) -{ - Stream &stream(*dump_options.GetStream()); - if (dump_options.GetPrefixToken() != 0) - stream.Printf("%s",dump_options.GetPrefixToken()); - if (dump_options.GetQuote() != 0) - stream.Printf("%c",dump_options.GetQuote()); - auto data(dump_options.GetData()); - auto source_size(dump_options.GetSourceSize()); - if (data.GetByteSize() && data.GetDataStart() && data.GetDataEnd()) - { - const int bufferSPSize = data.GetByteSize(); - if (dump_options.GetSourceSize() == 0) - { - const int origin_encoding = 8*sizeof(SourceDataType); - source_size = bufferSPSize/(origin_encoding / 4); - } - - const SourceDataType *data_ptr = (const SourceDataType*)data.GetDataStart(); - const SourceDataType *data_end_ptr = data_ptr + source_size; - - const bool zero_is_terminator = dump_options.GetBinaryZeroIsTerminator(); - - if (zero_is_terminator) - { - while (data_ptr < data_end_ptr) - { - if (!*data_ptr) - { - data_end_ptr = data_ptr; - break; - } - data_ptr++; - } - - data_ptr = (const SourceDataType*)data.GetDataStart(); - } - - lldb::DataBufferSP utf8_data_buffer_sp; - UTF8* utf8_data_ptr = nullptr; - UTF8* utf8_data_end_ptr = nullptr; - - if (ConvertFunction) - { - utf8_data_buffer_sp.reset(new DataBufferHeap(4*bufferSPSize,0)); - utf8_data_ptr = (UTF8*)utf8_data_buffer_sp->GetBytes(); - utf8_data_end_ptr = utf8_data_ptr + utf8_data_buffer_sp->GetByteSize(); - ConvertFunction ( &data_ptr, data_end_ptr, &utf8_data_ptr, utf8_data_end_ptr, lenientConversion ); - if (false == zero_is_terminator) - utf8_data_end_ptr = utf8_data_ptr; - utf8_data_ptr = (UTF8*)utf8_data_buffer_sp->GetBytes(); // needed because the ConvertFunction will change the value of the data_ptr - } - else - { - // just copy the pointers - the cast is necessary to make the compiler happy - // but this should only happen if we are reading UTF8 data - utf8_data_ptr = const_cast<UTF8 *>(reinterpret_cast<const UTF8*>(data_ptr)); - utf8_data_end_ptr = const_cast<UTF8 *>(reinterpret_cast<const UTF8*>(data_end_ptr)); - } - - const bool escape_non_printables = dump_options.GetEscapeNonPrintables(); - lldb_private::formatters::StringPrinter::EscapingHelper escaping_callback; - if (escape_non_printables) - { - if (Language *language = Language::FindPlugin(dump_options.GetLanguage())) - escaping_callback = language->GetStringPrinterEscapingHelper(lldb_private::formatters::StringPrinter::GetPrintableElementType::UTF8); - else - escaping_callback = lldb_private::formatters::StringPrinter::GetDefaultEscapingHelper(lldb_private::formatters::StringPrinter::GetPrintableElementType::UTF8); +template <typename SourceDataType> +static bool DumpUTFBufferToStream( + ConversionResult (*ConvertFunction)(const SourceDataType **, + const SourceDataType *, UTF8 **, UTF8 *, + ConversionFlags), + const StringPrinter::ReadBufferAndDumpToStreamOptions &dump_options) { + Stream &stream(*dump_options.GetStream()); + if (dump_options.GetPrefixToken() != 0) + stream.Printf("%s", dump_options.GetPrefixToken()); + if (dump_options.GetQuote() != 0) + stream.Printf("%c", dump_options.GetQuote()); + auto data(dump_options.GetData()); + auto source_size(dump_options.GetSourceSize()); + if (data.GetByteSize() && data.GetDataStart() && data.GetDataEnd()) { + const int bufferSPSize = data.GetByteSize(); + if (dump_options.GetSourceSize() == 0) { + const int origin_encoding = 8 * sizeof(SourceDataType); + source_size = bufferSPSize / (origin_encoding / 4); + } + + const SourceDataType *data_ptr = + (const SourceDataType *)data.GetDataStart(); + const SourceDataType *data_end_ptr = data_ptr + source_size; + + const bool zero_is_terminator = dump_options.GetBinaryZeroIsTerminator(); + + if (zero_is_terminator) { + while (data_ptr < data_end_ptr) { + if (!*data_ptr) { + data_end_ptr = data_ptr; + break; } - - // since we tend to accept partial data (and even partially malformed data) - // we might end up with no NULL terminator before the end_ptr - // hence we need to take a slower route and ensure we stay within boundaries - for (;utf8_data_ptr < utf8_data_end_ptr;) - { - if (zero_is_terminator && !*utf8_data_ptr) - break; - - if (escape_non_printables) - { - uint8_t* next_data = nullptr; - auto printable = escaping_callback(utf8_data_ptr, utf8_data_end_ptr, next_data); - auto printable_bytes = printable.GetBytes(); - auto printable_size = printable.GetSize(); - if (!printable_bytes || !next_data) - { - // GetPrintable() failed on us - print one byte in a desperate resync attempt - printable_bytes = utf8_data_ptr; - printable_size = 1; - next_data = utf8_data_ptr+1; - } - for (unsigned c = 0; c < printable_size; c++) - stream.Printf("%c", *(printable_bytes+c)); - utf8_data_ptr = (uint8_t*)next_data; - } - else - { - stream.Printf("%c",*utf8_data_ptr); - utf8_data_ptr++; - } + data_ptr++; + } + + data_ptr = (const SourceDataType *)data.GetDataStart(); + } + + lldb::DataBufferSP utf8_data_buffer_sp; + UTF8 *utf8_data_ptr = nullptr; + UTF8 *utf8_data_end_ptr = nullptr; + + if (ConvertFunction) { + utf8_data_buffer_sp.reset(new DataBufferHeap(4 * bufferSPSize, 0)); + utf8_data_ptr = (UTF8 *)utf8_data_buffer_sp->GetBytes(); + utf8_data_end_ptr = utf8_data_ptr + utf8_data_buffer_sp->GetByteSize(); + ConvertFunction(&data_ptr, data_end_ptr, &utf8_data_ptr, + utf8_data_end_ptr, lenientConversion); + if (false == zero_is_terminator) + utf8_data_end_ptr = utf8_data_ptr; + utf8_data_ptr = + (UTF8 *)utf8_data_buffer_sp->GetBytes(); // needed because the + // ConvertFunction will + // change the value of the + // data_ptr + } else { + // just copy the pointers - the cast is necessary to make the compiler + // happy + // but this should only happen if we are reading UTF8 data + utf8_data_ptr = + const_cast<UTF8 *>(reinterpret_cast<const UTF8 *>(data_ptr)); + utf8_data_end_ptr = + const_cast<UTF8 *>(reinterpret_cast<const UTF8 *>(data_end_ptr)); + } + + const bool escape_non_printables = dump_options.GetEscapeNonPrintables(); + lldb_private::formatters::StringPrinter::EscapingHelper escaping_callback; + if (escape_non_printables) { + if (Language *language = Language::FindPlugin(dump_options.GetLanguage())) + escaping_callback = language->GetStringPrinterEscapingHelper( + lldb_private::formatters::StringPrinter::GetPrintableElementType:: + UTF8); + else + escaping_callback = + lldb_private::formatters::StringPrinter::GetDefaultEscapingHelper( + lldb_private::formatters::StringPrinter:: + GetPrintableElementType::UTF8); + } + + // since we tend to accept partial data (and even partially malformed data) + // we might end up with no NULL terminator before the end_ptr + // hence we need to take a slower route and ensure we stay within boundaries + for (; utf8_data_ptr < utf8_data_end_ptr;) { + if (zero_is_terminator && !*utf8_data_ptr) + break; + + if (escape_non_printables) { + uint8_t *next_data = nullptr; + auto printable = + escaping_callback(utf8_data_ptr, utf8_data_end_ptr, next_data); + auto printable_bytes = printable.GetBytes(); + auto printable_size = printable.GetSize(); + if (!printable_bytes || !next_data) { + // GetPrintable() failed on us - print one byte in a desperate resync + // attempt + printable_bytes = utf8_data_ptr; + printable_size = 1; + next_data = utf8_data_ptr + 1; } + for (unsigned c = 0; c < printable_size; c++) + stream.Printf("%c", *(printable_bytes + c)); + utf8_data_ptr = (uint8_t *)next_data; + } else { + stream.Printf("%c", *utf8_data_ptr); + utf8_data_ptr++; + } } - if (dump_options.GetQuote() != 0) - stream.Printf("%c",dump_options.GetQuote()); - if (dump_options.GetSuffixToken() != 0) - stream.Printf("%s",dump_options.GetSuffixToken()); - if (dump_options.GetIsTruncated()) - stream.Printf("..."); - return true; + } + if (dump_options.GetQuote() != 0) + stream.Printf("%c", dump_options.GetQuote()); + if (dump_options.GetSuffixToken() != 0) + stream.Printf("%s", dump_options.GetSuffixToken()); + if (dump_options.GetIsTruncated()) + stream.Printf("..."); + return true; } -lldb_private::formatters::StringPrinter::ReadStringAndDumpToStreamOptions::ReadStringAndDumpToStreamOptions (ValueObject& valobj) : - ReadStringAndDumpToStreamOptions() -{ - SetEscapeNonPrintables(valobj.GetTargetSP()->GetDebugger().GetEscapeNonPrintables()); +lldb_private::formatters::StringPrinter::ReadStringAndDumpToStreamOptions:: + ReadStringAndDumpToStreamOptions(ValueObject &valobj) + : ReadStringAndDumpToStreamOptions() { + SetEscapeNonPrintables( + valobj.GetTargetSP()->GetDebugger().GetEscapeNonPrintables()); } -lldb_private::formatters::StringPrinter::ReadBufferAndDumpToStreamOptions::ReadBufferAndDumpToStreamOptions (ValueObject& valobj) : - ReadBufferAndDumpToStreamOptions() -{ - SetEscapeNonPrintables(valobj.GetTargetSP()->GetDebugger().GetEscapeNonPrintables()); +lldb_private::formatters::StringPrinter::ReadBufferAndDumpToStreamOptions:: + ReadBufferAndDumpToStreamOptions(ValueObject &valobj) + : ReadBufferAndDumpToStreamOptions() { + SetEscapeNonPrintables( + valobj.GetTargetSP()->GetDebugger().GetEscapeNonPrintables()); } -lldb_private::formatters::StringPrinter::ReadBufferAndDumpToStreamOptions::ReadBufferAndDumpToStreamOptions (const ReadStringAndDumpToStreamOptions& options) : - ReadBufferAndDumpToStreamOptions() -{ - SetStream(options.GetStream()); - SetPrefixToken(options.GetPrefixToken()); - SetSuffixToken(options.GetSuffixToken()); - SetQuote(options.GetQuote()); - SetEscapeNonPrintables(options.GetEscapeNonPrintables()); - SetBinaryZeroIsTerminator(options.GetBinaryZeroIsTerminator()); - SetLanguage(options.GetLanguage()); +lldb_private::formatters::StringPrinter::ReadBufferAndDumpToStreamOptions:: + ReadBufferAndDumpToStreamOptions( + const ReadStringAndDumpToStreamOptions &options) + : ReadBufferAndDumpToStreamOptions() { + SetStream(options.GetStream()); + SetPrefixToken(options.GetPrefixToken()); + SetSuffixToken(options.GetSuffixToken()); + SetQuote(options.GetQuote()); + SetEscapeNonPrintables(options.GetEscapeNonPrintables()); + SetBinaryZeroIsTerminator(options.GetBinaryZeroIsTerminator()); + SetLanguage(options.GetLanguage()); } +namespace lldb_private { -namespace lldb_private -{ - -namespace formatters -{ +namespace formatters { template <> -bool -StringPrinter::ReadStringAndDumpToStream<StringPrinter::StringElementType::ASCII> (const ReadStringAndDumpToStreamOptions& options) -{ - assert(options.GetStream() && "need a Stream to print the string to"); - Error my_error; - - ProcessSP process_sp(options.GetProcessSP()); - - if (process_sp.get() == nullptr || options.GetLocation() == 0) - return false; - - size_t size; - const auto max_size = process_sp->GetTarget().GetMaximumSizeOfStringSummary(); - bool is_truncated = false; - - if (options.GetSourceSize() == 0) - size = max_size; - else if (!options.GetIgnoreMaxLength()) - { - size = options.GetSourceSize(); - if (size > max_size) - { - size = max_size; - is_truncated = true; - } +bool StringPrinter::ReadStringAndDumpToStream< + StringPrinter::StringElementType::ASCII>( + const ReadStringAndDumpToStreamOptions &options) { + assert(options.GetStream() && "need a Stream to print the string to"); + Error my_error; + + ProcessSP process_sp(options.GetProcessSP()); + + if (process_sp.get() == nullptr || options.GetLocation() == 0) + return false; + + size_t size; + const auto max_size = process_sp->GetTarget().GetMaximumSizeOfStringSummary(); + bool is_truncated = false; + + if (options.GetSourceSize() == 0) + size = max_size; + else if (!options.GetIgnoreMaxLength()) { + size = options.GetSourceSize(); + if (size > max_size) { + size = max_size; + is_truncated = true; } - else - size = options.GetSourceSize(); + } else + size = options.GetSourceSize(); - lldb::DataBufferSP buffer_sp(new DataBufferHeap(size,0)); + lldb::DataBufferSP buffer_sp(new DataBufferHeap(size, 0)); - process_sp->ReadCStringFromMemory(options.GetLocation(), (char*)buffer_sp->GetBytes(), size, my_error); + process_sp->ReadCStringFromMemory( + options.GetLocation(), (char *)buffer_sp->GetBytes(), size, my_error); - if (my_error.Fail()) - return false; + if (my_error.Fail()) + return false; - const char* prefix_token = options.GetPrefixToken(); - char quote = options.GetQuote(); + const char *prefix_token = options.GetPrefixToken(); + char quote = options.GetQuote(); - if (prefix_token != 0) - options.GetStream()->Printf("%s%c",prefix_token,quote); - else if (quote != 0) - options.GetStream()->Printf("%c",quote); + if (prefix_token != 0) + options.GetStream()->Printf("%s%c", prefix_token, quote); + else if (quote != 0) + options.GetStream()->Printf("%c", quote); - uint8_t* data_end = buffer_sp->GetBytes()+buffer_sp->GetByteSize(); + uint8_t *data_end = buffer_sp->GetBytes() + buffer_sp->GetByteSize(); - const bool escape_non_printables = options.GetEscapeNonPrintables(); - lldb_private::formatters::StringPrinter::EscapingHelper escaping_callback; - if (escape_non_printables) - { - if (Language *language = Language::FindPlugin(options.GetLanguage())) - escaping_callback = language->GetStringPrinterEscapingHelper(lldb_private::formatters::StringPrinter::GetPrintableElementType::ASCII); - else - escaping_callback = lldb_private::formatters::StringPrinter::GetDefaultEscapingHelper(lldb_private::formatters::StringPrinter::GetPrintableElementType::ASCII); - } - - // since we tend to accept partial data (and even partially malformed data) - // we might end up with no NULL terminator before the end_ptr - // hence we need to take a slower route and ensure we stay within boundaries - for (uint8_t* data = buffer_sp->GetBytes(); *data && (data < data_end);) - { - if (escape_non_printables) - { - uint8_t* next_data = nullptr; - auto printable = escaping_callback(data, data_end, next_data); - auto printable_bytes = printable.GetBytes(); - auto printable_size = printable.GetSize(); - if (!printable_bytes || !next_data) - { - // GetPrintable() failed on us - print one byte in a desperate resync attempt - printable_bytes = data; - printable_size = 1; - next_data = data+1; - } - for (unsigned c = 0; c < printable_size; c++) - options.GetStream()->Printf("%c", *(printable_bytes+c)); - data = (uint8_t*)next_data; - } - else - { - options.GetStream()->Printf("%c",*data); - data++; - } + const bool escape_non_printables = options.GetEscapeNonPrintables(); + lldb_private::formatters::StringPrinter::EscapingHelper escaping_callback; + if (escape_non_printables) { + if (Language *language = Language::FindPlugin(options.GetLanguage())) + escaping_callback = language->GetStringPrinterEscapingHelper( + lldb_private::formatters::StringPrinter::GetPrintableElementType:: + ASCII); + else + escaping_callback = + lldb_private::formatters::StringPrinter::GetDefaultEscapingHelper( + lldb_private::formatters::StringPrinter::GetPrintableElementType:: + ASCII); + } + + // since we tend to accept partial data (and even partially malformed data) + // we might end up with no NULL terminator before the end_ptr + // hence we need to take a slower route and ensure we stay within boundaries + for (uint8_t *data = buffer_sp->GetBytes(); *data && (data < data_end);) { + if (escape_non_printables) { + uint8_t *next_data = nullptr; + auto printable = escaping_callback(data, data_end, next_data); + auto printable_bytes = printable.GetBytes(); + auto printable_size = printable.GetSize(); + if (!printable_bytes || !next_data) { + // GetPrintable() failed on us - print one byte in a desperate resync + // attempt + printable_bytes = data; + printable_size = 1; + next_data = data + 1; + } + for (unsigned c = 0; c < printable_size; c++) + options.GetStream()->Printf("%c", *(printable_bytes + c)); + data = (uint8_t *)next_data; + } else { + options.GetStream()->Printf("%c", *data); + data++; } - - const char* suffix_token = options.GetSuffixToken(); - - if (suffix_token != 0) - options.GetStream()->Printf("%c%s",quote, suffix_token); - else if (quote != 0) - options.GetStream()->Printf("%c",quote); - - if (is_truncated) - options.GetStream()->Printf("..."); - - return true; + } + + const char *suffix_token = options.GetSuffixToken(); + + if (suffix_token != 0) + options.GetStream()->Printf("%c%s", quote, suffix_token); + else if (quote != 0) + options.GetStream()->Printf("%c", quote); + + if (is_truncated) + options.GetStream()->Printf("..."); + + return true; } -template<typename SourceDataType> -static bool -ReadUTFBufferAndDumpToStream (const StringPrinter::ReadStringAndDumpToStreamOptions& options, - ConversionResult (*ConvertFunction) (const SourceDataType**, - const SourceDataType*, - UTF8**, - UTF8*, - ConversionFlags)) -{ - assert(options.GetStream() && "need a Stream to print the string to"); - - if (options.GetLocation() == 0 || options.GetLocation() == LLDB_INVALID_ADDRESS) - return false; - - lldb::ProcessSP process_sp(options.GetProcessSP()); - - if (!process_sp) - return false; - - const int type_width = sizeof(SourceDataType); - const int origin_encoding = 8 * type_width ; - if (origin_encoding != 8 && origin_encoding != 16 && origin_encoding != 32) - return false; - // if not UTF8, I need a conversion function to return proper UTF8 - if (origin_encoding != 8 && !ConvertFunction) - return false; - - if (!options.GetStream()) - return false; - - uint32_t sourceSize = options.GetSourceSize(); - bool needs_zero_terminator = options.GetNeedsZeroTermination(); - - bool is_truncated = false; - const auto max_size = process_sp->GetTarget().GetMaximumSizeOfStringSummary(); - - if (!sourceSize) - { - sourceSize = max_size; - needs_zero_terminator = true; - } - else if (!options.GetIgnoreMaxLength()) - { - if (sourceSize > max_size) - { - sourceSize = max_size; - is_truncated = true; - } +template <typename SourceDataType> +static bool ReadUTFBufferAndDumpToStream( + const StringPrinter::ReadStringAndDumpToStreamOptions &options, + ConversionResult (*ConvertFunction)(const SourceDataType **, + const SourceDataType *, UTF8 **, UTF8 *, + ConversionFlags)) { + assert(options.GetStream() && "need a Stream to print the string to"); + + if (options.GetLocation() == 0 || + options.GetLocation() == LLDB_INVALID_ADDRESS) + return false; + + lldb::ProcessSP process_sp(options.GetProcessSP()); + + if (!process_sp) + return false; + + const int type_width = sizeof(SourceDataType); + const int origin_encoding = 8 * type_width; + if (origin_encoding != 8 && origin_encoding != 16 && origin_encoding != 32) + return false; + // if not UTF8, I need a conversion function to return proper UTF8 + if (origin_encoding != 8 && !ConvertFunction) + return false; + + if (!options.GetStream()) + return false; + + uint32_t sourceSize = options.GetSourceSize(); + bool needs_zero_terminator = options.GetNeedsZeroTermination(); + + bool is_truncated = false; + const auto max_size = process_sp->GetTarget().GetMaximumSizeOfStringSummary(); + + if (!sourceSize) { + sourceSize = max_size; + needs_zero_terminator = true; + } else if (!options.GetIgnoreMaxLength()) { + if (sourceSize > max_size) { + sourceSize = max_size; + is_truncated = true; } + } - const int bufferSPSize = sourceSize * type_width; + const int bufferSPSize = sourceSize * type_width; - lldb::DataBufferSP buffer_sp(new DataBufferHeap(bufferSPSize,0)); + lldb::DataBufferSP buffer_sp(new DataBufferHeap(bufferSPSize, 0)); - if (!buffer_sp->GetBytes()) - return false; + if (!buffer_sp->GetBytes()) + return false; - Error error; - char *buffer = reinterpret_cast<char *>(buffer_sp->GetBytes()); + Error error; + char *buffer = reinterpret_cast<char *>(buffer_sp->GetBytes()); - if (needs_zero_terminator) - process_sp->ReadStringFromMemory(options.GetLocation(), buffer, bufferSPSize, error, type_width); - else - process_sp->ReadMemoryFromInferior(options.GetLocation(), (char*)buffer_sp->GetBytes(), bufferSPSize, error); + if (needs_zero_terminator) + process_sp->ReadStringFromMemory(options.GetLocation(), buffer, + bufferSPSize, error, type_width); + else + process_sp->ReadMemoryFromInferior(options.GetLocation(), + (char *)buffer_sp->GetBytes(), + bufferSPSize, error); - if (error.Fail()) - { - options.GetStream()->Printf("unable to read data"); - return true; - } + if (error.Fail()) { + options.GetStream()->Printf("unable to read data"); + return true; + } + + DataExtractor data(buffer_sp, process_sp->GetByteOrder(), + process_sp->GetAddressByteSize()); - DataExtractor data(buffer_sp, process_sp->GetByteOrder(), process_sp->GetAddressByteSize()); - - StringPrinter::ReadBufferAndDumpToStreamOptions dump_options(options); - dump_options.SetData(data); - dump_options.SetSourceSize(sourceSize); - dump_options.SetIsTruncated(is_truncated); + StringPrinter::ReadBufferAndDumpToStreamOptions dump_options(options); + dump_options.SetData(data); + dump_options.SetSourceSize(sourceSize); + dump_options.SetIsTruncated(is_truncated); - return DumpUTFBufferToStream(ConvertFunction, dump_options); + return DumpUTFBufferToStream(ConvertFunction, dump_options); } template <> -bool -StringPrinter::ReadStringAndDumpToStream<StringPrinter::StringElementType::UTF8> (const ReadStringAndDumpToStreamOptions& options) -{ - return ReadUTFBufferAndDumpToStream<UTF8>(options, - nullptr); +bool StringPrinter::ReadStringAndDumpToStream< + StringPrinter::StringElementType::UTF8>( + const ReadStringAndDumpToStreamOptions &options) { + return ReadUTFBufferAndDumpToStream<UTF8>(options, nullptr); } template <> -bool -StringPrinter::ReadStringAndDumpToStream<StringPrinter::StringElementType::UTF16> (const ReadStringAndDumpToStreamOptions& options) -{ - return ReadUTFBufferAndDumpToStream<UTF16>(options, - ConvertUTF16toUTF8); +bool StringPrinter::ReadStringAndDumpToStream< + StringPrinter::StringElementType::UTF16>( + const ReadStringAndDumpToStreamOptions &options) { + return ReadUTFBufferAndDumpToStream<UTF16>(options, ConvertUTF16toUTF8); } template <> -bool -StringPrinter::ReadStringAndDumpToStream<StringPrinter::StringElementType::UTF32> (const ReadStringAndDumpToStreamOptions& options) -{ - return ReadUTFBufferAndDumpToStream<UTF32>(options, - ConvertUTF32toUTF8); +bool StringPrinter::ReadStringAndDumpToStream< + StringPrinter::StringElementType::UTF32>( + const ReadStringAndDumpToStreamOptions &options) { + return ReadUTFBufferAndDumpToStream<UTF32>(options, ConvertUTF32toUTF8); } template <> -bool -StringPrinter::ReadBufferAndDumpToStream<StringPrinter::StringElementType::UTF8> (const ReadBufferAndDumpToStreamOptions& options) -{ - assert(options.GetStream() && "need a Stream to print the string to"); +bool StringPrinter::ReadBufferAndDumpToStream< + StringPrinter::StringElementType::UTF8>( + const ReadBufferAndDumpToStreamOptions &options) { + assert(options.GetStream() && "need a Stream to print the string to"); - return DumpUTFBufferToStream<UTF8>(nullptr, options); + return DumpUTFBufferToStream<UTF8>(nullptr, options); } template <> -bool -StringPrinter::ReadBufferAndDumpToStream<StringPrinter::StringElementType::ASCII> (const ReadBufferAndDumpToStreamOptions& options) -{ - // treat ASCII the same as UTF8 - // FIXME: can we optimize ASCII some more? - return ReadBufferAndDumpToStream<StringElementType::UTF8>(options); +bool StringPrinter::ReadBufferAndDumpToStream< + StringPrinter::StringElementType::ASCII>( + const ReadBufferAndDumpToStreamOptions &options) { + // treat ASCII the same as UTF8 + // FIXME: can we optimize ASCII some more? + return ReadBufferAndDumpToStream<StringElementType::UTF8>(options); } template <> -bool -StringPrinter::ReadBufferAndDumpToStream<StringPrinter::StringElementType::UTF16> (const ReadBufferAndDumpToStreamOptions& options) -{ - assert(options.GetStream() && "need a Stream to print the string to"); +bool StringPrinter::ReadBufferAndDumpToStream< + StringPrinter::StringElementType::UTF16>( + const ReadBufferAndDumpToStreamOptions &options) { + assert(options.GetStream() && "need a Stream to print the string to"); - return DumpUTFBufferToStream(ConvertUTF16toUTF8, options); + return DumpUTFBufferToStream(ConvertUTF16toUTF8, options); } template <> -bool -StringPrinter::ReadBufferAndDumpToStream<StringPrinter::StringElementType::UTF32> (const ReadBufferAndDumpToStreamOptions& options) -{ - assert(options.GetStream() && "need a Stream to print the string to"); +bool StringPrinter::ReadBufferAndDumpToStream< + StringPrinter::StringElementType::UTF32>( + const ReadBufferAndDumpToStreamOptions &options) { + assert(options.GetStream() && "need a Stream to print the string to"); - return DumpUTFBufferToStream(ConvertUTF32toUTF8, options); + return DumpUTFBufferToStream(ConvertUTF32toUTF8, options); } } // namespace formatters diff --git a/lldb/source/DataFormatters/TypeCategory.cpp b/lldb/source/DataFormatters/TypeCategory.cpp index 9df3ec6721f..5f4863a7c5f 100644 --- a/lldb/source/DataFormatters/TypeCategory.cpp +++ b/lldb/source/DataFormatters/TypeCategory.cpp @@ -1,4 +1,5 @@ -//===-- TypeCategory.cpp -------------------------------------------*- C++ -*-===// +//===-- TypeCategory.cpp -------------------------------------------*- C++ +//-*-===// // // The LLVM Compiler Infrastructure // @@ -18,690 +19,626 @@ using namespace lldb; using namespace lldb_private; -TypeCategoryImpl::TypeCategoryImpl(IFormatChangeListener *clist, ConstString name, - std::initializer_list<lldb::LanguageType> langs) +TypeCategoryImpl::TypeCategoryImpl( + IFormatChangeListener *clist, ConstString name, + std::initializer_list<lldb::LanguageType> langs) : m_format_cont("format", "regex-format", clist), m_summary_cont("summary", "regex-summary", clist), m_filter_cont("filter", "regex-filter", clist), #ifndef LLDB_DISABLE_PYTHON m_synth_cont("synth", "regex-synth", clist), #endif - m_validator_cont("validator", "regex-validator", clist), - m_enabled(false), - m_change_listener(clist), - m_mutex(), - m_name(name), - m_languages() -{ - for (const lldb::LanguageType lang : langs) - AddLanguage(lang); -} - -static bool -IsApplicable(lldb::LanguageType category_lang, - lldb::LanguageType valobj_lang) -{ - switch (category_lang) - { - // these are not languages that LLDB would ordinarily deal with - // only allow an exact equality here, since we really don't know - // any better - case eLanguageTypeAda83: - case eLanguageTypeCobol74: - case eLanguageTypeCobol85: - case eLanguageTypeFortran77: - case eLanguageTypeFortran90: - case eLanguageTypePascal83: - case eLanguageTypeModula2: - case eLanguageTypeJava: - case eLanguageTypeAda95: - case eLanguageTypeFortran95: - case eLanguageTypePLI: - case eLanguageTypeUPC: - case eLanguageTypeD: - case eLanguageTypePython: - return category_lang == valobj_lang; - - // the C family, we consider it as one - case eLanguageTypeC89: - case eLanguageTypeC: - case eLanguageTypeC99: - return valobj_lang == eLanguageTypeC89 || - valobj_lang == eLanguageTypeC || - valobj_lang == eLanguageTypeC99; - - // ObjC knows about C and itself - case eLanguageTypeObjC: - return valobj_lang == eLanguageTypeC89 || - valobj_lang == eLanguageTypeC || - valobj_lang == eLanguageTypeC99 || - valobj_lang == eLanguageTypeObjC; - - // C++ knows about C and C++ - case eLanguageTypeC_plus_plus: - return valobj_lang == eLanguageTypeC89 || - valobj_lang == eLanguageTypeC || - valobj_lang == eLanguageTypeC99 || - valobj_lang == eLanguageTypeC_plus_plus; - - // ObjC++ knows about C,C++,ObjC and ObjC++ - case eLanguageTypeObjC_plus_plus: - return valobj_lang == eLanguageTypeC89 || - valobj_lang == eLanguageTypeC || - valobj_lang == eLanguageTypeC99 || - valobj_lang == eLanguageTypeC_plus_plus || - valobj_lang == eLanguageTypeObjC; - - default: - case eLanguageTypeUnknown: - return true; - } -} - -bool -TypeCategoryImpl::IsApplicable (ValueObject& valobj) -{ - lldb::LanguageType valobj_lang = valobj.GetObjectRuntimeLanguage(); - for (size_t idx = 0; - idx < GetNumLanguages(); - idx++) - { - const lldb::LanguageType category_lang = GetLanguageAtIndex(idx); - if (::IsApplicable(category_lang,valobj_lang)) - return true; - } + m_validator_cont("validator", "regex-validator", clist), m_enabled(false), + m_change_listener(clist), m_mutex(), m_name(name), m_languages() { + for (const lldb::LanguageType lang : langs) + AddLanguage(lang); +} + +static bool IsApplicable(lldb::LanguageType category_lang, + lldb::LanguageType valobj_lang) { + switch (category_lang) { + // these are not languages that LLDB would ordinarily deal with + // only allow an exact equality here, since we really don't know + // any better + case eLanguageTypeAda83: + case eLanguageTypeCobol74: + case eLanguageTypeCobol85: + case eLanguageTypeFortran77: + case eLanguageTypeFortran90: + case eLanguageTypePascal83: + case eLanguageTypeModula2: + case eLanguageTypeJava: + case eLanguageTypeAda95: + case eLanguageTypeFortran95: + case eLanguageTypePLI: + case eLanguageTypeUPC: + case eLanguageTypeD: + case eLanguageTypePython: + return category_lang == valobj_lang; + + // the C family, we consider it as one + case eLanguageTypeC89: + case eLanguageTypeC: + case eLanguageTypeC99: + return valobj_lang == eLanguageTypeC89 || valobj_lang == eLanguageTypeC || + valobj_lang == eLanguageTypeC99; + + // ObjC knows about C and itself + case eLanguageTypeObjC: + return valobj_lang == eLanguageTypeC89 || valobj_lang == eLanguageTypeC || + valobj_lang == eLanguageTypeC99 || valobj_lang == eLanguageTypeObjC; + + // C++ knows about C and C++ + case eLanguageTypeC_plus_plus: + return valobj_lang == eLanguageTypeC89 || valobj_lang == eLanguageTypeC || + valobj_lang == eLanguageTypeC99 || + valobj_lang == eLanguageTypeC_plus_plus; + + // ObjC++ knows about C,C++,ObjC and ObjC++ + case eLanguageTypeObjC_plus_plus: + return valobj_lang == eLanguageTypeC89 || valobj_lang == eLanguageTypeC || + valobj_lang == eLanguageTypeC99 || + valobj_lang == eLanguageTypeC_plus_plus || + valobj_lang == eLanguageTypeObjC; + + default: + case eLanguageTypeUnknown: + return true; + } +} + +bool TypeCategoryImpl::IsApplicable(ValueObject &valobj) { + lldb::LanguageType valobj_lang = valobj.GetObjectRuntimeLanguage(); + for (size_t idx = 0; idx < GetNumLanguages(); idx++) { + const lldb::LanguageType category_lang = GetLanguageAtIndex(idx); + if (::IsApplicable(category_lang, valobj_lang)) + return true; + } + return false; +} + +size_t TypeCategoryImpl::GetNumLanguages() { + if (m_languages.empty()) + return 1; + return m_languages.size(); +} + +lldb::LanguageType TypeCategoryImpl::GetLanguageAtIndex(size_t idx) { + if (m_languages.empty()) + return lldb::eLanguageTypeUnknown; + return m_languages[idx]; +} + +void TypeCategoryImpl::AddLanguage(lldb::LanguageType lang) { + m_languages.push_back(lang); +} + +bool TypeCategoryImpl::HasLanguage(lldb::LanguageType lang) { + const auto iter = std::find(m_languages.begin(), m_languages.end(), lang), + end = m_languages.end(); + return (iter != end); +} + +bool TypeCategoryImpl::Get(ValueObject &valobj, + const FormattersMatchVector &candidates, + lldb::TypeFormatImplSP &entry, uint32_t *reason) { + if (!IsEnabled() || !IsApplicable(valobj)) return false; -} + if (GetTypeFormatsContainer()->Get(candidates, entry, reason)) + return true; + bool regex = GetRegexTypeFormatsContainer()->Get(candidates, entry, reason); + if (regex && reason) + *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionSummary; + return regex; +} + +bool TypeCategoryImpl::Get(ValueObject &valobj, + const FormattersMatchVector &candidates, + lldb::TypeSummaryImplSP &entry, uint32_t *reason) { + if (!IsEnabled() || !IsApplicable(valobj)) + return false; + if (GetTypeSummariesContainer()->Get(candidates, entry, reason)) + return true; + bool regex = GetRegexTypeSummariesContainer()->Get(candidates, entry, reason); + if (regex && reason) + *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionSummary; + return regex; +} + +bool TypeCategoryImpl::Get(ValueObject &valobj, + const FormattersMatchVector &candidates, + lldb::SyntheticChildrenSP &entry, uint32_t *reason) { + if (!IsEnabled() || !IsApplicable(valobj)) + return false; + TypeFilterImpl::SharedPointer filter_sp; + uint32_t reason_filter = 0; + bool regex_filter = false; + // first find both Filter and Synth, and then check which is most recent + + if (!GetTypeFiltersContainer()->Get(candidates, filter_sp, &reason_filter)) + regex_filter = GetRegexTypeFiltersContainer()->Get(candidates, filter_sp, + &reason_filter); -size_t -TypeCategoryImpl::GetNumLanguages () -{ - if (m_languages.empty()) - return 1; - return m_languages.size(); -} - -lldb::LanguageType -TypeCategoryImpl::GetLanguageAtIndex (size_t idx) -{ - if (m_languages.empty()) - return lldb::eLanguageTypeUnknown; - return m_languages[idx]; -} - -void -TypeCategoryImpl::AddLanguage (lldb::LanguageType lang) -{ - m_languages.push_back(lang); -} - -bool -TypeCategoryImpl::HasLanguage (lldb::LanguageType lang) -{ - const auto iter = std::find(m_languages.begin(), m_languages.end(), lang), - end = m_languages.end(); - return (iter != end); -} - -bool -TypeCategoryImpl::Get (ValueObject& valobj, - const FormattersMatchVector& candidates, - lldb::TypeFormatImplSP& entry, - uint32_t* reason) -{ - if (!IsEnabled() || !IsApplicable(valobj)) - return false; - if (GetTypeFormatsContainer()->Get(candidates, entry, reason)) - return true; - bool regex = GetRegexTypeFormatsContainer()->Get(candidates, entry, reason); - if (regex && reason) - *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionSummary; - return regex; -} - -bool -TypeCategoryImpl::Get (ValueObject& valobj, - const FormattersMatchVector& candidates, - lldb::TypeSummaryImplSP& entry, - uint32_t* reason) -{ - if (!IsEnabled() || !IsApplicable(valobj)) - return false; - if (GetTypeSummariesContainer()->Get(candidates, entry, reason)) - return true; - bool regex = GetRegexTypeSummariesContainer()->Get(candidates, entry, reason); - if (regex && reason) - *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionSummary; - return regex; -} - -bool -TypeCategoryImpl::Get (ValueObject& valobj, - const FormattersMatchVector& candidates, - lldb::SyntheticChildrenSP& entry, - uint32_t* reason) -{ - if (!IsEnabled() || !IsApplicable(valobj)) - return false; - TypeFilterImpl::SharedPointer filter_sp; - uint32_t reason_filter = 0; - bool regex_filter = false; - // first find both Filter and Synth, and then check which is most recent - - if (!GetTypeFiltersContainer()->Get(candidates, filter_sp, &reason_filter)) - regex_filter = GetRegexTypeFiltersContainer()->Get (candidates, filter_sp, &reason_filter); - #ifndef LLDB_DISABLE_PYTHON - bool regex_synth = false; - uint32_t reason_synth = 0; - bool pick_synth = false; - ScriptedSyntheticChildren::SharedPointer synth; - if (!GetTypeSyntheticsContainer()->Get(candidates, synth, &reason_synth)) - regex_synth = GetRegexTypeSyntheticsContainer()->Get (candidates, synth, &reason_synth); - if (!filter_sp.get() && !synth.get()) - return false; - else if (!filter_sp.get() && synth.get()) - pick_synth = true; - - else if (filter_sp.get() && !synth.get()) - pick_synth = false; - - else /*if (filter_sp.get() && synth.get())*/ - { - if (filter_sp->GetRevision() > synth->GetRevision()) - pick_synth = false; - else - pick_synth = true; - } - if (pick_synth) - { - if (regex_synth && reason) - *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionFilter; - entry = synth; - return true; - } + bool regex_synth = false; + uint32_t reason_synth = 0; + bool pick_synth = false; + ScriptedSyntheticChildren::SharedPointer synth; + if (!GetTypeSyntheticsContainer()->Get(candidates, synth, &reason_synth)) + regex_synth = GetRegexTypeSyntheticsContainer()->Get(candidates, synth, + &reason_synth); + if (!filter_sp.get() && !synth.get()) + return false; + else if (!filter_sp.get() && synth.get()) + pick_synth = true; + + else if (filter_sp.get() && !synth.get()) + pick_synth = false; + + else /*if (filter_sp.get() && synth.get())*/ + { + if (filter_sp->GetRevision() > synth->GetRevision()) + pick_synth = false; else - { - if (regex_filter && reason) - *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionFilter; - entry = filter_sp; - return true; - } - + pick_synth = true; + } + if (pick_synth) { + if (regex_synth && reason) + *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionFilter; + entry = synth; + return true; + } else { + if (regex_filter && reason) + *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionFilter; + entry = filter_sp; + return true; + } + #else - if (filter_sp) - { - entry = filter_sp; - return true; - } + if (filter_sp) { + entry = filter_sp; + return true; + } #endif - - return false; + + return false; } -bool -TypeCategoryImpl::Get (ValueObject& valobj, - const FormattersMatchVector& candidates, - lldb::TypeValidatorImplSP& entry, - uint32_t* reason) -{ - if (!IsEnabled()) - return false; - if (GetTypeValidatorsContainer()->Get(candidates, entry, reason)) - return true; - bool regex = GetRegexTypeValidatorsContainer()->Get(candidates, entry, reason); - if (regex && reason) - *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionSummary; - return regex; -} - -void -TypeCategoryImpl::Clear (FormatCategoryItems items) -{ - if ( (items & eFormatCategoryItemValue) == eFormatCategoryItemValue ) - GetTypeFormatsContainer()->Clear(); - if ( (items & eFormatCategoryItemRegexValue) == eFormatCategoryItemRegexValue ) - GetRegexTypeFormatsContainer()->Clear(); - - if ( (items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary ) - GetTypeSummariesContainer()->Clear(); - if ( (items & eFormatCategoryItemRegexSummary) == eFormatCategoryItemRegexSummary ) - GetRegexTypeSummariesContainer()->Clear(); - - if ( (items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter ) - GetTypeFiltersContainer()->Clear(); - if ( (items & eFormatCategoryItemRegexFilter) == eFormatCategoryItemRegexFilter ) - GetRegexTypeFiltersContainer()->Clear(); +bool TypeCategoryImpl::Get(ValueObject &valobj, + const FormattersMatchVector &candidates, + lldb::TypeValidatorImplSP &entry, uint32_t *reason) { + if (!IsEnabled()) + return false; + if (GetTypeValidatorsContainer()->Get(candidates, entry, reason)) + return true; + bool regex = + GetRegexTypeValidatorsContainer()->Get(candidates, entry, reason); + if (regex && reason) + *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionSummary; + return regex; +} + +void TypeCategoryImpl::Clear(FormatCategoryItems items) { + if ((items & eFormatCategoryItemValue) == eFormatCategoryItemValue) + GetTypeFormatsContainer()->Clear(); + if ((items & eFormatCategoryItemRegexValue) == eFormatCategoryItemRegexValue) + GetRegexTypeFormatsContainer()->Clear(); + + if ((items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary) + GetTypeSummariesContainer()->Clear(); + if ((items & eFormatCategoryItemRegexSummary) == + eFormatCategoryItemRegexSummary) + GetRegexTypeSummariesContainer()->Clear(); + + if ((items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter) + GetTypeFiltersContainer()->Clear(); + if ((items & eFormatCategoryItemRegexFilter) == + eFormatCategoryItemRegexFilter) + GetRegexTypeFiltersContainer()->Clear(); #ifndef LLDB_DISABLE_PYTHON - if ( (items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth ) - GetTypeSyntheticsContainer()->Clear(); - if ( (items & eFormatCategoryItemRegexSynth) == eFormatCategoryItemRegexSynth ) - GetRegexTypeSyntheticsContainer()->Clear(); + if ((items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth) + GetTypeSyntheticsContainer()->Clear(); + if ((items & eFormatCategoryItemRegexSynth) == eFormatCategoryItemRegexSynth) + GetRegexTypeSyntheticsContainer()->Clear(); #endif - - if ( (items & eFormatCategoryItemValidator) == eFormatCategoryItemValidator ) - GetTypeValidatorsContainer()->Clear(); - if ( (items & eFormatCategoryItemRegexValidator) == eFormatCategoryItemRegexValidator ) - GetRegexTypeValidatorsContainer()->Clear(); -} - -bool -TypeCategoryImpl::Delete (ConstString name, - FormatCategoryItems items) -{ - bool success = false; - - if ( (items & eFormatCategoryItemValue) == eFormatCategoryItemValue ) - success = GetTypeFormatsContainer()->Delete(name) || success; - if ( (items & eFormatCategoryItemRegexValue) == eFormatCategoryItemRegexValue ) - success = GetRegexTypeFormatsContainer()->Delete(name) || success; - - if ( (items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary ) - success = GetTypeSummariesContainer()->Delete(name) || success; - if ( (items & eFormatCategoryItemRegexSummary) == eFormatCategoryItemRegexSummary ) - success = GetRegexTypeSummariesContainer()->Delete(name) || success; - - if ( (items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter ) - success = GetTypeFiltersContainer()->Delete(name) || success; - if ( (items & eFormatCategoryItemRegexFilter) == eFormatCategoryItemRegexFilter ) - success = GetRegexTypeFiltersContainer()->Delete(name) || success; + + if ((items & eFormatCategoryItemValidator) == eFormatCategoryItemValidator) + GetTypeValidatorsContainer()->Clear(); + if ((items & eFormatCategoryItemRegexValidator) == + eFormatCategoryItemRegexValidator) + GetRegexTypeValidatorsContainer()->Clear(); +} + +bool TypeCategoryImpl::Delete(ConstString name, FormatCategoryItems items) { + bool success = false; + + if ((items & eFormatCategoryItemValue) == eFormatCategoryItemValue) + success = GetTypeFormatsContainer()->Delete(name) || success; + if ((items & eFormatCategoryItemRegexValue) == eFormatCategoryItemRegexValue) + success = GetRegexTypeFormatsContainer()->Delete(name) || success; + + if ((items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary) + success = GetTypeSummariesContainer()->Delete(name) || success; + if ((items & eFormatCategoryItemRegexSummary) == + eFormatCategoryItemRegexSummary) + success = GetRegexTypeSummariesContainer()->Delete(name) || success; + + if ((items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter) + success = GetTypeFiltersContainer()->Delete(name) || success; + if ((items & eFormatCategoryItemRegexFilter) == + eFormatCategoryItemRegexFilter) + success = GetRegexTypeFiltersContainer()->Delete(name) || success; #ifndef LLDB_DISABLE_PYTHON - if ( (items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth ) - success = GetTypeSyntheticsContainer()->Delete(name) || success; - if ( (items & eFormatCategoryItemRegexSynth) == eFormatCategoryItemRegexSynth ) - success = GetRegexTypeSyntheticsContainer()->Delete(name) || success; + if ((items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth) + success = GetTypeSyntheticsContainer()->Delete(name) || success; + if ((items & eFormatCategoryItemRegexSynth) == eFormatCategoryItemRegexSynth) + success = GetRegexTypeSyntheticsContainer()->Delete(name) || success; #endif - - if ( (items & eFormatCategoryItemValidator) == eFormatCategoryItemValidator ) - success = GetTypeValidatorsContainer()->Delete(name) || success; - if ( (items & eFormatCategoryItemRegexValidator) == eFormatCategoryItemRegexValidator ) - success = GetRegexTypeValidatorsContainer()->Delete(name) || success; - - return success; -} - -uint32_t -TypeCategoryImpl::GetCount (FormatCategoryItems items) -{ - uint32_t count = 0; - - if ( (items & eFormatCategoryItemValue) == eFormatCategoryItemValue ) - count += GetTypeFormatsContainer()->GetCount(); - if ( (items & eFormatCategoryItemRegexValue) == eFormatCategoryItemRegexValue ) - count += GetRegexTypeFormatsContainer()->GetCount(); - - if ( (items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary ) - count += GetTypeSummariesContainer()->GetCount(); - if ( (items & eFormatCategoryItemRegexSummary) == eFormatCategoryItemRegexSummary ) - count += GetRegexTypeSummariesContainer()->GetCount(); - - if ( (items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter ) - count += GetTypeFiltersContainer()->GetCount(); - if ( (items & eFormatCategoryItemRegexFilter) == eFormatCategoryItemRegexFilter ) - count += GetRegexTypeFiltersContainer()->GetCount(); + + if ((items & eFormatCategoryItemValidator) == eFormatCategoryItemValidator) + success = GetTypeValidatorsContainer()->Delete(name) || success; + if ((items & eFormatCategoryItemRegexValidator) == + eFormatCategoryItemRegexValidator) + success = GetRegexTypeValidatorsContainer()->Delete(name) || success; + + return success; +} + +uint32_t TypeCategoryImpl::GetCount(FormatCategoryItems items) { + uint32_t count = 0; + + if ((items & eFormatCategoryItemValue) == eFormatCategoryItemValue) + count += GetTypeFormatsContainer()->GetCount(); + if ((items & eFormatCategoryItemRegexValue) == eFormatCategoryItemRegexValue) + count += GetRegexTypeFormatsContainer()->GetCount(); + + if ((items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary) + count += GetTypeSummariesContainer()->GetCount(); + if ((items & eFormatCategoryItemRegexSummary) == + eFormatCategoryItemRegexSummary) + count += GetRegexTypeSummariesContainer()->GetCount(); + + if ((items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter) + count += GetTypeFiltersContainer()->GetCount(); + if ((items & eFormatCategoryItemRegexFilter) == + eFormatCategoryItemRegexFilter) + count += GetRegexTypeFiltersContainer()->GetCount(); #ifndef LLDB_DISABLE_PYTHON - if ( (items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth ) - count += GetTypeSyntheticsContainer()->GetCount(); - if ( (items & eFormatCategoryItemRegexSynth) == eFormatCategoryItemRegexSynth ) - count += GetRegexTypeSyntheticsContainer()->GetCount(); + if ((items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth) + count += GetTypeSyntheticsContainer()->GetCount(); + if ((items & eFormatCategoryItemRegexSynth) == eFormatCategoryItemRegexSynth) + count += GetRegexTypeSyntheticsContainer()->GetCount(); #endif - - if ( (items & eFormatCategoryItemValidator) == eFormatCategoryItemValidator ) - count += GetTypeValidatorsContainer()->GetCount(); - if ( (items & eFormatCategoryItemRegexValidator) == eFormatCategoryItemRegexValidator ) - count += GetRegexTypeValidatorsContainer()->GetCount(); - - return count; -} - -bool -TypeCategoryImpl::AnyMatches(ConstString type_name, - FormatCategoryItems items, - bool only_enabled, - const char** matching_category, - FormatCategoryItems* matching_type) -{ - if (!IsEnabled() && only_enabled) - return false; - - lldb::TypeFormatImplSP format_sp; - lldb::TypeSummaryImplSP summary_sp; - TypeFilterImpl::SharedPointer filter_sp; + + if ((items & eFormatCategoryItemValidator) == eFormatCategoryItemValidator) + count += GetTypeValidatorsContainer()->GetCount(); + if ((items & eFormatCategoryItemRegexValidator) == + eFormatCategoryItemRegexValidator) + count += GetRegexTypeValidatorsContainer()->GetCount(); + + return count; +} + +bool TypeCategoryImpl::AnyMatches(ConstString type_name, + FormatCategoryItems items, bool only_enabled, + const char **matching_category, + FormatCategoryItems *matching_type) { + if (!IsEnabled() && only_enabled) + return false; + + lldb::TypeFormatImplSP format_sp; + lldb::TypeSummaryImplSP summary_sp; + TypeFilterImpl::SharedPointer filter_sp; #ifndef LLDB_DISABLE_PYTHON - ScriptedSyntheticChildren::SharedPointer synth_sp; + ScriptedSyntheticChildren::SharedPointer synth_sp; #endif - TypeValidatorImpl::SharedPointer validator_sp; - - if ( (items & eFormatCategoryItemValue) == eFormatCategoryItemValue ) - { - if (GetTypeFormatsContainer()->Get(type_name, format_sp)) - { - if (matching_category) - *matching_category = m_name.GetCString(); - if (matching_type) - *matching_type = eFormatCategoryItemValue; - return true; - } + TypeValidatorImpl::SharedPointer validator_sp; + + if ((items & eFormatCategoryItemValue) == eFormatCategoryItemValue) { + if (GetTypeFormatsContainer()->Get(type_name, format_sp)) { + if (matching_category) + *matching_category = m_name.GetCString(); + if (matching_type) + *matching_type = eFormatCategoryItemValue; + return true; } - if ( (items & eFormatCategoryItemRegexValue) == eFormatCategoryItemRegexValue ) - { - if (GetRegexTypeFormatsContainer()->Get(type_name, format_sp)) - { - if (matching_category) - *matching_category = m_name.GetCString(); - if (matching_type) - *matching_type = eFormatCategoryItemRegexValue; - return true; - } + } + if ((items & eFormatCategoryItemRegexValue) == + eFormatCategoryItemRegexValue) { + if (GetRegexTypeFormatsContainer()->Get(type_name, format_sp)) { + if (matching_category) + *matching_category = m_name.GetCString(); + if (matching_type) + *matching_type = eFormatCategoryItemRegexValue; + return true; } - - if ( (items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary ) - { - if (GetTypeSummariesContainer()->Get(type_name, summary_sp)) - { - if (matching_category) - *matching_category = m_name.GetCString(); - if (matching_type) - *matching_type = eFormatCategoryItemSummary; - return true; - } + } + + if ((items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary) { + if (GetTypeSummariesContainer()->Get(type_name, summary_sp)) { + if (matching_category) + *matching_category = m_name.GetCString(); + if (matching_type) + *matching_type = eFormatCategoryItemSummary; + return true; } - if ( (items & eFormatCategoryItemRegexSummary) == eFormatCategoryItemRegexSummary ) - { - if (GetRegexTypeSummariesContainer()->Get(type_name, summary_sp)) - { - if (matching_category) - *matching_category = m_name.GetCString(); - if (matching_type) - *matching_type = eFormatCategoryItemRegexSummary; - return true; - } + } + if ((items & eFormatCategoryItemRegexSummary) == + eFormatCategoryItemRegexSummary) { + if (GetRegexTypeSummariesContainer()->Get(type_name, summary_sp)) { + if (matching_category) + *matching_category = m_name.GetCString(); + if (matching_type) + *matching_type = eFormatCategoryItemRegexSummary; + return true; } - - if ( (items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter ) - { - if (GetTypeFiltersContainer()->Get(type_name, filter_sp)) - { - if (matching_category) - *matching_category = m_name.GetCString(); - if (matching_type) - *matching_type = eFormatCategoryItemFilter; - return true; - } + } + + if ((items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter) { + if (GetTypeFiltersContainer()->Get(type_name, filter_sp)) { + if (matching_category) + *matching_category = m_name.GetCString(); + if (matching_type) + *matching_type = eFormatCategoryItemFilter; + return true; } - if ( (items & eFormatCategoryItemRegexFilter) == eFormatCategoryItemRegexFilter ) - { - if (GetRegexTypeFiltersContainer()->Get(type_name, filter_sp)) - { - if (matching_category) - *matching_category = m_name.GetCString(); - if (matching_type) - *matching_type = eFormatCategoryItemRegexFilter; - return true; - } + } + if ((items & eFormatCategoryItemRegexFilter) == + eFormatCategoryItemRegexFilter) { + if (GetRegexTypeFiltersContainer()->Get(type_name, filter_sp)) { + if (matching_category) + *matching_category = m_name.GetCString(); + if (matching_type) + *matching_type = eFormatCategoryItemRegexFilter; + return true; } - + } + #ifndef LLDB_DISABLE_PYTHON - if ( (items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth ) - { - if (GetTypeSyntheticsContainer()->Get(type_name, synth_sp)) - { - if (matching_category) - *matching_category = m_name.GetCString(); - if (matching_type) - *matching_type = eFormatCategoryItemSynth; - return true; - } + if ((items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth) { + if (GetTypeSyntheticsContainer()->Get(type_name, synth_sp)) { + if (matching_category) + *matching_category = m_name.GetCString(); + if (matching_type) + *matching_type = eFormatCategoryItemSynth; + return true; } - if ( (items & eFormatCategoryItemRegexSynth) == eFormatCategoryItemRegexSynth ) - { - if (GetRegexTypeSyntheticsContainer()->Get(type_name, synth_sp)) - { - if (matching_category) - *matching_category = m_name.GetCString(); - if (matching_type) - *matching_type = eFormatCategoryItemRegexSynth; - return true; - } + } + if ((items & eFormatCategoryItemRegexSynth) == + eFormatCategoryItemRegexSynth) { + if (GetRegexTypeSyntheticsContainer()->Get(type_name, synth_sp)) { + if (matching_category) + *matching_category = m_name.GetCString(); + if (matching_type) + *matching_type = eFormatCategoryItemRegexSynth; + return true; } + } #endif - - if ( (items & eFormatCategoryItemValidator) == eFormatCategoryItemValidator ) - { - if (GetTypeValidatorsContainer()->Get(type_name, validator_sp)) - { - if (matching_category) - *matching_category = m_name.GetCString(); - if (matching_type) - *matching_type = eFormatCategoryItemValidator; - return true; - } + + if ((items & eFormatCategoryItemValidator) == eFormatCategoryItemValidator) { + if (GetTypeValidatorsContainer()->Get(type_name, validator_sp)) { + if (matching_category) + *matching_category = m_name.GetCString(); + if (matching_type) + *matching_type = eFormatCategoryItemValidator; + return true; } - if ( (items & eFormatCategoryItemRegexValidator) == eFormatCategoryItemRegexValidator ) - { - if (GetRegexTypeValidatorsContainer()->Get(type_name, validator_sp)) - { - if (matching_category) - *matching_category = m_name.GetCString(); - if (matching_type) - *matching_type = eFormatCategoryItemRegexValidator; - return true; - } + } + if ((items & eFormatCategoryItemRegexValidator) == + eFormatCategoryItemRegexValidator) { + if (GetRegexTypeValidatorsContainer()->Get(type_name, validator_sp)) { + if (matching_category) + *matching_category = m_name.GetCString(); + if (matching_type) + *matching_type = eFormatCategoryItemRegexValidator; + return true; } - - return false; + } + + return false; } TypeCategoryImpl::FormatContainer::MapValueType -TypeCategoryImpl::GetFormatForType (lldb::TypeNameSpecifierImplSP type_sp) -{ - FormatContainer::MapValueType retval; - - if (type_sp) - { - if (type_sp->IsRegex()) - GetRegexTypeFormatsContainer()->GetExact(ConstString(type_sp->GetName()),retval); - else - GetTypeFormatsContainer()->GetExact(ConstString(type_sp->GetName()),retval); - } - - return retval; +TypeCategoryImpl::GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp) { + FormatContainer::MapValueType retval; + + if (type_sp) { + if (type_sp->IsRegex()) + GetRegexTypeFormatsContainer()->GetExact(ConstString(type_sp->GetName()), + retval); + else + GetTypeFormatsContainer()->GetExact(ConstString(type_sp->GetName()), + retval); + } + + return retval; } TypeCategoryImpl::SummaryContainer::MapValueType -TypeCategoryImpl::GetSummaryForType (lldb::TypeNameSpecifierImplSP type_sp) -{ - SummaryContainer::MapValueType retval; - - if (type_sp) - { - if (type_sp->IsRegex()) - GetRegexTypeSummariesContainer()->GetExact(ConstString(type_sp->GetName()),retval); - else - GetTypeSummariesContainer()->GetExact(ConstString(type_sp->GetName()),retval); - } - - return retval; +TypeCategoryImpl::GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp) { + SummaryContainer::MapValueType retval; + + if (type_sp) { + if (type_sp->IsRegex()) + GetRegexTypeSummariesContainer()->GetExact( + ConstString(type_sp->GetName()), retval); + else + GetTypeSummariesContainer()->GetExact(ConstString(type_sp->GetName()), + retval); + } + + return retval; } TypeCategoryImpl::FilterContainer::MapValueType -TypeCategoryImpl::GetFilterForType (lldb::TypeNameSpecifierImplSP type_sp) -{ - FilterContainer::MapValueType retval; - - if (type_sp) - { - if (type_sp->IsRegex()) - GetRegexTypeFiltersContainer()->GetExact(ConstString(type_sp->GetName()),retval); - else - GetTypeFiltersContainer()->GetExact(ConstString(type_sp->GetName()),retval); - } - - return retval; +TypeCategoryImpl::GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp) { + FilterContainer::MapValueType retval; + + if (type_sp) { + if (type_sp->IsRegex()) + GetRegexTypeFiltersContainer()->GetExact(ConstString(type_sp->GetName()), + retval); + else + GetTypeFiltersContainer()->GetExact(ConstString(type_sp->GetName()), + retval); + } + + return retval; } #ifndef LLDB_DISABLE_PYTHON TypeCategoryImpl::SynthContainer::MapValueType -TypeCategoryImpl::GetSyntheticForType (lldb::TypeNameSpecifierImplSP type_sp) -{ - SynthContainer::MapValueType retval; - - if (type_sp) - { - if (type_sp->IsRegex()) - GetRegexTypeSyntheticsContainer()->GetExact(ConstString(type_sp->GetName()),retval); - else - GetTypeSyntheticsContainer()->GetExact(ConstString(type_sp->GetName()),retval); - } - - return retval; +TypeCategoryImpl::GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp) { + SynthContainer::MapValueType retval; + + if (type_sp) { + if (type_sp->IsRegex()) + GetRegexTypeSyntheticsContainer()->GetExact( + ConstString(type_sp->GetName()), retval); + else + GetTypeSyntheticsContainer()->GetExact(ConstString(type_sp->GetName()), + retval); + } + + return retval; } #endif TypeCategoryImpl::ValidatorContainer::MapValueType -TypeCategoryImpl::GetValidatorForType (lldb::TypeNameSpecifierImplSP type_sp) -{ - ValidatorContainer::MapValueType retval; - - if (type_sp) - { - if (type_sp->IsRegex()) - GetRegexTypeValidatorsContainer()->GetExact(ConstString(type_sp->GetName()),retval); - else - GetTypeValidatorsContainer()->GetExact(ConstString(type_sp->GetName()),retval); - } - - return retval; +TypeCategoryImpl::GetValidatorForType(lldb::TypeNameSpecifierImplSP type_sp) { + ValidatorContainer::MapValueType retval; + + if (type_sp) { + if (type_sp->IsRegex()) + GetRegexTypeValidatorsContainer()->GetExact( + ConstString(type_sp->GetName()), retval); + else + GetTypeValidatorsContainer()->GetExact(ConstString(type_sp->GetName()), + retval); + } + + return retval; } lldb::TypeNameSpecifierImplSP -TypeCategoryImpl::GetTypeNameSpecifierForSummaryAtIndex (size_t index) -{ - if (index < GetTypeSummariesContainer()->GetCount()) - return GetTypeSummariesContainer()->GetTypeNameSpecifierAtIndex(index); - else - return GetRegexTypeSummariesContainer()->GetTypeNameSpecifierAtIndex(index-GetTypeSummariesContainer()->GetCount()); +TypeCategoryImpl::GetTypeNameSpecifierForSummaryAtIndex(size_t index) { + if (index < GetTypeSummariesContainer()->GetCount()) + return GetTypeSummariesContainer()->GetTypeNameSpecifierAtIndex(index); + else + return GetRegexTypeSummariesContainer()->GetTypeNameSpecifierAtIndex( + index - GetTypeSummariesContainer()->GetCount()); } TypeCategoryImpl::FormatContainer::MapValueType -TypeCategoryImpl::GetFormatAtIndex (size_t index) -{ - if (index < GetTypeFormatsContainer()->GetCount()) - return GetTypeFormatsContainer()->GetAtIndex(index); - else - return GetRegexTypeFormatsContainer()->GetAtIndex(index-GetTypeFormatsContainer()->GetCount()); +TypeCategoryImpl::GetFormatAtIndex(size_t index) { + if (index < GetTypeFormatsContainer()->GetCount()) + return GetTypeFormatsContainer()->GetAtIndex(index); + else + return GetRegexTypeFormatsContainer()->GetAtIndex( + index - GetTypeFormatsContainer()->GetCount()); } TypeCategoryImpl::SummaryContainer::MapValueType -TypeCategoryImpl::GetSummaryAtIndex (size_t index) -{ - if (index < GetTypeSummariesContainer()->GetCount()) - return GetTypeSummariesContainer()->GetAtIndex(index); - else - return GetRegexTypeSummariesContainer()->GetAtIndex(index-GetTypeSummariesContainer()->GetCount()); +TypeCategoryImpl::GetSummaryAtIndex(size_t index) { + if (index < GetTypeSummariesContainer()->GetCount()) + return GetTypeSummariesContainer()->GetAtIndex(index); + else + return GetRegexTypeSummariesContainer()->GetAtIndex( + index - GetTypeSummariesContainer()->GetCount()); } TypeCategoryImpl::FilterContainer::MapValueType -TypeCategoryImpl::GetFilterAtIndex (size_t index) -{ - if (index < GetTypeFiltersContainer()->GetCount()) - return GetTypeFiltersContainer()->GetAtIndex(index); - else - return GetRegexTypeFiltersContainer()->GetAtIndex(index-GetTypeFiltersContainer()->GetCount()); +TypeCategoryImpl::GetFilterAtIndex(size_t index) { + if (index < GetTypeFiltersContainer()->GetCount()) + return GetTypeFiltersContainer()->GetAtIndex(index); + else + return GetRegexTypeFiltersContainer()->GetAtIndex( + index - GetTypeFiltersContainer()->GetCount()); } lldb::TypeNameSpecifierImplSP -TypeCategoryImpl::GetTypeNameSpecifierForFormatAtIndex (size_t index) -{ - if (index < GetTypeFormatsContainer()->GetCount()) - return GetTypeFormatsContainer()->GetTypeNameSpecifierAtIndex(index); - else - return GetRegexTypeFormatsContainer()->GetTypeNameSpecifierAtIndex(index-GetTypeFormatsContainer()->GetCount()); +TypeCategoryImpl::GetTypeNameSpecifierForFormatAtIndex(size_t index) { + if (index < GetTypeFormatsContainer()->GetCount()) + return GetTypeFormatsContainer()->GetTypeNameSpecifierAtIndex(index); + else + return GetRegexTypeFormatsContainer()->GetTypeNameSpecifierAtIndex( + index - GetTypeFormatsContainer()->GetCount()); } lldb::TypeNameSpecifierImplSP -TypeCategoryImpl::GetTypeNameSpecifierForFilterAtIndex (size_t index) -{ - if (index < GetTypeFiltersContainer()->GetCount()) - return GetTypeFiltersContainer()->GetTypeNameSpecifierAtIndex(index); - else - return GetRegexTypeFiltersContainer()->GetTypeNameSpecifierAtIndex(index-GetTypeFiltersContainer()->GetCount()); +TypeCategoryImpl::GetTypeNameSpecifierForFilterAtIndex(size_t index) { + if (index < GetTypeFiltersContainer()->GetCount()) + return GetTypeFiltersContainer()->GetTypeNameSpecifierAtIndex(index); + else + return GetRegexTypeFiltersContainer()->GetTypeNameSpecifierAtIndex( + index - GetTypeFiltersContainer()->GetCount()); } #ifndef LLDB_DISABLE_PYTHON TypeCategoryImpl::SynthContainer::MapValueType -TypeCategoryImpl::GetSyntheticAtIndex (size_t index) -{ - if (index < GetTypeSyntheticsContainer()->GetCount()) - return GetTypeSyntheticsContainer()->GetAtIndex(index); - else - return GetRegexTypeSyntheticsContainer()->GetAtIndex(index-GetTypeSyntheticsContainer()->GetCount()); +TypeCategoryImpl::GetSyntheticAtIndex(size_t index) { + if (index < GetTypeSyntheticsContainer()->GetCount()) + return GetTypeSyntheticsContainer()->GetAtIndex(index); + else + return GetRegexTypeSyntheticsContainer()->GetAtIndex( + index - GetTypeSyntheticsContainer()->GetCount()); } lldb::TypeNameSpecifierImplSP -TypeCategoryImpl::GetTypeNameSpecifierForSyntheticAtIndex (size_t index) -{ - if (index < GetTypeSyntheticsContainer()->GetCount()) - return GetTypeSyntheticsContainer()->GetTypeNameSpecifierAtIndex(index); - else - return GetRegexTypeSyntheticsContainer()->GetTypeNameSpecifierAtIndex(index - GetTypeSyntheticsContainer()->GetCount()); +TypeCategoryImpl::GetTypeNameSpecifierForSyntheticAtIndex(size_t index) { + if (index < GetTypeSyntheticsContainer()->GetCount()) + return GetTypeSyntheticsContainer()->GetTypeNameSpecifierAtIndex(index); + else + return GetRegexTypeSyntheticsContainer()->GetTypeNameSpecifierAtIndex( + index - GetTypeSyntheticsContainer()->GetCount()); } #endif TypeCategoryImpl::ValidatorContainer::MapValueType -TypeCategoryImpl::GetValidatorAtIndex (size_t index) -{ - if (index < GetTypeValidatorsContainer()->GetCount()) - return GetTypeValidatorsContainer()->GetAtIndex(index); - else - return GetRegexTypeValidatorsContainer()->GetAtIndex(index-GetTypeValidatorsContainer()->GetCount()); +TypeCategoryImpl::GetValidatorAtIndex(size_t index) { + if (index < GetTypeValidatorsContainer()->GetCount()) + return GetTypeValidatorsContainer()->GetAtIndex(index); + else + return GetRegexTypeValidatorsContainer()->GetAtIndex( + index - GetTypeValidatorsContainer()->GetCount()); } lldb::TypeNameSpecifierImplSP -TypeCategoryImpl::GetTypeNameSpecifierForValidatorAtIndex (size_t index) -{ - if (index < GetTypeValidatorsContainer()->GetCount()) - return GetTypeValidatorsContainer()->GetTypeNameSpecifierAtIndex(index); - else - return GetRegexTypeValidatorsContainer()->GetTypeNameSpecifierAtIndex(index - GetTypeValidatorsContainer()->GetCount()); -} - -void -TypeCategoryImpl::Enable (bool value, uint32_t position) -{ - std::lock_guard<std::recursive_mutex> guard(m_mutex); - if ( (m_enabled = value) ) - m_enabled_position = position; - if (m_change_listener) - m_change_listener->Changed(); -} - -std::string -TypeCategoryImpl::GetDescription () -{ - StreamString stream; - stream.Printf("%s (%s", - GetName(), - (IsEnabled() ? "enabled" : "disabled")); - StreamString lang_stream; - lang_stream.Printf(", applicable for language(s): "); - bool print_lang = false; - for (size_t idx = 0; - idx < GetNumLanguages(); - idx++) - { - const lldb::LanguageType lang = GetLanguageAtIndex(idx); - if (lang != lldb::eLanguageTypeUnknown) - print_lang = true; - lang_stream.Printf("%s%s", - Language::GetNameForLanguageType(lang), - idx+1<GetNumLanguages() ? ", " : ""); - } - if (print_lang) - stream.Printf("%s",lang_stream.GetData()); - stream.PutChar(')'); - return stream.GetData(); +TypeCategoryImpl::GetTypeNameSpecifierForValidatorAtIndex(size_t index) { + if (index < GetTypeValidatorsContainer()->GetCount()) + return GetTypeValidatorsContainer()->GetTypeNameSpecifierAtIndex(index); + else + return GetRegexTypeValidatorsContainer()->GetTypeNameSpecifierAtIndex( + index - GetTypeValidatorsContainer()->GetCount()); +} + +void TypeCategoryImpl::Enable(bool value, uint32_t position) { + std::lock_guard<std::recursive_mutex> guard(m_mutex); + if ((m_enabled = value)) + m_enabled_position = position; + if (m_change_listener) + m_change_listener->Changed(); +} + +std::string TypeCategoryImpl::GetDescription() { + StreamString stream; + stream.Printf("%s (%s", GetName(), (IsEnabled() ? "enabled" : "disabled")); + StreamString lang_stream; + lang_stream.Printf(", applicable for language(s): "); + bool print_lang = false; + for (size_t idx = 0; idx < GetNumLanguages(); idx++) { + const lldb::LanguageType lang = GetLanguageAtIndex(idx); + if (lang != lldb::eLanguageTypeUnknown) + print_lang = true; + lang_stream.Printf("%s%s", Language::GetNameForLanguageType(lang), + idx + 1 < GetNumLanguages() ? ", " : ""); + } + if (print_lang) + stream.Printf("%s", lang_stream.GetData()); + stream.PutChar(')'); + return stream.GetData(); } diff --git a/lldb/source/DataFormatters/TypeCategoryMap.cpp b/lldb/source/DataFormatters/TypeCategoryMap.cpp index fc28783e36f..cc85288c23f 100644 --- a/lldb/source/DataFormatters/TypeCategoryMap.cpp +++ b/lldb/source/DataFormatters/TypeCategoryMap.cpp @@ -1,4 +1,5 @@ -//===-- TypeCategoryMap.cpp ----------------------------------------*- C++ -*-===// +//===-- TypeCategoryMap.cpp ----------------------------------------*- C++ +//-*-===// // // The LLVM Compiler Infrastructure // @@ -21,401 +22,361 @@ using namespace lldb; using namespace lldb_private; TypeCategoryMap::TypeCategoryMap(IFormatChangeListener *lst) - : m_map_mutex(), listener(lst), m_map(), m_active_categories() -{ - ConstString default_cs("default"); - lldb::TypeCategoryImplSP default_sp = lldb::TypeCategoryImplSP(new TypeCategoryImpl(listener, default_cs)); - Add(default_cs, default_sp); - Enable(default_cs, First); + : m_map_mutex(), listener(lst), m_map(), m_active_categories() { + ConstString default_cs("default"); + lldb::TypeCategoryImplSP default_sp = + lldb::TypeCategoryImplSP(new TypeCategoryImpl(listener, default_cs)); + Add(default_cs, default_sp); + Enable(default_cs, First); } -void -TypeCategoryMap::Add (KeyType name, const ValueSP& entry) -{ - std::lock_guard<std::recursive_mutex> guard(m_map_mutex); - m_map[name] = entry; - if (listener) - listener->Changed(); -} - -bool -TypeCategoryMap::Delete (KeyType name) -{ - std::lock_guard<std::recursive_mutex> guard(m_map_mutex); - MapIterator iter = m_map.find(name); - if (iter == m_map.end()) - return false; - m_map.erase(name); - Disable(name); - if (listener) - listener->Changed(); - return true; +void TypeCategoryMap::Add(KeyType name, const ValueSP &entry) { + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); + m_map[name] = entry; + if (listener) + listener->Changed(); } -bool -TypeCategoryMap::Enable (KeyType category_name, Position pos) -{ - std::lock_guard<std::recursive_mutex> guard(m_map_mutex); - ValueSP category; - if (!Get(category_name,category)) - return false; - return Enable(category, pos); +bool TypeCategoryMap::Delete(KeyType name) { + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); + MapIterator iter = m_map.find(name); + if (iter == m_map.end()) + return false; + m_map.erase(name); + Disable(name); + if (listener) + listener->Changed(); + return true; } -bool -TypeCategoryMap::Disable (KeyType category_name) -{ - std::lock_guard<std::recursive_mutex> guard(m_map_mutex); - ValueSP category; - if (!Get(category_name,category)) - return false; - return Disable(category); +bool TypeCategoryMap::Enable(KeyType category_name, Position pos) { + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); + ValueSP category; + if (!Get(category_name, category)) + return false; + return Enable(category, pos); } -bool -TypeCategoryMap::Enable (ValueSP category, Position pos) -{ - std::lock_guard<std::recursive_mutex> guard(m_map_mutex); - if (category.get()) - { - Position pos_w = pos; - if (pos == First || m_active_categories.size() == 0) - m_active_categories.push_front(category); - else if (pos == Last || pos == m_active_categories.size()) - m_active_categories.push_back(category); - else if (pos < m_active_categories.size()) - { - ActiveCategoriesList::iterator iter = m_active_categories.begin(); - while (pos_w) - { - pos_w--,iter++; - } - m_active_categories.insert(iter,category); - } - else - return false; - category->Enable(true, - pos); - return true; - } +bool TypeCategoryMap::Disable(KeyType category_name) { + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); + ValueSP category; + if (!Get(category_name, category)) return false; + return Disable(category); } -bool -TypeCategoryMap::Disable (ValueSP category) -{ - std::lock_guard<std::recursive_mutex> guard(m_map_mutex); - if (category.get()) - { - m_active_categories.remove_if(delete_matching_categories(category)); - category->Disable(); - return true; - } - return false; +bool TypeCategoryMap::Enable(ValueSP category, Position pos) { + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); + if (category.get()) { + Position pos_w = pos; + if (pos == First || m_active_categories.size() == 0) + m_active_categories.push_front(category); + else if (pos == Last || pos == m_active_categories.size()) + m_active_categories.push_back(category); + else if (pos < m_active_categories.size()) { + ActiveCategoriesList::iterator iter = m_active_categories.begin(); + while (pos_w) { + pos_w--, iter++; + } + m_active_categories.insert(iter, category); + } else + return false; + category->Enable(true, pos); + return true; + } + return false; } -void -TypeCategoryMap::EnableAllCategories () -{ - std::lock_guard<std::recursive_mutex> guard(m_map_mutex); - std::vector<ValueSP> sorted_categories(m_map.size(), ValueSP()); - MapType::iterator iter = m_map.begin(), end = m_map.end(); - for (; iter != end; ++iter) - { - if (iter->second->IsEnabled()) - continue; - auto pos = iter->second->GetLastEnabledPosition(); - if (pos >= sorted_categories.size()) - { - auto iter = std::find_if(sorted_categories.begin(), - sorted_categories.end(), - [] (const ValueSP& sp) -> bool { - return sp.get() == nullptr; - }); - pos = std::distance(sorted_categories.begin(), iter); - } - sorted_categories.at(pos) = iter->second; - } - decltype(sorted_categories)::iterator viter = sorted_categories.begin(), vend = sorted_categories.end(); - for (; viter != vend; viter++) - if (viter->get()) - Enable(*viter, Last); +bool TypeCategoryMap::Disable(ValueSP category) { + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); + if (category.get()) { + m_active_categories.remove_if(delete_matching_categories(category)); + category->Disable(); + return true; + } + return false; } -void -TypeCategoryMap::DisableAllCategories () -{ - std::lock_guard<std::recursive_mutex> guard(m_map_mutex); - Position p = First; - for (; false == m_active_categories.empty(); p++) - { - m_active_categories.front()->SetEnabledPosition(p); - Disable(m_active_categories.front()); +void TypeCategoryMap::EnableAllCategories() { + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); + std::vector<ValueSP> sorted_categories(m_map.size(), ValueSP()); + MapType::iterator iter = m_map.begin(), end = m_map.end(); + for (; iter != end; ++iter) { + if (iter->second->IsEnabled()) + continue; + auto pos = iter->second->GetLastEnabledPosition(); + if (pos >= sorted_categories.size()) { + auto iter = std::find_if( + sorted_categories.begin(), sorted_categories.end(), + [](const ValueSP &sp) -> bool { return sp.get() == nullptr; }); + pos = std::distance(sorted_categories.begin(), iter); } + sorted_categories.at(pos) = iter->second; + } + decltype(sorted_categories)::iterator viter = sorted_categories.begin(), + vend = sorted_categories.end(); + for (; viter != vend; viter++) + if (viter->get()) + Enable(*viter, Last); } -void -TypeCategoryMap::Clear () -{ - std::lock_guard<std::recursive_mutex> guard(m_map_mutex); - m_map.clear(); - m_active_categories.clear(); - if (listener) - listener->Changed(); +void TypeCategoryMap::DisableAllCategories() { + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); + Position p = First; + for (; false == m_active_categories.empty(); p++) { + m_active_categories.front()->SetEnabledPosition(p); + Disable(m_active_categories.front()); + } } -bool -TypeCategoryMap::Get (KeyType name, ValueSP& entry) -{ - std::lock_guard<std::recursive_mutex> guard(m_map_mutex); - MapIterator iter = m_map.find(name); - if (iter == m_map.end()) - return false; - entry = iter->second; - return true; +void TypeCategoryMap::Clear() { + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); + m_map.clear(); + m_active_categories.clear(); + if (listener) + listener->Changed(); } -bool -TypeCategoryMap::Get (uint32_t pos, ValueSP& entry) -{ - std::lock_guard<std::recursive_mutex> guard(m_map_mutex); - MapIterator iter = m_map.begin(); - MapIterator end = m_map.end(); - while (pos > 0) - { - iter++; - pos--; - if (iter == end) - return false; - } - entry = iter->second; +bool TypeCategoryMap::Get(KeyType name, ValueSP &entry) { + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); + MapIterator iter = m_map.find(name); + if (iter == m_map.end()) return false; + entry = iter->second; + return true; } -bool -TypeCategoryMap::AnyMatches (ConstString type_name, - TypeCategoryImpl::FormatCategoryItems items, - bool only_enabled, - const char** matching_category, - TypeCategoryImpl::FormatCategoryItems* matching_type) -{ - std::lock_guard<std::recursive_mutex> guard(m_map_mutex); +bool TypeCategoryMap::Get(uint32_t pos, ValueSP &entry) { + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); + MapIterator iter = m_map.begin(); + MapIterator end = m_map.end(); + while (pos > 0) { + iter++; + pos--; + if (iter == end) + return false; + } + entry = iter->second; + return false; +} - MapIterator pos, end = m_map.end(); - for (pos = m_map.begin(); pos != end; pos++) - { - if (pos->second->AnyMatches(type_name, - items, - only_enabled, - matching_category, - matching_type)) - return true; - } - return false; +bool TypeCategoryMap::AnyMatches( + ConstString type_name, TypeCategoryImpl::FormatCategoryItems items, + bool only_enabled, const char **matching_category, + TypeCategoryImpl::FormatCategoryItems *matching_type) { + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); + + MapIterator pos, end = m_map.end(); + for (pos = m_map.begin(); pos != end; pos++) { + if (pos->second->AnyMatches(type_name, items, only_enabled, + matching_category, matching_type)) + return true; + } + return false; } lldb::TypeFormatImplSP -TypeCategoryMap::GetFormat (FormattersMatchData& match_data) -{ - std::lock_guard<std::recursive_mutex> guard(m_map_mutex); - - uint32_t reason_why; - ActiveCategoriesIterator begin, end = m_active_categories.end(); - - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_DATAFORMATTERS)); - - if (log) - { - for (auto match : match_data.GetMatchesVector()) - { - log->Printf("[CategoryMap::GetFormat] candidate match = %s %s %s %s reason = %" PRIu32, - match.GetTypeName().GetCString(), - match.DidStripPointer() ? "strip-pointers" : "no-strip-pointers", - match.DidStripReference() ? "strip-reference" : "no-strip-reference", - match.DidStripTypedef() ? "strip-typedef" : "no-strip-typedef", - match.GetReason()); - } +TypeCategoryMap::GetFormat(FormattersMatchData &match_data) { + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); + + uint32_t reason_why; + ActiveCategoriesIterator begin, end = m_active_categories.end(); + + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DATAFORMATTERS)); + + if (log) { + for (auto match : match_data.GetMatchesVector()) { + log->Printf( + "[CategoryMap::GetFormat] candidate match = %s %s %s %s reason = " + "%" PRIu32, + match.GetTypeName().GetCString(), + match.DidStripPointer() ? "strip-pointers" : "no-strip-pointers", + match.DidStripReference() ? "strip-reference" : "no-strip-reference", + match.DidStripTypedef() ? "strip-typedef" : "no-strip-typedef", + match.GetReason()); } + } - for (begin = m_active_categories.begin(); begin != end; begin++) - { - lldb::TypeCategoryImplSP category_sp = *begin; - lldb::TypeFormatImplSP current_format; - if (log) - log->Printf("[TypeCategoryMap::GetFormat] Trying to use category %s", category_sp->GetName()); - if (!category_sp->Get(match_data.GetValueObject(), match_data.GetMatchesVector(), current_format, &reason_why)) - continue; - return current_format; - } + for (begin = m_active_categories.begin(); begin != end; begin++) { + lldb::TypeCategoryImplSP category_sp = *begin; + lldb::TypeFormatImplSP current_format; if (log) - log->Printf("[TypeCategoryMap::GetFormat] nothing found - returning empty SP"); - return lldb::TypeFormatImplSP(); + log->Printf("[TypeCategoryMap::GetFormat] Trying to use category %s", + category_sp->GetName()); + if (!category_sp->Get(match_data.GetValueObject(), + match_data.GetMatchesVector(), current_format, + &reason_why)) + continue; + return current_format; + } + if (log) + log->Printf( + "[TypeCategoryMap::GetFormat] nothing found - returning empty SP"); + return lldb::TypeFormatImplSP(); } lldb::TypeSummaryImplSP -TypeCategoryMap::GetSummaryFormat (FormattersMatchData& match_data) -{ - std::lock_guard<std::recursive_mutex> guard(m_map_mutex); - - uint32_t reason_why; - ActiveCategoriesIterator begin, end = m_active_categories.end(); - - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_DATAFORMATTERS)); - - if (log) - { - for (auto match : match_data.GetMatchesVector()) - { - log->Printf("[CategoryMap::GetSummaryFormat] candidate match = %s %s %s %s reason = %" PRIu32, - match.GetTypeName().GetCString(), - match.DidStripPointer() ? "strip-pointers" : "no-strip-pointers", - match.DidStripReference() ? "strip-reference" : "no-strip-reference", - match.DidStripTypedef() ? "strip-typedef" : "no-strip-typedef", - match.GetReason()); - } +TypeCategoryMap::GetSummaryFormat(FormattersMatchData &match_data) { + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); + + uint32_t reason_why; + ActiveCategoriesIterator begin, end = m_active_categories.end(); + + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DATAFORMATTERS)); + + if (log) { + for (auto match : match_data.GetMatchesVector()) { + log->Printf( + "[CategoryMap::GetSummaryFormat] candidate match = %s %s %s %s " + "reason = %" PRIu32, + match.GetTypeName().GetCString(), + match.DidStripPointer() ? "strip-pointers" : "no-strip-pointers", + match.DidStripReference() ? "strip-reference" : "no-strip-reference", + match.DidStripTypedef() ? "strip-typedef" : "no-strip-typedef", + match.GetReason()); } + } - for (begin = m_active_categories.begin(); begin != end; begin++) - { - lldb::TypeCategoryImplSP category_sp = *begin; - lldb::TypeSummaryImplSP current_format; - if (log) - log->Printf("[CategoryMap::GetSummaryFormat] Trying to use category %s", category_sp->GetName()); - if (!category_sp->Get(match_data.GetValueObject(), match_data.GetMatchesVector(), current_format, &reason_why)) - continue; - return current_format; - } + for (begin = m_active_categories.begin(); begin != end; begin++) { + lldb::TypeCategoryImplSP category_sp = *begin; + lldb::TypeSummaryImplSP current_format; if (log) - log->Printf("[CategoryMap::GetSummaryFormat] nothing found - returning empty SP"); - return lldb::TypeSummaryImplSP(); + log->Printf("[CategoryMap::GetSummaryFormat] Trying to use category %s", + category_sp->GetName()); + if (!category_sp->Get(match_data.GetValueObject(), + match_data.GetMatchesVector(), current_format, + &reason_why)) + continue; + return current_format; + } + if (log) + log->Printf( + "[CategoryMap::GetSummaryFormat] nothing found - returning empty SP"); + return lldb::TypeSummaryImplSP(); } #ifndef LLDB_DISABLE_PYTHON lldb::SyntheticChildrenSP -TypeCategoryMap::GetSyntheticChildren (FormattersMatchData& match_data) -{ - std::lock_guard<std::recursive_mutex> guard(m_map_mutex); +TypeCategoryMap::GetSyntheticChildren(FormattersMatchData &match_data) { + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); - uint32_t reason_why; - - ActiveCategoriesIterator begin, end = m_active_categories.end(); - - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_DATAFORMATTERS)); - - if (log) - { - for (auto match : match_data.GetMatchesVector()) - { - log->Printf("[CategoryMap::GetSyntheticChildren] candidate match = %s %s %s %s reason = %" PRIu32, - match.GetTypeName().GetCString(), - match.DidStripPointer() ? "strip-pointers" : "no-strip-pointers", - match.DidStripReference() ? "strip-reference" : "no-strip-reference", - match.DidStripTypedef() ? "strip-typedef" : "no-strip-typedef", - match.GetReason()); - } - } + uint32_t reason_why; - for (begin = m_active_categories.begin(); begin != end; begin++) - { - lldb::TypeCategoryImplSP category_sp = *begin; - lldb::SyntheticChildrenSP current_format; - if (log) - log->Printf("[CategoryMap::GetSyntheticChildren] Trying to use category %s", category_sp->GetName()); - if (!category_sp->Get(match_data.GetValueObject(), match_data.GetMatchesVector(), current_format, &reason_why)) - continue; - return current_format; + ActiveCategoriesIterator begin, end = m_active_categories.end(); + + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DATAFORMATTERS)); + + if (log) { + for (auto match : match_data.GetMatchesVector()) { + log->Printf( + "[CategoryMap::GetSyntheticChildren] candidate match = %s %s %s %s " + "reason = %" PRIu32, + match.GetTypeName().GetCString(), + match.DidStripPointer() ? "strip-pointers" : "no-strip-pointers", + match.DidStripReference() ? "strip-reference" : "no-strip-reference", + match.DidStripTypedef() ? "strip-typedef" : "no-strip-typedef", + match.GetReason()); } + } + + for (begin = m_active_categories.begin(); begin != end; begin++) { + lldb::TypeCategoryImplSP category_sp = *begin; + lldb::SyntheticChildrenSP current_format; if (log) - log->Printf("[CategoryMap::GetSyntheticChildren] nothing found - returning empty SP"); - return lldb::SyntheticChildrenSP(); + log->Printf( + "[CategoryMap::GetSyntheticChildren] Trying to use category %s", + category_sp->GetName()); + if (!category_sp->Get(match_data.GetValueObject(), + match_data.GetMatchesVector(), current_format, + &reason_why)) + continue; + return current_format; + } + if (log) + log->Printf("[CategoryMap::GetSyntheticChildren] nothing found - returning " + "empty SP"); + return lldb::SyntheticChildrenSP(); } #endif lldb::TypeValidatorImplSP -TypeCategoryMap::GetValidator (FormattersMatchData& match_data) -{ - std::lock_guard<std::recursive_mutex> guard(m_map_mutex); +TypeCategoryMap::GetValidator(FormattersMatchData &match_data) { + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); + + uint32_t reason_why; + ActiveCategoriesIterator begin, end = m_active_categories.end(); + + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DATAFORMATTERS)); + + if (log) { + for (auto match : match_data.GetMatchesVector()) { + log->Printf( + "[CategoryMap::GetValidator] candidate match = %s %s %s %s reason = " + "%" PRIu32, + match.GetTypeName().GetCString(), + match.DidStripPointer() ? "strip-pointers" : "no-strip-pointers", + match.DidStripReference() ? "strip-reference" : "no-strip-reference", + match.DidStripTypedef() ? "strip-typedef" : "no-strip-typedef", + match.GetReason()); + } + } - uint32_t reason_why; - ActiveCategoriesIterator begin, end = m_active_categories.end(); - - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_DATAFORMATTERS)); - + for (begin = m_active_categories.begin(); begin != end; begin++) { + lldb::TypeCategoryImplSP category_sp = *begin; + lldb::TypeValidatorImplSP current_format; if (log) - { - for (auto match : match_data.GetMatchesVector()) - { - log->Printf("[CategoryMap::GetValidator] candidate match = %s %s %s %s reason = %" PRIu32, - match.GetTypeName().GetCString(), - match.DidStripPointer() ? "strip-pointers" : "no-strip-pointers", - match.DidStripReference() ? "strip-reference" : "no-strip-reference", - match.DidStripTypedef() ? "strip-typedef" : "no-strip-typedef", - match.GetReason()); - } - } + log->Printf("[CategoryMap::GetValidator] Trying to use category %s", + category_sp->GetName()); + if (!category_sp->Get(match_data.GetValueObject(), + match_data.GetMatchesVector(), current_format, + &reason_why)) + continue; + return current_format; + } + if (log) + log->Printf( + "[CategoryMap::GetValidator] nothing found - returning empty SP"); + return lldb::TypeValidatorImplSP(); +} - for (begin = m_active_categories.begin(); begin != end; begin++) +void TypeCategoryMap::ForEach(ForEachCallback callback) { + if (callback) { + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); + + // loop through enabled categories in respective order { - lldb::TypeCategoryImplSP category_sp = *begin; - lldb::TypeValidatorImplSP current_format; - if (log) - log->Printf("[CategoryMap::GetValidator] Trying to use category %s", category_sp->GetName()); - if (!category_sp->Get(match_data.GetValueObject(), match_data.GetMatchesVector(), current_format, &reason_why)) - continue; - return current_format; + ActiveCategoriesIterator begin, end = m_active_categories.end(); + for (begin = m_active_categories.begin(); begin != end; begin++) { + lldb::TypeCategoryImplSP category = *begin; + if (!callback(category)) + break; + } } - if (log) - log->Printf("[CategoryMap::GetValidator] nothing found - returning empty SP"); - return lldb::TypeValidatorImplSP(); -} -void -TypeCategoryMap::ForEach(ForEachCallback callback) -{ - if (callback) + // loop through disabled categories in just any order { - std::lock_guard<std::recursive_mutex> guard(m_map_mutex); - - // loop through enabled categories in respective order - { - ActiveCategoriesIterator begin, end = m_active_categories.end(); - for (begin = m_active_categories.begin(); begin != end; begin++) - { - lldb::TypeCategoryImplSP category = *begin; - if (!callback(category)) - break; - } - } - - // loop through disabled categories in just any order - { - MapIterator pos, end = m_map.end(); - for (pos = m_map.begin(); pos != end; pos++) - { - if (pos->second->IsEnabled()) - continue; - if (!callback(pos->second)) - break; - } - } + MapIterator pos, end = m_map.end(); + for (pos = m_map.begin(); pos != end; pos++) { + if (pos->second->IsEnabled()) + continue; + if (!callback(pos->second)) + break; + } } + } } -TypeCategoryImplSP -TypeCategoryMap::GetAtIndex (uint32_t index) -{ - std::lock_guard<std::recursive_mutex> guard(m_map_mutex); +TypeCategoryImplSP TypeCategoryMap::GetAtIndex(uint32_t index) { + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); - if (index < m_map.size()) - { - MapIterator pos, end = m_map.end(); - for (pos = m_map.begin(); pos != end; pos++) - { - if (index == 0) - return pos->second; - index--; - } + if (index < m_map.size()) { + MapIterator pos, end = m_map.end(); + for (pos = m_map.begin(); pos != end; pos++) { + if (index == 0) + return pos->second; + index--; } - - return TypeCategoryImplSP(); + } + + return TypeCategoryImplSP(); } diff --git a/lldb/source/DataFormatters/TypeFormat.cpp b/lldb/source/DataFormatters/TypeFormat.cpp index 2409ddbb1c4..1ec52083c7c 100644 --- a/lldb/source/DataFormatters/TypeFormat.cpp +++ b/lldb/source/DataFormatters/TypeFormat.cpp @@ -16,8 +16,8 @@ // Other libraries and framework includes // Project includes -#include "lldb/lldb-public.h" #include "lldb/lldb-enumerations.h" +#include "lldb/lldb-public.h" #include "lldb/Core/StreamString.h" #include "lldb/DataFormatters/FormatManager.h" @@ -30,225 +30,181 @@ using namespace lldb; using namespace lldb_private; -TypeFormatImpl::TypeFormatImpl (const Flags& flags) : -m_flags(flags), -m_my_revision(0) -{ -} +TypeFormatImpl::TypeFormatImpl(const Flags &flags) + : m_flags(flags), m_my_revision(0) {} -TypeFormatImpl::~TypeFormatImpl () -{ -} +TypeFormatImpl::~TypeFormatImpl() {} -TypeFormatImpl_Format::TypeFormatImpl_Format (lldb::Format f, - const TypeFormatImpl::Flags& flags) : -TypeFormatImpl(flags), -m_format (f) -{ -} +TypeFormatImpl_Format::TypeFormatImpl_Format(lldb::Format f, + const TypeFormatImpl::Flags &flags) + : TypeFormatImpl(flags), m_format(f) {} -TypeFormatImpl_Format::~TypeFormatImpl_Format () -{ -} +TypeFormatImpl_Format::~TypeFormatImpl_Format() {} -bool -TypeFormatImpl_Format::FormatObject (ValueObject *valobj, - std::string& dest) const -{ - if (!valobj) - return false; - if (valobj->CanProvideValue()) - { - Value& value(valobj->GetValue()); - const Value::ContextType context_type = value.GetContextType(); - ExecutionContext exe_ctx (valobj->GetExecutionContextRef()); - DataExtractor data; - - if (context_type == Value::eContextTypeRegisterInfo) - { - const RegisterInfo *reg_info = value.GetRegisterInfo(); - if (reg_info) - { - Error error; - valobj->GetData(data, error); - if (error.Fail()) - return false; - - StreamString reg_sstr; - data.Dump (®_sstr, - 0, - GetFormat(), - reg_info->byte_size, - 1, - UINT32_MAX, - LLDB_INVALID_ADDRESS, - 0, - 0, - exe_ctx.GetBestExecutionContextScope()); - dest.swap(reg_sstr.GetString()); +bool TypeFormatImpl_Format::FormatObject(ValueObject *valobj, + std::string &dest) const { + if (!valobj) + return false; + if (valobj->CanProvideValue()) { + Value &value(valobj->GetValue()); + const Value::ContextType context_type = value.GetContextType(); + ExecutionContext exe_ctx(valobj->GetExecutionContextRef()); + DataExtractor data; + + if (context_type == Value::eContextTypeRegisterInfo) { + const RegisterInfo *reg_info = value.GetRegisterInfo(); + if (reg_info) { + Error error; + valobj->GetData(data, error); + if (error.Fail()) + return false; + + StreamString reg_sstr; + data.Dump(®_sstr, 0, GetFormat(), reg_info->byte_size, 1, UINT32_MAX, + LLDB_INVALID_ADDRESS, 0, 0, + exe_ctx.GetBestExecutionContextScope()); + dest.swap(reg_sstr.GetString()); + } + } else { + CompilerType compiler_type = value.GetCompilerType(); + if (compiler_type) { + // put custom bytes to display in the DataExtractor to override the + // default value logic + if (GetFormat() == eFormatCString) { + lldb_private::Flags type_flags(compiler_type.GetTypeInfo( + NULL)); // disambiguate w.r.t. TypeFormatImpl::Flags + if (type_flags.Test(eTypeIsPointer) && + !type_flags.Test(eTypeIsObjC)) { + // if we are dumping a pointer as a c-string, get the pointee data + // as a string + TargetSP target_sp(valobj->GetTargetSP()); + if (target_sp) { + size_t max_len = target_sp->GetMaximumSizeOfStringSummary(); + Error error; + DataBufferSP buffer_sp(new DataBufferHeap(max_len + 1, 0)); + Address address(valobj->GetPointerValue()); + if (target_sp->ReadCStringFromMemory( + address, (char *)buffer_sp->GetBytes(), max_len, error) && + error.Success()) + data.SetData(buffer_sp); } + } + } else { + Error error; + valobj->GetData(data, error); + if (error.Fail()) + return false; } + + StreamString sstr; + ExecutionContextScope *exe_scope( + exe_ctx.GetBestExecutionContextScope()); + compiler_type.DumpTypeValue( + &sstr, // The stream to use for display + GetFormat(), // Format to display this type with + data, // Data to extract from + 0, // Byte offset into "m_data" + compiler_type.GetByteSize( + exe_scope), // Byte size of item in "m_data" + valobj->GetBitfieldBitSize(), // Bitfield bit size + valobj->GetBitfieldBitOffset(), // Bitfield bit offset + exe_scope); + // Given that we do not want to set the ValueObject's m_error + // for a formatting error (or else we wouldn't be able to reformat + // until a next update), an empty string is treated as a "false" + // return from here, but that's about as severe as we get + // CompilerType::DumpTypeValue() should always return + // something, even if that something is an error message + if (sstr.GetString().empty()) + dest.clear(); else - { - CompilerType compiler_type = value.GetCompilerType (); - if (compiler_type) - { - // put custom bytes to display in the DataExtractor to override the default value logic - if (GetFormat() == eFormatCString) - { - lldb_private::Flags type_flags(compiler_type.GetTypeInfo(NULL)); // disambiguate w.r.t. TypeFormatImpl::Flags - if (type_flags.Test(eTypeIsPointer) && !type_flags.Test(eTypeIsObjC)) - { - // if we are dumping a pointer as a c-string, get the pointee data as a string - TargetSP target_sp(valobj->GetTargetSP()); - if (target_sp) - { - size_t max_len = target_sp->GetMaximumSizeOfStringSummary(); - Error error; - DataBufferSP buffer_sp(new DataBufferHeap(max_len+1,0)); - Address address(valobj->GetPointerValue()); - if (target_sp->ReadCStringFromMemory(address, (char*)buffer_sp->GetBytes(), max_len, error) && error.Success()) - data.SetData(buffer_sp); - } - } - } - else - { - Error error; - valobj->GetData(data, error); - if (error.Fail()) - return false; - } - - StreamString sstr; - ExecutionContextScope *exe_scope(exe_ctx.GetBestExecutionContextScope()); - compiler_type.DumpTypeValue (&sstr, // The stream to use for display - GetFormat(), // Format to display this type with - data, // Data to extract from - 0, // Byte offset into "m_data" - compiler_type.GetByteSize(exe_scope), // Byte size of item in "m_data" - valobj->GetBitfieldBitSize(), // Bitfield bit size - valobj->GetBitfieldBitOffset(), // Bitfield bit offset - exe_scope); - // Given that we do not want to set the ValueObject's m_error - // for a formatting error (or else we wouldn't be able to reformat - // until a next update), an empty string is treated as a "false" - // return from here, but that's about as severe as we get - // CompilerType::DumpTypeValue() should always return - // something, even if that something is an error message - if (sstr.GetString().empty()) - dest.clear(); - else - dest.swap(sstr.GetString()); - } - } - return !dest.empty(); + dest.swap(sstr.GetString()); + } } - else - return false; -} - -std::string -TypeFormatImpl_Format::GetDescription() -{ - StreamString sstr; - sstr.Printf ("%s%s%s%s", - FormatManager::GetFormatAsCString (GetFormat()), - Cascades() ? "" : " (not cascading)", - SkipsPointers() ? " (skip pointers)" : "", - SkipsReferences() ? " (skip references)" : ""); - return sstr.GetString(); -} - -TypeFormatImpl_EnumType::TypeFormatImpl_EnumType (ConstString type_name, - const TypeFormatImpl::Flags& flags) : -TypeFormatImpl(flags), -m_enum_type(type_name), -m_types() -{ + return !dest.empty(); + } else + return false; } -TypeFormatImpl_EnumType::~TypeFormatImpl_EnumType () -{ +std::string TypeFormatImpl_Format::GetDescription() { + StreamString sstr; + sstr.Printf("%s%s%s%s", FormatManager::GetFormatAsCString(GetFormat()), + Cascades() ? "" : " (not cascading)", + SkipsPointers() ? " (skip pointers)" : "", + SkipsReferences() ? " (skip references)" : ""); + return sstr.GetString(); } -bool -TypeFormatImpl_EnumType::FormatObject (ValueObject *valobj, - std::string& dest) const -{ - dest.clear(); - if (!valobj) - return false; - if (!valobj->CanProvideValue()) - return false; - ProcessSP process_sp; - TargetSP target_sp; - void* valobj_key = (process_sp = valobj->GetProcessSP()).get(); - if (!valobj_key) - valobj_key = (target_sp = valobj->GetTargetSP()).get(); - else - target_sp = process_sp->GetTarget().shared_from_this(); - if (!valobj_key) - return false; - auto iter = m_types.find(valobj_key), - end = m_types.end(); - CompilerType valobj_enum_type; - if (iter == end) - { - // probably a redundant check - if (!target_sp) - return false; - const ModuleList& images(target_sp->GetImages()); - SymbolContext sc; - TypeList types; - llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files; - images.FindTypes(sc, m_enum_type, false, UINT32_MAX, searched_symbol_files, types); - if (types.GetSize() == 0) - return false; - for (lldb::TypeSP type_sp : types.Types()) - { - if (!type_sp) - continue; - if ( (type_sp->GetForwardCompilerType().GetTypeInfo() & eTypeIsEnumeration) == eTypeIsEnumeration) - { - valobj_enum_type = type_sp->GetFullCompilerType (); - m_types.emplace(valobj_key,valobj_enum_type); - break; - } - } +TypeFormatImpl_EnumType::TypeFormatImpl_EnumType( + ConstString type_name, const TypeFormatImpl::Flags &flags) + : TypeFormatImpl(flags), m_enum_type(type_name), m_types() {} + +TypeFormatImpl_EnumType::~TypeFormatImpl_EnumType() {} + +bool TypeFormatImpl_EnumType::FormatObject(ValueObject *valobj, + std::string &dest) const { + dest.clear(); + if (!valobj) + return false; + if (!valobj->CanProvideValue()) + return false; + ProcessSP process_sp; + TargetSP target_sp; + void *valobj_key = (process_sp = valobj->GetProcessSP()).get(); + if (!valobj_key) + valobj_key = (target_sp = valobj->GetTargetSP()).get(); + else + target_sp = process_sp->GetTarget().shared_from_this(); + if (!valobj_key) + return false; + auto iter = m_types.find(valobj_key), end = m_types.end(); + CompilerType valobj_enum_type; + if (iter == end) { + // probably a redundant check + if (!target_sp) + return false; + const ModuleList &images(target_sp->GetImages()); + SymbolContext sc; + TypeList types; + llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files; + images.FindTypes(sc, m_enum_type, false, UINT32_MAX, searched_symbol_files, + types); + if (types.GetSize() == 0) + return false; + for (lldb::TypeSP type_sp : types.Types()) { + if (!type_sp) + continue; + if ((type_sp->GetForwardCompilerType().GetTypeInfo() & + eTypeIsEnumeration) == eTypeIsEnumeration) { + valobj_enum_type = type_sp->GetFullCompilerType(); + m_types.emplace(valobj_key, valobj_enum_type); + break; + } } - else - valobj_enum_type = iter->second; - if (valobj_enum_type.IsValid() == false) - return false; - DataExtractor data; - Error error; - valobj->GetData(data, error); - if (error.Fail()) - return false; - ExecutionContext exe_ctx (valobj->GetExecutionContextRef()); - StreamString sstr; - valobj_enum_type.DumpTypeValue(&sstr, - lldb::eFormatEnum, - data, - 0, - data.GetByteSize(), - 0, - 0, - exe_ctx.GetBestExecutionContextScope()); - if (!sstr.GetString().empty()) - dest.swap(sstr.GetString()); - return !dest.empty(); + } else + valobj_enum_type = iter->second; + if (valobj_enum_type.IsValid() == false) + return false; + DataExtractor data; + Error error; + valobj->GetData(data, error); + if (error.Fail()) + return false; + ExecutionContext exe_ctx(valobj->GetExecutionContextRef()); + StreamString sstr; + valobj_enum_type.DumpTypeValue(&sstr, lldb::eFormatEnum, data, 0, + data.GetByteSize(), 0, 0, + exe_ctx.GetBestExecutionContextScope()); + if (!sstr.GetString().empty()) + dest.swap(sstr.GetString()); + return !dest.empty(); } -std::string -TypeFormatImpl_EnumType::GetDescription() -{ - StreamString sstr; - sstr.Printf ("as type %s%s%s%s", - m_enum_type.AsCString("<invalid type>"), - Cascades() ? "" : " (not cascading)", - SkipsPointers() ? " (skip pointers)" : "", - SkipsReferences() ? " (skip references)" : ""); - return sstr.GetString(); +std::string TypeFormatImpl_EnumType::GetDescription() { + StreamString sstr; + sstr.Printf("as type %s%s%s%s", m_enum_type.AsCString("<invalid type>"), + Cascades() ? "" : " (not cascading)", + SkipsPointers() ? " (skip pointers)" : "", + SkipsReferences() ? " (skip references)" : ""); + return sstr.GetString(); } diff --git a/lldb/source/DataFormatters/TypeSummary.cpp b/lldb/source/DataFormatters/TypeSummary.cpp index dd4cd97f001..f77f524ee4d 100644 --- a/lldb/source/DataFormatters/TypeSummary.cpp +++ b/lldb/source/DataFormatters/TypeSummary.cpp @@ -16,8 +16,8 @@ // Other libraries and framework includes // Project includes -#include "lldb/lldb-public.h" #include "lldb/lldb-enumerations.h" +#include "lldb/lldb-public.h" #include "lldb/Core/Debugger.h" #include "lldb/Core/StreamString.h" @@ -31,252 +31,186 @@ using namespace lldb; using namespace lldb_private; -TypeSummaryOptions::TypeSummaryOptions () : - m_lang(eLanguageTypeUnknown), - m_capping(eTypeSummaryCapped) -{} - -TypeSummaryOptions::TypeSummaryOptions (const TypeSummaryOptions& rhs) : - m_lang(rhs.m_lang), - m_capping(rhs.m_capping) -{} - -TypeSummaryOptions& -TypeSummaryOptions::operator = (const TypeSummaryOptions& rhs) -{ - m_lang = rhs.m_lang; - m_capping = rhs.m_capping; - return *this; -} +TypeSummaryOptions::TypeSummaryOptions() + : m_lang(eLanguageTypeUnknown), m_capping(eTypeSummaryCapped) {} -lldb::LanguageType -TypeSummaryOptions::GetLanguage () const -{ - return m_lang; -} +TypeSummaryOptions::TypeSummaryOptions(const TypeSummaryOptions &rhs) + : m_lang(rhs.m_lang), m_capping(rhs.m_capping) {} -lldb::TypeSummaryCapping -TypeSummaryOptions::GetCapping () const -{ - return m_capping; +TypeSummaryOptions &TypeSummaryOptions:: +operator=(const TypeSummaryOptions &rhs) { + m_lang = rhs.m_lang; + m_capping = rhs.m_capping; + return *this; } -TypeSummaryOptions& -TypeSummaryOptions::SetLanguage (lldb::LanguageType lang) -{ - m_lang = lang; - return *this; -} - -TypeSummaryOptions& -TypeSummaryOptions::SetCapping (lldb::TypeSummaryCapping cap) -{ - m_capping = cap; - return *this; -} +lldb::LanguageType TypeSummaryOptions::GetLanguage() const { return m_lang; } -TypeSummaryImpl::TypeSummaryImpl (Kind kind, - const TypeSummaryImpl::Flags& flags) : - m_flags(flags), - m_kind(kind) -{ -} - - -StringSummaryFormat::StringSummaryFormat (const TypeSummaryImpl::Flags& flags, - const char *format_cstr) : - TypeSummaryImpl(Kind::eSummaryString,flags), - m_format_str() -{ - SetSummaryString (format_cstr); -} - -void -StringSummaryFormat::SetSummaryString (const char* format_cstr) -{ - m_format.Clear(); - if (format_cstr && format_cstr[0]) - { - m_format_str = format_cstr; - m_error = FormatEntity::Parse(format_cstr, m_format); - } - else - { - m_format_str.clear(); - m_error.Clear(); - } +lldb::TypeSummaryCapping TypeSummaryOptions::GetCapping() const { + return m_capping; } - - -bool -StringSummaryFormat::FormatObject (ValueObject *valobj, - std::string& retval, - const TypeSummaryOptions& options) -{ - if (!valobj) - { - retval.assign("NULL ValueObject"); - return false; - } - - StreamString s; - ExecutionContext exe_ctx (valobj->GetExecutionContextRef()); - SymbolContext sc; - StackFrame *frame = exe_ctx.GetFramePtr(); - if (frame) - sc = frame->GetSymbolContext(lldb::eSymbolContextEverything); - - if (IsOneLiner()) - { - ValueObjectPrinter printer(valobj,&s,DumpValueObjectOptions()); - printer.PrintChildrenOneLiner(HideNames(valobj)); - retval.assign(s.GetData()); - return true; - } - else - { - if (FormatEntity::Format(m_format, s, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), valobj, false, false)) - { - retval.assign(s.GetString()); - return true; - } - else - { - retval.assign("error: summary string parsing error"); - return false; - } - } +TypeSummaryOptions &TypeSummaryOptions::SetLanguage(lldb::LanguageType lang) { + m_lang = lang; + return *this; } -std::string -StringSummaryFormat::GetDescription () -{ - StreamString sstr; - - sstr.Printf ("`%s`%s%s%s%s%s%s%s%s%s", - m_format_str.c_str(), - m_error.Fail() ? " error: " : "", - m_error.Fail() ? m_error.AsCString() : "", - Cascades() ? "" : " (not cascading)", - !DoesPrintChildren(nullptr) ? "" : " (show children)", - !DoesPrintValue(nullptr) ? " (hide value)" : "", - IsOneLiner() ? " (one-line printout)" : "", - SkipsPointers() ? " (skip pointers)" : "", - SkipsReferences() ? " (skip references)" : "", - HideNames(nullptr) ? " (hide member names)" : ""); - return sstr.GetString(); +TypeSummaryOptions & +TypeSummaryOptions::SetCapping(lldb::TypeSummaryCapping cap) { + m_capping = cap; + return *this; } -CXXFunctionSummaryFormat::CXXFunctionSummaryFormat (const TypeSummaryImpl::Flags& flags, - Callback impl, - const char* description) : - TypeSummaryImpl(Kind::eCallback,flags), - m_impl(impl), - m_description(description ? description : "") -{ -} +TypeSummaryImpl::TypeSummaryImpl(Kind kind, const TypeSummaryImpl::Flags &flags) + : m_flags(flags), m_kind(kind) {} -bool -CXXFunctionSummaryFormat::FormatObject (ValueObject *valobj, - std::string& dest, - const TypeSummaryOptions& options) -{ - dest.clear(); - StreamString stream; - if (!m_impl || m_impl(*valobj,stream,options) == false) - return false; - dest.assign(stream.GetData()); - return true; +StringSummaryFormat::StringSummaryFormat(const TypeSummaryImpl::Flags &flags, + const char *format_cstr) + : TypeSummaryImpl(Kind::eSummaryString, flags), m_format_str() { + SetSummaryString(format_cstr); } -std::string -CXXFunctionSummaryFormat::GetDescription () -{ - StreamString sstr; - sstr.Printf ("%s%s%s%s%s%s%s %s", - Cascades() ? "" : " (not cascading)", - !DoesPrintChildren(nullptr) ? "" : " (show children)", - !DoesPrintValue(nullptr) ? " (hide value)" : "", - IsOneLiner() ? " (one-line printout)" : "", - SkipsPointers() ? " (skip pointers)" : "", - SkipsReferences() ? " (skip references)" : "", - HideNames(nullptr) ? " (hide member names)" : "", - m_description.c_str()); - return sstr.GetString(); +void StringSummaryFormat::SetSummaryString(const char *format_cstr) { + m_format.Clear(); + if (format_cstr && format_cstr[0]) { + m_format_str = format_cstr; + m_error = FormatEntity::Parse(format_cstr, m_format); + } else { + m_format_str.clear(); + m_error.Clear(); + } } -ScriptSummaryFormat::ScriptSummaryFormat (const TypeSummaryImpl::Flags& flags, - const char * function_name, - const char * python_script) : - TypeSummaryImpl(Kind::eScript,flags), - m_function_name(), - m_python_script(), - m_script_function_sp() -{ - if (function_name) - m_function_name.assign(function_name); - if (python_script) - m_python_script.assign(python_script); -} +bool StringSummaryFormat::FormatObject(ValueObject *valobj, std::string &retval, + const TypeSummaryOptions &options) { + if (!valobj) { + retval.assign("NULL ValueObject"); + return false; + } -bool -ScriptSummaryFormat::FormatObject (ValueObject *valobj, - std::string& retval, - const TypeSummaryOptions& options) -{ - if (!valobj) - return false; - - TargetSP target_sp(valobj->GetTargetSP()); - - if (!target_sp) - { - retval.assign("error: no target"); - return false; - } - - ScriptInterpreter *script_interpreter = target_sp->GetDebugger().GetCommandInterpreter().GetScriptInterpreter(); - - if (!script_interpreter) - { - retval.assign("error: no ScriptInterpreter"); - return false; - } - - return script_interpreter->GetScriptedSummary(m_function_name.c_str(), - valobj->GetSP(), - m_script_function_sp, - options, - retval); - -} + StreamString s; + ExecutionContext exe_ctx(valobj->GetExecutionContextRef()); + SymbolContext sc; + StackFrame *frame = exe_ctx.GetFramePtr(); + if (frame) + sc = frame->GetSymbolContext(lldb::eSymbolContextEverything); -std::string -ScriptSummaryFormat::GetDescription () -{ - StreamString sstr; - sstr.Printf ("%s%s%s%s%s%s%s\n ", Cascades() ? "" : " (not cascading)", - !DoesPrintChildren(nullptr) ? "" : " (show children)", - !DoesPrintValue(nullptr) ? " (hide value)" : "", - IsOneLiner() ? " (one-line printout)" : "", - SkipsPointers() ? " (skip pointers)" : "", - SkipsReferences() ? " (skip references)" : "", - HideNames(nullptr) ? " (hide member names)" : ""); - if (m_python_script.empty()) - { - if (m_function_name.empty()) - { - sstr.PutCString("no backing script"); - } - else - { - sstr.PutCString(m_function_name.c_str()); - } + if (IsOneLiner()) { + ValueObjectPrinter printer(valobj, &s, DumpValueObjectOptions()); + printer.PrintChildrenOneLiner(HideNames(valobj)); + retval.assign(s.GetData()); + return true; + } else { + if (FormatEntity::Format(m_format, s, &sc, &exe_ctx, + &sc.line_entry.range.GetBaseAddress(), valobj, + false, false)) { + retval.assign(s.GetString()); + return true; + } else { + retval.assign("error: summary string parsing error"); + return false; } - else - { - sstr.PutCString(m_python_script.c_str()); + } +} + +std::string StringSummaryFormat::GetDescription() { + StreamString sstr; + + sstr.Printf("`%s`%s%s%s%s%s%s%s%s%s", m_format_str.c_str(), + m_error.Fail() ? " error: " : "", + m_error.Fail() ? m_error.AsCString() : "", + Cascades() ? "" : " (not cascading)", + !DoesPrintChildren(nullptr) ? "" : " (show children)", + !DoesPrintValue(nullptr) ? " (hide value)" : "", + IsOneLiner() ? " (one-line printout)" : "", + SkipsPointers() ? " (skip pointers)" : "", + SkipsReferences() ? " (skip references)" : "", + HideNames(nullptr) ? " (hide member names)" : ""); + return sstr.GetString(); +} + +CXXFunctionSummaryFormat::CXXFunctionSummaryFormat( + const TypeSummaryImpl::Flags &flags, Callback impl, const char *description) + : TypeSummaryImpl(Kind::eCallback, flags), m_impl(impl), + m_description(description ? description : "") {} + +bool CXXFunctionSummaryFormat::FormatObject(ValueObject *valobj, + std::string &dest, + const TypeSummaryOptions &options) { + dest.clear(); + StreamString stream; + if (!m_impl || m_impl(*valobj, stream, options) == false) + return false; + dest.assign(stream.GetData()); + return true; +} + +std::string CXXFunctionSummaryFormat::GetDescription() { + StreamString sstr; + sstr.Printf("%s%s%s%s%s%s%s %s", Cascades() ? "" : " (not cascading)", + !DoesPrintChildren(nullptr) ? "" : " (show children)", + !DoesPrintValue(nullptr) ? " (hide value)" : "", + IsOneLiner() ? " (one-line printout)" : "", + SkipsPointers() ? " (skip pointers)" : "", + SkipsReferences() ? " (skip references)" : "", + HideNames(nullptr) ? " (hide member names)" : "", + m_description.c_str()); + return sstr.GetString(); +} + +ScriptSummaryFormat::ScriptSummaryFormat(const TypeSummaryImpl::Flags &flags, + const char *function_name, + const char *python_script) + : TypeSummaryImpl(Kind::eScript, flags), m_function_name(), + m_python_script(), m_script_function_sp() { + if (function_name) + m_function_name.assign(function_name); + if (python_script) + m_python_script.assign(python_script); +} + +bool ScriptSummaryFormat::FormatObject(ValueObject *valobj, std::string &retval, + const TypeSummaryOptions &options) { + if (!valobj) + return false; + + TargetSP target_sp(valobj->GetTargetSP()); + + if (!target_sp) { + retval.assign("error: no target"); + return false; + } + + ScriptInterpreter *script_interpreter = + target_sp->GetDebugger().GetCommandInterpreter().GetScriptInterpreter(); + + if (!script_interpreter) { + retval.assign("error: no ScriptInterpreter"); + return false; + } + + return script_interpreter->GetScriptedSummary( + m_function_name.c_str(), valobj->GetSP(), m_script_function_sp, options, + retval); +} + +std::string ScriptSummaryFormat::GetDescription() { + StreamString sstr; + sstr.Printf("%s%s%s%s%s%s%s\n ", Cascades() ? "" : " (not cascading)", + !DoesPrintChildren(nullptr) ? "" : " (show children)", + !DoesPrintValue(nullptr) ? " (hide value)" : "", + IsOneLiner() ? " (one-line printout)" : "", + SkipsPointers() ? " (skip pointers)" : "", + SkipsReferences() ? " (skip references)" : "", + HideNames(nullptr) ? " (hide member names)" : ""); + if (m_python_script.empty()) { + if (m_function_name.empty()) { + sstr.PutCString("no backing script"); + } else { + sstr.PutCString(m_function_name.c_str()); } - return sstr.GetString(); + } else { + sstr.PutCString(m_python_script.c_str()); + } + return sstr.GetString(); } diff --git a/lldb/source/DataFormatters/TypeSynthetic.cpp b/lldb/source/DataFormatters/TypeSynthetic.cpp index c8de1759c91..7bfc8794e5c 100644 --- a/lldb/source/DataFormatters/TypeSynthetic.cpp +++ b/lldb/source/DataFormatters/TypeSynthetic.cpp @@ -1,4 +1,5 @@ -//===-- TypeSynthetic.cpp ----------------------------------------*- C++ -*-===// +//===-- TypeSynthetic.cpp ----------------------------------------*- C++ +//-*-===// // // The LLVM Compiler Infrastructure // @@ -14,8 +15,8 @@ // Other libraries and framework includes // Project includes -#include "lldb/lldb-public.h" #include "lldb/lldb-enumerations.h" +#include "lldb/lldb-public.h" #include "lldb/Core/Debugger.h" #include "lldb/Core/StreamString.h" @@ -28,244 +29,198 @@ using namespace lldb; using namespace lldb_private; -void -TypeFilterImpl::AddExpressionPath (const std::string& path) -{ - bool need_add_dot = true; - if (path[0] == '.' || - (path[0] == '-' && path[1] == '>') || - path[0] == '[') - need_add_dot = false; - // add a '.' symbol to help forgetful users - if(!need_add_dot) - m_expression_paths.push_back(path); - else - m_expression_paths.push_back(std::string(".") + path); -} - -bool -TypeFilterImpl::SetExpressionPathAtIndex (size_t i, const std::string& path) -{ - if (i >= GetCount()) - return false; - bool need_add_dot = true; - if (path[0] == '.' || - (path[0] == '-' && path[1] == '>') || - path[0] == '[') - need_add_dot = false; - // add a '.' symbol to help forgetful users - if(!need_add_dot) - m_expression_paths[i] = path; - else - m_expression_paths[i] = std::string(".") + path; - return true; +void TypeFilterImpl::AddExpressionPath(const std::string &path) { + bool need_add_dot = true; + if (path[0] == '.' || (path[0] == '-' && path[1] == '>') || path[0] == '[') + need_add_dot = false; + // add a '.' symbol to help forgetful users + if (!need_add_dot) + m_expression_paths.push_back(path); + else + m_expression_paths.push_back(std::string(".") + path); +} + +bool TypeFilterImpl::SetExpressionPathAtIndex(size_t i, + const std::string &path) { + if (i >= GetCount()) + return false; + bool need_add_dot = true; + if (path[0] == '.' || (path[0] == '-' && path[1] == '>') || path[0] == '[') + need_add_dot = false; + // add a '.' symbol to help forgetful users + if (!need_add_dot) + m_expression_paths[i] = path; + else + m_expression_paths[i] = std::string(".") + path; + return true; } size_t -TypeFilterImpl::FrontEnd::GetIndexOfChildWithName (const ConstString &name) -{ - const char* name_cstr = name.GetCString(); - if (name_cstr) - { - for (size_t i = 0; i < filter->GetCount(); i++) - { - const char* expr_cstr = filter->GetExpressionPathAtIndex(i); - if (expr_cstr) - { - if (*expr_cstr == '.') - expr_cstr++; - else if (*expr_cstr == '-' && *(expr_cstr+1) == '>') - expr_cstr += 2; - } - if (expr_cstr) - { - if (!::strcmp(name_cstr, expr_cstr)) - return i; - } - } +TypeFilterImpl::FrontEnd::GetIndexOfChildWithName(const ConstString &name) { + const char *name_cstr = name.GetCString(); + if (name_cstr) { + for (size_t i = 0; i < filter->GetCount(); i++) { + const char *expr_cstr = filter->GetExpressionPathAtIndex(i); + if (expr_cstr) { + if (*expr_cstr == '.') + expr_cstr++; + else if (*expr_cstr == '-' && *(expr_cstr + 1) == '>') + expr_cstr += 2; + } + if (expr_cstr) { + if (!::strcmp(name_cstr, expr_cstr)) + return i; + } } - return UINT32_MAX; + } + return UINT32_MAX; } -std::string -TypeFilterImpl::GetDescription() -{ - StreamString sstr; - sstr.Printf("%s%s%s {\n", - Cascades() ? "" : " (not cascading)", - SkipsPointers() ? " (skip pointers)" : "", - SkipsReferences() ? " (skip references)" : ""); - - for (size_t i = 0; i < GetCount(); i++) - { - sstr.Printf(" %s\n", - GetExpressionPathAtIndex(i)); - } - - sstr.Printf("}"); - return sstr.GetString(); +std::string TypeFilterImpl::GetDescription() { + StreamString sstr; + sstr.Printf("%s%s%s {\n", Cascades() ? "" : " (not cascading)", + SkipsPointers() ? " (skip pointers)" : "", + SkipsReferences() ? " (skip references)" : ""); + + for (size_t i = 0; i < GetCount(); i++) { + sstr.Printf(" %s\n", GetExpressionPathAtIndex(i)); + } + + sstr.Printf("}"); + return sstr.GetString(); } -std::string -CXXSyntheticChildren::GetDescription() -{ - StreamString sstr; - sstr.Printf("%s%s%s %s", - Cascades() ? "" : " (not cascading)", - SkipsPointers() ? " (skip pointers)" : "", - SkipsReferences() ? " (skip references)" : "", - m_description.c_str()); - - return sstr.GetString(); +std::string CXXSyntheticChildren::GetDescription() { + StreamString sstr; + sstr.Printf("%s%s%s %s", Cascades() ? "" : " (not cascading)", + SkipsPointers() ? " (skip pointers)" : "", + SkipsReferences() ? " (skip references)" : "", + m_description.c_str()); + + return sstr.GetString(); } -lldb::ValueObjectSP -SyntheticChildrenFrontEnd::CreateValueObjectFromExpression (const char* name, - const char* expression, - const ExecutionContext& exe_ctx) -{ - ValueObjectSP valobj_sp(ValueObject::CreateValueObjectFromExpression(name, expression, exe_ctx)); - if (valobj_sp) - valobj_sp->SetSyntheticChildrenGenerated(true); - return valobj_sp; +lldb::ValueObjectSP SyntheticChildrenFrontEnd::CreateValueObjectFromExpression( + const char *name, const char *expression, const ExecutionContext &exe_ctx) { + ValueObjectSP valobj_sp( + ValueObject::CreateValueObjectFromExpression(name, expression, exe_ctx)); + if (valobj_sp) + valobj_sp->SetSyntheticChildrenGenerated(true); + return valobj_sp; } -lldb::ValueObjectSP -SyntheticChildrenFrontEnd::CreateValueObjectFromAddress (const char* name, - uint64_t address, - const ExecutionContext& exe_ctx, - CompilerType type) -{ - ValueObjectSP valobj_sp(ValueObject::CreateValueObjectFromAddress(name, address, exe_ctx, type)); - if (valobj_sp) - valobj_sp->SetSyntheticChildrenGenerated(true); - return valobj_sp; +lldb::ValueObjectSP SyntheticChildrenFrontEnd::CreateValueObjectFromAddress( + const char *name, uint64_t address, const ExecutionContext &exe_ctx, + CompilerType type) { + ValueObjectSP valobj_sp( + ValueObject::CreateValueObjectFromAddress(name, address, exe_ctx, type)); + if (valobj_sp) + valobj_sp->SetSyntheticChildrenGenerated(true); + return valobj_sp; } -lldb::ValueObjectSP -SyntheticChildrenFrontEnd::CreateValueObjectFromData (const char* name, - const DataExtractor& data, - const ExecutionContext& exe_ctx, - CompilerType type) -{ - ValueObjectSP valobj_sp(ValueObject::CreateValueObjectFromData(name, data, exe_ctx, type)); - if (valobj_sp) - valobj_sp->SetSyntheticChildrenGenerated(true); - return valobj_sp; +lldb::ValueObjectSP SyntheticChildrenFrontEnd::CreateValueObjectFromData( + const char *name, const DataExtractor &data, + const ExecutionContext &exe_ctx, CompilerType type) { + ValueObjectSP valobj_sp( + ValueObject::CreateValueObjectFromData(name, data, exe_ctx, type)); + if (valobj_sp) + valobj_sp->SetSyntheticChildrenGenerated(true); + return valobj_sp; } #ifndef LLDB_DISABLE_PYTHON -ScriptedSyntheticChildren::FrontEnd::FrontEnd(std::string pclass, ValueObject &backend) : -SyntheticChildrenFrontEnd(backend), -m_python_class(pclass), -m_wrapper_sp(), -m_interpreter(NULL) -{ - if (backend == LLDB_INVALID_UID) - return; - - TargetSP target_sp = backend.GetTargetSP(); - - if (!target_sp) - return; - - m_interpreter = target_sp->GetDebugger().GetCommandInterpreter().GetScriptInterpreter(); - - if (m_interpreter != NULL) - m_wrapper_sp = m_interpreter->CreateSyntheticScriptedProvider(m_python_class.c_str(), backend.GetSP()); -} +ScriptedSyntheticChildren::FrontEnd::FrontEnd(std::string pclass, + ValueObject &backend) + : SyntheticChildrenFrontEnd(backend), m_python_class(pclass), + m_wrapper_sp(), m_interpreter(NULL) { + if (backend == LLDB_INVALID_UID) + return; + + TargetSP target_sp = backend.GetTargetSP(); -ScriptedSyntheticChildren::FrontEnd::~FrontEnd() -{ + if (!target_sp) + return; + + m_interpreter = + target_sp->GetDebugger().GetCommandInterpreter().GetScriptInterpreter(); + + if (m_interpreter != NULL) + m_wrapper_sp = m_interpreter->CreateSyntheticScriptedProvider( + m_python_class.c_str(), backend.GetSP()); } +ScriptedSyntheticChildren::FrontEnd::~FrontEnd() {} + lldb::ValueObjectSP -ScriptedSyntheticChildren::FrontEnd::GetChildAtIndex (size_t idx) -{ - if (!m_wrapper_sp || !m_interpreter) - return lldb::ValueObjectSP(); - - return m_interpreter->GetChildAtIndex(m_wrapper_sp, idx); +ScriptedSyntheticChildren::FrontEnd::GetChildAtIndex(size_t idx) { + if (!m_wrapper_sp || !m_interpreter) + return lldb::ValueObjectSP(); + + return m_interpreter->GetChildAtIndex(m_wrapper_sp, idx); } -bool -ScriptedSyntheticChildren::FrontEnd::IsValid () -{ - return (m_wrapper_sp && m_wrapper_sp->IsValid() && m_interpreter); +bool ScriptedSyntheticChildren::FrontEnd::IsValid() { + return (m_wrapper_sp && m_wrapper_sp->IsValid() && m_interpreter); } -size_t -ScriptedSyntheticChildren::FrontEnd::CalculateNumChildren () -{ - if (!m_wrapper_sp || m_interpreter == NULL) - return 0; - return m_interpreter->CalculateNumChildren(m_wrapper_sp, UINT32_MAX); +size_t ScriptedSyntheticChildren::FrontEnd::CalculateNumChildren() { + if (!m_wrapper_sp || m_interpreter == NULL) + return 0; + return m_interpreter->CalculateNumChildren(m_wrapper_sp, UINT32_MAX); } -size_t -ScriptedSyntheticChildren::FrontEnd::CalculateNumChildren (uint32_t max) -{ - if (!m_wrapper_sp || m_interpreter == NULL) - return 0; - return m_interpreter->CalculateNumChildren(m_wrapper_sp, max); +size_t ScriptedSyntheticChildren::FrontEnd::CalculateNumChildren(uint32_t max) { + if (!m_wrapper_sp || m_interpreter == NULL) + return 0; + return m_interpreter->CalculateNumChildren(m_wrapper_sp, max); } -bool -ScriptedSyntheticChildren::FrontEnd::Update () -{ - if (!m_wrapper_sp || m_interpreter == NULL) - return false; - - return m_interpreter->UpdateSynthProviderInstance(m_wrapper_sp); +bool ScriptedSyntheticChildren::FrontEnd::Update() { + if (!m_wrapper_sp || m_interpreter == NULL) + return false; + + return m_interpreter->UpdateSynthProviderInstance(m_wrapper_sp); } -bool -ScriptedSyntheticChildren::FrontEnd::MightHaveChildren () -{ - if (!m_wrapper_sp || m_interpreter == NULL) - return false; - - return m_interpreter->MightHaveChildrenSynthProviderInstance(m_wrapper_sp); +bool ScriptedSyntheticChildren::FrontEnd::MightHaveChildren() { + if (!m_wrapper_sp || m_interpreter == NULL) + return false; + + return m_interpreter->MightHaveChildrenSynthProviderInstance(m_wrapper_sp); } -size_t -ScriptedSyntheticChildren::FrontEnd::GetIndexOfChildWithName (const ConstString &name) -{ - if (!m_wrapper_sp || m_interpreter == NULL) - return UINT32_MAX; - return m_interpreter->GetIndexOfChildWithName(m_wrapper_sp, name.GetCString()); +size_t ScriptedSyntheticChildren::FrontEnd::GetIndexOfChildWithName( + const ConstString &name) { + if (!m_wrapper_sp || m_interpreter == NULL) + return UINT32_MAX; + return m_interpreter->GetIndexOfChildWithName(m_wrapper_sp, + name.GetCString()); } -lldb::ValueObjectSP -ScriptedSyntheticChildren::FrontEnd::GetSyntheticValue () -{ - if (!m_wrapper_sp || m_interpreter == NULL) - return nullptr; - - return m_interpreter->GetSyntheticValue(m_wrapper_sp); +lldb::ValueObjectSP ScriptedSyntheticChildren::FrontEnd::GetSyntheticValue() { + if (!m_wrapper_sp || m_interpreter == NULL) + return nullptr; + + return m_interpreter->GetSyntheticValue(m_wrapper_sp); } -ConstString -ScriptedSyntheticChildren::FrontEnd::GetSyntheticTypeName () -{ - if (!m_wrapper_sp || m_interpreter == NULL) - return ConstString(); - - return m_interpreter->GetSyntheticTypeName(m_wrapper_sp); +ConstString ScriptedSyntheticChildren::FrontEnd::GetSyntheticTypeName() { + if (!m_wrapper_sp || m_interpreter == NULL) + return ConstString(); + + return m_interpreter->GetSyntheticTypeName(m_wrapper_sp); } -std::string -ScriptedSyntheticChildren::GetDescription() -{ - StreamString sstr; - sstr.Printf("%s%s%s Python class %s", - Cascades() ? "" : " (not cascading)", - SkipsPointers() ? " (skip pointers)" : "", - SkipsReferences() ? " (skip references)" : "", - m_python_class.c_str()); - - return sstr.GetString(); +std::string ScriptedSyntheticChildren::GetDescription() { + StreamString sstr; + sstr.Printf("%s%s%s Python class %s", Cascades() ? "" : " (not cascading)", + SkipsPointers() ? " (skip pointers)" : "", + SkipsReferences() ? " (skip references)" : "", + m_python_class.c_str()); + + return sstr.GetString(); } #endif // #ifndef LLDB_DISABLE_PYTHON diff --git a/lldb/source/DataFormatters/TypeValidator.cpp b/lldb/source/DataFormatters/TypeValidator.cpp index b5efac8f586..2affd7311e0 100644 --- a/lldb/source/DataFormatters/TypeValidator.cpp +++ b/lldb/source/DataFormatters/TypeValidator.cpp @@ -20,56 +20,39 @@ using namespace lldb; using namespace lldb_private; -TypeValidatorImpl::TypeValidatorImpl(const Flags &flags) : - m_flags(flags), - m_my_revision(0) -{ -} +TypeValidatorImpl::TypeValidatorImpl(const Flags &flags) + : m_flags(flags), m_my_revision(0) {} -TypeValidatorImpl::~TypeValidatorImpl() -{ -} +TypeValidatorImpl::~TypeValidatorImpl() {} -TypeValidatorImpl::ValidationResult -TypeValidatorImpl::Success () -{ - return ValidationResult { TypeValidatorResult::Success, "" }; +TypeValidatorImpl::ValidationResult TypeValidatorImpl::Success() { + return ValidationResult{TypeValidatorResult::Success, ""}; } TypeValidatorImpl::ValidationResult -TypeValidatorImpl::Failure (std::string message) -{ - return ValidationResult { TypeValidatorResult::Failure, message }; +TypeValidatorImpl::Failure(std::string message) { + return ValidationResult{TypeValidatorResult::Failure, message}; } -TypeValidatorImpl_CXX::TypeValidatorImpl_CXX (ValidatorFunction f, std::string d, const TypeValidatorImpl::Flags& flags) : - TypeValidatorImpl(flags), - m_description(d), - m_validator_function(f) -{ -} +TypeValidatorImpl_CXX::TypeValidatorImpl_CXX( + ValidatorFunction f, std::string d, const TypeValidatorImpl::Flags &flags) + : TypeValidatorImpl(flags), m_description(d), m_validator_function(f) {} -TypeValidatorImpl_CXX::~TypeValidatorImpl_CXX() -{ -} +TypeValidatorImpl_CXX::~TypeValidatorImpl_CXX() {} TypeValidatorImpl::ValidationResult -TypeValidatorImpl_CXX::FormatObject (ValueObject *valobj) const -{ - if (!valobj) - return Success(); // I guess there's nothing wrong with a null valueobject.. - - return m_validator_function(valobj); +TypeValidatorImpl_CXX::FormatObject(ValueObject *valobj) const { + if (!valobj) + return Success(); // I guess there's nothing wrong with a null valueobject.. + + return m_validator_function(valobj); } -std::string -TypeValidatorImpl_CXX::GetDescription() -{ - StreamString sstr; - sstr.Printf ("%s%s%s%s", - m_description.c_str(), - Cascades() ? "" : " (not cascading)", - SkipsPointers() ? " (skip pointers)" : "", - SkipsReferences() ? " (skip references)" : ""); - return sstr.GetString(); +std::string TypeValidatorImpl_CXX::GetDescription() { + StreamString sstr; + sstr.Printf("%s%s%s%s", m_description.c_str(), + Cascades() ? "" : " (not cascading)", + SkipsPointers() ? " (skip pointers)" : "", + SkipsReferences() ? " (skip references)" : ""); + return sstr.GetString(); } diff --git a/lldb/source/DataFormatters/ValueObjectPrinter.cpp b/lldb/source/DataFormatters/ValueObjectPrinter.cpp index 167afca7fbb..b8ccc7abcbc 100644 --- a/lldb/source/DataFormatters/ValueObjectPrinter.cpp +++ b/lldb/source/DataFormatters/ValueObjectPrinter.cpp @@ -1,4 +1,5 @@ -//===-- ValueObjectPrinter.cpp -------------------------------------*- C++ -*-===// +//===-- ValueObjectPrinter.cpp -------------------------------------*- C++ +//-*-===// // // The LLVM Compiler Infrastructure // @@ -23,952 +24,824 @@ using namespace lldb; using namespace lldb_private; -ValueObjectPrinter::ValueObjectPrinter (ValueObject* valobj, - Stream* s) -{ - if (valobj) - { - DumpValueObjectOptions options(*valobj); - Init (valobj,s,options,m_options.m_max_ptr_depth,0, nullptr); - } - else - { - DumpValueObjectOptions options; - Init (valobj,s,options,m_options.m_max_ptr_depth,0, nullptr); - } -} +ValueObjectPrinter::ValueObjectPrinter(ValueObject *valobj, Stream *s) { + if (valobj) { + DumpValueObjectOptions options(*valobj); + Init(valobj, s, options, m_options.m_max_ptr_depth, 0, nullptr); + } else { + DumpValueObjectOptions options; + Init(valobj, s, options, m_options.m_max_ptr_depth, 0, nullptr); + } +} + +ValueObjectPrinter::ValueObjectPrinter(ValueObject *valobj, Stream *s, + const DumpValueObjectOptions &options) { + Init(valobj, s, options, m_options.m_max_ptr_depth, 0, nullptr); +} + +ValueObjectPrinter::ValueObjectPrinter( + ValueObject *valobj, Stream *s, const DumpValueObjectOptions &options, + const DumpValueObjectOptions::PointerDepth &ptr_depth, uint32_t curr_depth, + InstancePointersSetSP printed_instance_pointers) { + Init(valobj, s, options, ptr_depth, curr_depth, printed_instance_pointers); +} + +void ValueObjectPrinter::Init( + ValueObject *valobj, Stream *s, const DumpValueObjectOptions &options, + const DumpValueObjectOptions::PointerDepth &ptr_depth, uint32_t curr_depth, + InstancePointersSetSP printed_instance_pointers) { + m_orig_valobj = valobj; + m_valobj = nullptr; + m_stream = s; + m_options = options; + m_ptr_depth = ptr_depth; + m_curr_depth = curr_depth; + assert(m_orig_valobj && "cannot print a NULL ValueObject"); + assert(m_stream && "cannot print to a NULL Stream"); + m_should_print = eLazyBoolCalculate; + m_is_nil = eLazyBoolCalculate; + m_is_uninit = eLazyBoolCalculate; + m_is_ptr = eLazyBoolCalculate; + m_is_ref = eLazyBoolCalculate; + m_is_aggregate = eLazyBoolCalculate; + m_is_instance_ptr = eLazyBoolCalculate; + m_summary_formatter = {nullptr, false}; + m_value.assign(""); + m_summary.assign(""); + m_error.assign(""); + m_val_summary_ok = false; + m_printed_instance_pointers = + printed_instance_pointers + ? printed_instance_pointers + : InstancePointersSetSP(new InstancePointersSet()); +} + +bool ValueObjectPrinter::PrintValueObject() { + if (!GetMostSpecializedValue() || m_valobj == nullptr) + return false; -ValueObjectPrinter::ValueObjectPrinter (ValueObject* valobj, - Stream* s, - const DumpValueObjectOptions& options) -{ - Init(valobj,s,options,m_options.m_max_ptr_depth,0, nullptr); -} - -ValueObjectPrinter::ValueObjectPrinter (ValueObject* valobj, - Stream* s, - const DumpValueObjectOptions& options, - const DumpValueObjectOptions::PointerDepth& ptr_depth, - uint32_t curr_depth, - InstancePointersSetSP printed_instance_pointers) -{ - Init(valobj,s,options,ptr_depth,curr_depth, printed_instance_pointers); -} - -void -ValueObjectPrinter::Init (ValueObject* valobj, - Stream* s, - const DumpValueObjectOptions& options, - const DumpValueObjectOptions::PointerDepth& ptr_depth, - uint32_t curr_depth, - InstancePointersSetSP printed_instance_pointers) -{ - m_orig_valobj = valobj; - m_valobj = nullptr; - m_stream = s; - m_options = options; - m_ptr_depth = ptr_depth; - m_curr_depth = curr_depth; - assert (m_orig_valobj && "cannot print a NULL ValueObject"); - assert (m_stream && "cannot print to a NULL Stream"); - m_should_print = eLazyBoolCalculate; - m_is_nil = eLazyBoolCalculate; - m_is_uninit = eLazyBoolCalculate; - m_is_ptr = eLazyBoolCalculate; - m_is_ref = eLazyBoolCalculate; - m_is_aggregate = eLazyBoolCalculate; - m_is_instance_ptr = eLazyBoolCalculate; - m_summary_formatter = {nullptr,false}; - m_value.assign(""); - m_summary.assign(""); - m_error.assign(""); - m_val_summary_ok = false; - m_printed_instance_pointers = printed_instance_pointers ? printed_instance_pointers : InstancePointersSetSP(new InstancePointersSet()); -} - -bool -ValueObjectPrinter::PrintValueObject () -{ - if (!GetMostSpecializedValue () || m_valobj == nullptr) - return false; - - if (ShouldPrintValueObject()) - { - PrintValidationMarkerIfNeeded(); - - PrintLocationIfNeeded(); - m_stream->Indent(); - - PrintDecl(); - } + if (ShouldPrintValueObject()) { + PrintValidationMarkerIfNeeded(); - bool value_printed = false; - bool summary_printed = false; - - m_val_summary_ok = PrintValueAndSummaryIfNeeded (value_printed,summary_printed); + PrintLocationIfNeeded(); + m_stream->Indent(); - if (m_val_summary_ok) - PrintChildrenIfNeeded (value_printed, summary_printed); - else - m_stream->EOL(); - - PrintValidationErrorIfNeeded(); - - return true; + PrintDecl(); + } + + bool value_printed = false; + bool summary_printed = false; + + m_val_summary_ok = + PrintValueAndSummaryIfNeeded(value_printed, summary_printed); + + if (m_val_summary_ok) + PrintChildrenIfNeeded(value_printed, summary_printed); + else + m_stream->EOL(); + + PrintValidationErrorIfNeeded(); + + return true; } -bool -ValueObjectPrinter::GetMostSpecializedValue () -{ - if (m_valobj) - return true; - bool update_success = m_orig_valobj->UpdateValueIfNeeded (true); - if (!update_success) - { - m_valobj = m_orig_valobj; - } - else - { - if (m_orig_valobj->IsDynamic()) - { - if (m_options.m_use_dynamic == eNoDynamicValues) - { - ValueObject *static_value = m_orig_valobj->GetStaticValue().get(); - if (static_value) - m_valobj = static_value; - else - m_valobj = m_orig_valobj; - } - else - m_valobj = m_orig_valobj; - } +bool ValueObjectPrinter::GetMostSpecializedValue() { + if (m_valobj) + return true; + bool update_success = m_orig_valobj->UpdateValueIfNeeded(true); + if (!update_success) { + m_valobj = m_orig_valobj; + } else { + if (m_orig_valobj->IsDynamic()) { + if (m_options.m_use_dynamic == eNoDynamicValues) { + ValueObject *static_value = m_orig_valobj->GetStaticValue().get(); + if (static_value) + m_valobj = static_value; else - { - if (m_options.m_use_dynamic != eNoDynamicValues) - { - ValueObject *dynamic_value = m_orig_valobj->GetDynamicValue(m_options.m_use_dynamic).get(); - if (dynamic_value) - m_valobj = dynamic_value; - else - m_valobj = m_orig_valobj; - } - else - m_valobj = m_orig_valobj; - } - - if (m_valobj->IsSynthetic()) - { - if (m_options.m_use_synthetic == false) - { - ValueObject *non_synthetic = m_valobj->GetNonSyntheticValue().get(); - if (non_synthetic) - m_valobj = non_synthetic; - } - } + m_valobj = m_orig_valobj; + } else + m_valobj = m_orig_valobj; + } else { + if (m_options.m_use_dynamic != eNoDynamicValues) { + ValueObject *dynamic_value = + m_orig_valobj->GetDynamicValue(m_options.m_use_dynamic).get(); + if (dynamic_value) + m_valobj = dynamic_value; else - { - if (m_options.m_use_synthetic == true) - { - ValueObject *synthetic = m_valobj->GetSyntheticValue().get(); - if (synthetic) - m_valobj = synthetic; - } - } + m_valobj = m_orig_valobj; + } else + m_valobj = m_orig_valobj; } - m_compiler_type = m_valobj->GetCompilerType(); - m_type_flags = m_compiler_type.GetTypeInfo (); - return true; -} -const char* -ValueObjectPrinter::GetDescriptionForDisplay () -{ - const char* str = m_valobj->GetObjectDescription(); - if (!str) - str = m_valobj->GetSummaryAsCString(); - if (!str) - str = m_valobj->GetValueAsCString(); - return str; -} - -const char* -ValueObjectPrinter::GetRootNameForDisplay (const char* if_fail) -{ - const char *root_valobj_name = m_options.m_root_valobj_name.empty() ? - m_valobj->GetName().AsCString() : - m_options.m_root_valobj_name.c_str(); - return root_valobj_name ? root_valobj_name : if_fail; -} - -bool -ValueObjectPrinter::ShouldPrintValueObject () -{ - if (m_should_print == eLazyBoolCalculate) - m_should_print = (m_options.m_flat_output == false || m_type_flags.Test (eTypeHasValue)) ? eLazyBoolYes : eLazyBoolNo; - return m_should_print == eLazyBoolYes; -} - -bool -ValueObjectPrinter::IsNil () -{ - if (m_is_nil == eLazyBoolCalculate) - m_is_nil = m_valobj->IsNilReference() ? eLazyBoolYes : eLazyBoolNo; - return m_is_nil == eLazyBoolYes; -} - -bool -ValueObjectPrinter::IsUninitialized () -{ - if (m_is_uninit == eLazyBoolCalculate) - m_is_uninit = m_valobj->IsUninitializedReference() ? eLazyBoolYes : eLazyBoolNo; - return m_is_uninit == eLazyBoolYes; -} - -bool -ValueObjectPrinter::IsPtr () -{ - if (m_is_ptr == eLazyBoolCalculate) - m_is_ptr = m_type_flags.Test (eTypeIsPointer) ? eLazyBoolYes : eLazyBoolNo; - return m_is_ptr == eLazyBoolYes; -} - -bool -ValueObjectPrinter::IsRef () -{ - if (m_is_ref == eLazyBoolCalculate) - m_is_ref = m_type_flags.Test (eTypeIsReference) ? eLazyBoolYes : eLazyBoolNo; - return m_is_ref == eLazyBoolYes; -} - -bool -ValueObjectPrinter::IsAggregate () -{ - if (m_is_aggregate == eLazyBoolCalculate) - m_is_aggregate = m_type_flags.Test (eTypeHasChildren) ? eLazyBoolYes : eLazyBoolNo; - return m_is_aggregate == eLazyBoolYes; -} - -bool -ValueObjectPrinter::IsInstancePointer () -{ - // you need to do this check on the value's clang type - if (m_is_instance_ptr == eLazyBoolCalculate) - m_is_instance_ptr = (m_valobj->GetValue().GetCompilerType().GetTypeInfo() & eTypeInstanceIsPointer) != 0 ? eLazyBoolYes : eLazyBoolNo; - if ((eLazyBoolYes == m_is_instance_ptr) && m_valobj->IsBaseClass()) - m_is_instance_ptr = eLazyBoolNo; - return m_is_instance_ptr == eLazyBoolYes; -} - -bool -ValueObjectPrinter::PrintLocationIfNeeded () -{ - if (m_options.m_show_location) - { - m_stream->Printf("%s: ", m_valobj->GetLocationAsCString()); - return true; + if (m_valobj->IsSynthetic()) { + if (m_options.m_use_synthetic == false) { + ValueObject *non_synthetic = m_valobj->GetNonSyntheticValue().get(); + if (non_synthetic) + m_valobj = non_synthetic; + } + } else { + if (m_options.m_use_synthetic == true) { + ValueObject *synthetic = m_valobj->GetSyntheticValue().get(); + if (synthetic) + m_valobj = synthetic; + } } - return false; + } + m_compiler_type = m_valobj->GetCompilerType(); + m_type_flags = m_compiler_type.GetTypeInfo(); + return true; } -void -ValueObjectPrinter::PrintDecl () -{ - bool show_type = true; - // if we are at the root-level and been asked to hide the root's type, then hide it - if (m_curr_depth == 0 && m_options.m_hide_root_type) - show_type = false; - else - // otherwise decide according to the usual rules (asked to show types - always at the root level) - show_type = m_options.m_show_types || (m_curr_depth == 0 && !m_options.m_flat_output); - - StreamString typeName; - - // always show the type at the root level if it is invalid - if (show_type) - { - // Some ValueObjects don't have types (like registers sets). Only print - // the type if there is one to print - ConstString type_name; - if (m_compiler_type.IsValid()) - { - if (m_options.m_use_type_display_name) - type_name = m_valobj->GetDisplayTypeName(); - else - type_name = m_valobj->GetQualifiedTypeName(); - } - else - { - // only show an invalid type name if the user explicitly triggered show_type - if (m_options.m_show_types) - type_name = ConstString("<invalid type>"); - else - type_name.Clear(); - } - - if (type_name) - { - std::string type_name_str(type_name.GetCString()); - if (m_options.m_hide_pointer_value) - { - for(auto iter = type_name_str.find(" *"); - iter != std::string::npos; - iter = type_name_str.find(" *")) - { - type_name_str.erase(iter, 2); - } - } - typeName.Printf("%s", type_name_str.c_str()); - } - } - - StreamString varName; - - if (m_options.m_flat_output) - { - // If we are showing types, also qualify the C++ base classes - const bool qualify_cxx_base_classes = show_type; - if (!m_options.m_hide_name) - { - m_valobj->GetExpressionPath(varName, qualify_cxx_base_classes); - } - } - else if (!m_options.m_hide_name) - { - const char *name_cstr = GetRootNameForDisplay(""); - varName.Printf ("%s", name_cstr); - } - - bool decl_printed = false; - if (!m_options.m_decl_printing_helper) - { - // if the user didn't give us a custom helper, pick one based upon the language, either the one that this printer is bound to, or the preferred one for the ValueObject - lldb::LanguageType lang_type = (m_options.m_varformat_language == lldb::eLanguageTypeUnknown) ? m_valobj->GetPreferredDisplayLanguage() : m_options.m_varformat_language; - if (Language *lang_plugin = Language::FindPlugin(lang_type)) - { - m_options.m_decl_printing_helper = lang_plugin->GetDeclPrintingHelper(); - } - } - - if (m_options.m_decl_printing_helper) - { - ConstString type_name_cstr(typeName.GetData()); - ConstString var_name_cstr(varName.GetData()); - - StreamString dest_stream; - if (m_options.m_decl_printing_helper (type_name_cstr, - var_name_cstr, - m_options, - dest_stream)) - { - decl_printed = true; - m_stream->Printf("%s", dest_stream.GetData()); - } - } - - // if the helper failed, or there is none, do a default thing - if (!decl_printed) - { - if (typeName.GetSize()) - m_stream->Printf("(%s) ", typeName.GetData()); - if (varName.GetSize()) - m_stream->Printf("%s =", varName.GetData()); - else if (!m_options.m_hide_name) - m_stream->Printf(" ="); - } +const char *ValueObjectPrinter::GetDescriptionForDisplay() { + const char *str = m_valobj->GetObjectDescription(); + if (!str) + str = m_valobj->GetSummaryAsCString(); + if (!str) + str = m_valobj->GetValueAsCString(); + return str; } -bool -ValueObjectPrinter::CheckScopeIfNeeded () -{ - if (m_options.m_scope_already_checked) - return true; - return m_valobj->IsInScope(); -} - -TypeSummaryImpl* -ValueObjectPrinter::GetSummaryFormatter (bool null_if_omitted) -{ - if (m_summary_formatter.second == false) - { - TypeSummaryImpl* entry = m_options.m_summary_sp ? m_options.m_summary_sp.get() : m_valobj->GetSummaryFormat().get(); - - if (m_options.m_omit_summary_depth > 0) - entry = NULL; - m_summary_formatter.first = entry; - m_summary_formatter.second = true; - } - if (m_options.m_omit_summary_depth > 0 && null_if_omitted) - return nullptr; - return m_summary_formatter.first; +const char *ValueObjectPrinter::GetRootNameForDisplay(const char *if_fail) { + const char *root_valobj_name = m_options.m_root_valobj_name.empty() + ? m_valobj->GetName().AsCString() + : m_options.m_root_valobj_name.c_str(); + return root_valobj_name ? root_valobj_name : if_fail; } -static bool -IsPointerValue (const CompilerType &type) -{ - Flags type_flags(type.GetTypeInfo()); - if (type_flags.AnySet(eTypeInstanceIsPointer | eTypeIsPointer)) - return type_flags.AllClear(eTypeIsBuiltIn); - return false; +bool ValueObjectPrinter::ShouldPrintValueObject() { + if (m_should_print == eLazyBoolCalculate) + m_should_print = + (m_options.m_flat_output == false || m_type_flags.Test(eTypeHasValue)) + ? eLazyBoolYes + : eLazyBoolNo; + return m_should_print == eLazyBoolYes; } -void -ValueObjectPrinter::GetValueSummaryError (std::string& value, - std::string& summary, - std::string& error) -{ - lldb::Format format = m_options.m_format; - // if I am printing synthetized elements, apply the format to those elements only - if (m_options.m_element_count > 0) - m_valobj->GetValueAsCString(lldb::eFormatDefault, value); - else if (format != eFormatDefault && format != m_valobj->GetFormat()) - m_valobj->GetValueAsCString(format, value); - else - { - const char* val_cstr = m_valobj->GetValueAsCString(); - if (val_cstr) - value.assign(val_cstr); - } - const char* err_cstr = m_valobj->GetError().AsCString(); - if (err_cstr) - error.assign(err_cstr); - - if (ShouldPrintValueObject()) - { - if (IsNil()) - summary.assign("nil"); - else if (IsUninitialized()) - summary.assign("<uninitialized>"); - else if (m_options.m_omit_summary_depth == 0) - { - TypeSummaryImpl* entry = GetSummaryFormatter(); - if (entry) - m_valobj->GetSummaryAsCString(entry, summary, m_options.m_varformat_language); - else - { - const char* sum_cstr = m_valobj->GetSummaryAsCString(m_options.m_varformat_language); - if (sum_cstr) - summary.assign(sum_cstr); - } - } - } +bool ValueObjectPrinter::IsNil() { + if (m_is_nil == eLazyBoolCalculate) + m_is_nil = m_valobj->IsNilReference() ? eLazyBoolYes : eLazyBoolNo; + return m_is_nil == eLazyBoolYes; } -bool -ValueObjectPrinter::PrintValueAndSummaryIfNeeded (bool& value_printed, - bool& summary_printed) -{ - bool error_printed = false; - if (ShouldPrintValueObject()) - { - if (!CheckScopeIfNeeded()) - m_error.assign("out of scope"); - if (m_error.empty()) - { - GetValueSummaryError(m_value, m_summary, m_error); - } - if (m_error.size()) - { - // we need to support scenarios in which it is actually fine for a value to have no type - // but - on the other hand - if we get an error *AND* have no type, we try to get out - // gracefully, since most often that combination means "could not resolve a type" - // and the default failure mode is quite ugly - if (!m_compiler_type.IsValid()) - { - m_stream->Printf(" <could not resolve type>"); - return false; - } - - error_printed = true; - m_stream->Printf (" <%s>\n", m_error.c_str()); - } - else - { - // Make sure we have a value and make sure the summary didn't - // specify that the value should not be printed - and do not print - // the value if this thing is nil - // (but show the value if the user passes a format explicitly) - TypeSummaryImpl* entry = GetSummaryFormatter(); - if (!IsNil() && !IsUninitialized() && !m_value.empty() && (entry == NULL || (entry->DoesPrintValue(m_valobj) || m_options.m_format != eFormatDefault) || m_summary.empty()) && !m_options.m_hide_value) - { - if (m_options.m_hide_pointer_value && IsPointerValue(m_valobj->GetCompilerType())) {} - else - { - m_stream->Printf(" %s", m_value.c_str()); - value_printed = true; - } - } - - if (m_summary.size()) - { - m_stream->Printf(" %s", m_summary.c_str()); - summary_printed = true; - } - } - } - return !error_printed; +bool ValueObjectPrinter::IsUninitialized() { + if (m_is_uninit == eLazyBoolCalculate) + m_is_uninit = + m_valobj->IsUninitializedReference() ? eLazyBoolYes : eLazyBoolNo; + return m_is_uninit == eLazyBoolYes; } -bool -ValueObjectPrinter::PrintObjectDescriptionIfNeeded (bool value_printed, - bool summary_printed) -{ - if (ShouldPrintValueObject()) - { - // let's avoid the overly verbose no description error for a nil thing - if (m_options.m_use_objc && !IsNil() && !IsUninitialized() && (m_options.m_element_count == 0)) - { - if (!m_options.m_hide_value || !m_options.m_hide_name) - m_stream->Printf(" "); - const char *object_desc = nullptr; - if (value_printed || summary_printed) - object_desc = m_valobj->GetObjectDescription(); - else - object_desc = GetDescriptionForDisplay(); - if (object_desc && *object_desc) - { - m_stream->Printf("%s\n", object_desc); - return true; - } - else if (value_printed == false && summary_printed == false) - return true; - else - return false; - } - } - return true; +bool ValueObjectPrinter::IsPtr() { + if (m_is_ptr == eLazyBoolCalculate) + m_is_ptr = m_type_flags.Test(eTypeIsPointer) ? eLazyBoolYes : eLazyBoolNo; + return m_is_ptr == eLazyBoolYes; } -bool -DumpValueObjectOptions::PointerDepth::CanAllowExpansion (bool is_root, - TypeSummaryImpl* entry, - ValueObject *valobj, - const std::string& summary) -{ - switch (m_mode) - { - case Mode::Always: - return (m_count > 0); - case Mode::Never: - return false; - case Mode::Default: - if (is_root) - m_count = std::min<decltype(m_count)>(m_count,1); - return m_count > 0; - case Mode::Formatters: - if (!entry || entry->DoesPrintChildren(valobj) || summary.empty()) - return m_count > 0; - return false; - } - return false; +bool ValueObjectPrinter::IsRef() { + if (m_is_ref == eLazyBoolCalculate) + m_is_ref = m_type_flags.Test(eTypeIsReference) ? eLazyBoolYes : eLazyBoolNo; + return m_is_ref == eLazyBoolYes; } -bool -DumpValueObjectOptions::PointerDepth::CanAllowExpansion () const -{ - switch (m_mode) - { - case Mode::Always: - case Mode::Default: - case Mode::Formatters: - return (m_count > 0); - case Mode::Never: - return false; - } - return false; +bool ValueObjectPrinter::IsAggregate() { + if (m_is_aggregate == eLazyBoolCalculate) + m_is_aggregate = + m_type_flags.Test(eTypeHasChildren) ? eLazyBoolYes : eLazyBoolNo; + return m_is_aggregate == eLazyBoolYes; +} + +bool ValueObjectPrinter::IsInstancePointer() { + // you need to do this check on the value's clang type + if (m_is_instance_ptr == eLazyBoolCalculate) + m_is_instance_ptr = (m_valobj->GetValue().GetCompilerType().GetTypeInfo() & + eTypeInstanceIsPointer) != 0 + ? eLazyBoolYes + : eLazyBoolNo; + if ((eLazyBoolYes == m_is_instance_ptr) && m_valobj->IsBaseClass()) + m_is_instance_ptr = eLazyBoolNo; + return m_is_instance_ptr == eLazyBoolYes; +} + +bool ValueObjectPrinter::PrintLocationIfNeeded() { + if (m_options.m_show_location) { + m_stream->Printf("%s: ", m_valobj->GetLocationAsCString()); + return true; + } + return false; +} + +void ValueObjectPrinter::PrintDecl() { + bool show_type = true; + // if we are at the root-level and been asked to hide the root's type, then + // hide it + if (m_curr_depth == 0 && m_options.m_hide_root_type) + show_type = false; + else + // otherwise decide according to the usual rules (asked to show types - + // always at the root level) + show_type = m_options.m_show_types || + (m_curr_depth == 0 && !m_options.m_flat_output); + + StreamString typeName; + + // always show the type at the root level if it is invalid + if (show_type) { + // Some ValueObjects don't have types (like registers sets). Only print + // the type if there is one to print + ConstString type_name; + if (m_compiler_type.IsValid()) { + if (m_options.m_use_type_display_name) + type_name = m_valobj->GetDisplayTypeName(); + else + type_name = m_valobj->GetQualifiedTypeName(); + } else { + // only show an invalid type name if the user explicitly triggered + // show_type + if (m_options.m_show_types) + type_name = ConstString("<invalid type>"); + else + type_name.Clear(); + } + + if (type_name) { + std::string type_name_str(type_name.GetCString()); + if (m_options.m_hide_pointer_value) { + for (auto iter = type_name_str.find(" *"); iter != std::string::npos; + iter = type_name_str.find(" *")) { + type_name_str.erase(iter, 2); + } + } + typeName.Printf("%s", type_name_str.c_str()); + } + } + + StreamString varName; + + if (m_options.m_flat_output) { + // If we are showing types, also qualify the C++ base classes + const bool qualify_cxx_base_classes = show_type; + if (!m_options.m_hide_name) { + m_valobj->GetExpressionPath(varName, qualify_cxx_base_classes); + } + } else if (!m_options.m_hide_name) { + const char *name_cstr = GetRootNameForDisplay(""); + varName.Printf("%s", name_cstr); + } + + bool decl_printed = false; + if (!m_options.m_decl_printing_helper) { + // if the user didn't give us a custom helper, pick one based upon the + // language, either the one that this printer is bound to, or the preferred + // one for the ValueObject + lldb::LanguageType lang_type = + (m_options.m_varformat_language == lldb::eLanguageTypeUnknown) + ? m_valobj->GetPreferredDisplayLanguage() + : m_options.m_varformat_language; + if (Language *lang_plugin = Language::FindPlugin(lang_type)) { + m_options.m_decl_printing_helper = lang_plugin->GetDeclPrintingHelper(); + } + } + + if (m_options.m_decl_printing_helper) { + ConstString type_name_cstr(typeName.GetData()); + ConstString var_name_cstr(varName.GetData()); + + StreamString dest_stream; + if (m_options.m_decl_printing_helper(type_name_cstr, var_name_cstr, + m_options, dest_stream)) { + decl_printed = true; + m_stream->Printf("%s", dest_stream.GetData()); + } + } + + // if the helper failed, or there is none, do a default thing + if (!decl_printed) { + if (typeName.GetSize()) + m_stream->Printf("(%s) ", typeName.GetData()); + if (varName.GetSize()) + m_stream->Printf("%s =", varName.GetData()); + else if (!m_options.m_hide_name) + m_stream->Printf(" ="); + } } -bool -ValueObjectPrinter::ShouldPrintChildren (bool is_failed_description, - DumpValueObjectOptions::PointerDepth& curr_ptr_depth) -{ - const bool is_ref = IsRef (); - const bool is_ptr = IsPtr (); - const bool is_uninit = IsUninitialized(); - - if (is_uninit) +bool ValueObjectPrinter::CheckScopeIfNeeded() { + if (m_options.m_scope_already_checked) + return true; + return m_valobj->IsInScope(); +} + +TypeSummaryImpl *ValueObjectPrinter::GetSummaryFormatter(bool null_if_omitted) { + if (m_summary_formatter.second == false) { + TypeSummaryImpl *entry = m_options.m_summary_sp + ? m_options.m_summary_sp.get() + : m_valobj->GetSummaryFormat().get(); + + if (m_options.m_omit_summary_depth > 0) + entry = NULL; + m_summary_formatter.first = entry; + m_summary_formatter.second = true; + } + if (m_options.m_omit_summary_depth > 0 && null_if_omitted) + return nullptr; + return m_summary_formatter.first; +} + +static bool IsPointerValue(const CompilerType &type) { + Flags type_flags(type.GetTypeInfo()); + if (type_flags.AnySet(eTypeInstanceIsPointer | eTypeIsPointer)) + return type_flags.AllClear(eTypeIsBuiltIn); + return false; +} + +void ValueObjectPrinter::GetValueSummaryError(std::string &value, + std::string &summary, + std::string &error) { + lldb::Format format = m_options.m_format; + // if I am printing synthetized elements, apply the format to those elements + // only + if (m_options.m_element_count > 0) + m_valobj->GetValueAsCString(lldb::eFormatDefault, value); + else if (format != eFormatDefault && format != m_valobj->GetFormat()) + m_valobj->GetValueAsCString(format, value); + else { + const char *val_cstr = m_valobj->GetValueAsCString(); + if (val_cstr) + value.assign(val_cstr); + } + const char *err_cstr = m_valobj->GetError().AsCString(); + if (err_cstr) + error.assign(err_cstr); + + if (ShouldPrintValueObject()) { + if (IsNil()) + summary.assign("nil"); + else if (IsUninitialized()) + summary.assign("<uninitialized>"); + else if (m_options.m_omit_summary_depth == 0) { + TypeSummaryImpl *entry = GetSummaryFormatter(); + if (entry) + m_valobj->GetSummaryAsCString(entry, summary, + m_options.m_varformat_language); + else { + const char *sum_cstr = + m_valobj->GetSummaryAsCString(m_options.m_varformat_language); + if (sum_cstr) + summary.assign(sum_cstr); + } + } + } +} + +bool ValueObjectPrinter::PrintValueAndSummaryIfNeeded(bool &value_printed, + bool &summary_printed) { + bool error_printed = false; + if (ShouldPrintValueObject()) { + if (!CheckScopeIfNeeded()) + m_error.assign("out of scope"); + if (m_error.empty()) { + GetValueSummaryError(m_value, m_summary, m_error); + } + if (m_error.size()) { + // we need to support scenarios in which it is actually fine for a value + // to have no type + // but - on the other hand - if we get an error *AND* have no type, we try + // to get out + // gracefully, since most often that combination means "could not resolve + // a type" + // and the default failure mode is quite ugly + if (!m_compiler_type.IsValid()) { + m_stream->Printf(" <could not resolve type>"); return false; - - // if the user has specified an element count, always print children - // as it is explicit user demand being honored - if (m_options.m_element_count > 0) + } + + error_printed = true; + m_stream->Printf(" <%s>\n", m_error.c_str()); + } else { + // Make sure we have a value and make sure the summary didn't + // specify that the value should not be printed - and do not print + // the value if this thing is nil + // (but show the value if the user passes a format explicitly) + TypeSummaryImpl *entry = GetSummaryFormatter(); + if (!IsNil() && !IsUninitialized() && !m_value.empty() && + (entry == NULL || (entry->DoesPrintValue(m_valobj) || + m_options.m_format != eFormatDefault) || + m_summary.empty()) && + !m_options.m_hide_value) { + if (m_options.m_hide_pointer_value && + IsPointerValue(m_valobj->GetCompilerType())) { + } else { + m_stream->Printf(" %s", m_value.c_str()); + value_printed = true; + } + } + + if (m_summary.size()) { + m_stream->Printf(" %s", m_summary.c_str()); + summary_printed = true; + } + } + } + return !error_printed; +} + +bool ValueObjectPrinter::PrintObjectDescriptionIfNeeded(bool value_printed, + bool summary_printed) { + if (ShouldPrintValueObject()) { + // let's avoid the overly verbose no description error for a nil thing + if (m_options.m_use_objc && !IsNil() && !IsUninitialized() && + (m_options.m_element_count == 0)) { + if (!m_options.m_hide_value || !m_options.m_hide_name) + m_stream->Printf(" "); + const char *object_desc = nullptr; + if (value_printed || summary_printed) + object_desc = m_valobj->GetObjectDescription(); + else + object_desc = GetDescriptionForDisplay(); + if (object_desc && *object_desc) { + m_stream->Printf("%s\n", object_desc); + return true; + } else if (value_printed == false && summary_printed == false) return true; - - TypeSummaryImpl* entry = GetSummaryFormatter(); - - if (m_options.m_use_objc) + else return false; - - if (is_failed_description || m_curr_depth < m_options.m_max_depth) - { - // We will show children for all concrete types. We won't show - // pointer contents unless a pointer depth has been specified. - // We won't reference contents unless the reference is the - // root object (depth of zero). - - // Use a new temporary pointer depth in case we override the - // current pointer depth below... - - if (is_ptr || is_ref) - { - // We have a pointer or reference whose value is an address. - // Make sure that address is not NULL - AddressType ptr_address_type; - if (m_valobj->GetPointerValue (&ptr_address_type) == 0) - return false; - - const bool is_root_level = m_curr_depth == 0; - - if (is_ref && - is_root_level) - { - // If this is the root object (depth is zero) that we are showing - // and it is a reference, and no pointer depth has been supplied - // print out what it references. Don't do this at deeper depths - // otherwise we can end up with infinite recursion... - return true; - } - - return curr_ptr_depth.CanAllowExpansion(false, entry, m_valobj, m_summary); - } - - return (!entry || entry->DoesPrintChildren(m_valobj) || m_summary.empty()); } - return false; + } + return true; } -bool -ValueObjectPrinter::ShouldExpandEmptyAggregates () -{ - TypeSummaryImpl* entry = GetSummaryFormatter(); - - if (!entry) - return true; - - return entry->DoesPrintEmptyAggregates(); +bool DumpValueObjectOptions::PointerDepth::CanAllowExpansion( + bool is_root, TypeSummaryImpl *entry, ValueObject *valobj, + const std::string &summary) { + switch (m_mode) { + case Mode::Always: + return (m_count > 0); + case Mode::Never: + return false; + case Mode::Default: + if (is_root) + m_count = std::min<decltype(m_count)>(m_count, 1); + return m_count > 0; + case Mode::Formatters: + if (!entry || entry->DoesPrintChildren(valobj) || summary.empty()) + return m_count > 0; + return false; + } + return false; } -ValueObject* -ValueObjectPrinter::GetValueObjectForChildrenGeneration () -{ - return m_valobj; +bool DumpValueObjectOptions::PointerDepth::CanAllowExpansion() const { + switch (m_mode) { + case Mode::Always: + case Mode::Default: + case Mode::Formatters: + return (m_count > 0); + case Mode::Never: + return false; + } + return false; } -void -ValueObjectPrinter::PrintChildrenPreamble () -{ - if (m_options.m_flat_output) - { - if (ShouldPrintValueObject()) - m_stream->EOL(); - } - else - { - if (ShouldPrintValueObject()) - m_stream->PutCString(IsRef () ? ": {\n" : " {\n"); - m_stream->IndentMore(); +bool ValueObjectPrinter::ShouldPrintChildren( + bool is_failed_description, + DumpValueObjectOptions::PointerDepth &curr_ptr_depth) { + const bool is_ref = IsRef(); + const bool is_ptr = IsPtr(); + const bool is_uninit = IsUninitialized(); + + if (is_uninit) + return false; + + // if the user has specified an element count, always print children + // as it is explicit user demand being honored + if (m_options.m_element_count > 0) + return true; + + TypeSummaryImpl *entry = GetSummaryFormatter(); + + if (m_options.m_use_objc) + return false; + + if (is_failed_description || m_curr_depth < m_options.m_max_depth) { + // We will show children for all concrete types. We won't show + // pointer contents unless a pointer depth has been specified. + // We won't reference contents unless the reference is the + // root object (depth of zero). + + // Use a new temporary pointer depth in case we override the + // current pointer depth below... + + if (is_ptr || is_ref) { + // We have a pointer or reference whose value is an address. + // Make sure that address is not NULL + AddressType ptr_address_type; + if (m_valobj->GetPointerValue(&ptr_address_type) == 0) + return false; + + const bool is_root_level = m_curr_depth == 0; + + if (is_ref && is_root_level) { + // If this is the root object (depth is zero) that we are showing + // and it is a reference, and no pointer depth has been supplied + // print out what it references. Don't do this at deeper depths + // otherwise we can end up with infinite recursion... + return true; + } + + return curr_ptr_depth.CanAllowExpansion(false, entry, m_valobj, + m_summary); } + + return (!entry || entry->DoesPrintChildren(m_valobj) || m_summary.empty()); + } + return false; } -void -ValueObjectPrinter::PrintChild (ValueObjectSP child_sp, - const DumpValueObjectOptions::PointerDepth& curr_ptr_depth) -{ - const uint32_t consumed_depth = (m_options.m_element_count == 0) ? 1 : 0; - const bool does_consume_ptr_depth = ((IsPtr() && m_options.m_element_count == 0) || IsRef()); - - DumpValueObjectOptions child_options(m_options); - child_options.SetFormat(m_options.m_format).SetSummary().SetRootValueObjectName(); - child_options.SetScopeChecked(true).SetHideName(m_options.m_hide_name).SetHideValue(m_options.m_hide_value) - .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - consumed_depth : 0) - .SetElementCount(0); - - if (child_sp.get()) - { - ValueObjectPrinter child_printer(child_sp.get(), - m_stream, - child_options, - does_consume_ptr_depth ? --curr_ptr_depth : curr_ptr_depth, - m_curr_depth + consumed_depth, - m_printed_instance_pointers); - child_printer.PrintValueObject(); - } +bool ValueObjectPrinter::ShouldExpandEmptyAggregates() { + TypeSummaryImpl *entry = GetSummaryFormatter(); + + if (!entry) + return true; + + return entry->DoesPrintEmptyAggregates(); } -uint32_t -ValueObjectPrinter::GetMaxNumChildrenToPrint (bool& print_dotdotdot) -{ - ValueObject* synth_m_valobj = GetValueObjectForChildrenGeneration(); - - if (m_options.m_element_count > 0) - return m_options.m_element_count; - - size_t num_children = synth_m_valobj->GetNumChildren(); - print_dotdotdot = false; - if (num_children) - { - const size_t max_num_children = m_valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay(); - - if (num_children > max_num_children && !m_options.m_ignore_cap) - { - print_dotdotdot = true; - return max_num_children; - } - } - return num_children; -} - -void -ValueObjectPrinter::PrintChildrenPostamble (bool print_dotdotdot) -{ - if (!m_options.m_flat_output) - { - if (print_dotdotdot) - { - m_valobj->GetTargetSP()->GetDebugger().GetCommandInterpreter().ChildrenTruncated(); - m_stream->Indent("...\n"); - } - m_stream->IndentLess(); - m_stream->Indent("}\n"); - } +ValueObject *ValueObjectPrinter::GetValueObjectForChildrenGeneration() { + return m_valobj; } -bool -ValueObjectPrinter::ShouldPrintEmptyBrackets (bool value_printed, - bool summary_printed) -{ - ValueObject* synth_m_valobj = GetValueObjectForChildrenGeneration(); - - if (!IsAggregate()) - return false; - - if (m_options.m_reveal_empty_aggregates == false) - { - if (value_printed || summary_printed) - return false; - } - - if (synth_m_valobj->MightHaveChildren()) - return true; - - if (m_val_summary_ok) - return false; - +void ValueObjectPrinter::PrintChildrenPreamble() { + if (m_options.m_flat_output) { + if (ShouldPrintValueObject()) + m_stream->EOL(); + } else { + if (ShouldPrintValueObject()) + m_stream->PutCString(IsRef() ? ": {\n" : " {\n"); + m_stream->IndentMore(); + } +} + +void ValueObjectPrinter::PrintChild( + ValueObjectSP child_sp, + const DumpValueObjectOptions::PointerDepth &curr_ptr_depth) { + const uint32_t consumed_depth = (m_options.m_element_count == 0) ? 1 : 0; + const bool does_consume_ptr_depth = + ((IsPtr() && m_options.m_element_count == 0) || IsRef()); + + DumpValueObjectOptions child_options(m_options); + child_options.SetFormat(m_options.m_format) + .SetSummary() + .SetRootValueObjectName(); + child_options.SetScopeChecked(true) + .SetHideName(m_options.m_hide_name) + .SetHideValue(m_options.m_hide_value) + .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 + ? child_options.m_omit_summary_depth - + consumed_depth + : 0) + .SetElementCount(0); + + if (child_sp.get()) { + ValueObjectPrinter child_printer( + child_sp.get(), m_stream, child_options, + does_consume_ptr_depth ? --curr_ptr_depth : curr_ptr_depth, + m_curr_depth + consumed_depth, m_printed_instance_pointers); + child_printer.PrintValueObject(); + } +} + +uint32_t ValueObjectPrinter::GetMaxNumChildrenToPrint(bool &print_dotdotdot) { + ValueObject *synth_m_valobj = GetValueObjectForChildrenGeneration(); + + if (m_options.m_element_count > 0) + return m_options.m_element_count; + + size_t num_children = synth_m_valobj->GetNumChildren(); + print_dotdotdot = false; + if (num_children) { + const size_t max_num_children = + m_valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay(); + + if (num_children > max_num_children && !m_options.m_ignore_cap) { + print_dotdotdot = true; + return max_num_children; + } + } + return num_children; +} + +void ValueObjectPrinter::PrintChildrenPostamble(bool print_dotdotdot) { + if (!m_options.m_flat_output) { + if (print_dotdotdot) { + m_valobj->GetTargetSP() + ->GetDebugger() + .GetCommandInterpreter() + .ChildrenTruncated(); + m_stream->Indent("...\n"); + } + m_stream->IndentLess(); + m_stream->Indent("}\n"); + } +} + +bool ValueObjectPrinter::ShouldPrintEmptyBrackets(bool value_printed, + bool summary_printed) { + ValueObject *synth_m_valobj = GetValueObjectForChildrenGeneration(); + + if (!IsAggregate()) + return false; + + if (m_options.m_reveal_empty_aggregates == false) { + if (value_printed || summary_printed) + return false; + } + + if (synth_m_valobj->MightHaveChildren()) return true; + + if (m_val_summary_ok) + return false; + + return true; } -ValueObjectSP -ValueObjectPrinter::GenerateChild (ValueObject* synth_valobj, size_t idx) -{ - if (m_options.m_element_count > 0) - { - // if generating pointer-as-array children, use GetSyntheticArrayMember - return synth_valobj->GetSyntheticArrayMember(idx, true); - } - else - { - // otherwise, do the usual thing - return synth_valobj->GetChildAtIndex(idx, true); - } +ValueObjectSP ValueObjectPrinter::GenerateChild(ValueObject *synth_valobj, + size_t idx) { + if (m_options.m_element_count > 0) { + // if generating pointer-as-array children, use GetSyntheticArrayMember + return synth_valobj->GetSyntheticArrayMember(idx, true); + } else { + // otherwise, do the usual thing + return synth_valobj->GetChildAtIndex(idx, true); + } } -void -ValueObjectPrinter::PrintChildren (bool value_printed, - bool summary_printed, - const DumpValueObjectOptions::PointerDepth& curr_ptr_depth) -{ - ValueObject* synth_m_valobj = GetValueObjectForChildrenGeneration(); - - bool print_dotdotdot = false; - size_t num_children = GetMaxNumChildrenToPrint(print_dotdotdot); - if (num_children) - { - bool any_children_printed = false; - - for (size_t idx=0; idx<num_children; ++idx) - { - if (ValueObjectSP child_sp = GenerateChild(synth_m_valobj, idx)) - { - if (!any_children_printed) - { - PrintChildrenPreamble (); - any_children_printed = true; - } - PrintChild (child_sp, curr_ptr_depth); - } - } - - if (any_children_printed) - PrintChildrenPostamble (print_dotdotdot); - else - { - if (ShouldPrintEmptyBrackets(value_printed, summary_printed)) - { - if (ShouldPrintValueObject()) - m_stream->PutCString(" {}\n"); - else - m_stream->EOL(); - } - else - m_stream->EOL(); - } - } - else if (ShouldPrintEmptyBrackets(value_printed, summary_printed)) - { - // Aggregate, no children... - if (ShouldPrintValueObject()) - { - // if it has a synthetic value, then don't print {}, the synthetic children are probably only being used to vend a value - if (m_valobj->DoesProvideSyntheticValue() || !ShouldExpandEmptyAggregates()) - m_stream->PutCString( "\n"); - else - m_stream->PutCString(" {}\n"); +void ValueObjectPrinter::PrintChildren( + bool value_printed, bool summary_printed, + const DumpValueObjectOptions::PointerDepth &curr_ptr_depth) { + ValueObject *synth_m_valobj = GetValueObjectForChildrenGeneration(); + + bool print_dotdotdot = false; + size_t num_children = GetMaxNumChildrenToPrint(print_dotdotdot); + if (num_children) { + bool any_children_printed = false; + + for (size_t idx = 0; idx < num_children; ++idx) { + if (ValueObjectSP child_sp = GenerateChild(synth_m_valobj, idx)) { + if (!any_children_printed) { + PrintChildrenPreamble(); + any_children_printed = true; } + PrintChild(child_sp, curr_ptr_depth); + } } - else - { - if (ShouldPrintValueObject()) - m_stream->EOL(); - } -} -bool -ValueObjectPrinter::PrintChildrenOneLiner (bool hide_names) -{ - if (!GetMostSpecializedValue () || m_valobj == nullptr) - return false; - - ValueObject* synth_m_valobj = GetValueObjectForChildrenGeneration(); - - bool print_dotdotdot = false; - size_t num_children = GetMaxNumChildrenToPrint(print_dotdotdot); - - if (num_children) - { - m_stream->PutChar('('); - - for (uint32_t idx=0; idx<num_children; ++idx) - { - lldb::ValueObjectSP child_sp(synth_m_valobj->GetChildAtIndex(idx, true)); - if (child_sp) - child_sp = child_sp->GetQualifiedRepresentationIfAvailable(m_options.m_use_dynamic, m_options.m_use_synthetic); - if (child_sp) - { - if (idx) - m_stream->PutCString(", "); - if (!hide_names) - { - const char* name = child_sp.get()->GetName().AsCString(); - if (name && *name) - { - m_stream->PutCString(name); - m_stream->PutCString(" = "); - } - } - child_sp->DumpPrintableRepresentation(*m_stream, - ValueObject::eValueObjectRepresentationStyleSummary, - m_options.m_format, - ValueObject::ePrintableRepresentationSpecialCasesDisable); - } - } - - if (print_dotdotdot) - m_stream->PutCString(", ...)"); + if (any_children_printed) + PrintChildrenPostamble(print_dotdotdot); + else { + if (ShouldPrintEmptyBrackets(value_printed, summary_printed)) { + if (ShouldPrintValueObject()) + m_stream->PutCString(" {}\n"); else - m_stream->PutChar(')'); + m_stream->EOL(); + } else + m_stream->EOL(); } - return true; + } else if (ShouldPrintEmptyBrackets(value_printed, summary_printed)) { + // Aggregate, no children... + if (ShouldPrintValueObject()) { + // if it has a synthetic value, then don't print {}, the synthetic + // children are probably only being used to vend a value + if (m_valobj->DoesProvideSyntheticValue() || + !ShouldExpandEmptyAggregates()) + m_stream->PutCString("\n"); + else + m_stream->PutCString(" {}\n"); + } + } else { + if (ShouldPrintValueObject()) + m_stream->EOL(); + } } -void -ValueObjectPrinter::PrintChildrenIfNeeded (bool value_printed, - bool summary_printed) -{ - // this flag controls whether we tried to display a description for this object and failed - // if that happens, we want to display the children, if any - bool is_failed_description = !PrintObjectDescriptionIfNeeded(value_printed, summary_printed); - - auto curr_ptr_depth = m_ptr_depth; - bool print_children = ShouldPrintChildren (is_failed_description,curr_ptr_depth); - bool print_oneline = (curr_ptr_depth.CanAllowExpansion() || - m_options.m_show_types || - !m_options.m_allow_oneliner_mode || - m_options.m_flat_output || - (m_options.m_element_count > 0) || - m_options.m_show_location) ? false : DataVisualization::ShouldPrintAsOneLiner(*m_valobj); - bool is_instance_ptr = IsInstancePointer(); - uint64_t instance_ptr_value = LLDB_INVALID_ADDRESS; - - if (print_children && is_instance_ptr) - { - instance_ptr_value = m_valobj->GetValueAsUnsigned(0); - if (m_printed_instance_pointers->count(instance_ptr_value)) - { - // we already printed this instance-is-pointer thing, so don't expand it - m_stream->PutCString(" {...}\n"); - - // we're done here - get out fast - return; - } - else - m_printed_instance_pointers->emplace(instance_ptr_value); // remember this guy for future reference - } - - if (print_children) - { - if (print_oneline) - { - m_stream->PutChar(' '); - PrintChildrenOneLiner (false); - m_stream->EOL(); +bool ValueObjectPrinter::PrintChildrenOneLiner(bool hide_names) { + if (!GetMostSpecializedValue() || m_valobj == nullptr) + return false; + + ValueObject *synth_m_valobj = GetValueObjectForChildrenGeneration(); + + bool print_dotdotdot = false; + size_t num_children = GetMaxNumChildrenToPrint(print_dotdotdot); + + if (num_children) { + m_stream->PutChar('('); + + for (uint32_t idx = 0; idx < num_children; ++idx) { + lldb::ValueObjectSP child_sp(synth_m_valobj->GetChildAtIndex(idx, true)); + if (child_sp) + child_sp = child_sp->GetQualifiedRepresentationIfAvailable( + m_options.m_use_dynamic, m_options.m_use_synthetic); + if (child_sp) { + if (idx) + m_stream->PutCString(", "); + if (!hide_names) { + const char *name = child_sp.get()->GetName().AsCString(); + if (name && *name) { + m_stream->PutCString(name); + m_stream->PutCString(" = "); + } } - else - PrintChildren (value_printed, summary_printed, curr_ptr_depth); - } - else if (m_curr_depth >= m_options.m_max_depth && IsAggregate() && ShouldPrintValueObject()) - { - m_stream->PutCString("{...}\n"); + child_sp->DumpPrintableRepresentation( + *m_stream, ValueObject::eValueObjectRepresentationStyleSummary, + m_options.m_format, + ValueObject::ePrintableRepresentationSpecialCasesDisable); + } } + + if (print_dotdotdot) + m_stream->PutCString(", ...)"); else - m_stream->EOL(); + m_stream->PutChar(')'); + } + return true; +} + +void ValueObjectPrinter::PrintChildrenIfNeeded(bool value_printed, + bool summary_printed) { + // this flag controls whether we tried to display a description for this + // object and failed + // if that happens, we want to display the children, if any + bool is_failed_description = + !PrintObjectDescriptionIfNeeded(value_printed, summary_printed); + + auto curr_ptr_depth = m_ptr_depth; + bool print_children = + ShouldPrintChildren(is_failed_description, curr_ptr_depth); + bool print_oneline = + (curr_ptr_depth.CanAllowExpansion() || m_options.m_show_types || + !m_options.m_allow_oneliner_mode || m_options.m_flat_output || + (m_options.m_element_count > 0) || m_options.m_show_location) + ? false + : DataVisualization::ShouldPrintAsOneLiner(*m_valobj); + bool is_instance_ptr = IsInstancePointer(); + uint64_t instance_ptr_value = LLDB_INVALID_ADDRESS; + + if (print_children && is_instance_ptr) { + instance_ptr_value = m_valobj->GetValueAsUnsigned(0); + if (m_printed_instance_pointers->count(instance_ptr_value)) { + // we already printed this instance-is-pointer thing, so don't expand it + m_stream->PutCString(" {...}\n"); + + // we're done here - get out fast + return; + } else + m_printed_instance_pointers->emplace( + instance_ptr_value); // remember this guy for future reference + } + + if (print_children) { + if (print_oneline) { + m_stream->PutChar(' '); + PrintChildrenOneLiner(false); + m_stream->EOL(); + } else + PrintChildren(value_printed, summary_printed, curr_ptr_depth); + } else if (m_curr_depth >= m_options.m_max_depth && IsAggregate() && + ShouldPrintValueObject()) { + m_stream->PutCString("{...}\n"); + } else + m_stream->EOL(); } -bool -ValueObjectPrinter::ShouldPrintValidation () -{ - return m_options.m_run_validator; +bool ValueObjectPrinter::ShouldPrintValidation() { + return m_options.m_run_validator; } -bool -ValueObjectPrinter::PrintValidationMarkerIfNeeded () -{ - if (!ShouldPrintValidation()) - return false; - - m_validation = m_valobj->GetValidationStatus(); - - if (TypeValidatorResult::Failure == m_validation.first) - { - m_stream->Printf("! "); - return true; - } - +bool ValueObjectPrinter::PrintValidationMarkerIfNeeded() { + if (!ShouldPrintValidation()) return false; -} -bool -ValueObjectPrinter::PrintValidationErrorIfNeeded () -{ - if (!ShouldPrintValidation()) - return false; - - if (TypeValidatorResult::Success == m_validation.first) - return false; - - if (m_validation.second.empty()) - m_validation.second.assign("unknown error"); - - m_stream->Printf(" ! validation error: %s", m_validation.second.c_str()); - m_stream->EOL(); - + m_validation = m_valobj->GetValidationStatus(); + + if (TypeValidatorResult::Failure == m_validation.first) { + m_stream->Printf("! "); return true; + } + + return false; +} + +bool ValueObjectPrinter::PrintValidationErrorIfNeeded() { + if (!ShouldPrintValidation()) + return false; + + if (TypeValidatorResult::Success == m_validation.first) + return false; + + if (m_validation.second.empty()) + m_validation.second.assign("unknown error"); + + m_stream->Printf(" ! validation error: %s", m_validation.second.c_str()); + m_stream->EOL(); + + return true; } diff --git a/lldb/source/DataFormatters/VectorType.cpp b/lldb/source/DataFormatters/VectorType.cpp index 347afa5c055..77694618ded 100644 --- a/lldb/source/DataFormatters/VectorType.cpp +++ b/lldb/source/DataFormatters/VectorType.cpp @@ -25,306 +25,277 @@ using namespace lldb; using namespace lldb_private; using namespace lldb_private::formatters; -static CompilerType -GetCompilerTypeForFormat (lldb::Format format, - CompilerType element_type, - TypeSystem *type_system) -{ - lldbassert(type_system && "type_system needs to be not NULL"); - - switch (format) - { - case lldb::eFormatAddressInfo: - case lldb::eFormatPointer: - return type_system->GetBuiltinTypeForEncodingAndBitSize (eEncodingUint, 8*type_system->GetPointerByteSize()); - - case lldb::eFormatBoolean: - return type_system->GetBasicTypeFromAST(lldb::eBasicTypeBool); - - case lldb::eFormatBytes: - case lldb::eFormatBytesWithASCII: - case lldb::eFormatChar: - case lldb::eFormatCharArray: - case lldb::eFormatCharPrintable: - return type_system->GetBasicTypeFromAST(lldb::eBasicTypeChar); - - case lldb::eFormatComplex /* lldb::eFormatComplexFloat */: - return type_system->GetBasicTypeFromAST(lldb::eBasicTypeFloatComplex); - - case lldb::eFormatCString: - return type_system->GetBasicTypeFromAST(lldb::eBasicTypeChar).GetPointerType(); - - case lldb::eFormatFloat: - return type_system->GetBasicTypeFromAST(lldb::eBasicTypeFloat); - - case lldb::eFormatHex: - case lldb::eFormatHexUppercase: - case lldb::eFormatOctal: - return type_system->GetBasicTypeFromAST(lldb::eBasicTypeInt); - - case lldb::eFormatHexFloat: - return type_system->GetBasicTypeFromAST(lldb::eBasicTypeFloat); - - case lldb::eFormatUnicode16: - case lldb::eFormatUnicode32: - - case lldb::eFormatUnsigned: - return type_system->GetBasicTypeFromAST(lldb::eBasicTypeUnsignedInt); - - case lldb::eFormatVectorOfChar: - return type_system->GetBasicTypeFromAST(lldb::eBasicTypeChar); - - case lldb::eFormatVectorOfFloat32: - return type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingIEEE754, 32); - - case lldb::eFormatVectorOfFloat64: - return type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingIEEE754, 64); - - case lldb::eFormatVectorOfSInt16: - return type_system->GetBuiltinTypeForEncodingAndBitSize (eEncodingSint, 16); - - case lldb::eFormatVectorOfSInt32: - return type_system->GetBuiltinTypeForEncodingAndBitSize (eEncodingSint, 32); - - case lldb::eFormatVectorOfSInt64: - return type_system->GetBuiltinTypeForEncodingAndBitSize (eEncodingSint, 64); - - case lldb::eFormatVectorOfSInt8: - return type_system->GetBuiltinTypeForEncodingAndBitSize (eEncodingSint, 8); - - case lldb::eFormatVectorOfUInt128: - return type_system->GetBuiltinTypeForEncodingAndBitSize (eEncodingUint, 128); - - case lldb::eFormatVectorOfUInt16: - return type_system->GetBuiltinTypeForEncodingAndBitSize (eEncodingUint, 16); - - case lldb::eFormatVectorOfUInt32: - return type_system->GetBuiltinTypeForEncodingAndBitSize (eEncodingUint, 32); - - case lldb::eFormatVectorOfUInt64: - return type_system->GetBuiltinTypeForEncodingAndBitSize (eEncodingUint, 64); - - case lldb::eFormatVectorOfUInt8: - return type_system->GetBuiltinTypeForEncodingAndBitSize (eEncodingUint, 8); - - case lldb::eFormatDefault: - return element_type; - - case lldb::eFormatBinary: - case lldb::eFormatComplexInteger: - case lldb::eFormatDecimal: - case lldb::eFormatEnum: - case lldb::eFormatInstruction: - case lldb::eFormatOSType: - case lldb::eFormatVoid: - default: - return type_system->GetBuiltinTypeForEncodingAndBitSize (eEncodingUint, 8); - } +static CompilerType GetCompilerTypeForFormat(lldb::Format format, + CompilerType element_type, + TypeSystem *type_system) { + lldbassert(type_system && "type_system needs to be not NULL"); + + switch (format) { + case lldb::eFormatAddressInfo: + case lldb::eFormatPointer: + return type_system->GetBuiltinTypeForEncodingAndBitSize( + eEncodingUint, 8 * type_system->GetPointerByteSize()); + + case lldb::eFormatBoolean: + return type_system->GetBasicTypeFromAST(lldb::eBasicTypeBool); + + case lldb::eFormatBytes: + case lldb::eFormatBytesWithASCII: + case lldb::eFormatChar: + case lldb::eFormatCharArray: + case lldb::eFormatCharPrintable: + return type_system->GetBasicTypeFromAST(lldb::eBasicTypeChar); + + case lldb::eFormatComplex /* lldb::eFormatComplexFloat */: + return type_system->GetBasicTypeFromAST(lldb::eBasicTypeFloatComplex); + + case lldb::eFormatCString: + return type_system->GetBasicTypeFromAST(lldb::eBasicTypeChar) + .GetPointerType(); + + case lldb::eFormatFloat: + return type_system->GetBasicTypeFromAST(lldb::eBasicTypeFloat); + + case lldb::eFormatHex: + case lldb::eFormatHexUppercase: + case lldb::eFormatOctal: + return type_system->GetBasicTypeFromAST(lldb::eBasicTypeInt); + + case lldb::eFormatHexFloat: + return type_system->GetBasicTypeFromAST(lldb::eBasicTypeFloat); + + case lldb::eFormatUnicode16: + case lldb::eFormatUnicode32: + + case lldb::eFormatUnsigned: + return type_system->GetBasicTypeFromAST(lldb::eBasicTypeUnsignedInt); + + case lldb::eFormatVectorOfChar: + return type_system->GetBasicTypeFromAST(lldb::eBasicTypeChar); + + case lldb::eFormatVectorOfFloat32: + return type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingIEEE754, + 32); + + case lldb::eFormatVectorOfFloat64: + return type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingIEEE754, + 64); + + case lldb::eFormatVectorOfSInt16: + return type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, 16); + + case lldb::eFormatVectorOfSInt32: + return type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, 32); + + case lldb::eFormatVectorOfSInt64: + return type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, 64); + + case lldb::eFormatVectorOfSInt8: + return type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, 8); + + case lldb::eFormatVectorOfUInt128: + return type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 128); + + case lldb::eFormatVectorOfUInt16: + return type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 16); + + case lldb::eFormatVectorOfUInt32: + return type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 32); + + case lldb::eFormatVectorOfUInt64: + return type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 64); + + case lldb::eFormatVectorOfUInt8: + return type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 8); + + case lldb::eFormatDefault: + return element_type; + + case lldb::eFormatBinary: + case lldb::eFormatComplexInteger: + case lldb::eFormatDecimal: + case lldb::eFormatEnum: + case lldb::eFormatInstruction: + case lldb::eFormatOSType: + case lldb::eFormatVoid: + default: + return type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 8); + } } -static lldb::Format -GetItemFormatForFormat (lldb::Format format, - CompilerType element_type) -{ - switch (format) - { - case lldb::eFormatVectorOfChar: - return lldb::eFormatChar; - - case lldb::eFormatVectorOfFloat32: - case lldb::eFormatVectorOfFloat64: - return lldb::eFormatFloat; - - case lldb::eFormatVectorOfSInt16: - case lldb::eFormatVectorOfSInt32: - case lldb::eFormatVectorOfSInt64: - case lldb::eFormatVectorOfSInt8: - return lldb::eFormatDecimal; - - case lldb::eFormatVectorOfUInt128: - case lldb::eFormatVectorOfUInt16: - case lldb::eFormatVectorOfUInt32: - case lldb::eFormatVectorOfUInt64: - case lldb::eFormatVectorOfUInt8: - return lldb::eFormatUnsigned; - - case lldb::eFormatBinary: - case lldb::eFormatComplexInteger: - case lldb::eFormatDecimal: - case lldb::eFormatEnum: - case lldb::eFormatInstruction: - case lldb::eFormatOSType: - case lldb::eFormatVoid: - return eFormatHex; - - case lldb::eFormatDefault: - { - // special case the (default, char) combination to actually display as an integer value - // most often, you won't want to see the ASCII characters... (and if you do, eFormatChar is a keystroke away) - bool is_char = element_type.IsCharType(); - bool is_signed = false; - element_type.IsIntegerType(is_signed); - return is_char ? (is_signed ? lldb::eFormatDecimal : eFormatHex) : format; - } - break; - - default: - return format; - } +static lldb::Format GetItemFormatForFormat(lldb::Format format, + CompilerType element_type) { + switch (format) { + case lldb::eFormatVectorOfChar: + return lldb::eFormatChar; + + case lldb::eFormatVectorOfFloat32: + case lldb::eFormatVectorOfFloat64: + return lldb::eFormatFloat; + + case lldb::eFormatVectorOfSInt16: + case lldb::eFormatVectorOfSInt32: + case lldb::eFormatVectorOfSInt64: + case lldb::eFormatVectorOfSInt8: + return lldb::eFormatDecimal; + + case lldb::eFormatVectorOfUInt128: + case lldb::eFormatVectorOfUInt16: + case lldb::eFormatVectorOfUInt32: + case lldb::eFormatVectorOfUInt64: + case lldb::eFormatVectorOfUInt8: + return lldb::eFormatUnsigned; + + case lldb::eFormatBinary: + case lldb::eFormatComplexInteger: + case lldb::eFormatDecimal: + case lldb::eFormatEnum: + case lldb::eFormatInstruction: + case lldb::eFormatOSType: + case lldb::eFormatVoid: + return eFormatHex; + + case lldb::eFormatDefault: { + // special case the (default, char) combination to actually display as an + // integer value + // most often, you won't want to see the ASCII characters... (and if you do, + // eFormatChar is a keystroke away) + bool is_char = element_type.IsCharType(); + bool is_signed = false; + element_type.IsIntegerType(is_signed); + return is_char ? (is_signed ? lldb::eFormatDecimal : eFormatHex) : format; + } break; + + default: + return format; + } } -static size_t -CalculateNumChildren (CompilerType container_type, - CompilerType element_type, - lldb_private::ExecutionContextScope *exe_scope = nullptr // does not matter here because all we trade in are basic types - ) -{ - auto container_size = container_type.GetByteSize(exe_scope); - auto element_size = element_type.GetByteSize(exe_scope); - - if (element_size) - { - if (container_size % element_size) - return 0; - return container_size / element_size; - } - return 0; +static size_t CalculateNumChildren( + CompilerType container_type, CompilerType element_type, + lldb_private::ExecutionContextScope *exe_scope = + nullptr // does not matter here because all we trade in are basic types + ) { + auto container_size = container_type.GetByteSize(exe_scope); + auto element_size = element_type.GetByteSize(exe_scope); + + if (element_size) { + if (container_size % element_size) + return 0; + return container_size / element_size; + } + return 0; } namespace lldb_private { - namespace formatters { - - class VectorTypeSyntheticFrontEnd : public SyntheticChildrenFrontEnd - { - public: - VectorTypeSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp) : - SyntheticChildrenFrontEnd(*valobj_sp), - m_parent_format (eFormatInvalid), - m_item_format(eFormatInvalid), - m_child_type(), - m_num_children(0) - {} - - ~VectorTypeSyntheticFrontEnd() override = default; - - size_t - CalculateNumChildren() override - { - return m_num_children; - } - - lldb::ValueObjectSP - GetChildAtIndex(size_t idx) override - { - if (idx >= CalculateNumChildren()) - return lldb::ValueObjectSP(); - auto offset = idx * m_child_type.GetByteSize(nullptr); - ValueObjectSP child_sp(m_backend.GetSyntheticChildAtOffset(offset, m_child_type, true)); - if (!child_sp) - return child_sp; - - StreamString idx_name; - idx_name.Printf("[%" PRIu64 "]", (uint64_t)idx); - child_sp->SetName( ConstString( idx_name.GetData() ) ); - - child_sp->SetFormat(m_item_format); - - return child_sp; - } - - bool - Update() override - { - m_parent_format = m_backend.GetFormat(); - CompilerType parent_type(m_backend.GetCompilerType()); - CompilerType element_type; - parent_type.IsVectorType(&element_type, nullptr); - TargetSP target_sp(m_backend.GetTargetSP()); - m_child_type = ::GetCompilerTypeForFormat(m_parent_format, - element_type, - target_sp ? target_sp->GetScratchTypeSystemForLanguage(nullptr, lldb::eLanguageTypeC) : nullptr); - m_num_children = ::CalculateNumChildren(parent_type, - m_child_type); - m_item_format = GetItemFormatForFormat(m_parent_format, - m_child_type); - return false; - } - - bool - MightHaveChildren() override - { - return true; - } - - size_t - GetIndexOfChildWithName(const ConstString &name) override - { - const char* item_name = name.GetCString(); - uint32_t idx = ExtractIndexFromString(item_name); - if (idx < UINT32_MAX && idx >= CalculateNumChildren()) - return UINT32_MAX; - return idx; - } - - private: - lldb::Format m_parent_format; - lldb::Format m_item_format; - CompilerType m_child_type; - size_t m_num_children; - }; - - } // namespace formatters +namespace formatters { + +class VectorTypeSyntheticFrontEnd : public SyntheticChildrenFrontEnd { +public: + VectorTypeSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp) + : SyntheticChildrenFrontEnd(*valobj_sp), m_parent_format(eFormatInvalid), + m_item_format(eFormatInvalid), m_child_type(), m_num_children(0) {} + + ~VectorTypeSyntheticFrontEnd() override = default; + + size_t CalculateNumChildren() override { return m_num_children; } + + lldb::ValueObjectSP GetChildAtIndex(size_t idx) override { + if (idx >= CalculateNumChildren()) + return lldb::ValueObjectSP(); + auto offset = idx * m_child_type.GetByteSize(nullptr); + ValueObjectSP child_sp( + m_backend.GetSyntheticChildAtOffset(offset, m_child_type, true)); + if (!child_sp) + return child_sp; + + StreamString idx_name; + idx_name.Printf("[%" PRIu64 "]", (uint64_t)idx); + child_sp->SetName(ConstString(idx_name.GetData())); + + child_sp->SetFormat(m_item_format); + + return child_sp; + } + + bool Update() override { + m_parent_format = m_backend.GetFormat(); + CompilerType parent_type(m_backend.GetCompilerType()); + CompilerType element_type; + parent_type.IsVectorType(&element_type, nullptr); + TargetSP target_sp(m_backend.GetTargetSP()); + m_child_type = ::GetCompilerTypeForFormat( + m_parent_format, element_type, + target_sp + ? target_sp->GetScratchTypeSystemForLanguage(nullptr, + lldb::eLanguageTypeC) + : nullptr); + m_num_children = ::CalculateNumChildren(parent_type, m_child_type); + m_item_format = GetItemFormatForFormat(m_parent_format, m_child_type); + return false; + } + + bool MightHaveChildren() override { return true; } + + size_t GetIndexOfChildWithName(const ConstString &name) override { + const char *item_name = name.GetCString(); + uint32_t idx = ExtractIndexFromString(item_name); + if (idx < UINT32_MAX && idx >= CalculateNumChildren()) + return UINT32_MAX; + return idx; + } + +private: + lldb::Format m_parent_format; + lldb::Format m_item_format; + CompilerType m_child_type; + size_t m_num_children; +}; + +} // namespace formatters } // namespace lldb_private -bool -lldb_private::formatters::VectorTypeSummaryProvider (ValueObject& valobj, - Stream& s, - const TypeSummaryOptions&) -{ - auto synthetic_children = VectorTypeSyntheticFrontEndCreator(nullptr, valobj.GetSP()); - if (!synthetic_children) - return false; - - synthetic_children->Update(); - - s.PutChar('('); - bool first = true; - - size_t idx = 0, len = synthetic_children->CalculateNumChildren(); - - for (; - idx < len; - idx++) - { - auto child_sp = synthetic_children->GetChildAtIndex(idx); - if (!child_sp) - continue; - child_sp = child_sp->GetQualifiedRepresentationIfAvailable(lldb::eDynamicDontRunTarget, true); - - const char* child_value = child_sp->GetValueAsCString(); - if (child_value && *child_value) - { - if (first) - { - s.Printf("%s", child_value); - first = false; - } - else - { - s.Printf(", %s", child_value); - } - } +bool lldb_private::formatters::VectorTypeSummaryProvider( + ValueObject &valobj, Stream &s, const TypeSummaryOptions &) { + auto synthetic_children = + VectorTypeSyntheticFrontEndCreator(nullptr, valobj.GetSP()); + if (!synthetic_children) + return false; + + synthetic_children->Update(); + + s.PutChar('('); + bool first = true; + + size_t idx = 0, len = synthetic_children->CalculateNumChildren(); + + for (; idx < len; idx++) { + auto child_sp = synthetic_children->GetChildAtIndex(idx); + if (!child_sp) + continue; + child_sp = child_sp->GetQualifiedRepresentationIfAvailable( + lldb::eDynamicDontRunTarget, true); + + const char *child_value = child_sp->GetValueAsCString(); + if (child_value && *child_value) { + if (first) { + s.Printf("%s", child_value); + first = false; + } else { + s.Printf(", %s", child_value); + } } - - s.PutChar(')'); - - return true; + } + + s.PutChar(')'); + + return true; } -lldb_private::SyntheticChildrenFrontEnd* -lldb_private::formatters::VectorTypeSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP valobj_sp) -{ - if (!valobj_sp) - return nullptr; - return new VectorTypeSyntheticFrontEnd(valobj_sp); +lldb_private::SyntheticChildrenFrontEnd * +lldb_private::formatters::VectorTypeSyntheticFrontEndCreator( + CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) { + if (!valobj_sp) + return nullptr; + return new VectorTypeSyntheticFrontEnd(valobj_sp); } |