Author: enrico Date: Thu Jul 16 20:56:25 2015 New Revision: 242501 URL: http://llvm.org/viewvc/llvm-project?rev=242501&view=rev Log: Teach the std::wstring data formatter how to properly display strings with embedded NUL bytes
Modified: lldb/trunk/source/DataFormatters/CXXFormatterFunctions.cpp lldb/trunk/source/DataFormatters/StringPrinter.cpp lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/libcxx/string/main.cpp Modified: lldb/trunk/source/DataFormatters/CXXFormatterFunctions.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/CXXFormatterFunctions.cpp?rev=242501&r1=242500&r2=242501&view=diff ============================================================================== --- lldb/trunk/source/DataFormatters/CXXFormatterFunctions.cpp (original) +++ lldb/trunk/source/DataFormatters/CXXFormatterFunctions.cpp Thu Jul 16 20:56:25 2015 @@ -494,7 +494,7 @@ ExtractLibcxxStringInfo (ValueObject& va } bool -lldb_private::formatters::LibcxxWStringSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options) +lldb_private::formatters::LibcxxWStringSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& summary_options) { uint64_t size = 0; ValueObjectSP location_sp((ValueObject*)nullptr); @@ -507,7 +507,43 @@ lldb_private::formatters::LibcxxWStringS } if (!location_sp) return false; - return WCharStringSummaryProvider(*location_sp.get(), stream, options); + + DataExtractor extractor; + if (summary_options.GetCapping() == TypeSummaryCapping::eTypeSummaryCapped) + size = std::min<decltype(size)>(size, valobj.GetTargetSP()->GetMaximumSizeOfStringSummary()); + location_sp->GetPointeeData(extractor, 0, size); + + // std::wstring::size() is measured in 'characters', not bytes + auto wchar_t_size = valobj.GetTargetSP()->GetScratchClangASTContext()->GetBasicType(lldb::eBasicTypeWChar).GetByteSize(nullptr); + + ReadBufferAndDumpToStreamOptions options(valobj); + options.SetData(extractor); + options.SetStream(&stream); + options.SetPrefixToken('L'); + options.SetQuote('"'); + options.SetSourceSize(size); + options.SetBinaryZeroIsTerminator(false); + + switch (wchar_t_size) + { + case 1: + lldb_private::formatters::ReadBufferAndDumpToStream<lldb_private::formatters::StringElementType::UTF8>(options); + break; + + case 2: + lldb_private::formatters::ReadBufferAndDumpToStream<lldb_private::formatters::StringElementType::UTF16>(options); + break; + + case 4: + lldb_private::formatters::ReadBufferAndDumpToStream<lldb_private::formatters::StringElementType::UTF32>(options); + break; + + default: + stream.Printf("size for wchar_t is not valid"); + return true; + } + + return true; } bool @@ -534,7 +570,7 @@ lldb_private::formatters::LibcxxStringSu location_sp->GetPointeeData(extractor, 0, size); ReadBufferAndDumpToStreamOptions options(valobj); - options.SetData(extractor); // none of this matters for a string - pass some defaults + options.SetData(extractor); options.SetStream(&stream); options.SetPrefixToken(0); options.SetQuote('"'); Modified: lldb/trunk/source/DataFormatters/StringPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/StringPrinter.cpp?rev=242501&r1=242500&r2=242501&view=diff ============================================================================== --- lldb/trunk/source/DataFormatters/StringPrinter.cpp (original) +++ lldb/trunk/source/DataFormatters/StringPrinter.cpp Thu Jul 16 20:56:25 2015 @@ -382,6 +382,8 @@ DumpUTFBufferToStream (ConversionResult utf8_data_ptr = (UTF8*)utf8_data_buffer_sp->GetBytes(); utf8_data_end_ptr = utf8_data_ptr + utf8_data_buffer_sp->GetByteSize(); ConvertFunction ( &data_ptr, data_end_ptr, &utf8_data_ptr, utf8_data_end_ptr, lenientConversion ); + if (false == zero_is_terminator) + utf8_data_end_ptr = utf8_data_ptr; utf8_data_ptr = (UTF8*)utf8_data_buffer_sp->GetBytes(); // needed because the ConvertFunction will change the value of the data_ptr } else Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py?rev=242501&r1=242500&r2=242501&view=diff ============================================================================== --- lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py (original) +++ lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py Thu Jul 16 20:56:25 2015 @@ -65,7 +65,8 @@ class LibcxxStringDataFormatterTestCase( '(const wchar_t *) mazeltov = 0x','L"××× ×××"', '(std::__1::string) q = "hello world"', '(std::__1::string) Q = "quite a long std::strin with lots of info inside it"', - '(std::__1::string) IHaveEmbeddedZeros = "a\\0b\\0c\\0d"']) + '(std::__1::string) IHaveEmbeddedZeros = "a\\0b\\0c\\0d"', + '(std::__1::wstring) IHaveEmbeddedZerosToo = L"hello world!\\0ã¦ã ã«ãä¨ãã §æ§ ãã ã¸ç¦ç©¤è¥© ãã馩ãªã§ 䤦ç£"']) self.runCmd("n") @@ -88,7 +89,8 @@ class LibcxxStringDataFormatterTestCase( '(const wchar_t *) mazeltov = 0x','L"××× ×××"', '(std::__1::string) q = "hello world"', '(std::__1::string) Q = "quite a long std::strin with lots of info inside it"', - '(std::__1::string) IHaveEmbeddedZeros = "a\\0b\\0c\\0d"']) + '(std::__1::string) IHaveEmbeddedZeros = "a\\0b\\0c\\0d"', + '(std::__1::wstring) IHaveEmbeddedZerosToo = L"hello world!\\0ã¦ã ã«ãä¨ãã §æ§ ãã ã¸ç¦ç©¤è¥© ãã馩ãªã§ 䤦ç£"']) if __name__ == '__main__': import atexit Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/libcxx/string/main.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/libcxx/string/main.cpp?rev=242501&r1=242500&r2=242501&view=diff ============================================================================== --- lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/libcxx/string/main.cpp (original) +++ lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/libcxx/string/main.cpp Thu Jul 16 20:56:25 2015 @@ -9,6 +9,7 @@ int main() std::string Q("quite a long std::strin with lots of info inside it"); std::string TheVeryLongOne("12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345 6789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012 3456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890someText1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901 2345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678 9012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345 6789012345678901234567890123456789012345678901234567890"); std::string IHaveEmbeddedZeros("a\0b\0c\0d",7); + std::wstring IHaveEmbeddedZerosToo(L"hello world!\0ã¦ã ã«ãä¨ãã §æ§ ãã ã¸ç¦ç©¤è¥© ãã馩ãªã§ 䤦ç£", 38); S.assign(L"!!!!!"); // Set break point at this line. return 0; } _______________________________________________ lldb-commits mailing list lldb-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits