1 | /* $Id: DBGFInternal.h 45984 2013-05-11 12:46:30Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DBGF - Internal header file.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2013 Oracle Corporation
|
---|
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 |
|
---|
18 | #ifndef ___DBGFInternal_h
|
---|
19 | #define ___DBGFInternal_h
|
---|
20 |
|
---|
21 | #include <VBox/cdefs.h>
|
---|
22 | #include <VBox/types.h>
|
---|
23 | #include <iprt/semaphore.h>
|
---|
24 | #include <iprt/critsect.h>
|
---|
25 | #include <iprt/string.h>
|
---|
26 | #include <iprt/avl.h>
|
---|
27 | #include <iprt/dbg.h>
|
---|
28 | #include <VBox/vmm/dbgf.h>
|
---|
29 |
|
---|
30 |
|
---|
31 |
|
---|
32 | /** @defgroup grp_dbgf_int Internals
|
---|
33 | * @ingroup grp_dbgf
|
---|
34 | * @internal
|
---|
35 | * @{
|
---|
36 | */
|
---|
37 |
|
---|
38 |
|
---|
39 | /** VMM Debugger Command. */
|
---|
40 | typedef enum DBGFCMD
|
---|
41 | {
|
---|
42 | /** No command.
|
---|
43 | * This is assigned to the field by the emulation thread after
|
---|
44 | * a command has been completed. */
|
---|
45 | DBGFCMD_NO_COMMAND = 0,
|
---|
46 | /** Halt the VM. */
|
---|
47 | DBGFCMD_HALT,
|
---|
48 | /** Resume execution. */
|
---|
49 | DBGFCMD_GO,
|
---|
50 | /** Single step execution - stepping into calls. */
|
---|
51 | DBGFCMD_SINGLE_STEP,
|
---|
52 | /** Set a breakpoint. */
|
---|
53 | DBGFCMD_BREAKPOINT_SET,
|
---|
54 | /** Set a access breakpoint. */
|
---|
55 | DBGFCMD_BREAKPOINT_SET_ACCESS,
|
---|
56 | /** Set a REM breakpoint. */
|
---|
57 | DBGFCMD_BREAKPOINT_SET_REM,
|
---|
58 | /** Clear a breakpoint. */
|
---|
59 | DBGFCMD_BREAKPOINT_CLEAR,
|
---|
60 | /** Enable a breakpoint. */
|
---|
61 | DBGFCMD_BREAKPOINT_ENABLE,
|
---|
62 | /** Disable a breakpoint. */
|
---|
63 | DBGFCMD_BREAKPOINT_DISABLE,
|
---|
64 | /** List breakpoints. */
|
---|
65 | DBGFCMD_BREAKPOINT_LIST,
|
---|
66 |
|
---|
67 | /** Detaches the debugger.
|
---|
68 | * Disabling all breakpoints, watch points and the like. */
|
---|
69 | DBGFCMD_DETACH_DEBUGGER = 0x7ffffffe,
|
---|
70 | /** Detached the debugger.
|
---|
71 | * The isn't a command as such, it's just that it's necessary for the
|
---|
72 | * detaching protocol to be racefree. */
|
---|
73 | DBGFCMD_DETACHED_DEBUGGER = 0x7fffffff
|
---|
74 | } DBGFCMD;
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * VMM Debugger Command.
|
---|
78 | */
|
---|
79 | typedef union DBGFCMDDATA
|
---|
80 | {
|
---|
81 | uint32_t uDummy;
|
---|
82 | } DBGFCMDDATA;
|
---|
83 | /** Pointer to DBGF Command Data. */
|
---|
84 | typedef DBGFCMDDATA *PDBGFCMDDATA;
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Info type.
|
---|
88 | */
|
---|
89 | typedef enum DBGFINFOTYPE
|
---|
90 | {
|
---|
91 | /** Invalid. */
|
---|
92 | DBGFINFOTYPE_INVALID = 0,
|
---|
93 | /** Device owner. */
|
---|
94 | DBGFINFOTYPE_DEV,
|
---|
95 | /** Driver owner. */
|
---|
96 | DBGFINFOTYPE_DRV,
|
---|
97 | /** Internal owner. */
|
---|
98 | DBGFINFOTYPE_INT,
|
---|
99 | /** External owner. */
|
---|
100 | DBGFINFOTYPE_EXT
|
---|
101 | } DBGFINFOTYPE;
|
---|
102 |
|
---|
103 |
|
---|
104 | /** Pointer to info structure. */
|
---|
105 | typedef struct DBGFINFO *PDBGFINFO;
|
---|
106 |
|
---|
107 | #ifdef IN_RING3
|
---|
108 | /**
|
---|
109 | * Info structure.
|
---|
110 | */
|
---|
111 | typedef struct DBGFINFO
|
---|
112 | {
|
---|
113 | /** The flags. */
|
---|
114 | uint32_t fFlags;
|
---|
115 | /** Owner type. */
|
---|
116 | DBGFINFOTYPE enmType;
|
---|
117 | /** Per type data. */
|
---|
118 | union
|
---|
119 | {
|
---|
120 | /** DBGFINFOTYPE_DEV */
|
---|
121 | struct
|
---|
122 | {
|
---|
123 | /** Device info handler function. */
|
---|
124 | PFNDBGFHANDLERDEV pfnHandler;
|
---|
125 | /** The device instance. */
|
---|
126 | PPDMDEVINS pDevIns;
|
---|
127 | } Dev;
|
---|
128 |
|
---|
129 | /** DBGFINFOTYPE_DRV */
|
---|
130 | struct
|
---|
131 | {
|
---|
132 | /** Driver info handler function. */
|
---|
133 | PFNDBGFHANDLERDRV pfnHandler;
|
---|
134 | /** The driver instance. */
|
---|
135 | PPDMDRVINS pDrvIns;
|
---|
136 | } Drv;
|
---|
137 |
|
---|
138 | /** DBGFINFOTYPE_INT */
|
---|
139 | struct
|
---|
140 | {
|
---|
141 | /** Internal info handler function. */
|
---|
142 | PFNDBGFHANDLERINT pfnHandler;
|
---|
143 | } Int;
|
---|
144 |
|
---|
145 | /** DBGFINFOTYPE_EXT */
|
---|
146 | struct
|
---|
147 | {
|
---|
148 | /** External info handler function. */
|
---|
149 | PFNDBGFHANDLEREXT pfnHandler;
|
---|
150 | /** The user argument. */
|
---|
151 | void *pvUser;
|
---|
152 | } Ext;
|
---|
153 | } u;
|
---|
154 |
|
---|
155 | /** Pointer to the description. */
|
---|
156 | const char *pszDesc;
|
---|
157 | /** Pointer to the next info structure. */
|
---|
158 | PDBGFINFO pNext;
|
---|
159 | /** The identifier name length. */
|
---|
160 | size_t cchName;
|
---|
161 | /** The identifier name. (Extends 'beyond' the struct as usual.) */
|
---|
162 | char szName[1];
|
---|
163 | } DBGFINFO;
|
---|
164 | #endif /* IN_RING3 */
|
---|
165 |
|
---|
166 |
|
---|
167 | /**
|
---|
168 | * Guest OS digger instance.
|
---|
169 | */
|
---|
170 | typedef struct DBGFOS
|
---|
171 | {
|
---|
172 | /** Pointer to the registration record. */
|
---|
173 | PCDBGFOSREG pReg;
|
---|
174 | /** Pointer to the next OS we've registered. */
|
---|
175 | struct DBGFOS *pNext;
|
---|
176 | /** The instance data (variable size). */
|
---|
177 | uint8_t abData[16];
|
---|
178 | } DBGFOS;
|
---|
179 | /** Pointer to guest OS digger instance. */
|
---|
180 | typedef DBGFOS *PDBGFOS;
|
---|
181 | /** Pointer to const guest OS digger instance. */
|
---|
182 | typedef DBGFOS const *PCDBGFOS;
|
---|
183 |
|
---|
184 |
|
---|
185 | /**
|
---|
186 | * Converts a DBGF pointer into a VM pointer.
|
---|
187 | * @returns Pointer to the VM structure the CPUM is part of.
|
---|
188 | * @param pDBGF Pointer to DBGF instance data.
|
---|
189 | */
|
---|
190 | #define DBGF2VM(pDBGF) ( (PVM)((char*)pDBGF - pDBGF->offVM) )
|
---|
191 |
|
---|
192 |
|
---|
193 | /**
|
---|
194 | * DBGF Data (part of VM)
|
---|
195 | */
|
---|
196 | typedef struct DBGF
|
---|
197 | {
|
---|
198 | /** Offset to the VM structure. */
|
---|
199 | int32_t offVM;
|
---|
200 |
|
---|
201 | /** Debugger Attached flag.
|
---|
202 | * Set if a debugger is attached, elsewise it's clear.
|
---|
203 | */
|
---|
204 | bool volatile fAttached;
|
---|
205 |
|
---|
206 | /** Stopped in the Hypervisor.
|
---|
207 | * Set if we're stopped on a trace, breakpoint or assertion inside
|
---|
208 | * the hypervisor and have to restrict the available operations.
|
---|
209 | */
|
---|
210 | bool volatile fStoppedInHyper;
|
---|
211 |
|
---|
212 | /**
|
---|
213 | * Ping-Pong construct where the Ping side is the VMM and the Pong side
|
---|
214 | * the Debugger.
|
---|
215 | */
|
---|
216 | RTPINGPONG PingPong;
|
---|
217 |
|
---|
218 | /** The Event to the debugger.
|
---|
219 | * The VMM will ping the debugger when the event is ready. The event is
|
---|
220 | * either a response to a command or to a break/watch point issued
|
---|
221 | * previously.
|
---|
222 | */
|
---|
223 | DBGFEVENT DbgEvent;
|
---|
224 |
|
---|
225 | /** The Command to the VMM.
|
---|
226 | * Operated in an atomic fashion since the VMM will poll on this.
|
---|
227 | * This means that a the command data must be written before this member
|
---|
228 | * is set. The VMM will reset this member to the no-command state
|
---|
229 | * when it have processed it.
|
---|
230 | */
|
---|
231 | DBGFCMD volatile enmVMMCmd;
|
---|
232 | /** The Command data.
|
---|
233 | * Not all commands take data. */
|
---|
234 | DBGFCMDDATA VMMCmdData;
|
---|
235 |
|
---|
236 | /** Range tree containing the loaded symbols of the a VM.
|
---|
237 | * This tree will never have blind spots. */
|
---|
238 | R3PTRTYPE(AVLRGCPTRTREE) SymbolTree;
|
---|
239 | /** Symbol name space. */
|
---|
240 | R3PTRTYPE(PRTSTRSPACE) pSymbolSpace;
|
---|
241 | /** Indicates whether DBGFSym.cpp is initialized or not.
|
---|
242 | * This part is initialized in a lazy manner for performance reasons. */
|
---|
243 | bool fSymInited;
|
---|
244 | /** Alignment padding. */
|
---|
245 | uint32_t uAlignment0;
|
---|
246 |
|
---|
247 | /** The number of hardware breakpoints. */
|
---|
248 | uint32_t cHwBreakpoints;
|
---|
249 | /** The number of active breakpoints. */
|
---|
250 | uint32_t cBreakpoints;
|
---|
251 | /** Array of hardware breakpoints. (0..3)
|
---|
252 | * This is shared among all the CPUs because life is much simpler that way. */
|
---|
253 | DBGFBP aHwBreakpoints[4];
|
---|
254 | /** Array of int 3 and REM breakpoints. (4..)
|
---|
255 | * @remark This is currently a fixed size array for reasons of simplicity. */
|
---|
256 | DBGFBP aBreakpoints[32];
|
---|
257 | } DBGF;
|
---|
258 | /** Pointer to DBGF Data. */
|
---|
259 | typedef DBGF *PDBGF;
|
---|
260 |
|
---|
261 |
|
---|
262 | /** Converts a DBGFCPU pointer into a VM pointer. */
|
---|
263 | #define DBGFCPU_2_VM(pDbgfCpu) ((PVM)((uint8_t *)(pDbgfCpu) + (pDbgfCpu)->offVM))
|
---|
264 |
|
---|
265 | /**
|
---|
266 | * The per CPU data for DBGF.
|
---|
267 | */
|
---|
268 | typedef struct DBGFCPU
|
---|
269 | {
|
---|
270 | /** The offset into the VM structure.
|
---|
271 | * @see DBGFCPU_2_VM(). */
|
---|
272 | uint32_t offVM;
|
---|
273 |
|
---|
274 | /** Current active breakpoint (id).
|
---|
275 | * This is ~0U if not active. It is set when a execution engine
|
---|
276 | * encounters a breakpoint and returns VINF_EM_DBG_BREAKPOINT. This is
|
---|
277 | * currently not used for REM breakpoints because of the lazy coupling
|
---|
278 | * between VBox and REM. */
|
---|
279 | uint32_t iActiveBp;
|
---|
280 | /** Set if we're singlestepping in raw mode.
|
---|
281 | * This is checked and cleared in the \#DB handler. */
|
---|
282 | bool fSingleSteppingRaw;
|
---|
283 |
|
---|
284 | /** Padding the structure to 16 bytes. */
|
---|
285 | bool afReserved[7];
|
---|
286 | } DBGFCPU;
|
---|
287 | /** Pointer to DBGFCPU data. */
|
---|
288 | typedef DBGFCPU *PDBGFCPU;
|
---|
289 |
|
---|
290 |
|
---|
291 | /**
|
---|
292 | * The DBGF data kept in the UVM.
|
---|
293 | */
|
---|
294 | typedef struct DBGFUSERPERVM
|
---|
295 | {
|
---|
296 | /** The address space database lock. */
|
---|
297 | RTSEMRW hAsDbLock;
|
---|
298 | /** The address space handle database. (Protected by hAsDbLock.) */
|
---|
299 | R3PTRTYPE(AVLPVTREE) AsHandleTree;
|
---|
300 | /** The address space process id database. (Protected by hAsDbLock.) */
|
---|
301 | R3PTRTYPE(AVLU32TREE) AsPidTree;
|
---|
302 | /** The address space name database. (Protected by hAsDbLock.) */
|
---|
303 | R3PTRTYPE(RTSTRSPACE) AsNameSpace;
|
---|
304 | /** Special address space aliases. (Protected by hAsDbLock.) */
|
---|
305 | RTDBGAS volatile ahAsAliases[DBGF_AS_COUNT];
|
---|
306 | /** For lazily populating the aliased address spaces. */
|
---|
307 | bool volatile afAsAliasPopuplated[DBGF_AS_COUNT];
|
---|
308 | /** Alignment padding. */
|
---|
309 | bool afAlignment1[2];
|
---|
310 | /** Debug configuration. */
|
---|
311 | R3PTRTYPE(RTDBGCFG) hDbgCfg;
|
---|
312 |
|
---|
313 | /** The register database lock. */
|
---|
314 | RTSEMRW hRegDbLock;
|
---|
315 | /** String space for looking up registers. (Protected by hRegDbLock.) */
|
---|
316 | R3PTRTYPE(RTSTRSPACE) RegSpace;
|
---|
317 | /** String space holding the register sets. (Protected by hRegDbLock.) */
|
---|
318 | R3PTRTYPE(RTSTRSPACE) RegSetSpace;
|
---|
319 | /** The number of registers (aliases, sub-fields and the special CPU
|
---|
320 | * register aliases (eg AH) are not counted). */
|
---|
321 | uint32_t cRegs;
|
---|
322 | /** For early initialization by . */
|
---|
323 | bool volatile fRegDbInitialized;
|
---|
324 | /** Alignment padding. */
|
---|
325 | bool afAlignment2[3];
|
---|
326 |
|
---|
327 | /** The current Guest OS digger. */
|
---|
328 | R3PTRTYPE(PDBGFOS) pCurOS;
|
---|
329 | /** The head of the Guest OS digger instances. */
|
---|
330 | R3PTRTYPE(PDBGFOS) pOSHead;
|
---|
331 |
|
---|
332 | /** List of registered info handlers. */
|
---|
333 | R3PTRTYPE(PDBGFINFO) pInfoFirst;
|
---|
334 | /** Critical section protecting the above list. */
|
---|
335 | RTCRITSECT InfoCritSect;
|
---|
336 |
|
---|
337 | } DBGFUSERPERVM;
|
---|
338 |
|
---|
339 | /**
|
---|
340 | * The per-CPU DBGF data kept in the UVM.
|
---|
341 | */
|
---|
342 | typedef struct DBGFUSERPERVMCPU
|
---|
343 | {
|
---|
344 | /** The guest register set for this CPU. Can be NULL. */
|
---|
345 | R3PTRTYPE(struct DBGFREGSET *) pGuestRegSet;
|
---|
346 | /** The hypervisor register set for this CPU. Can be NULL. */
|
---|
347 | R3PTRTYPE(struct DBGFREGSET *) pHyperRegSet;
|
---|
348 | } DBGFUSERPERVMCPU;
|
---|
349 |
|
---|
350 |
|
---|
351 | int dbgfR3AsInit(PUVM pUVM);
|
---|
352 | void dbgfR3AsTerm(PUVM pUVM);
|
---|
353 | void dbgfR3AsRelocate(PUVM pUVM, RTGCUINTPTR offDelta);
|
---|
354 | int dbgfR3BpInit(PVM pVM);
|
---|
355 | int dbgfR3InfoInit(PUVM pUVM);
|
---|
356 | int dbgfR3InfoTerm(PUVM pUVM);
|
---|
357 | void dbgfR3OSTerm(PUVM pUVM);
|
---|
358 | int dbgfR3RegInit(PUVM pUVM);
|
---|
359 | void dbgfR3RegTerm(PUVM pUVM);
|
---|
360 | int dbgfR3SymInit(PVM pVM);
|
---|
361 | int dbgfR3SymTerm(PVM pVM);
|
---|
362 | int dbgfR3TraceInit(PVM pVM);
|
---|
363 | void dbgfR3TraceRelocate(PVM pVM);
|
---|
364 | void dbgfR3TraceTerm(PVM pVM);
|
---|
365 |
|
---|
366 |
|
---|
367 |
|
---|
368 | #ifdef IN_RING3
|
---|
369 |
|
---|
370 | #endif
|
---|
371 |
|
---|
372 | /** @} */
|
---|
373 |
|
---|
374 | #endif
|
---|