Handle run-away instruction in oatdump.
Log the same warning as dexdump.
Test: oatdump of oat file with run-away instruction
Bug: 186405713
Change-Id: Iffa3d4cdf21023cc57c3fcdc666526a5fd5e8e37
diff --git a/oatdump/oatdump.cc b/oatdump/oatdump.cc
index b7eecb7..df31ded 100644
--- a/oatdump/oatdump.cc
+++ b/oatdump/oatdump.cc
@@ -1127,7 +1127,12 @@
vios->Stream() << "DEX CODE:\n";
ScopedIndentation indent2(vios);
if (code_item_accessor.HasCodeItem()) {
+ uint32_t max_pc = code_item_accessor.InsnsSizeInCodeUnits();
for (const DexInstructionPcPair& inst : code_item_accessor) {
+ if (inst.DexPc() + inst->SizeInCodeUnits() > max_pc) {
+ LOG(WARNING) << "GLITCH: run-away instruction at idx=0x" << std::hex << inst.DexPc();
+ break;
+ }
vios->Stream() << StringPrintf("0x%04x: ", inst.DexPc()) << inst->DumpHexLE(5)
<< StringPrintf("\t| %s\n", inst->DumpString(&dex_file).c_str());
}