1 /** 2 * Copyright (c) 2021-2024 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_RUNTIME_TESTS_TOOLING_TEST_EXTRACTOR_H 17 #define PANDA_RUNTIME_TESTS_TOOLING_TEST_EXTRACTOR_H 18 19 #include "libpandafile/debug_info_extractor.h" 20 #include "libpandafile/line_number_program.h" 21 #include "runtime/include/tooling/debug_interface.h" 22 23 namespace ark::tooling::test { 24 using EntityId = panda_file::File::EntityId; 25 26 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) 27 struct SourceLocation { 28 PandaString path; // NOLINT(misc-non-private-member-variables-in-classes) 29 size_t line; // NOLINT(misc-non-private-member-variables-in-classes) 30 31 bool operator==(const SourceLocation &other) const 32 { 33 return path == other.path && line == other.line; 34 } 35 IsValidSourceLocation36 bool IsValid() const 37 { 38 return !path.empty(); 39 } 40 }; 41 42 class TestExtractor { 43 public: 44 TestExtractor() = default; 45 46 explicit TestExtractor(const panda_file::File *pf); 47 48 virtual ~TestExtractor() = default; 49 50 std::pair<EntityId, uint32_t> GetBreakpointAddress(const SourceLocation &sourceLocation); 51 52 PandaList<PtStepRange> GetStepRanges(EntityId methodId, uint32_t currentOffset); 53 54 virtual std::vector<panda_file::LocalVariableInfo> GetLocalVariableInfo(EntityId methodId, size_t offset); 55 const std::vector<panda_file::DebugInfoExtractor::ParamInfo> &GetParameterInfo(EntityId methodId); 56 57 SourceLocation GetSourceLocation(EntityId methodId, uint32_t bytecodeOffset); 58 59 static std::optional<size_t> GetLineNumberByTableOffset(const panda_file::LineNumberTable &table, uint32_t offset); 60 static std::optional<uint32_t> GetOffsetByTableLineNumber(const panda_file::LineNumberTable &table, size_t line); 61 62 NO_COPY_SEMANTIC(TestExtractor); 63 NO_MOVE_SEMANTIC(TestExtractor); 64 65 protected: 66 // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) 67 PandaUniquePtr<panda_file::DebugInfoExtractor> langExtractor_; 68 }; 69 70 class TestExtractorFactory { 71 public: 72 TestExtractorFactory() = default; 73 virtual ~TestExtractorFactory() = default; 74 MakeTestExtractor(const panda_file::File * pf)75 virtual PandaUniquePtr<TestExtractor> MakeTestExtractor(const panda_file::File *pf) 76 { 77 return MakePandaUnique<TestExtractor>(pf); 78 } 79 80 NO_COPY_SEMANTIC(TestExtractorFactory); 81 NO_MOVE_SEMANTIC(TestExtractorFactory); 82 }; 83 } // namespace ark::tooling::test 84 85 #endif // PANDA_RUNTIME_TESTS_TOOLING_TEST_EXTRACTOR_H 86