From bb557065f60fa03e7a46a0b69bc0abea6ae46ca4 Mon Sep 17 00:00:00 2001 From: Enrico Granata Date: Tue, 10 Feb 2015 23:02:25 +0000 Subject: [PATCH] Add an LLDB summary for CMTime. Fixes rdar://15370376 llvm-svn: 228759 --- .../DataFormatters/CXXFormatterFunctions.h | 3 + .../lldb/DataFormatters/FormatManager.h | 4 + lldb/lldb.xcodeproj/project.pbxproj | 4 + lldb/source/DataFormatters/CoreMedia.cpp | 85 +++++++++++++++++++ lldb/source/DataFormatters/FormatManager.cpp | 19 +++++ 5 files changed, 115 insertions(+) create mode 100644 lldb/source/DataFormatters/CoreMedia.cpp diff --git a/lldb/include/lldb/DataFormatters/CXXFormatterFunctions.h b/lldb/include/lldb/DataFormatters/CXXFormatterFunctions.h index 53b7468bb13c..81856aae1d48 100644 --- a/lldb/include/lldb/DataFormatters/CXXFormatterFunctions.h +++ b/lldb/include/lldb/DataFormatters/CXXFormatterFunctions.h @@ -186,6 +186,9 @@ namespace lldb_private { extern template bool ObjCSELSummaryProvider (ValueObject&, Stream&, const TypeSummaryOptions&); + bool + CMTimeSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); + SyntheticChildrenFrontEnd* NSArraySyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP); SyntheticChildrenFrontEnd* NSDictionarySyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP); diff --git a/lldb/include/lldb/DataFormatters/FormatManager.h b/lldb/include/lldb/DataFormatters/FormatManager.h index 37dae6536761..a1f4b59fb344 100644 --- a/lldb/include/lldb/DataFormatters/FormatManager.h +++ b/lldb/include/lldb/DataFormatters/FormatManager.h @@ -287,6 +287,7 @@ private: ConstString m_coreservices_category_name; ConstString m_vectortypes_category_name; ConstString m_appkit_category_name; + ConstString m_coremedia_category_name; HardcodedFormatterFinders m_hardcoded_formats; HardcodedFormatterFinders m_hardcoded_summaries; @@ -326,6 +327,9 @@ private: void LoadObjCFormatters (); + + void + LoadCoreMediaFormatters (); void LoadHardcodedFormatters (); diff --git a/lldb/lldb.xcodeproj/project.pbxproj b/lldb/lldb.xcodeproj/project.pbxproj index a753d42798b2..1c0ff119ccb1 100644 --- a/lldb/lldb.xcodeproj/project.pbxproj +++ b/lldb/lldb.xcodeproj/project.pbxproj @@ -784,6 +784,7 @@ 9475C18F14E5F858001BFC6D /* SBTypeNameSpecifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 9475C18C14E5F826001BFC6D /* SBTypeNameSpecifier.h */; settings = {ATTRIBUTES = (Public, ); }; }; 947A1D641616476B0017C8D1 /* CommandObjectPlugin.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 947A1D621616476A0017C8D1 /* CommandObjectPlugin.cpp */; }; 947A1D651616476B0017C8D1 /* CommandObjectPlugin.h in Headers */ = {isa = PBXBuildFile; fileRef = 947A1D631616476A0017C8D1 /* CommandObjectPlugin.h */; }; + 9492E2A51A8AC11000295BBD /* CoreMedia.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9492E2A41A8AC11000295BBD /* CoreMedia.cpp */; }; 949ADF031406F648004833E1 /* ValueObjectConstResultImpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 949ADF021406F648004833E1 /* ValueObjectConstResultImpl.cpp */; }; 94B6E76213D88365005F417F /* ValueObjectSyntheticFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94B6E76113D88362005F417F /* ValueObjectSyntheticFilter.cpp */; }; 94BA8B6D176F8C9B005A91B5 /* Range.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94BA8B6C176F8C9B005A91B5 /* Range.cpp */; }; @@ -2420,6 +2421,7 @@ 9475C18D14E5F834001BFC6D /* SBTypeNameSpecifier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SBTypeNameSpecifier.cpp; path = source/API/SBTypeNameSpecifier.cpp; sourceTree = ""; }; 947A1D621616476A0017C8D1 /* CommandObjectPlugin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CommandObjectPlugin.cpp; path = source/Commands/CommandObjectPlugin.cpp; sourceTree = ""; }; 947A1D631616476A0017C8D1 /* CommandObjectPlugin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CommandObjectPlugin.h; path = source/Commands/CommandObjectPlugin.h; sourceTree = ""; }; + 9492E2A41A8AC11000295BBD /* CoreMedia.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CoreMedia.cpp; path = source/DataFormatters/CoreMedia.cpp; sourceTree = ""; }; 949ADF001406F62E004833E1 /* ValueObjectConstResultImpl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ValueObjectConstResultImpl.h; path = include/lldb/Core/ValueObjectConstResultImpl.h; sourceTree = ""; }; 949ADF021406F648004833E1 /* ValueObjectConstResultImpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ValueObjectConstResultImpl.cpp; path = source/Core/ValueObjectConstResultImpl.cpp; sourceTree = ""; }; 94B6E76013D8833C005F417F /* ValueObjectSyntheticFilter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ValueObjectSyntheticFilter.h; path = include/lldb/Core/ValueObjectSyntheticFilter.h; sourceTree = ""; }; @@ -4969,6 +4971,7 @@ children = ( 94CD704B16F8DDEA00CF1E42 /* CF.cpp */, 94CD704C16F8DDEA00CF1E42 /* Cocoa.cpp */, + 9492E2A41A8AC11000295BBD /* CoreMedia.cpp */, 94CB255F16B069800059775D /* CXXFormatterFunctions.h */, 94CB255716B069770059775D /* CXXFormatterFunctions.cpp */, 94CB256016B069800059775D /* DataVisualization.h */, @@ -6057,6 +6060,7 @@ 268900EB13353E6F00698AC0 /* ExecutionContext.cpp in Sources */, 268900EC13353E6F00698AC0 /* LanguageRuntime.cpp in Sources */, 268900ED13353E6F00698AC0 /* ObjCLanguageRuntime.cpp in Sources */, + 9492E2A51A8AC11000295BBD /* CoreMedia.cpp in Sources */, 268900EE13353E6F00698AC0 /* PathMappingList.cpp in Sources */, 268900EF13353E6F00698AC0 /* Platform.cpp in Sources */, 268900F013353E6F00698AC0 /* Process.cpp in Sources */, diff --git a/lldb/source/DataFormatters/CoreMedia.cpp b/lldb/source/DataFormatters/CoreMedia.cpp new file mode 100644 index 000000000000..003d01f1569d --- /dev/null +++ b/lldb/source/DataFormatters/CoreMedia.cpp @@ -0,0 +1,85 @@ +//===-- CoreMedia.cpp --------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/DataFormatters/CXXFormatterFunctions.h" + +#include "lldb/Core/Flags.h" +#include "lldb/Symbol/ClangASTContext.h" + +#include + +using namespace lldb; +using namespace lldb_private; +using namespace lldb_private::formatters; + +bool +lldb_private::formatters::CMTimeSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options) +{ + ClangASTContext *ast_ctx = ClangASTContext::GetASTContext(valobj.GetClangType().GetASTContext()); + if (!ast_ctx) + return false; + + // fetch children by offset to compensate for potential lack of debug info + auto int64_ty = ast_ctx->GetIntTypeFromBitSize(64, true); + auto int32_ty = ast_ctx->GetIntTypeFromBitSize(32, true); + + auto value_sp(valobj.GetSyntheticChildAtOffset(0, int64_ty, true)); + auto timescale_sp(valobj.GetSyntheticChildAtOffset(8, int32_ty, true)); + auto flags_sp(valobj.GetSyntheticChildAtOffset(12, int32_ty, true)); + + if (!value_sp || !timescale_sp || !flags_sp) + return false; + + auto value = value_sp->GetValueAsUnsigned(0); + auto timescale = (int32_t)timescale_sp->GetValueAsUnsigned(0); // the timescale specifies the fraction of a second each unit in the numerator occupies + auto flags = Flags(flags_sp->GetValueAsUnsigned(0) & 0x00000000000000FF); // the flags I need sit in the LSB + + const unsigned int FlagPositiveInf = 4; + const unsigned int FlagNegativeInf = 8; + const unsigned int FlagIndefinite = 16; + + if (flags.AnySet(FlagIndefinite)) + { + stream.Printf("indefinite"); + return true; + } + + if (flags.AnySet(FlagPositiveInf)) + { + stream.Printf("+oo"); + return true; + } + + if (flags.AnySet(FlagNegativeInf)) + { + stream.Printf("-oo"); + return true; + } + + if (timescale == 0) + return false; + + switch (timescale) + { + case 0: + return false; + case 1: + stream.Printf("%" PRId64 " seconds", value); + return true; + case 2: + stream.Printf("%" PRId64 " half seconds", value); + return true; + case 3: + stream.Printf("%" PRId64 " third%sof a second", value, value == 1 ? " " : "s "); + return true; + default: + stream.Printf("%" PRId64 " %" PRId32 " of a second", value, timescale); + return true; + } +} diff --git a/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp index ae52b3309ed8..324f05b8f6a0 100644 --- a/lldb/source/DataFormatters/FormatManager.cpp +++ b/lldb/source/DataFormatters/FormatManager.cpp @@ -866,6 +866,7 @@ FormatManager::FormatManager() : m_coreservices_category_name(ConstString("CoreServices")), m_vectortypes_category_name(ConstString("VectorTypes")), m_appkit_category_name(ConstString("AppKit")), + m_coremedia_category_name(ConstString("CoreMedia")), m_hardcoded_formats(), m_hardcoded_summaries(), m_hardcoded_synthetics(), @@ -876,6 +877,7 @@ FormatManager::FormatManager() : LoadLibStdcppFormatters(); LoadLibcxxFormatters(); LoadObjCFormatters(); + LoadCoreMediaFormatters(); LoadHardcodedFormatters(); EnableCategory(m_objc_category_name,TypeCategoryMap::Last); @@ -1562,6 +1564,23 @@ FormatManager::LoadObjCFormatters() vector_flags); } +void +FormatManager::LoadCoreMediaFormatters() +{ + TypeSummaryImpl::Flags cm_flags; + cm_flags.SetCascades(true) + .SetDontShowChildren(false) + .SetDontShowValue(false) + .SetHideItemNames(false) + .SetShowMembersOneLiner(false) + .SetSkipPointers(false) + .SetSkipReferences(false); + + TypeCategoryImpl::SharedPointer cm_category_sp = GetCategory(m_coremedia_category_name); + + AddCXXSummary(cm_category_sp, lldb_private::formatters::CMTimeSummaryProvider, "CMTime summary provider", ConstString("CMTime"), cm_flags); +} + void FormatManager::LoadHardcodedFormatters() {