[Lldb-commits] [lldb] r198724 - New and improved data formatter for std::shared_ptr<> and std::weak_ptr<>
Enrico Granata
egranata at apple.com
Tue Jan 7 17:36:59 PST 2014
Author: enrico
Date: Tue Jan 7 19:36:59 2014
New Revision: 198724
URL: http://llvm.org/viewvc/llvm-project?rev=198724&view=rev
Log:
New and improved data formatter for std::shared_ptr<> and std::weak_ptr<>
Modified:
lldb/trunk/include/lldb/Core/ValueObject.h
lldb/trunk/include/lldb/DataFormatters/CXXFormatterFunctions.h
lldb/trunk/source/Core/ValueObject.cpp
lldb/trunk/source/DataFormatters/FormatManager.cpp
lldb/trunk/source/DataFormatters/LibCxx.cpp
Modified: lldb/trunk/include/lldb/Core/ValueObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObject.h?rev=198724&r1=198723&r2=198724&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObject.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObject.h Tue Jan 7 19:36:59 2014
@@ -619,7 +619,8 @@ public:
DumpPrintableRepresentation (Stream& s,
ValueObjectRepresentationStyle val_obj_display = eValueObjectRepresentationStyleSummary,
lldb::Format custom_format = lldb::eFormatInvalid,
- PrintableRepresentationSpecialCases special = ePrintableRepresentationSpecialCasesAllow);
+ PrintableRepresentationSpecialCases special = ePrintableRepresentationSpecialCasesAllow,
+ bool do_dump_error = true);
bool
GetValueIsValid () const;
Modified: lldb/trunk/include/lldb/DataFormatters/CXXFormatterFunctions.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/CXXFormatterFunctions.h?rev=198724&r1=198723&r2=198724&view=diff
==============================================================================
--- lldb/trunk/include/lldb/DataFormatters/CXXFormatterFunctions.h (original)
+++ lldb/trunk/include/lldb/DataFormatters/CXXFormatterFunctions.h Tue Jan 7 19:36:59 2014
@@ -79,6 +79,9 @@ namespace lldb_private {
bool
LibcxxWStringSummaryProvider (ValueObject& valobj, Stream& stream); // libc++ std::wstring
+
+ bool
+ LibcxxSmartPointerSummaryProvider (ValueObject& valobj, Stream& stream); // libc++ std::shared_ptr<> and std::weak_ptr<>
bool
ObjCClassSummaryProvider (ValueObject& valobj, Stream& stream);
Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=198724&r1=198723&r2=198724&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Tue Jan 7 19:36:59 2014
@@ -1546,7 +1546,8 @@ bool
ValueObject::DumpPrintableRepresentation(Stream& s,
ValueObjectRepresentationStyle val_obj_display,
Format custom_format,
- PrintableRepresentationSpecialCases special)
+ PrintableRepresentationSpecialCases special,
+ bool do_dump_error)
{
Flags flags(GetTypeInfo());
@@ -1745,7 +1746,12 @@ ValueObject::DumpPrintableRepresentation
else
{
if (m_error.Fail())
- s.Printf("<%s>", m_error.AsCString());
+ {
+ if (do_dump_error)
+ s.Printf("<%s>", m_error.AsCString());
+ else
+ return false;
+ }
else if (val_obj_display == eValueObjectRepresentationStyleSummary)
s.PutCString("<no summary available>");
else if (val_obj_display == eValueObjectRepresentationStyleValue)
Modified: lldb/trunk/source/DataFormatters/FormatManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/FormatManager.cpp?rev=198724&r1=198723&r2=198724&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/FormatManager.cpp (original)
+++ lldb/trunk/source/DataFormatters/FormatManager.cpp Tue Jan 7 19:36:59 2014
@@ -963,8 +963,9 @@ FormatManager::LoadLibcxxFormatters()
AddCXXSummary(libcxx_category_sp, lldb_private::formatters::LibcxxContainerSummaryProvider, "libc++ std::unordered containers summary provider", ConstString("^(std::__1::)unordered_(multi)?(map|set)<.+> >$"), stl_summary_flags, true);
stl_summary_flags.SetSkipPointers(true);
- AddStringSummary(libcxx_category_sp, "{${var.__ptr_%S}} (strong=${var.count} weak=${var.weak_count})}", ConstString("^std::__1::shared_ptr<.+>(( )?&)?$"), stl_summary_flags, true);
- AddStringSummary(libcxx_category_sp, "{${var.__ptr_%S}} (strong=${var.count} weak=${var.weak_count})}", ConstString("^std::__1::weak_ptr<.+>(( )?&)?$"), stl_summary_flags, true);
+
+ AddCXXSummary(libcxx_category_sp, lldb_private::formatters::LibcxxSmartPointerSummaryProvider, "libc++ std::shared_ptr summary provider", ConstString("^std::__1::shared_ptr<.+>(( )?&)?$"), stl_summary_flags, true);
+ AddCXXSummary(libcxx_category_sp, lldb_private::formatters::LibcxxSmartPointerSummaryProvider, "libc++ std::weak_ptr summary provider", ConstString("^std::__1::weak_ptr<.+>(( )?&)?$"), stl_summary_flags, true);
AddCXXSynthetic(libcxx_category_sp, lldb_private::formatters::LibCxxVectorIteratorSyntheticFrontEndCreator, "std::vector iterator synthetic children", ConstString("^std::__1::__wrap_iter<.+>$"), stl_synth_flags, true);
Modified: lldb/trunk/source/DataFormatters/LibCxx.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/LibCxx.cpp?rev=198724&r1=198723&r2=198724&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/LibCxx.cpp (original)
+++ lldb/trunk/source/DataFormatters/LibCxx.cpp Tue Jan 7 19:36:59 2014
@@ -26,6 +26,51 @@ using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::formatters;
+bool
+lldb_private::formatters::LibcxxSmartPointerSummaryProvider (ValueObject& valobj, Stream& stream)
+{
+ ValueObjectSP valobj_sp(valobj.GetNonSyntheticValue());
+ if (!valobj_sp)
+ return false;
+ ValueObjectSP ptr_sp(valobj_sp->GetChildMemberWithName(ConstString("__ptr_"), true));
+ ValueObjectSP count_sp(valobj_sp->GetChildAtNamePath( {ConstString("__cntrl_"),ConstString("__shared_owners_")} ));
+ ValueObjectSP weakcount_sp(valobj_sp->GetChildAtNamePath( {ConstString("__cntrl_"),ConstString("__shared_weak_owners_")} ));
+
+ if (!ptr_sp)
+ return false;
+
+ if (ptr_sp->GetValueAsUnsigned(0) == 0)
+ {
+ stream.Printf("nullptr");
+ return true;
+ }
+ else
+ {
+ bool print_pointee = false;
+ Error error;
+ ValueObjectSP pointee_sp = ptr_sp->Dereference(error);
+ if (pointee_sp && error.Success())
+ {
+ if (pointee_sp->DumpPrintableRepresentation(stream,
+ ValueObject::eValueObjectRepresentationStyleSummary,
+ lldb::eFormatInvalid,
+ ValueObject::ePrintableRepresentationSpecialCasesDisable,
+ false))
+ print_pointee = true;
+ }
+ if (!print_pointee)
+ stream.Printf("ptr = 0x%" PRIx64, ptr_sp->GetValueAsUnsigned(0));
+ }
+
+ if (count_sp)
+ stream.Printf(" strong=%" PRIu64, 1+count_sp->GetValueAsUnsigned(0));
+
+ if (weakcount_sp)
+ stream.Printf(" weak=%" PRIu64, 1+weakcount_sp->GetValueAsUnsigned(0));
+
+ return true;
+}
+
lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEnd::LibcxxVectorBoolSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp) :
SyntheticChildrenFrontEnd(*valobj_sp.get()),
m_bool_type(),
More information about the lldb-commits
mailing list