forked from OSchip/llvm-project
[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
This commit is contained in:
parent
4bcadd6686
commit
acf77bd2fd
|
@ -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;
|
||||
|
|
|
@ -90,8 +90,8 @@ class TestCase(TestBase):
|
|||
|
||||
# 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 @@ class TestCase(TestBase):
|
|||
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"))
|
||||
|
|
|
@ -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"]:
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue