[PATCH] D48271: [llvm-readobj] Fix printing format
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 18 08:31:28 PDT 2018
Could you add a test case?
On Mon, Jun 18, 2018 at 3:36 AM Paul Semel via Phabricator <
reviews at reviews.llvm.org> wrote:
> paulsemel created this revision.
> paulsemel added reviewers: echristo, dblaikie.
>
> 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
> (this matches GNU readelf behavior)
>
>
> Repository:
> rL LLVM
>
> https://reviews.llvm.org/D48271
>
> Files:
> 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;
> }
> }
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180618/0bfef89b/attachment.html>
More information about the llvm-commits
mailing list