[llvm] r237276 - [llvm-bcanalyzer] Add -show-binary-blobs option.
Jordan Rose
jordan_rose at apple.com
Wed May 13 11:51:49 PDT 2015
Author: jrose
Date: Wed May 13 13:51:49 2015
New Revision: 237276
URL: http://llvm.org/viewvc/llvm-project?rev=237276&view=rev
Log:
[llvm-bcanalyzer] Add -show-binary-blobs option.
-dump mode normally omits blob data that contains unprintable characters.
When -show-binary-blobs is passed, it unilaterally escapes all blobs,
allowing those with binary data to be displayed.
Modified:
llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
Modified: llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp?rev=237276&r1=237275&r2=237276&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp (original)
+++ llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp Wed May 13 13:51:49 2015
@@ -66,6 +66,10 @@ static cl::opt<std::string>
BlockInfoFilename("block-info",
cl::desc("Use the BLOCK_INFO from the given file"));
+static cl::opt<bool>
+ ShowBinaryBlobs("show-binary-blobs",
+ cl::desc("Print binary blobs using hex escapes"));
+
namespace {
/// CurStreamTypeType - A type for CurStreamType
@@ -460,17 +464,22 @@ static bool ParseBlock(BitstreamCursor &
if (Blob.data()) {
outs() << " blob data = ";
- bool BlobIsPrintable = true;
- for (unsigned i = 0, e = Blob.size(); i != e; ++i)
- if (!isprint(static_cast<unsigned char>(Blob[i]))) {
- BlobIsPrintable = false;
- break;
- }
-
- if (BlobIsPrintable)
- outs() << "'" << Blob << "'";
- else
- outs() << "unprintable, " << Blob.size() << " bytes.";
+ if (ShowBinaryBlobs) {
+ outs() << "'";
+ outs().write_escaped(Blob, /*hex=*/true) << "'";
+ } else {
+ bool BlobIsPrintable = true;
+ for (unsigned i = 0, e = Blob.size(); i != e; ++i)
+ if (!isprint(static_cast<unsigned char>(Blob[i]))) {
+ BlobIsPrintable = false;
+ break;
+ }
+
+ if (BlobIsPrintable)
+ outs() << "'" << Blob << "'";
+ else
+ outs() << "unprintable, " << Blob.size() << " bytes.";
+ }
}
outs() << "\n";
More information about the llvm-commits
mailing list