[Lldb-commits] [PATCH] D70393: [lldb] Fix NSURL data formatter truncation issue in Swift

Martin Svensson via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Nov 18 06:13:01 PST 2019


poya created this revision.
poya added a reviewer: davide.
Herald added subscribers: lldb-commits, JDevlieghere.
Herald added a project: LLDB.

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.

https://bugs.swift.org/browse/SR-5994


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D70393

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


Index: lldb/source/Plugins/Language/ObjC/Cocoa.cpp
===================================================================
--- lldb/source/Plugins/Language/ObjC/Cocoa.cpp
+++ lldb/source/Plugins/Language/ObjC/Cocoa.cpp
@@ -659,6 +659,29 @@
   return true;
 }
 
+static void NSURL_ConcatSummary(StreamString &first, const StreamString &second,
+    std::string prefix, std::string suffix) {
+  if (second.Empty())
+    return;
+
+  // Remove suffix and quotation char from first
+  llvm::StringRef first_str = std::string(first.GetString());
+  first_str.consume_back(suffix);
+  if (!first_str.empty())
+    first_str = first_str.drop_back();
+
+  // Remove prefix and quotation char from second
+  llvm::StringRef second_str = std::string(second.GetString());
+  second_str.consume_front(prefix);
+  if (!second_str.empty())
+    second_str = second_str.drop_front();
+
+  if (!first_str.empty() && !second_str.empty()) {
+    first.Clear();
+    first.Printf("%s -- %s", first_str.str().c_str(), second_str.str().c_str());
+  }
+}
+
 bool lldb_private::formatters::NSURLSummaryProvider(
     ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
   ProcessSP process_sp = valobj.GetProcessSP();
@@ -702,21 +725,20 @@
   if (!NSStringSummaryProvider(*text, summary, options))
     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;
+      std::string prefix, suffix;
+      if (Language *language = Language::FindPlugin(options.GetLanguage())) {
+        if (!language->GetFormatterPrefixSuffix(*text, ConstString("NSString"),
+                                                prefix, suffix)) {
+          prefix.clear();
+          suffix.clear();
+        }
+      }
+
+      NSURL_ConcatSummary(summary, base_summary, prefix, suffix);
     }
-    summary.Clear();
-    summary.PutCString(summary_str);
   }
   if (!summary.Empty()) {
     stream.PutCString(summary.GetString());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70393.229823.patch
Type: text/x-patch
Size: 2349 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20191118/a89b95bb/attachment.bin>


More information about the lldb-commits mailing list