• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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_RUNTIME_TESTS_TOOLING_API_TEST_H
17 #define PANDA_RUNTIME_TESTS_TOOLING_API_TEST_H
18 
19 #include <utility>
20 #include "runtime/include/tooling/debug_interface.h"
21 
22 namespace panda::tooling::test {
23 using BreakpointCallback = std::function<bool(PtThread, Method *, const PtLocation &)>;
24 using LoadModuleCallback = std::function<bool(std::string_view)>;
25 using PausedCallback = std::function<bool(PauseReason)>;
26 using ExceptionCallback =
27     std::function<bool(PtThread, Method *, const PtLocation &, ObjectHeader *, Method *, const PtLocation &)>;
28 using ExceptionCatchCallback = std::function<bool(PtThread, Method *, const PtLocation &, ObjectHeader *)>;
29 using PropertyAccessCallback = std::function<bool(PtThread, Method *, const PtLocation &, ObjectHeader *, PtProperty)>;
30 using PropertyModificationCallback =
31     std::function<bool(PtThread, Method *, const PtLocation &, ObjectHeader *, PtProperty, VRegValue)>;
32 using FramePopCallback = std::function<bool(PtThread, Method *, bool)>;
33 using GarbageCollectionStartCallback = std::function<bool()>;
34 using GarbageCollectionFinishCallback = std::function<bool()>;
35 using ObjectAllocCallback = std::function<bool(BaseClass *, ObjectHeader *, PtThread, size_t)>;
36 using MethodEntryCallback = std::function<bool(PtThread, Method *)>;
37 using MethodExitCallback = std::function<bool(PtThread, Method *, bool, VRegValue)>;
38 using SingleStepCallback = std::function<bool(PtThread, Method *, const PtLocation &)>;
39 using ThreadStartCallback = std::function<bool(PtThread)>;
40 using ThreadEndCallback = std::function<bool(PtThread)>;
41 using VmStartCallback = std::function<bool()>;
42 using VmInitializationCallback = std::function<bool(PtThread)>;
43 using VmDeathCallback = std::function<bool()>;
44 using ExceptionRevokedCallback = std::function<bool(ExceptionWrapper, ExceptionID)>;
45 using ExecutionContextCreatedCallback = std::function<bool(ExecutionContextWrapper)>;
46 using ExecutionContextDestroyedCallback = std::function<bool(ExecutionContextWrapper)>;
47 using ExecutionContextsClearedCallback = std::function<bool()>;
48 using InspectRequestedCallback = std::function<bool(PtObject, PtObject)>;
49 using ClassLoadCallback = std::function<bool(PtThread, BaseClass *)>;
50 using ClassPrepareCallback = std::function<bool(PtThread, BaseClass *)>;
51 using MonitorWaitCallback = std::function<bool(PtThread, ObjectHeader *, int64_t)>;
52 using MonitorWaitedCallback = std::function<bool(PtThread, ObjectHeader *, bool)>;
53 using MonitorContendedEnterCallback = std::function<bool(PtThread, ObjectHeader *)>;
54 using MonitorContendedEnteredCallback = std::function<bool(PtThread, ObjectHeader *)>;
55 
56 using Scenario = std::function<bool()>;
57 
58 enum class DebugEvent {
59     BREAKPOINT,
60     LOAD_MODULE,
61     PAUSED,
62     EXCEPTION,
63     EXCEPTION_CATCH,
64     FIELD_ACCESS,
65     FIELD_MODIFICATION,
66     FRAME_POP,
67     GARBAGE_COLLECTIION_START,
68     GARBAGE_COLLECTIION_FINISH,
69     METHOD_ENTRY,
70     METHOD_EXIT,
71     SINGLE_STEP,
72     THREAD_START,
73     THREAD_END,
74     VM_START,
75     VM_INITIALIZATION,
76     VM_DEATH,
77     EXCEPTION_REVOKED,
78     EXECUTION_CONTEXT_CREATED,
79     EXECUTION_CONTEXT_DESTROYED,
80     EXECUTION_CONTEXT_CLEARED,
81     INSPECT_REQUESTED,
82     CLASS_LOAD,
83     CLASS_PREPARE,
84     MONITOR_WAIT,
85     MONITOR_WAITED,
86     MONITOR_CONTENDED_ENTER,
87     MONITOR_CONTENDED_ENTERED,
88     UNINITIALIZED
89 };
90 
91 std::ostream &operator<<(std::ostream &out, DebugEvent value);
92 
93 struct ApiTest {
94     BreakpointCallback breakpoint;
95     LoadModuleCallback load_module;
96     PausedCallback paused;
97     ExceptionCallback exception;
98     ExceptionCatchCallback exception_catch;
99     PropertyAccessCallback property_access;
100     PropertyModificationCallback property_modification;
101     FramePopCallback frame_pop;
102     GarbageCollectionStartCallback garbage_collection_start;
103     GarbageCollectionFinishCallback garbage_collection_finish;
104     ObjectAllocCallback object_alloc;
105     MethodEntryCallback method_entry;
106     MethodExitCallback method_exit;
107     SingleStepCallback single_step;
108     ThreadStartCallback thread_start;
109     ThreadEndCallback thread_end;
110     VmStartCallback vm_start;
111     VmInitializationCallback vm_init;
112     VmDeathCallback vm_death;
113     ExceptionRevokedCallback exception_revoked;
114     ExecutionContextCreatedCallback execution_context_created;
115     ExecutionContextDestroyedCallback execution_context_destroyed;
116     ExecutionContextsClearedCallback execution_context_cleared;
117     InspectRequestedCallback inspect_requested;
118     ClassLoadCallback class_load;
119     ClassPrepareCallback class_prepare;
120     MonitorWaitCallback monitor_wait;
121     MonitorWaitedCallback monitor_waited;
122     MonitorContendedEnterCallback monitor_contended_enter;
123     MonitorContendedEnteredCallback monitor_contended_entered;
124 
125     Scenario scenario;
126     DebugInterface *debug_interface {nullptr};
127     ApiTest();
128     virtual ~ApiTest() = default;
129 
130     virtual std::pair<const char *, const char *> GetEntryPoint() = 0;
131 };
132 }  // namespace panda::tooling::test
133 
134 #endif  // PANDA_RUNTIME_TESTS_TOOLING_API_TEST_H
135