diff --git a/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp --- a/lldb/source/DataFormatters/FormatManager.cpp +++ b/lldb/source/DataFormatters/FormatManager.cpp @@ -722,7 +722,7 @@ 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 --- 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 +#include + +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 @@ ); 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"') }