From 8826519e2af08b79944e187aadf11e7a92cbe039 Mon Sep 17 00:00:00 2001 From: Dawn Perchik Date: Fri, 23 Oct 2015 00:02:56 +0000 Subject: [PATCH] Summary provider for char. This patch enables type summary for 'char' type. Given: char c = 'h'; Before this patch, c evaluates as: (char) $0 = 'h' After this patch, we get: (char) $0 = 104 'h' This change allows the formatting of character types in MI to be removed and replaced with that in lldb, and can be useful when evaluating non-printable characters. Patch from evgeny.leviant@gmail.com Reviewed by: granata.enrico Subscribers: lldb-commits Differential Revision: http://reviews.llvm.org/D13657 llvm-svn: 251080 --- lldb/include/lldb/API/SBTypeSummary.h | 7 +++++++ lldb/source/API/SBTypeSummary.cpp | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lldb/include/lldb/API/SBTypeSummary.h b/lldb/include/lldb/API/SBTypeSummary.h index 9e0bf34dfc1f..758d5b157ed9 100644 --- a/lldb/include/lldb/API/SBTypeSummary.h +++ b/lldb/include/lldb/API/SBTypeSummary.h @@ -69,6 +69,9 @@ namespace lldb { public: SBTypeSummary(); + + // Native function summary formatter callback + typedef bool (*FormatCallback) (SBValue, SBTypeSummaryOptions, SBStream&); static SBTypeSummary CreateWithSummaryString (const char* data, @@ -81,6 +84,10 @@ namespace lldb { static SBTypeSummary CreateWithScriptCode (const char* data, uint32_t options = 0); // see lldb::eTypeOption values + + static SBTypeSummary + CreateWithCallback (FormatCallback cb, + uint32_t options = 0); SBTypeSummary (const lldb::SBTypeSummary &rhs); diff --git a/lldb/source/API/SBTypeSummary.cpp b/lldb/source/API/SBTypeSummary.cpp index 08d8b96560a3..1934f4e87f9c 100644 --- a/lldb/source/API/SBTypeSummary.cpp +++ b/lldb/source/API/SBTypeSummary.cpp @@ -146,6 +146,25 @@ SBTypeSummary::CreateWithScriptCode (const char* data, uint32_t options) return SBTypeSummary(TypeSummaryImplSP(new ScriptSummaryFormat(options, "", data))); } +SBTypeSummary +SBTypeSummary::CreateWithCallback (FormatCallback cb, uint32_t options) +{ + return SBTypeSummary( + TypeSummaryImplSP( + cb ? new CXXFunctionSummaryFormat(options, + [cb] (ValueObject& valobj, Stream& stm, const TypeSummaryOptions& opt) -> bool { + BStream stream; + if (!cb(SBValue(valobj.GetSP()), SBTypeSummaryOptions(&opt), stream)) + return false; + stm.Write(stream.GetData(), stream.GetSize()); + return true; + }, + "SBTypeSummary formatter callback" + ) : nullptr + ) + ); +} + SBTypeSummary::SBTypeSummary (const lldb::SBTypeSummary &rhs) : m_opaque_sp(rhs.m_opaque_sp) {