1e509ee18Sopenharmony_ci/* 2e509ee18Sopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 3e509ee18Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e509ee18Sopenharmony_ci * you may not use this file except in compliance with the License. 5e509ee18Sopenharmony_ci * You may obtain a copy of the License at 6e509ee18Sopenharmony_ci * 7e509ee18Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e509ee18Sopenharmony_ci * 9e509ee18Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e509ee18Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e509ee18Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e509ee18Sopenharmony_ci * See the License for the specific language governing permissions and 13e509ee18Sopenharmony_ci * limitations under the License. 14e509ee18Sopenharmony_ci */ 15e509ee18Sopenharmony_ci 16e509ee18Sopenharmony_ci#ifndef ECMASCRIPT_TOOLING_BACKEND_JS_SINGLE_STEPPER_H 17e509ee18Sopenharmony_ci#define ECMASCRIPT_TOOLING_BACKEND_JS_SINGLE_STEPPER_H 18e509ee18Sopenharmony_ci 19e509ee18Sopenharmony_ci#include "ecmascript/debugger/js_debugger_interface.h" 20e509ee18Sopenharmony_ci#include "ecmascript/debugger/js_pt_method.h" 21e509ee18Sopenharmony_ci#include "ecmascript/js_thread.h" 22e509ee18Sopenharmony_ci#include "ecmascript/jspandafile/debug_info_extractor.h" 23e509ee18Sopenharmony_ci 24e509ee18Sopenharmony_ci#include "libpandabase/macros.h" 25e509ee18Sopenharmony_ci 26e509ee18Sopenharmony_cinamespace panda::ecmascript::tooling { 27e509ee18Sopenharmony_ciclass SingleStepper { 28e509ee18Sopenharmony_cipublic: 29e509ee18Sopenharmony_ci enum class Type { STEP_INTO, STEP_OVER, STEP_OUT }; 30e509ee18Sopenharmony_ci SingleStepper(const EcmaVM *ecmaVm, std::unique_ptr<PtMethod> ptMethod, 31e509ee18Sopenharmony_ci std::list<JSPtStepRange> stepRanges, Type type) 32e509ee18Sopenharmony_ci : ecmaVm_(ecmaVm), 33e509ee18Sopenharmony_ci method_(std::move(ptMethod)), 34e509ee18Sopenharmony_ci stepRanges_(std::move(stepRanges)), 35e509ee18Sopenharmony_ci stackDepth_(GetStackDepth()), 36e509ee18Sopenharmony_ci type_(type) {} 37e509ee18Sopenharmony_ci 38e509ee18Sopenharmony_ci virtual ~SingleStepper() = default; 39e509ee18Sopenharmony_ci NO_COPY_SEMANTIC(SingleStepper); 40e509ee18Sopenharmony_ci NO_MOVE_SEMANTIC(SingleStepper); 41e509ee18Sopenharmony_ci 42e509ee18Sopenharmony_ci bool StepComplete(uint32_t bcOffset) const; 43e509ee18Sopenharmony_ci Type GetStepperType() const 44e509ee18Sopenharmony_ci { 45e509ee18Sopenharmony_ci return type_; 46e509ee18Sopenharmony_ci } 47e509ee18Sopenharmony_ci 48e509ee18Sopenharmony_ci static std::unique_ptr<SingleStepper> GetStepIntoStepper(const EcmaVM *ecmaVm); 49e509ee18Sopenharmony_ci static std::unique_ptr<SingleStepper> GetStepOverStepper(const EcmaVM *ecmaVm); 50e509ee18Sopenharmony_ci static std::unique_ptr<SingleStepper> GetStepOutStepper(const EcmaVM *ecmaVm); 51e509ee18Sopenharmony_ci 52e509ee18Sopenharmony_ciprivate: 53e509ee18Sopenharmony_ci uint32_t GetStackDepth() const; 54e509ee18Sopenharmony_ci bool InStepRange(uint32_t pc) const; 55e509ee18Sopenharmony_ci static std::list<JSPtStepRange> GetStepRanges(DebugInfoExtractor *extractor, 56e509ee18Sopenharmony_ci panda_file::File::EntityId methodId, uint32_t offset); 57e509ee18Sopenharmony_ci static std::unique_ptr<SingleStepper> GetStepper(const EcmaVM *ecmaVm, SingleStepper::Type type); 58e509ee18Sopenharmony_ci 59e509ee18Sopenharmony_ci const EcmaVM *ecmaVm_; 60e509ee18Sopenharmony_ci std::unique_ptr<PtMethod> method_; 61e509ee18Sopenharmony_ci std::list<JSPtStepRange> stepRanges_; 62e509ee18Sopenharmony_ci uint32_t stackDepth_; 63e509ee18Sopenharmony_ci Type type_; 64e509ee18Sopenharmony_ci}; 65e509ee18Sopenharmony_ci} // namespace panda::ecmascript::tooling 66e509ee18Sopenharmony_ci#endif // ECMASCRIPT_TOOLING_BACKEND_JS_SINGLE_STEPPER_H 67