1 /** 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef LIBPANDAFILE_DEBUG_INFO_EXTRACTOR_H 17 #define LIBPANDAFILE_DEBUG_INFO_EXTRACTOR_H 18 19 #include "file.h" 20 #include "file_items.h" 21 22 #include <string> 23 #include <vector> 24 #include <list> 25 26 namespace panda::panda_file { 27 28 struct LineTableEntry { 29 uint32_t offset; 30 size_t line; 31 }; 32 33 struct ColumnTableEntry { 34 uint32_t offset; 35 size_t column; 36 }; 37 38 using LineNumberTable = std::vector<LineTableEntry>; 39 using ColumnNumberTable = std::vector<ColumnTableEntry>; 40 41 struct LocalVariableInfo { 42 std::string name; 43 std::string type; 44 std::string type_signature; 45 int32_t reg_number; 46 uint32_t start_offset; 47 uint32_t end_offset; 48 }; 49 50 using LocalVariableTable = std::vector<LocalVariableInfo>; 51 52 class DebugInfoExtractor { 53 public: 54 struct ParamInfo { 55 std::string name; 56 std::string signature; 57 }; 58 59 explicit DebugInfoExtractor(const File *pf); 60 61 ~DebugInfoExtractor() = default; 62 63 DEFAULT_COPY_SEMANTIC(DebugInfoExtractor); 64 DEFAULT_MOVE_SEMANTIC(DebugInfoExtractor); 65 66 const LineNumberTable &GetLineNumberTable(File::EntityId method_id) const; 67 68 const ColumnNumberTable &GetColumnNumberTable(File::EntityId method_id) const; 69 70 const LocalVariableTable &GetLocalVariableTable(File::EntityId method_id) const; 71 72 const std::vector<ParamInfo> &GetParameterInfo(File::EntityId method_id) const; 73 74 const char *GetSourceFile(File::EntityId method_id) const; 75 76 const char *GetSourceCode(File::EntityId method_id) const; 77 78 std::vector<File::EntityId> GetMethodIdList() const; 79 80 private: 81 void Extract(const File *pf); 82 83 struct MethodDebugInfo { 84 std::string source_file; 85 std::string source_code; 86 File::EntityId method_id; 87 LineNumberTable line_number_table; 88 LocalVariableTable local_variable_table; 89 std::vector<ParamInfo> param_info; 90 ColumnNumberTable column_number_table; 91 }; 92 93 std::list<MethodDebugInfo> methods_; 94 }; 95 96 } // namespace panda::panda_file 97 98 #endif // LIBPANDAFILE_DEBUG_INFO_EXTRACTOR_H 99