• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2022-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_TOOLING_INSPECTOR_THREAD_STATE_H
17 #define PANDA_TOOLING_INSPECTOR_THREAD_STATE_H
18 
19 #include "types/numeric_id.h"
20 #include "types/pause_on_exceptions_state.h"
21 
22 #include "tooling/debugger.h"
23 
24 #include <unordered_set>
25 #include <vector>
26 
27 namespace ark::tooling::inspector {
28 class ThreadState final {
29 public:
30     ThreadState() = default;
31     ~ThreadState() = default;
32 
33     NO_COPY_SEMANTIC(ThreadState);
34     NO_MOVE_SEMANTIC(ThreadState);
35 
IsPaused()36     bool IsPaused() const
37     {
38         return paused_;
39     }
40 
41     std::vector<BreakpointId> GetBreakpointsByLocation(const PtLocation &location) const;
42 
43     void Reset();
44     void BreakOnStart();
45     void Continue();
46     void ContinueTo(std::unordered_set<PtLocation, HashLocation> locations);
47     void StepInto(std::unordered_set<PtLocation, HashLocation> locations);
48     void StepOver(std::unordered_set<PtLocation, HashLocation> locations);
49     void StepOut();
50     void Pause();
51     void SetBreakpointsActive(bool active);
52     BreakpointId SetBreakpoint(const std::vector<PtLocation> &locations);
53     void RemoveBreakpoint(BreakpointId id);
54     void SetPauseOnExceptions(PauseOnExceptionsState state);
55 
56     void OnException(bool uncaught);
57     void OnFramePop();
58     bool OnMethodEntry();
59     void OnSingleStep(const PtLocation &location);
60 
61 private:
62     enum class StepKind {
63         // Just continue execution
64         NONE,
65 
66         // Stop on the next step event. It is not reset to NONE during resetting the state on a new connection
67         BREAK_ON_START,
68 
69         // Continue execution until one of the specified locations is reached
70         CONTINUE_TO,
71 
72         // Stop on the next step event
73         PAUSE,
74 
75         // Continue execution until one of the locations, other than the current line, is reached
76         STEP_INTO,
77 
78         // Continue execution until the current frame is popped
79         STEP_OUT,
80 
81         // Continue execution until both:
82         // - The call frame is not a child to the starting position (e.g. we have not entered some method);
83         // - One of the locations, other than the current line, is reached.
84         STEP_OVER
85     };
86 
87     StepKind stepKind_ {StepKind::NONE};
88 
89     // The set of locations has different semantics for various kinds of stepping:
90     // - for CONTINUE_TO it contains the set of locations we should reach to end the step;
91     // - for STEP_INTO and STEP_OVER it contains the set of locations corresponding to the current line
92     //   (then, the locations we should leave to end the step).
93     std::unordered_set<PtLocation, HashLocation> stepLocations_;
94 
95     bool methodEntered_ {false};
96 
97     bool breakpointsActive_ {true};
98     BreakpointId nextBreakpointId_ {0};
99     std::unordered_multimap<PtLocation, BreakpointId, HashLocation> breakpointLocations_;
100 
101     PauseOnExceptionsState pauseOnExceptionsState_ {PauseOnExceptionsState::NONE};
102 
103     bool paused_ {false};
104 };
105 }  // namespace ark::tooling::inspector
106 
107 #endif  // PANDA_TOOLING_INSPECTOR_THREAD_STATE_H
108