1 /* 2 * Copyright (C) 2017 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 17 #ifndef ART_LIBDEXFILE_DEX_DEX_FILE_EXCEPTION_HELPERS_H_ 18 #define ART_LIBDEXFILE_DEX_DEX_FILE_EXCEPTION_HELPERS_H_ 19 20 #include "dex_file.h" 21 22 namespace art { 23 24 class CodeItemDataAccessor; 25 26 class CatchHandlerIterator { 27 public: 28 CatchHandlerIterator(const CodeItemDataAccessor& accessor, uint32_t address); 29 30 CatchHandlerIterator(const CodeItemDataAccessor& accessor, const DexFile::TryItem& try_item); 31 CatchHandlerIterator(const uint8_t * handler_data)32 explicit CatchHandlerIterator(const uint8_t* handler_data) { 33 Init(handler_data); 34 } 35 GetHandlerTypeIndex()36 dex::TypeIndex GetHandlerTypeIndex() const { 37 return handler_.type_idx_; 38 } GetHandlerAddress()39 uint32_t GetHandlerAddress() const { 40 return handler_.address_; 41 } 42 void Next(); HasNext()43 bool HasNext() const { 44 return remaining_count_ != -1 || catch_all_; 45 } 46 // End of this set of catch blocks, convenience method to locate next set of catch blocks EndDataPointer()47 const uint8_t* EndDataPointer() const { 48 CHECK(!HasNext()); 49 return current_data_; 50 } 51 52 private: 53 void Init(const CodeItemDataAccessor& accessor, int32_t offset); 54 void Init(const uint8_t* handler_data); 55 56 struct CatchHandlerItem { 57 dex::TypeIndex type_idx_; // type index of the caught exception type 58 uint32_t address_; // handler address 59 } handler_; 60 const uint8_t* current_data_; // the current handler in dex file. 61 int32_t remaining_count_; // number of handlers not read. 62 bool catch_all_; // is there a handler that will catch all exceptions in case 63 // that all typed handler does not match. 64 }; 65 66 } // namespace art 67 68 #endif // ART_LIBDEXFILE_DEX_DEX_FILE_EXCEPTION_HELPERS_H_ 69