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.h" | |
5 #include "debugger/core/debug_logger.h" | |
6 | |
7 namespace debug { | |
8 BOOL DebugAPI::CreateProcess( | |
9 LPCTSTR lpApplicationName, | |
10 LPTSTR lpCommandLine, | |
11 LPSECURITY_ATTRIBUTES lpProcessAttributes, | |
12 LPSECURITY_ATTRIBUTES lpThreadAttributes, | |
13 BOOL bInheritHandles, | |
14 DWORD dwCreationFlags, | |
15 LPVOID lpEnvironment, | |
16 LPCTSTR lpCurrentDirectory, | |
17 LPSTARTUPINFO lpStartupInfo, | |
18 LPPROCESS_INFORMATION lpProcessInformation) { | |
19 return ::CreateProcess(lpApplicationName, | |
20 lpCommandLine, | |
21 lpProcessAttributes, | |
22 lpThreadAttributes, | |
23 bInheritHandles, | |
24 dwCreationFlags, | |
25 lpEnvironment, | |
26 lpCurrentDirectory, | |
27 lpStartupInfo, | |
28 lpProcessInformation); | |
29 } | |
30 | |
31 BOOL DebugAPI::CloseHandle(HANDLE hObject) { | |
32 return ::CloseHandle(hObject); | |
33 } | |
34 | |
35 BOOL DebugAPI::ReadProcessMemory(HANDLE hProcess, | |
36 LPCVOID lpBaseAddress, | |
37 LPVOID lpBuffer, | |
38 SIZE_T nSize, | |
39 SIZE_T *lpNumberOfBytesRead) { | |
40 int pid = ::GetProcessId(hProcess); | |
41 SIZE_T rd = 0; | |
42 BOOL res = ::ReadProcessMemory(hProcess, | |
43 lpBaseAddress, | |
44 lpBuffer, | |
45 nSize, | |
46 &rd); | |
47 if (TRUE != res) | |
48 DBG_LOG("ERR02.01", | |
49 "msg='::ReadProcessMemory(pid=%d addr=%p len=%d) -> error' rd=%d", | |
50 pid, | |
51 lpBaseAddress, | |
52 nSize, | |
53 rd); | |
54 if (NULL != lpNumberOfBytesRead) | |
55 *lpNumberOfBytesRead = rd; | |
56 return res; | |
57 } | |
58 | |
59 BOOL DebugAPI::WriteProcessMemory(HANDLE hProcess, | |
60 LPVOID lpBaseAddress, | |
61 LPCVOID lpBuffer, | |
62 SIZE_T nSize, | |
63 SIZE_T *lpNumberOfBytesWritten) { | |
64 return ::WriteProcessMemory(hProcess, | |
65 lpBaseAddress, | |
66 lpBuffer, | |
67 nSize, | |
68 lpNumberOfBytesWritten); | |
69 } | |
70 | |
71 BOOL DebugAPI::FlushInstructionCache(HANDLE hProcess, | |
72 LPCVOID lpBaseAddress, | |
73 SIZE_T dwSize) { | |
74 return ::FlushInstructionCache(hProcess, lpBaseAddress, dwSize); | |
75 } | |
76 | |
77 BOOL DebugAPI::GetThreadContext(HANDLE hThread, LPCONTEXT lpContext) { | |
78 return ::GetThreadContext(hThread, lpContext); | |
79 } | |
80 | |
81 BOOL DebugAPI::SetThreadContext(HANDLE hThread, CONTEXT *lpContext) { | |
82 return ::SetThreadContext(hThread, lpContext); | |
83 } | |
84 | |
85 BOOL DebugAPI::WaitForDebugEvent(LPDEBUG_EVENT lpDebugEvent, | |
86 DWORD dwMilliseconds) { | |
87 return ::WaitForDebugEvent(lpDebugEvent, dwMilliseconds); | |
88 } | |
89 | |
90 BOOL DebugAPI::ContinueDebugEvent(DWORD dwProcessId, | |
91 DWORD dwThreadId, | |
92 DWORD dwContinueStatus) { | |
93 BOOL res = ::ContinueDebugEvent(dwProcessId, dwThreadId, dwContinueStatus); | |
94 DBG_LOG("TR02.02", | |
95 "msg='::ContinueDebugEvent(dwProcessId=%d dwThreadId=%d" | |
96 " dwContinueStatus=0x%X) -> %s", | |
97 dwProcessId, | |
98 dwThreadId, | |
99 dwContinueStatus, | |
100 res ? "ok" : "error"); | |
101 return res; | |
102 } | |
103 | |
104 BOOL DebugAPI::TerminateThread(HANDLE hThread, DWORD dwExitCode) { | |
105 return ::TerminateThread(hThread, dwExitCode); | |
106 } | |
107 | |
108 BOOL DebugAPI::DebugBreakProcess(HANDLE Process) { | |
109 return ::DebugBreakProcess(Process); | |
110 } | |
111 | |
112 BOOL DebugAPI::Wow64GetThreadContext(HANDLE hThread, PWOW64_CONTEXT lpContext) { | |
113 return ::Wow64GetThreadContext(hThread, lpContext); | |
114 } | |
115 | |
116 BOOL DebugAPI::Wow64SetThreadContext(HANDLE hThread, | |
117 const WOW64_CONTEXT* lpContext) { | |
118 return ::Wow64SetThreadContext(hThread, lpContext); | |
119 } | |
120 | |
121 BOOL DebugAPI::IsWoW64Process(HANDLE hProcess, PBOOL Wow64Process) { | |
122 return ::IsWow64Process(hProcess, Wow64Process); | |
123 } | |
124 | |
125 BOOL DebugAPI::DebugActiveProcess(DWORD dwProcessId) { | |
126 return ::DebugActiveProcess(dwProcessId); | |
127 } | |
128 | |
129 BOOL DebugAPI::DebugActiveProcessStop(DWORD dwProcessId) { | |
130 return ::DebugActiveProcessStop(dwProcessId); | |
131 } | |
132 } // namespace debug | |
133 | |
OLD | NEW |