JDevlieghere created this revision. JDevlieghere added reviewers: jasonmolenda, DavidSpickett, bulbazord. Herald added a project: All. JDevlieghere requested review of this revision.
When specifying the C-string format for dumping memory, we treat unprintable characters as signed. Whether a character is signed or not is implementation defined, but all printable characters are signed. Therefore it's fair to assume that unprintable characters are unsigned. Before this patch, the newly added unit test would print: "\xffffffcf\xfffffffa\xffffffed\xfffffffe\fâ With this patch, it prints what you would expect: â\xcf\xfa\xed\xfe\fâ rdar://111126134 https://reviews.llvm.org/D153644 Files: lldb/source/Core/DumpDataExtractor.cpp lldb/unittests/Core/DumpDataExtractorTest.cpp Index: lldb/unittests/Core/DumpDataExtractorTest.cpp =================================================================== --- lldb/unittests/Core/DumpDataExtractorTest.cpp +++ lldb/unittests/Core/DumpDataExtractorTest.cpp @@ -133,6 +133,8 @@ TestDump(llvm::StringRef("aardvark"), lldb::Format::eFormatCString, "\"aardvark\""); + TestDump(llvm::StringRef("\xcf\xfa\xed\xfe\f"), lldb::Format::eFormatCString, + "\"\\xcf\\xfa\\xed\\xfe\\f\""); TestDump<uint16_t>(99, lldb::Format::eFormatDecimal, "99"); // Just prints as a signed integer. TestDump(-1, lldb::Format::eFormatEnum, "-1"); Index: lldb/source/Core/DumpDataExtractor.cpp =================================================================== --- lldb/source/Core/DumpDataExtractor.cpp +++ 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<unsigned char>(c)); } /// Dump a floating point type.
Index: lldb/unittests/Core/DumpDataExtractorTest.cpp =================================================================== --- lldb/unittests/Core/DumpDataExtractorTest.cpp +++ lldb/unittests/Core/DumpDataExtractorTest.cpp @@ -133,6 +133,8 @@ TestDump(llvm::StringRef("aardvark"), lldb::Format::eFormatCString, "\"aardvark\""); + TestDump(llvm::StringRef("\xcf\xfa\xed\xfe\f"), lldb::Format::eFormatCString, + "\"\\xcf\\xfa\\xed\\xfe\\f\""); TestDump<uint16_t>(99, lldb::Format::eFormatDecimal, "99"); // Just prints as a signed integer. TestDump(-1, lldb::Format::eFormatEnum, "-1"); Index: lldb/source/Core/DumpDataExtractor.cpp =================================================================== --- lldb/source/Core/DumpDataExtractor.cpp +++ 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<unsigned char>(c)); } /// Dump a floating point type.
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits