• 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 PANDA_TOOLING_INSPECTOR_TEST_TEST_FRAME_H
17 #define PANDA_TOOLING_INSPECTOR_TEST_TEST_FRAME_H
18 
19 #include "test_debugger.h"
20 
21 #include "macros.h"
22 #include "method.h"
23 #include "tooling/debug_interface.h"
24 #include "tooling/pt_thread.h"
25 #include "utils/list.h"
26 
27 #include <cstdint>
28 
29 namespace panda::tooling::inspector::test {
30 class TestFrame : public PtFrame, public ListNode {
31 public:
TestFrame(TestDebugger & debugger)32     explicit TestFrame(TestDebugger &debugger) : debugger_(&debugger)
33     {
34         debugger.PushFrame(*this);
35     }
36 
TestFrame(const TestFrame & other)37     TestFrame(const TestFrame &other)  // NOLINT(bugprone-copy-constructor-init)
38         : PtFrame(),                   // NOLINT(readability-redundant-member-init)
39           ListNode(),                  // NOLINT(readability-redundant-member-init)
40           method_(other.method_),
41           bytecodeOffset_(other.bytecodeOffset_)
42     {
43     }
44 
45     TestFrame &operator=(const TestFrame &other)
46     {
47         if (&other == this) {
48             return *this;
49         }
50 
51         debugger_ = nullptr;
52         method_ = other.method_;
53         bytecodeOffset_ = other.bytecodeOffset_;
54         notifyPop_ = false;
55         return *this;
56     }
57 
58     NO_MOVE_SEMANTIC(TestFrame);
59 
~TestFrame()60     ~TestFrame() override
61     {
62         if (notifyPop_) {
63             ASSERT(debugger_ != nullptr);
64             debugger_->GetHooks().FramePop(PtThread::NONE, method_, false);
65         }
66 
67         if (debugger_ != nullptr) {
68             debugger_->PopFrame();
69         }
70     }
71 
IsInterpreterFrame()72     bool IsInterpreterFrame() const override
73     {
74         return true;
75     }
76 
SetMethod(Method * method)77     void SetMethod(Method *method)
78     {
79         method_ = method;
80     }
81 
GetMethod()82     Method *GetMethod() const override
83     {
84         return method_;
85     }
86 
GetVReg(size_t)87     uint64_t GetVReg(size_t /* i */) const override
88     {
89         return 0;
90     }
91 
GetVRegNum()92     size_t GetVRegNum() const override
93     {
94         return 0;
95     }
96 
GetArgument(size_t)97     uint64_t GetArgument(size_t /* i */) const override
98     {
99         return 0;
100     }
101 
GetArgumentNum()102     size_t GetArgumentNum() const override
103     {
104         return 0;
105     }
106 
GetAccumulator()107     uint64_t GetAccumulator() const override
108     {
109         return 0;
110     }
111 
GetMethodId()112     panda_file::File::EntityId GetMethodId() const override
113     {
114         return method_->GetFileId();
115     }
116 
SetBytecodeOffset(uint32_t bytecodeOffset)117     void SetBytecodeOffset(uint32_t bytecodeOffset)
118     {
119         bytecodeOffset_ = bytecodeOffset;
120     }
121 
GetBytecodeOffset()122     uint32_t GetBytecodeOffset() const override
123     {
124         return bytecodeOffset_;
125     }
126 
GetPandaFile()127     std::string GetPandaFile() const override
128     {
129         return method_->GetPandaFile()->GetFilename();
130     }
131 
GetFrameId()132     uint32_t GetFrameId() const override
133     {
134         return reinterpret_cast<uintptr_t>(this);
135     }
136 
SetNotifyPop()137     void SetNotifyPop()
138     {
139         ASSERT(debugger_ != nullptr);
140         notifyPop_ = true;
141     }
142 
143 private:
144     TestDebugger *debugger_ {nullptr};
145     Method *method_ {nullptr};
146     uint32_t bytecodeOffset_ {0};
147     bool notifyPop_ {false};
148 };
149 }  // namespace panda::tooling::inspector::test
150 
151 #endif  // PANDA_TOOLING_INSPECTOR_TEST_TEST_FRAME_H
152