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 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 panda::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 56 SourceLocation GetSourceLocation(EntityId methodId, uint32_t bytecodeOffset); 57 58 static std::optional<size_t> GetLineNumberByTableOffset(const panda_file::LineNumberTable &table, uint32_t offset); 59 static std::optional<uint32_t> GetOffsetByTableLineNumber(const panda_file::LineNumberTable &table, size_t line); 60 61 NO_COPY_SEMANTIC(TestExtractor); 62 NO_MOVE_SEMANTIC(TestExtractor); 63 64 protected: 65 PandaUniquePtr<panda_file::DebugInfoExtractor> lang_extractor_; 66 }; 67 68 class TestExtractorFactory { 69 public: 70 TestExtractorFactory() = default; 71 virtual ~TestExtractorFactory() = default; 72 MakeTestExtractor(const panda_file::File * pf)73 virtual PandaUniquePtr<TestExtractor> MakeTestExtractor(const panda_file::File *pf) 74 { 75 return MakePandaUnique<TestExtractor>(pf); 76 } 77 78 NO_COPY_SEMANTIC(TestExtractorFactory); 79 NO_MOVE_SEMANTIC(TestExtractorFactory); 80 }; 81 } // namespace panda::tooling::test 82 83 #endif // PANDA_RUNTIME_TESTS_TOOLING_TEST_EXTRACTOR_H 84