1 | /* $Id: DBGFInternal.h 19286 2009-05-01 12:41:07Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DBGF - Internal header file.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #ifndef ___DBGFInternal_h
|
---|
23 | #define ___DBGFInternal_h
|
---|
24 |
|
---|
25 | #include <VBox/cdefs.h>
|
---|
26 | #include <VBox/types.h>
|
---|
27 | #include <iprt/semaphore.h>
|
---|
28 | #include <iprt/critsect.h>
|
---|
29 | #include <iprt/string.h>
|
---|
30 | #include <iprt/avl.h>
|
---|
31 | #include <VBox/dbgf.h>
|
---|
32 |
|
---|
33 |
|
---|
34 |
|
---|
35 | /** @defgroup grp_dbgf_int Internals
|
---|
36 | * @ingroup grp_dbgf
|
---|
37 | * @internal
|
---|
38 | * @{
|
---|
39 | */
|
---|
40 |
|
---|
41 |
|
---|
42 | /** VMM Debugger Command. */
|
---|
43 | typedef enum DBGFCMD
|
---|
44 | {
|
---|
45 | /** No command.
|
---|
46 | * This is assigned to the field by the emulation thread after
|
---|
47 | * a command has been completed. */
|
---|
48 | DBGFCMD_NO_COMMAND = 0,
|
---|
49 | /** Halt the VM. */
|
---|
50 | DBGFCMD_HALT,
|
---|
51 | /** Resume execution. */
|
---|
52 | DBGFCMD_GO,
|
---|
53 | /** Single step execution - stepping into calls. */
|
---|
54 | DBGFCMD_SINGLE_STEP,
|
---|
55 | /** Set a breakpoint. */
|
---|
56 | DBGFCMD_BREAKPOINT_SET,
|
---|
57 | /** Set a access breakpoint. */
|
---|
58 | DBGFCMD_BREAKPOINT_SET_ACCESS,
|
---|
59 | /** Set a REM breakpoint. */
|
---|
60 | DBGFCMD_BREAKPOINT_SET_REM,
|
---|
61 | /** Clear a breakpoint. */
|
---|
62 | DBGFCMD_BREAKPOINT_CLEAR,
|
---|
63 | /** Enable a breakpoint. */
|
---|
64 | DBGFCMD_BREAKPOINT_ENABLE,
|
---|
65 | /** Disable a breakpoint. */
|
---|
66 | DBGFCMD_BREAKPOINT_DISABLE,
|
---|
67 | /** List breakpoints. */
|
---|
68 | DBGFCMD_BREAKPOINT_LIST,
|
---|
69 |
|
---|
70 | /** Detaches the debugger.
|
---|
71 | * Disabling all breakpoints, watch points and the like. */
|
---|
72 | DBGFCMD_DETACH_DEBUGGER = 0x7ffffffe,
|
---|
73 | /** Detached the debugger.
|
---|
74 | * The isn't a command as such, it's just that it's necessary for the
|
---|
75 | * detaching protocol to be racefree. */
|
---|
76 | DBGFCMD_DETACHED_DEBUGGER = 0x7fffffff
|
---|
77 | } DBGFCMD;
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * VMM Debugger Command.
|
---|
81 | */
|
---|
82 | typedef union DBGFCMDDATA
|
---|
83 | {
|
---|
84 | uint32_t uDummy;
|
---|
85 | } DBGFCMDDATA;
|
---|
86 | /** Pointer to DBGF Command Data. */
|
---|
87 | typedef DBGFCMDDATA *PDBGFCMDDATA;
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Info type.
|
---|
91 | */
|
---|
92 | typedef enum DBGFINFOTYPE
|
---|
93 | {
|
---|
94 | /** Invalid. */
|
---|
95 | DBGFINFOTYPE_INVALID = 0,
|
---|
96 | /** Device owner. */
|
---|
97 | DBGFINFOTYPE_DEV,
|
---|
98 | /** Driver owner. */
|
---|
99 | DBGFINFOTYPE_DRV,
|
---|
100 | /** Internal owner. */
|
---|
101 | DBGFINFOTYPE_INT,
|
---|
102 | /** External owner. */
|
---|
103 | DBGFINFOTYPE_EXT
|
---|
104 | } DBGFINFOTYPE;
|
---|
105 |
|
---|
106 |
|
---|
107 | /** Pointer to info structure. */
|
---|
108 | typedef struct DBGFINFO *PDBGFINFO;
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * Info structure.
|
---|
112 | */
|
---|
113 | typedef struct DBGFINFO
|
---|
114 | {
|
---|
115 | /** The flags. */
|
---|
116 | uint32_t fFlags;
|
---|
117 | /** Owner type. */
|
---|
118 | DBGFINFOTYPE enmType;
|
---|
119 | /** Per type data. */
|
---|
120 | union
|
---|
121 | {
|
---|
122 | /** DBGFINFOTYPE_DEV */
|
---|
123 | struct
|
---|
124 | {
|
---|
125 | /** Device info handler function. */
|
---|
126 | PFNDBGFHANDLERDEV pfnHandler;
|
---|
127 | /** The device instance. */
|
---|
128 | PPDMDEVINS pDevIns;
|
---|
129 | } Dev;
|
---|
130 |
|
---|
131 | /** DBGFINFOTYPE_DRV */
|
---|
132 | struct
|
---|
133 | {
|
---|
134 | /** Driver info handler function. */
|
---|
135 | PFNDBGFHANDLERDRV pfnHandler;
|
---|
136 | /** The driver instance. */
|
---|
137 | PPDMDRVINS pDrvIns;
|
---|
138 | } Drv;
|
---|
139 |
|
---|
140 | /** DBGFINFOTYPE_INT */
|
---|
141 | struct
|
---|
142 | {
|
---|
143 | /** Internal info handler function. */
|
---|
144 | PFNDBGFHANDLERINT pfnHandler;
|
---|
145 | } Int;
|
---|
146 |
|
---|
147 | /** DBGFINFOTYPE_EXT */
|
---|
148 | struct
|
---|
149 | {
|
---|
150 | /** External info handler function. */
|
---|
151 | PFNDBGFHANDLEREXT pfnHandler;
|
---|
152 | /** The user argument. */
|
---|
153 | void *pvUser;
|
---|
154 | } Ext;
|
---|
155 | } u;
|
---|
156 |
|
---|
157 | /** Pointer to the description. */
|
---|
158 | const char *pszDesc;
|
---|
159 | /** Pointer to the next info structure. */
|
---|
160 | PDBGFINFO pNext;
|
---|
161 | /** The identifier name length. */
|
---|
162 | size_t cchName;
|
---|
163 | /** The identifier name. (Extends 'beyond' the struct as usual.) */
|
---|
164 | char szName[1];
|
---|
165 | } DBGFINFO;
|
---|
166 |
|
---|
167 |
|
---|
168 | /**
|
---|
169 | * Guest OS digger instance.
|
---|
170 | */
|
---|
171 | typedef struct DBGFOS
|
---|
172 | {
|
---|
173 | /** Pointer to the registration record. */
|
---|
174 | PCDBGFOSREG pReg;
|
---|
175 | /** Pointer to the next OS we've registered. */
|
---|
176 | struct DBGFOS *pNext;
|
---|
177 | /** The instance data (variable size). */
|
---|
178 | uint8_t abData[16];
|
---|
179 | } DBGFOS;
|
---|
180 | /** Pointer to guest OS digger instance. */
|
---|
181 | typedef DBGFOS *PDBGFOS;
|
---|
182 | /** Pointer to const guest OS digger instance. */
|
---|
183 | typedef DBGFOS const *PCDBGFOS;
|
---|
184 |
|
---|
185 |
|
---|
186 | /**
|
---|
187 | * Converts a DBGF pointer into a VM pointer.
|
---|
188 | * @returns Pointer to the VM structure the CPUM is part of.
|
---|
189 | * @param pDBGF Pointer to DBGF instance data.
|
---|
190 | */
|
---|
191 | #define DBGF2VM(pDBGF) ( (PVM)((char*)pDBGF - pDBGF->offVM) )
|
---|
192 |
|
---|
193 |
|
---|
194 | /**
|
---|
195 | * DBGF Data (part of VM)
|
---|
196 | */
|
---|
197 | typedef struct DBGF
|
---|
198 | {
|
---|
199 | /** Offset to the VM structure. */
|
---|
200 | RTINT offVM;
|
---|
201 |
|
---|
202 | /** Debugger Attached flag.
|
---|
203 | * Set if a debugger is attached, elsewise it's clear.
|
---|
204 | */
|
---|
205 | bool volatile fAttached;
|
---|
206 |
|
---|
207 | /** Stopped in the Hypervisor.
|
---|
208 | * Set if we're stopped on a trace, breakpoint or assertion inside
|
---|
209 | * the hypervisor and have to restrict the available operations.
|
---|
210 | */
|
---|
211 | bool volatile fStoppedInHyper;
|
---|
212 |
|
---|
213 | /**
|
---|
214 | * Ping-Pong construct where the Ping side is the VMM and the Pong side
|
---|
215 | * the Debugger.
|
---|
216 | */
|
---|
217 | RTPINGPONG PingPong;
|
---|
218 |
|
---|
219 | /** The Event to the debugger.
|
---|
220 | * The VMM will ping the debugger when the event is ready. The event is
|
---|
221 | * either a response to a command or to a break/watch point issued
|
---|
222 | * previously.
|
---|
223 | */
|
---|
224 | DBGFEVENT DbgEvent;
|
---|
225 |
|
---|
226 | /** The Command to the VMM.
|
---|
227 | * Operated in an atomic fashion since the VMM will poll on this.
|
---|
228 | * This means that a the command data must be written before this member
|
---|
229 | * is set. The VMM will reset this member to the no-command state
|
---|
230 | * when it have processed it.
|
---|
231 | */
|
---|
232 | DBGFCMD volatile enmVMMCmd;
|
---|
233 | /** The Command data.
|
---|
234 | * Not all commands take data. */
|
---|
235 | DBGFCMDDATA VMMCmdData;
|
---|
236 |
|
---|
237 | /** List of registered info handlers. */
|
---|
238 | R3PTRTYPE(PDBGFINFO) pInfoFirst;
|
---|
239 | /** Critical section protecting the above list. */
|
---|
240 | RTCRITSECT InfoCritSect;
|
---|
241 |
|
---|
242 | /** Range tree containing the loaded symbols of the a VM.
|
---|
243 | * This tree will never have blind spots. */
|
---|
244 | R3PTRTYPE(AVLRGCPTRTREE) SymbolTree;
|
---|
245 | /** Symbol name space. */
|
---|
246 | R3PTRTYPE(PRTSTRSPACE) pSymbolSpace;
|
---|
247 | /** Indicates whether DBGFSym.cpp is initialized or not.
|
---|
248 | * This part is initialized in a lazy manner for performance reasons. */
|
---|
249 | bool fSymInited;
|
---|
250 | /** Alignment padding. */
|
---|
251 | RTUINT uAlignment0;
|
---|
252 |
|
---|
253 | /** The number of hardware breakpoints. */
|
---|
254 | RTUINT cHwBreakpoints;
|
---|
255 | /** The number of active breakpoints. */
|
---|
256 | RTUINT cBreakpoints;
|
---|
257 | /** Array of hardware breakpoints. (0..3)
|
---|
258 | * This is shared among all the CPUs because life is much simpler that way. */
|
---|
259 | DBGFBP aHwBreakpoints[4];
|
---|
260 | /** Array of int 3 and REM breakpoints. (4..)
|
---|
261 | * @remark This is currently a fixed size array for reasons of simplicity. */
|
---|
262 | DBGFBP aBreakpoints[32];
|
---|
263 |
|
---|
264 | /** The current Guest OS digger. */
|
---|
265 | R3PTRTYPE(PDBGFOS) pCurOS;
|
---|
266 | /** The head of the Guest OS digger instances. */
|
---|
267 | R3PTRTYPE(PDBGFOS) pOSHead;
|
---|
268 | } DBGF;
|
---|
269 | /** Pointer to DBGF Data. */
|
---|
270 | typedef DBGF *PDBGF;
|
---|
271 |
|
---|
272 |
|
---|
273 | /** Converts a DBGFCPU pointer into a VM pointer. */
|
---|
274 | #define DBGFCPU_2_VM(pDbgfCpu) ((PVM)((uint8_t *)(pDbgfCpu) + (pDbgfCpu)->offVM))
|
---|
275 |
|
---|
276 | /**
|
---|
277 | * The per CPU data for DBGF.
|
---|
278 | */
|
---|
279 | typedef struct DBGFCPU
|
---|
280 | {
|
---|
281 | /** The offset into the VM structure.
|
---|
282 | * @see DBGFCPU_2_VM(). */
|
---|
283 | uint32_t offVM;
|
---|
284 |
|
---|
285 | /** Current active breakpoint (id).
|
---|
286 | * This is ~0U if not active. It is set when a execution engine
|
---|
287 | * encounters a breakpoint and returns VINF_EM_DBG_BREAKPOINT. This is
|
---|
288 | * currently not used for REM breakpoints because of the lazy coupling
|
---|
289 | * between VBox and REM. */
|
---|
290 | uint32_t iActiveBp;
|
---|
291 | /** Set if we're singlestepping in raw mode.
|
---|
292 | * This is checked and cleared in the \#DB handler. */
|
---|
293 | bool fSingleSteppingRaw;
|
---|
294 |
|
---|
295 | /** Padding the structure to 16 bytes. */
|
---|
296 | uint8_t abReserved[3];
|
---|
297 | } DBGFCPU;
|
---|
298 | /** Pointer to DBGFCPU data. */
|
---|
299 | typedef DBGFCPU *PDBGFCPU;
|
---|
300 |
|
---|
301 |
|
---|
302 | extern int dbgfR3InfoInit(PVM pVM);
|
---|
303 | extern int dbgfR3InfoTerm(PVM pVM);
|
---|
304 | extern void dbgfR3OSTerm(PVM pVM);
|
---|
305 | extern int dbgfR3SymInit(PVM pVM);
|
---|
306 | extern int dbgfR3SymTerm(PVM pVM);
|
---|
307 | extern int dbgfR3BpInit(PVM pVM);
|
---|
308 |
|
---|
309 |
|
---|
310 |
|
---|
311 | #ifdef IN_RING3
|
---|
312 |
|
---|
313 | #endif
|
---|
314 |
|
---|
315 | /** @} */
|
---|
316 |
|
---|
317 | #endif
|
---|