[PATCH] D48271: [llvm-readobj] Fix printing format
Paul Semel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 29 10:15:33 PDT 2018
paulsemel updated this revision to Diff 153522.
paulsemel marked an inline comment as done.
paulsemel added a comment.
Refactor printing function.
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
@@ -3220,6 +3220,11 @@
}
}
+void printAsPrintable(raw_ostream &W, StringRef S) {
+ for (char C : S)
+ W << (isprint(C) ? C : '.');
+}
+
template <class ELFT>
void GNUStyle<ELFT>::printSectionAsString(const ELFO *Obj,
StringRef SectionName) {
@@ -3243,8 +3248,9 @@
CurrentWord++;
continue;
}
- OS << format("[%6tx]", CurrentWord - SecContent);
- OS << format(" %.*s\n", WordSize, CurrentWord);
+ OS << format("[%6tx] ", CurrentWord - SecContent);
+ printAsPrintable(OS, StringRef(CurrentWord, WordSize));
+ OS << '\n';
CurrentWord += WordSize + 1;
}
OS.flush();
@@ -4270,8 +4276,9 @@
W.startLine() << "["
<< to_string(
format_hex_no_prefix((CurrentWord - SecContent), 6))
- << "]";
- W.startLine() << format(" %.*s\n", WordSize, CurrentWord);
+ << "] ";
+ printAsPrintable(W.startLine(), StringRef(CurrentWord, WordSize));
+ 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.153522.patch
Type: text/x-patch
Size: 1676 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180629/16830cdd/attachment.bin>
More information about the llvm-commits
mailing list