[llvm] r336058 - [llvm-readobj] Fix printing format
Paul Semel via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 1 02:51:59 PDT 2018
Author: paulsemel
Date: Sun Jul 1 02:51:59 2018
New Revision: 336058
URL: http://llvm.org/viewvc/llvm-project?rev=336058&view=rev
Log:
[llvm-readobj] Fix printing format
We were printing every character, even those that weren't printable. It
doesn't really make sense for this option.
The string content was sticked to its address, added two spaces in
between.
Differential Revision: https://reviews.llvm.org/D48271
Added:
llvm/trunk/test/tools/llvm-readobj/print-section.test
Modified:
llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
Added: llvm/trunk/test/tools/llvm-readobj/print-section.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/print-section.test?rev=336058&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/print-section.test (added)
+++ llvm/trunk/test/tools/llvm-readobj/print-section.test Sun Jul 1 02:51:59 2018
@@ -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...].
Modified: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ELFDumper.cpp?rev=336058&r1=336057&r2=336058&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp Sun Jul 1 02:51:59 2018
@@ -3275,6 +3275,11 @@ void GNUStyle<ELFT>::printProgramHeaders
}
}
+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) {
@@ -3298,8 +3303,9 @@ void GNUStyle<ELFT>::printSectionAsStrin
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();
@@ -4361,8 +4367,9 @@ void LLVMStyle<ELFT>::printSectionAsStri
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;
}
}
More information about the llvm-commits
mailing list