1 /** 2 * Copyright (c) 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_TOOLING_INSPECTOR_STEP_HOOKS_H 17 #define PANDA_TOOLING_INSPECTOR_STEP_HOOKS_H 18 19 #include "tooling/debugger.h" 20 #include "tooling/debug_interface.h" 21 #include "tooling/pt_location.h" 22 #include "tooling/pt_thread.h" 23 24 #include <optional> 25 #include <unordered_map> 26 27 namespace panda { 28 class JsonObject; 29 } // namespace panda 30 31 namespace panda::tooling::inspector { 32 class Inspector; 33 34 class StepHooks : public PtHooks { 35 public: 36 explicit StepHooks(Inspector &inspector); 37 38 void Breakpoint(PtThread thread, Method * /* method */, const PtLocation &location) override; 39 void FramePop(PtThread thread, Method * /* method */, bool /* wasPoppedByException */) override; 40 void MethodEntry(PtThread thread, Method * /* method */) override; 41 void SingleStep(PtThread thread, Method * /* method */, const PtLocation & /* location */) override; 42 void VmInitialization(PtThread thread) override; 43 44 private: 45 enum StepKind { 46 BREAK_ON_START, 47 CONTINUE_TO, 48 STEP_INTO, 49 STEP_OUT, 50 STEP_OVER, 51 }; 52 53 void AddLocation(const PtLocation &location); 54 void ContinueToLocation(const JsonObject ¶ms); 55 void OnPause(); 56 void SetBreakOnStart(); 57 void SetStep(StepKind stepKind); 58 59 struct State { 60 StepKind stepKind; 61 PtThread thread {PtThread::NONE}; 62 std::unordered_map<PtLocation, bool, HashLocation> locations; 63 bool methodEntered {false}; 64 bool pauseOnStep {false}; 65 }; 66 67 Inspector &inspector_; 68 std::optional<State> state_; 69 }; 70 } // namespace panda::tooling::inspector 71 72 #endif // PANDA_TOOLING_INSPECTOR_STEP_HOOKS_H 73