blob: c884eee88b278c11df2ac8e5a58f545c7bc5a34d [file] [log] [blame]
Ian Rogers4f6ad8a2013-03-18 15:27:28 -07001/*
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 */
16
David Sehr334b9d72018-02-12 18:27:56 -080017#ifndef ART_LIBDEXFILE_DEX_DEX_FILE_INL_H_
18#define ART_LIBDEXFILE_DEX_DEX_FILE_INL_H_
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070019
Andreas Gampe1e96e132018-06-25 19:36:55 -070020#include "dex_file.h"
21
David Sehraa6abb02017-10-12 08:25:11 -070022#include "base/casts.h"
David Sehr67bf42e2018-02-26 16:43:04 -080023#include "base/leb128.h"
Brian Carlstroma2806552014-02-27 12:29:32 -080024#include "base/stringpiece.h"
Mathieu Chartier3e2e1232018-09-11 12:35:30 -070025#include "base/utils.h"
Mathieu Chartier05dc23e2018-05-22 11:56:14 -070026#include "class_iterator.h"
David Sehr9e734c72018-01-04 17:56:19 -080027#include "compact_dex_file.h"
Andreas Gampe1e96e132018-06-25 19:36:55 -070028#include "dex_instruction_iterator.h"
Andreas Gampe04c6ab92017-06-08 21:49:14 -070029#include "invoke_type.h"
Mathieu Chartier69147f12017-11-06 20:02:24 -080030#include "standard_dex_file.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070031
32namespace art {
33
34inline int32_t DexFile::GetStringLength(const StringId& string_id) const {
Mathieu Chartierc3a22aa2018-01-19 18:58:34 -080035 const uint8_t* ptr = DataBegin() + string_id.string_data_off_;
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070036 return DecodeUnsignedLeb128(&ptr);
37}
38
Ian Rogersdfb325e2013-10-30 01:00:44 -070039inline const char* DexFile::GetStringDataAndUtf16Length(const StringId& string_id,
40 uint32_t* utf16_length) const {
Mathieu Chartier2cebb242015-04-21 16:50:40 -070041 DCHECK(utf16_length != nullptr) << GetLocation();
Mathieu Chartierc3a22aa2018-01-19 18:58:34 -080042 const uint8_t* ptr = DataBegin() + string_id.string_data_off_;
Ian Rogersdfb325e2013-10-30 01:00:44 -070043 *utf16_length = DecodeUnsignedLeb128(&ptr);
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070044 return reinterpret_cast<const char*>(ptr);
45}
46
Vladimir Marko5c6a5872016-06-27 13:50:16 +010047inline const char* DexFile::GetStringData(const StringId& string_id) const {
48 uint32_t ignored;
49 return GetStringDataAndUtf16Length(string_id, &ignored);
50}
51
Andreas Gampe8a0128a2016-11-28 07:38:35 -080052inline const char* DexFile::StringDataAndUtf16LengthByIdx(dex::StringIndex idx,
Vladimir Marko5c6a5872016-06-27 13:50:16 +010053 uint32_t* utf16_length) const {
Andreas Gampe8a0128a2016-11-28 07:38:35 -080054 if (!idx.IsValid()) {
Vladimir Marko5c6a5872016-06-27 13:50:16 +010055 *utf16_length = 0;
56 return nullptr;
57 }
58 const StringId& string_id = GetStringId(idx);
59 return GetStringDataAndUtf16Length(string_id, utf16_length);
60}
61
Andreas Gampe8a0128a2016-11-28 07:38:35 -080062inline const char* DexFile::StringDataByIdx(dex::StringIndex idx) const {
Vladimir Marko5c6a5872016-06-27 13:50:16 +010063 uint32_t unicode_length;
64 return StringDataAndUtf16LengthByIdx(idx, &unicode_length);
65}
66
Andreas Gampea5b09a62016-11-17 15:21:22 -080067inline const char* DexFile::StringByTypeIdx(dex::TypeIndex idx, uint32_t* unicode_length) const {
Jeff Hao120504f2017-04-14 14:33:52 -070068 if (!idx.IsValid()) {
69 return nullptr;
70 }
Vladimir Marko5c6a5872016-06-27 13:50:16 +010071 const TypeId& type_id = GetTypeId(idx);
72 return StringDataAndUtf16LengthByIdx(type_id.descriptor_idx_, unicode_length);
73}
74
Andreas Gampea5b09a62016-11-17 15:21:22 -080075inline const char* DexFile::StringByTypeIdx(dex::TypeIndex idx) const {
Jeff Hao120504f2017-04-14 14:33:52 -070076 if (!idx.IsValid()) {
77 return nullptr;
78 }
Vladimir Marko5c6a5872016-06-27 13:50:16 +010079 const TypeId& type_id = GetTypeId(idx);
80 return StringDataByIdx(type_id.descriptor_idx_);
81}
82
83inline const char* DexFile::GetTypeDescriptor(const TypeId& type_id) const {
84 return StringDataByIdx(type_id.descriptor_idx_);
85}
86
87inline const char* DexFile::GetFieldTypeDescriptor(const FieldId& field_id) const {
88 const DexFile::TypeId& type_id = GetTypeId(field_id.type_idx_);
89 return GetTypeDescriptor(type_id);
90}
91
92inline const char* DexFile::GetFieldName(const FieldId& field_id) const {
93 return StringDataByIdx(field_id.name_idx_);
94}
95
96inline const char* DexFile::GetMethodDeclaringClassDescriptor(const MethodId& method_id) const {
97 const DexFile::TypeId& type_id = GetTypeId(method_id.class_idx_);
98 return GetTypeDescriptor(type_id);
99}
100
Ian Rogersd91d6d62013-09-25 20:26:14 -0700101inline const Signature DexFile::GetMethodSignature(const MethodId& method_id) const {
102 return Signature(this, GetProtoId(method_id.proto_idx_));
103}
104
Orion Hodsonb34bb192016-10-18 17:02:58 +0100105inline const Signature DexFile::GetProtoSignature(const ProtoId& proto_id) const {
106 return Signature(this, proto_id);
107}
108
Vladimir Marko5c6a5872016-06-27 13:50:16 +0100109inline const char* DexFile::GetMethodName(const MethodId& method_id) const {
110 return StringDataByIdx(method_id.name_idx_);
111}
112
David Srbecky39d8c872018-11-01 16:44:20 +0000113inline const char* DexFile::GetMethodName(const MethodId& method_id, uint32_t* utf_length) const {
114 return StringDataAndUtf16LengthByIdx(method_id.name_idx_, utf_length);
115}
116
117inline const char* DexFile::GetMethodName(uint32_t idx, uint32_t* utf_length) const {
118 return StringDataAndUtf16LengthByIdx(GetMethodId(idx).name_idx_, utf_length);
119}
120
Vladimir Marko5c6a5872016-06-27 13:50:16 +0100121inline const char* DexFile::GetMethodShorty(uint32_t idx) const {
122 return StringDataByIdx(GetProtoId(GetMethodId(idx).proto_idx_).shorty_idx_);
123}
124
125inline const char* DexFile::GetMethodShorty(const MethodId& method_id) const {
126 return StringDataByIdx(GetProtoId(method_id.proto_idx_).shorty_idx_);
127}
128
129inline const char* DexFile::GetMethodShorty(const MethodId& method_id, uint32_t* length) const {
130 // Using the UTF16 length is safe here as shorties are guaranteed to be ASCII characters.
131 return StringDataAndUtf16LengthByIdx(GetProtoId(method_id.proto_idx_).shorty_idx_, length);
132}
133
134inline const char* DexFile::GetClassDescriptor(const ClassDef& class_def) const {
135 return StringByTypeIdx(class_def.class_idx_);
136}
137
138inline const char* DexFile::GetReturnTypeDescriptor(const ProtoId& proto_id) const {
139 return StringByTypeIdx(proto_id.return_type_idx_);
140}
141
Orion Hodson06d10a72018-05-14 08:53:38 +0100142inline const char* DexFile::GetShorty(dex::ProtoIndex proto_idx) const {
Vladimir Marko5c6a5872016-06-27 13:50:16 +0100143 const ProtoId& proto_id = GetProtoId(proto_idx);
144 return StringDataByIdx(proto_id.shorty_idx_);
145}
146
Mathieu Chartier3da1d0f2017-11-06 20:02:24 -0800147inline const DexFile::TryItem* DexFile::GetTryItems(const DexInstructionIterator& code_item_end,
148 uint32_t offset) {
Ian Rogers4f6ad8a2013-03-18 15:27:28 -0700149 return reinterpret_cast<const TryItem*>
Mathieu Chartier8740c662018-01-11 14:50:02 -0800150 (RoundUp(reinterpret_cast<uintptr_t>(&code_item_end.Inst()), TryItem::kAlignment)) + offset;
Ian Rogers4f6ad8a2013-03-18 15:27:28 -0700151}
152
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800153static inline bool DexFileStringEquals(const DexFile* df1, dex::StringIndex sidx1,
154 const DexFile* df2, dex::StringIndex sidx2) {
Ian Rogersdfb325e2013-10-30 01:00:44 -0700155 uint32_t s1_len; // Note: utf16 length != mutf8 length.
156 const char* s1_data = df1->StringDataAndUtf16LengthByIdx(sidx1, &s1_len);
157 uint32_t s2_len;
158 const char* s2_data = df2->StringDataAndUtf16LengthByIdx(sidx2, &s2_len);
159 return (s1_len == s2_len) && (strcmp(s1_data, s2_data) == 0);
160}
161
162inline bool Signature::operator==(const Signature& rhs) const {
163 if (dex_file_ == nullptr) {
164 return rhs.dex_file_ == nullptr;
165 }
166 if (rhs.dex_file_ == nullptr) {
167 return false;
168 }
169 if (dex_file_ == rhs.dex_file_) {
170 return proto_id_ == rhs.proto_id_;
171 }
172 uint32_t lhs_shorty_len; // For a shorty utf16 length == mutf8 length.
173 const char* lhs_shorty_data = dex_file_->StringDataAndUtf16LengthByIdx(proto_id_->shorty_idx_,
174 &lhs_shorty_len);
175 StringPiece lhs_shorty(lhs_shorty_data, lhs_shorty_len);
176 {
177 uint32_t rhs_shorty_len;
178 const char* rhs_shorty_data =
179 rhs.dex_file_->StringDataAndUtf16LengthByIdx(rhs.proto_id_->shorty_idx_,
180 &rhs_shorty_len);
181 StringPiece rhs_shorty(rhs_shorty_data, rhs_shorty_len);
182 if (lhs_shorty != rhs_shorty) {
183 return false; // Shorty mismatch.
184 }
185 }
186 if (lhs_shorty[0] == 'L') {
187 const DexFile::TypeId& return_type_id = dex_file_->GetTypeId(proto_id_->return_type_idx_);
188 const DexFile::TypeId& rhs_return_type_id =
189 rhs.dex_file_->GetTypeId(rhs.proto_id_->return_type_idx_);
190 if (!DexFileStringEquals(dex_file_, return_type_id.descriptor_idx_,
191 rhs.dex_file_, rhs_return_type_id.descriptor_idx_)) {
192 return false; // Return type mismatch.
193 }
194 }
195 if (lhs_shorty.find('L', 1) != StringPiece::npos) {
196 const DexFile::TypeList* params = dex_file_->GetProtoParameters(*proto_id_);
197 const DexFile::TypeList* rhs_params = rhs.dex_file_->GetProtoParameters(*rhs.proto_id_);
Vladimir Markoba118822017-06-12 15:41:56 +0100198 // We found a reference parameter in the matching shorty, so both lists must be non-empty.
199 DCHECK(params != nullptr);
200 DCHECK(rhs_params != nullptr);
201 uint32_t params_size = params->Size();
202 DCHECK_EQ(params_size, rhs_params->Size()); // Parameter list size must match.
203 for (uint32_t i = 0; i < params_size; ++i) {
204 const DexFile::TypeId& param_id = dex_file_->GetTypeId(params->GetTypeItem(i).type_idx_);
205 const DexFile::TypeId& rhs_param_id =
206 rhs.dex_file_->GetTypeId(rhs_params->GetTypeItem(i).type_idx_);
207 if (!DexFileStringEquals(dex_file_, param_id.descriptor_idx_,
208 rhs.dex_file_, rhs_param_id.descriptor_idx_)) {
209 return false; // Parameter type mismatch.
Ian Rogersdfb325e2013-10-30 01:00:44 -0700210 }
211 }
212 }
213 return true;
214}
215
David Sehraa6abb02017-10-12 08:25:11 -0700216template<typename NewLocalCallback, typename IndexToStringData, typename TypeIndexToStringData>
217bool DexFile::DecodeDebugLocalInfo(const uint8_t* stream,
218 const std::string& location,
219 const char* declaring_class_descriptor,
220 const std::vector<const char*>& arg_descriptors,
221 const std::string& method_name,
222 bool is_static,
223 uint16_t registers_size,
224 uint16_t ins_size,
225 uint16_t insns_size_in_code_units,
Mathieu Chartiere5afbf32018-09-12 17:51:54 -0700226 const IndexToStringData& index_to_string_data,
227 const TypeIndexToStringData& type_index_to_string_data,
228 const NewLocalCallback& new_local_callback) {
David Sehraa6abb02017-10-12 08:25:11 -0700229 if (stream == nullptr) {
230 return false;
231 }
232 std::vector<LocalInfo> local_in_reg(registers_size);
233
234 uint16_t arg_reg = registers_size - ins_size;
235 if (!is_static) {
236 const char* descriptor = declaring_class_descriptor;
237 local_in_reg[arg_reg].name_ = "this";
238 local_in_reg[arg_reg].descriptor_ = descriptor;
239 local_in_reg[arg_reg].signature_ = nullptr;
240 local_in_reg[arg_reg].start_address_ = 0;
241 local_in_reg[arg_reg].reg_ = arg_reg;
242 local_in_reg[arg_reg].is_live_ = true;
243 arg_reg++;
244 }
245
246 DecodeUnsignedLeb128(&stream); // Line.
247 uint32_t parameters_size = DecodeUnsignedLeb128(&stream);
248 uint32_t i;
249 if (parameters_size != arg_descriptors.size()) {
250 LOG(ERROR) << "invalid stream - problem with parameter iterator in " << location
251 << " for method " << method_name;
252 return false;
253 }
254 for (i = 0; i < parameters_size && i < arg_descriptors.size(); ++i) {
255 if (arg_reg >= registers_size) {
256 LOG(ERROR) << "invalid stream - arg reg >= reg size (" << arg_reg
257 << " >= " << registers_size << ") in " << location;
258 return false;
259 }
260 uint32_t name_idx = DecodeUnsignedLeb128P1(&stream);
261 const char* descriptor = arg_descriptors[i];
262 local_in_reg[arg_reg].name_ = index_to_string_data(name_idx);
263 local_in_reg[arg_reg].descriptor_ = descriptor;
264 local_in_reg[arg_reg].signature_ = nullptr;
265 local_in_reg[arg_reg].start_address_ = 0;
266 local_in_reg[arg_reg].reg_ = arg_reg;
267 local_in_reg[arg_reg].is_live_ = true;
268 switch (*descriptor) {
269 case 'D':
270 case 'J':
271 arg_reg += 2;
272 break;
273 default:
274 arg_reg += 1;
275 break;
276 }
277 }
278
279 uint32_t address = 0;
280 for (;;) {
281 uint8_t opcode = *stream++;
282 switch (opcode) {
283 case DBG_END_SEQUENCE:
284 // Emit all variables which are still alive at the end of the method.
285 for (uint16_t reg = 0; reg < registers_size; reg++) {
286 if (local_in_reg[reg].is_live_) {
287 local_in_reg[reg].end_address_ = insns_size_in_code_units;
Mathieu Chartiere5afbf32018-09-12 17:51:54 -0700288 new_local_callback(local_in_reg[reg]);
David Sehraa6abb02017-10-12 08:25:11 -0700289 }
290 }
291 return true;
292 case DBG_ADVANCE_PC:
293 address += DecodeUnsignedLeb128(&stream);
294 break;
295 case DBG_ADVANCE_LINE:
296 DecodeSignedLeb128(&stream); // Line.
297 break;
298 case DBG_START_LOCAL:
299 case DBG_START_LOCAL_EXTENDED: {
300 uint16_t reg = DecodeUnsignedLeb128(&stream);
301 if (reg >= registers_size) {
302 LOG(ERROR) << "invalid stream - reg >= reg size (" << reg << " >= "
303 << registers_size << ") in " << location;
304 return false;
305 }
306
307 uint32_t name_idx = DecodeUnsignedLeb128P1(&stream);
308 uint16_t descriptor_idx = DecodeUnsignedLeb128P1(&stream);
309 uint32_t signature_idx = dex::kDexNoIndex;
310 if (opcode == DBG_START_LOCAL_EXTENDED) {
311 signature_idx = DecodeUnsignedLeb128P1(&stream);
312 }
313
314 // Emit what was previously there, if anything
315 if (local_in_reg[reg].is_live_) {
316 local_in_reg[reg].end_address_ = address;
Mathieu Chartiere5afbf32018-09-12 17:51:54 -0700317 new_local_callback(local_in_reg[reg]);
David Sehraa6abb02017-10-12 08:25:11 -0700318 }
319
320 local_in_reg[reg].name_ = index_to_string_data(name_idx);
321 local_in_reg[reg].descriptor_ = type_index_to_string_data(descriptor_idx);;
322 local_in_reg[reg].signature_ = index_to_string_data(signature_idx);
323 local_in_reg[reg].start_address_ = address;
324 local_in_reg[reg].reg_ = reg;
325 local_in_reg[reg].is_live_ = true;
326 break;
327 }
328 case DBG_END_LOCAL: {
329 uint16_t reg = DecodeUnsignedLeb128(&stream);
330 if (reg >= registers_size) {
331 LOG(ERROR) << "invalid stream - reg >= reg size (" << reg << " >= "
332 << registers_size << ") in " << location;
333 return false;
334 }
335 // If the register is live, close it properly. Otherwise, closing an already
336 // closed register is sloppy, but harmless if no further action is taken.
337 if (local_in_reg[reg].is_live_) {
338 local_in_reg[reg].end_address_ = address;
Mathieu Chartiere5afbf32018-09-12 17:51:54 -0700339 new_local_callback(local_in_reg[reg]);
David Sehraa6abb02017-10-12 08:25:11 -0700340 local_in_reg[reg].is_live_ = false;
341 }
342 break;
343 }
344 case DBG_RESTART_LOCAL: {
345 uint16_t reg = DecodeUnsignedLeb128(&stream);
346 if (reg >= registers_size) {
347 LOG(ERROR) << "invalid stream - reg >= reg size (" << reg << " >= "
348 << registers_size << ") in " << location;
349 return false;
350 }
351 // If the register is live, the "restart" is superfluous,
352 // and we don't want to mess with the existing start address.
353 if (!local_in_reg[reg].is_live_) {
354 local_in_reg[reg].start_address_ = address;
355 local_in_reg[reg].is_live_ = true;
356 }
357 break;
358 }
359 case DBG_SET_PROLOGUE_END:
360 case DBG_SET_EPILOGUE_BEGIN:
361 break;
362 case DBG_SET_FILE:
363 DecodeUnsignedLeb128P1(&stream); // name.
364 break;
365 default:
366 address += (opcode - DBG_FIRST_SPECIAL) / DBG_LINE_RANGE;
367 break;
368 }
369 }
370}
371
372template<typename NewLocalCallback>
Mathieu Chartier31f4c9f2017-12-08 15:46:11 -0800373bool DexFile::DecodeDebugLocalInfo(uint32_t registers_size,
374 uint32_t ins_size,
375 uint32_t insns_size_in_code_units,
Nicolas Geoffray58cc1cb2017-11-20 13:27:29 +0000376 uint32_t debug_info_offset,
David Sehraa6abb02017-10-12 08:25:11 -0700377 bool is_static,
378 uint32_t method_idx,
Mathieu Chartiere5afbf32018-09-12 17:51:54 -0700379 const NewLocalCallback& new_local_callback) const {
Mathieu Chartier31f4c9f2017-12-08 15:46:11 -0800380 const uint8_t* const stream = GetDebugInfoStream(debug_info_offset);
381 if (stream == nullptr) {
David Sehraa6abb02017-10-12 08:25:11 -0700382 return false;
383 }
384 std::vector<const char*> arg_descriptors;
385 DexFileParameterIterator it(*this, GetMethodPrototype(GetMethodId(method_idx)));
386 for (; it.HasNext(); it.Next()) {
387 arg_descriptors.push_back(it.GetDescriptor());
388 }
Mathieu Chartier31f4c9f2017-12-08 15:46:11 -0800389 return DecodeDebugLocalInfo(stream,
David Sehraa6abb02017-10-12 08:25:11 -0700390 GetLocation(),
391 GetMethodDeclaringClassDescriptor(GetMethodId(method_idx)),
392 arg_descriptors,
393 this->PrettyMethod(method_idx),
394 is_static,
Mathieu Chartier31f4c9f2017-12-08 15:46:11 -0800395 registers_size,
396 ins_size,
397 insns_size_in_code_units,
David Sehraa6abb02017-10-12 08:25:11 -0700398 [this](uint32_t idx) {
399 return StringDataByIdx(dex::StringIndex(idx));
400 },
401 [this](uint32_t idx) {
402 return StringByTypeIdx(dex::TypeIndex(
403 dchecked_integral_cast<uint16_t>(idx)));
404 },
Mathieu Chartiere5afbf32018-09-12 17:51:54 -0700405 new_local_callback);
David Sehraa6abb02017-10-12 08:25:11 -0700406}
407
408template<typename DexDebugNewPosition, typename IndexToStringData>
409bool DexFile::DecodeDebugPositionInfo(const uint8_t* stream,
Mathieu Chartier3e2e1232018-09-11 12:35:30 -0700410 const IndexToStringData& index_to_string_data,
411 const DexDebugNewPosition& position_functor) {
David Sehraa6abb02017-10-12 08:25:11 -0700412 if (stream == nullptr) {
413 return false;
414 }
415
Mathieu Chartier3e2e1232018-09-11 12:35:30 -0700416 PositionInfo entry;
417 entry.line_ = DecodeDebugInfoParameterNames(&stream, VoidFunctor());
David Sehraa6abb02017-10-12 08:25:11 -0700418
419 for (;;) {
420 uint8_t opcode = *stream++;
421 switch (opcode) {
422 case DBG_END_SEQUENCE:
423 return true; // end of stream.
424 case DBG_ADVANCE_PC:
425 entry.address_ += DecodeUnsignedLeb128(&stream);
426 break;
427 case DBG_ADVANCE_LINE:
428 entry.line_ += DecodeSignedLeb128(&stream);
429 break;
430 case DBG_START_LOCAL:
431 DecodeUnsignedLeb128(&stream); // reg.
432 DecodeUnsignedLeb128P1(&stream); // name.
433 DecodeUnsignedLeb128P1(&stream); // descriptor.
434 break;
435 case DBG_START_LOCAL_EXTENDED:
436 DecodeUnsignedLeb128(&stream); // reg.
437 DecodeUnsignedLeb128P1(&stream); // name.
438 DecodeUnsignedLeb128P1(&stream); // descriptor.
439 DecodeUnsignedLeb128P1(&stream); // signature.
440 break;
441 case DBG_END_LOCAL:
442 case DBG_RESTART_LOCAL:
443 DecodeUnsignedLeb128(&stream); // reg.
444 break;
445 case DBG_SET_PROLOGUE_END:
446 entry.prologue_end_ = true;
447 break;
448 case DBG_SET_EPILOGUE_BEGIN:
449 entry.epilogue_begin_ = true;
450 break;
451 case DBG_SET_FILE: {
452 uint32_t name_idx = DecodeUnsignedLeb128P1(&stream);
453 entry.source_file_ = index_to_string_data(name_idx);
454 break;
455 }
456 default: {
457 int adjopcode = opcode - DBG_FIRST_SPECIAL;
458 entry.address_ += adjopcode / DBG_LINE_RANGE;
459 entry.line_ += DBG_LINE_BASE + (adjopcode % DBG_LINE_RANGE);
Mathieu Chartier3e2e1232018-09-11 12:35:30 -0700460 if (position_functor(entry)) {
David Sehraa6abb02017-10-12 08:25:11 -0700461 return true; // early exit.
462 }
463 entry.prologue_end_ = false;
464 entry.epilogue_begin_ = false;
465 break;
466 }
467 }
468 }
469}
470
Mathieu Chartier69147f12017-11-06 20:02:24 -0800471inline const CompactDexFile* DexFile::AsCompactDexFile() const {
472 DCHECK(IsCompactDexFile());
473 return down_cast<const CompactDexFile*>(this);
474}
475
476inline const StandardDexFile* DexFile::AsStandardDexFile() const {
477 DCHECK(IsStandardDexFile());
478 return down_cast<const StandardDexFile*>(this);
479}
480
Mathieu Chartier6238c832018-01-04 09:55:13 -0800481// Get the base of the encoded data for the given DexCode.
482inline const uint8_t* DexFile::GetCatchHandlerData(const DexInstructionIterator& code_item_end,
483 uint32_t tries_size,
484 uint32_t offset) {
485 const uint8_t* handler_data =
486 reinterpret_cast<const uint8_t*>(GetTryItems(code_item_end, tries_size));
487 return handler_data + offset;
488}
489
Mathieu Chartier05dc23e2018-05-22 11:56:14 -0700490inline IterationRange<ClassIterator> DexFile::GetClasses() const {
491 return { ClassIterator(*this, 0u), ClassIterator(*this, NumClassDefs()) };
492}
493
Mathieu Chartier3e2e1232018-09-11 12:35:30 -0700494// Returns the line number
495template <typename Visitor>
496inline uint32_t DexFile::DecodeDebugInfoParameterNames(const uint8_t** debug_info,
497 const Visitor& visitor) {
498 uint32_t line = DecodeUnsignedLeb128(debug_info);
499 const uint32_t parameters_size = DecodeUnsignedLeb128(debug_info);
500 for (uint32_t i = 0; i < parameters_size; ++i) {
501 visitor(dex::StringIndex(DecodeUnsignedLeb128P1(debug_info)));
502 }
503 return line;
504}
505
Ian Rogers4f6ad8a2013-03-18 15:27:28 -0700506} // namespace art
507
David Sehr334b9d72018-02-12 18:27:56 -0800508#endif // ART_LIBDEXFILE_DEX_DEX_FILE_INL_H_