Shuffle APIs around a little bit, so that if you pass custom summary options, we don't end up caching the summary hence obtained. You may want to obtain an uncapped summary, but this should not be reflected in the summary we cache. The drawback is that we don't cache as aggressively as we could, but at least you get to have different summaries with different options without having to reset formatters or the SBValue at each step

llvm-svn: 222280
diff --git a/lldb/include/lldb/API/SBValue.h b/lldb/include/lldb/API/SBValue.h
index db3bd87..427b9ef 100644
--- a/lldb/include/lldb/API/SBValue.h
+++ b/lldb/include/lldb/API/SBValue.h
@@ -91,7 +91,8 @@
     GetSummary ();
     
     const char *
-    GetSummary (lldb::SBTypeSummaryOptions& options);
+    GetSummary (lldb::SBStream& stream,
+                lldb::SBTypeSummaryOptions& options);
     
     const char *
     GetObjectDescription ();
diff --git a/lldb/include/lldb/Core/ValueObject.h b/lldb/include/lldb/Core/ValueObject.h
index 992d9a1..75c4f34 100644
--- a/lldb/include/lldb/Core/ValueObject.h
+++ b/lldb/include/lldb/Core/ValueObject.h
@@ -612,8 +612,9 @@
     GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
                          std::string& destination);
     
-    const char *
-    GetSummaryAsCString (const TypeSummaryOptions& options);
+    bool
+    GetSummaryAsCString (std::string& destination,
+                         const TypeSummaryOptions& options);
     
     bool
     GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
diff --git a/lldb/scripts/Python/interface/SBValue.i b/lldb/scripts/Python/interface/SBValue.i
index db78039..728dae9 100644
--- a/lldb/scripts/Python/interface/SBValue.i
+++ b/lldb/scripts/Python/interface/SBValue.i
@@ -122,7 +122,8 @@
     GetSummary ();
     
     const char *
-    GetSummary (lldb::SBTypeSummaryOptions& options);
+    GetSummary (lldb::SBStream& stream,
+                lldb::SBTypeSummaryOptions& options);
     
     const char *
     GetObjectDescription ();
diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
index 1b7c48c..f56013a 100644
--- a/lldb/source/API/SBValue.cpp
+++ b/lldb/source/API/SBValue.cpp
@@ -642,16 +642,19 @@
 }
 
 const char *
-SBValue::GetSummary (lldb::SBTypeSummaryOptions& options)
+SBValue::GetSummary (lldb::SBStream& stream,
+                     lldb::SBTypeSummaryOptions& options)
 {
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
-    const char *cstr = NULL;
     ValueLocker locker;
     lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        cstr = value_sp->GetSummaryAsCString(options.ref());
+        std::string buffer;
+        if (value_sp->GetSummaryAsCString(buffer,options.ref()) && !buffer.empty())
+            stream.Printf("%s",buffer.c_str());
     }
+    const char* cstr = stream.GetData();
     if (log)
     {
         if (cstr)
diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp
index 9b1cb24..1c3d148 100644
--- a/lldb/source/Core/ValueObject.cpp
+++ b/lldb/source/Core/ValueObject.cpp
@@ -934,17 +934,11 @@
 const char *
 ValueObject::GetSummaryAsCString ()
 {
-    return GetSummaryAsCString(TypeSummaryOptions());
-}
-
-const char *
-ValueObject::GetSummaryAsCString (const TypeSummaryOptions& options)
-{
     if (UpdateValueIfNeeded(true) && m_summary_str.empty())
     {
         GetSummaryAsCString(GetSummaryFormat().get(),
                             m_summary_str,
-                            options);
+                            TypeSummaryOptions());
     }
     if (m_summary_str.empty())
         return NULL;
@@ -952,6 +946,15 @@
 }
 
 bool
+ValueObject::GetSummaryAsCString (std::string& destination,
+                                  const TypeSummaryOptions& options)
+{
+    return GetSummaryAsCString(GetSummaryFormat().get(),
+                        destination,
+                        options);
+}
+
+bool
 ValueObject::IsCStringContainer(bool check_pointer)
 {
     ClangASTType pointee_or_element_clang_type;
diff --git a/lldb/test/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py b/lldb/test/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py
index 75e0a5c..cfa7cb1 100644
--- a/lldb/test/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py
+++ b/lldb/test/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py
@@ -70,8 +70,15 @@
         TheVeryLongOne = self.frame().FindVariable("TheVeryLongOne");
         summaryOptions = lldb.SBTypeSummaryOptions()
         summaryOptions.SetCapping(lldb.eTypeSummaryUncapped)
-        uncappedSummary = TheVeryLongOne.GetSummary(summaryOptions)
+        uncappedSummaryStream = lldb.SBStream()
+        TheVeryLongOne.GetSummary(uncappedSummaryStream,summaryOptions)
+        uncappedSummary = uncappedSummaryStream.GetData()
         self.assertTrue(uncappedSummary.find("someText") > 0, "uncappedSummary does not include the full string")
+        summaryOptions.SetCapping(lldb.eTypeSummaryCapped)
+        cappedSummaryStream = lldb.SBStream()
+        TheVeryLongOne.GetSummary(cappedSummaryStream,summaryOptions)
+        cappedSummary = cappedSummaryStream.GetData()
+        self.assertTrue(cappedSummary.find("someText") <= 0, "cappedSummary includes the full string")
 
         self.expect("frame variable",
                     substrs = ['(std::__1::wstring) s = L"hello world! מזל טוב!"',