Skip to content

Commit acf77bd

Browse files
committed
[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
1 parent 4bcadd6 commit acf77bd

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

lldb/source/Core/ValueObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ bool ValueObject::SetData(DataExtractor &data, Status &error) {
850850
static bool CopyStringDataToBufferSP(const StreamString &source,
851851
lldb::DataBufferSP &destination) {
852852
llvm::StringRef src = source.GetString();
853-
src.consume_back(llvm::StringRef("\0", 1));
853+
src = src.rtrim('\0');
854854
destination = std::make_shared<DataBufferHeap>(src.size(), 0);
855855
memcpy(destination->GetBytes(), src.data(), src.size());
856856
return true;

lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ def test(self):
9090

9191
# Different character arrays.
9292
# FIXME: Passing a 'const char *' will ignore any given format,
93-
self.assertIn(r'= " \U0000001b\a\b\f\n\r\t\vaA09\0"', self.getFormatted("character array", "cstring"))
94-
self.assertIn(r'= " \U0000001b\a\b\f\n\r\t\vaA09\0"', self.getFormatted("c-string", "cstring"))
93+
self.assertIn(r'= " \U0000001b\a\b\f\n\r\t\vaA09"', self.getFormatted("character array", "cstring"))
94+
self.assertIn(r'= " \U0000001b\a\b\f\n\r\t\vaA09"', self.getFormatted("c-string", "cstring"))
9595
self.assertIn(' = " \\e\\a\\b\\f\\n\\r\\t\\vaA09" " \\U0000001b\\a\\b\\f\\n\\r\\t\\vaA09"\n',
9696
self.getFormatted("c-string", "(char *)cstring"))
9797
self.assertIn('=\n', self.getFormatted("c-string", "(__UINT64_TYPE__)0"))
@@ -131,10 +131,10 @@ def test(self):
131131
self.assertIn('= 0x2007080c0a0d090b415a617a30391b00\n', self.getFormatted("OSType", string_expr))
132132

133133
# bytes
134-
self.assertIn(r'= " \U0000001b\a\b\f\n\r\t\vaA09\0"', self.getFormatted("bytes", "cstring"))
134+
self.assertIn(r'= " \U0000001b\a\b\f\n\r\t\vaA09"', self.getFormatted("bytes", "cstring"))
135135

136136
# bytes with ASCII
137-
self.assertIn(r'= " \U0000001b\a\b\f\n\r\t\vaA09\0"', self.getFormatted("bytes with ASCII", "cstring"))
137+
self.assertIn(r'= " \U0000001b\a\b\f\n\r\t\vaA09"', self.getFormatted("bytes with ASCII", "cstring"))
138138

139139
# unicode8
140140
self.assertIn('= 0x78 0x56 0x34 0x12\n', self.getFormatted("unicode8", "0x12345678"))

lldb/test/API/functionalities/data-formatter/stringprinter/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ S<char *> Scharstar;
2929

3030
int main (int argc, char const *argv[])
3131
{
32+
const char manytrailingnuls[] = "F\0OO\0BA\0R\0\0\0\0";
3233
A a, b, c;
3334
// Deliberately write past the end of data to test that the formatter stops
3435
// at the end of array.
@@ -59,6 +60,7 @@ int main (int argc, char const *argv[])
5960
//% self.expect_var_path("a.data", summary='"FOOB"')
6061
//% self.expect_var_path("b.data", summary=r'"FO\0B"')
6162
//% self.expect_var_path("c.data", summary=r'"F\0O"')
63+
//% self.expect_var_path("manytrailingnuls", summary=r'"F\0OO\0BA\0R"')
6264
//%
6365
//% for c in ["", "const"]:
6466
//% for v in ["", "volatile"]:

lldb/test/Shell/SymbolFile/DWARF/x86/DW_AT_const_value.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
## Variables specified using string forms. This behavior purely speculative -- I
1818
## don't know of any compiler that would represent character strings this way.
1919
# CHECK: (char[7]) string = "string"
20-
# CHECK: (char[7]) strp = "strp\0\0"
20+
# CHECK: (char[7]) strp = "strp"
2121
## Bogus attribute form. Let's make sure we don't crash at least.
2222
# CHECK: (char[7]) ref4 = <empty constant data>
2323
## A variable of pointer type.

0 commit comments

Comments
 (0)