[Lldb-commits] [lldb] 6f4398d - [lldb] Fix NSURL data formatter truncation issue

Davide Italiano via lldb-commits lldb-commits at lists.llvm.org
Wed Nov 20 12:28:23 PST 2019


Author: Davide Italiano
Date: 2019-11-20T12:28:14-08:00
New Revision: 6f4398d1b9950d48ead91b2b550792f2bbe4778e

URL: https://github.com/llvm/llvm-project/commit/6f4398d1b9950d48ead91b2b550792f2bbe4778e
DIFF: https://github.com/llvm/llvm-project/commit/6f4398d1b9950d48ead91b2b550792f2bbe4778e.diff

LOG: [lldb] Fix NSURL data formatter truncation issue

Remove hardcoded string prefix length assumption causing issues when
concatenating summary for NSURL in NSURLSummaryProvider. Provider relies
on concatenation of NSStringProvider results for summary, and while the
strings are prefixed with '@' in Objective-C, that is not the case in
Swift causing part of the description to be truncated.

This will be tested in the downstream fork.

Patch by Martin Svensson!

Added: 
    

Modified: 
    lldb/source/Plugins/Language/ObjC/Cocoa.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/Language/ObjC/Cocoa.cpp b/lldb/source/Plugins/Language/ObjC/Cocoa.cpp
index ddf3953bb512..8a81abbaedbe 100644
--- a/lldb/source/Plugins/Language/ObjC/Cocoa.cpp
+++ b/lldb/source/Plugins/Language/ObjC/Cocoa.cpp
@@ -694,32 +694,44 @@ bool lldb_private::formatters::NSURLSummaryProvider(
   CompilerType type(valobj.GetCompilerType());
   ValueObjectSP text(valobj.GetSyntheticChildAtOffset(offset_text, type, true));
   ValueObjectSP base(valobj.GetSyntheticChildAtOffset(offset_base, type, true));
-  if (!text)
-    return false;
-  if (text->GetValueAsUnsigned(0) == 0)
+  if (!text || text->GetValueAsUnsigned(0) == 0)
     return false;
+
+  StreamString base_summary;
+  if (base && base->GetValueAsUnsigned(0)) {
+    if (!NSURLSummaryProvider(*base, base_summary, options))
+      base_summary.Clear();
+  }
+  if (base_summary.Empty())
+    return NSStringSummaryProvider(*text, stream, options);
+
   StreamString summary;
-  if (!NSStringSummaryProvider(*text, summary, options))
+  if (!NSStringSummaryProvider(*text, summary, options) || summary.Empty())
     return false;
-  if (base && base->GetValueAsUnsigned(0)) {
-    std::string summary_str = summary.GetString();
-
-    if (!summary_str.empty())
-      summary_str.pop_back();
-    summary_str += " -- ";
-    StreamString base_summary;
-    if (NSURLSummaryProvider(*base, base_summary, options) &&
-        !base_summary.Empty()) {
-      llvm::StringRef base_str = base_summary.GetString();
-      if (base_str.size() > 2)
-        base_str = base_str.drop_front(2);
-      summary_str += base_str;
+
+  const char quote_char = '"';
+  std::string prefix, suffix;
+  if (Language *language = Language::FindPlugin(options.GetLanguage())) {
+    if (!language->GetFormatterPrefixSuffix(*text, ConstString("NSString"),
+                                            prefix, suffix)) {
+      prefix.clear();
+      suffix.clear();
     }
-    summary.Clear();
-    summary.PutCString(summary_str);
   }
-  if (!summary.Empty()) {
-    stream.PutCString(summary.GetString());
+  // @"A" -> @"A
+  llvm::StringRef summary_str = summary.GetString();
+  bool back_consumed = summary_str.consume_back(quote_char + suffix);
+  assert(back_consumed);
+  UNUSED_IF_ASSERT_DISABLED(back_consumed);
+  // @"B" -> B"
+  llvm::StringRef base_summary_str = base_summary.GetString();
+  bool front_consumed = base_summary_str.consume_front(prefix + quote_char);
+  assert(front_consumed);
+  UNUSED_IF_ASSERT_DISABLED(front_consumed);
+  // @"A -- B"
+  if (!summary_str.empty() && !base_summary_str.empty()) {
+    stream.Printf("%s -- %s", summary_str.str().c_str(),
+                  base_summary_str.str().c_str());
     return true;
   }
 


        


More information about the lldb-commits mailing list