ART: Instruction dumper should handle out-of-bound index for const-string

If const-string refers to out-of-bound index then we should handle it
similarly to PrettyField, PrettyMethod and PrettyType.

Change-Id: Ib6b1e20169e4b47c1cdb7dda80320ed21d61cfe3
Signed-off-by: Serdjuk, Nikolay Y <nikolay.y.serdjuk@intel.com>
diff --git a/runtime/dex_instruction.cc b/runtime/dex_instruction.cc
index 438b6b8..3f62124 100644
--- a/runtime/dex_instruction.cc
+++ b/runtime/dex_instruction.cc
@@ -189,8 +189,17 @@
         case CONST_STRING:
           if (file != nullptr) {
             uint32_t string_idx = VRegB_21c();
-            os << StringPrintf("const-string v%d, %s // string@%d", VRegA_21c(),
-                               PrintableString(file->StringDataByIdx(string_idx)).c_str(), string_idx);
+            if (string_idx < file->NumStringIds()) {
+              os << StringPrintf("const-string v%d, %s // string@%d",
+                                 VRegA_21c(),
+                                 PrintableString(file->StringDataByIdx(string_idx)).c_str(),
+                                 string_idx);
+            } else {
+              os << StringPrintf("const-string v%d, <<invalid-string-idx-%d>> // string@%d",
+                                 VRegA_21c(),
+                                 string_idx,
+                                 string_idx);
+            }
             break;
           }
           FALLTHROUGH_INTENDED;
@@ -348,9 +357,19 @@
       if (Opcode() == CONST_STRING_JUMBO) {
         uint32_t string_idx = VRegB_31c();
         if (file != nullptr) {
-          os << StringPrintf("%s v%d, %s // string@%d", opcode, VRegA_31c(),
-                             PrintableString(file->StringDataByIdx(string_idx)).c_str(),
-                             string_idx);
+          if (string_idx < file->NumStringIds()) {
+            os << StringPrintf("%s v%d, %s // string@%d",
+                               opcode,
+                               VRegA_31c(),
+                               PrintableString(file->StringDataByIdx(string_idx)).c_str(),
+                               string_idx);
+          } else {
+            os << StringPrintf("%s v%d, <<invalid-string-idx-%d>> // string@%d",
+                               opcode,
+                               VRegA_31c(),
+                               string_idx,
+                               string_idx);
+          }
         } else {
           os << StringPrintf("%s v%d, string@%d", opcode, VRegA_31c(), string_idx);
         }