1 /** 2 * Copyright (c) 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_TOOLING_INSPECTOR_BREAKPOINT_H 17 #define PANDA_TOOLING_INSPECTOR_BREAKPOINT_H 18 19 #include <algorithm> 20 #include <functional> 21 #include <unordered_set> 22 23 #include "breakpoint_base.h" 24 25 namespace ark::tooling::inspector { 26 class EvaluationEngine; 27 28 /// @brief Breakpoint without condition, can be set in multiple locations 29 class Breakpoint final : public BreakpointBase { 30 public: Breakpoint(BreakpointId id,SourceFileFilter && filter,size_t line,bool isUrlPattern)31 explicit Breakpoint(BreakpointId id, SourceFileFilter &&filter, size_t line, bool isUrlPattern) 32 : BreakpointBase(id), sourceFileFilter_(std::move(filter)), lineNumber_(line), isUrlPattern_(isUrlPattern) 33 { 34 } 35 36 NO_COPY_SEMANTIC(Breakpoint); 37 NO_MOVE_SEMANTIC(Breakpoint); 38 39 ~Breakpoint() override = default; 40 41 bool SetLocations(std::set<std::string_view> &sourceFiles, const DebugInfoCache &debugCache, 42 std::unordered_multimap<PtLocation, BreakpointId, HashLocation> &breakpointLocations) override; 43 EnumerateLocations(const std::function<bool (BreakpointId,const PtLocation &)> & func)44 void EnumerateLocations(const std::function<bool(BreakpointId, const PtLocation &)> &func) override 45 { 46 for (const auto &loc : locations_) { 47 if (!func(GetId(), loc)) { 48 return; 49 } 50 } 51 } 52 ShouldStopAt(const PtLocation & location,EvaluationEngine & engine)53 bool ShouldStopAt(const PtLocation &location, [[maybe_unused]] EvaluationEngine &engine) override 54 { 55 if (!IsResolved()) { 56 return false; 57 } 58 return std::any_of(locations_.begin(), locations_.end(), 59 [location](const auto &loc) { return loc == location; }); 60 } 61 IsUrlPattern()62 bool IsUrlPattern() 63 { 64 return isUrlPattern_; 65 } 66 67 protected: 68 void TryResolveImpl(const panda_file::File &file, const panda_file::DebugInfoExtractor *debugInfo, 69 std::unordered_multimap<PtLocation, BreakpointId, HashLocation> &breakpointLocations) override; 70 71 private: 72 std::unordered_set<PtLocation, HashLocation> locations_; 73 SourceFileFilter sourceFileFilter_; 74 size_t lineNumber_ {0}; 75 bool isUrlPattern_ {false}; 76 }; 77 78 } // namespace ark::tooling::inspector 79 80 #endif // PANDA_TOOLING_INSPECTOR_BREAKPOINT_H 81