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 #ifndef DEBUGGER_CORE_DEBUGGEE_IPROCESS_H_ | |
5 #define DEBUGGER_CORE_DEBUGGEE_IPROCESS_H_ | |
6 #include <windows.h> | |
7 #include <deque> | |
8 | |
9 /// \brief This namespace groups classes related to OOP (out-of-process) | |
10 /// Windows debugger. | |
11 namespace debug { | |
12 class Breakpoint; | |
13 class DebugAPI; | |
14 class DebuggeeThread; | |
15 class DebugEvent; | |
16 | |
17 /// This abstract class represents a process in debugged application. | |
18 /// Inherited by DebuggeeProcess and DebuggeeProcessMock classes. | |
19 | |
20 /// Class diagram (and more) is here: | |
21 /// https://docs.google.com/a/google.com/document/d/1lTN-IYqDd_oy9XQg9-zlNc_vbg-
qyr4q2MKNEjhSA84/edit?hl=en&authkey=CJyJlOgF# | |
22 class IDebuggeeProcess { | |
23 public: | |
24 enum State { | |
25 kRunning, // process is alive, event loop is running | |
26 kHalted, // process is alive, event loop is not running | |
27 kDead // process is deleted by OS | |
28 }; | |
29 | |
30 IDebuggeeProcess() {} | |
31 virtual ~IDebuggeeProcess() {} | |
32 | |
33 /// @return id of the process | |
34 virtual int id() const = 0; | |
35 | |
36 virtual State state() const = 0; | |
37 virtual DebugAPI& debug_api() = 0; | |
38 | |
39 virtual bool IsHalted() const = 0; | |
40 | |
41 /// @return reference to last received debug event | |
42 virtual const DebugEvent& last_debug_event() const = 0; | |
43 | |
44 /// @return address of memory region where nexe is loaded. | |
45 virtual void* nexe_mem_base() const = 0; | |
46 | |
47 virtual void set_nexe_mem_base(void* addr) = 0; | |
48 | |
49 /// @return code address of nexe _start() routine. | |
50 virtual void* nexe_entry_point() const = 0; | |
51 | |
52 virtual void set_nexe_entry_point(void* addr) = 0; | |
53 | |
54 /// @return word size of the debuggee process (32 or 64). | |
55 virtual int GetWordSizeInBits() = 0; | |
56 | |
57 /// @return true for WoW (windows-on-windows) processes - | |
58 /// i.e. 32-bit processes running on 64-bit windows. | |
59 virtual bool IsWoW() = 0; | |
60 | |
61 /// Allows process execution to continue (i.e. it calls | |
62 /// ContinueDebugEvent() for halted thread). | |
63 /// Shall be called only on halted process, and only from the thread that | |
64 /// started the debuggee. | |
65 virtual bool Continue() = 0; | |
66 | |
67 /// Allows process execution to continue. If thread was halted due | |
68 /// to exception, that exception is passed to the debugee thread. | |
69 /// Shall be called only on halted process, and only from the thread that | |
70 /// started the debuggee. | |
71 virtual bool ContinueAndPassExceptionToDebuggee() = 0; | |
72 | |
73 /// Cause halted thread to execute single CPU instruction. | |
74 /// Shall be called only on halted process, and only from the thread that | |
75 /// started the debuggee. | |
76 virtual bool SingleStep() = 0; | |
77 | |
78 /// Cause running process to break (calls | |
79 /// debug::DebugApi::DebugBreakProcess). | |
80 /// Shall not be called on halted process, and only from the thread that | |
81 /// started the debuggee. | |
82 virtual bool Break() = 0; | |
83 | |
84 /// Terminates all threads of the process. | |
85 /// Event loop should process exiting debug event before DebuggeeProcess | |
86 /// object gets into kDead state and can be safely deleted. | |
87 /// TODO(garianov): verify that |Kill| can be called from any thread. | |
88 virtual bool Kill() = 0; | |
89 | |
90 /// Detaches debugger fom the process. Process is not killed. | |
91 /// TODO(garianov): verify that |Detach| can be called from any thread. | |
92 virtual bool Detach() = 0; | |
93 | |
94 /// @return a pointer to the thread object, or NULL if there's | |
95 /// no thread with such |id|. | |
96 /// Thread object is owned by the process. | |
97 virtual DebuggeeThread* GetThread(int id) = 0; | |
98 | |
99 /// @return a poiner to the halted thread object, or NULL | |
100 /// if process is not halted. | |
101 /// Thread object is owned by the process. | |
102 virtual DebuggeeThread* GetHaltedThread() = 0; | |
103 | |
104 /// @return all thread ids. | |
105 virtual void GetThreadIds(std::deque<int>* threads) const = 0; | |
106 | |
107 /// Copies memory from debuggee process to debugger buffer. | |
108 /// Shall be called only on halted process. There's no harm though if you | |
109 /// call it on running process. | |
110 /// @param[in] addr address (in debugger address space) from where to read. | |
111 /// @param[in] size number of bytes to read. | |
112 /// @param[out] destination destination buffer (in debugger address space). | |
113 /// TODO(garianov): verify that |ReadMemory| can be called from any thread. | |
114 virtual bool ReadMemory(const void* addr, size_t size, void* destination) = 0; | |
115 | |
116 /// Copies memory from debugger to debuggee process. | |
117 /// Shall be called only on halted process. | |
118 /// @param[in] addr address (in debugger address space) where to write. | |
119 /// @param[in] size number of bytes to write. | |
120 /// @param[in] source address of source buffer. | |
121 /// TODO(garianov): verify that |WriteMemory| can be called from any thread. | |
122 virtual bool WriteMemory(const void* addr, | |
123 size_t size, | |
124 const void* source) = 0; | |
125 | |
126 /// Sets breakpoint at specified address |addr|. | |
127 /// Shall be called only on halted process. | |
128 /// Note: for NaCl threads, breakpoints are supported only in nexe code, | |
129 /// i.e. breakpoints in TCB won't work. | |
130 /// TODO(garianov): add support for breakpoints in TCB. | |
131 /// @param[in] addr address where breakpoint shall be. | |
132 /// @return false if process is not able to access memory at |addr|, | |
133 /// or process is not halted, or if there is breakpoint with the same |addr|. | |
134 virtual bool SetBreakpoint(void* addr) = 0; | |
135 | |
136 /// Removes breakpoint at specified address |addr|. | |
137 /// Shall be called only on halted process. | |
138 /// @param[in] addr address of breakpoint. | |
139 /// @return false if process is not halted. | |
140 virtual bool RemoveBreakpoint(void* addr) = 0; | |
141 | |
142 /// @return breakpoint object, or NULL if there's no breakpoint | |
143 /// set at |addr|. | |
144 /// @param[in] addr address of breakpoint. | |
145 virtual Breakpoint* GetBreakpoint(void* addr) = 0; | |
146 | |
147 /// Return all breakpoints. | |
148 /// @param[out] breakpoints | |
149 virtual void GetBreakpoints(std::deque<Breakpoint*>* breakpoints) = 0; | |
150 | |
151 /// Converts relative pointer to flat(aka linear) process address. | |
152 /// Calling this function makes sense only for nexe threads, | |
153 /// it's safe to call for any thread. | |
154 /// @param[in] ptr relative pointer | |
155 /// @return flat address | |
156 virtual void* FromNexeToFlatAddress(void* ptr) const = 0; | |
157 | |
158 private: | |
159 friend class ExecutionEngine; | |
160 | |
161 /// Handler of debug events. | |
162 /// @param[in] debug_event debug event received from debuggee process | |
163 virtual void OnDebugEvent(DebugEvent* debug_event) = 0; | |
164 | |
165 IDebuggeeProcess(const IDebuggeeProcess&); // DISALLOW_COPY_AND_ASSIGN | |
166 void operator=(const IDebuggeeProcess&); | |
167 }; | |
168 } // namespace debug | |
169 #endif // DEBUGGER_CORE_DEBUGGEE_IPROCESS_H_ | |
170 | |
OLD | NEW |