[llvm-bcanalyzer] Add -show-binary-blobs option.
authorJordan Rose <jordan_rose@apple.com>
Wed, 13 May 2015 18:51:49 +0000 (18:51 +0000)
committerJordan Rose <jordan_rose@apple.com>
Wed, 13 May 2015 18:51:49 +0000 (18:51 +0000)
-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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237276 91177308-0d34-0410-b5e6-96231b3b80d8

tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp

index 8aa5697f6ad81d7ea95f58e90dd792956b6cb41c..58b02be7b92f0cb8e028f47f28a2b514ffbebc47 100644 (file)
@@ -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 &Stream, unsigned BlockID,
 
       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";