forked from OSchip/llvm-project
Teach the std::wstring data formatter how to properly display strings with embedded NUL bytes
llvm-svn: 242501
This commit is contained in:
parent
2d8315f806
commit
8101f570f8
|
@ -494,7 +494,7 @@ ExtractLibcxxStringInfo (ValueObject& valobj,
|
|||
}
|
||||
|
||||
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::LibcxxWStringSummaryProvider (ValueObject& valobj, Str
|
|||
}
|
||||
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::LibcxxStringSummaryProvider (ValueObject& valobj, Stre
|
|||
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('"');
|
||||
|
|
|
@ -382,6 +382,8 @@ DumpUTFBufferToStream (ConversionResult (*ConvertFunction) (const SourceDataType
|
|||
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
|
||||
|
|
|
@ -65,7 +65,8 @@ class LibcxxStringDataFormatterTestCase(TestBase):
|
|||
'(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(TestBase):
|
|||
'(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
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue