diff options
Diffstat (limited to 'include/lldb/DataFormatters')
19 files changed, 1880 insertions, 1317 deletions
diff --git a/include/lldb/DataFormatters/CXXFormatterFunctions.h b/include/lldb/DataFormatters/CXXFormatterFunctions.h deleted file mode 100644 index a175e1a4d1641..0000000000000 --- a/include/lldb/DataFormatters/CXXFormatterFunctions.h +++ /dev/null @@ -1,375 +0,0 @@ -//===-- CXXFormatterFunctions.h------------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef liblldb_CXXFormatterFunctions_h_ -#define liblldb_CXXFormatterFunctions_h_ - -#include <stdint.h> -#include <time.h> - -#include "lldb/lldb-forward.h" - -#include "lldb/Core/ConstString.h" -#include "lldb/DataFormatters/FormatClasses.h" -#include "lldb/DataFormatters/TypeSynthetic.h" -#include "lldb/DataFormatters/VectorType.h" -#include "lldb/Target/ExecutionContext.h" -#include "lldb/Target/ObjCLanguageRuntime.h" -#include "lldb/Target/Target.h" - -#include "clang/AST/ASTContext.h" - -namespace lldb_private { - namespace formatters - { - StackFrame* - GetViableFrame (ExecutionContext exe_ctx); - - bool - ExtractValueFromObjCExpression (ValueObject &valobj, - const char* target_type, - const char* selector, - uint64_t &value); - - bool - ExtractSummaryFromObjCExpression (ValueObject &valobj, - const char* target_type, - const char* selector, - Stream &stream); - - lldb::ValueObjectSP - CallSelectorOnObject (ValueObject &valobj, - const char* return_type, - const char* selector, - uint64_t index); - - lldb::ValueObjectSP - CallSelectorOnObject (ValueObject &valobj, - const char* return_type, - const char* selector, - const char* key); - - size_t - ExtractIndexFromString (const char* item_name); - - time_t - GetOSXEpoch (); - - bool - FunctionPointerSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); // C++ function pointer - - bool - Char16StringSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); // char16_t* and unichar* - - bool - Char32StringSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); // char32_t* - - bool - WCharStringSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); // wchar_t* - - bool - Char16SummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); // char16_t and unichar - - bool - Char32SummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); // char32_t - - bool - WCharSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); // wchar_t - - bool - LibcxxStringSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); // libc++ std::string - - bool - LibcxxWStringSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); // libc++ std::wstring - - bool - LibcxxSmartPointerSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); // libc++ std::shared_ptr<> and std::weak_ptr<> - - bool - ObjCClassSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); - - SyntheticChildrenFrontEnd* ObjCClassSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP); - - template<bool name_entries> - bool - NSDictionarySummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); - - bool - NSIndexSetSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); - - bool - NSArraySummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); - - template<bool cf_style> - bool - NSSetSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); - - template<bool needs_at> - bool - NSDataSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); - - bool - NSNumberSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); - - bool - NSNotificationSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); - - bool - NSTimeZoneSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); - - bool - NSMachPortSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); - - bool - CFBagSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); - - bool - CFBinaryHeapSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); - - bool - CFBitVectorSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); - - bool - NSDateSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); - - bool - CFAbsoluteTimeSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); - - bool - NSBundleSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); - - bool - NSStringSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); - - bool - NSTaggedString_SummaryProvider (ObjCLanguageRuntime::ClassDescriptorSP descriptor, Stream& stream); - - bool - NSAttributedStringSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); - - bool - NSMutableAttributedStringSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); - - bool - NSURLSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); - - bool - ObjCBOOLSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); - - template <bool is_sel_ptr> - bool - ObjCSELSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); - - bool - RuntimeSpecificDescriptionSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); - - extern template bool - NSDictionarySummaryProvider<true> (ValueObject&, Stream&, const TypeSummaryOptions&) ; - - extern template bool - NSDictionarySummaryProvider<false> (ValueObject&, Stream&, const TypeSummaryOptions&) ; - - extern template bool - NSDataSummaryProvider<true> (ValueObject&, Stream&, const TypeSummaryOptions&) ; - - extern template bool - NSDataSummaryProvider<false> (ValueObject&, Stream&, const TypeSummaryOptions&) ; - - extern template bool - ObjCSELSummaryProvider<true> (ValueObject&, Stream&, const TypeSummaryOptions&); - - extern template bool - ObjCSELSummaryProvider<false> (ValueObject&, Stream&, const TypeSummaryOptions&); - - bool - CMTimeSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); - - SyntheticChildrenFrontEnd* NSArraySyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP); - - SyntheticChildrenFrontEnd* NSDictionarySyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP); - - SyntheticChildrenFrontEnd* NSSetSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP); - - SyntheticChildrenFrontEnd* NSIndexPathSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP); - - class LibcxxVectorBoolSyntheticFrontEnd : public SyntheticChildrenFrontEnd - { - public: - LibcxxVectorBoolSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp); - - virtual size_t - CalculateNumChildren (); - - virtual lldb::ValueObjectSP - GetChildAtIndex (size_t idx); - - virtual bool - Update(); - - virtual bool - MightHaveChildren (); - - virtual size_t - GetIndexOfChildWithName (const ConstString &name); - - virtual - ~LibcxxVectorBoolSyntheticFrontEnd (); - private: - ClangASTType m_bool_type; - ExecutionContextRef m_exe_ctx_ref; - uint64_t m_count; - lldb::addr_t m_base_data_address; - std::map<size_t,lldb::ValueObjectSP> m_children; - }; - - SyntheticChildrenFrontEnd* LibcxxVectorBoolSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP); - - bool - LibcxxContainerSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); - - class LibstdcppMapIteratorSyntheticFrontEnd : public SyntheticChildrenFrontEnd - { - public: - LibstdcppMapIteratorSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp); - - virtual size_t - CalculateNumChildren (); - - virtual lldb::ValueObjectSP - GetChildAtIndex (size_t idx); - - virtual bool - Update(); - - virtual bool - MightHaveChildren (); - - virtual size_t - GetIndexOfChildWithName (const ConstString &name); - - virtual - ~LibstdcppMapIteratorSyntheticFrontEnd (); - private: - ExecutionContextRef m_exe_ctx_ref; - lldb::addr_t m_pair_address; - ClangASTType m_pair_type; - EvaluateExpressionOptions m_options; - lldb::ValueObjectSP m_pair_sp; - }; - - SyntheticChildrenFrontEnd* LibstdcppMapIteratorSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP); - - class LibCxxMapIteratorSyntheticFrontEnd : public SyntheticChildrenFrontEnd - { - public: - LibCxxMapIteratorSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp); - - virtual size_t - CalculateNumChildren (); - - virtual lldb::ValueObjectSP - GetChildAtIndex (size_t idx); - - virtual bool - Update(); - - virtual bool - MightHaveChildren (); - - virtual size_t - GetIndexOfChildWithName (const ConstString &name); - - virtual - ~LibCxxMapIteratorSyntheticFrontEnd (); - private: - ValueObject *m_pair_ptr; - }; - - SyntheticChildrenFrontEnd* LibCxxMapIteratorSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP); - - class VectorIteratorSyntheticFrontEnd : public SyntheticChildrenFrontEnd - { - public: - VectorIteratorSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp, - ConstString item_name); - - virtual size_t - CalculateNumChildren (); - - virtual lldb::ValueObjectSP - GetChildAtIndex (size_t idx); - - virtual bool - Update(); - - virtual bool - MightHaveChildren (); - - virtual size_t - GetIndexOfChildWithName (const ConstString &name); - - virtual - ~VectorIteratorSyntheticFrontEnd (); - private: - ExecutionContextRef m_exe_ctx_ref; - ConstString m_item_name; - lldb::ValueObjectSP m_item_sp; - }; - - SyntheticChildrenFrontEnd* LibCxxVectorIteratorSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP); - - SyntheticChildrenFrontEnd* LibStdcppVectorIteratorSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP); - - class LibcxxSharedPtrSyntheticFrontEnd : public SyntheticChildrenFrontEnd - { - public: - LibcxxSharedPtrSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp); - - virtual size_t - CalculateNumChildren (); - - virtual lldb::ValueObjectSP - GetChildAtIndex (size_t idx); - - virtual bool - Update(); - - virtual bool - MightHaveChildren (); - - virtual size_t - GetIndexOfChildWithName (const ConstString &name); - - virtual - ~LibcxxSharedPtrSyntheticFrontEnd (); - private: - ValueObject* m_cntrl; - lldb::ValueObjectSP m_count_sp; - lldb::ValueObjectSP m_weak_count_sp; - uint8_t m_ptr_size; - lldb::ByteOrder m_byte_order; - }; - - SyntheticChildrenFrontEnd* LibcxxSharedPtrSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP); - - SyntheticChildrenFrontEnd* LibcxxStdVectorSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP); - - SyntheticChildrenFrontEnd* LibcxxStdListSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP); - - SyntheticChildrenFrontEnd* LibcxxStdMapSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP); - - SyntheticChildrenFrontEnd* LibcxxStdUnorderedMapSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP); - - SyntheticChildrenFrontEnd* LibcxxInitializerListSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP); - - SyntheticChildrenFrontEnd* VectorTypeSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP); - } // namespace formatters -} // namespace lldb_private - -#endif // liblldb_CXXFormatterFunctions_h_ diff --git a/include/lldb/DataFormatters/CXXFunctionPointer.h b/include/lldb/DataFormatters/CXXFunctionPointer.h new file mode 100644 index 0000000000000..eaa39582eaaaa --- /dev/null +++ b/include/lldb/DataFormatters/CXXFunctionPointer.h @@ -0,0 +1,23 @@ +//===-- CXXFunctionPointer.h ------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_CXXFunctionPointer_h_ +#define liblldb_CXXFunctionPointer_h_ + +#include "lldb/lldb-forward.h" + +namespace lldb_private { + namespace formatters + { + bool + CXXFunctionPointerSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); + } // namespace formatters +} // namespace lldb_private + +#endif // liblldb_CXXFunctionPointer_h_ diff --git a/include/lldb/DataFormatters/DataVisualization.h b/include/lldb/DataFormatters/DataVisualization.h index a0b2e58bba288..856156670c96f 100644 --- a/include/lldb/DataFormatters/DataVisualization.h +++ b/include/lldb/DataFormatters/DataVisualization.h @@ -1,4 +1,4 @@ -//===-- DataVisualization.h ----------------------------------------*- C++ -*-===// +//===-- DataVisualization.h -------------------------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -28,7 +28,6 @@ namespace lldb_private { class DataVisualization { public: - // use this call to force the FM to consider itself updated even when there is no apparent reason for that static void ForceUpdate(); @@ -83,8 +82,8 @@ public: AnyMatches(ConstString type_name, TypeCategoryImpl::FormatCategoryItems items = TypeCategoryImpl::ALL_ITEM_TYPES, bool only_enabled = true, - const char** matching_category = NULL, - TypeCategoryImpl::FormatCategoryItems* matching_type = NULL); + const char** matching_category = nullptr, + TypeCategoryImpl::FormatCategoryItems* matching_type = nullptr); class NamedSummaryFormats { @@ -102,7 +101,7 @@ public: Clear (); static void - LoopThrough (TypeSummaryImpl::SummaryCallback callback, void* callback_baton); + ForEach (std::function<bool(ConstString, const lldb::TypeSummaryImplSP&)> callback); static uint32_t GetCount (); @@ -111,12 +110,15 @@ public: class Categories { public: - static bool GetCategory (const ConstString &category, lldb::TypeCategoryImplSP &entry, bool allow_create = true); + static bool + GetCategory (lldb::LanguageType language, + lldb::TypeCategoryImplSP &entry); + static void Add (const ConstString &category); @@ -134,7 +136,13 @@ public: TypeCategoryMap::Position = TypeCategoryMap::Default); static void + Enable (lldb::LanguageType lang_type); + + static void Disable (const ConstString& category); + + static void + Disable (lldb::LanguageType lang_type); static void Enable (const lldb::TypeCategoryImplSP& category, @@ -150,7 +158,7 @@ public: DisableStar (); static void - LoopThrough (FormatManager::CategoryCallback callback, void* callback_baton); + ForEach (TypeCategoryMap::ForEachCallback callback); static uint32_t GetCount (); @@ -160,7 +168,6 @@ public: }; }; - } // namespace lldb_private -#endif // lldb_DataVisualization_h_ +#endif// lldb_DataVisualization_h_ diff --git a/include/lldb/DataFormatters/DumpValueObjectOptions.h b/include/lldb/DataFormatters/DumpValueObjectOptions.h new file mode 100644 index 0000000000000..f65ee7b958452 --- /dev/null +++ b/include/lldb/DataFormatters/DumpValueObjectOptions.h @@ -0,0 +1,185 @@ +//===-- DumpValueObjectOptions.h --------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef lldb_DumpValueObjectOptions_h_ +#define lldb_DumpValueObjectOptions_h_ + +// C Includes +// C++ Includes +#include <string> + +// Other libraries and framework includes +// Project includes +#include "lldb/lldb-private.h" +#include "lldb/lldb-public.h" + +#include <functional> +#include <string> + +namespace lldb_private { + +class DumpValueObjectOptions +{ +public: + struct PointerDepth + { + enum class Mode + { + Always, + Formatters, + Default, + Never + } m_mode; + uint32_t m_count; + + PointerDepth + operator --() const + { + if (m_count > 0) + return PointerDepth {m_mode,m_count-1}; + return PointerDepth {m_mode,m_count}; + } + + bool + CanAllowExpansion () const; + + bool + CanAllowExpansion (bool is_root, + TypeSummaryImpl* entry, + ValueObject *valobj, + const std::string& summary); + }; + + typedef std::function<bool(ConstString, + ConstString, + const DumpValueObjectOptions &, + Stream&)> DeclPrintingHelper; + + static const DumpValueObjectOptions + DefaultOptions() + { + static DumpValueObjectOptions g_default_options; + + return g_default_options; + } + + DumpValueObjectOptions(); + + DumpValueObjectOptions (const DumpValueObjectOptions& rhs) = default; + + DumpValueObjectOptions (ValueObject& valobj); + + DumpValueObjectOptions& + SetMaximumPointerDepth(PointerDepth depth = {PointerDepth::Mode::Never,0}); + + DumpValueObjectOptions& + SetMaximumDepth(uint32_t depth = 0); + + DumpValueObjectOptions& + SetDeclPrintingHelper(DeclPrintingHelper helper); + + DumpValueObjectOptions& + SetShowTypes(bool show = false); + + DumpValueObjectOptions& + SetShowLocation(bool show = false); + + DumpValueObjectOptions& + SetUseObjectiveC(bool use = false); + + DumpValueObjectOptions& + SetShowSummary(bool show = true); + + DumpValueObjectOptions& + SetUseDynamicType(lldb::DynamicValueType dyn = lldb::eNoDynamicValues); + + DumpValueObjectOptions& + SetUseSyntheticValue(bool use_synthetic = true); + + DumpValueObjectOptions& + SetScopeChecked(bool check = true); + + DumpValueObjectOptions& + SetFlatOutput(bool flat = false); + + DumpValueObjectOptions& + SetOmitSummaryDepth(uint32_t depth = 0); + + DumpValueObjectOptions& + SetIgnoreCap(bool ignore = false); + + DumpValueObjectOptions& + SetRawDisplay(); + + DumpValueObjectOptions& + SetFormat (lldb::Format format = lldb::eFormatDefault); + + DumpValueObjectOptions& + SetSummary (lldb::TypeSummaryImplSP summary = lldb::TypeSummaryImplSP()); + + DumpValueObjectOptions& + SetRootValueObjectName(const char* name = nullptr); + + DumpValueObjectOptions& + SetHideRootType (bool hide_root_type = false); + + DumpValueObjectOptions& + SetHideName (bool hide_name = false); + + DumpValueObjectOptions& + SetHideValue (bool hide_value = false); + + DumpValueObjectOptions& + SetHidePointerValue (bool hide = false); + + DumpValueObjectOptions& + SetVariableFormatDisplayLanguage (lldb::LanguageType lang = lldb::eLanguageTypeUnknown); + + DumpValueObjectOptions& + SetRunValidator (bool run = true); + + DumpValueObjectOptions& + SetUseTypeDisplayName (bool dis = false); + + DumpValueObjectOptions& + SetAllowOnelinerMode (bool oneliner = false); + + DumpValueObjectOptions& + SetRevealEmptyAggregates (bool reveal = true); + +public: + uint32_t m_max_depth = UINT32_MAX; + lldb::DynamicValueType m_use_dynamic = lldb::eNoDynamicValues; + uint32_t m_omit_summary_depth = 0; + lldb::Format m_format = lldb::eFormatDefault; + lldb::TypeSummaryImplSP m_summary_sp; + std::string m_root_valobj_name; + lldb::LanguageType m_varformat_language = lldb::eLanguageTypeUnknown; + PointerDepth m_max_ptr_depth; + DeclPrintingHelper m_decl_printing_helper; + bool m_use_synthetic : 1; + bool m_scope_already_checked : 1; + bool m_flat_output : 1; + bool m_ignore_cap : 1; + bool m_show_types : 1; + bool m_show_location : 1; + bool m_use_objc : 1; + bool m_hide_root_type : 1; + bool m_hide_name : 1; + bool m_hide_value : 1; + bool m_run_validator : 1; + bool m_use_type_display_name : 1; + bool m_allow_oneliner_mode : 1; + bool m_hide_pointer_value : 1; + bool m_reveal_empty_aggregates : 1; +}; + +} // namespace lldb_private + +#endif // lldb_DumpValueObjectOptions_h_ diff --git a/include/lldb/DataFormatters/FormatCache.h b/include/lldb/DataFormatters/FormatCache.h index fa46306e54042..9f1e078f71990 100644 --- a/include/lldb/DataFormatters/FormatCache.h +++ b/include/lldb/DataFormatters/FormatCache.h @@ -19,7 +19,6 @@ #include "lldb/lldb-public.h" #include "lldb/Core/ConstString.h" #include "lldb/Host/Mutex.h" -#include "lldb/DataFormatters/FormatClasses.h" namespace lldb_private { class FormatCache diff --git a/include/lldb/DataFormatters/FormatClasses.h b/include/lldb/DataFormatters/FormatClasses.h index 651160371c69b..b5ac41c2bd6e7 100644 --- a/include/lldb/DataFormatters/FormatClasses.h +++ b/include/lldb/DataFormatters/FormatClasses.h @@ -10,25 +10,45 @@ #ifndef lldb_FormatClasses_h_ #define lldb_FormatClasses_h_ +// C Includes // C++ Includes +#include <functional> +#include <memory> #include <string> #include <vector> // Other libraries and framework includes - // Project includes #include "lldb/lldb-public.h" #include "lldb/lldb-enumerations.h" - -#include "lldb/Symbol/ClangASTType.h" +#include "lldb/DataFormatters/TypeFormat.h" +#include "lldb/DataFormatters/TypeSummary.h" +#include "lldb/DataFormatters/TypeSynthetic.h" +#include "lldb/DataFormatters/TypeValidator.h" +#include "lldb/Symbol/CompilerType.h" #include "lldb/Symbol/Type.h" namespace lldb_private { +class HardcodedFormatters { +public: + template <typename FormatterType> + using HardcodedFormatterFinder = std::function<typename FormatterType::SharedPointer (lldb_private::ValueObject&, + lldb::DynamicValueType, + FormatManager&)>; + + template <typename FormatterType> + using HardcodedFormatterFinders = std::vector<HardcodedFormatterFinder<FormatterType>>; + + typedef HardcodedFormatterFinders<TypeFormatImpl> HardcodedFormatFinder; + typedef HardcodedFormatterFinders<TypeSummaryImpl> HardcodedSummaryFinder; + typedef HardcodedFormatterFinders<SyntheticChildren> HardcodedSyntheticFinder; + typedef HardcodedFormatterFinders<TypeValidatorImpl> HardcodedValidatorFinder; +}; + class FormattersMatchCandidate { public: - FormattersMatchCandidate (ConstString name, uint32_t reason, bool strip_ptr, @@ -41,10 +61,9 @@ public: m_stripped_typedef(strip_tydef) { } - - ~FormattersMatchCandidate () - {} - + + ~FormattersMatchCandidate() = default; + ConstString GetTypeName () const { @@ -99,6 +118,36 @@ private: }; typedef std::vector<FormattersMatchCandidate> FormattersMatchVector; +typedef std::vector<lldb::LanguageType> CandidateLanguagesVector; + +class FormattersMatchData +{ +public: + FormattersMatchData (ValueObject&, + lldb::DynamicValueType); + + FormattersMatchVector + GetMatchesVector (); + + ConstString + GetTypeForCache (); + + CandidateLanguagesVector + GetCandidateLanguages (); + + ValueObject& + GetValueObject (); + + lldb::DynamicValueType + GetDynamicValueType (); + +private: + ValueObject& m_valobj; + lldb::DynamicValueType m_dynamic_value_type; + std::pair<FormattersMatchVector,bool> m_formatters_match_vector; + ConstString m_type_for_cache; + CandidateLanguagesVector m_candidate_languages; +}; class TypeNameSpecifierImpl { @@ -130,7 +179,7 @@ public: } } - TypeNameSpecifierImpl (ClangASTType type) : + TypeNameSpecifierImpl (CompilerType type) : m_is_regex(false), m_type() { @@ -146,7 +195,7 @@ public: { if (m_type.m_type_name.size()) return m_type.m_type_name.c_str(); - return NULL; + return nullptr; } lldb::TypeSP @@ -157,12 +206,12 @@ public: return lldb::TypeSP(); } - ClangASTType - GetClangASTType () + CompilerType + GetCompilerType () { if (m_type.m_type_pair.IsValid()) - return m_type.m_type_pair.GetClangASTType(); - return ClangASTType(); + return m_type.m_type_pair.GetCompilerType(); + return CompilerType(); } bool @@ -174,19 +223,18 @@ public: private: bool m_is_regex; // this works better than TypeAndOrName because the latter only wraps a TypeSP - // whereas TypePair can also be backed by a ClangASTType + // whereas TypePair can also be backed by a CompilerType struct TypeOrName { std::string m_type_name; TypePair m_type_pair; }; TypeOrName m_type; - - + private: DISALLOW_COPY_AND_ASSIGN(TypeNameSpecifierImpl); }; } // namespace lldb_private -#endif // lldb_FormatClasses_h_ +#endif // lldb_FormatClasses_h_ diff --git a/include/lldb/DataFormatters/FormatManager.h b/include/lldb/DataFormatters/FormatManager.h index a1f4b59fb3448..24ba5a7f0aa55 100644 --- a/include/lldb/DataFormatters/FormatManager.h +++ b/include/lldb/DataFormatters/FormatManager.h @@ -1,4 +1,4 @@ -//===-- FormatManager.h -------------------------------------------*- C++ -*-===// +//===-- FormatManager.h -----------------------------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -12,6 +12,10 @@ // C Includes // C++ Includes +#include <atomic> +#include <initializer_list> +#include <map> +#include <vector> // Other libraries and framework includes // Project includes @@ -21,12 +25,10 @@ #include "lldb/DataFormatters/FormatCache.h" #include "lldb/DataFormatters/FormatClasses.h" #include "lldb/DataFormatters/FormattersContainer.h" +#include "lldb/DataFormatters/LanguageCategory.h" #include "lldb/DataFormatters/TypeCategory.h" #include "lldb/DataFormatters/TypeCategoryMap.h" -#include <atomic> -#include <functional> - namespace lldb_private { // this file (and its. cpp) contain the low-level implementation of LLDB Data Visualization @@ -39,19 +41,12 @@ class FormatManager : public IFormatChangeListener typedef FormatMap<ConstString, TypeSummaryImpl> NamedSummariesMap; typedef TypeCategoryMap::MapType::iterator CategoryMapIterator; public: + typedef std::map<lldb::LanguageType, LanguageCategory::UniquePointer> LanguageCategories; - template <typename FormatterType> - using HardcodedFormatterFinder = std::function<typename FormatterType::SharedPointer (lldb_private::ValueObject&, - lldb::DynamicValueType, - FormatManager&)>; - - template <typename FormatterType> - using HardcodedFormatterFinders = std::vector<HardcodedFormatterFinder<FormatterType>>; - - typedef TypeCategoryMap::CallbackType CategoryCallback; - - FormatManager (); + FormatManager(); + ~FormatManager() override = default; + NamedSummariesMap& GetNamedSummaryContainer () { @@ -62,8 +57,34 @@ public: EnableCategory (const ConstString& category_name, TypeCategoryMap::Position pos = TypeCategoryMap::Default) { - m_categories_map.Enable(category_name, - pos); + EnableCategory(category_name, + pos, + std::initializer_list<lldb::LanguageType>()); + } + + void + EnableCategory (const ConstString& category_name, + TypeCategoryMap::Position pos, + lldb::LanguageType lang) + { + std::initializer_list<lldb::LanguageType> langs = {lang}; + EnableCategory(category_name, + pos, + langs); + } + + void + EnableCategory (const ConstString& category_name, + TypeCategoryMap::Position pos = TypeCategoryMap::Default, + std::initializer_list<lldb::LanguageType> langs = {}) + { + TypeCategoryMap::ValueSP category_sp; + if (m_categories_map.Get(category_name, category_sp) && category_sp) + { + m_categories_map.Enable(category_sp, pos); + for (const lldb::LanguageType lang : langs) + category_sp->AddLanguage(lang); + } } void @@ -87,16 +108,10 @@ public: } void - EnableAllCategories () - { - m_categories_map.EnableAllCategories (); - } + EnableAllCategories (); void - DisableAllCategories () - { - m_categories_map.DisableAllCategories (); - } + DisableAllCategories (); bool DeleteCategory (const ConstString& category_name) @@ -123,14 +138,11 @@ public: } void - LoopThroughCategories (CategoryCallback callback, void* param) - { - m_categories_map.LoopThrough(callback, param); - } + ForEachCategory (TypeCategoryMap::ForEachCallback callback); lldb::TypeCategoryImplSP - GetCategory (const char* category_name = NULL, - bool can_create = true) + GetCategory(const char* category_name = nullptr, + bool can_create = true) { if (!category_name) return GetCategory(m_default_category_name); @@ -182,11 +194,11 @@ public: lldb::DynamicValueType use_dynamic); bool - AnyMatches (ConstString type_name, - TypeCategoryImpl::FormatCategoryItems items = TypeCategoryImpl::ALL_ITEM_TYPES, - bool only_enabled = true, - const char** matching_category = NULL, - TypeCategoryImpl::FormatCategoryItems* matching_type = NULL) + AnyMatches(ConstString type_name, + TypeCategoryImpl::FormatCategoryItems items = TypeCategoryImpl::ALL_ITEM_TYPES, + bool only_enabled = true, + const char** matching_category = nullptr, + TypeCategoryImpl::FormatCategoryItems* matching_type = nullptr) { return m_categories_map.AnyMatches(type_name, items, @@ -226,29 +238,21 @@ public: ShouldPrintAsOneLiner (ValueObject& valobj); void - Changed () - { - ++m_last_revision; - m_format_cache.Clear (); - } + Changed () override; uint32_t - GetCurrentRevision () + GetCurrentRevision () override { return m_last_revision; } - - ~FormatManager () - { - } - + static FormattersMatchVector GetPossibleMatches (ValueObject& valobj, lldb::DynamicValueType use_dynamic) { FormattersMatchVector matches; GetPossibleMatches (valobj, - valobj.GetClangType(), + valobj.GetCompilerType(), lldb_private::eFormatterChoiceCriterionDirectChoice, use_dynamic, matches, @@ -258,12 +262,23 @@ public: true); return matches; } + + static ConstString + GetTypeForCache (ValueObject&, lldb::DynamicValueType); + + LanguageCategory* + GetCategoryForLanguage (lldb::LanguageType lang_type); + + static std::vector<lldb::LanguageType> + GetCandidateLanguages (lldb::LanguageType lang_type); private: + static std::vector<lldb::LanguageType> + GetCandidateLanguages (ValueObject& valobj); static void GetPossibleMatches (ValueObject& valobj, - ClangASTType clang_type, + CompilerType compiler_type, uint32_t reason, lldb::DynamicValueType use_dynamic, FormattersMatchVector& entries, @@ -271,40 +286,29 @@ private: bool did_strip_ref, bool did_strip_typedef, bool root_level = false); - + + std::atomic<uint32_t> m_last_revision; FormatCache m_format_cache; + Mutex m_language_categories_mutex; + LanguageCategories m_language_categories_map; NamedSummariesMap m_named_summaries_map; - std::atomic<uint32_t> m_last_revision; TypeCategoryMap m_categories_map; ConstString m_default_category_name; ConstString m_system_category_name; - ConstString m_gnu_cpp_category_name; - ConstString m_libcxx_category_name; - ConstString m_objc_category_name; - ConstString m_corefoundation_category_name; - ConstString m_coregraphics_category_name; - ConstString m_coreservices_category_name; ConstString m_vectortypes_category_name; - ConstString m_appkit_category_name; - ConstString m_coremedia_category_name; - - HardcodedFormatterFinders<TypeFormatImpl> m_hardcoded_formats; - HardcodedFormatterFinders<TypeSummaryImpl> m_hardcoded_summaries; - HardcodedFormatterFinders<SyntheticChildren> m_hardcoded_synthetics; - HardcodedFormatterFinders<TypeValidatorImpl> m_hardcoded_validators; lldb::TypeFormatImplSP - GetHardcodedFormat (ValueObject&,lldb::DynamicValueType); + GetHardcodedFormat (FormattersMatchData&); lldb::TypeSummaryImplSP - GetHardcodedSummaryFormat (ValueObject&,lldb::DynamicValueType); + GetHardcodedSummaryFormat (FormattersMatchData&); lldb::SyntheticChildrenSP - GetHardcodedSyntheticChildren (ValueObject&,lldb::DynamicValueType); + GetHardcodedSyntheticChildren (FormattersMatchData&); lldb::TypeValidatorImplSP - GetHardcodedValidator (ValueObject&,lldb::DynamicValueType); + GetHardcodedValidator (FormattersMatchData&); TypeCategoryMap& GetCategories () @@ -312,29 +316,20 @@ private: return m_categories_map; } - // WARNING: these are temporary functions that setup formatters - // while a few of these actually should be globally available and setup by LLDB itself - // most would actually belong to the users' lldbinit file or to some other form of configurable - // storage - void - LoadLibStdcppFormatters (); - - void - LoadLibcxxFormatters (); - + // These functions are meant to initialize formatters that are very low-level/global in nature + // and do not naturally belong in any language. The intent is that most formatters go in + // language-specific categories. Eventually, the runtimes should also be allowed to vend their + // own formatters, and then one could put formatters that depend on specific library load events + // in the language runtimes, on an as-needed basis void LoadSystemFormatters (); void - LoadObjCFormatters (); - - void - LoadCoreMediaFormatters (); + LoadVectorFormatters (); - void - LoadHardcodedFormatters (); + friend class FormattersMatchData; }; } // namespace lldb_private -#endif // lldb_FormatManager_h_ +#endif // lldb_FormatManager_h_ diff --git a/include/lldb/DataFormatters/FormattersContainer.h b/include/lldb/DataFormatters/FormattersContainer.h index daf2f24ae3e55..dcd08211f19b8 100644 --- a/include/lldb/DataFormatters/FormattersContainer.h +++ b/include/lldb/DataFormatters/FormattersContainer.h @@ -1,4 +1,4 @@ -//===-- FormattersContainer.h ----------------------------------------*- C++ -*-===// +//===-- FormattersContainer.h -----------------------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -12,53 +12,38 @@ // C Includes // C++ Includes +#include <functional> +#include <map> +#include <memory> +#include <string> // Other libraries and framework includes -#include "clang/AST/DeclCXX.h" -#include "clang/AST/Type.h" -#include "clang/AST/DeclObjC.h" - // Project includes #include "lldb/lldb-public.h" -#include "lldb/Core/Log.h" #include "lldb/Core/RegularExpression.h" #include "lldb/Core/ValueObject.h" - #include "lldb/DataFormatters/FormatClasses.h" #include "lldb/DataFormatters/TypeFormat.h" #include "lldb/DataFormatters/TypeSummary.h" #include "lldb/DataFormatters/TypeSynthetic.h" #include "lldb/DataFormatters/TypeValidator.h" - -#include "lldb/Symbol/ClangASTContext.h" -#include "lldb/Symbol/ClangASTType.h" - -#include "lldb/Target/ObjCLanguageRuntime.h" -#include "lldb/Target/Process.h" -#include "lldb/Target/StackFrame.h" -#include "lldb/Target/TargetList.h" - +#include "lldb/Symbol/CompilerType.h" #include "lldb/Utility/StringLexer.h" namespace lldb_private { -// this file (and its. cpp) contain the low-level implementation of LLDB Data Visualization -// class DataVisualization is the high-level front-end of this feature -// clients should refer to that class as the entry-point into the data formatters -// unless they have a good reason to bypass it and prefer to use this file's objects directly class IFormatChangeListener { public: + virtual + ~IFormatChangeListener() = default; + virtual void Changed () = 0; - - virtual - ~IFormatChangeListener () {} - + virtual uint32_t GetCurrentRevision () = 0; - }; // if the user tries to add formatters for, say, "struct Foo" @@ -92,11 +77,10 @@ template<typename KeyType, typename ValueType> class FormatMap { public: - typedef typename ValueType::SharedPointer ValueSP; typedef std::map<KeyType, ValueSP> MapType; typedef typename MapType::iterator MapIterator; - typedef bool(*CallbackType)(void*, KeyType, const ValueSP&); + typedef std::function<bool(KeyType, const ValueSP&)> ForEachCallback; FormatMap(IFormatChangeListener* lst) : m_map(), @@ -155,7 +139,7 @@ public: } void - LoopThrough (CallbackType callback, void* param) + ForEach (ForEachCallback callback) { if (callback) { @@ -164,7 +148,7 @@ public: for (pos = m_map.begin(); pos != end; pos++) { KeyType type = pos->first; - if (!callback(param, type, pos->second)) + if (!callback(type, pos->second)) break; } } @@ -227,7 +211,6 @@ protected: friend class FormattersContainer<KeyType, ValueType>; friend class FormatManager; - }; template<typename KeyType, typename ValueType> @@ -241,7 +224,7 @@ public: typedef typename MapType::iterator MapIterator; typedef typename MapType::key_type MapKeyType; typedef typename MapType::mapped_type MapValueType; - typedef typename BackEndType::CallbackType CallbackType; + typedef typename BackEndType::ForEachCallback ForEachCallback; typedef typename std::shared_ptr<FormattersContainer<KeyType, ValueType> > SharedPointer; friend class TypeCategoryImpl; @@ -256,23 +239,23 @@ public: void Add (const MapKeyType &type, const MapValueType& entry) { - Add_Impl(type, entry, (KeyType*)NULL); + Add_Impl(type, entry, static_cast<KeyType*>(nullptr)); } bool Delete (ConstString type) { - return Delete_Impl(type, (KeyType*)NULL); + return Delete_Impl(type, static_cast<KeyType*>(nullptr)); } bool Get(ValueObject& valobj, MapValueType& entry, lldb::DynamicValueType use_dynamic, - uint32_t* why = NULL) + uint32_t* why = nullptr) { uint32_t value = lldb_private::eFormatterChoiceCriterionDirectChoice; - ClangASTType ast_type(valobj.GetClangType()); + CompilerType ast_type(valobj.GetCompilerType()); bool ret = Get(valobj, ast_type, entry, use_dynamic, value); if (ret) entry = MapValueType(entry); @@ -286,13 +269,13 @@ public: bool Get (ConstString type, MapValueType& entry) { - return Get_Impl(type, entry, (KeyType*)NULL); + return Get_Impl(type, entry, static_cast<KeyType*>(nullptr)); } bool GetExact (ConstString type, MapValueType& entry) { - return GetExact_Impl(type, entry, (KeyType*)NULL); + return GetExact_Impl(type, entry, static_cast<KeyType*>(nullptr)); } MapValueType @@ -304,7 +287,7 @@ public: lldb::TypeNameSpecifierImplSP GetTypeNameSpecifierAtIndex (size_t index) { - return GetTypeNameSpecifierAtIndex_Impl(index, (KeyType*)NULL); + return GetTypeNameSpecifierAtIndex_Impl(index, static_cast<KeyType*>(nullptr)); } void @@ -314,9 +297,9 @@ public: } void - LoopThrough (CallbackType callback, void* param) + ForEach (ForEachCallback callback) { - m_format_map.LoopThrough(callback,param); + m_format_map.ForEach(callback); } uint32_t @@ -377,7 +360,7 @@ protected: bool GetExact_Impl (ConstString type, MapValueType& entry, ConstString *dummy) { - return Get_Impl(type,entry, (KeyType*)0); + return Get_Impl(type, entry, static_cast<KeyType*>(nullptr)); } lldb::TypeNameSpecifierImplSP @@ -395,7 +378,7 @@ protected: GetTypeNameSpecifierAtIndex_Impl (size_t index, lldb::RegularExpressionSP *dummy) { lldb::RegularExpressionSP regex = m_format_map.GetKeyAtIndex(index); - if (regex.get() == NULL) + if (regex.get() == nullptr) return lldb::TypeNameSpecifierImplSP(); return lldb::TypeNameSpecifierImplSP(new TypeNameSpecifierImpl(regex->GetText(), true)); @@ -447,7 +430,6 @@ protected: { for (const FormattersMatchCandidate& candidate : candidates) { - // FIXME: could we do the IsMatch() check first? if (Get(candidate.GetTypeName(),entry)) { if (candidate.IsMatch(entry) == false) @@ -469,4 +451,4 @@ protected: } // namespace lldb_private -#endif // lldb_FormattersContainer_h_ +#endif // lldb_FormattersContainer_h_ diff --git a/include/lldb/DataFormatters/FormattersHelpers.h b/include/lldb/DataFormatters/FormattersHelpers.h new file mode 100644 index 0000000000000..4627a61e94f14 --- /dev/null +++ b/include/lldb/DataFormatters/FormattersHelpers.h @@ -0,0 +1,279 @@ +//===-- FormattersHelpers.h --------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef lldb_FormattersHelpers_h_ +#define lldb_FormattersHelpers_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/lldb-forward.h" +#include "lldb/lldb-enumerations.h" + +#include "lldb/DataFormatters/TypeCategory.h" +#include "lldb/DataFormatters/TypeFormat.h" +#include "lldb/DataFormatters/TypeSummary.h" +#include "lldb/DataFormatters/TypeSynthetic.h" + +namespace lldb_private { + namespace formatters { + void + AddFormat (TypeCategoryImpl::SharedPointer category_sp, + lldb::Format format, + ConstString type_name, + TypeFormatImpl::Flags flags, + bool regex = false); + + void + AddSummary(TypeCategoryImpl::SharedPointer category_sp, + lldb::TypeSummaryImplSP summary_sp, + ConstString type_name, + bool regex = false); + + void + AddStringSummary(TypeCategoryImpl::SharedPointer category_sp, + const char* string, + ConstString type_name, + TypeSummaryImpl::Flags flags, + bool regex = false); + + void + AddOneLineSummary (TypeCategoryImpl::SharedPointer category_sp, + ConstString type_name, + TypeSummaryImpl::Flags flags, + bool regex = false); + +#ifndef LLDB_DISABLE_PYTHON + void + AddCXXSummary (TypeCategoryImpl::SharedPointer category_sp, + CXXFunctionSummaryFormat::Callback funct, + const char* description, + ConstString type_name, + TypeSummaryImpl::Flags flags, + bool regex = false); + + void + AddCXXSynthetic (TypeCategoryImpl::SharedPointer category_sp, + CXXSyntheticChildren::CreateFrontEndCallback generator, + const char* description, + ConstString type_name, + ScriptedSyntheticChildren::Flags flags, + bool regex = false); + + void + AddFilter (TypeCategoryImpl::SharedPointer category_sp, + std::vector<std::string> children, + const char* description, + ConstString type_name, + ScriptedSyntheticChildren::Flags flags, + bool regex = false); +#endif + + StackFrame* + GetViableFrame (ExecutionContext exe_ctx); + + bool + ExtractValueFromObjCExpression (ValueObject &valobj, + const char* target_type, + const char* selector, + uint64_t &value); + + bool + ExtractSummaryFromObjCExpression (ValueObject &valobj, + const char* target_type, + const char* selector, + Stream &stream, + lldb::LanguageType lang_type); + + lldb::ValueObjectSP + CallSelectorOnObject (ValueObject &valobj, + const char* return_type, + const char* selector, + uint64_t index); + + lldb::ValueObjectSP + CallSelectorOnObject (ValueObject &valobj, + const char* return_type, + const char* selector, + const char* key); + + size_t + ExtractIndexFromString (const char* item_name); + + lldb::addr_t + GetArrayAddressOrPointerValue (ValueObject& valobj); + + time_t + GetOSXEpoch (); + + struct InferiorSizedWord { + + InferiorSizedWord(const InferiorSizedWord& word) : ptr_size(word.ptr_size) + { + if (ptr_size == 4) + thirty_two = word.thirty_two; + else + sixty_four = word.sixty_four; + } + + InferiorSizedWord + operator = (const InferiorSizedWord& word) + { + ptr_size = word.ptr_size; + if (ptr_size == 4) + thirty_two = word.thirty_two; + else + sixty_four = word.sixty_four; + return *this; + } + + InferiorSizedWord(uint64_t val, Process& process) : ptr_size(process.GetAddressByteSize()) + { + if (ptr_size == 4) + thirty_two = (uint32_t)val; + else if (ptr_size == 8) + sixty_four = val; + else + assert (false && "new pointer size is unknown"); + } + + bool + IsNegative () const + { + if (ptr_size == 4) + return ((int32_t)thirty_two) < 0; + else + return ((int64_t)sixty_four) < 0; + } + + bool + IsZero () const + { + if (ptr_size == 4) + return thirty_two == 0; + else + return sixty_four == 0; + } + + static InferiorSizedWord + GetMaximum (Process& process) + { + if (process.GetAddressByteSize() == 4) + return InferiorSizedWord(UINT32_MAX,4); + else + return InferiorSizedWord(UINT64_MAX,8); + } + + InferiorSizedWord + operator >> (int rhs) const + { + if (ptr_size == 4) + return InferiorSizedWord(thirty_two >> rhs,4); + return InferiorSizedWord(sixty_four>>rhs,8); + } + + InferiorSizedWord + operator << (int rhs) const + { + if (ptr_size == 4) + return InferiorSizedWord(thirty_two << rhs,4); + return InferiorSizedWord(sixty_four << rhs,8); + } + + InferiorSizedWord + operator & (const InferiorSizedWord& word) const + { + if (ptr_size != word.ptr_size) + return InferiorSizedWord(0,ptr_size); + if (ptr_size == 4) + return InferiorSizedWord(thirty_two & word.thirty_two,4); + return InferiorSizedWord(sixty_four & word.sixty_four,8); + } + + InferiorSizedWord + operator & (int x) const + { + if (ptr_size == 4) + return InferiorSizedWord(thirty_two & x,4); + return InferiorSizedWord(sixty_four & x,8); + } + + size_t + GetBitSize () const + { + return ptr_size << 3; + } + + size_t + GetByteSize () const + { + return ptr_size; + } + + uint64_t + GetValue () const + { + if (ptr_size == 4) + return (uint64_t)thirty_two; + return sixty_four; + } + + InferiorSizedWord + SignExtend () const + { + if (ptr_size == 4) + return InferiorSizedWord ((int32_t)thirty_two,4); + return InferiorSizedWord((int64_t)sixty_four,8); + } + + uint8_t* + CopyToBuffer (uint8_t* buffer) const + { + if (ptr_size == 4) + { + memcpy(buffer, &thirty_two, 4); + return buffer + 4; + } + else + { + memcpy(buffer, &sixty_four, 8); + return buffer + 8; + } + } + + DataExtractor + GetAsData (lldb::ByteOrder byte_order = lldb::eByteOrderInvalid) const + { + if (ptr_size == 4) + return DataExtractor(&thirty_two, 4, byte_order, 4); + else + return DataExtractor(&sixty_four, 8, byte_order, 8); + } + + private: + + InferiorSizedWord(uint64_t val, size_t psz) : ptr_size(psz) + { + if (ptr_size == 4) + thirty_two = (uint32_t)val; + else + sixty_four = val; + } + + size_t ptr_size; + union { + uint32_t thirty_two; + uint64_t sixty_four; + }; + }; + } // namespace formatters +} // namespace lldb_private + +#endif // lldb_FormattersHelpers_h_ diff --git a/include/lldb/DataFormatters/LanguageCategory.h b/include/lldb/DataFormatters/LanguageCategory.h new file mode 100644 index 0000000000000..a7040099f2137 --- /dev/null +++ b/include/lldb/DataFormatters/LanguageCategory.h @@ -0,0 +1,99 @@ +//===-- LanguageCategory.h----------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef lldb_LanguageCategory_h_ +#define lldb_LanguageCategory_h_ + +// C Includes +// C++ Includes + +// Other libraries and framework includes +// Project includes +#include "lldb/lldb-public.h" +#include "lldb/DataFormatters/FormatCache.h" +#include "lldb/DataFormatters/FormatClasses.h" + +#include <memory> + +namespace lldb_private { + +class LanguageCategory +{ +public: + typedef std::unique_ptr<LanguageCategory> UniquePointer; + + LanguageCategory (lldb::LanguageType lang_type); + + bool + Get (FormattersMatchData& match_data, + lldb::TypeFormatImplSP& format_sp); + + bool + Get (FormattersMatchData& match_data, + lldb::TypeSummaryImplSP& format_sp); + + bool + Get (FormattersMatchData& match_data, + lldb::SyntheticChildrenSP& format_sp); + + bool + Get (FormattersMatchData& match_data, + lldb::TypeValidatorImplSP& format_sp); + + bool + GetHardcoded (FormatManager& fmt_mgr, + FormattersMatchData& match_data, + lldb::TypeFormatImplSP& format_sp); + + bool + GetHardcoded (FormatManager& fmt_mgr, + FormattersMatchData& match_data, + lldb::TypeSummaryImplSP& format_sp); + + bool + GetHardcoded (FormatManager& fmt_mgr, + FormattersMatchData& match_data, + lldb::SyntheticChildrenSP& format_sp); + + bool + GetHardcoded (FormatManager& fmt_mgr, + FormattersMatchData& match_data, + lldb::TypeValidatorImplSP& format_sp); + + lldb::TypeCategoryImplSP + GetCategory () const; + + FormatCache& + GetFormatCache (); + + void + Enable (); + + void + Disable (); + + bool + IsEnabled (); + +private: + lldb::TypeCategoryImplSP m_category_sp; + + HardcodedFormatters::HardcodedFormatFinder m_hardcoded_formats; + HardcodedFormatters::HardcodedSummaryFinder m_hardcoded_summaries; + HardcodedFormatters::HardcodedSyntheticFinder m_hardcoded_synthetics; + HardcodedFormatters::HardcodedValidatorFinder m_hardcoded_validators; + + lldb_private::FormatCache m_format_cache; + + bool m_enabled; +}; + +} // namespace lldb_private + +#endif // lldb_LanguageCategory_h_ diff --git a/include/lldb/DataFormatters/StringPrinter.h b/include/lldb/DataFormatters/StringPrinter.h index 48e27ace5d920..a849c4e011094 100644 --- a/include/lldb/DataFormatters/StringPrinter.h +++ b/include/lldb/DataFormatters/StringPrinter.h @@ -10,6 +10,13 @@ #ifndef liblldb_StringPrinter_h_ #define liblldb_StringPrinter_h_ +// C Includes +// C++ Includes +#include <functional> +#include <string> + +// Other libraries and framework includes +// Project includes #include "lldb/lldb-forward.h" #include "lldb/Core/DataExtractor.h" @@ -17,273 +24,505 @@ namespace lldb_private { namespace formatters { - - enum class StringElementType { - ASCII, - UTF8, - UTF16, - UTF32 - }; - - class ReadStringAndDumpToStreamOptions + class StringPrinter { public: - - ReadStringAndDumpToStreamOptions () : - m_location(0), - m_process_sp(), - m_stream(NULL), - m_prefix_token(0), - m_quote('"'), - m_source_size(0), - m_needs_zero_termination(true), - m_escape_non_printables(true), - m_ignore_max_length(false) - { - } - - ReadStringAndDumpToStreamOptions (ValueObject& valobj); - - ReadStringAndDumpToStreamOptions& - SetLocation (uint64_t l) - { - m_location = l; - return *this; - } - - uint64_t - GetLocation () const - { - return m_location; - } - - ReadStringAndDumpToStreamOptions& - SetProcessSP (lldb::ProcessSP p) - { - m_process_sp = p; - return *this; - } - - lldb::ProcessSP - GetProcessSP () const - { - return m_process_sp; - } - - ReadStringAndDumpToStreamOptions& - SetStream (Stream* s) - { - m_stream = s; - return *this; - } - - Stream* - GetStream () const - { - return m_stream; - } - - ReadStringAndDumpToStreamOptions& - SetPrefixToken (char p) - { - m_prefix_token = p; - return *this; - } - - char - GetPrefixToken () const - { - return m_prefix_token; - } - - ReadStringAndDumpToStreamOptions& - SetQuote (char q) - { - m_quote = q; - return *this; - } - - char - GetQuote () const - { - return m_quote; - } - - ReadStringAndDumpToStreamOptions& - SetSourceSize (uint32_t s) - { - m_source_size = s; - return *this; - } - - uint32_t - GetSourceSize () const - { - return m_source_size; - } - - ReadStringAndDumpToStreamOptions& - SetNeedsZeroTermination (bool z) - { - m_needs_zero_termination = z; - return *this; - } - - bool - GetNeedsZeroTermination () const - { - return m_needs_zero_termination; - } - - ReadStringAndDumpToStreamOptions& - SetEscapeNonPrintables (bool e) - { - m_escape_non_printables = e; - return *this; - } - - bool - GetEscapeNonPrintables () const - { - return m_escape_non_printables; - } - - ReadStringAndDumpToStreamOptions& - SetIgnoreMaxLength (bool e) - { - m_ignore_max_length = e; - return *this; - } - - bool - GetIgnoreMaxLength () const - { - return m_ignore_max_length; - } - - private: - uint64_t m_location; - lldb::ProcessSP m_process_sp; - Stream* m_stream; - char m_prefix_token; - char m_quote; - uint32_t m_source_size; - bool m_needs_zero_termination; - bool m_escape_non_printables; - bool m_ignore_max_length; - }; - - class ReadBufferAndDumpToStreamOptions - { - public: - - ReadBufferAndDumpToStreamOptions () : - m_data(), - m_stream(NULL), - m_prefix_token(0), - m_quote('"'), - m_source_size(0), - m_escape_non_printables(true) - { - } - - ReadBufferAndDumpToStreamOptions (ValueObject& valobj); - - ReadBufferAndDumpToStreamOptions& - SetData (DataExtractor d) - { - m_data = d; - return *this; - } - - lldb_private::DataExtractor - GetData () const - { - return m_data; - } - - ReadBufferAndDumpToStreamOptions& - SetStream (Stream* s) - { - m_stream = s; - return *this; - } - - Stream* - GetStream () const - { - return m_stream; - } - - ReadBufferAndDumpToStreamOptions& - SetPrefixToken (char p) - { - m_prefix_token = p; - return *this; - } - - char - GetPrefixToken () const - { - return m_prefix_token; - } - - ReadBufferAndDumpToStreamOptions& - SetQuote (char q) - { - m_quote = q; - return *this; - } - - char - GetQuote () const - { - return m_quote; - } - - ReadBufferAndDumpToStreamOptions& - SetSourceSize (uint32_t s) - { - m_source_size = s; - return *this; - } - - uint32_t - GetSourceSize () const - { - return m_source_size; - } - - ReadBufferAndDumpToStreamOptions& - SetEscapeNonPrintables (bool e) - { - m_escape_non_printables = e; - return *this; - } - - bool - GetEscapeNonPrintables () const - { - return m_escape_non_printables; - } - - private: - DataExtractor m_data; - Stream* m_stream; - char m_prefix_token; - char m_quote; - uint32_t m_source_size; - bool m_escape_non_printables; + enum class StringElementType + { + ASCII, + UTF8, + UTF16, + UTF32 + }; + + enum class GetPrintableElementType + { + ASCII, + UTF8 + }; + + class ReadStringAndDumpToStreamOptions + { + public: + ReadStringAndDumpToStreamOptions () : + m_location(0), + m_process_sp(), + m_stream(nullptr), + m_prefix_token(), + m_suffix_token(), + m_quote('"'), + m_source_size(0), + m_needs_zero_termination(true), + m_escape_non_printables(true), + m_ignore_max_length(false), + m_zero_is_terminator(true), + m_language_type(lldb::eLanguageTypeUnknown) + { + } + + ReadStringAndDumpToStreamOptions (ValueObject& valobj); + + ReadStringAndDumpToStreamOptions& + SetLocation (uint64_t l) + { + m_location = l; + return *this; + } + + uint64_t + GetLocation () const + { + return m_location; + } + + ReadStringAndDumpToStreamOptions& + SetProcessSP (lldb::ProcessSP p) + { + m_process_sp = p; + return *this; + } + + lldb::ProcessSP + GetProcessSP () const + { + return m_process_sp; + } + + ReadStringAndDumpToStreamOptions& + SetStream (Stream* s) + { + m_stream = s; + return *this; + } + + Stream* + GetStream () const + { + return m_stream; + } + + ReadStringAndDumpToStreamOptions& + SetPrefixToken (const std::string& p) + { + m_prefix_token = p; + return *this; + } + + ReadStringAndDumpToStreamOptions& + SetPrefixToken (std::nullptr_t) + { + m_prefix_token.clear(); + return *this; + } + + const char* + GetPrefixToken () const + { + return m_prefix_token.c_str(); + } + + ReadStringAndDumpToStreamOptions& + SetSuffixToken (const std::string& p) + { + m_suffix_token = p; + return *this; + } + + ReadStringAndDumpToStreamOptions& + SetSuffixToken (std::nullptr_t) + { + m_suffix_token.clear(); + return *this; + } + + const char* + GetSuffixToken () const + { + return m_suffix_token.c_str(); + } + + ReadStringAndDumpToStreamOptions& + SetQuote (char q) + { + m_quote = q; + return *this; + } + + char + GetQuote () const + { + return m_quote; + } + + ReadStringAndDumpToStreamOptions& + SetSourceSize (uint32_t s) + { + m_source_size = s; + return *this; + } + + uint32_t + GetSourceSize () const + { + return m_source_size; + } + + ReadStringAndDumpToStreamOptions& + SetNeedsZeroTermination (bool z) + { + m_needs_zero_termination = z; + return *this; + } + + bool + GetNeedsZeroTermination () const + { + return m_needs_zero_termination; + } + + ReadStringAndDumpToStreamOptions& + SetBinaryZeroIsTerminator (bool e) + { + m_zero_is_terminator = e; + return *this; + } + + bool + GetBinaryZeroIsTerminator () const + { + return m_zero_is_terminator; + } + + ReadStringAndDumpToStreamOptions& + SetEscapeNonPrintables (bool e) + { + m_escape_non_printables = e; + return *this; + } + + bool + GetEscapeNonPrintables () const + { + return m_escape_non_printables; + } + + ReadStringAndDumpToStreamOptions& + SetIgnoreMaxLength (bool e) + { + m_ignore_max_length = e; + return *this; + } + + bool + GetIgnoreMaxLength () const + { + return m_ignore_max_length; + } + + ReadStringAndDumpToStreamOptions& + SetLanguage (lldb::LanguageType l) + { + m_language_type = l; + return *this; + } + + lldb::LanguageType + GetLanguage () const + + { + return m_language_type; + } + + private: + uint64_t m_location; + lldb::ProcessSP m_process_sp; + Stream* m_stream; + std::string m_prefix_token; + std::string m_suffix_token; + char m_quote; + uint32_t m_source_size; + bool m_needs_zero_termination; + bool m_escape_non_printables; + bool m_ignore_max_length; + bool m_zero_is_terminator; + lldb::LanguageType m_language_type; + }; + + class ReadBufferAndDumpToStreamOptions + { + public: + ReadBufferAndDumpToStreamOptions () : + m_data(), + m_stream(nullptr), + m_prefix_token(), + m_suffix_token(), + m_quote('"'), + m_source_size(0), + m_escape_non_printables(true), + m_zero_is_terminator(true), + m_is_truncated(false), + m_language_type(lldb::eLanguageTypeUnknown) + { + } + + ReadBufferAndDumpToStreamOptions (ValueObject& valobj); + + ReadBufferAndDumpToStreamOptions (const ReadStringAndDumpToStreamOptions& options); + + ReadBufferAndDumpToStreamOptions& + SetData (DataExtractor d) + { + m_data = d; + return *this; + } + + lldb_private::DataExtractor + GetData () const + { + return m_data; + } + + ReadBufferAndDumpToStreamOptions& + SetStream (Stream* s) + { + m_stream = s; + return *this; + } + + Stream* + GetStream () const + { + return m_stream; + } + + ReadBufferAndDumpToStreamOptions& + SetPrefixToken (const std::string& p) + { + m_prefix_token = p; + return *this; + } + + ReadBufferAndDumpToStreamOptions& + SetPrefixToken (std::nullptr_t) + { + m_prefix_token.clear(); + return *this; + } + + const char* + GetPrefixToken () const + { + return m_prefix_token.c_str(); + } + + ReadBufferAndDumpToStreamOptions& + SetSuffixToken (const std::string& p) + { + m_suffix_token = p; + return *this; + } + + ReadBufferAndDumpToStreamOptions& + SetSuffixToken (std::nullptr_t) + { + m_suffix_token.clear(); + return *this; + } + + const char* + GetSuffixToken () const + { + return m_suffix_token.c_str(); + } + + ReadBufferAndDumpToStreamOptions& + SetQuote (char q) + { + m_quote = q; + return *this; + } + + char + GetQuote () const + { + return m_quote; + } + + ReadBufferAndDumpToStreamOptions& + SetSourceSize (uint32_t s) + { + m_source_size = s; + return *this; + } + + uint32_t + GetSourceSize () const + { + return m_source_size; + } + + ReadBufferAndDumpToStreamOptions& + SetEscapeNonPrintables (bool e) + { + m_escape_non_printables = e; + return *this; + } + + bool + GetEscapeNonPrintables () const + { + return m_escape_non_printables; + } + + ReadBufferAndDumpToStreamOptions& + SetBinaryZeroIsTerminator (bool e) + { + m_zero_is_terminator = e; + return *this; + } + + bool + GetBinaryZeroIsTerminator () const + { + return m_zero_is_terminator; + } + + ReadBufferAndDumpToStreamOptions& + SetIsTruncated (bool t) + { + m_is_truncated = t; + return *this; + } + + bool + GetIsTruncated () const + { + return m_is_truncated; + } + + ReadBufferAndDumpToStreamOptions& + SetLanguage (lldb::LanguageType l) + { + m_language_type = l; + return *this; + } + + lldb::LanguageType + GetLanguage () const + + { + return m_language_type; + } + + private: + DataExtractor m_data; + Stream* m_stream; + std::string m_prefix_token; + std::string m_suffix_token; + char m_quote; + uint32_t m_source_size; + bool m_escape_non_printables; + bool m_zero_is_terminator; + bool m_is_truncated; + lldb::LanguageType m_language_type; + }; + + // I can't use a std::unique_ptr for this because the Deleter is a template argument there + // and I want the same type to represent both pointers I want to free and pointers I don't need + // to free - which is what this class essentially is + // It's very specialized to the needs of this file, and not suggested for general use + template <typename T = uint8_t, typename U = char, typename S = size_t> + struct StringPrinterBufferPointer + { + public: + typedef std::function<void(const T*)> Deleter; + + StringPrinterBufferPointer (std::nullptr_t ptr) : + m_data(nullptr), + m_size(0), + m_deleter() + {} + + StringPrinterBufferPointer(const T* bytes, S size, Deleter deleter = nullptr) : + m_data(bytes), + m_size(size), + m_deleter(deleter) + {} + + StringPrinterBufferPointer(const U* bytes, S size, Deleter deleter = nullptr) : + m_data(reinterpret_cast<const T*>(bytes)), + m_size(size), + m_deleter(deleter) + {} + + StringPrinterBufferPointer(StringPrinterBufferPointer&& rhs) : + m_data(rhs.m_data), + m_size(rhs.m_size), + m_deleter(rhs.m_deleter) + { + rhs.m_data = nullptr; + } + + StringPrinterBufferPointer(const StringPrinterBufferPointer& rhs) : + m_data(rhs.m_data), + m_size(rhs.m_size), + m_deleter(rhs.m_deleter) + { + rhs.m_data = nullptr; // this is why m_data has to be mutable + } + + ~StringPrinterBufferPointer() + { + if (m_data && m_deleter) + m_deleter(m_data); + m_data = nullptr; + } + + const T* + GetBytes () const + { + return m_data; + } + + const S + GetSize () const + { + return m_size; + } + + StringPrinterBufferPointer& + operator = (const StringPrinterBufferPointer& rhs) + { + if (m_data && m_deleter) + m_deleter(m_data); + m_data = rhs.m_data; + m_size = rhs.m_size; + m_deleter = rhs.m_deleter; + rhs.m_data = nullptr; + return *this; + } + + private: + mutable const T* m_data; + size_t m_size; + Deleter m_deleter; + }; + + typedef std::function<StringPrinter::StringPrinterBufferPointer<uint8_t,char,size_t>(uint8_t*, uint8_t*, uint8_t*&)> EscapingHelper; + typedef std::function<EscapingHelper(GetPrintableElementType)> EscapingHelperGenerator; + + static EscapingHelper + GetDefaultEscapingHelper (GetPrintableElementType elem_type); + + template <StringElementType element_type> + static bool + ReadStringAndDumpToStream (const ReadStringAndDumpToStreamOptions& options); + + template <StringElementType element_type> + static bool + ReadBufferAndDumpToStream (const ReadBufferAndDumpToStreamOptions& options); }; - template <StringElementType element_type> - bool - ReadStringAndDumpToStream (ReadStringAndDumpToStreamOptions options); - - template <StringElementType element_type> - bool - ReadBufferAndDumpToStream (ReadBufferAndDumpToStreamOptions options); - } // namespace formatters } // namespace lldb_private diff --git a/include/lldb/DataFormatters/TypeCategory.h b/include/lldb/DataFormatters/TypeCategory.h index e32efa420a55a..075d31d1cf6f7 100644 --- a/include/lldb/DataFormatters/TypeCategory.h +++ b/include/lldb/DataFormatters/TypeCategory.h @@ -1,4 +1,4 @@ -//===-- TypeCategory.h -------------------------------------------*- C++ -*-===// +//===-- TypeCategory.h ------------------------------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -12,6 +12,10 @@ // C Includes // C++ Includes +#include <initializer_list> +#include <memory> +#include <string> +#include <vector> // Other libraries and framework includes // Project includes @@ -38,6 +42,9 @@ namespace lldb_private { typedef typename ExactMatchContainer::SharedPointer ExactMatchContainerSP; typedef typename RegexMatchContainer::SharedPointer RegexMatchContainerSP; + typedef typename ExactMatchContainer::ForEachCallback ExactMatchForEachCallback; + typedef typename RegexMatchContainer::ForEachCallback RegexMatchForEachCallback; + FormatterContainerPair (const char* exact_name, const char* regex_name, IFormatChangeListener* clist) : @@ -60,6 +67,12 @@ namespace lldb_private { return m_regex_sp; } + uint32_t + GetCount () + { + return GetExactMatch()->GetCount() + GetRegexMatch()->GetCount(); + } + private: ExactMatchContainerSP m_exact_sp; RegexMatchContainerSP m_regex_sp; @@ -74,11 +87,10 @@ namespace lldb_private { typedef FormatterContainerPair<TypeValidatorImpl> ValidatorContainer; #ifndef LLDB_DISABLE_PYTHON - typedef FormatterContainerPair<ScriptedSyntheticChildren> SynthContainer; -#endif // #ifndef LLDB_DISABLE_PYTHON + typedef FormatterContainerPair<SyntheticChildren> SynthContainer; +#endif // LLDB_DISABLE_PYTHON public: - typedef uint16_t FormatCategoryItems; static const uint16_t ALL_ITEM_TYPES = UINT16_MAX; @@ -93,13 +105,195 @@ namespace lldb_private { #ifndef LLDB_DISABLE_PYTHON typedef SynthContainer::ExactMatchContainerSP SynthContainerSP; typedef SynthContainer::RegexMatchContainerSP RegexSynthContainerSP; -#endif // #ifndef LLDB_DISABLE_PYTHON +#endif // LLDB_DISABLE_PYTHON typedef ValidatorContainer::ExactMatchContainerSP ValidatorContainerSP; typedef ValidatorContainer::RegexMatchContainerSP RegexValidatorContainerSP; + template <typename T> + class ForEachCallbacks + { + public: + ForEachCallbacks () = default; + ~ForEachCallbacks () = default; + + template<typename U = TypeFormatImpl> + typename std::enable_if<std::is_same<U,T>::value, ForEachCallbacks&>::type + SetExact (FormatContainer::ExactMatchForEachCallback callback) + { + m_format_exact = callback; + return *this; + } + template<typename U = TypeFormatImpl> + typename std::enable_if<std::is_same<U,T>::value, ForEachCallbacks&>::type + SetWithRegex (FormatContainer::RegexMatchForEachCallback callback) + { + m_format_regex = callback; + return *this; + } + + template<typename U = TypeSummaryImpl> + typename std::enable_if<std::is_same<U,T>::value, ForEachCallbacks&>::type + SetExact (SummaryContainer::ExactMatchForEachCallback callback) + { + m_summary_exact = callback; + return *this; + } + template<typename U = TypeSummaryImpl> + typename std::enable_if<std::is_same<U,T>::value, ForEachCallbacks&>::type + SetWithRegex (SummaryContainer::RegexMatchForEachCallback callback) + { + m_summary_regex = callback; + return *this; + } + + template<typename U = TypeFilterImpl> + typename std::enable_if<std::is_same<U,T>::value, ForEachCallbacks&>::type + SetExact (FilterContainer::ExactMatchForEachCallback callback) + { + m_filter_exact = callback; + return *this; + } + template<typename U = TypeFilterImpl> + typename std::enable_if<std::is_same<U,T>::value, ForEachCallbacks&>::type + SetWithRegex (FilterContainer::RegexMatchForEachCallback callback) + { + m_filter_regex = callback; + return *this; + } + +#ifndef LLDB_DISABLE_PYTHON + template<typename U = SyntheticChildren> + typename std::enable_if<std::is_same<U,T>::value, ForEachCallbacks&>::type + SetExact (SynthContainer::ExactMatchForEachCallback callback) + { + m_synth_exact = callback; + return *this; + } + template<typename U = SyntheticChildren> + typename std::enable_if<std::is_same<U,T>::value, ForEachCallbacks&>::type + SetWithRegex (SynthContainer::RegexMatchForEachCallback callback) + { + m_synth_regex = callback; + return *this; + } +#endif // LLDB_DISABLE_PYTHON + template<typename U = TypeValidatorImpl> + typename std::enable_if<std::is_same<U,T>::value, ForEachCallbacks&>::type + SetExact (ValidatorContainer::ExactMatchForEachCallback callback) + { + m_validator_exact = callback; + return *this; + } + template<typename U = TypeValidatorImpl> + typename std::enable_if<std::is_same<U,T>::value, ForEachCallbacks&>::type + SetWithRegex (ValidatorContainer::RegexMatchForEachCallback callback) + { + m_validator_regex = callback; + return *this; + } + + FormatContainer::ExactMatchForEachCallback + GetFormatExactCallback () const + { + return m_format_exact; + } + FormatContainer::RegexMatchForEachCallback + GetFormatRegexCallback () const + { + return m_format_regex; + } + + SummaryContainer::ExactMatchForEachCallback + GetSummaryExactCallback () const + { + return m_summary_exact; + } + SummaryContainer::RegexMatchForEachCallback + GetSummaryRegexCallback () const + { + return m_summary_regex; + } + + FilterContainer::ExactMatchForEachCallback + GetFilterExactCallback () const + { + return m_filter_exact; + } + FilterContainer::RegexMatchForEachCallback + GetFilterRegexCallback () const + { + return m_filter_regex; + } + +#ifndef LLDB_DISABLE_PYTHON + SynthContainer::ExactMatchForEachCallback + GetSynthExactCallback () const + { + return m_synth_exact; + } + SynthContainer::RegexMatchForEachCallback + GetSynthRegexCallback () const + { + return m_synth_regex; + } +#endif // LLDB_DISABLE_PYTHON + + ValidatorContainer::ExactMatchForEachCallback + GetValidatorExactCallback () const + { + return m_validator_exact; + } + ValidatorContainer::RegexMatchForEachCallback + GetValidatorRegexCallback () const + { + return m_validator_regex; + } + + private: + FormatContainer::ExactMatchForEachCallback m_format_exact; + FormatContainer::RegexMatchForEachCallback m_format_regex; + + SummaryContainer::ExactMatchForEachCallback m_summary_exact; + SummaryContainer::RegexMatchForEachCallback m_summary_regex; + + FilterContainer::ExactMatchForEachCallback m_filter_exact; + FilterContainer::RegexMatchForEachCallback m_filter_regex; + +#ifndef LLDB_DISABLE_PYTHON + SynthContainer::ExactMatchForEachCallback m_synth_exact; + SynthContainer::RegexMatchForEachCallback m_synth_regex; +#endif // LLDB_DISABLE_PYTHON + + ValidatorContainer::ExactMatchForEachCallback m_validator_exact; + ValidatorContainer::RegexMatchForEachCallback m_validator_regex; + }; + TypeCategoryImpl (IFormatChangeListener* clist, - ConstString name); + ConstString name, + std::initializer_list<lldb::LanguageType> langs = {}); + + template <typename T> + void + ForEach (const ForEachCallbacks<T> &foreach) + { + GetTypeFormatsContainer()->ForEach(foreach.GetFormatExactCallback()); + GetRegexTypeFormatsContainer()->ForEach(foreach.GetFormatRegexCallback()); + + GetTypeSummariesContainer()->ForEach(foreach.GetSummaryExactCallback()); + GetRegexTypeSummariesContainer()->ForEach(foreach.GetSummaryRegexCallback()); + + GetTypeFiltersContainer()->ForEach(foreach.GetFilterExactCallback()); + GetRegexTypeFiltersContainer()->ForEach(foreach.GetFilterRegexCallback()); + +#ifndef LLDB_DISABLE_PYTHON + GetTypeSyntheticsContainer()->ForEach(foreach.GetSynthExactCallback()); + GetRegexTypeSyntheticsContainer()->ForEach(foreach.GetSynthRegexCallback()); +#endif // LLDB_DISABLE_PYTHON + + GetTypeValidatorsContainer()->ForEach(foreach.GetValidatorExactCallback()); + GetRegexTypeValidatorsContainer()->ForEach(foreach.GetValidatorRegexCallback()); + } FormatContainerSP GetTypeFormatsContainer () @@ -113,6 +307,12 @@ namespace lldb_private { return m_format_cont.GetRegexMatch(); } + FormatContainer& + GetFormatContainer () + { + return m_format_cont; + } + SummaryContainerSP GetTypeSummariesContainer () { @@ -125,6 +325,12 @@ namespace lldb_private { return m_summary_cont.GetRegexMatch(); } + SummaryContainer& + GetSummaryContainer () + { + return m_summary_cont; + } + FilterContainerSP GetTypeFiltersContainer () { @@ -136,6 +342,12 @@ namespace lldb_private { { return m_filter_cont.GetRegexMatch(); } + + FilterContainer& + GetFilterContainer () + { + return m_filter_cont; + } FormatContainer::MapValueType GetFormatForType (lldb::TypeNameSpecifierImplSP type_sp); @@ -185,12 +397,18 @@ namespace lldb_private { return m_synth_cont.GetRegexMatch(); } + SynthContainer& + GetSyntheticsContainer () + { + return m_synth_cont; + } + SynthContainer::MapValueType GetSyntheticAtIndex (size_t index); lldb::TypeNameSpecifierImplSP GetTypeNameSpecifierForSyntheticAtIndex (size_t index); -#endif // #ifndef LLDB_DISABLE_PYTHON +#endif // LLDB_DISABLE_PYTHON ValidatorContainerSP GetTypeValidatorsContainer () @@ -226,28 +444,28 @@ namespace lldb_private { } bool - Get (ValueObject& valobj, - const FormattersMatchVector& candidates, - lldb::TypeFormatImplSP& entry, - uint32_t* reason = NULL); + Get(ValueObject& valobj, + const FormattersMatchVector& candidates, + lldb::TypeFormatImplSP& entry, + uint32_t* reason = nullptr); bool - Get (ValueObject& valobj, - const FormattersMatchVector& candidates, - lldb::TypeSummaryImplSP& entry, - uint32_t* reason = NULL); + Get(ValueObject& valobj, + const FormattersMatchVector& candidates, + lldb::TypeSummaryImplSP& entry, + uint32_t* reason = nullptr); bool - Get (ValueObject& valobj, - const FormattersMatchVector& candidates, - lldb::SyntheticChildrenSP& entry, - uint32_t* reason = NULL); + Get(ValueObject& valobj, + const FormattersMatchVector& candidates, + lldb::SyntheticChildrenSP& entry, + uint32_t* reason = nullptr); bool - Get (ValueObject& valobj, - const FormattersMatchVector& candidates, - lldb::TypeValidatorImplSP& entry, - uint32_t* reason = NULL); + Get(ValueObject& valobj, + const FormattersMatchVector& candidates, + lldb::TypeValidatorImplSP& entry, + uint32_t* reason = nullptr); void Clear (FormatCategoryItems items = ALL_ITEM_TYPES); @@ -264,13 +482,28 @@ namespace lldb_private { { return m_name.GetCString(); } + + size_t + GetNumLanguages (); + + lldb::LanguageType + GetLanguageAtIndex (size_t idx); + + void + AddLanguage (lldb::LanguageType lang); bool - AnyMatches (ConstString type_name, - FormatCategoryItems items = ALL_ITEM_TYPES, - bool only_enabled = true, - const char** matching_category = NULL, - FormatCategoryItems* matching_type = NULL); + HasLanguage (lldb::LanguageType lang); + + std::string + GetDescription (); + + bool + AnyMatches(ConstString type_name, + FormatCategoryItems items = ALL_ITEM_TYPES, + bool only_enabled = true, + const char** matching_category = nullptr, + FormatCategoryItems* matching_type = nullptr); typedef std::shared_ptr<TypeCategoryImpl> SharedPointer; @@ -280,7 +513,7 @@ namespace lldb_private { FilterContainer m_filter_cont; #ifndef LLDB_DISABLE_PYTHON SynthContainer m_synth_cont; -#endif // #ifndef LLDB_DISABLE_PYTHON +#endif // LLDB_DISABLE_PYTHON ValidatorContainer m_validator_cont; bool m_enabled; @@ -291,6 +524,8 @@ namespace lldb_private { ConstString m_name; + std::vector<lldb::LanguageType> m_languages; + uint32_t m_enabled_position; void @@ -302,6 +537,9 @@ namespace lldb_private { Enable(false, UINT32_MAX); } + bool + IsApplicable (ValueObject& valobj); + uint32_t GetLastEnabledPosition () { @@ -314,6 +552,8 @@ namespace lldb_private { m_enabled_position = p; } + friend class FormatManager; + friend class LanguageCategory; friend class TypeCategoryMap; friend class FormattersContainer<ConstString, TypeFormatImpl>; @@ -328,7 +568,7 @@ namespace lldb_private { #ifndef LLDB_DISABLE_PYTHON friend class FormattersContainer<ConstString, ScriptedSyntheticChildren>; friend class FormattersContainer<lldb::RegularExpressionSP, ScriptedSyntheticChildren>; -#endif // #ifndef LLDB_DISABLE_PYTHON +#endif // LLDB_DISABLE_PYTHON friend class FormattersContainer<ConstString, TypeValidatorImpl>; friend class FormattersContainer<lldb::RegularExpressionSP, TypeValidatorImpl>; @@ -336,4 +576,4 @@ namespace lldb_private { } // namespace lldb_private -#endif // lldb_TypeCategory_h_ +#endif // lldb_TypeCategory_h_ diff --git a/include/lldb/DataFormatters/TypeCategoryMap.h b/include/lldb/DataFormatters/TypeCategoryMap.h index 41b170d5335e4..8afeaf87cec5c 100644 --- a/include/lldb/DataFormatters/TypeCategoryMap.h +++ b/include/lldb/DataFormatters/TypeCategoryMap.h @@ -1,4 +1,4 @@ -//===-- TypeCategoryMap.h ----------------------------------------*- C++ -*-===// +//===-- TypeCategoryMap.h ---------------------------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -12,6 +12,9 @@ // C Includes // C++ Includes +#include <functional> +#include <list> +#include <map> // Other libraries and framework includes // Project includes @@ -34,7 +37,8 @@ namespace lldb_private { public: typedef std::map<KeyType, ValueSP> MapType; typedef MapType::iterator MapIterator; - typedef bool(*CallbackType)(void*, const ValueSP&); + typedef std::function<bool(const ValueSP&)> ForEachCallback; + typedef uint32_t Position; static const Position First = 0; @@ -82,17 +86,17 @@ namespace lldb_private { ValueSP& entry); void - LoopThrough (CallbackType callback, void* param); + ForEach (ForEachCallback callback); lldb::TypeCategoryImplSP GetAtIndex (uint32_t); bool - AnyMatches (ConstString type_name, - TypeCategoryImpl::FormatCategoryItems items = TypeCategoryImpl::ALL_ITEM_TYPES, - bool only_enabled = true, - const char** matching_category = NULL, - TypeCategoryImpl::FormatCategoryItems* matching_type = NULL); + AnyMatches(ConstString type_name, + TypeCategoryImpl::FormatCategoryItems items = TypeCategoryImpl::ALL_ITEM_TYPES, + bool only_enabled = true, + const char** matching_category = nullptr, + TypeCategoryImpl::FormatCategoryItems* matching_type = nullptr); uint32_t GetCount () @@ -101,25 +105,20 @@ namespace lldb_private { } lldb::TypeFormatImplSP - GetFormat (ValueObject& valobj, - lldb::DynamicValueType use_dynamic); + GetFormat (FormattersMatchData& match_data); lldb::TypeSummaryImplSP - GetSummaryFormat (ValueObject& valobj, - lldb::DynamicValueType use_dynamic); + GetSummaryFormat (FormattersMatchData& match_data); #ifndef LLDB_DISABLE_PYTHON lldb::SyntheticChildrenSP - GetSyntheticChildren (ValueObject& valobj, - lldb::DynamicValueType use_dynamic); + GetSyntheticChildren (FormattersMatchData& match_data); #endif - lldb::TypeValidatorImplSP - GetValidator (ValueObject& valobj, - lldb::DynamicValueType use_dynamic); + lldb::TypeValidatorImplSP + GetValidator(FormattersMatchData& match_data); private: - class delete_matching_categories { lldb::TypeCategoryImplSP ptr; @@ -159,4 +158,4 @@ namespace lldb_private { }; } // namespace lldb_private -#endif // lldb_TypeCategoryMap_h_ +#endif // lldb_TypeCategoryMap_h_ diff --git a/include/lldb/DataFormatters/TypeFormat.h b/include/lldb/DataFormatters/TypeFormat.h index 8aa7c60b49389..4ed28b6920617 100644 --- a/include/lldb/DataFormatters/TypeFormat.h +++ b/include/lldb/DataFormatters/TypeFormat.h @@ -13,6 +13,7 @@ // C Includes // C++ Includes +#include <functional> #include <string> #include <unordered_map> @@ -150,7 +151,6 @@ namespace lldb_private { TypeFormatImpl (const Flags& flags = Flags()); typedef std::shared_ptr<TypeFormatImpl> SharedPointer; - typedef bool(*ValueCallback)(void*, ConstString, const lldb::TypeFormatImplSP&); virtual ~TypeFormatImpl (); @@ -159,16 +159,19 @@ namespace lldb_private { { return m_flags.GetCascades(); } + bool SkipsPointers () const { return m_flags.GetSkipPointers(); } + bool SkipsReferences () const { return m_flags.GetSkipReferences(); } + bool NonCacheable () const { @@ -255,9 +258,8 @@ namespace lldb_private { const TypeFormatImpl::Flags& flags = Flags()); typedef std::shared_ptr<TypeFormatImpl_Format> SharedPointer; - typedef bool(*ValueCallback)(void*, ConstString, const TypeFormatImpl_Format::SharedPointer&); - virtual ~TypeFormatImpl_Format (); + ~TypeFormatImpl_Format() override; lldb::Format GetFormat () const @@ -271,18 +273,18 @@ namespace lldb_private { m_format = fmt; } - virtual TypeFormatImpl::Type - GetType () + TypeFormatImpl::Type + GetType() override { return TypeFormatImpl::Type::eTypeFormat; } - virtual bool - FormatObject (ValueObject *valobj, - std::string& dest) const; + bool + FormatObject(ValueObject *valobj, + std::string& dest) const override; - virtual std::string - GetDescription(); + std::string + GetDescription() override; protected: lldb::Format m_format; @@ -298,9 +300,8 @@ namespace lldb_private { const TypeFormatImpl::Flags& flags = Flags()); typedef std::shared_ptr<TypeFormatImpl_EnumType> SharedPointer; - typedef bool(*ValueCallback)(void*, ConstString, const TypeFormatImpl_EnumType::SharedPointer&); - ~TypeFormatImpl_EnumType (); + ~TypeFormatImpl_EnumType() override; ConstString GetTypeName () @@ -314,26 +315,26 @@ namespace lldb_private { m_enum_type = enum_type; } - virtual TypeFormatImpl::Type - GetType () + TypeFormatImpl::Type + GetType() override { return TypeFormatImpl::Type::eTypeEnum; } - virtual bool - FormatObject (ValueObject *valobj, - std::string& dest) const; + bool + FormatObject(ValueObject *valobj, + std::string& dest) const override; - virtual std::string - GetDescription(); + std::string + GetDescription() override; protected: ConstString m_enum_type; - mutable std::unordered_map<void*,ClangASTType> m_types; + mutable std::unordered_map<void*,CompilerType> m_types; private: DISALLOW_COPY_AND_ASSIGN(TypeFormatImpl_EnumType); }; } // namespace lldb_private -#endif // lldb_TypeFormat_h_ +#endif // lldb_TypeFormat_h_ diff --git a/include/lldb/DataFormatters/TypeSummary.h b/include/lldb/DataFormatters/TypeSummary.h index c2838eac27f17..e5bf4ecadfdfb 100644 --- a/include/lldb/DataFormatters/TypeSummary.h +++ b/include/lldb/DataFormatters/TypeSummary.h @@ -1,4 +1,4 @@ -//===-- TypeSummary.h --------------------------------------------*- C++ -*-===// +//===-- TypeSummary.h -------------------------------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -14,11 +14,11 @@ #include <stdint.h> // C++ Includes +#include <functional> +#include <memory> #include <string> -#include <vector> // Other libraries and framework includes - // Project includes #include "lldb/lldb-public.h" #include "lldb/lldb-enumerations.h" @@ -26,8 +26,6 @@ #include "lldb/Core/Error.h" #include "lldb/Core/FormatEntity.h" #include "lldb/Core/StructuredData.h" -#include "lldb/Core/ValueObject.h" -#include "lldb/Symbol/Type.h" namespace lldb_private { class TypeSummaryOptions @@ -36,6 +34,8 @@ namespace lldb_private { TypeSummaryOptions (); TypeSummaryOptions (const TypeSummaryOptions& rhs); + ~TypeSummaryOptions() = default; + TypeSummaryOptions& operator = (const TypeSummaryOptions& rhs); @@ -50,8 +50,7 @@ namespace lldb_private { TypeSummaryOptions& SetCapping (lldb::TypeSummaryCapping); - - ~TypeSummaryOptions() = default; + private: lldb::LanguageType m_lang; lldb::TypeSummaryCapping m_capping; @@ -60,10 +59,26 @@ namespace lldb_private { class TypeSummaryImpl { public: + enum class Kind + { + eSummaryString, + eScript, + eCallback, + eInternal + }; + + virtual + ~TypeSummaryImpl() = default; + + Kind + GetKind () const + { + return m_kind; + } + class Flags { public: - Flags () : m_flags (lldb::eTypeOptionCascade) {} @@ -162,6 +177,22 @@ namespace lldb_private { m_flags &= ~lldb::eTypeOptionHideChildren; return *this; } + + bool + GetHideEmptyAggregates () const + { + return (m_flags & lldb::eTypeOptionHideEmptyAggregates) == lldb::eTypeOptionHideEmptyAggregates; + } + + Flags& + SetHideEmptyAggregates (bool value = true) + { + if (value) + m_flags |= lldb::eTypeOptionHideEmptyAggregates; + else + m_flags &= ~lldb::eTypeOptionHideEmptyAggregates; + return *this; + } bool GetDontShowValue () const @@ -243,31 +274,24 @@ namespace lldb_private { uint32_t m_flags; }; - typedef enum Type - { - eTypeUnknown, - eTypeString, - eTypeScript, - eTypeCallback - } Type; - - TypeSummaryImpl (const TypeSummaryImpl::Flags& flags); - bool Cascades () const { return m_flags.GetCascades(); } + bool SkipsPointers () const { return m_flags.GetSkipPointers(); } + bool SkipsReferences () const { return m_flags.GetSkipReferences(); } + bool NonCacheable () const { @@ -279,6 +303,12 @@ namespace lldb_private { { return !m_flags.GetDontShowChildren(); } + + virtual bool + DoesPrintEmptyAggregates () const + { + return !m_flags.GetHideEmptyAggregates(); + } virtual bool DoesPrintValue (ValueObject* valobj) const @@ -358,11 +388,6 @@ namespace lldb_private { m_flags.SetValue(value); } - virtual - ~TypeSummaryImpl () - { - } - // we are using a ValueObject* instead of a ValueObjectSP because we do not need to hold on to this for // extended periods of time and we trust the ValueObject to stay around for as long as it is required // for us to generate its summary @@ -374,12 +399,6 @@ namespace lldb_private { virtual std::string GetDescription () = 0; - virtual bool - IsScripted () = 0; - - virtual Type - GetType () = 0; - uint32_t& GetRevision () { @@ -387,14 +406,16 @@ namespace lldb_private { } typedef std::shared_ptr<TypeSummaryImpl> SharedPointer; - typedef bool(*SummaryCallback)(void*, ConstString, const lldb::TypeSummaryImplSP&); - typedef bool(*RegexSummaryCallback)(void*, lldb::RegularExpressionSP, const lldb::TypeSummaryImplSP&); protected: uint32_t m_my_revision; Flags m_flags; + TypeSummaryImpl (Kind kind, + const TypeSummaryImpl::Flags& flags); + private: + Kind m_kind; DISALLOW_COPY_AND_ASSIGN(TypeSummaryImpl); }; @@ -407,11 +428,8 @@ namespace lldb_private { StringSummaryFormat(const TypeSummaryImpl::Flags& flags, const char* f); - - virtual - ~StringSummaryFormat() - { - } + + ~StringSummaryFormat() override = default; const char* GetSummaryString () const @@ -422,25 +440,17 @@ namespace lldb_private { void SetSummaryString (const char* f); - virtual bool + bool FormatObject(ValueObject *valobj, std::string& dest, - const TypeSummaryOptions& options); - - virtual std::string - GetDescription(); - - virtual bool - IsScripted () - { - return false; - } + const TypeSummaryOptions& options) override; + std::string + GetDescription() override; - virtual Type - GetType () + static bool classof(const TypeSummaryImpl* S) { - return TypeSummaryImpl::eTypeString; + return S->GetKind() == Kind::eSummaryString; } private: @@ -452,9 +462,9 @@ namespace lldb_private { { // we should convert these to SBValue and SBStream if we ever cross // the boundary towards the external world - typedef bool (*Callback)(ValueObject&, - Stream&, - const TypeSummaryOptions&); + typedef std::function<bool(ValueObject&, + Stream&, + const TypeSummaryOptions&)> Callback; Callback m_impl; std::string m_description; @@ -462,7 +472,9 @@ namespace lldb_private { CXXFunctionSummaryFormat (const TypeSummaryImpl::Flags& flags, Callback impl, const char* description); - + + ~CXXFunctionSummaryFormat() override = default; + Callback GetBackendFunction () const { @@ -489,30 +501,18 @@ namespace lldb_private { else m_description.clear(); } + + bool + FormatObject(ValueObject *valobj, + std::string& dest, + const TypeSummaryOptions& options) override; - virtual - ~CXXFunctionSummaryFormat () - { - } - - virtual bool - FormatObject (ValueObject *valobj, - std::string& dest, - const TypeSummaryOptions& options); - - virtual std::string - GetDescription (); - - virtual bool - IsScripted () - { - return false; - } + std::string + GetDescription() override; - virtual Type - GetType () + static bool classof(const TypeSummaryImpl* S) { - return TypeSummaryImpl::eTypeCallback; + return S->GetKind() == Kind::eCallback; } typedef std::shared_ptr<CXXFunctionSummaryFormat> SharedPointer; @@ -521,8 +521,6 @@ namespace lldb_private { DISALLOW_COPY_AND_ASSIGN(CXXFunctionSummaryFormat); }; -#ifndef LLDB_DISABLE_PYTHON - // Python-based summaries, running script code to show data struct ScriptSummaryFormat : public TypeSummaryImpl { @@ -532,8 +530,10 @@ namespace lldb_private { ScriptSummaryFormat(const TypeSummaryImpl::Flags& flags, const char *function_name, - const char* python_script = NULL); - + const char* python_script = nullptr); + + ~ScriptSummaryFormat() override = default; + const char* GetFunctionName () const { @@ -565,38 +565,24 @@ namespace lldb_private { m_python_script.clear(); } - virtual - ~ScriptSummaryFormat () - { - } - - virtual bool - FormatObject (ValueObject *valobj, - std::string& dest, - const TypeSummaryOptions& options); - - virtual std::string - GetDescription (); + bool + FormatObject(ValueObject *valobj, + std::string& dest, + const TypeSummaryOptions& options) override; - virtual bool - IsScripted () - { - return true; - } + std::string + GetDescription() override; - virtual Type - GetType () + static bool classof(const TypeSummaryImpl* S) { - return TypeSummaryImpl::eTypeScript; + return S->GetKind() == Kind::eScript; } typedef std::shared_ptr<ScriptSummaryFormat> SharedPointer; - private: DISALLOW_COPY_AND_ASSIGN(ScriptSummaryFormat); }; -#endif } // namespace lldb_private -#endif // lldb_TypeSummary_h_ +#endif // lldb_TypeSummary_h_ diff --git a/include/lldb/DataFormatters/TypeSynthetic.h b/include/lldb/DataFormatters/TypeSynthetic.h index ff6691c9a1b8e..90e5730288c4e 100644 --- a/include/lldb/DataFormatters/TypeSynthetic.h +++ b/include/lldb/DataFormatters/TypeSynthetic.h @@ -1,4 +1,4 @@ -//===-- TypeSynthetic.h -------------------------------------------*- C++ -*-===// +//===-- TypeSynthetic.h -----------------------------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -14,11 +14,13 @@ #include <stdint.h> // C++ Includes +#include <initializer_list> +#include <functional> +#include <memory> #include <string> #include <vector> // Other libraries and framework includes - // Project includes #include "lldb/lldb-public.h" #include "lldb/lldb-enumerations.h" @@ -45,23 +47,27 @@ namespace lldb_private { } public: - SyntheticChildrenFrontEnd (ValueObject &backend) : m_backend(backend), m_valid(true) {} - + virtual - ~SyntheticChildrenFrontEnd () - { - } - + ~SyntheticChildrenFrontEnd() = default; + virtual size_t CalculateNumChildren () = 0; + + virtual size_t + CalculateNumChildren (uint32_t max) + { + auto count = CalculateNumChildren (); + return count <= max ? count : max; + } virtual lldb::ValueObjectSP GetChildAtIndex (size_t idx) = 0; - + virtual size_t GetIndexOfChildWithName (const ConstString &name) = 0; @@ -98,13 +104,13 @@ namespace lldb_private { CreateValueObjectFromAddress (const char* name, uint64_t address, const ExecutionContext& exe_ctx, - ClangASTType type); + CompilerType type); lldb::ValueObjectSP CreateValueObjectFromData (const char* name, const DataExtractor& data, const ExecutionContext& exe_ctx, - ClangASTType type); + CompilerType type); private: bool m_valid; @@ -117,29 +123,26 @@ namespace lldb_private { SyntheticValueProviderFrontEnd (ValueObject &backend) : SyntheticChildrenFrontEnd(backend) {} + + ~SyntheticValueProviderFrontEnd() override = default; + + size_t + CalculateNumChildren() override { return 0; } - virtual - ~SyntheticValueProviderFrontEnd () - { - } - - virtual size_t - CalculateNumChildren () { return 0; } - - virtual lldb::ValueObjectSP - GetChildAtIndex (size_t idx) { return nullptr; } + lldb::ValueObjectSP + GetChildAtIndex(size_t idx) override { return nullptr; } - virtual size_t - GetIndexOfChildWithName (const ConstString &name) { return UINT32_MAX; } + size_t + GetIndexOfChildWithName(const ConstString &name) override { return UINT32_MAX; } - virtual bool - Update () { return false; } + bool + Update() override { return false; } - virtual bool - MightHaveChildren () { return false; } + bool + MightHaveChildren () override { return false; } - virtual lldb::ValueObjectSP - GetSyntheticValue () = 0; + lldb::ValueObjectSP + GetSyntheticValue() override = 0; private: DISALLOW_COPY_AND_ASSIGN(SyntheticValueProviderFrontEnd); @@ -148,7 +151,6 @@ namespace lldb_private { class SyntheticChildren { public: - class Flags { public: @@ -272,27 +274,28 @@ namespace lldb_private { m_flags(flags) { } - + virtual - ~SyntheticChildren () - { - } - + ~SyntheticChildren() = default; + bool Cascades () const { return m_flags.GetCascades(); } + bool SkipsPointers () const { return m_flags.GetSkipPointers(); } + bool SkipsReferences () const { return m_flags.GetSkipReferences(); } + bool NonCacheable () const { @@ -345,7 +348,6 @@ namespace lldb_private { GetFrontEnd (ValueObject &backend) = 0; typedef std::shared_ptr<SyntheticChildren> SharedPointer; - typedef bool(*SyntheticChildrenCallback)(void*, ConstString, const SyntheticChildren::SharedPointer&); uint32_t& GetRevision () @@ -417,69 +419,67 @@ namespace lldb_private { SetExpressionPathAtIndex (size_t i, const std::string& path); bool - IsScripted () + IsScripted() override { return false; } std::string - GetDescription (); + GetDescription() override; class FrontEnd : public SyntheticChildrenFrontEnd { - private: - TypeFilterImpl* filter; public: - FrontEnd(TypeFilterImpl* flt, ValueObject &backend) : SyntheticChildrenFrontEnd(backend), filter(flt) {} - - virtual - ~FrontEnd () - { - } - - virtual size_t - CalculateNumChildren () + + ~FrontEnd() override = default; + + size_t + CalculateNumChildren() override { return filter->GetCount(); } - virtual lldb::ValueObjectSP - GetChildAtIndex (size_t idx) + lldb::ValueObjectSP + GetChildAtIndex(size_t idx) override { if (idx >= filter->GetCount()) return lldb::ValueObjectSP(); return m_backend.GetSyntheticExpressionPathChild(filter->GetExpressionPathAtIndex(idx), true); } + + bool + Update() override { return false; } - virtual bool - Update() { return false; } - - virtual bool - MightHaveChildren () + bool + MightHaveChildren() override { return filter->GetCount() > 0; } - virtual size_t - GetIndexOfChildWithName (const ConstString &name); + size_t + GetIndexOfChildWithName(const ConstString &name) override; typedef std::shared_ptr<SyntheticChildrenFrontEnd> SharedPointer; private: + TypeFilterImpl* filter; + DISALLOW_COPY_AND_ASSIGN(FrontEnd); }; - virtual SyntheticChildrenFrontEnd::AutoPointer - GetFrontEnd(ValueObject &backend) + SyntheticChildrenFrontEnd::AutoPointer + GetFrontEnd(ValueObject &backend) override { return SyntheticChildrenFrontEnd::AutoPointer(new FrontEnd(this, backend)); } + typedef std::shared_ptr<TypeFilterImpl> SharedPointer; + private: DISALLOW_COPY_AND_ASSIGN(TypeFilterImpl); }; @@ -487,11 +487,7 @@ namespace lldb_private { class CXXSyntheticChildren : public SyntheticChildren { public: - typedef SyntheticChildrenFrontEnd* (*CreateFrontEndCallback) (CXXSyntheticChildren*, lldb::ValueObjectSP); - protected: - CreateFrontEndCallback m_create_callback; - std::string m_description; - public: + typedef std::function<SyntheticChildrenFrontEnd*(CXXSyntheticChildren*, lldb::ValueObjectSP)> CreateFrontEndCallback; CXXSyntheticChildren (const SyntheticChildren::Flags& flags, const char* description, CreateFrontEndCallback callback) : @@ -502,20 +498,24 @@ namespace lldb_private { } bool - IsScripted () + IsScripted() override { return false; } std::string - GetDescription (); + GetDescription() override; - virtual SyntheticChildrenFrontEnd::AutoPointer - GetFrontEnd (ValueObject &backend) + SyntheticChildrenFrontEnd::AutoPointer + GetFrontEnd(ValueObject &backend) override { return SyntheticChildrenFrontEnd::AutoPointer(m_create_callback(this, backend.GetSP())); } + protected: + CreateFrontEndCallback m_create_callback; + std::string m_description; + private: DISALLOW_COPY_AND_ASSIGN(CXXSyntheticChildren); }; @@ -528,9 +528,9 @@ namespace lldb_private { std::string m_python_code; public: - ScriptedSyntheticChildren (const SyntheticChildren::Flags& flags, - const char* pclass, - const char* pcode = NULL) : + ScriptedSyntheticChildren(const SyntheticChildren::Flags& flags, + const char* pclass, + const char* pcode = nullptr) : SyntheticChildren(flags), m_python_class(), m_python_code() @@ -567,62 +567,63 @@ namespace lldb_private { } std::string - GetDescription (); + GetDescription() override; bool - IsScripted () + IsScripted() override { return true; } class FrontEnd : public SyntheticChildrenFrontEnd { - private: - std::string m_python_class; - StructuredData::ObjectSP m_wrapper_sp; - ScriptInterpreter *m_interpreter; public: - FrontEnd (std::string pclass, ValueObject &backend); + ~FrontEnd() override; + bool IsValid (); - virtual - ~FrontEnd (); - - virtual size_t - CalculateNumChildren (); - - virtual lldb::ValueObjectSP - GetChildAtIndex (size_t idx); + size_t + CalculateNumChildren() override; + + size_t + CalculateNumChildren(uint32_t max) override; - virtual bool - Update (); + lldb::ValueObjectSP + GetChildAtIndex(size_t idx) override; + + bool + Update() override; - virtual bool - MightHaveChildren (); + bool + MightHaveChildren() override; - virtual size_t - GetIndexOfChildWithName (const ConstString &name); + size_t + GetIndexOfChildWithName(const ConstString &name) override; - virtual lldb::ValueObjectSP - GetSyntheticValue (); + lldb::ValueObjectSP + GetSyntheticValue() override; typedef std::shared_ptr<SyntheticChildrenFrontEnd> SharedPointer; private: + std::string m_python_class; + StructuredData::ObjectSP m_wrapper_sp; + ScriptInterpreter *m_interpreter; + DISALLOW_COPY_AND_ASSIGN(FrontEnd); }; - virtual SyntheticChildrenFrontEnd::AutoPointer - GetFrontEnd(ValueObject &backend) + SyntheticChildrenFrontEnd::AutoPointer + GetFrontEnd(ValueObject &backend) override { auto synth_ptr = SyntheticChildrenFrontEnd::AutoPointer(new FrontEnd(m_python_class, backend)); if (synth_ptr && ((FrontEnd*)synth_ptr.get())->IsValid()) return synth_ptr; - return NULL; + return nullptr; } private: @@ -631,4 +632,4 @@ namespace lldb_private { #endif } // namespace lldb_private -#endif // lldb_TypeSynthetic_h_ +#endif // lldb_TypeSynthetic_h_ diff --git a/include/lldb/DataFormatters/TypeValidator.h b/include/lldb/DataFormatters/TypeValidator.h index d06fac01f8246..f1f9a11049dbc 100644 --- a/include/lldb/DataFormatters/TypeValidator.h +++ b/include/lldb/DataFormatters/TypeValidator.h @@ -13,8 +13,8 @@ // C Includes // C++ Includes -#include <string> #include <functional> +#include <string> // Other libraries and framework includes @@ -150,7 +150,6 @@ public: TypeValidatorImpl (const Flags& flags = Flags()); typedef std::shared_ptr<TypeValidatorImpl> SharedPointer; - typedef bool(*ValueCallback)(void*, ConstString, const lldb::TypeValidatorImplSP&); virtual ~TypeValidatorImpl (); @@ -265,9 +264,8 @@ public: TypeValidatorImpl_CXX (ValidatorFunction f, std::string d, const TypeValidatorImpl::Flags& flags = Flags()); typedef std::shared_ptr<TypeValidatorImpl_CXX> SharedPointer; - typedef bool(*ValueCallback)(void*, ConstString, const TypeValidatorImpl_CXX::SharedPointer&); - virtual ~TypeValidatorImpl_CXX (); + ~TypeValidatorImpl_CXX() override; ValidatorFunction GetValidatorFunction () const @@ -281,17 +279,17 @@ public: m_validator_function = f; } - virtual TypeValidatorImpl::Type - GetType () + TypeValidatorImpl::Type + GetType() override { return TypeValidatorImpl::Type::eTypeCXX; } - virtual ValidationResult - FormatObject (ValueObject *valobj) const; + ValidationResult + FormatObject(ValueObject *valobj) const override; - virtual std::string - GetDescription(); + std::string + GetDescription() override; protected: std::string m_description; @@ -304,4 +302,4 @@ private: } // namespace lldb_private -#endif // lldb_TypeValidator_h_ +#endif // lldb_TypeValidator_h_ diff --git a/include/lldb/DataFormatters/ValueObjectPrinter.h b/include/lldb/DataFormatters/ValueObjectPrinter.h index dc05fd4826763..23d7ee2edf502 100644 --- a/include/lldb/DataFormatters/ValueObjectPrinter.h +++ b/include/lldb/DataFormatters/ValueObjectPrinter.h @@ -18,232 +18,15 @@ #include "lldb/lldb-private.h" #include "lldb/lldb-public.h" -#include "lldb/Core/Stream.h" -#include "lldb/Core/ValueObject.h" -#include "lldb/DataFormatters/TypeSummary.h" +#include "lldb/Core/Flags.h" +#include "lldb/DataFormatters/DumpValueObjectOptions.h" +#include "lldb/Symbol/CompilerType.h" -namespace lldb_private { +//#include <functional> +//#include <memory> +//#include <set> -struct DumpValueObjectOptions -{ - uint32_t m_max_ptr_depth = 0; - uint32_t m_max_depth = UINT32_MAX; - lldb::DynamicValueType m_use_dynamic = lldb::eNoDynamicValues; - uint32_t m_omit_summary_depth = 0; - lldb::Format m_format = lldb::eFormatDefault; - lldb::TypeSummaryImplSP m_summary_sp; - std::string m_root_valobj_name; - bool m_use_synthetic : 1; - bool m_scope_already_checked : 1; - bool m_flat_output : 1; - bool m_ignore_cap : 1; - bool m_show_types : 1; - bool m_show_location : 1; - bool m_use_objc : 1; - bool m_hide_root_type : 1; - bool m_hide_name : 1; - bool m_hide_value : 1; - bool m_run_validator : 1; - bool m_use_type_display_name : 1; - bool m_allow_oneliner_mode : 1; - - DumpValueObjectOptions() : - m_summary_sp(), - m_root_valobj_name(), - 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) - {} - - static const DumpValueObjectOptions - DefaultOptions() - { - static DumpValueObjectOptions g_default_options; - - return g_default_options; - } - - DumpValueObjectOptions (const DumpValueObjectOptions& rhs) = default; - - DumpValueObjectOptions (ValueObject& valobj); - - DumpValueObjectOptions& - SetMaximumPointerDepth(uint32_t depth = 0) - { - m_max_ptr_depth = depth; - return *this; - } - - DumpValueObjectOptions& - SetMaximumDepth(uint32_t depth = 0) - { - m_max_depth = depth; - return *this; - } - - DumpValueObjectOptions& - SetShowTypes(bool show = false) - { - m_show_types = show; - return *this; - } - - DumpValueObjectOptions& - SetShowLocation(bool show = false) - { - m_show_location = show; - return *this; - } - - DumpValueObjectOptions& - SetUseObjectiveC(bool use = false) - { - m_use_objc = use; - return *this; - } - - DumpValueObjectOptions& - SetShowSummary(bool show = true) - { - if (show == false) - SetOmitSummaryDepth(UINT32_MAX); - else - SetOmitSummaryDepth(0); - return *this; - } - - DumpValueObjectOptions& - SetUseDynamicType(lldb::DynamicValueType dyn = lldb::eNoDynamicValues) - { - m_use_dynamic = dyn; - return *this; - } - - DumpValueObjectOptions& - SetUseSyntheticValue(bool use_synthetic = true) - { - m_use_synthetic = use_synthetic; - return *this; - } - - DumpValueObjectOptions& - SetScopeChecked(bool check = true) - { - m_scope_already_checked = check; - return *this; - } - - DumpValueObjectOptions& - SetFlatOutput(bool flat = false) - { - m_flat_output = flat; - return *this; - } - - DumpValueObjectOptions& - SetOmitSummaryDepth(uint32_t depth = 0) - { - m_omit_summary_depth = depth; - return *this; - } - - DumpValueObjectOptions& - SetIgnoreCap(bool ignore = false) - { - m_ignore_cap = ignore; - return *this; - } - - DumpValueObjectOptions& - SetRawDisplay() - { - SetUseSyntheticValue(false); - SetOmitSummaryDepth(UINT32_MAX); - SetIgnoreCap(true); - SetHideName(false); - SetHideValue(false); - SetUseTypeDisplayName(false); - SetAllowOnelinerMode(false); - return *this; - } - - DumpValueObjectOptions& - SetFormat (lldb::Format format = lldb::eFormatDefault) - { - m_format = format; - return *this; - } - - DumpValueObjectOptions& - SetSummary (lldb::TypeSummaryImplSP summary = lldb::TypeSummaryImplSP()) - { - m_summary_sp = summary; - return *this; - } - - DumpValueObjectOptions& - SetRootValueObjectName (const char* name = NULL) - { - if (name) - m_root_valobj_name.assign(name); - else - m_root_valobj_name.clear(); - return *this; - } - - DumpValueObjectOptions& - SetHideRootType (bool hide_root_type = false) - { - m_hide_root_type = hide_root_type; - return *this; - } - - DumpValueObjectOptions& - SetHideName (bool hide_name = false) - { - m_hide_name = hide_name; - return *this; - } - - DumpValueObjectOptions& - SetHideValue (bool hide_value = false) - { - m_hide_value = hide_value; - return *this; - } - - DumpValueObjectOptions& - SetRunValidator (bool run = true) - { - m_run_validator = run; - return *this; - } - - DumpValueObjectOptions& - SetUseTypeDisplayName (bool dis = false) - { - m_use_type_display_name = dis; - return *this; - } - - DumpValueObjectOptions& - SetAllowOnelinerMode (bool oneliner = false) - { - m_allow_oneliner_mode = oneliner; - return *this; - } - -}; +namespace lldb_private { class ValueObjectPrinter { @@ -262,14 +45,19 @@ public: PrintValueObject (); protected: + typedef std::set<uint64_t> InstancePointersSet; + typedef std::shared_ptr<InstancePointersSet> InstancePointersSetSP; + InstancePointersSetSP m_printed_instance_pointers; + // only this class (and subclasses, if any) should ever be concerned with // the depth mechanism ValueObjectPrinter (ValueObject* valobj, Stream* s, const DumpValueObjectOptions& options, - uint32_t ptr_depth, - uint32_t curr_depth); + const DumpValueObjectOptions::PointerDepth& ptr_depth, + uint32_t curr_depth, + InstancePointersSetSP printed_instance_pointers); // we should actually be using delegating constructors here // but some versions of GCC still have trouble with those @@ -277,8 +65,9 @@ protected: Init (ValueObject* valobj, Stream* s, const DumpValueObjectOptions& options, - uint32_t ptr_depth, - uint32_t curr_depth); + const DumpValueObjectOptions::PointerDepth& ptr_depth, + uint32_t curr_depth, + InstancePointersSetSP printed_instance_pointers); bool GetMostSpecializedValue (); @@ -299,12 +88,18 @@ protected: IsNil (); bool + IsUninitialized (); + + bool IsPtr (); bool IsRef (); bool + IsInstancePointer (); + + bool IsAggregate (); bool @@ -316,17 +111,18 @@ protected: bool PrintLocationIfNeeded (); - bool - PrintTypeIfNeeded (); + void + PrintDecl (); bool - PrintNameIfNeeded (bool show_type); + CheckScopeIfNeeded (); bool - CheckScopeIfNeeded (); + ShouldPrintEmptyBrackets (bool value_printed, + bool summary_printed); TypeSummaryImpl* - GetSummaryFormatter (); + GetSummaryFormatter (bool null_if_omitted = true); void GetValueSummaryError (std::string& value, @@ -343,7 +139,10 @@ protected: bool ShouldPrintChildren (bool is_failed_description, - uint32_t& curr_ptr_depth); + DumpValueObjectOptions::PointerDepth& curr_ptr_depth); + + bool + ShouldExpandEmptyAggregates (); ValueObject* GetValueObjectForChildrenGeneration (); @@ -356,13 +155,15 @@ protected: void PrintChild (lldb::ValueObjectSP child_sp, - uint32_t curr_ptr_depth); + const DumpValueObjectOptions::PointerDepth& curr_ptr_depth); uint32_t GetMaxNumChildrenToPrint (bool& print_dotdotdot); void - PrintChildren (uint32_t curr_ptr_depth); + PrintChildren (bool value_printed, + bool summary_printed, + const DumpValueObjectOptions::PointerDepth& curr_ptr_depth); void PrintChildrenIfNeeded (bool value_printed, @@ -376,20 +177,23 @@ private: ValueObject *m_orig_valobj; ValueObject *m_valobj; Stream *m_stream; - DumpValueObjectOptions options; + DumpValueObjectOptions m_options; Flags m_type_flags; - ClangASTType m_clang_type; - uint32_t m_ptr_depth; + CompilerType m_compiler_type; + DumpValueObjectOptions::PointerDepth m_ptr_depth; uint32_t m_curr_depth; LazyBool m_should_print; LazyBool m_is_nil; + LazyBool m_is_uninit; LazyBool m_is_ptr; LazyBool m_is_ref; LazyBool m_is_aggregate; + LazyBool m_is_instance_ptr; std::pair<TypeSummaryImpl*,bool> m_summary_formatter; std::string m_value; std::string m_summary; std::string m_error; + bool m_val_summary_ok; std::pair<TypeValidatorResult,std::string> m_validation; friend struct StringSummaryFormat; diff --git a/include/lldb/DataFormatters/VectorIterator.h b/include/lldb/DataFormatters/VectorIterator.h new file mode 100644 index 0000000000000..3d96ee4c093b9 --- /dev/null +++ b/include/lldb/DataFormatters/VectorIterator.h @@ -0,0 +1,53 @@ +//===-- VectorIterator.h ----------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_VectorIterator_h_ +#define liblldb_VectorIterator_h_ + +#include "lldb/lldb-forward.h" + +#include "lldb/Core/ConstString.h" +#include "lldb/Target/ExecutionContext.h" + +namespace lldb_private { + namespace formatters + { + class VectorIteratorSyntheticFrontEnd : public SyntheticChildrenFrontEnd + { + public: + VectorIteratorSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp, + ConstString item_name); + + size_t + CalculateNumChildren() override; + + lldb::ValueObjectSP + GetChildAtIndex(size_t idx) override; + + bool + Update() override; + + bool + MightHaveChildren() override; + + size_t + GetIndexOfChildWithName(const ConstString &name) override; + + ~VectorIteratorSyntheticFrontEnd() override; + + private: + ExecutionContextRef m_exe_ctx_ref; + ConstString m_item_name; + lldb::ValueObjectSP m_item_sp; + }; + + } // namespace formatters +} // namespace lldb_private + +#endif // liblldb_CF_h_ |