[PATCH] D48271: [llvm-readobj] Fix printing format
Paul Semel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 19 09:30:32 PDT 2018
paulsemel updated this revision to Diff 151930.
paulsemel added a comment.
Added tests
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,19 @@
+RUN: llvm-readobj -p .strtab %p/Inputs/elf-groups.x86_64 \
+RUN: | FileCheck %s
+
+CHECK: [000001] _ZNKSt9type_info4nameEv
+CHECK: [000019] _ZNSt8ios_base4InitD1Ev
+CHECK: [000031] _ZNSt8ios_base4InitC1Ev
+CHECK: [000049] _ZSt4cout
+CHECK: [000053] __cxa_atexit
+CHECK: [000060] _ZStL8__ioinit
+CHECK: [00006f] __cxx_global_var_init
+CHECK: [000085] _GLOBAL__sub_I_elf_groups.cpp
+CHECK: [0000a3] elf-groups.cpp
+CHECK: [0000b2] main
+CHECK: [0000b7] _ZTIi
+CHECK: [0000bd] __dso_handle
+CHECK: [0000ca] _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
+CHECK: [000102] _ZTIc
+CHECK: [000108] _Z3fooIiEvT_
+CHECK: [000115] _Z3fooIcEvT_
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48271.151930.patch
Type: text/x-patch
Size: 2006 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180619/be144414/attachment.bin>
More information about the llvm-commits
mailing list