• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CONDITIONAL_BREAKPOINT_H
17 #define PANDA_TOOLING_INSPECTOR_CONDITIONAL_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 Conditional breakpoint, allows only one location, condition is evaluated on breakpoint hit
29 class ConditionalBreakpoint final : public BreakpointBase {
30 public:
ConditionalBreakpoint(BreakpointId id,SourceFileFilter && filter,size_t line,const std::string * bytecode)31     explicit ConditionalBreakpoint(BreakpointId id, SourceFileFilter &&filter, size_t line, const std::string *bytecode)
32         : BreakpointBase(id), sourceFileFilter_(std::move(filter)), lineNumber_(line), bytecode_(*bytecode)
33     {
34     }
35 
36     NO_COPY_SEMANTIC(ConditionalBreakpoint);
37     NO_MOVE_SEMANTIC(ConditionalBreakpoint);
38 
39     ~ConditionalBreakpoint() 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         if (location_) {
47             func(GetId(), *location_);
48         }
49     }
50 
51     bool ShouldStopAt(const PtLocation &location, EvaluationEngine &engine) override;
52 
53 protected:
54     void TryResolveImpl(const panda_file::File &file, const panda_file::DebugInfoExtractor *debugInfo,
55                         std::unordered_multimap<PtLocation, BreakpointId, HashLocation> &breakpointLocations) override;
56 
57 private:
58     std::optional<PtLocation> location_;
59     SourceFileFilter sourceFileFilter_;
60     size_t lineNumber_ {0};
61     std::string bytecode_;
62     Method *method_ {nullptr};
63 };
64 
65 }  // namespace ark::tooling::inspector
66 
67 #endif  // PANDA_TOOLING_INSPECTOR_CONDITIONAL_BREAKPOINT_H
68