• 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_TEST_TEST_FRAME_H
17 #define PANDA_TOOLING_INSPECTOR_TEST_TEST_FRAME_H
18 
19 #include <cstddef>
20 #include <cstdint>
21 #include <vector>
22 
23 #include "include/method.h"
24 #include "include/tooling/debug_interface.h"
25 #include "include/tooling/pt_thread.h"
26 #include "macros.h"
27 #include "utils/list.h"
28 
29 // NOLINTBEGIN
30 
31 namespace ark::tooling::inspector::test {
32 class TestFrame : public PtFrame {
33 public:
TestFrame(Method * method,uint32_t bytecode_offset)34     explicit TestFrame(Method *method, uint32_t bytecode_offset) : method_(method), bytecode_offset_(bytecode_offset) {}
35 
~TestFrame()36     ~TestFrame() override {}
37 
IsInterpreterFrame()38     bool IsInterpreterFrame() const override
39     {
40         return true;
41     }
42 
SetMethod(Method * method)43     void SetMethod(Method *method)
44     {
45         method_ = method;
46     }
47 
GetMethod()48     Method *GetMethod() const override
49     {
50         return method_;
51     }
52 
SetVReg(size_t index,uint64_t value)53     void SetVReg(size_t index, uint64_t value)
54     {
55         if (vregs_.size() <= index) {
56             vregs_.resize(index + 1);
57         }
58         vregs_[index] = value;
59     }
60 
GetVReg(size_t index)61     uint64_t GetVReg(size_t index) const override
62     {
63         return vregs_[index];
64     }
65 
SetVRegKind(size_t index,RegisterKind value)66     void SetVRegKind(size_t index, RegisterKind value)
67     {
68         if (vreg_kinds_.size() <= index) {
69             vreg_kinds_.resize(index + 1);
70         }
71         vreg_kinds_[index] = value;
72     }
73 
GetVRegKind(size_t i)74     RegisterKind GetVRegKind(size_t i) const override
75     {
76         return vreg_kinds_[i];
77     }
78 
GetVRegNum()79     size_t GetVRegNum() const override
80     {
81         return vregs_.size();
82     }
83 
SetArgument(size_t index,uint64_t value)84     void SetArgument(size_t index, uint64_t value)
85     {
86         if (args_.size() <= index) {
87             args_.resize(index + 1);
88         }
89         args_[index] = value;
90     }
91 
GetArgument(size_t index)92     uint64_t GetArgument(size_t index) const override
93     {
94         return args_[index];
95     }
96 
SetArgumentKind(size_t index,RegisterKind value)97     void SetArgumentKind(size_t index, RegisterKind value)
98     {
99         if (arg_kinds_.size() <= index) {
100             arg_kinds_.resize(index + 1);
101         }
102         arg_kinds_[index] = value;
103     }
104 
GetArgumentKind(size_t i)105     RegisterKind GetArgumentKind(size_t i) const override
106     {
107         return arg_kinds_[i];
108     }
109 
GetArgumentNum()110     size_t GetArgumentNum() const override
111     {
112         return args_.size();
113     }
114 
SetAccumulator(uint64_t value)115     void SetAccumulator(uint64_t value)
116     {
117         acc_ = value;
118     }
119 
GetAccumulator()120     uint64_t GetAccumulator() const override
121     {
122         return acc_;
123     }
124 
GetAccumulatorKind()125     RegisterKind GetAccumulatorKind() const override
126     {
127         return acc_kind_;
128     }
129 
GetMethodId()130     panda_file::File::EntityId GetMethodId() const override
131     {
132         return method_->GetFileId();
133     }
134 
SetBytecodeOffset(uint32_t bytecode_offset)135     void SetBytecodeOffset(uint32_t bytecode_offset)
136     {
137         bytecode_offset_ = bytecode_offset;
138     }
139 
GetBytecodeOffset()140     uint32_t GetBytecodeOffset() const override
141     {
142         return bytecode_offset_;
143     }
144 
GetPandaFile()145     std::string GetPandaFile() const override
146     {
147         return method_->GetPandaFile()->GetFilename();
148     }
149 
GetFrameId()150     uint32_t GetFrameId() const override
151     {
152         return reinterpret_cast<uintptr_t>(this);
153     }
154 
155 private:
156     Method *method_ {nullptr};
157     uint32_t bytecode_offset_ {0};
158 
159     uint64_t acc_ {0};
160     std::vector<uint64_t> args_;
161     std::vector<uint64_t> vregs_;
162     PandaVector<RegisterKind> vreg_kinds_;
163     PandaVector<RegisterKind> arg_kinds_;
164     RegisterKind acc_kind_ {PtFrame::RegisterKind::PRIMITIVE};
165 };
166 }  // namespace ark::tooling::inspector::test
167 
168 // NOLINTEND
169 
170 #endif  // PANDA_TOOLING_INSPECTOR_TEST_TEST_FRAME_H
171