• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ECMASCRIPT_TOOLING_BACKEND_JS_PT_EXTRACTOR_H
17 #define ECMASCRIPT_TOOLING_BACKEND_JS_PT_EXTRACTOR_H
18 
19 #include "ecmascript/debugger/js_debugger_interface.h"
20 #include "ecmascript/debugger/js_pt_method.h"
21 #include "ecmascript/js_thread.h"
22 #include "ecmascript/jspandafile/debug_info_extractor.h"
23 
24 #include "libpandabase/macros.h"
25 
26 namespace panda::ecmascript::tooling {
27 using panda::panda_file::File;
28 
29 class SingleStepper {
30 public:
31     enum class Type { STEP_INTO, STEP_OVER, STEP_OUT };
SingleStepper(const EcmaVM * ecmaVm,std::unique_ptr<PtMethod> ptMethod,std::list<JSPtStepRange> stepRanges,Type type)32     SingleStepper(const EcmaVM *ecmaVm, std::unique_ptr<PtMethod> ptMethod,
33         std::list<JSPtStepRange> stepRanges, Type type)
34         : ecmaVm_(ecmaVm),
35           method_(std::move(ptMethod)),
36           stepRanges_(std::move(stepRanges)),
37           stackDepth_(GetStackDepth()),
38           type_(type) {}
39 
40     virtual ~SingleStepper() = default;
41     NO_COPY_SEMANTIC(SingleStepper);
42     NO_MOVE_SEMANTIC(SingleStepper);
43 
44     bool StepComplete(uint32_t bcOffset) const;
GetStepperType()45     Type GetStepperType() const
46     {
47         return type_;
48     }
49 
50     static std::unique_ptr<SingleStepper> GetStepIntoStepper(const EcmaVM *ecmaVm);
51     static std::unique_ptr<SingleStepper> GetStepOverStepper(const EcmaVM *ecmaVm);
52     static std::unique_ptr<SingleStepper> GetStepOutStepper(const EcmaVM *ecmaVm);
53 
54 private:
55     uint32_t GetStackDepth() const;
56     bool InStepRange(uint32_t pc) const;
57     static std::list<JSPtStepRange> GetStepRanges(DebugInfoExtractor *extractor,
58         File::EntityId methodId, uint32_t offset);
59     static std::unique_ptr<SingleStepper> GetStepper(const EcmaVM *ecmaVm, SingleStepper::Type type);
60 
61     const EcmaVM *ecmaVm_;
62     std::unique_ptr<PtMethod> method_;
63     std::list<JSPtStepRange> stepRanges_;
64     uint32_t stackDepth_;
65     Type type_;
66 };
67 }  // namespace panda::ecmascript::tooling
68 #endif  // ECMASCRIPT_TOOLING_BACKEND_JS_PT_EXTRACTOR_H
69