Author: Pavel Labath
Date: 2021-10-11T12:47:11+02:00
New Revision: 8093c2ea574b9f7cbeb6c150f6584446cfd93517

URL: 
https://github.com/llvm/llvm-project/commit/8093c2ea574b9f7cbeb6c150f6584446cfd93517
DIFF: 
https://github.com/llvm/llvm-project/commit/8093c2ea574b9f7cbeb6c150f6584446cfd93517.diff

LOG: [lldb] Make char[N] formatters respect the end of the array (PR44649)

I believe this is a more natural behavior, and it also matches what gdb
does.

Differential Revision: https://reviews.llvm.org/D111399

Added: 
    

Modified: 
    lldb/source/DataFormatters/FormatManager.cpp
    lldb/test/API/functionalities/data-formatter/stringprinter/main.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/DataFormatters/FormatManager.cpp 
b/lldb/source/DataFormatters/FormatManager.cpp
index 6c824d1f77284..2237fdd58a762 100644
--- a/lldb/source/DataFormatters/FormatManager.cpp
+++ b/lldb/source/DataFormatters/FormatManager.cpp
@@ -722,7 +722,7 @@ void FormatManager::LoadSystemFormatters() {
       new StringSummaryFormat(string_flags, "${var%s}"));
 
   lldb::TypeSummaryImplSP string_array_format(
-      new StringSummaryFormat(string_array_flags, "${var%s}"));
+      new StringSummaryFormat(string_array_flags, "${var%char[]}"));
 
   RegularExpression any_size_char_arr(llvm::StringRef("char \\[[0-9]+\\]"));
 

diff  --git 
a/lldb/test/API/functionalities/data-formatter/stringprinter/main.cpp 
b/lldb/test/API/functionalities/data-formatter/stringprinter/main.cpp
index 670ed3db17483..ebc51d0c7aed1 100644
--- a/lldb/test/API/functionalities/data-formatter/stringprinter/main.cpp
+++ b/lldb/test/API/functionalities/data-formatter/stringprinter/main.cpp
@@ -1,7 +1,18 @@
 #include <string>
+#include <cstring>
+
+struct A {
+  char data[4];
+  char overflow[4];
+};
 
 int main (int argc, char const *argv[])
 {
+    A a, b;
+    // Deliberately write past the end of data to test that the formatter stops
+    // at the end of array.
+    memcpy(a.data, "FOOBAR", 7);
+    memcpy(b.data, "FO\0BAR", 7);
     std::string stdstring("Hello\t\tWorld\nI am here\t\tto say hello\n"); 
//%self.addTearDownHook(lambda x: x.runCmd("setting set escape-non-printables 
true"))
     const char* constcharstar = stdstring.c_str();
     std::string longstring(
@@ -20,12 +31,15 @@ int main (int argc, char const *argv[])
       );
     const char* longconstcharstar = longstring.c_str();
     return 0;     //% if self.TraceOn(): self.runCmd('frame variable')
-      //% self.assertTrue(self.frame().FindVariable('stdstring').GetSummary() 
== '"Hello\\t\\tWorld\\nI am here\\t\\tto say hello\\n"')
-     //% 
self.assertTrue(self.frame().FindVariable('constcharstar').GetSummary() == 
'"Hello\\t\\tWorld\\nI am here\\t\\tto say hello\\n"')
-     //% self.runCmd("setting set escape-non-printables false")
-     //% self.assertTrue(self.frame().FindVariable('stdstring').GetSummary() 
== '"Hello\t\tWorld\nI am here\t\tto say hello\n"')
-     //% 
self.assertTrue(self.frame().FindVariable('constcharstar').GetSummary() == 
'"Hello\t\tWorld\nI am here\t\tto say hello\n"')
+    //% self.expect_var_path('stdstring', summary='"Hello\\t\\tWorld\\nI am 
here\\t\\tto say hello\\n"')
+    //% self.expect_var_path('constcharstar', summary='"Hello\\t\\tWorld\\nI 
am here\\t\\tto say hello\\n"')
+    //% self.runCmd("setting set escape-non-printables false")
+    //% self.expect_var_path('stdstring', summary='"Hello\t\tWorld\nI am 
here\t\tto say hello\n"')
+    //% self.expect_var_path('constcharstar', summary='"Hello\t\tWorld\nI am 
here\t\tto say hello\n"')
     //% 
self.assertTrue(self.frame().FindVariable('longstring').GetSummary().endswith('"...'))
     //% 
self.assertTrue(self.frame().FindVariable('longconstcharstar').GetSummary().endswith('"...'))
+    //% self.expect_var_path("a.data", summary='"FOOB"')
+    // FIXME: Should this be "FO\0B" instead?
+    //% self.expect_var_path("b.data", summary='"FO"')
 }
 


        
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to