OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 #include "debugger/core/debug_api_mock.h" | |
5 | |
6 #define DAPI_PROLOG(function) called_functions_.push_back(k##function) | |
7 #define CASE_NAME(x) case debug::DebugAPIMock::x: return #x | |
8 | |
9 namespace { | |
10 const char* GetNameOfDebugApiCall(debug::DebugAPIMock::FunctionId call_id) { | |
11 switch (call_id) { | |
12 CASE_NAME(kCreateProcess); | |
13 CASE_NAME(kCloseHandle); | |
14 CASE_NAME(kReadProcessMemory); | |
15 CASE_NAME(kWriteProcessMemory); | |
16 CASE_NAME(kFlushInstructionCache); | |
17 CASE_NAME(kGetThreadContext); | |
18 CASE_NAME(kSetThreadContext); | |
19 CASE_NAME(kWaitForDebugEvent); | |
20 CASE_NAME(kContinueDebugEvent); | |
21 CASE_NAME(kTerminateThread); | |
22 CASE_NAME(kDebugBreakProcess); | |
23 CASE_NAME(kWow64GetThreadContext); | |
24 CASE_NAME(kWow64SetThreadContext); | |
25 CASE_NAME(kIsWoW64Process); | |
26 CASE_NAME(kDebugActiveProcess); | |
27 CASE_NAME(kDebugActiveProcessStop); | |
28 } | |
29 return "N/A"; | |
30 } | |
31 } | |
32 | |
33 namespace debug { | |
34 DebugAPIMock::DebugAPIMock() | |
35 : single_step_enabled_(false) { | |
36 } | |
37 | |
38 void DebugAPIMock::ClearCallSequence() { | |
39 called_functions_.clear(); | |
40 } | |
41 | |
42 bool DebugAPIMock::CompareCallSequence( | |
43 const std::deque<FunctionId>& call_list) const { | |
44 bool equal = true; | |
45 | |
46 size_t num = called_functions_.size(); | |
47 if (call_list.size() != num) { | |
48 equal = false; | |
49 } | |
50 if (equal) { | |
51 for (size_t i = 0; i < num; i++) { | |
52 if (called_functions_[i] != call_list[i]) { | |
53 equal = false; | |
54 break; | |
55 } | |
56 } | |
57 } | |
58 if (!equal) { // Print out expected and actual call list. | |
59 printf("=== expected call list:\n"); | |
60 for (size_t i = 0; i < call_list.size(); i++) { | |
61 const char* call_name = GetNameOfDebugApiCall(call_list[i]); | |
62 printf("\t%s\n", call_name); | |
63 } | |
64 printf("=== actual call list:\n"); | |
65 for (size_t i = 0; i < called_functions_.size(); i++) { | |
66 const char* call_name = GetNameOfDebugApiCall(called_functions_[i]); | |
67 printf("\t%s\n", call_name); | |
68 } | |
69 } | |
70 return equal; | |
71 } | |
72 | |
73 BOOL DebugAPIMock::CreateProcess(LPCTSTR lpApplicationName, | |
74 LPTSTR lpCommandLine, | |
75 LPSECURITY_ATTRIBUTES lpProcessAttributes, | |
76 LPSECURITY_ATTRIBUTES lpThreadAttributes, | |
77 BOOL bInheritHandles, | |
78 DWORD dwCreationFlags, | |
79 LPVOID lpEnvironment, | |
80 LPCTSTR lpCurrentDirectory, | |
81 LPSTARTUPINFO lpStartupInfo, | |
82 LPPROCESS_INFORMATION lpProcessInformation) { | |
83 DAPI_PROLOG(CreateProcess); | |
84 return TRUE; | |
85 } | |
86 | |
87 BOOL DebugAPIMock::CloseHandle(HANDLE hObject) { | |
88 DAPI_PROLOG(CloseHandle); | |
89 return TRUE; | |
90 } | |
91 | |
92 BOOL DebugAPIMock::ReadProcessMemory(HANDLE hProcess, | |
93 LPCVOID lpBaseAddress, | |
94 LPVOID lpBuffer, | |
95 SIZE_T nSize, | |
96 SIZE_T *lpNumberOfBytesRead) { | |
97 DAPI_PROLOG(ReadProcessMemory); | |
98 return TRUE; | |
99 } | |
100 | |
101 BOOL DebugAPIMock::WriteProcessMemory(HANDLE hProcess, | |
102 LPVOID lpBaseAddress, | |
103 LPCVOID lpBuffer, | |
104 SIZE_T nSize, | |
105 SIZE_T *lpNumberOfBytesWritten) { | |
106 DAPI_PROLOG(WriteProcessMemory); | |
107 return TRUE; | |
108 } | |
109 | |
110 BOOL DebugAPIMock::FlushInstructionCache(HANDLE hProcess, | |
111 LPCVOID lpBaseAddress, | |
112 SIZE_T dwSize) { | |
113 DAPI_PROLOG(FlushInstructionCache); | |
114 return TRUE; | |
115 } | |
116 | |
117 BOOL DebugAPIMock::GetThreadContext(HANDLE hThread, LPCONTEXT lpContext) { | |
118 DAPI_PROLOG(GetThreadContext); | |
119 return TRUE; | |
120 } | |
121 | |
122 BOOL DebugAPIMock::SetThreadContext(HANDLE hThread, CONTEXT *lpContext) { | |
123 DAPI_PROLOG(SetThreadContext); | |
124 single_step_enabled_ = (lpContext->EFlags & (1 << 8)) > 0; | |
125 return TRUE; | |
126 } | |
127 | |
128 BOOL DebugAPIMock::WaitForDebugEvent(LPDEBUG_EVENT lpDebugEvent, | |
129 DWORD dwMilliseconds) { | |
130 DAPI_PROLOG(WaitForDebugEvent); | |
131 return FALSE; | |
132 } | |
133 | |
134 BOOL DebugAPIMock::ContinueDebugEvent(DWORD dwProcessId, | |
135 DWORD dwThreadId, | |
136 DWORD dwContinueStatus) { | |
137 DAPI_PROLOG(ContinueDebugEvent); | |
138 return TRUE; | |
139 } | |
140 | |
141 BOOL DebugAPIMock::TerminateThread(HANDLE hThread, DWORD dwExitCode) { | |
142 DAPI_PROLOG(TerminateThread); | |
143 return TRUE; | |
144 } | |
145 | |
146 BOOL DebugAPIMock::DebugBreakProcess(HANDLE Process) { | |
147 DAPI_PROLOG(DebugBreakProcess); | |
148 return TRUE; | |
149 } | |
150 | |
151 BOOL DebugAPIMock::Wow64GetThreadContext(HANDLE hThread, | |
152 PWOW64_CONTEXT lpContext) { | |
153 DAPI_PROLOG(Wow64GetThreadContext); | |
154 return TRUE; | |
155 } | |
156 | |
157 BOOL DebugAPIMock::Wow64SetThreadContext(HANDLE hThread, | |
158 const WOW64_CONTEXT* lpContext) { | |
159 DAPI_PROLOG(Wow64SetThreadContext); | |
160 return TRUE; | |
161 } | |
162 | |
163 BOOL DebugAPIMock::IsWoW64Process(HANDLE hProcess, PBOOL Wow64Process) { | |
164 DAPI_PROLOG(IsWoW64Process); | |
165 return TRUE; | |
166 } | |
167 | |
168 BOOL DebugAPIMock::DebugActiveProcess(DWORD dwProcessId) { | |
169 DAPI_PROLOG(DebugActiveProcess); | |
170 return TRUE; | |
171 } | |
172 | |
173 BOOL DebugAPIMock::DebugActiveProcessStop(DWORD dwProcessId) { | |
174 DAPI_PROLOG(DebugActiveProcessStop); | |
175 return TRUE; | |
176 } | |
177 } // namespace debug | |
178 | |
OLD | NEW |