[Lldb-commits] [PATCH] D120803: [lldb] Don't print *trailing* nuls in char arrays

Pavel Labath via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Mar 9 05:31:42 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGacf77bd2fd90: [lldb] Don't print *trailing* nuls in char arrays (authored by labath).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120803/new/

https://reviews.llvm.org/D120803

Files:
  lldb/source/Core/ValueObject.cpp
  lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py
  lldb/test/API/functionalities/data-formatter/stringprinter/main.cpp
  lldb/test/Shell/SymbolFile/DWARF/x86/DW_AT_const_value.s


Index: lldb/test/Shell/SymbolFile/DWARF/x86/DW_AT_const_value.s
===================================================================
--- lldb/test/Shell/SymbolFile/DWARF/x86/DW_AT_const_value.s
+++ lldb/test/Shell/SymbolFile/DWARF/x86/DW_AT_const_value.s
@@ -17,7 +17,7 @@
 ## Variables specified using string forms. This behavior purely speculative -- I
 ## don't know of any compiler that would represent character strings this way.
 # CHECK: (char[7]) string = "string"
-# CHECK: (char[7]) strp = "strp\0\0"
+# CHECK: (char[7]) strp = "strp"
 ## Bogus attribute form. Let's make sure we don't crash at least.
 # CHECK: (char[7]) ref4 = <empty constant data>
 ## A variable of pointer type.
Index: lldb/test/API/functionalities/data-formatter/stringprinter/main.cpp
===================================================================
--- lldb/test/API/functionalities/data-formatter/stringprinter/main.cpp
+++ lldb/test/API/functionalities/data-formatter/stringprinter/main.cpp
@@ -29,6 +29,7 @@
 
 int main (int argc, char const *argv[])
 {
+    const char manytrailingnuls[] = "F\0OO\0BA\0R\0\0\0\0";
     A a, b, c;
     // Deliberately write past the end of data to test that the formatter stops
     // at the end of array.
@@ -59,6 +60,7 @@
     //% self.expect_var_path("a.data", summary='"FOOB"')
     //% self.expect_var_path("b.data", summary=r'"FO\0B"')
     //% self.expect_var_path("c.data", summary=r'"F\0O"')
+    //% self.expect_var_path("manytrailingnuls", summary=r'"F\0OO\0BA\0R"')
     //%
     //% for c in ["", "const"]:
     //%   for v in ["", "volatile"]:
Index: lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py
===================================================================
--- lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py
+++ lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py
@@ -90,8 +90,8 @@
 
         # Different character arrays.
         # FIXME: Passing a 'const char *' will ignore any given format,
-        self.assertIn(r'= " \U0000001b\a\b\f\n\r\t\vaA09\0"', self.getFormatted("character array", "cstring"))
-        self.assertIn(r'= " \U0000001b\a\b\f\n\r\t\vaA09\0"', self.getFormatted("c-string", "cstring"))
+        self.assertIn(r'= " \U0000001b\a\b\f\n\r\t\vaA09"', self.getFormatted("character array", "cstring"))
+        self.assertIn(r'= " \U0000001b\a\b\f\n\r\t\vaA09"', self.getFormatted("c-string", "cstring"))
         self.assertIn(' = " \\e\\a\\b\\f\\n\\r\\t\\vaA09" " \\U0000001b\\a\\b\\f\\n\\r\\t\\vaA09"\n',
                       self.getFormatted("c-string", "(char *)cstring"))
         self.assertIn('=\n', self.getFormatted("c-string", "(__UINT64_TYPE__)0"))
@@ -131,10 +131,10 @@
         self.assertIn('= 0x2007080c0a0d090b415a617a30391b00\n', self.getFormatted("OSType", string_expr))
 
         # bytes
-        self.assertIn(r'= " \U0000001b\a\b\f\n\r\t\vaA09\0"', self.getFormatted("bytes", "cstring"))
+        self.assertIn(r'= " \U0000001b\a\b\f\n\r\t\vaA09"', self.getFormatted("bytes", "cstring"))
 
         # bytes with ASCII
-        self.assertIn(r'= " \U0000001b\a\b\f\n\r\t\vaA09\0"', self.getFormatted("bytes with ASCII", "cstring"))
+        self.assertIn(r'= " \U0000001b\a\b\f\n\r\t\vaA09"', self.getFormatted("bytes with ASCII", "cstring"))
 
         # unicode8
         self.assertIn('= 0x78 0x56 0x34 0x12\n', self.getFormatted("unicode8", "0x12345678"))
Index: lldb/source/Core/ValueObject.cpp
===================================================================
--- lldb/source/Core/ValueObject.cpp
+++ lldb/source/Core/ValueObject.cpp
@@ -850,7 +850,7 @@
 static bool CopyStringDataToBufferSP(const StreamString &source,
                                      lldb::DataBufferSP &destination) {
   llvm::StringRef src = source.GetString();
-  src.consume_back(llvm::StringRef("\0", 1));
+  src = src.rtrim('\0');
   destination = std::make_shared<DataBufferHeap>(src.size(), 0);
   memcpy(destination->GetBytes(), src.data(), src.size());
   return true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120803.414079.patch
Type: text/x-patch
Size: 4057 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220309/48cf8735/attachment.bin>


More information about the lldb-commits mailing list