blob: 99023893ba050e746dbb017165b06795f0d07d7f [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Carl Shapiro12eb78e2011-06-24 14:51:06 -070016
Sebastien Hertz807a2562013-04-15 09:33:39 +020017#include "dex_instruction-inl.h"
Carl Shapiro12eb78e2011-06-24 14:51:06 -070018
Ian Rogersb574c182014-01-23 19:51:19 -080019#include <inttypes.h>
20
21#include <iomanip>
Ian Rogersc7dd2952014-10-21 23:31:19 -070022#include <sstream>
Ian Rogersb574c182014-01-23 19:51:19 -080023
Ian Rogers576ca0c2014-06-06 15:58:22 -070024#include "base/stringprintf.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070025#include "dex_file-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080026#include "utils.h"
Ian Rogersd81871c2011-10-03 13:57:23 -070027
Carl Shapiro12eb78e2011-06-24 14:51:06 -070028namespace art {
29
Carl Shapiroe4c1ce42011-07-09 02:31:57 -070030const char* const Instruction::kInstructionNames[] = {
Narayan Kamathbd48b342016-08-01 17:32:37 +010031#define INSTRUCTION_NAME(o, c, pname, f, i, a, v) pname,
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070032#include "dex_instruction_list.h"
Carl Shapiroe4c1ce42011-07-09 02:31:57 -070033 DEX_INSTRUCTION_LIST(INSTRUCTION_NAME)
34#undef DEX_INSTRUCTION_LIST
35#undef INSTRUCTION_NAME
36};
37
Elliott Hughesadb8c672012-03-06 16:49:32 -080038Instruction::Format const Instruction::kInstructionFormats[] = {
Narayan Kamathbd48b342016-08-01 17:32:37 +010039#define INSTRUCTION_FORMAT(o, c, p, format, i, a, v) format,
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070040#include "dex_instruction_list.h"
Carl Shapiroe4c1ce42011-07-09 02:31:57 -070041 DEX_INSTRUCTION_LIST(INSTRUCTION_FORMAT)
42#undef DEX_INSTRUCTION_LIST
43#undef INSTRUCTION_FORMAT
44};
45
Aart Bikb1f37532015-06-29 11:03:55 -070046Instruction::IndexType const Instruction::kInstructionIndexTypes[] = {
Narayan Kamathbd48b342016-08-01 17:32:37 +010047#define INSTRUCTION_INDEX_TYPE(o, c, p, f, index, a, v) index,
Aart Bikb1f37532015-06-29 11:03:55 -070048#include "dex_instruction_list.h"
49 DEX_INSTRUCTION_LIST(INSTRUCTION_INDEX_TYPE)
50#undef DEX_INSTRUCTION_LIST
51#undef INSTRUCTION_FLAGS
52};
53
Carl Shapiroe4c1ce42011-07-09 02:31:57 -070054int const Instruction::kInstructionFlags[] = {
Narayan Kamathbd48b342016-08-01 17:32:37 +010055#define INSTRUCTION_FLAGS(o, c, p, f, i, flags, v) flags,
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070056#include "dex_instruction_list.h"
Carl Shapiroe4c1ce42011-07-09 02:31:57 -070057 DEX_INSTRUCTION_LIST(INSTRUCTION_FLAGS)
58#undef DEX_INSTRUCTION_LIST
59#undef INSTRUCTION_FLAGS
60};
61
jeffhaoba5ebb92011-08-25 17:24:37 -070062int const Instruction::kInstructionVerifyFlags[] = {
Narayan Kamathbd48b342016-08-01 17:32:37 +010063#define INSTRUCTION_VERIFY_FLAGS(o, c, p, f, i, a, vflags) vflags,
jeffhaoba5ebb92011-08-25 17:24:37 -070064#include "dex_instruction_list.h"
65 DEX_INSTRUCTION_LIST(INSTRUCTION_VERIFY_FLAGS)
66#undef DEX_INSTRUCTION_LIST
67#undef INSTRUCTION_VERIFY_FLAGS
68};
69
Ian Rogersa75a0132012-09-28 11:41:42 -070070int const Instruction::kInstructionSizeInCodeUnits[] = {
Narayan Kamathbd48b342016-08-01 17:32:37 +010071#define INSTRUCTION_SIZE(opcode, c, p, format, i, a, v) \
Narayan Kamath8ec3bd22016-08-03 12:46:23 +010072 (((opcode) == NOP) ? -1 : \
73 (((format) >= k10x) && ((format) <= k10t)) ? 1 : \
74 (((format) >= k20t) && ((format) <= k22c)) ? 2 : \
75 (((format) >= k32x) && ((format) <= k3rc)) ? 3 : \
76 (((format) >= k45cc) && ((format) <= k4rcc)) ? 4 : \
77 ((format) == k51l) ? 5 : -1),
Ian Rogersa75a0132012-09-28 11:41:42 -070078#include "dex_instruction_list.h"
79 DEX_INSTRUCTION_LIST(INSTRUCTION_SIZE)
80#undef DEX_INSTRUCTION_LIST
81#undef INSTRUCTION_SIZE
82};
83
Dragos Sbirlea39f99272013-06-25 13:17:36 -070084int32_t Instruction::GetTargetOffset() const {
85 switch (FormatOf(Opcode())) {
86 // Cases for conditional branches follow.
87 case k22t: return VRegC_22t();
88 case k21t: return VRegB_21t();
89 // Cases for unconditional branches follow.
90 case k10t: return VRegA_10t();
91 case k20t: return VRegA_20t();
92 case k30t: return VRegA_30t();
93 default: LOG(FATAL) << "Tried to access the branch offset of an instruction " << Name() <<
94 " which does not have a target operand.";
95 }
96 return 0;
97}
98
99bool Instruction::CanFlowThrough() const {
100 const uint16_t* insns = reinterpret_cast<const uint16_t*>(this);
101 uint16_t insn = *insns;
102 Code opcode = static_cast<Code>(insn & 0xFF);
103 return FlagsOf(opcode) & Instruction::kContinue;
104}
105
Ian Rogersa75a0132012-09-28 11:41:42 -0700106size_t Instruction::SizeInCodeUnitsComplexOpcode() const {
Carl Shapiro12eb78e2011-06-24 14:51:06 -0700107 const uint16_t* insns = reinterpret_cast<const uint16_t*>(this);
Ian Rogersa75a0132012-09-28 11:41:42 -0700108 // Handle special NOP encoded variable length sequences.
109 switch (*insns) {
110 case kPackedSwitchSignature:
111 return (4 + insns[1] * 2);
112 case kSparseSwitchSignature:
113 return (2 + insns[1] * 4);
114 case kArrayDataSignature: {
115 uint16_t element_size = insns[1];
116 uint32_t length = insns[2] | (((uint32_t)insns[3]) << 16);
117 // The plus 1 is to round up for odd size and width.
118 return (4 + (element_size * length + 1) / 2);
Carl Shapiroe4c1ce42011-07-09 02:31:57 -0700119 }
Ian Rogersa75a0132012-09-28 11:41:42 -0700120 default:
121 if ((*insns & 0xFF) == 0) {
122 return 1; // NOP.
123 } else {
Ian Rogersfc787ec2014-10-09 21:56:44 -0700124 LOG(FATAL) << "Unreachable: " << DumpString(nullptr);
Ian Rogers2c4257b2014-10-24 14:20:06 -0700125 UNREACHABLE();
Ian Rogersa75a0132012-09-28 11:41:42 -0700126 }
Carl Shapiroe4c1ce42011-07-09 02:31:57 -0700127 }
Ian Rogersd81871c2011-10-03 13:57:23 -0700128}
129
Ian Rogers2c8a8572011-10-24 17:11:36 -0700130std::string Instruction::DumpHex(size_t code_units) const {
Ian Rogersd81871c2011-10-03 13:57:23 -0700131 size_t inst_length = SizeInCodeUnits();
132 if (inst_length > code_units) {
133 inst_length = code_units;
134 }
Ian Rogers2c8a8572011-10-24 17:11:36 -0700135 std::ostringstream os;
Ian Rogersd81871c2011-10-03 13:57:23 -0700136 const uint16_t* insn = reinterpret_cast<const uint16_t*>(this);
137 for (size_t i = 0; i < inst_length; i++) {
Ian Rogers2c8a8572011-10-24 17:11:36 -0700138 os << StringPrintf("0x%04x", insn[i]) << " ";
Ian Rogersd81871c2011-10-03 13:57:23 -0700139 }
140 for (size_t i = inst_length; i < code_units; i++) {
141 os << " ";
142 }
Ian Rogers2c8a8572011-10-24 17:11:36 -0700143 return os.str();
Ian Rogersd81871c2011-10-03 13:57:23 -0700144}
145
Anestis Bechtsoudis32f500d2015-02-22 22:32:57 -0800146std::string Instruction::DumpHexLE(size_t instr_code_units) const {
147 size_t inst_length = SizeInCodeUnits();
148 if (inst_length > instr_code_units) {
149 inst_length = instr_code_units;
150 }
151 std::ostringstream os;
152 const uint16_t* insn = reinterpret_cast<const uint16_t*>(this);
153 for (size_t i = 0; i < inst_length; i++) {
Andreas Gampe4f0be4d2015-02-27 22:16:14 -0800154 os << StringPrintf("%02x%02x", static_cast<uint8_t>(insn[i] & 0x00FF),
155 static_cast<uint8_t>((insn[i] & 0xFF00) >> 8)) << " ";
Anestis Bechtsoudis32f500d2015-02-22 22:32:57 -0800156 }
157 for (size_t i = inst_length; i < instr_code_units; i++) {
Andreas Gampe4f0be4d2015-02-27 22:16:14 -0800158 os << " ";
Anestis Bechtsoudis32f500d2015-02-22 22:32:57 -0800159 }
160 return os.str();
161}
162
Ian Rogers2c8a8572011-10-24 17:11:36 -0700163std::string Instruction::DumpString(const DexFile* file) const {
Ian Rogers2c8a8572011-10-24 17:11:36 -0700164 std::ostringstream os;
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200165 const char* opcode = kInstructionNames[Opcode()];
Elliott Hughesadb8c672012-03-06 16:49:32 -0800166 switch (FormatOf(Opcode())) {
Elliott Hughese3c845c2012-02-28 17:23:01 -0800167 case k10x: os << opcode; break;
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200168 case k12x: os << StringPrintf("%s v%d, v%d", opcode, VRegA_12x(), VRegB_12x()); break;
169 case k11n: os << StringPrintf("%s v%d, #%+d", opcode, VRegA_11n(), VRegB_11n()); break;
170 case k11x: os << StringPrintf("%s v%d", opcode, VRegA_11x()); break;
171 case k10t: os << StringPrintf("%s %+d", opcode, VRegA_10t()); break;
172 case k20t: os << StringPrintf("%s %+d", opcode, VRegA_20t()); break;
173 case k22x: os << StringPrintf("%s v%d, v%d", opcode, VRegA_22x(), VRegB_22x()); break;
174 case k21t: os << StringPrintf("%s v%d, %+d", opcode, VRegA_21t(), VRegB_21t()); break;
175 case k21s: os << StringPrintf("%s v%d, #%+d", opcode, VRegA_21s(), VRegB_21s()); break;
Elliott Hughes1b3d6ca2012-04-25 13:00:14 -0700176 case k21h: {
177 // op vAA, #+BBBB0000[00000000]
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200178 if (Opcode() == CONST_HIGH16) {
179 uint32_t value = VRegB_21h() << 16;
180 os << StringPrintf("%s v%d, #int %+d // 0x%x", opcode, VRegA_21h(), value, value);
Elliott Hughes1b3d6ca2012-04-25 13:00:14 -0700181 } else {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200182 uint64_t value = static_cast<uint64_t>(VRegB_21h()) << 48;
Ian Rogersb574c182014-01-23 19:51:19 -0800183 os << StringPrintf("%s v%d, #long %+" PRId64 " // 0x%" PRIx64, opcode, VRegA_21h(),
184 value, value);
Elliott Hughes1b3d6ca2012-04-25 13:00:14 -0700185 }
186 }
187 break;
Ian Rogers90334e52012-06-06 20:22:20 -0700188 case k21c: {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200189 switch (Opcode()) {
Ian Rogers90334e52012-06-06 20:22:20 -0700190 case CONST_STRING:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700191 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200192 uint32_t string_idx = VRegB_21c();
Serdjuk, Nikolay Y67c5ddd2015-12-07 14:45:44 +0600193 if (string_idx < file->NumStringIds()) {
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800194 os << StringPrintf(
195 "const-string v%d, %s // string@%d",
196 VRegA_21c(),
197 PrintableString(file->StringDataByIdx(dex::StringIndex(string_idx))).c_str(),
198 string_idx);
Serdjuk, Nikolay Y67c5ddd2015-12-07 14:45:44 +0600199 } else {
200 os << StringPrintf("const-string v%d, <<invalid-string-idx-%d>> // string@%d",
201 VRegA_21c(),
202 string_idx,
203 string_idx);
204 }
Ian Rogers90334e52012-06-06 20:22:20 -0700205 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700206 }
207 FALLTHROUGH_INTENDED;
Mathieu Chartier18c24b62012-09-10 08:54:25 -0700208 case CHECK_CAST:
209 case CONST_CLASS:
Ian Rogers90334e52012-06-06 20:22:20 -0700210 case NEW_INSTANCE:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700211 if (file != nullptr) {
Andreas Gampea5b09a62016-11-17 15:21:22 -0800212 dex::TypeIndex type_idx(VRegB_21c());
213 os << opcode << " v" << static_cast<int>(VRegA_21c()) << ", "
214 << file->PrettyType(type_idx) << " // type@" << type_idx;
Ian Rogers90334e52012-06-06 20:22:20 -0700215 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700216 }
217 FALLTHROUGH_INTENDED;
Ian Rogers90334e52012-06-06 20:22:20 -0700218 case SGET:
219 case SGET_WIDE:
220 case SGET_OBJECT:
221 case SGET_BOOLEAN:
222 case SGET_BYTE:
223 case SGET_CHAR:
224 case SGET_SHORT:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700225 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200226 uint32_t field_idx = VRegB_21c();
David Sehr709b0702016-10-13 09:12:37 -0700227 os << opcode << " v" << static_cast<int>(VRegA_21c()) << ", " << file->PrettyField(field_idx, true)
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200228 << " // field@" << field_idx;
Ian Rogers90334e52012-06-06 20:22:20 -0700229 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700230 }
231 FALLTHROUGH_INTENDED;
Ian Rogers90334e52012-06-06 20:22:20 -0700232 case SPUT:
233 case SPUT_WIDE:
234 case SPUT_OBJECT:
235 case SPUT_BOOLEAN:
236 case SPUT_BYTE:
237 case SPUT_CHAR:
238 case SPUT_SHORT:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700239 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200240 uint32_t field_idx = VRegB_21c();
David Sehr709b0702016-10-13 09:12:37 -0700241 os << opcode << " v" << static_cast<int>(VRegA_21c()) << ", " << file->PrettyField(field_idx, true)
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200242 << " // field@" << field_idx;
Ian Rogers90334e52012-06-06 20:22:20 -0700243 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700244 }
245 FALLTHROUGH_INTENDED;
Ian Rogers90334e52012-06-06 20:22:20 -0700246 default:
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200247 os << StringPrintf("%s v%d, thing@%d", opcode, VRegA_21c(), VRegB_21c());
Ian Rogers90334e52012-06-06 20:22:20 -0700248 break;
249 }
250 break;
251 }
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200252 case k23x: os << StringPrintf("%s v%d, v%d, v%d", opcode, VRegA_23x(), VRegB_23x(), VRegC_23x()); break;
253 case k22b: os << StringPrintf("%s v%d, v%d, #%+d", opcode, VRegA_22b(), VRegB_22b(), VRegC_22b()); break;
254 case k22t: os << StringPrintf("%s v%d, v%d, %+d", opcode, VRegA_22t(), VRegB_22t(), VRegC_22t()); break;
255 case k22s: os << StringPrintf("%s v%d, v%d, #%+d", opcode, VRegA_22s(), VRegB_22s(), VRegC_22s()); break;
Ian Rogers90334e52012-06-06 20:22:20 -0700256 case k22c: {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200257 switch (Opcode()) {
Ian Rogers90334e52012-06-06 20:22:20 -0700258 case IGET:
259 case IGET_WIDE:
260 case IGET_OBJECT:
261 case IGET_BOOLEAN:
262 case IGET_BYTE:
263 case IGET_CHAR:
264 case IGET_SHORT:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700265 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200266 uint32_t field_idx = VRegC_22c();
Dragos Sbirleab43cef32013-05-23 11:59:20 -0700267 os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", "
David Sehr709b0702016-10-13 09:12:37 -0700268 << file->PrettyField(field_idx, true) << " // field@" << field_idx;
Ian Rogers90334e52012-06-06 20:22:20 -0700269 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700270 }
271 FALLTHROUGH_INTENDED;
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200272 case IGET_QUICK:
273 case IGET_OBJECT_QUICK:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700274 if (file != nullptr) {
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200275 uint32_t field_idx = VRegC_22c();
276 os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", "
277 << "// offset@" << field_idx;
278 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700279 }
280 FALLTHROUGH_INTENDED;
Ian Rogers90334e52012-06-06 20:22:20 -0700281 case IPUT:
282 case IPUT_WIDE:
283 case IPUT_OBJECT:
284 case IPUT_BOOLEAN:
285 case IPUT_BYTE:
286 case IPUT_CHAR:
287 case IPUT_SHORT:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700288 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200289 uint32_t field_idx = VRegC_22c();
Dragos Sbirleab43cef32013-05-23 11:59:20 -0700290 os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", "
David Sehr709b0702016-10-13 09:12:37 -0700291 << file->PrettyField(field_idx, true) << " // field@" << field_idx;
Ian Rogers90334e52012-06-06 20:22:20 -0700292 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700293 }
294 FALLTHROUGH_INTENDED;
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200295 case IPUT_QUICK:
296 case IPUT_OBJECT_QUICK:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700297 if (file != nullptr) {
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200298 uint32_t field_idx = VRegC_22c();
299 os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", "
300 << "// offset@" << field_idx;
301 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700302 }
303 FALLTHROUGH_INTENDED;
Ian Rogers90334e52012-06-06 20:22:20 -0700304 case INSTANCE_OF:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700305 if (file != nullptr) {
Andreas Gampea5b09a62016-11-17 15:21:22 -0800306 dex::TypeIndex type_idx(VRegC_22c());
307 os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v"
308 << static_cast<int>(VRegB_22c()) << ", " << file->PrettyType(type_idx)
309 << " // type@" << type_idx.index_;
Mathieu Chartier18c24b62012-09-10 08:54:25 -0700310 break;
311 }
Ian Rogersfc787ec2014-10-09 21:56:44 -0700312 FALLTHROUGH_INTENDED;
Mathieu Chartier18c24b62012-09-10 08:54:25 -0700313 case NEW_ARRAY:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700314 if (file != nullptr) {
Andreas Gampea5b09a62016-11-17 15:21:22 -0800315 dex::TypeIndex type_idx(VRegC_22c());
316 os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v"
317 << static_cast<int>(VRegB_22c()) << ", " << file->PrettyType(type_idx)
318 << " // type@" << type_idx.index_;
Ian Rogers90334e52012-06-06 20:22:20 -0700319 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700320 }
321 FALLTHROUGH_INTENDED;
Ian Rogers90334e52012-06-06 20:22:20 -0700322 default:
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200323 os << StringPrintf("%s v%d, v%d, thing@%d", opcode, VRegA_22c(), VRegB_22c(), VRegC_22c());
Ian Rogers90334e52012-06-06 20:22:20 -0700324 break;
325 }
326 break;
327 }
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200328 case k32x: os << StringPrintf("%s v%d, v%d", opcode, VRegA_32x(), VRegB_32x()); break;
329 case k30t: os << StringPrintf("%s %+d", opcode, VRegA_30t()); break;
330 case k31t: os << StringPrintf("%s v%d, %+d", opcode, VRegA_31t(), VRegB_31t()); break;
331 case k31i: os << StringPrintf("%s v%d, #%+d", opcode, VRegA_31i(), VRegB_31i()); break;
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700332 case k31c:
333 if (Opcode() == CONST_STRING_JUMBO) {
334 uint32_t string_idx = VRegB_31c();
Ian Rogersfc787ec2014-10-09 21:56:44 -0700335 if (file != nullptr) {
Serdjuk, Nikolay Y67c5ddd2015-12-07 14:45:44 +0600336 if (string_idx < file->NumStringIds()) {
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800337 os << StringPrintf(
338 "%s v%d, %s // string@%d",
339 opcode,
340 VRegA_31c(),
341 PrintableString(file->StringDataByIdx(dex::StringIndex(string_idx))).c_str(),
342 string_idx);
Serdjuk, Nikolay Y67c5ddd2015-12-07 14:45:44 +0600343 } else {
344 os << StringPrintf("%s v%d, <<invalid-string-idx-%d>> // string@%d",
345 opcode,
346 VRegA_31c(),
347 string_idx,
348 string_idx);
349 }
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700350 } else {
351 os << StringPrintf("%s v%d, string@%d", opcode, VRegA_31c(), string_idx);
352 }
353 } else {
354 os << StringPrintf("%s v%d, thing@%d", opcode, VRegA_31c(), VRegB_31c()); break;
355 }
356 break;
Ian Rogersd81871c2011-10-03 13:57:23 -0700357 case k35c: {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200358 uint32_t arg[5];
Ian Rogers29a26482014-05-02 15:27:29 -0700359 GetVarArgs(arg);
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200360 switch (Opcode()) {
Andreas Gampe7aca91d2014-03-31 18:10:53 -0700361 case FILLED_NEW_ARRAY:
362 {
363 const int32_t a = VRegA_35c();
364 os << opcode << " {";
365 for (int i = 0; i < a; ++i) {
366 if (i > 0) {
367 os << ", ";
368 }
369 os << "v" << arg[i];
370 }
371 os << "}, type@" << VRegB_35c();
372 }
373 break;
374
Ian Rogersd81871c2011-10-03 13:57:23 -0700375 case INVOKE_VIRTUAL:
376 case INVOKE_SUPER:
377 case INVOKE_DIRECT:
378 case INVOKE_STATIC:
379 case INVOKE_INTERFACE:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700380 if (file != nullptr) {
Elliott Hughese3c845c2012-02-28 17:23:01 -0800381 os << opcode << " {";
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200382 uint32_t method_idx = VRegB_35c();
383 for (size_t i = 0; i < VRegA_35c(); ++i) {
Elliott Hughese3c845c2012-02-28 17:23:01 -0800384 if (i != 0) {
385 os << ", ";
386 }
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200387 os << "v" << arg[i];
Elliott Hughese3c845c2012-02-28 17:23:01 -0800388 }
David Sehr709b0702016-10-13 09:12:37 -0700389 os << "}, " << file->PrettyMethod(method_idx) << " // method@" << method_idx;
Ian Rogersd81871c2011-10-03 13:57:23 -0700390 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700391 }
392 FALLTHROUGH_INTENDED;
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200393 case INVOKE_VIRTUAL_QUICK:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700394 if (file != nullptr) {
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200395 os << opcode << " {";
396 uint32_t method_idx = VRegB_35c();
397 for (size_t i = 0; i < VRegA_35c(); ++i) {
398 if (i != 0) {
399 os << ", ";
400 }
401 os << "v" << arg[i];
402 }
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700403 os << "}, // vtable@" << method_idx;
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200404 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700405 }
406 FALLTHROUGH_INTENDED;
Ian Rogersd81871c2011-10-03 13:57:23 -0700407 default:
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200408 os << opcode << " {v" << arg[0] << ", v" << arg[1] << ", v" << arg[2]
409 << ", v" << arg[3] << ", v" << arg[4] << "}, thing@" << VRegB_35c();
Ian Rogersd81871c2011-10-03 13:57:23 -0700410 break;
411 }
412 break;
413 }
Ian Rogers4c5dd5a2012-09-07 11:27:28 -0700414 case k3rc: {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200415 switch (Opcode()) {
Ian Rogers4c5dd5a2012-09-07 11:27:28 -0700416 case INVOKE_VIRTUAL_RANGE:
417 case INVOKE_SUPER_RANGE:
418 case INVOKE_DIRECT_RANGE:
419 case INVOKE_STATIC_RANGE:
420 case INVOKE_INTERFACE_RANGE:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700421 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200422 uint32_t method_idx = VRegB_3rc();
423 os << StringPrintf("%s, {v%d .. v%d}, ", opcode, VRegC_3rc(), (VRegC_3rc() + VRegA_3rc() - 1))
David Sehr709b0702016-10-13 09:12:37 -0700424 << file->PrettyMethod(method_idx) << " // method@" << method_idx;
Ian Rogers4c5dd5a2012-09-07 11:27:28 -0700425 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700426 }
427 FALLTHROUGH_INTENDED;
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200428 case INVOKE_VIRTUAL_RANGE_QUICK:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700429 if (file != nullptr) {
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200430 uint32_t method_idx = VRegB_3rc();
431 os << StringPrintf("%s, {v%d .. v%d}, ", opcode, VRegC_3rc(), (VRegC_3rc() + VRegA_3rc() - 1))
432 << "// vtable@" << method_idx;
433 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700434 }
435 FALLTHROUGH_INTENDED;
Ian Rogers4c5dd5a2012-09-07 11:27:28 -0700436 default:
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200437 os << StringPrintf("%s, {v%d .. v%d}, thing@%d", opcode, VRegC_3rc(),
438 (VRegC_3rc() + VRegA_3rc() - 1), VRegB_3rc());
Ian Rogers4c5dd5a2012-09-07 11:27:28 -0700439 break;
440 }
441 break;
442 }
Ian Rogersb574c182014-01-23 19:51:19 -0800443 case k51l: os << StringPrintf("%s v%d, #%+" PRId64, opcode, VRegA_51l(), VRegB_51l()); break;
Ian Rogers2c8a8572011-10-24 17:11:36 -0700444 default: os << " unknown format (" << DumpHex(5) << ")"; break;
Ian Rogersd81871c2011-10-03 13:57:23 -0700445 }
Ian Rogers2c8a8572011-10-24 17:11:36 -0700446 return os.str();
Carl Shapiro12eb78e2011-06-24 14:51:06 -0700447}
448
Ian Rogersa75a0132012-09-28 11:41:42 -0700449std::ostream& operator<<(std::ostream& os, const Instruction::Code& code) {
450 return os << Instruction::Name(code);
Elliott Hughesadb8c672012-03-06 16:49:32 -0800451}
452
Carl Shapiro12eb78e2011-06-24 14:51:06 -0700453} // namespace art