1 /* 2 * Copyright (c) 2021-2025 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 PANDA_DISASM_BACKED_DEBUG_INFO_EXTRACTOR_H 17 #define PANDA_DISASM_BACKED_DEBUG_INFO_EXTRACTOR_H 18 19 #include "disassembler.h" 20 21 namespace ark::disasm { 22 class PANDA_PUBLIC_API DisasmBackedDebugInfoExtractor : public panda_file::DebugInfoExtractor { 23 public: 24 explicit DisasmBackedDebugInfoExtractor( 25 const panda_file::File &file, 26 std::function<void(panda_file::File::EntityId, std::string_view)> &&onDisasmSourceName = [](auto, auto) {}); 27 28 const panda_file::LineNumberTable &GetLineNumberTable(panda_file::File::EntityId methodId) const override; 29 const panda_file::ColumnNumberTable &GetColumnNumberTable(panda_file::File::EntityId methodId) const override; 30 const panda_file::LocalVariableTable &GetLocalVariableTable(panda_file::File::EntityId methodId) const override; 31 const std::vector<ParamInfo> &GetParameterInfo(panda_file::File::EntityId methodId) const override; 32 const char *GetSourceFile(panda_file::File::EntityId methodId) const override; 33 const char *GetSourceCode(panda_file::File::EntityId methodId) const override; 34 bool IsUserFile() const override; 35 void SetUserFile(bool isUser); 36 37 private: 38 struct Disassembly { 39 std::string sourceCode; 40 panda_file::LineNumberTable lineTable; 41 std::vector<ParamInfo> parameterInfo; 42 panda_file::LocalVariableTable localVariableTable; 43 }; 44 45 const std::optional<std::string> &GetDisassemblySourceName(panda_file::File::EntityId methodId) const; 46 const Disassembly &GetDisassembly(panda_file::File::EntityId methodId) const; 47 48 const std::string sourceNamePrefix_; 49 const std::function<void(panda_file::File::EntityId, std::string_view)> onDisasmSourceName_; 50 51 mutable os::memory::Mutex mutex_; 52 mutable Disassembler disassembler_ GUARDED_BY(mutex_); 53 mutable std::unordered_map<panda_file::File::EntityId, std::optional<std::string>> sourceNames_ GUARDED_BY(mutex_); 54 mutable std::unordered_map<panda_file::File::EntityId, Disassembly> disassemblies_ GUARDED_BY(mutex_); 55 bool isUserFile_ = false; 56 }; 57 } // namespace ark::disasm 58 59 #endif // PANDA_DISASM_BACKED_DEBUG_INFO_EXTRACTOR_H 60