• 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_DEBUGGER_H
17 #define PANDA_TOOLING_INSPECTOR_TEST_TEST_DEBUGGER_H
18 
19 #include "macros.h"
20 #include "tooling/debugger.h"
21 #include "tooling/debug_interface.h"
22 #include "tooling/pt_location.h"
23 #include "utils/list.h"
24 
25 #include "gmock/gmock.h"
26 
27 #include <unordered_set>
28 
29 namespace panda::tooling::inspector::test {
30 class TestFrame;
31 
32 class TestDebugger : public DebugInterface {
33 public:
RegisterHooks(PtHooks * hooks)34     std::optional<Error> RegisterHooks(PtHooks *hooks) override
35     {
36         hooks_ = hooks;
37         return {};
38     }
UnregisterHooks()39     std::optional<Error> UnregisterHooks() override
40     {
41         hooks_ = nullptr;
42         return {};
43     }
GetHooks()44     PtHooks &GetHooks()
45     {
46         ASSERT(hooks_ != nullptr);
47         return *hooks_;
48     }
49 
50     void PushFrame(TestFrame &frame);
PopFrame()51     void PopFrame()
52     {
53         callStack_.PopFront();
54     }
55 
56     Expected<std::unique_ptr<PtFrame>, Error> GetCurrentFrame(PtThread thread) const override;
57     std::optional<Error> EnumerateFrames(PtThread thread, std::function<bool(const PtFrame &)> function) const override;
58     std::optional<Error> NotifyFramePop(PtThread thread, uint32_t frameDepth) const override;
59 
60     void HandleBreakpoint(const PtLocation &location) const;
61     std::optional<Error> SetBreakpoint(const PtLocation &location) override;
62     std::optional<Error> RemoveBreakpoint(const PtLocation &location) override;
63 
64     MOCK_METHOD(std::optional<Error>, EnableAllGlobalHook, (), (override));
65     MOCK_METHOD(std::optional<Error>, DisableAllGlobalHook, (), (override));
66     MOCK_METHOD(std::optional<Error>, SetNotification, (PtThread, bool, PtHookType), (override));
67     MOCK_METHOD(std::optional<Error>, SuspendThread, (PtThread), (const override));
68     MOCK_METHOD(std::optional<Error>, ResumeThread, (PtThread), (const override));
69     MOCK_METHOD(PtLangExt *, GetLangExtension, (), (const override));
70     MOCK_METHOD((Expected<PtMethod, Error>), GetPtMethod, (const PtLocation &), (const override));
71     MOCK_METHOD(std::optional<Error>, GetThreadList, (PandaVector<PtThread> *), (const override));
72     MOCK_METHOD(std::optional<Error>, SetVariable, (PtThread, uint32_t, int32_t, const PtValue &), (const override));
73     MOCK_METHOD(std::optional<Error>, GetVariable, (PtThread, uint32_t, int32_t, PtValue *), (const override));
74     MOCK_METHOD(std::optional<Error>, GetProperty, (PtObject, PtProperty, PtValue *), (const override));
75     MOCK_METHOD(std::optional<Error>, SetProperty, (PtObject, PtProperty, const PtValue &), (const override));
76     MOCK_METHOD(std::optional<Error>, EvaluateExpression, (PtThread, uint32_t, ExpressionWrapper, PtValue *),
77                 (const override));
78     MOCK_METHOD(std::optional<Error>, RetransformClasses, (int, const PtClass *), (const override));
79     MOCK_METHOD(std::optional<Error>, RedefineClasses, (int, const PandaClassDefinition *), (const override));
80     MOCK_METHOD(std::optional<Error>, GetThreadInfo, (PtThread, ThreadInfo *), (const override));
81     MOCK_METHOD(std::optional<Error>, RestartFrame, (PtThread, uint32_t), (const override));
82     MOCK_METHOD(std::optional<Error>, SetAsyncCallStackDepth, (uint32_t), (const override));
83     MOCK_METHOD(std::optional<Error>, AwaitPromise, (PtObject, PtValue *), (const override));
84     MOCK_METHOD(std::optional<Error>, CallFunctionOn, (PtObject, PtMethod, const PandaVector<PtValue> &, PtValue *),
85                 (const override));
86     MOCK_METHOD(std::optional<Error>, GetProperties, (uint32_t *, char ***), (const override));
87     MOCK_METHOD(std::optional<Error>, GetThisVariableByFrame, (PtThread, uint32_t, ObjectHeader **), (override));
88     MOCK_METHOD(std::optional<Error>, SetPropertyAccessWatch, (BaseClass *, PtProperty), (override));
89     MOCK_METHOD(std::optional<Error>, ClearPropertyAccessWatch, (BaseClass *, PtProperty), (override));
90     MOCK_METHOD(std::optional<Error>, SetPropertyModificationWatch, (BaseClass *, PtProperty), (override));
91     MOCK_METHOD(std::optional<Error>, ClearPropertyModificationWatch, (BaseClass *, PtProperty), (override));
92     MOCK_METHOD(std::optional<Error>, SetPropertyAccessWatch, (PtClass, PtProperty), (override));
93     MOCK_METHOD(std::optional<Error>, ClearPropertyAccessWatch, (PtClass, PtProperty), (override));
94     MOCK_METHOD(std::optional<Error>, SetPropertyModificationWatch, (PtClass, PtProperty), (override));
95     MOCK_METHOD(std::optional<Error>, GetThisVariableByFrame, (PtThread, uint32_t, PtValue *), (override));
96     MOCK_METHOD(std::optional<Error>, ClearPropertyModificationWatch, (PtClass, PtProperty), (override));
97 
98 private:
99     PtHooks *hooks_ {nullptr};
100     mutable List<TestFrame> callStack_;
101     std::unordered_set<PtLocation, HashLocation> breakpoints_;
102 };
103 }  // namespace panda::tooling::inspector::test
104 
105 #endif  // PANDA_TOOLING_INSPECTOR_TEST_TEST_DEBUGGER_H
106