[Lldb-commits] [lldb] acf77bd - [lldb] Don't print *trailing* nuls in char arrays
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Wed Mar 9 05:31:28 PST 2022
Author: Pavel Labath
Date: 2022-03-09T14:31:17+01:00
New Revision: acf77bd2fd90d3b1347e50219c556057ef882d55
URL: https://github.com/llvm/llvm-project/commit/acf77bd2fd90d3b1347e50219c556057ef882d55
DIFF: https://github.com/llvm/llvm-project/commit/acf77bd2fd90d3b1347e50219c556057ef882d55.diff
LOG: [lldb] Don't print *trailing* nuls in char arrays
Embedded nul characters are still printed, and they don't terminate the
string. See also D111634.
Differential Revision: https://reviews.llvm.org/D120803
Added:
Modified:
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
Removed:
################################################################################
diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp
index 6bbd98be837b9..8af7c3f6d6eaf 100644
--- a/lldb/source/Core/ValueObject.cpp
+++ b/lldb/source/Core/ValueObject.cpp
@@ -850,7 +850,7 @@ bool ValueObject::SetData(DataExtractor &data, Status &error) {
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;
diff --git a/lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py b/lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py
index 7763305b58db8..ee5c77280623a 100644
--- a/lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py
+++ b/lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py
@@ -90,8 +90,8 @@ def test(self):
# 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 @@ def test(self):
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"))
diff --git a/lldb/test/API/functionalities/data-formatter/stringprinter/main.cpp b/lldb/test/API/functionalities/data-formatter/stringprinter/main.cpp
index ff833da0b7a8a..6b39e4bf6e846 100644
--- a/lldb/test/API/functionalities/data-formatter/stringprinter/main.cpp
+++ b/lldb/test/API/functionalities/data-formatter/stringprinter/main.cpp
@@ -29,6 +29,7 @@ S<char *> Scharstar;
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 @@ int main (int argc, char const *argv[])
//% 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"]:
diff --git a/lldb/test/Shell/SymbolFile/DWARF/x86/DW_AT_const_value.s b/lldb/test/Shell/SymbolFile/DWARF/x86/DW_AT_const_value.s
index 4bb7b2578a59d..720684c19beeb 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/x86/DW_AT_const_value.s
+++ b/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.
More information about the lldb-commits
mailing list