[Lldb-commits] [PATCH] D153644: [lldb] Print unprintable characters as unsigned

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Jun 23 11:00:36 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG85f40fc676df: [lldb] Print unprintable characters as unsigned (authored by JDevlieghere).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D153644?vs=533985&id=534020#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153644/new/

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
@@ -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<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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153644.534020.patch
Type: text/x-patch
Size: 1426 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230623/2395efb4/attachment-0001.bin>


More information about the lldb-commits mailing list