Add -n dexdump flag to disable printing debug information.

Bug: 215672548
Test: n/a
Change-Id: I6ff4c775f82d97aa2e649411b44805c830072113
diff --git a/dexdump/dexdump.cc b/dexdump/dexdump.cc
index 2345437..409ae55 100644
--- a/dexdump/dexdump.cc
+++ b/dexdump/dexdump.cc
@@ -1217,7 +1217,6 @@
 static void dumpCode(const DexFile* pDexFile, u4 idx, u4 flags,
                      const dex::CodeItem* pCode, u4 codeOffset) {
   CodeItemDebugInfoAccessor accessor(*pDexFile, pCode, idx);
-  const u4 lastInstructionAddress = findLastInstructionAddress(accessor);
 
   fprintf(gOutFile, "      registers     : %d\n", accessor.RegistersSize());
   fprintf(gOutFile, "      ins           : %d\n", accessor.InsSize());
@@ -1233,31 +1232,34 @@
   // Try-catch blocks.
   dumpCatches(pDexFile, pCode);
 
-  // Positions and locals table in the debug info.
-  bool is_static = (flags & kAccStatic) != 0;
-  fprintf(gOutFile, "      positions     : \n");
-  accessor.DecodeDebugPositionInfo([&](const DexFile::PositionInfo& entry) {
-    if (entry.address_ > lastInstructionAddress) {
-      return true;
-    } else {
-      fprintf(gOutFile, "        0x%04x line=%d\n", entry.address_, entry.line_);
-      return false;
-    }
-  });
-  fprintf(gOutFile, "      locals        : \n");
-  accessor.DecodeDebugLocalInfo(is_static,
-                                idx,
-                                [&](const DexFile::LocalInfo& entry) {
-    const char* signature = entry.signature_ != nullptr ? entry.signature_ : "";
-    fprintf(gOutFile,
-            "        0x%04x - 0x%04x reg=%d %s %s %s\n",
-            entry.start_address_,
-            entry.end_address_,
-            entry.reg_,
-            entry.name_,
-            entry.descriptor_,
-            signature);
-  });
+  if (gOptions.showDebugInfo) {
+    const u4 lastInstructionAddress = findLastInstructionAddress(accessor);
+    // Positions and locals table in the debug info.
+    bool is_static = (flags & kAccStatic) != 0;
+    fprintf(gOutFile, "      positions     : \n");
+    accessor.DecodeDebugPositionInfo([&](const DexFile::PositionInfo& entry) {
+      if (entry.address_ > lastInstructionAddress) {
+        return true;
+      } else {
+        fprintf(gOutFile, "        0x%04x line=%d\n", entry.address_, entry.line_);
+        return false;
+      }
+    });
+    fprintf(gOutFile, "      locals        : \n");
+    accessor.DecodeDebugLocalInfo(is_static,
+                                  idx,
+                                  [&](const DexFile::LocalInfo& entry) {
+      const char* signature = entry.signature_ != nullptr ? entry.signature_ : "";
+      fprintf(gOutFile,
+              "        0x%04x - 0x%04x reg=%d %s %s %s\n",
+              entry.start_address_,
+              entry.end_address_,
+              entry.reg_,
+              entry.name_,
+              entry.descriptor_,
+              signature);
+    });
+  }
 }
 
 static std::string GetHiddenapiFlagStr(uint32_t hiddenapi_flags) {
diff --git a/dexdump/dexdump.h b/dexdump/dexdump.h
index 930d0ce..7226ca0 100644
--- a/dexdump/dexdump.h
+++ b/dexdump/dexdump.h
@@ -47,6 +47,7 @@
   bool showCfg;
   bool showFileHeaders;
   bool showSectionHeaders;
+  bool showDebugInfo;
   bool verbose;
   OutputFormat outputFormat;
   const char* outputFileName;
diff --git a/dexdump/dexdump_main.cc b/dexdump/dexdump_main.cc
index 8b2b71c..3afee0d 100644
--- a/dexdump/dexdump_main.cc
+++ b/dexdump/dexdump_main.cc
@@ -39,8 +39,8 @@
  */
 static void usage() {
   LOG(ERROR) << "Copyright (C) 2007 The Android Open Source Project\n";
-  LOG(ERROR) << gProgName << ": [-a] [-c] [-d] [-e] [-f] [-h] [-i] [-j] [-l layout] [-o outfile]"
-                  " dexfile...\n";
+  LOG(ERROR) << gProgName << ": [-a] [-c] [-d] [-e] [-f] [-h] [-i] [-j] [-l layout] [-n]"
+                  "  [-o outfile] dexfile...\n";
   LOG(ERROR) << " -a : display annotations";
   LOG(ERROR) << " -c : verify checksum and exit";
   LOG(ERROR) << " -d : disassemble code sections";
@@ -51,6 +51,7 @@
   LOG(ERROR) << " -i : ignore checksum failures";
   LOG(ERROR) << " -j : disable dex file verification";
   LOG(ERROR) << " -l : output layout, either 'plain' or 'xml'";
+  LOG(ERROR) << " -n : don't display debug information";
   LOG(ERROR) << " -o : output file name (defaults to stdout)";
 }
 
@@ -62,10 +63,11 @@
   bool wantUsage = false;
   memset(&gOptions, 0, sizeof(gOptions));
   gOptions.verbose = true;
+  gOptions.showDebugInfo = true;
 
   // Parse all arguments.
   while (true) {
-    const int ic = getopt(argc, argv, "acdefghijl:o:");
+    const int ic = getopt(argc, argv, "acdefghijl:no:");
     if (ic < 0) {
       break;  // done
     }
@@ -107,6 +109,9 @@
           wantUsage = true;
         }
         break;
+      case 'n':  // don't display debug information
+        gOptions.showDebugInfo = false;
+        break;
       case 'o':  // output file
         gOptions.outputFileName = optarg;
         break;