[PATCH] D48271: [llvm-readobj] Fix printing format

Paul Semel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 21 13:49:16 PDT 2018


paulsemel updated this revision to Diff 152372.
paulsemel marked an inline comment as done.
paulsemel added a comment.

Added a test with non printable characters.


Repository:
  rL LLVM

https://reviews.llvm.org/D48271

Files:
  test/tools/llvm-readobj/print-section.test
  tools/llvm-readobj/ELFDumper.cpp


Index: tools/llvm-readobj/ELFDumper.cpp
===================================================================
--- tools/llvm-readobj/ELFDumper.cpp
+++ tools/llvm-readobj/ELFDumper.cpp
@@ -3243,8 +3243,14 @@
       CurrentWord++;
       continue;
     }
-    OS << format("[%6tx]", CurrentWord - SecContent);
-    OS << format(" %.*s\n", WordSize, CurrentWord);
+    OS << format("[%6tx]  ", CurrentWord - SecContent);
+    for (size_t i = 0; i < WordSize; ++i) {
+      if (isprint(CurrentWord[i]))
+        OS << CurrentWord[i];
+      else
+        OS << '.';
+    }
+    OS << '\n';
     CurrentWord += WordSize + 1;
   }
   OS.flush();
@@ -4270,8 +4276,14 @@
     W.startLine() << "["
                   << to_string(
                          format_hex_no_prefix((CurrentWord - SecContent), 6))
-                  << "]";
-    W.startLine() << format(" %.*s\n", WordSize, CurrentWord);
+                  << "]  ";
+    for (size_t i = 0; i < WordSize; ++i) {
+      if (isprint(CurrentWord[i]))
+        W.startLine() << CurrentWord[i];
+      else
+        W.startLine() << '.';
+    }
+    W.startLine() << '\n';
     CurrentWord += WordSize + 1;
   }
 }
Index: test/tools/llvm-readobj/print-section.test
===================================================================
--- /dev/null
+++ test/tools/llvm-readobj/print-section.test
@@ -0,0 +1,8 @@
+RUN: llvm-readobj -p .text %p/Inputs/elf-groups.x86_64 \
+RUN:     | FileCheck %s
+
+CHECK: [000000]  UH..H....E.
+CHECK: [00000f]  .E.x.E..
+CHECK: [00001a]  ..}..
+CHECK: [000023]  .}..
+CHECK: [00002b]  1.H...].


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48271.152372.patch
Type: text/x-patch
Size: 1573 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180621/f0370599/attachment-0001.bin>


More information about the llvm-commits mailing list