1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-02-01 05:01:59 +01:00

[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

llvm-svn: 336058
This commit is contained in:
Paul Semel 2018-07-01 09:51:59 +00:00
parent 50dc237abc
commit 406504e4b7
2 changed files with 19 additions and 4 deletions

View File

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

View File

@ -3275,6 +3275,11 @@ void GNUStyle<ELFT>::printProgramHeaders(const ELFO *Obj) {
} }
} }
void printAsPrintable(raw_ostream &W, StringRef S) {
for (char C : S)
W << (isprint(C) ? C : '.');
}
template <class ELFT> template <class ELFT>
void GNUStyle<ELFT>::printSectionAsString(const ELFO *Obj, void GNUStyle<ELFT>::printSectionAsString(const ELFO *Obj,
StringRef SectionName) { StringRef SectionName) {
@ -3298,8 +3303,9 @@ void GNUStyle<ELFT>::printSectionAsString(const ELFO *Obj,
CurrentWord++; CurrentWord++;
continue; continue;
} }
OS << format("[%6tx]", CurrentWord - SecContent); OS << format("[%6tx] ", CurrentWord - SecContent);
OS << format(" %.*s\n", WordSize, CurrentWord); printAsPrintable(OS, StringRef(CurrentWord, WordSize));
OS << '\n';
CurrentWord += WordSize + 1; CurrentWord += WordSize + 1;
} }
OS.flush(); OS.flush();
@ -4361,8 +4367,9 @@ void LLVMStyle<ELFT>::printSectionAsString(const ELFO *Obj,
W.startLine() << "[" W.startLine() << "["
<< to_string( << to_string(
format_hex_no_prefix((CurrentWord - SecContent), 6)) 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; CurrentWord += WordSize + 1;
} }
} }