diff --git a/lldb/source/Core/DumpDataExtractor.cpp b/lldb/source/Core/DumpDataExtractor.cpp --- a/lldb/source/Core/DumpDataExtractor.cpp +++ b/lldb/source/Core/DumpDataExtractor.cpp @@ -212,7 +212,8 @@ s.PutChar(c); return; } - s.Printf("\\x%2.2x", c); + // Non-print characters can be assumed to be unsigned. + s.Printf("\\x%2.2x", static_cast(c)); } /// Dump a floating point type. diff --git a/lldb/unittests/Core/DumpDataExtractorTest.cpp b/lldb/unittests/Core/DumpDataExtractorTest.cpp --- a/lldb/unittests/Core/DumpDataExtractorTest.cpp +++ b/lldb/unittests/Core/DumpDataExtractorTest.cpp @@ -131,8 +131,16 @@ // set of bytes to match the 10 byte format but then if the test runs on a // machine where we don't use 10 it'll break. + // Test printable characters. TestDump(llvm::StringRef("aardvark"), lldb::Format::eFormatCString, "\"aardvark\""); + // Test unprintable characters. + TestDump(llvm::StringRef("\xcf\xfa\xed\xfe\f"), lldb::Format::eFormatCString, + "\"\\xcf\\xfa\\xed\\xfe\\f\""); + // Test a mix of printable and unprintable characters. + TestDump(llvm::StringRef("\xcf\xfa\ffoo"), lldb::Format::eFormatCString, + "\"\\xcf\\xfa\\ffoo\""); + TestDump(99, lldb::Format::eFormatDecimal, "99"); // Just prints as a signed integer. TestDump(-1, lldb::Format::eFormatEnum, "-1");