VirtualBox

source: vbox/trunk/include/VBox/vmm/dbgf.h@ 87518

Last change on this file since 87518 was 87137, checked in by vboxsync, 4 years ago

VMM/DBGFR3FlowTrace: First commit of a new DBGF framework to collect guest state information during execution, allowing visualization of guest execution flow, bugref:8650 [doxygen]

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 133.1 KB
Line 
1/** @file
2 * DBGF - Debugger Facility.
3 */
4
5/*
6 * Copyright (C) 2006-2020 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef VBOX_INCLUDED_vmm_dbgf_h
27#define VBOX_INCLUDED_vmm_dbgf_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32#include <VBox/types.h>
33#include <VBox/log.h> /* LOG_ENABLED */
34#include <VBox/vmm/vmm.h>
35#include <VBox/vmm/dbgfsel.h>
36
37#include <iprt/stdarg.h>
38#include <iprt/dbg.h>
39
40RT_C_DECLS_BEGIN
41
42
43/** @defgroup grp_dbgf The Debugger Facility API
44 * @ingroup grp_vmm
45 * @{
46 */
47
48/** @defgroup grp_dbgf_r0 The R0 DBGF API
49 * @{
50 */
51VMMR0_INT_DECL(void) DBGFR0InitPerVMData(PGVM pGVM);
52VMMR0_INT_DECL(void) DBGFR0CleanupVM(PGVM pGVM);
53
54/**
55 * Request buffer for DBGFR0TracerCreateReqHandler / VMMR0_DO_DBGF_TRACER_CREATE.
56 * @see DBGFR0TracerCreateReqHandler.
57 */
58typedef struct DBGFTRACERCREATEREQ
59{
60 /** The header. */
61 SUPVMMR0REQHDR Hdr;
62 /** Out: Where to return the address of the ring-3 tracer instance. */
63 PDBGFTRACERINSR3 pTracerInsR3;
64
65 /** Number of bytes for the shared event ring buffer. */
66 uint32_t cbRingBuf;
67
68 /** Set if the raw-mode component is desired. */
69 bool fRCEnabled;
70 /** Explicit padding. */
71 bool afReserved[3];
72
73} DBGFTRACERCREATEREQ;
74/** Pointer to a DBGFR0TracerCreate / VMMR0_DO_DBGF_TRACER_CREATE request buffer. */
75typedef DBGFTRACERCREATEREQ *PDBGFTRACERCREATEREQ;
76
77VMMR0_INT_DECL(int) DBGFR0TracerCreateReqHandler(PGVM pGVM, PDBGFTRACERCREATEREQ pReq);
78
79#ifdef VBOX_WITH_LOTS_OF_DBGF_BPS
80/**
81 * Request buffer for DBGFR0BpInitReqHandler / VMMR0_DO_DBGF_BP_INIT.
82 * @see DBGFR0BpInitReqHandler.
83 */
84typedef struct DBGFBPINITREQ
85{
86 /** The header. */
87 SUPVMMR0REQHDR Hdr;
88 /** Out: Ring-3 pointer of the L1 lookup table on success. */
89 R3PTRTYPE(volatile uint32_t *) paBpLocL1R3;
90} DBGFBPINITREQ;
91/** Pointer to a DBGFR0BpInitReqHandler / VMMR0_DO_DBGF_BP_INIT request buffer. */
92typedef DBGFBPINITREQ *PDBGFBPINITREQ;
93
94VMMR0_INT_DECL(int) DBGFR0BpInitReqHandler(PGVM pGVM, PDBGFBPINITREQ pReq);
95
96/**
97 * Request buffer for DBGFR0BpOwnerInitReqHandler / VMMR0_DO_DBGF_BP_OWNER_INIT.
98 * @see DBGFR0BpOwnerInitReqHandler.
99 */
100typedef struct DBGFBPOWNERINITREQ
101{
102 /** The header. */
103 SUPVMMR0REQHDR Hdr;
104 /** Out: Ring-3 pointer of the breakpoint owner table on success. */
105 R3PTRTYPE(void *) paBpOwnerR3;
106} DBGFBPOWNERINITREQ;
107/** Pointer to a DBGFR0BpOwnerInitReqHandler / VMMR0_DO_DBGF_BP_INIT request buffer. */
108typedef DBGFBPOWNERINITREQ *PDBGFBPOWNERINITREQ;
109
110VMMR0_INT_DECL(int) DBGFR0BpOwnerInitReqHandler(PGVM pGVM, PDBGFBPOWNERINITREQ pReq);
111
112/**
113 * Request buffer for DBGFR0BpChunkAllocReqHandler / VMMR0_DO_DBGF_CHUNK_ALLOC.
114 * @see DBGFR0BpChunkAllocReqHandler.
115 */
116typedef struct DBGFBPCHUNKALLOCREQ
117{
118 /** The header. */
119 SUPVMMR0REQHDR Hdr;
120 /** Out: Ring-3 pointer of the chunk base on success. */
121 R3PTRTYPE(void *) pChunkBaseR3;
122
123 /** The chunk ID to allocate. */
124 uint32_t idChunk;
125} DBGFBPCHUNKALLOCREQ;
126/** Pointer to a DBGFR0BpChunkAllocReqHandler / VMMR0_DO_DBGF_CHUNK_ALLOC request buffer. */
127typedef DBGFBPCHUNKALLOCREQ *PDBGFBPCHUNKALLOCREQ;
128
129VMMR0_INT_DECL(int) DBGFR0BpChunkAllocReqHandler(PGVM pGVM, PDBGFBPCHUNKALLOCREQ pReq);
130
131/**
132 * Request buffer for DBGFR0BpL2TblChunkAllocReqHandler / VMMR0_DO_DBGF_L2_TBL_CHUNK_ALLOC.
133 * @see DBGFR0BpL2TblChunkAllocReqHandler.
134 */
135typedef struct DBGFBPL2TBLCHUNKALLOCREQ
136{
137 /** The header. */
138 SUPVMMR0REQHDR Hdr;
139 /** Out: Ring-3 pointer of the chunk base on success. */
140 R3PTRTYPE(void *) pChunkBaseR3;
141
142 /** The chunk ID to allocate. */
143 uint32_t idChunk;
144} DBGFBPL2TBLCHUNKALLOCREQ;
145/** Pointer to a DBGFR0BpChunkAllocReqHandler / VMMR0_DO_DBGF_L2_TBL_CHUNK_ALLOC request buffer. */
146typedef DBGFBPL2TBLCHUNKALLOCREQ *PDBGFBPL2TBLCHUNKALLOCREQ;
147
148VMMR0_INT_DECL(int) DBGFR0BpL2TblChunkAllocReqHandler(PGVM pGVM, PDBGFBPL2TBLCHUNKALLOCREQ pReq);
149#endif
150/** @} */
151
152
153#ifdef IN_RING3
154
155/**
156 * Mixed address.
157 */
158typedef struct DBGFADDRESS
159{
160 /** The flat address. */
161 RTGCUINTPTR FlatPtr;
162 /** The selector offset address. */
163 RTGCUINTPTR off;
164 /** The selector. DBGF_SEL_FLAT is a legal value. */
165 RTSEL Sel;
166 /** Flags describing further details about the address. */
167 uint16_t fFlags;
168} DBGFADDRESS;
169/** Pointer to a mixed address. */
170typedef DBGFADDRESS *PDBGFADDRESS;
171/** Pointer to a const mixed address. */
172typedef const DBGFADDRESS *PCDBGFADDRESS;
173
174/** @name DBGFADDRESS Flags.
175 * @{ */
176/** A 16:16 far address. */
177#define DBGFADDRESS_FLAGS_FAR16 0
178/** A 16:32 far address. */
179#define DBGFADDRESS_FLAGS_FAR32 1
180/** A 16:64 far address. */
181#define DBGFADDRESS_FLAGS_FAR64 2
182/** A flat address. */
183#define DBGFADDRESS_FLAGS_FLAT 3
184/** A physical address. */
185#define DBGFADDRESS_FLAGS_PHYS 4
186/** A ring-0 host address (internal use only). */
187#define DBGFADDRESS_FLAGS_RING0 5
188/** The address type mask. */
189#define DBGFADDRESS_FLAGS_TYPE_MASK 7
190
191/** Set if the address is valid. */
192#define DBGFADDRESS_FLAGS_VALID RT_BIT(3)
193
194/** Checks if the mixed address is flat or not. */
195#define DBGFADDRESS_IS_FLAT(pAddress) ( ((pAddress)->fFlags & DBGFADDRESS_FLAGS_TYPE_MASK) == DBGFADDRESS_FLAGS_FLAT )
196/** Checks if the mixed address is flat or not. */
197#define DBGFADDRESS_IS_PHYS(pAddress) ( ((pAddress)->fFlags & DBGFADDRESS_FLAGS_TYPE_MASK) == DBGFADDRESS_FLAGS_PHYS )
198/** Checks if the mixed address is far 16:16 or not. */
199#define DBGFADDRESS_IS_FAR16(pAddress) ( ((pAddress)->fFlags & DBGFADDRESS_FLAGS_TYPE_MASK) == DBGFADDRESS_FLAGS_FAR16 )
200/** Checks if the mixed address is far 16:32 or not. */
201#define DBGFADDRESS_IS_FAR32(pAddress) ( ((pAddress)->fFlags & DBGFADDRESS_FLAGS_TYPE_MASK) == DBGFADDRESS_FLAGS_FAR32 )
202/** Checks if the mixed address is far 16:64 or not. */
203#define DBGFADDRESS_IS_FAR64(pAddress) ( ((pAddress)->fFlags & DBGFADDRESS_FLAGS_TYPE_MASK) == DBGFADDRESS_FLAGS_FAR64 )
204/** Checks if the mixed address is any kind of far address. */
205#define DBGFADDRESS_IS_FAR(pAddress) ( ((pAddress)->fFlags & DBGFADDRESS_FLAGS_TYPE_MASK) <= DBGFADDRESS_FLAGS_FAR64 )
206/** Checks if the mixed address host context ring-0 (special). */
207#define DBGFADDRESS_IS_R0_HC(pAddress) ( ((pAddress)->fFlags & DBGFADDRESS_FLAGS_TYPE_MASK) == DBGFADDRESS_FLAGS_RING0 )
208/** Checks if the mixed address a virtual guest context address (incl HMA). */
209#define DBGFADDRESS_IS_VIRT_GC(pAddress) ( ((pAddress)->fFlags & DBGFADDRESS_FLAGS_TYPE_MASK) <= DBGFADDRESS_FLAGS_FLAT )
210/** Checks if the mixed address is valid. */
211#define DBGFADDRESS_IS_VALID(pAddress) RT_BOOL((pAddress)->fFlags & DBGFADDRESS_FLAGS_VALID)
212/** @} */
213
214VMMR3DECL(int) DBGFR3AddrFromSelOff(PUVM pUVM, VMCPUID idCpu, PDBGFADDRESS pAddress, RTSEL Sel, RTUINTPTR off);
215VMMR3DECL(int) DBGFR3AddrFromSelInfoOff(PUVM pUVM, PDBGFADDRESS pAddress, PCDBGFSELINFO pSelInfo, RTUINTPTR off);
216VMMR3DECL(PDBGFADDRESS) DBGFR3AddrFromFlat(PUVM pUVM, PDBGFADDRESS pAddress, RTGCUINTPTR FlatPtr);
217VMMR3DECL(PDBGFADDRESS) DBGFR3AddrFromPhys(PUVM pUVM, PDBGFADDRESS pAddress, RTGCPHYS PhysAddr);
218VMMR3_INT_DECL(PDBGFADDRESS) DBGFR3AddrFromHostR0(PDBGFADDRESS pAddress, RTR0UINTPTR R0Ptr);
219VMMR3DECL(bool) DBGFR3AddrIsValid(PUVM pUVM, PCDBGFADDRESS pAddress);
220VMMR3DECL(int) DBGFR3AddrToPhys(PUVM pUVM, VMCPUID idCpu, PCDBGFADDRESS pAddress, PRTGCPHYS pGCPhys);
221VMMR3DECL(int) DBGFR3AddrToHostPhys(PUVM pUVM, VMCPUID idCpu, PDBGFADDRESS pAddress, PRTHCPHYS pHCPhys);
222VMMR3DECL(int) DBGFR3AddrToVolatileR3Ptr(PUVM pUVM, VMCPUID idCpu, PDBGFADDRESS pAddress, bool fReadOnly, void **ppvR3Ptr);
223VMMR3DECL(PDBGFADDRESS) DBGFR3AddrAdd(PDBGFADDRESS pAddress, RTGCUINTPTR uAddend);
224VMMR3DECL(PDBGFADDRESS) DBGFR3AddrSub(PDBGFADDRESS pAddress, RTGCUINTPTR uSubtrahend);
225
226#endif /* IN_RING3 */
227
228
229
230/**
231 * VMM Debug Event Type.
232 */
233typedef enum DBGFEVENTTYPE
234{
235 /** Halt completed.
236 * This notifies that a halt command have been successfully completed.
237 */
238 DBGFEVENT_HALT_DONE = 0,
239 /** Detach completed.
240 * This notifies that the detach command have been successfully completed.
241 */
242 DBGFEVENT_DETACH_DONE,
243 /** The command from the debugger is not recognized.
244 * This means internal error or half implemented features.
245 */
246 DBGFEVENT_INVALID_COMMAND,
247
248 /** Fatal error.
249 * This notifies a fatal error in the VMM and that the debugger get's a
250 * chance to first hand information about the the problem.
251 */
252 DBGFEVENT_FATAL_ERROR,
253 /** Breakpoint Hit.
254 * This notifies that a breakpoint installed by the debugger was hit. The
255 * identifier of the breakpoint can be found in the DBGFEVENT::u::Bp::iBp member.
256 */
257 DBGFEVENT_BREAKPOINT,
258 /** I/O port breakpoint.
259 * @todo not yet implemented. */
260 DBGFEVENT_BREAKPOINT_IO,
261 /** MMIO breakpoint.
262 * @todo not yet implemented. */
263 DBGFEVENT_BREAKPOINT_MMIO,
264 /** Breakpoint Hit in the Hypervisor.
265 * This notifies that a breakpoint installed by the debugger was hit. The
266 * identifier of the breakpoint can be found in the DBGFEVENT::u::Bp::iBp member.
267 * @todo raw-mode: remove this
268 */
269 DBGFEVENT_BREAKPOINT_HYPER,
270 /** Assertion in the Hypervisor (breakpoint instruction).
271 * This notifies that a breakpoint instruction was hit in the hypervisor context.
272 */
273 DBGFEVENT_ASSERTION_HYPER,
274 /** Single Stepped.
275 * This notifies that a single step operation was completed.
276 */
277 DBGFEVENT_STEPPED,
278 /** Single Stepped.
279 * This notifies that a hypervisor single step operation was completed.
280 */
281 DBGFEVENT_STEPPED_HYPER,
282 /** The developer have used the DBGFSTOP macro or the PDMDeviceDBGFSTOP function
283 * to bring up the debugger at a specific place.
284 */
285 DBGFEVENT_DEV_STOP,
286 /** The VM is powering off.
287 * When this notification is received, the debugger thread should detach ASAP.
288 */
289 DBGFEVENT_POWERING_OFF,
290
291 /** Hardware Interrupt break.
292 * @todo not yet implemented. */
293 DBGFEVENT_INTERRUPT_HARDWARE,
294 /** Software Interrupt break.
295 * @todo not yet implemented. */
296 DBGFEVENT_INTERRUPT_SOFTWARE,
297
298 /** The first selectable event.
299 * Whether the debugger wants or doesn't want these events can be configured
300 * via DBGFR3xxx and queried via DBGFR3yyy. */
301 DBGFEVENT_FIRST_SELECTABLE,
302 /** Tripple fault. */
303 DBGFEVENT_TRIPLE_FAULT = DBGFEVENT_FIRST_SELECTABLE,
304
305 /** @name Exception events
306 * The exception events normally represents guest exceptions, but depending on
307 * the execution mode some virtualization exceptions may occure (no nested
308 * paging, raw-mode, ++). When necessary, we will request additional VM exits.
309 * @{ */
310 DBGFEVENT_XCPT_FIRST, /**< The first exception event. */
311 DBGFEVENT_XCPT_DE /**< 0x00 - \#DE - Fault - NoErr - Integer divide error (zero/overflow). */
312 = DBGFEVENT_XCPT_FIRST,
313 DBGFEVENT_XCPT_DB, /**< 0x01 - \#DB - trap/fault - NoErr - debug event. */
314 DBGFEVENT_XCPT_02, /**< 0x02 - Reserved for NMI, see interrupt events. */
315 DBGFEVENT_XCPT_BP, /**< 0x03 - \#BP - Trap - NoErr - Breakpoint, INT 3 instruction. */
316 DBGFEVENT_XCPT_OF, /**< 0x04 - \#OF - Trap - NoErr - Overflow, INTO instruction. */
317 DBGFEVENT_XCPT_BR, /**< 0x05 - \#BR - Fault - NoErr - BOUND Range Exceeded, BOUND instruction. */
318 DBGFEVENT_XCPT_UD, /**< 0x06 - \#UD - Fault - NoErr - Undefined(/Invalid) Opcode. */
319 DBGFEVENT_XCPT_NM, /**< 0x07 - \#NM - Fault - NoErr - Device not available, FP or (F)WAIT instruction. */
320 DBGFEVENT_XCPT_DF, /**< 0x08 - \#DF - Abort - Err=0 - Double fault. */
321 DBGFEVENT_XCPT_09, /**< 0x09 - Int9 - Fault - NoErr - Coprocessor Segment Overrun (obsolete). */
322 DBGFEVENT_XCPT_TS, /**< 0x0a - \#TS - Fault - ErrCd - Invalid TSS, Taskswitch or TSS access. */
323 DBGFEVENT_XCPT_NP, /**< 0x0b - \#NP - Fault - ErrCd - Segment not present. */
324 DBGFEVENT_XCPT_SS, /**< 0x0c - \#SS - Fault - ErrCd - Stack-Segment fault. */
325 DBGFEVENT_XCPT_GP, /**< 0x0d - \#GP - Fault - ErrCd - General protection fault. */
326 DBGFEVENT_XCPT_PF, /**< 0x0e - \#PF - Fault - ErrCd - Page fault. - interrupt gate!!! */
327 DBGFEVENT_XCPT_0f, /**< 0x0f - Rsvd - Resvd - Resvd - Intel Reserved. */
328 DBGFEVENT_XCPT_MF, /**< 0x10 - \#MF - Fault - NoErr - x86 FPU Floating-Point Error (Math fault), FP or (F)WAIT instruction. */
329 DBGFEVENT_XCPT_AC, /**< 0x11 - \#AC - Fault - Err=0 - Alignment Check. */
330 DBGFEVENT_XCPT_MC, /**< 0x12 - \#MC - Abort - NoErr - Machine Check. */
331 DBGFEVENT_XCPT_XF, /**< 0x13 - \#XF - Fault - NoErr - SIMD Floating-Point Exception. */
332 DBGFEVENT_XCPT_VE, /**< 0x14 - \#VE - Fault - Noerr - Virtualization exception. */
333 DBGFEVENT_XCPT_15, /**< 0x15 - Intel Reserved. */
334 DBGFEVENT_XCPT_16, /**< 0x16 - Intel Reserved. */
335 DBGFEVENT_XCPT_17, /**< 0x17 - Intel Reserved. */
336 DBGFEVENT_XCPT_18, /**< 0x18 - Intel Reserved. */
337 DBGFEVENT_XCPT_19, /**< 0x19 - Intel Reserved. */
338 DBGFEVENT_XCPT_1a, /**< 0x1a - Intel Reserved. */
339 DBGFEVENT_XCPT_1b, /**< 0x1b - Intel Reserved. */
340 DBGFEVENT_XCPT_1c, /**< 0x1c - Intel Reserved. */
341 DBGFEVENT_XCPT_1d, /**< 0x1d - Intel Reserved. */
342 DBGFEVENT_XCPT_SX, /**< 0x1e - \#SX - Fault - ErrCd - Security Exception. */
343 DBGFEVENT_XCPT_1f, /**< 0x1f - Intel Reserved. */
344 DBGFEVENT_XCPT_LAST /**< The last exception event. */
345 = DBGFEVENT_XCPT_1f,
346 /** @} */
347
348 /** @name Instruction events
349 * The instruction events exerts all possible effort to intercept the
350 * relevant instructions. However, in some execution modes we won't be able
351 * to catch them. So it goes.
352 * @{ */
353 DBGFEVENT_INSTR_FIRST, /**< The first VM instruction event. */
354 DBGFEVENT_INSTR_HALT /**< Instruction: HALT */
355 = DBGFEVENT_INSTR_FIRST,
356 DBGFEVENT_INSTR_MWAIT, /**< Instruction: MWAIT */
357 DBGFEVENT_INSTR_MONITOR, /**< Instruction: MONITOR */
358 DBGFEVENT_INSTR_CPUID, /**< Instruction: CPUID (missing stuff in raw-mode). */
359 DBGFEVENT_INSTR_INVD, /**< Instruction: INVD */
360 DBGFEVENT_INSTR_WBINVD, /**< Instruction: WBINVD */
361 DBGFEVENT_INSTR_INVLPG, /**< Instruction: INVLPG */
362 DBGFEVENT_INSTR_RDTSC, /**< Instruction: RDTSC */
363 DBGFEVENT_INSTR_RDTSCP, /**< Instruction: RDTSCP */
364 DBGFEVENT_INSTR_RDPMC, /**< Instruction: RDPMC */
365 DBGFEVENT_INSTR_RDMSR, /**< Instruction: RDMSR */
366 DBGFEVENT_INSTR_WRMSR, /**< Instruction: WRMSR */
367 DBGFEVENT_INSTR_CRX_READ, /**< Instruction: CRx read instruction (missing smsw in raw-mode, and reads in general in VT-x). */
368 DBGFEVENT_INSTR_CRX_WRITE, /**< Instruction: CRx write */
369 DBGFEVENT_INSTR_DRX_READ, /**< Instruction: DRx read */
370 DBGFEVENT_INSTR_DRX_WRITE, /**< Instruction: DRx write */
371 DBGFEVENT_INSTR_PAUSE, /**< Instruction: PAUSE instruction (not in raw-mode). */
372 DBGFEVENT_INSTR_XSETBV, /**< Instruction: XSETBV */
373 DBGFEVENT_INSTR_SIDT, /**< Instruction: SIDT */
374 DBGFEVENT_INSTR_LIDT, /**< Instruction: LIDT */
375 DBGFEVENT_INSTR_SGDT, /**< Instruction: SGDT */
376 DBGFEVENT_INSTR_LGDT, /**< Instruction: LGDT */
377 DBGFEVENT_INSTR_SLDT, /**< Instruction: SLDT */
378 DBGFEVENT_INSTR_LLDT, /**< Instruction: LLDT */
379 DBGFEVENT_INSTR_STR, /**< Instruction: STR */
380 DBGFEVENT_INSTR_LTR, /**< Instruction: LTR */
381 DBGFEVENT_INSTR_GETSEC, /**< Instruction: GETSEC */
382 DBGFEVENT_INSTR_RSM, /**< Instruction: RSM */
383 DBGFEVENT_INSTR_RDRAND, /**< Instruction: RDRAND */
384 DBGFEVENT_INSTR_RDSEED, /**< Instruction: RDSEED */
385 DBGFEVENT_INSTR_XSAVES, /**< Instruction: XSAVES */
386 DBGFEVENT_INSTR_XRSTORS, /**< Instruction: XRSTORS */
387 DBGFEVENT_INSTR_VMM_CALL, /**< Instruction: VMCALL (intel) or VMMCALL (AMD) */
388 DBGFEVENT_INSTR_LAST_COMMON /**< Instruction: the last common event. */
389 = DBGFEVENT_INSTR_VMM_CALL,
390 DBGFEVENT_INSTR_VMX_FIRST, /**< Instruction: VT-x - First. */
391 DBGFEVENT_INSTR_VMX_VMCLEAR /**< Instruction: VT-x VMCLEAR */
392 = DBGFEVENT_INSTR_VMX_FIRST,
393 DBGFEVENT_INSTR_VMX_VMLAUNCH, /**< Instruction: VT-x VMLAUNCH */
394 DBGFEVENT_INSTR_VMX_VMPTRLD, /**< Instruction: VT-x VMPTRLD */
395 DBGFEVENT_INSTR_VMX_VMPTRST, /**< Instruction: VT-x VMPTRST */
396 DBGFEVENT_INSTR_VMX_VMREAD, /**< Instruction: VT-x VMREAD */
397 DBGFEVENT_INSTR_VMX_VMRESUME, /**< Instruction: VT-x VMRESUME */
398 DBGFEVENT_INSTR_VMX_VMWRITE, /**< Instruction: VT-x VMWRITE */
399 DBGFEVENT_INSTR_VMX_VMXOFF, /**< Instruction: VT-x VMXOFF */
400 DBGFEVENT_INSTR_VMX_VMXON, /**< Instruction: VT-x VMXON */
401 DBGFEVENT_INSTR_VMX_VMFUNC, /**< Instruction: VT-x VMFUNC */
402 DBGFEVENT_INSTR_VMX_INVEPT, /**< Instruction: VT-x INVEPT */
403 DBGFEVENT_INSTR_VMX_INVVPID, /**< Instruction: VT-x INVVPID */
404 DBGFEVENT_INSTR_VMX_INVPCID, /**< Instruction: VT-x INVPCID */
405 DBGFEVENT_INSTR_VMX_LAST /**< Instruction: VT-x - Last. */
406 = DBGFEVENT_INSTR_VMX_INVPCID,
407 DBGFEVENT_INSTR_SVM_FIRST, /**< Instruction: AMD-V - first */
408 DBGFEVENT_INSTR_SVM_VMRUN /**< Instruction: AMD-V VMRUN */
409 = DBGFEVENT_INSTR_SVM_FIRST,
410 DBGFEVENT_INSTR_SVM_VMLOAD, /**< Instruction: AMD-V VMLOAD */
411 DBGFEVENT_INSTR_SVM_VMSAVE, /**< Instruction: AMD-V VMSAVE */
412 DBGFEVENT_INSTR_SVM_STGI, /**< Instruction: AMD-V STGI */
413 DBGFEVENT_INSTR_SVM_CLGI, /**< Instruction: AMD-V CLGI */
414 DBGFEVENT_INSTR_SVM_LAST /**< Instruction: The last ADM-V VM exit event. */
415 = DBGFEVENT_INSTR_SVM_CLGI,
416 DBGFEVENT_INSTR_LAST /**< Instruction: The last instruction event. */
417 = DBGFEVENT_INSTR_SVM_LAST,
418 /** @} */
419
420
421 /** @name VM exit events.
422 * VM exits events for VT-x and AMD-V execution mode. Many of the VM exits
423 * behind these events are also directly translated into instruction events, but
424 * the difference here is that the exit events will not try provoke the exits.
425 * @{ */
426 DBGFEVENT_EXIT_FIRST, /**< The first VM exit event. */
427 DBGFEVENT_EXIT_TASK_SWITCH /**< Exit: Task switch. */
428 = DBGFEVENT_EXIT_FIRST,
429 DBGFEVENT_EXIT_HALT, /**< Exit: HALT instruction. */
430 DBGFEVENT_EXIT_MWAIT, /**< Exit: MWAIT instruction. */
431 DBGFEVENT_EXIT_MONITOR, /**< Exit: MONITOR instruction. */
432 DBGFEVENT_EXIT_CPUID, /**< Exit: CPUID instruction (missing stuff in raw-mode). */
433 DBGFEVENT_EXIT_INVD, /**< Exit: INVD instruction. */
434 DBGFEVENT_EXIT_WBINVD, /**< Exit: WBINVD instruction. */
435 DBGFEVENT_EXIT_INVLPG, /**< Exit: INVLPG instruction. */
436 DBGFEVENT_EXIT_RDTSC, /**< Exit: RDTSC instruction. */
437 DBGFEVENT_EXIT_RDTSCP, /**< Exit: RDTSCP instruction. */
438 DBGFEVENT_EXIT_RDPMC, /**< Exit: RDPMC instruction. */
439 DBGFEVENT_EXIT_RDMSR, /**< Exit: RDMSR instruction. */
440 DBGFEVENT_EXIT_WRMSR, /**< Exit: WRMSR instruction. */
441 DBGFEVENT_EXIT_CRX_READ, /**< Exit: CRx read instruction (missing smsw in raw-mode, and reads in general in VT-x). */
442 DBGFEVENT_EXIT_CRX_WRITE, /**< Exit: CRx write instruction. */
443 DBGFEVENT_EXIT_DRX_READ, /**< Exit: DRx read instruction. */
444 DBGFEVENT_EXIT_DRX_WRITE, /**< Exit: DRx write instruction. */
445 DBGFEVENT_EXIT_PAUSE, /**< Exit: PAUSE instruction (not in raw-mode). */
446 DBGFEVENT_EXIT_XSETBV, /**< Exit: XSETBV instruction. */
447 DBGFEVENT_EXIT_SIDT, /**< Exit: SIDT instruction. */
448 DBGFEVENT_EXIT_LIDT, /**< Exit: LIDT instruction. */
449 DBGFEVENT_EXIT_SGDT, /**< Exit: SGDT instruction. */
450 DBGFEVENT_EXIT_LGDT, /**< Exit: LGDT instruction. */
451 DBGFEVENT_EXIT_SLDT, /**< Exit: SLDT instruction. */
452 DBGFEVENT_EXIT_LLDT, /**< Exit: LLDT instruction. */
453 DBGFEVENT_EXIT_STR, /**< Exit: STR instruction. */
454 DBGFEVENT_EXIT_LTR, /**< Exit: LTR instruction. */
455 DBGFEVENT_EXIT_GETSEC, /**< Exit: GETSEC instruction. */
456 DBGFEVENT_EXIT_RSM, /**< Exit: RSM instruction. */
457 DBGFEVENT_EXIT_RDRAND, /**< Exit: RDRAND instruction. */
458 DBGFEVENT_EXIT_RDSEED, /**< Exit: RDSEED instruction. */
459 DBGFEVENT_EXIT_XSAVES, /**< Exit: XSAVES instruction. */
460 DBGFEVENT_EXIT_XRSTORS, /**< Exit: XRSTORS instruction. */
461 DBGFEVENT_EXIT_VMM_CALL, /**< Exit: VMCALL (intel) or VMMCALL (AMD) instruction. */
462 DBGFEVENT_EXIT_LAST_COMMON /**< Exit: the last common event. */
463 = DBGFEVENT_EXIT_VMM_CALL,
464 DBGFEVENT_EXIT_VMX_FIRST, /**< Exit: VT-x - First. */
465 DBGFEVENT_EXIT_VMX_VMCLEAR /**< Exit: VT-x VMCLEAR instruction. */
466 = DBGFEVENT_EXIT_VMX_FIRST,
467 DBGFEVENT_EXIT_VMX_VMLAUNCH, /**< Exit: VT-x VMLAUNCH instruction. */
468 DBGFEVENT_EXIT_VMX_VMPTRLD, /**< Exit: VT-x VMPTRLD instruction. */
469 DBGFEVENT_EXIT_VMX_VMPTRST, /**< Exit: VT-x VMPTRST instruction. */
470 DBGFEVENT_EXIT_VMX_VMREAD, /**< Exit: VT-x VMREAD instruction. */
471 DBGFEVENT_EXIT_VMX_VMRESUME, /**< Exit: VT-x VMRESUME instruction. */
472 DBGFEVENT_EXIT_VMX_VMWRITE, /**< Exit: VT-x VMWRITE instruction. */
473 DBGFEVENT_EXIT_VMX_VMXOFF, /**< Exit: VT-x VMXOFF instruction. */
474 DBGFEVENT_EXIT_VMX_VMXON, /**< Exit: VT-x VMXON instruction. */
475 DBGFEVENT_EXIT_VMX_VMFUNC, /**< Exit: VT-x VMFUNC instruction. */
476 DBGFEVENT_EXIT_VMX_INVEPT, /**< Exit: VT-x INVEPT instruction. */
477 DBGFEVENT_EXIT_VMX_INVVPID, /**< Exit: VT-x INVVPID instruction. */
478 DBGFEVENT_EXIT_VMX_INVPCID, /**< Exit: VT-x INVPCID instruction. */
479 DBGFEVENT_EXIT_VMX_EPT_VIOLATION, /**< Exit: VT-x EPT violation. */
480 DBGFEVENT_EXIT_VMX_EPT_MISCONFIG, /**< Exit: VT-x EPT misconfiguration. */
481 DBGFEVENT_EXIT_VMX_VAPIC_ACCESS, /**< Exit: VT-x Virtual APIC page access. */
482 DBGFEVENT_EXIT_VMX_VAPIC_WRITE, /**< Exit: VT-x Virtual APIC write. */
483 DBGFEVENT_EXIT_VMX_LAST /**< Exit: VT-x - Last. */
484 = DBGFEVENT_EXIT_VMX_VAPIC_WRITE,
485 DBGFEVENT_EXIT_SVM_FIRST, /**< Exit: AMD-V - first */
486 DBGFEVENT_EXIT_SVM_VMRUN /**< Exit: AMD-V VMRUN instruction. */
487 = DBGFEVENT_EXIT_SVM_FIRST,
488 DBGFEVENT_EXIT_SVM_VMLOAD, /**< Exit: AMD-V VMLOAD instruction. */
489 DBGFEVENT_EXIT_SVM_VMSAVE, /**< Exit: AMD-V VMSAVE instruction. */
490 DBGFEVENT_EXIT_SVM_STGI, /**< Exit: AMD-V STGI instruction. */
491 DBGFEVENT_EXIT_SVM_CLGI, /**< Exit: AMD-V CLGI instruction. */
492 DBGFEVENT_EXIT_SVM_LAST /**< Exit: The last ADM-V VM exit event. */
493 = DBGFEVENT_EXIT_SVM_CLGI,
494 DBGFEVENT_EXIT_LAST /**< Exit: The last VM exit event. */
495 = DBGFEVENT_EXIT_SVM_LAST,
496 /** @} */
497
498
499 /** Access to an unassigned I/O port.
500 * @todo not yet implemented. */
501 DBGFEVENT_IOPORT_UNASSIGNED,
502 /** Access to an unused I/O port on a device.
503 * @todo not yet implemented. */
504 DBGFEVENT_IOPORT_UNUSED,
505 /** Unassigned memory event.
506 * @todo not yet implemented. */
507 DBGFEVENT_MEMORY_UNASSIGNED,
508 /** Attempt to write to unshadowed ROM.
509 * @todo not yet implemented. */
510 DBGFEVENT_MEMORY_ROM_WRITE,
511
512 /** Windows guest reported BSOD via hyperv MSRs. */
513 DBGFEVENT_BSOD_MSR,
514 /** Windows guest reported BSOD via EFI variables. */
515 DBGFEVENT_BSOD_EFI,
516 /** Windows guest reported BSOD via VMMDev. */
517 DBGFEVENT_BSOD_VMMDEV,
518
519 /** End of valid event values. */
520 DBGFEVENT_END,
521 /** The usual 32-bit hack. */
522 DBGFEVENT_32BIT_HACK = 0x7fffffff
523} DBGFEVENTTYPE;
524AssertCompile(DBGFEVENT_XCPT_LAST - DBGFEVENT_XCPT_FIRST == 0x1f);
525
526/**
527 * The context of an event.
528 */
529typedef enum DBGFEVENTCTX
530{
531 /** The usual invalid entry. */
532 DBGFEVENTCTX_INVALID = 0,
533 /** Raw mode. */
534 DBGFEVENTCTX_RAW,
535 /** Recompiled mode. */
536 DBGFEVENTCTX_REM,
537 /** VMX / AVT mode. */
538 DBGFEVENTCTX_HM,
539 /** Hypervisor context. */
540 DBGFEVENTCTX_HYPER,
541 /** Other mode */
542 DBGFEVENTCTX_OTHER,
543
544 /** The usual 32-bit hack */
545 DBGFEVENTCTX_32BIT_HACK = 0x7fffffff
546} DBGFEVENTCTX;
547
548/**
549 * VMM Debug Event.
550 */
551typedef struct DBGFEVENT
552{
553 /** Type. */
554 DBGFEVENTTYPE enmType;
555 /** Context */
556 DBGFEVENTCTX enmCtx;
557 /** The vCPU/EMT which generated the event. */
558 VMCPUID idCpu;
559 /** Reserved. */
560 uint32_t uReserved;
561 /** Type specific data. */
562 union
563 {
564 /** Fatal error details. */
565 struct
566 {
567 /** The GC return code. */
568 int rc;
569 } FatalError;
570
571 /** Source location. */
572 struct
573 {
574 /** File name. */
575 R3PTRTYPE(const char *) pszFile;
576 /** Function name. */
577 R3PTRTYPE(const char *) pszFunction;
578 /** Message. */
579 R3PTRTYPE(const char *) pszMessage;
580 /** Line number. */
581 unsigned uLine;
582 } Src;
583
584 /** Assertion messages. */
585 struct
586 {
587 /** The first message. */
588 R3PTRTYPE(const char *) pszMsg1;
589 /** The second message. */
590 R3PTRTYPE(const char *) pszMsg2;
591 } Assert;
592
593 /** Breakpoint. */
594 struct DBGFEVENTBP
595 {
596#ifndef VBOX_WITH_LOTS_OF_DBGF_BPS
597 /** The identifier of the breakpoint which was hit. */
598 RTUINT hBp;
599#else
600 /** The handle of the breakpoint which was hit. */
601 DBGFBP hBp;
602#endif
603 } Bp;
604
605 /** Generic debug event. */
606 struct DBGFEVENTGENERIC
607 {
608 /** Number of arguments. */
609 uint8_t cArgs;
610 /** Alignment padding. */
611 uint8_t uPadding[7];
612 /** Arguments. */
613 uint64_t auArgs[5];
614 } Generic;
615
616 /** Padding for ensuring that the structure is 8 byte aligned. */
617 uint64_t au64Padding[6];
618 } u;
619} DBGFEVENT;
620AssertCompileSizeAlignment(DBGFEVENT, 8);
621AssertCompileSize(DBGFEVENT, 64);
622/** Pointer to VMM Debug Event. */
623typedef DBGFEVENT *PDBGFEVENT;
624/** Pointer to const VMM Debug Event. */
625typedef const DBGFEVENT *PCDBGFEVENT;
626
627#ifdef IN_RING3 /* The event API only works in ring-3. */
628
629/** @def DBGFSTOP
630 * Stops the debugger raising a DBGFEVENT_DEVELOPER_STOP event.
631 *
632 * @returns VBox status code which must be propagated up to EM if not VINF_SUCCESS.
633 * @param pVM The cross context VM structure.
634 */
635# ifdef VBOX_STRICT
636# define DBGFSTOP(pVM) DBGFR3EventSrc(pVM, DBGFEVENT_DEV_STOP, __FILE__, __LINE__, __PRETTY_FUNCTION__, NULL)
637# else
638# define DBGFSTOP(pVM) VINF_SUCCESS
639# endif
640
641VMMR3_INT_DECL(int) DBGFR3Init(PVM pVM);
642VMMR3_INT_DECL(int) DBGFR3Term(PVM pVM);
643VMMR3DECL(void) DBGFR3TermUVM(PUVM pUVM);
644VMMR3_INT_DECL(void) DBGFR3PowerOff(PVM pVM);
645VMMR3_INT_DECL(void) DBGFR3Relocate(PVM pVM, RTGCINTPTR offDelta);
646
647VMMR3_INT_DECL(int) DBGFR3VMMForcedAction(PVM pVM, PVMCPU pVCpu);
648VMMR3_INT_DECL(VBOXSTRICTRC) DBGFR3EventHandlePending(PVM pVM, PVMCPU pVCpu);
649VMMR3DECL(int) DBGFR3Event(PVM pVM, DBGFEVENTTYPE enmEvent);
650VMMR3DECL(int) DBGFR3EventSrc(PVM pVM, DBGFEVENTTYPE enmEvent, const char *pszFile, unsigned uLine,
651 const char *pszFunction, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR_MAYBE_NULL(6, 7);
652VMMR3DECL(int) DBGFR3EventSrcV(PVM pVM, DBGFEVENTTYPE enmEvent, const char *pszFile, unsigned uLine,
653 const char *pszFunction, const char *pszFormat, va_list args) RT_IPRT_FORMAT_ATTR_MAYBE_NULL(6, 0);
654VMMR3_INT_DECL(int) DBGFR3EventAssertion(PVM pVM, DBGFEVENTTYPE enmEvent, const char *pszMsg1, const char *pszMsg2);
655VMMR3_INT_DECL(int) DBGFR3EventBreakpoint(PVM pVM, DBGFEVENTTYPE enmEvent);
656
657VMMR3_INT_DECL(int) DBGFR3PrgStep(PVMCPU pVCpu);
658
659VMMR3DECL(int) DBGFR3Attach(PUVM pUVM);
660VMMR3DECL(int) DBGFR3Detach(PUVM pUVM);
661VMMR3DECL(int) DBGFR3EventWait(PUVM pUVM, RTMSINTERVAL cMillies, PDBGFEVENT pEvent);
662VMMR3DECL(int) DBGFR3Halt(PUVM pUVM, VMCPUID idCpu);
663VMMR3DECL(bool) DBGFR3IsHalted(PUVM pUVM, VMCPUID idCpu);
664VMMR3DECL(int) DBGFR3QueryWaitable(PUVM pUVM);
665VMMR3DECL(int) DBGFR3Resume(PUVM pUVM, VMCPUID idCpu);
666VMMR3DECL(int) DBGFR3InjectNMI(PUVM pUVM, VMCPUID idCpu);
667VMMR3DECL(int) DBGFR3Step(PUVM pUVM, VMCPUID idCpu);
668VMMR3DECL(int) DBGFR3StepEx(PUVM pUVM, VMCPUID idCpu, uint32_t fFlags, PCDBGFADDRESS pStopPcAddr,
669 PCDBGFADDRESS pStopPopAddr, RTGCUINTPTR cbStopPop, uint32_t cMaxSteps);
670
671/** @name DBGF_STEP_F_XXX - Flags for DBGFR3StepEx.
672 *
673 * @note The stop filters are not applied to the starting instruction.
674 *
675 * @{ */
676/** Step into CALL, INT, SYSCALL and SYSENTER instructions. */
677#define DBGF_STEP_F_INTO RT_BIT_32(0)
678/** Step over CALL, INT, SYSCALL and SYSENTER instruction when considering
679 * what's "next". */
680#define DBGF_STEP_F_OVER RT_BIT_32(1)
681
682/** Stop on the next CALL, INT, SYSCALL, SYSENTER instruction. */
683#define DBGF_STEP_F_STOP_ON_CALL RT_BIT_32(8)
684/** Stop on the next RET, IRET, SYSRET, SYSEXIT instruction. */
685#define DBGF_STEP_F_STOP_ON_RET RT_BIT_32(9)
686/** Stop after the next RET, IRET, SYSRET, SYSEXIT instruction. */
687#define DBGF_STEP_F_STOP_AFTER_RET RT_BIT_32(10)
688/** Stop on the given address.
689 * The comparison will be made using effective (flat) addresses. */
690#define DBGF_STEP_F_STOP_ON_ADDRESS RT_BIT_32(11)
691/** Stop when the stack pointer pops to or past the given address.
692 * The comparison will be made using effective (flat) addresses. */
693#define DBGF_STEP_F_STOP_ON_STACK_POP RT_BIT_32(12)
694/** Mask of stop filter flags. */
695#define DBGF_STEP_F_STOP_FILTER_MASK UINT32_C(0x00001f00)
696
697/** Mask of valid flags. */
698#define DBGF_STEP_F_VALID_MASK UINT32_C(0x00001f03)
699/** @} */
700
701/**
702 * Event configuration array element, see DBGFR3EventConfigEx.
703 */
704typedef struct DBGFEVENTCONFIG
705{
706 /** The event to configure */
707 DBGFEVENTTYPE enmType;
708 /** The new state. */
709 bool fEnabled;
710 /** Unused. */
711 uint8_t abUnused[3];
712} DBGFEVENTCONFIG;
713/** Pointer to an event config. */
714typedef DBGFEVENTCONFIG *PDBGFEVENTCONFIG;
715/** Pointer to a const event config. */
716typedef const DBGFEVENTCONFIG *PCDBGFEVENTCONFIG;
717
718VMMR3DECL(int) DBGFR3EventConfigEx(PUVM pUVM, PCDBGFEVENTCONFIG paConfigs, size_t cConfigs);
719VMMR3DECL(int) DBGFR3EventConfig(PUVM pUVM, DBGFEVENTTYPE enmEvent, bool fEnabled);
720VMMR3DECL(bool) DBGFR3EventIsEnabled(PUVM pUVM, DBGFEVENTTYPE enmEvent);
721VMMR3DECL(int) DBGFR3EventQuery(PUVM pUVM, PDBGFEVENTCONFIG paConfigs, size_t cConfigs);
722
723/** @name DBGFINTERRUPTSTATE_XXX - interrupt break state.
724 * @{ */
725#define DBGFINTERRUPTSTATE_DISABLED 0
726#define DBGFINTERRUPTSTATE_ENABLED 1
727#define DBGFINTERRUPTSTATE_DONT_TOUCH 2
728/** @} */
729
730/**
731 * Interrupt break state configuration entry.
732 */
733typedef struct DBGFINTERRUPTCONFIG
734{
735 /** The interrupt number. */
736 uint8_t iInterrupt;
737 /** The hardware interrupt state (DBGFINTERRUPTSTATE_XXX). */
738 uint8_t enmHardState;
739 /** The software interrupt state (DBGFINTERRUPTSTATE_XXX). */
740 uint8_t enmSoftState;
741} DBGFINTERRUPTCONFIG;
742/** Pointer to an interrupt break state config entyr. */
743typedef DBGFINTERRUPTCONFIG *PDBGFINTERRUPTCONFIG;
744/** Pointer to a const interrupt break state config entyr. */
745typedef DBGFINTERRUPTCONFIG const *PCDBGFINTERRUPTCONFIG;
746
747VMMR3DECL(int) DBGFR3InterruptConfigEx(PUVM pUVM, PCDBGFINTERRUPTCONFIG paConfigs, size_t cConfigs);
748VMMR3DECL(int) DBGFR3InterruptHardwareConfig(PUVM pUVM, uint8_t iInterrupt, bool fEnabled);
749VMMR3DECL(int) DBGFR3InterruptSoftwareConfig(PUVM pUVM, uint8_t iInterrupt, bool fEnabled);
750VMMR3DECL(int) DBGFR3InterruptHardwareIsEnabled(PUVM pUVM, uint8_t iInterrupt);
751VMMR3DECL(int) DBGFR3InterruptSoftwareIsEnabled(PUVM pUVM, uint8_t iInterrupt);
752
753#endif /* IN_RING3 */
754
755/** @def DBGF_IS_EVENT_ENABLED
756 * Checks if a selectable debug event is enabled or not (fast).
757 *
758 * @returns true/false.
759 * @param a_pVM Pointer to the cross context VM structure.
760 * @param a_enmEvent The selectable event to check.
761 * @remarks Only for use internally in the VMM. Use DBGFR3EventIsEnabled elsewhere.
762 */
763#if defined(VBOX_STRICT) && defined(RT_COMPILER_SUPPORTS_LAMBDA)
764# define DBGF_IS_EVENT_ENABLED(a_pVM, a_enmEvent) \
765 ([](PVM a_pLambdaVM, DBGFEVENTTYPE a_enmLambdaEvent) -> bool { \
766 Assert( a_enmLambdaEvent >= DBGFEVENT_FIRST_SELECTABLE \
767 || a_enmLambdaEvent == DBGFEVENT_INTERRUPT_HARDWARE \
768 || a_enmLambdaEvent == DBGFEVENT_INTERRUPT_SOFTWARE); \
769 Assert(a_enmLambdaEvent < DBGFEVENT_END); \
770 return ASMBitTest(&a_pLambdaVM->dbgf.ro.bmSelectedEvents, a_enmLambdaEvent); \
771 }(a_pVM, a_enmEvent))
772#elif defined(VBOX_STRICT) && defined(__GNUC__)
773# define DBGF_IS_EVENT_ENABLED(a_pVM, a_enmEvent) \
774 __extension__ ({ \
775 Assert( (a_enmEvent) >= DBGFEVENT_FIRST_SELECTABLE \
776 || (a_enmEvent) == DBGFEVENT_INTERRUPT_HARDWARE \
777 || (a_enmEvent) == DBGFEVENT_INTERRUPT_SOFTWARE); \
778 Assert((a_enmEvent) < DBGFEVENT_END); \
779 ASMBitTest(&(a_pVM)->dbgf.ro.bmSelectedEvents, (a_enmEvent)); \
780 })
781#else
782# define DBGF_IS_EVENT_ENABLED(a_pVM, a_enmEvent) \
783 ASMBitTest(&(a_pVM)->dbgf.ro.bmSelectedEvents, (a_enmEvent))
784#endif
785
786
787/** @def DBGF_IS_HARDWARE_INT_ENABLED
788 * Checks if hardware interrupt interception is enabled or not for an interrupt.
789 *
790 * @returns true/false.
791 * @param a_pVM Pointer to the cross context VM structure.
792 * @param a_iInterrupt Interrupt to check.
793 * @remarks Only for use internally in the VMM. Use
794 * DBGFR3InterruptHardwareIsEnabled elsewhere.
795 */
796#define DBGF_IS_HARDWARE_INT_ENABLED(a_pVM, a_iInterrupt) \
797 ASMBitTest(&(a_pVM)->dbgf.ro.bmHardIntBreakpoints, (uint8_t)(a_iInterrupt))
798
799/** @def DBGF_IS_SOFTWARE_INT_ENABLED
800 * Checks if software interrupt interception is enabled or not for an interrupt.
801 *
802 * @returns true/false.
803 * @param a_pVM Pointer to the cross context VM structure.
804 * @param a_iInterrupt Interrupt to check.
805 * @remarks Only for use internally in the VMM. Use
806 * DBGFR3InterruptSoftwareIsEnabled elsewhere.
807 */
808#define DBGF_IS_SOFTWARE_INT_ENABLED(a_pVM, a_iInterrupt) \
809 ASMBitTest(&(a_pVM)->dbgf.ro.bmSoftIntBreakpoints, (uint8_t)(a_iInterrupt))
810
811
812
813/** Breakpoint type. */
814typedef enum DBGFBPTYPE
815{
816#ifndef VBOX_WITH_LOTS_OF_DBGF_BPS
817 /** Free breakpoint entry. */
818 DBGFBPTYPE_FREE = 0,
819#else
820 /** Invalid breakpoint type. */
821 DBGFBPTYPE_INVALID = 0,
822#endif
823 /** Debug register. */
824 DBGFBPTYPE_REG,
825 /** INT 3 instruction. */
826 DBGFBPTYPE_INT3,
827#ifndef VBOX_WITH_LOTS_OF_DBGF_BPS
828 /** Recompiler. */
829 DBGFBPTYPE_REM,
830#endif
831 /** Port I/O breakpoint. */
832 DBGFBPTYPE_PORT_IO,
833 /** Memory mapped I/O breakpoint. */
834 DBGFBPTYPE_MMIO,
835 /** ensure 32-bit size. */
836 DBGFBPTYPE_32BIT_HACK = 0x7fffffff
837} DBGFBPTYPE;
838
839
840/** @name DBGFBPIOACCESS_XXX - I/O (port + mmio) access types.
841 * @{ */
842/** Byte sized read accesses. */
843#define DBGFBPIOACCESS_READ_BYTE UINT32_C(0x00000001)
844/** Word sized accesses. */
845#define DBGFBPIOACCESS_READ_WORD UINT32_C(0x00000002)
846/** Double word sized accesses. */
847#define DBGFBPIOACCESS_READ_DWORD UINT32_C(0x00000004)
848/** Quad word sized accesses - not available for I/O ports. */
849#define DBGFBPIOACCESS_READ_QWORD UINT32_C(0x00000008)
850/** Other sized accesses - not available for I/O ports. */
851#define DBGFBPIOACCESS_READ_OTHER UINT32_C(0x00000010)
852/** Read mask. */
853#define DBGFBPIOACCESS_READ_MASK UINT32_C(0x0000001f)
854
855/** Byte sized write accesses. */
856#define DBGFBPIOACCESS_WRITE_BYTE UINT32_C(0x00000100)
857/** Word sized write accesses. */
858#define DBGFBPIOACCESS_WRITE_WORD UINT32_C(0x00000200)
859/** Double word sized write accesses. */
860#define DBGFBPIOACCESS_WRITE_DWORD UINT32_C(0x00000400)
861/** Quad word sized write accesses - not available for I/O ports. */
862#define DBGFBPIOACCESS_WRITE_QWORD UINT32_C(0x00000800)
863/** Other sized write accesses - not available for I/O ports. */
864#define DBGFBPIOACCESS_WRITE_OTHER UINT32_C(0x00001000)
865/** Write mask. */
866#define DBGFBPIOACCESS_WRITE_MASK UINT32_C(0x00001f00)
867
868/** All kind of access (read, write, all sizes). */
869#define DBGFBPIOACCESS_ALL UINT32_C(0x00001f1f)
870
871/** The acceptable mask for I/O ports. */
872#define DBGFBPIOACCESS_VALID_MASK_PORT_IO UINT32_C(0x00000303)
873/** The acceptable mask for MMIO. */
874#define DBGFBPIOACCESS_VALID_MASK_MMIO UINT32_C(0x00001f1f)
875/** @} */
876
877#if defined(VBOX_WITH_LOTS_OF_DBGF_BPS) || defined(DOXYGEN_RUNNING)
878/**
879 * The visible breakpoint state (read-only).
880 */
881typedef struct DBGFBPPUB
882{
883 /** The number of breakpoint hits. */
884 uint64_t cHits;
885 /** The hit number which starts to trigger the breakpoint. */
886 uint64_t iHitTrigger;
887 /** The hit number which stops triggering the breakpoint (disables it).
888 * Use ~(uint64_t)0 if it should never stop. */
889 uint64_t iHitDisable;
890 /** The breakpoint owner handle (a nil owner defers the breakpoint to the
891 * debugger). */
892 DBGFBPOWNER hOwner;
893 /** Breakpoint type and flags, see DBGFBPTYPE for type and DBGF_BP_F_XXX for flags.
894 * Needs to be smashed together to be able to stay in the size limits. */
895 uint32_t fFlagsAndType;
896
897 /** Union of type specific data. */
898 union
899 {
900 /** The flat GC address breakpoint address for REG and INT3 breakpoints. */
901 RTGCUINTPTR GCPtr;
902
903 /** Debug register data. */
904 struct DBGFBPREG
905 {
906 /** The flat GC address of the breakpoint. */
907 RTGCUINTPTR GCPtr;
908 /** The debug register number. */
909 uint8_t iReg;
910 /** The access type (one of the X86_DR7_RW_* value). */
911 uint8_t fType;
912 /** The access size. */
913 uint8_t cb;
914 } Reg;
915
916 /** INT3 breakpoint data. */
917 struct DBGFBPINT3
918 {
919 /** The flat GC address of the breakpoint. */
920 RTGCUINTPTR GCPtr;
921 /** The physical address of the breakpoint. */
922 RTGCPHYS PhysAddr;
923 /** The byte value we replaced by the INT 3 instruction. */
924 uint8_t bOrg;
925 } Int3;
926
927 /** I/O port breakpoint data. */
928 struct DBGFBPPORTIO
929 {
930 /** The first port. */
931 RTIOPORT uPort;
932 /** The number of ports. */
933 RTIOPORT cPorts;
934 /** Valid DBGFBPIOACCESS_XXX selection, max DWORD size. */
935 uint32_t fAccess;
936 } PortIo;
937
938 /** Memory mapped I/O breakpoint data. */
939 struct DBGFBPMMIO
940 {
941 /** The first MMIO address. */
942 RTGCPHYS PhysAddr;
943 /** The size of the MMIO range in bytes. */
944 uint32_t cb;
945 /** Valid DBGFBPIOACCESS_XXX selection, max QWORD size. */
946 uint32_t fAccess;
947 } Mmio;
948
949 /** Padding to the anticipated size. */
950 uint64_t u64Padding[2];
951 } u;
952} DBGFBPPUB;
953AssertCompileSize(DBGFBPPUB, 64 - 8);
954AssertCompileMembersAtSameOffset(DBGFBPPUB, u.GCPtr, DBGFBPPUB, u.Reg.GCPtr);
955AssertCompileMembersAtSameOffset(DBGFBPPUB, u.GCPtr, DBGFBPPUB, u.Int3.GCPtr);
956
957/** Pointer to the visible breakpoint state. */
958typedef DBGFBPPUB *PDBGFBPPUB;
959/** Pointer to a const visible breakpoint state. */
960typedef const DBGFBPPUB *PCDBGFBPPUB;
961
962/** Sets the DBGFPUB::fFlagsAndType member. */
963#define DBGF_BP_PUB_SET_FLAGS_AND_TYPE(a_enmType, a_fFlags) ((uint32_t)(a_enmType) | (a_fFlags))
964/** Returns the type of the DBGFPUB::fFlagsAndType member. */
965#define DBGF_BP_PUB_GET_TYPE(a_fFlagsAndType) ((DBGFBPTYPE)((a_fFlagsAndType) & (UINT32_C(0x7fffffff))))
966/** Returns the enabled status of DBGFPUB::fFlagsAndType member. */
967#define DBGF_BP_PUB_IS_ENABLED(a_fFlagsAndType) RT_BOOL((DBGFBPTYPE)((a_fFlagsAndType) & DBGF_BP_F_ENABLED))
968
969/** @name Possible DBGFBPPUB::fFlagsAndType flags.
970 * @{ */
971/** Default flags. */
972#define DBGF_BP_F_DEFAULT 0
973/** Flag whether the breakpoint is enabled currently. */
974#define DBGF_BP_F_ENABLED RT_BIT_32(31)
975/** @} */
976
977
978/**
979 * Breakpoint hit handler.
980 *
981 * @returns Strict VBox status code.
982 * @retval VINF_SUCCESS if the breakpoint was handled and guest execution can resume.
983 * @retval VINF_DBGF_BP_HALT if guest execution should be stopped and the debugger should be invoked.
984 * @retval VINF_DBGF_R3_BP_OWNER_DEFER return to ring-3 and invoke the owner callback there again.
985 *
986 * @param pVM The cross-context VM structure pointer.
987 * @param idCpu ID of the vCPU triggering the breakpoint.
988 * @param pvUserBp User argument of the set breakpoint.
989 * @param hBp The breakpoint handle.
990 * @param pBpPub Pointer to the readonly public state of the breakpoint.
991 *
992 * @remarks The handler is called on the EMT of vCPU triggering the breakpoint and no locks are held.
993 * @remarks Any status code returned other than the ones mentioned will send the VM straight into a
994 * guru meditation.
995 */
996typedef DECLCALLBACKTYPE(VBOXSTRICTRC, FNDBGFBPHIT,(PVM pVM, VMCPUID idCpu, void *pvUserBp, DBGFBP hBp, PCDBGFBPPUB pBpPub));
997/** Pointer to a FNDBGFBPHIT(). */
998typedef FNDBGFBPHIT *PFNDBGFBPHIT;
999
1000
1001#ifdef IN_RING3
1002/** @defgroup grp_dbgf_bp_r3 The DBGF Breakpoint Host Context Ring-3 API
1003 * @{ */
1004VMMR3DECL(int) DBGFR3BpOwnerCreate(PUVM pUVM, PFNDBGFBPHIT pfnBpHit, PDBGFBPOWNER phBpOwner);
1005VMMR3DECL(int) DBGFR3BpOwnerDestroy(PUVM pUVM, DBGFBPOWNER hBpOwner);
1006
1007VMMR3DECL(int) DBGFR3BpSetInt3(PUVM pUVM, VMCPUID idSrcCpu, PCDBGFADDRESS pAddress,
1008 uint64_t iHitTrigger, uint64_t iHitDisable, PDBGFBP phBp);
1009VMMR3DECL(int) DBGFR3BpSetInt3Ex(PUVM pUVM, DBGFBPOWNER hOwner, void *pvUser,
1010 VMCPUID idSrcCpu, PCDBGFADDRESS pAddress,
1011 uint64_t iHitTrigger, uint64_t iHitDisable, PDBGFBP phBp);
1012VMMR3DECL(int) DBGFR3BpSetReg(PUVM pUVM, PCDBGFADDRESS pAddress, uint64_t iHitTrigger,
1013 uint64_t iHitDisable, uint8_t fType, uint8_t cb, PDBGFBP phBp);
1014VMMR3DECL(int) DBGFR3BpSetRegEx(PUVM pUVM, DBGFBPOWNER hOwner, void *pvUser,
1015 PCDBGFADDRESS pAddress, uint64_t iHitTrigger, uint64_t iHitDisable,
1016 uint8_t fType, uint8_t cb, PDBGFBP phBp);
1017VMMR3DECL(int) DBGFR3BpSetREM(PUVM pUVM, PCDBGFADDRESS pAddress, uint64_t iHitTrigger,
1018 uint64_t iHitDisable, PDBGFBP phBp);
1019VMMR3DECL(int) DBGFR3BpSetPortIo(PUVM pUVM, RTIOPORT uPort, RTIOPORT cPorts, uint32_t fAccess,
1020 uint64_t iHitTrigger, uint64_t iHitDisable, PDBGFBP phBp);
1021VMMR3DECL(int) DBGFR3BpSetPortIoEx(PUVM pUVM, DBGFBPOWNER hOwner, void *pvUser,
1022 RTIOPORT uPort, RTIOPORT cPorts, uint32_t fAccess,
1023 uint64_t iHitTrigger, uint64_t iHitDisable, PDBGFBP phBp);
1024VMMR3DECL(int) DBGFR3BpSetMmio(PUVM pUVM, RTGCPHYS GCPhys, uint32_t cb, uint32_t fAccess,
1025 uint64_t iHitTrigger, uint64_t iHitDisable, PDBGFBP phBp);
1026VMMR3DECL(int) DBGFR3BpSetMmioEx(PUVM pUVM, DBGFBPOWNER hOwner, void *pvUser,
1027 RTGCPHYS GCPhys, uint32_t cb, uint32_t fAccess,
1028 uint64_t iHitTrigger, uint64_t iHitDisable, PDBGFBP phBp);
1029VMMR3DECL(int) DBGFR3BpClear(PUVM pUVM, DBGFBP hBp);
1030VMMR3DECL(int) DBGFR3BpEnable(PUVM pUVM, DBGFBP hBp);
1031VMMR3DECL(int) DBGFR3BpDisable(PUVM pUVM, DBGFBP hBp);
1032
1033/**
1034 * Breakpoint enumeration callback function.
1035 *
1036 * @returns VBox status code.
1037 * The enumeration stops on failure status and VINF_CALLBACK_RETURN.
1038 * @param pUVM The user mode VM handle.
1039 * @param pvUser The user argument.
1040 * @param hBp The breakpoint handle.
1041 * @param pBp Pointer to the public breakpoint information. (readonly)
1042 */
1043typedef DECLCALLBACKTYPE(int, FNDBGFBPENUM,(PUVM pUVM, void *pvUser, DBGFBP hBp, PCDBGFBPPUB pBpPub));
1044/** Pointer to a breakpoint enumeration callback function. */
1045typedef FNDBGFBPENUM *PFNDBGFBPENUM;
1046
1047VMMR3DECL(int) DBGFR3BpEnum(PUVM pUVM, PFNDBGFBPENUM pfnCallback, void *pvUser);
1048
1049VMMR3_INT_DECL(int) DBGFR3BpHit(PVM pVM, PVMCPU pVCpu);
1050/** @} */
1051#endif /* !IN_RING3 */
1052
1053
1054#if defined(IN_RING0) || defined(DOXYGEN_RUNNING)
1055/** @defgroup grp_dbgf_bp_r0 The DBGF Breakpoint Host Context Ring-0 API
1056 * @{ */
1057VMMR0_INT_DECL(void) DBGFR0InitPerVMData(PGVM pGVM);
1058VMMR0_INT_DECL(void) DBGFR0CleanupVM(PGVM pGVM);
1059
1060VMMR0_INT_DECL(int) DBGFR0BpOwnerSetUpContext(PGVM pGVM, DBGFBPOWNER hBpOwner, PFNDBGFBPHIT pfnBpHit);
1061VMMR0_INT_DECL(int) DBGFR0BpOwnerDestroyContext(PGVM pGVM, DBGFBPOWNER hBpOwner);
1062
1063VMMR0_INT_DECL(int) DBGFR0BpSetUpContext(PGVM pGVM, DBGFBP hBp, void *pvUser);
1064VMMR0_INT_DECL(int) DBGFR0BpDestroyContext(PGVM pGVM, DBGFBP hBp);
1065/** @} */
1066#endif /* IN_RING0 || DOXYGEN_RUNNING */
1067
1068#else /* !VBOX_WITH_LOTS_OF_DBGF_BPS */
1069/**
1070 * A Breakpoint.
1071 */
1072typedef struct DBGFBP
1073{
1074 /** The number of breakpoint hits. */
1075 uint64_t cHits;
1076 /** The hit number which starts to trigger the breakpoint. */
1077 uint64_t iHitTrigger;
1078 /** The hit number which stops triggering the breakpoint (disables it).
1079 * Use ~(uint64_t)0 if it should never stop. */
1080 uint64_t iHitDisable;
1081 /** The breakpoint id. */
1082 uint16_t iBp;
1083 /** The breakpoint status - enabled or disabled. */
1084 bool fEnabled;
1085 /** The breakpoint type. */
1086 DBGFBPTYPE enmType;
1087
1088 /** Union of type specific data. */
1089 union
1090 {
1091 /** The flat GC address breakpoint address for REG, INT3 and REM breakpoints. */
1092 RTGCUINTPTR GCPtr;
1093
1094 /** Debug register data. */
1095 struct DBGFBPREG
1096 {
1097 /** The flat GC address of the breakpoint. */
1098 RTGCUINTPTR GCPtr;
1099 /** The debug register number. */
1100 uint8_t iReg;
1101 /** The access type (one of the X86_DR7_RW_* value). */
1102 uint8_t fType;
1103 /** The access size. */
1104 uint8_t cb;
1105 } Reg;
1106
1107 /** INT3 breakpoint data. */
1108 struct DBGFBPINT3
1109 {
1110 /** The flat GC address of the breakpoint. */
1111 RTGCUINTPTR GCPtr;
1112 /** The physical address of the breakpoint. */
1113 RTGCPHYS PhysAddr;
1114 /** The byte value we replaced by the INT 3 instruction. */
1115 uint8_t bOrg;
1116 } Int3;
1117
1118 /** Recompiler breakpoint data. */
1119 struct DBGFBPREM
1120 {
1121 /** The flat GC address of the breakpoint.
1122 * (PC register value?) */
1123 RTGCUINTPTR GCPtr;
1124 } Rem;
1125
1126 /** I/O port breakpoint data. */
1127 struct DBGFBPPORTIO
1128 {
1129 /** The first port. */
1130 RTIOPORT uPort;
1131 /** The number of ports. */
1132 RTIOPORT cPorts;
1133 /** Valid DBGFBPIOACCESS_XXX selection, max DWORD size. */
1134 uint32_t fAccess;
1135 } PortIo;
1136
1137 /** Memory mapped I/O breakpoint data. */
1138 struct DBGFBPMMIO
1139 {
1140 /** The first MMIO address. */
1141 RTGCPHYS PhysAddr;
1142 /** The size of the MMIO range in bytes. */
1143 uint32_t cb;
1144 /** Valid DBGFBPIOACCESS_XXX selection, max DWORD size. */
1145 uint32_t fAccess;
1146 } Mmio;
1147
1148 /** Paddind to ensure that the size is identical on win32 and linux. */
1149 uint64_t u64Padding[3];
1150 } u;
1151} DBGFBP;
1152AssertCompileMembersAtSameOffset(DBGFBP, u.GCPtr, DBGFBP, u.Reg.GCPtr);
1153AssertCompileMembersAtSameOffset(DBGFBP, u.GCPtr, DBGFBP, u.Int3.GCPtr);
1154AssertCompileMembersAtSameOffset(DBGFBP, u.GCPtr, DBGFBP, u.Rem.GCPtr);
1155
1156/** Pointer to a breakpoint. */
1157typedef DBGFBP *PDBGFBP;
1158/** Pointer to a const breakpoint. */
1159typedef const DBGFBP *PCDBGFBP;
1160
1161# ifdef IN_RING3 /* The breakpoint management API is only available in ring-3. */
1162VMMR3DECL(int) DBGFR3BpSetInt3(PUVM pUVM, VMCPUID idSrcCpu, PCDBGFADDRESS pAddress, uint64_t iHitTrigger, uint64_t iHitDisable, uint32_t *piBp);
1163VMMR3DECL(int) DBGFR3BpSetReg(PUVM pUVM, PCDBGFADDRESS pAddress, uint64_t iHitTrigger, uint64_t iHitDisable,
1164 uint8_t fType, uint8_t cb, uint32_t *piBp);
1165VMMR3DECL(int) DBGFR3BpSetREM(PUVM pUVM, PCDBGFADDRESS pAddress, uint64_t iHitTrigger, uint64_t iHitDisable, uint32_t *piBp);
1166VMMR3DECL(int) DBGFR3BpSetPortIo(PUVM pUVM, RTIOPORT uPort, RTIOPORT cPorts, uint32_t fAccess,
1167 uint64_t iHitTrigger, uint64_t iHitDisable, uint32_t *piBp);
1168VMMR3DECL(int) DBGFR3BpSetMmio(PUVM pUVM, RTGCPHYS GCPhys, uint32_t cb, uint32_t fAccess,
1169 uint64_t iHitTrigger, uint64_t iHitDisable, uint32_t *piBp);
1170VMMR3DECL(int) DBGFR3BpClear(PUVM pUVM, uint32_t iBp);
1171VMMR3DECL(int) DBGFR3BpEnable(PUVM pUVM, uint32_t iBp);
1172VMMR3DECL(int) DBGFR3BpDisable(PUVM pUVM, uint32_t iBp);
1173
1174/**
1175 * Breakpoint enumeration callback function.
1176 *
1177 * @returns VBox status code.
1178 * The enumeration stops on failure status and VINF_CALLBACK_RETURN.
1179 * @param pUVM The user mode VM handle.
1180 * @param pvUser The user argument.
1181 * @param pBp Pointer to the breakpoint information. (readonly)
1182 */
1183typedef DECLCALLBACKTYPE(int, FNDBGFBPENUM,(PUVM pUVM, void *pvUser, PCDBGFBP pBp));
1184/** Pointer to a breakpoint enumeration callback function. */
1185typedef FNDBGFBPENUM *PFNDBGFBPENUM;
1186
1187VMMR3DECL(int) DBGFR3BpEnum(PUVM pUVM, PFNDBGFBPENUM pfnCallback, void *pvUser);
1188# endif /* IN_RING3 */
1189#endif /* !VBOX_WITH_LOTS_OF_DBGF_BPS */
1190
1191VMM_INT_DECL(RTGCUINTREG) DBGFBpGetDR7(PVM pVM);
1192VMM_INT_DECL(RTGCUINTREG) DBGFBpGetDR0(PVM pVM);
1193VMM_INT_DECL(RTGCUINTREG) DBGFBpGetDR1(PVM pVM);
1194VMM_INT_DECL(RTGCUINTREG) DBGFBpGetDR2(PVM pVM);
1195VMM_INT_DECL(RTGCUINTREG) DBGFBpGetDR3(PVM pVM);
1196VMM_INT_DECL(bool) DBGFBpIsHwArmed(PVM pVM);
1197VMM_INT_DECL(bool) DBGFBpIsHwIoArmed(PVM pVM);
1198VMM_INT_DECL(bool) DBGFBpIsInt3Armed(PVM pVM);
1199VMM_INT_DECL(bool) DBGFIsStepping(PVMCPU pVCpu);
1200VMM_INT_DECL(VBOXSTRICTRC) DBGFBpCheckIo(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, RTIOPORT uIoPort, uint8_t cbValue);
1201VMM_INT_DECL(VBOXSTRICTRC) DBGFEventGenericWithArgs(PVM pVM, PVMCPU pVCpu, DBGFEVENTTYPE enmEvent, DBGFEVENTCTX enmCtx,
1202 unsigned cArgs, ...);
1203VMM_INT_DECL(int) DBGFTrap01Handler(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, RTGCUINTREG uDr6, bool fAltStepping);
1204VMM_INT_DECL(int) DBGFTrap03Handler(PVMCC pVM, PVMCPUCC pVCpu, PCPUMCTXCORE pRegFrame);
1205
1206
1207#ifdef IN_RING3 /* The CPU mode API only works in ring-3. */
1208VMMR3DECL(CPUMMODE) DBGFR3CpuGetMode(PUVM pUVM, VMCPUID idCpu);
1209VMMR3DECL(VMCPUID) DBGFR3CpuGetCount(PUVM pUVM);
1210VMMR3DECL(bool) DBGFR3CpuIsIn64BitCode(PUVM pUVM, VMCPUID idCpu);
1211VMMR3DECL(bool) DBGFR3CpuIsInV86Code(PUVM pUVM, VMCPUID idCpu);
1212VMMR3DECL(const char *) DBGFR3CpuGetState(PUVM pUVM, VMCPUID idCpu);
1213#endif
1214
1215
1216
1217#ifdef IN_RING3 /* The info callbacks API only works in ring-3. */
1218
1219struct RTGETOPTSTATE;
1220union RTGETOPTUNION;
1221
1222/**
1223 * Info helper callback structure.
1224 */
1225typedef struct DBGFINFOHLP
1226{
1227 /**
1228 * Print formatted string.
1229 *
1230 * @param pHlp Pointer to this structure.
1231 * @param pszFormat The format string.
1232 * @param ... Arguments.
1233 */
1234 DECLCALLBACKMEMBER(void, pfnPrintf,(PCDBGFINFOHLP pHlp, const char *pszFormat, ...)) RT_IPRT_FORMAT_ATTR(2, 3);
1235
1236 /**
1237 * Print formatted string.
1238 *
1239 * @param pHlp Pointer to this structure.
1240 * @param pszFormat The format string.
1241 * @param args Argument list.
1242 */
1243 DECLCALLBACKMEMBER(void, pfnPrintfV,(PCDBGFINFOHLP pHlp, const char *pszFormat, va_list args)) RT_IPRT_FORMAT_ATTR(2, 0);
1244
1245 /**
1246 * Report getopt parsing trouble
1247 *
1248 * @param pHlp Pointer to this structure.
1249 * @param rc The RTGetOpt return value.
1250 * @param pValueUnion The value union.
1251 * @param pState The getopt state.
1252 */
1253 DECLCALLBACKMEMBER(void, pfnGetOptError,(PCDBGFINFOHLP pHlp, int rc, union RTGETOPTUNION *pValueUnion,
1254 struct RTGETOPTSTATE *pState));
1255} DBGFINFOHLP;
1256
1257
1258/**
1259 * Info handler, device version.
1260 *
1261 * @param pDevIns The device instance which registered the info.
1262 * @param pHlp Callback functions for doing output.
1263 * @param pszArgs Argument string. Optional and specific to the handler.
1264 */
1265typedef DECLCALLBACKTYPE(void, FNDBGFHANDLERDEV,(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs));
1266/** Pointer to a FNDBGFHANDLERDEV function. */
1267typedef FNDBGFHANDLERDEV *PFNDBGFHANDLERDEV;
1268
1269/**
1270 * Info handler, driver version.
1271 *
1272 * @param pDrvIns The driver instance which registered the info.
1273 * @param pHlp Callback functions for doing output.
1274 * @param pszArgs Argument string. Optional and specific to the handler.
1275 */
1276typedef DECLCALLBACKTYPE(void, FNDBGFHANDLERDRV,(PPDMDRVINS pDrvIns, PCDBGFINFOHLP pHlp, const char *pszArgs));
1277/** Pointer to a FNDBGFHANDLERDRV function. */
1278typedef FNDBGFHANDLERDRV *PFNDBGFHANDLERDRV;
1279
1280/**
1281 * Info handler, internal version.
1282 *
1283 * @param pVM The cross context VM structure.
1284 * @param pHlp Callback functions for doing output.
1285 * @param pszArgs Argument string. Optional and specific to the handler.
1286 */
1287typedef DECLCALLBACKTYPE(void, FNDBGFHANDLERINT,(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs));
1288/** Pointer to a FNDBGFHANDLERINT function. */
1289typedef FNDBGFHANDLERINT *PFNDBGFHANDLERINT;
1290
1291/**
1292 * Info handler, external version.
1293 *
1294 * @param pvUser User argument.
1295 * @param pHlp Callback functions for doing output.
1296 * @param pszArgs Argument string. Optional and specific to the handler.
1297 */
1298typedef DECLCALLBACKTYPE(void, FNDBGFHANDLEREXT,(void *pvUser, PCDBGFINFOHLP pHlp, const char *pszArgs));
1299/** Pointer to a FNDBGFHANDLEREXT function. */
1300typedef FNDBGFHANDLEREXT *PFNDBGFHANDLEREXT;
1301
1302/**
1303 * Info handler, device version with argv.
1304 *
1305 * @param pDevIns The device instance which registered the info.
1306 * @param pHlp Callback functions for doing output.
1307 * @param cArgs Number of arguments.
1308 * @param papszArgs Argument vector.
1309 */
1310typedef DECLCALLBACKTYPE(void, FNDBGFINFOARGVDEV,(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, int cArgs, char **papszArgs));
1311/** Pointer to a FNDBGFINFOARGVDEV function. */
1312typedef FNDBGFINFOARGVDEV *PFNDBGFINFOARGVDEV;
1313
1314/**
1315 * Info handler, USB device version with argv.
1316 *
1317 * @param pUsbIns The USB device instance which registered the info.
1318 * @param pHlp Callback functions for doing output.
1319 * @param cArgs Number of arguments.
1320 * @param papszArgs Argument vector.
1321 */
1322typedef DECLCALLBACKTYPE(void, FNDBGFINFOARGVUSB,(PPDMUSBINS pUsbIns, PCDBGFINFOHLP pHlp, int cArgs, char **papszArgs));
1323/** Pointer to a FNDBGFINFOARGVUSB function. */
1324typedef FNDBGFINFOARGVUSB *PFNDBGFINFOARGVUSB;
1325
1326/**
1327 * Info handler, driver version with argv.
1328 *
1329 * @param pDrvIns The driver instance which registered the info.
1330 * @param pHlp Callback functions for doing output.
1331 * @param cArgs Number of arguments.
1332 * @param papszArgs Argument vector.
1333 */
1334typedef DECLCALLBACKTYPE(void, FNDBGFINFOARGVDRV,(PPDMDRVINS pDrvIns, PCDBGFINFOHLP pHlp, int cArgs, char **papszArgs));
1335/** Pointer to a FNDBGFINFOARGVDRV function. */
1336typedef FNDBGFINFOARGVDRV *PFNDBGFINFOARGVDRV;
1337
1338/**
1339 * Info handler, internal version with argv.
1340 *
1341 * @param pVM The cross context VM structure.
1342 * @param pHlp Callback functions for doing output.
1343 * @param cArgs Number of arguments.
1344 * @param papszArgs Argument vector.
1345 */
1346typedef DECLCALLBACKTYPE(void, FNDBGFINFOARGVINT,(PVM pVM, PCDBGFINFOHLP pHlp, int cArgs, char **papszArgs));
1347/** Pointer to a FNDBGFINFOARGVINT function. */
1348typedef FNDBGFINFOARGVINT *PFNDBGFINFOARGVINT;
1349
1350/**
1351 * Info handler, external version with argv.
1352 *
1353 * @param pvUser User argument.
1354 * @param pHlp Callback functions for doing output.
1355 * @param cArgs Number of arguments.
1356 * @param papszArgs Argument vector.
1357 */
1358typedef DECLCALLBACKTYPE(void, FNDBGFINFOARGVEXT,(void *pvUser, PCDBGFINFOHLP pHlp, int cArgs, char **papszArgs));
1359/** Pointer to a FNDBGFINFOARGVEXT function. */
1360typedef FNDBGFINFOARGVEXT *PFNDBGFINFOARGVEXT;
1361
1362
1363/** @name Flags for the info registration functions.
1364 * @{ */
1365/** The handler must run on the EMT. */
1366#define DBGFINFO_FLAGS_RUN_ON_EMT RT_BIT(0)
1367/** Call on all EMTs when a specific isn't specified. */
1368#define DBGFINFO_FLAGS_ALL_EMTS RT_BIT(1)
1369/** @} */
1370
1371VMMR3_INT_DECL(int) DBGFR3InfoRegisterDevice(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDEV pfnHandler, PPDMDEVINS pDevIns);
1372VMMR3_INT_DECL(int) DBGFR3InfoRegisterDriver(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDRV pfnHandler, PPDMDRVINS pDrvIns);
1373VMMR3_INT_DECL(int) DBGFR3InfoRegisterInternal(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFHANDLERINT pfnHandler);
1374VMMR3_INT_DECL(int) DBGFR3InfoRegisterInternalEx(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFHANDLERINT pfnHandler, uint32_t fFlags);
1375VMMR3DECL(int) DBGFR3InfoRegisterExternal(PUVM pUVM, const char *pszName, const char *pszDesc, PFNDBGFHANDLEREXT pfnHandler, void *pvUser);
1376
1377VMMR3_INT_DECL(int) DBGFR3InfoRegisterDeviceArgv(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFINFOARGVDEV pfnHandler, PPDMDEVINS pDevIns);
1378VMMR3_INT_DECL(int) DBGFR3InfoRegisterDriverArgv(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFINFOARGVDRV pfnHandler, PPDMDRVINS pDrvIns);
1379VMMR3_INT_DECL(int) DBGFR3InfoRegisterUsbArgv(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFINFOARGVUSB pfnHandler, PPDMUSBINS pUsbIns);
1380VMMR3_INT_DECL(int) DBGFR3InfoRegisterInternalArgv(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFINFOARGVINT pfnHandler, uint32_t fFlags);
1381VMMR3DECL(int) DBGFR3InfoRegisterExternalArgv(PUVM pUVM, const char *pszName, const char *pszDesc, PFNDBGFINFOARGVEXT pfnHandler, void *pvUser);
1382
1383VMMR3_INT_DECL(int) DBGFR3InfoDeregisterDevice(PVM pVM, PPDMDEVINS pDevIns, const char *pszName);
1384VMMR3_INT_DECL(int) DBGFR3InfoDeregisterDriver(PVM pVM, PPDMDRVINS pDrvIns, const char *pszName);
1385VMMR3_INT_DECL(int) DBGFR3InfoDeregisterUsb(PVM pVM, PPDMUSBINS pDrvIns, const char *pszName);
1386VMMR3_INT_DECL(int) DBGFR3InfoDeregisterInternal(PVM pVM, const char *pszName);
1387VMMR3DECL(int) DBGFR3InfoDeregisterExternal(PUVM pUVM, const char *pszName);
1388
1389VMMR3DECL(int) DBGFR3Info(PUVM pUVM, const char *pszName, const char *pszArgs, PCDBGFINFOHLP pHlp);
1390VMMR3DECL(int) DBGFR3InfoEx(PUVM pUVM, VMCPUID idCpu, const char *pszName, const char *pszArgs, PCDBGFINFOHLP pHlp);
1391VMMR3DECL(int) DBGFR3InfoLogRel(PUVM pUVM, const char *pszName, const char *pszArgs);
1392VMMR3DECL(int) DBGFR3InfoStdErr(PUVM pUVM, const char *pszName, const char *pszArgs);
1393VMMR3_INT_DECL(int) DBGFR3InfoMulti(PVM pVM, const char *pszIncludePat, const char *pszExcludePat,
1394 const char *pszSepFmt, PCDBGFINFOHLP pHlp);
1395
1396/** @def DBGFR3_INFO_LOG
1397 * Display a piece of info writing to the log if enabled.
1398 *
1399 * This is for execution on EMTs and will only show the items on the calling
1400 * EMT. This is to avoid deadlocking against other CPUs if a rendezvous is
1401 * initiated in parallel to this call. (Besides, nobody really wants or need
1402 * info for the other EMTs when using this macro.)
1403 *
1404 * @param a_pVM The shared VM handle.
1405 * @param a_pVCpu The cross context per CPU structure of the calling EMT.
1406 * @param a_pszName The identifier of the info to display.
1407 * @param a_pszArgs Arguments to the info handler.
1408 */
1409#ifdef LOG_ENABLED
1410# define DBGFR3_INFO_LOG(a_pVM, a_pVCpu, a_pszName, a_pszArgs) \
1411 do { \
1412 if (LogIsEnabled()) \
1413 DBGFR3InfoEx((a_pVM)->pUVM, (a_pVCpu)->idCpu, a_pszName, a_pszArgs, NULL); \
1414 } while (0)
1415#else
1416# define DBGFR3_INFO_LOG(a_pVM, a_pVCpu, a_pszName, a_pszArgs) do { } while (0)
1417#endif
1418
1419/** @def DBGFR3_INFO_LOG_SAFE
1420 * Display a piece of info (rendezvous safe) writing to the log if enabled.
1421 *
1422 * @param a_pVM The shared VM handle.
1423 * @param a_pszName The identifier of the info to display.
1424 * @param a_pszArgs Arguments to the info handler.
1425 *
1426 * @remarks Use DBGFR3_INFO_LOG where ever possible!
1427 */
1428#ifdef LOG_ENABLED
1429# define DBGFR3_INFO_LOG_SAFE(a_pVM, a_pszName, a_pszArgs) \
1430 do { \
1431 if (LogIsEnabled()) \
1432 DBGFR3Info((a_pVM)->pUVM, a_pszName, a_pszArgs, NULL); \
1433 } while (0)
1434#else
1435# define DBGFR3_INFO_LOG_SAFE(a_pVM, a_pszName, a_pszArgs) do { } while (0)
1436#endif
1437
1438/**
1439 * Enumeration callback for use with DBGFR3InfoEnum.
1440 *
1441 * @returns VBox status code.
1442 * A status code indicating failure will end the enumeration
1443 * and DBGFR3InfoEnum will return with that status code.
1444 * @param pUVM The user mode VM handle.
1445 * @param pszName Info identifier name.
1446 * @param pszDesc The description.
1447 */
1448typedef DECLCALLBACKTYPE(int, FNDBGFINFOENUM,(PUVM pUVM, const char *pszName, const char *pszDesc, void *pvUser));
1449/** Pointer to a FNDBGFINFOENUM function. */
1450typedef FNDBGFINFOENUM *PFNDBGFINFOENUM;
1451
1452VMMR3DECL(int) DBGFR3InfoEnum(PUVM pUVM, PFNDBGFINFOENUM pfnCallback, void *pvUser);
1453VMMR3DECL(PCDBGFINFOHLP) DBGFR3InfoLogHlp(void);
1454VMMR3DECL(PCDBGFINFOHLP) DBGFR3InfoLogRelHlp(void);
1455VMMR3DECL(void) DBGFR3InfoGenricGetOptError(PCDBGFINFOHLP pHlp, int rc, union RTGETOPTUNION *pValueUnion,
1456 struct RTGETOPTSTATE *pState);
1457
1458#endif /* IN_RING3 */
1459
1460
1461#ifdef IN_RING3 /* The log contrl API only works in ring-3. */
1462VMMR3DECL(int) DBGFR3LogModifyGroups(PUVM pUVM, const char *pszGroupSettings);
1463VMMR3DECL(int) DBGFR3LogModifyFlags(PUVM pUVM, const char *pszFlagSettings);
1464VMMR3DECL(int) DBGFR3LogModifyDestinations(PUVM pUVM, const char *pszDestSettings);
1465#endif /* IN_RING3 */
1466
1467#ifdef IN_RING3 /* The debug information management APIs only works in ring-3. */
1468
1469/** Max length (including '\\0') of a symbol name. */
1470#define DBGF_SYMBOL_NAME_LENGTH 512
1471
1472/**
1473 * Debug symbol.
1474 */
1475typedef struct DBGFSYMBOL
1476{
1477 /** Symbol value (address). */
1478 RTGCUINTPTR Value;
1479 /** Symbol size. */
1480 uint32_t cb;
1481 /** Symbol Flags. (reserved). */
1482 uint32_t fFlags;
1483 /** Symbol name. */
1484 char szName[DBGF_SYMBOL_NAME_LENGTH];
1485} DBGFSYMBOL;
1486/** Pointer to debug symbol. */
1487typedef DBGFSYMBOL *PDBGFSYMBOL;
1488/** Pointer to const debug symbol. */
1489typedef const DBGFSYMBOL *PCDBGFSYMBOL;
1490
1491/**
1492 * Debug line number information.
1493 */
1494typedef struct DBGFLINE
1495{
1496 /** Address. */
1497 RTGCUINTPTR Address;
1498 /** Line number. */
1499 uint32_t uLineNo;
1500 /** Filename. */
1501 char szFilename[260];
1502} DBGFLINE;
1503/** Pointer to debug line number. */
1504typedef DBGFLINE *PDBGFLINE;
1505/** Pointer to const debug line number. */
1506typedef const DBGFLINE *PCDBGFLINE;
1507
1508/** @name Address spaces aliases.
1509 * @{ */
1510/** The guest global address space. */
1511#define DBGF_AS_GLOBAL ((RTDBGAS)-1)
1512/** The guest kernel address space.
1513 * This is usually resolves to the same as DBGF_AS_GLOBAL. */
1514#define DBGF_AS_KERNEL ((RTDBGAS)-2)
1515/** The physical address space. */
1516#define DBGF_AS_PHYS ((RTDBGAS)-3)
1517/** Raw-mode context. */
1518#define DBGF_AS_RC ((RTDBGAS)-4)
1519/** Ring-0 context. */
1520#define DBGF_AS_R0 ((RTDBGAS)-5)
1521/** Raw-mode context and then global guest context.
1522 * When used for looking up information, it works as if the call was first made
1523 * with DBGF_AS_RC and then on failure with DBGF_AS_GLOBAL. When called for
1524 * making address space changes, it works as if DBGF_AS_RC was used. */
1525#define DBGF_AS_RC_AND_GC_GLOBAL ((RTDBGAS)-6)
1526
1527/** The first special one. */
1528#define DBGF_AS_FIRST DBGF_AS_RC_AND_GC_GLOBAL
1529/** The last special one. */
1530#define DBGF_AS_LAST DBGF_AS_GLOBAL
1531#endif
1532/** The number of special address space handles. */
1533#define DBGF_AS_COUNT (6U)
1534#ifdef IN_RING3
1535/** Converts an alias handle to an array index. */
1536#define DBGF_AS_ALIAS_2_INDEX(hAlias) \
1537 ( (uintptr_t)(hAlias) - (uintptr_t)DBGF_AS_FIRST )
1538/** Predicat macro that check if the specified handle is an alias. */
1539#define DBGF_AS_IS_ALIAS(hAlias) \
1540 ( DBGF_AS_ALIAS_2_INDEX(hAlias) < DBGF_AS_COUNT )
1541/** Predicat macro that check if the specified alias is a fixed one or not. */
1542#define DBGF_AS_IS_FIXED_ALIAS(hAlias) \
1543 ( DBGF_AS_ALIAS_2_INDEX(hAlias) < (uintptr_t)DBGF_AS_PHYS - (uintptr_t)DBGF_AS_FIRST + 1U )
1544
1545/** @} */
1546
1547VMMR3DECL(RTDBGCFG) DBGFR3AsGetConfig(PUVM pUVM);
1548
1549VMMR3DECL(int) DBGFR3AsAdd(PUVM pUVM, RTDBGAS hDbgAs, RTPROCESS ProcId);
1550VMMR3DECL(int) DBGFR3AsDelete(PUVM pUVM, RTDBGAS hDbgAs);
1551VMMR3DECL(int) DBGFR3AsSetAlias(PUVM pUVM, RTDBGAS hAlias, RTDBGAS hAliasFor);
1552VMMR3DECL(RTDBGAS) DBGFR3AsResolve(PUVM pUVM, RTDBGAS hAlias);
1553VMMR3DECL(RTDBGAS) DBGFR3AsResolveAndRetain(PUVM pUVM, RTDBGAS hAlias);
1554VMMR3DECL(RTDBGAS) DBGFR3AsQueryByName(PUVM pUVM, const char *pszName);
1555VMMR3DECL(RTDBGAS) DBGFR3AsQueryByPid(PUVM pUVM, RTPROCESS ProcId);
1556
1557VMMR3DECL(int) DBGFR3AsLoadImage(PUVM pUVM, RTDBGAS hDbgAs, const char *pszFilename, const char *pszModName,
1558 RTLDRARCH enmArch, PCDBGFADDRESS pModAddress, RTDBGSEGIDX iModSeg, uint32_t fFlags);
1559VMMR3DECL(int) DBGFR3AsLoadMap(PUVM pUVM, RTDBGAS hDbgAs, const char *pszFilename, const char *pszModName, PCDBGFADDRESS pModAddress, RTDBGSEGIDX iModSeg, RTGCUINTPTR uSubtrahend, uint32_t fFlags);
1560VMMR3DECL(int) DBGFR3AsLinkModule(PUVM pUVM, RTDBGAS hDbgAs, RTDBGMOD hMod, PCDBGFADDRESS pModAddress, RTDBGSEGIDX iModSeg, uint32_t fFlags);
1561VMMR3DECL(int) DBGFR3AsUnlinkModuleByName(PUVM pUVM, RTDBGAS hDbgAs, const char *pszModName);
1562
1563VMMR3DECL(int) DBGFR3AsSymbolByAddr(PUVM pUVM, RTDBGAS hDbgAs, PCDBGFADDRESS pAddress, uint32_t fFlags,
1564 PRTGCINTPTR poffDisp, PRTDBGSYMBOL pSymbol, PRTDBGMOD phMod);
1565VMMR3DECL(PRTDBGSYMBOL) DBGFR3AsSymbolByAddrA(PUVM pUVM, RTDBGAS hDbgAs, PCDBGFADDRESS pAddress, uint32_t Flags,
1566 PRTGCINTPTR poffDisp, PRTDBGMOD phMod);
1567VMMR3DECL(int) DBGFR3AsSymbolByName(PUVM pUVM, RTDBGAS hDbgAs, const char *pszSymbol, PRTDBGSYMBOL pSymbol, PRTDBGMOD phMod);
1568
1569VMMR3DECL(int) DBGFR3AsLineByAddr(PUVM pUVM, RTDBGAS hDbgAs, PCDBGFADDRESS pAddress,
1570 PRTGCINTPTR poffDisp, PRTDBGLINE pLine, PRTDBGMOD phMod);
1571VMMR3DECL(PRTDBGLINE) DBGFR3AsLineByAddrA(PUVM pUVM, RTDBGAS hDbgAs, PCDBGFADDRESS pAddress,
1572 PRTGCINTPTR poffDisp, PRTDBGMOD phMod);
1573
1574/** @name DBGFMOD_PE_F_XXX - flags for
1575 * @{ */
1576/** NT 3.1 images were a little different, so make allowances for that. */
1577#define DBGFMODINMEM_F_PE_NT31 RT_BIT_32(0)
1578/** No container fallback. */
1579#define DBGFMODINMEM_F_NO_CONTAINER_FALLBACK RT_BIT_32(1)
1580/** No in-memory reader fallback. */
1581#define DBGFMODINMEM_F_NO_READER_FALLBACK RT_BIT_32(2)
1582/** Valid flags. */
1583#define DBGFMODINMEM_F_VALID_MASK UINT32_C(0x00000007)
1584/** @} */
1585VMMR3DECL(int) DBGFR3ModInMem(PUVM pUVM, PCDBGFADDRESS pImageAddr, uint32_t fFlags, const char *pszName,
1586 const char *pszFilename, RTLDRARCH enmArch, uint32_t cbImage,
1587 PRTDBGMOD phDbgMod, PRTERRINFO pErrInfo);
1588
1589#endif /* IN_RING3 */
1590
1591#ifdef IN_RING3 /* The stack API only works in ring-3. */
1592
1593/** Pointer to stack frame info. */
1594typedef struct DBGFSTACKFRAME *PDBGFSTACKFRAME;
1595/** Pointer to const stack frame info. */
1596typedef struct DBGFSTACKFRAME const *PCDBGFSTACKFRAME;
1597/**
1598 * Info about a stack frame.
1599 */
1600typedef struct DBGFSTACKFRAME
1601{
1602 /** Frame number. */
1603 uint32_t iFrame;
1604 /** Frame flags (DBGFSTACKFRAME_FLAGS_XXX). */
1605 uint32_t fFlags;
1606 /** The stack address of the frame.
1607 * The off member is [e|r]sp and the Sel member is ss. */
1608 DBGFADDRESS AddrStack;
1609 /** The program counter (PC) address of the frame.
1610 * The off member is [e|r]ip and the Sel member is cs. */
1611 DBGFADDRESS AddrPC;
1612 /** Pointer to the symbol nearest the program counter (PC). NULL if not found. */
1613 PRTDBGSYMBOL pSymPC;
1614 /** Pointer to the linenumber nearest the program counter (PC). NULL if not found. */
1615 PRTDBGLINE pLinePC;
1616 /** The frame address.
1617 * The off member is [e|r]bp and the Sel member is ss. */
1618 DBGFADDRESS AddrFrame;
1619 /** The way this frame returns to the next one. */
1620 RTDBGRETURNTYPE enmReturnType;
1621
1622 /** The way the next frame returns.
1623 * Only valid when DBGFSTACKFRAME_FLAGS_UNWIND_INFO_RET is set. */
1624 RTDBGRETURNTYPE enmReturnFrameReturnType;
1625 /** The return frame address.
1626 * The off member is [e|r]bp and the Sel member is ss. */
1627 DBGFADDRESS AddrReturnFrame;
1628 /** The return stack address.
1629 * The off member is [e|r]sp and the Sel member is ss. */
1630 DBGFADDRESS AddrReturnStack;
1631
1632 /** The program counter (PC) address which the frame returns to.
1633 * The off member is [e|r]ip and the Sel member is cs. */
1634 DBGFADDRESS AddrReturnPC;
1635 /** Pointer to the symbol nearest the return PC. NULL if not found. */
1636 PRTDBGSYMBOL pSymReturnPC;
1637 /** Pointer to the linenumber nearest the return PC. NULL if not found. */
1638 PRTDBGLINE pLineReturnPC;
1639
1640 /** 32-bytes of stack arguments. */
1641 union
1642 {
1643 /** 64-bit view */
1644 uint64_t au64[4];
1645 /** 32-bit view */
1646 uint32_t au32[8];
1647 /** 16-bit view */
1648 uint16_t au16[16];
1649 /** 8-bit view */
1650 uint8_t au8[32];
1651 } Args;
1652
1653 /** Number of registers values we can be sure about.
1654 * @note This is generally zero in the first frame. */
1655 uint32_t cSureRegs;
1656 /** Registers we can be sure about (length given by cSureRegs). */
1657 struct DBGFREGVALEX *paSureRegs;
1658
1659 /** Pointer to the next frame.
1660 * Might not be used in some cases, so consider it internal. */
1661 PCDBGFSTACKFRAME pNextInternal;
1662 /** Pointer to the first frame.
1663 * Might not be used in some cases, so consider it internal. */
1664 PCDBGFSTACKFRAME pFirstInternal;
1665} DBGFSTACKFRAME;
1666
1667/** @name DBGFSTACKFRAME_FLAGS_XXX - DBGFSTACKFRAME Flags.
1668 * @{ */
1669/** This is the last stack frame we can read.
1670 * This flag is not set if the walk stop because of max dept or recursion. */
1671# define DBGFSTACKFRAME_FLAGS_LAST RT_BIT(1)
1672/** This is the last record because we detected a loop. */
1673# define DBGFSTACKFRAME_FLAGS_LOOP RT_BIT(2)
1674/** This is the last record because we reached the maximum depth. */
1675# define DBGFSTACKFRAME_FLAGS_MAX_DEPTH RT_BIT(3)
1676/** 16-bit frame. */
1677# define DBGFSTACKFRAME_FLAGS_16BIT RT_BIT(4)
1678/** 32-bit frame. */
1679# define DBGFSTACKFRAME_FLAGS_32BIT RT_BIT(5)
1680/** 64-bit frame. */
1681# define DBGFSTACKFRAME_FLAGS_64BIT RT_BIT(6)
1682/** Real mode or V86 frame. */
1683# define DBGFSTACKFRAME_FLAGS_REAL_V86 RT_BIT(7)
1684/** Is a trap frame (NT term). */
1685# define DBGFSTACKFRAME_FLAGS_TRAP_FRAME RT_BIT(8)
1686
1687/** Used Odd/even heuristics for far/near return. */
1688# define DBGFSTACKFRAME_FLAGS_USED_ODD_EVEN RT_BIT(29)
1689/** Set if we used unwind info to construct the frame. (Kind of internal.) */
1690# define DBGFSTACKFRAME_FLAGS_USED_UNWIND_INFO RT_BIT(30)
1691/** Internal: Unwind info used for the return frame. */
1692# define DBGFSTACKFRAME_FLAGS_UNWIND_INFO_RET RT_BIT(31)
1693/** @} */
1694
1695/** @name DBGFCODETYPE
1696 * @{ */
1697typedef enum DBGFCODETYPE
1698{
1699 /** The usual invalid 0 value. */
1700 DBGFCODETYPE_INVALID = 0,
1701 /** Stack walk for guest code. */
1702 DBGFCODETYPE_GUEST,
1703 /** Stack walk for hypervisor code. */
1704 DBGFCODETYPE_HYPER,
1705 /** Stack walk for ring 0 code. */
1706 DBGFCODETYPE_RING0,
1707 /** The usual 32-bit blowup. */
1708 DBGFCODETYPE_32BIT_HACK = 0x7fffffff
1709} DBGFCODETYPE;
1710/** @} */
1711
1712VMMR3DECL(int) DBGFR3StackWalkBegin(PUVM pUVM, VMCPUID idCpu, DBGFCODETYPE enmCodeType,
1713 PCDBGFSTACKFRAME *ppFirstFrame);
1714VMMR3DECL(int) DBGFR3StackWalkBeginEx(PUVM pUVM, VMCPUID idCpu, DBGFCODETYPE enmCodeType, PCDBGFADDRESS pAddrFrame,
1715 PCDBGFADDRESS pAddrStack,PCDBGFADDRESS pAddrPC,
1716 RTDBGRETURNTYPE enmReturnType, PCDBGFSTACKFRAME *ppFirstFrame);
1717VMMR3DECL(PCDBGFSTACKFRAME) DBGFR3StackWalkNext(PCDBGFSTACKFRAME pCurrent);
1718VMMR3DECL(void) DBGFR3StackWalkEnd(PCDBGFSTACKFRAME pFirstFrame);
1719
1720#endif /* IN_RING3 */
1721
1722
1723#ifdef IN_RING3 /* The disassembly API only works in ring-3. */
1724
1725/** @name Flags to pass to DBGFR3DisasInstrEx().
1726 * @{ */
1727/** Disassemble the current guest instruction, with annotations. */
1728#define DBGF_DISAS_FLAGS_CURRENT_GUEST RT_BIT(0)
1729/** No annotations for current context. */
1730#define DBGF_DISAS_FLAGS_NO_ANNOTATION RT_BIT(2)
1731/** No symbol lookup. */
1732#define DBGF_DISAS_FLAGS_NO_SYMBOLS RT_BIT(3)
1733/** No instruction bytes. */
1734#define DBGF_DISAS_FLAGS_NO_BYTES RT_BIT(4)
1735/** No address in the output. */
1736#define DBGF_DISAS_FLAGS_NO_ADDRESS RT_BIT(5)
1737/** Disassemble original unpatched bytes (PATM). */
1738#define DBGF_DISAS_FLAGS_UNPATCHED_BYTES RT_BIT(7)
1739/** Annotate patched instructions. */
1740#define DBGF_DISAS_FLAGS_ANNOTATE_PATCHED RT_BIT(8)
1741/** Disassemble in the default mode of the specific context. */
1742#define DBGF_DISAS_FLAGS_DEFAULT_MODE UINT32_C(0x00000000)
1743/** Disassemble in 16-bit mode. */
1744#define DBGF_DISAS_FLAGS_16BIT_MODE UINT32_C(0x10000000)
1745/** Disassemble in 16-bit mode with real mode address translation. */
1746#define DBGF_DISAS_FLAGS_16BIT_REAL_MODE UINT32_C(0x20000000)
1747/** Disassemble in 32-bit mode. */
1748#define DBGF_DISAS_FLAGS_32BIT_MODE UINT32_C(0x30000000)
1749/** Disassemble in 64-bit mode. */
1750#define DBGF_DISAS_FLAGS_64BIT_MODE UINT32_C(0x40000000)
1751/** The disassembly mode mask. */
1752#define DBGF_DISAS_FLAGS_MODE_MASK UINT32_C(0x70000000)
1753/** Mask containing the valid flags. */
1754#define DBGF_DISAS_FLAGS_VALID_MASK UINT32_C(0x700001ff)
1755/** @} */
1756
1757/** Special flat selector. */
1758#define DBGF_SEL_FLAT 1
1759
1760VMMR3DECL(int) DBGFR3DisasInstrEx(PUVM pUVM, VMCPUID idCpu, RTSEL Sel, RTGCPTR GCPtr, uint32_t fFlags,
1761 char *pszOutput, uint32_t cbOutput, uint32_t *pcbInstr);
1762VMMR3_INT_DECL(int) DBGFR3DisasInstrCurrent(PVMCPU pVCpu, char *pszOutput, uint32_t cbOutput);
1763VMMR3DECL(int) DBGFR3DisasInstrCurrentLogInternal(PVMCPU pVCpu, const char *pszPrefix);
1764
1765/** @def DBGFR3_DISAS_INSTR_CUR_LOG
1766 * Disassembles the current guest context instruction and writes it to the log.
1767 * All registers and data will be displayed. Addresses will be attempted resolved to symbols.
1768 */
1769#ifdef LOG_ENABLED
1770# define DBGFR3_DISAS_INSTR_CUR_LOG(pVCpu, pszPrefix) \
1771 do { \
1772 if (LogIsEnabled()) \
1773 DBGFR3DisasInstrCurrentLogInternal(pVCpu, pszPrefix); \
1774 } while (0)
1775#else
1776# define DBGFR3_DISAS_INSTR_CUR_LOG(pVCpu, pszPrefix) do { } while (0)
1777#endif
1778
1779VMMR3DECL(int) DBGFR3DisasInstrLogInternal(PVMCPU pVCpu, RTSEL Sel, RTGCPTR GCPtr, const char *pszPrefix);
1780
1781/** @def DBGFR3_DISAS_INSTR_LOG
1782 * Disassembles the specified guest context instruction and writes it to the log.
1783 * Addresses will be attempted resolved to symbols.
1784 * @thread Any EMT.
1785 */
1786# ifdef LOG_ENABLED
1787# define DBGFR3_DISAS_INSTR_LOG(pVCpu, Sel, GCPtr, pszPrefix) \
1788 do { \
1789 if (LogIsEnabled()) \
1790 DBGFR3DisasInstrLogInternal(pVCpu, Sel, GCPtr, pszPrefix); \
1791 } while (0)
1792# else
1793# define DBGFR3_DISAS_INSTR_LOG(pVCpu, Sel, GCPtr, pszPrefix) do { } while (0)
1794# endif
1795#endif
1796
1797
1798#ifdef IN_RING3
1799VMMR3DECL(int) DBGFR3MemScan(PUVM pUVM, VMCPUID idCpu, PCDBGFADDRESS pAddress, RTGCUINTPTR cbRange, RTGCUINTPTR uAlign,
1800 const void *pvNeedle, size_t cbNeedle, PDBGFADDRESS pHitAddress);
1801VMMR3DECL(int) DBGFR3MemRead(PUVM pUVM, VMCPUID idCpu, PCDBGFADDRESS pAddress, void *pvBuf, size_t cbRead);
1802VMMR3DECL(int) DBGFR3MemReadString(PUVM pUVM, VMCPUID idCpu, PCDBGFADDRESS pAddress, char *pszBuf, size_t cbBuf);
1803VMMR3DECL(int) DBGFR3MemWrite(PUVM pUVM, VMCPUID idCpu, PCDBGFADDRESS pAddress, void const *pvBuf, size_t cbRead);
1804#endif
1805
1806
1807/** @name Flags for DBGFR3PagingDumpEx, PGMR3DumpHierarchyHCEx and
1808 * PGMR3DumpHierarchyGCEx
1809 * @{ */
1810/** The CR3 from the current CPU state. */
1811#define DBGFPGDMP_FLAGS_CURRENT_CR3 RT_BIT_32(0)
1812/** The current CPU paging mode (PSE, PAE, LM, EPT, NX). */
1813#define DBGFPGDMP_FLAGS_CURRENT_MODE RT_BIT_32(1)
1814/** Whether PSE is enabled (!DBGFPGDMP_FLAGS_CURRENT_STATE).
1815 * Same value as X86_CR4_PSE. */
1816#define DBGFPGDMP_FLAGS_PSE RT_BIT_32(4) /* */
1817/** Whether PAE is enabled (!DBGFPGDMP_FLAGS_CURRENT_STATE).
1818 * Same value as X86_CR4_PAE. */
1819#define DBGFPGDMP_FLAGS_PAE RT_BIT_32(5) /* */
1820/** Whether LME is enabled (!DBGFPGDMP_FLAGS_CURRENT_STATE).
1821 * Same value as MSR_K6_EFER_LME. */
1822#define DBGFPGDMP_FLAGS_LME RT_BIT_32(8)
1823/** Whether nested paging is enabled (!DBGFPGDMP_FLAGS_CURRENT_STATE). */
1824#define DBGFPGDMP_FLAGS_NP RT_BIT_32(9)
1825/** Whether extended nested page tables are enabled
1826 * (!DBGFPGDMP_FLAGS_CURRENT_STATE). */
1827#define DBGFPGDMP_FLAGS_EPT RT_BIT_32(10)
1828/** Whether no-execution is enabled (!DBGFPGDMP_FLAGS_CURRENT_STATE).
1829 * Same value as MSR_K6_EFER_NXE. */
1830#define DBGFPGDMP_FLAGS_NXE RT_BIT_32(11)
1831/** Whether to print the CR3. */
1832#define DBGFPGDMP_FLAGS_PRINT_CR3 RT_BIT_32(27)
1833/** Whether to print the header. */
1834#define DBGFPGDMP_FLAGS_HEADER RT_BIT_32(28)
1835/** Whether to dump additional page information. */
1836#define DBGFPGDMP_FLAGS_PAGE_INFO RT_BIT_32(29)
1837/** Dump the shadow tables if set.
1838 * Cannot be used together with DBGFPGDMP_FLAGS_GUEST. */
1839#define DBGFPGDMP_FLAGS_SHADOW RT_BIT_32(30)
1840/** Dump the guest tables if set.
1841 * Cannot be used together with DBGFPGDMP_FLAGS_SHADOW. */
1842#define DBGFPGDMP_FLAGS_GUEST RT_BIT_32(31)
1843/** Mask of valid bits. */
1844#define DBGFPGDMP_FLAGS_VALID_MASK UINT32_C(0xf8000f33)
1845/** The mask of bits controlling the paging mode. */
1846#define DBGFPGDMP_FLAGS_MODE_MASK UINT32_C(0x00000f32)
1847/** @} */
1848VMMDECL(int) DBGFR3PagingDumpEx(PUVM pUVM, VMCPUID idCpu, uint32_t fFlags, uint64_t cr3, uint64_t u64FirstAddr,
1849 uint64_t u64LastAddr, uint32_t cMaxDepth, PCDBGFINFOHLP pHlp);
1850
1851
1852/** @name DBGFR3SelQueryInfo flags.
1853 * @{ */
1854/** Get the info from the guest descriptor table.
1855 * @note This is more or less a given now when raw-mode was kicked out. */
1856#define DBGFSELQI_FLAGS_DT_GUEST UINT32_C(0)
1857/** If currently executing in in 64-bit mode, blow up data selectors. */
1858#define DBGFSELQI_FLAGS_DT_ADJ_64BIT_MODE UINT32_C(2)
1859/** @} */
1860VMMR3DECL(int) DBGFR3SelQueryInfo(PUVM pUVM, VMCPUID idCpu, RTSEL Sel, uint32_t fFlags, PDBGFSELINFO pSelInfo);
1861
1862
1863/**
1864 * Register identifiers.
1865 */
1866typedef enum DBGFREG
1867{
1868 /* General purpose registers: */
1869 DBGFREG_AL = 0,
1870 DBGFREG_AX = DBGFREG_AL,
1871 DBGFREG_EAX = DBGFREG_AL,
1872 DBGFREG_RAX = DBGFREG_AL,
1873
1874 DBGFREG_CL,
1875 DBGFREG_CX = DBGFREG_CL,
1876 DBGFREG_ECX = DBGFREG_CL,
1877 DBGFREG_RCX = DBGFREG_CL,
1878
1879 DBGFREG_DL,
1880 DBGFREG_DX = DBGFREG_DL,
1881 DBGFREG_EDX = DBGFREG_DL,
1882 DBGFREG_RDX = DBGFREG_DL,
1883
1884 DBGFREG_BL,
1885 DBGFREG_BX = DBGFREG_BL,
1886 DBGFREG_EBX = DBGFREG_BL,
1887 DBGFREG_RBX = DBGFREG_BL,
1888
1889 DBGFREG_SPL,
1890 DBGFREG_SP = DBGFREG_SPL,
1891 DBGFREG_ESP = DBGFREG_SPL,
1892 DBGFREG_RSP = DBGFREG_SPL,
1893
1894 DBGFREG_BPL,
1895 DBGFREG_BP = DBGFREG_BPL,
1896 DBGFREG_EBP = DBGFREG_BPL,
1897 DBGFREG_RBP = DBGFREG_BPL,
1898
1899 DBGFREG_SIL,
1900 DBGFREG_SI = DBGFREG_SIL,
1901 DBGFREG_ESI = DBGFREG_SIL,
1902 DBGFREG_RSI = DBGFREG_SIL,
1903
1904 DBGFREG_DIL,
1905 DBGFREG_DI = DBGFREG_DIL,
1906 DBGFREG_EDI = DBGFREG_DIL,
1907 DBGFREG_RDI = DBGFREG_DIL,
1908
1909 DBGFREG_R8,
1910 DBGFREG_R8B = DBGFREG_R8,
1911 DBGFREG_R8W = DBGFREG_R8,
1912 DBGFREG_R8D = DBGFREG_R8,
1913
1914 DBGFREG_R9,
1915 DBGFREG_R9B = DBGFREG_R9,
1916 DBGFREG_R9W = DBGFREG_R9,
1917 DBGFREG_R9D = DBGFREG_R9,
1918
1919 DBGFREG_R10,
1920 DBGFREG_R10B = DBGFREG_R10,
1921 DBGFREG_R10W = DBGFREG_R10,
1922 DBGFREG_R10D = DBGFREG_R10,
1923
1924 DBGFREG_R11,
1925 DBGFREG_R11B = DBGFREG_R11,
1926 DBGFREG_R11W = DBGFREG_R11,
1927 DBGFREG_R11D = DBGFREG_R11,
1928
1929 DBGFREG_R12,
1930 DBGFREG_R12B = DBGFREG_R12,
1931 DBGFREG_R12W = DBGFREG_R12,
1932 DBGFREG_R12D = DBGFREG_R12,
1933
1934 DBGFREG_R13,
1935 DBGFREG_R13B = DBGFREG_R13,
1936 DBGFREG_R13W = DBGFREG_R13,
1937 DBGFREG_R13D = DBGFREG_R13,
1938
1939 DBGFREG_R14,
1940 DBGFREG_R14B = DBGFREG_R14,
1941 DBGFREG_R14W = DBGFREG_R14,
1942 DBGFREG_R14D = DBGFREG_R14,
1943
1944 DBGFREG_R15,
1945 DBGFREG_R15B = DBGFREG_R15,
1946 DBGFREG_R15W = DBGFREG_R15,
1947 DBGFREG_R15D = DBGFREG_R15,
1948
1949 /* Segments and other special registers: */
1950 DBGFREG_CS,
1951 DBGFREG_CS_ATTR,
1952 DBGFREG_CS_BASE,
1953 DBGFREG_CS_LIMIT,
1954
1955 DBGFREG_DS,
1956 DBGFREG_DS_ATTR,
1957 DBGFREG_DS_BASE,
1958 DBGFREG_DS_LIMIT,
1959
1960 DBGFREG_ES,
1961 DBGFREG_ES_ATTR,
1962 DBGFREG_ES_BASE,
1963 DBGFREG_ES_LIMIT,
1964
1965 DBGFREG_FS,
1966 DBGFREG_FS_ATTR,
1967 DBGFREG_FS_BASE,
1968 DBGFREG_FS_LIMIT,
1969
1970 DBGFREG_GS,
1971 DBGFREG_GS_ATTR,
1972 DBGFREG_GS_BASE,
1973 DBGFREG_GS_LIMIT,
1974
1975 DBGFREG_SS,
1976 DBGFREG_SS_ATTR,
1977 DBGFREG_SS_BASE,
1978 DBGFREG_SS_LIMIT,
1979
1980 DBGFREG_IP,
1981 DBGFREG_EIP = DBGFREG_IP,
1982 DBGFREG_RIP = DBGFREG_IP,
1983
1984 DBGFREG_FLAGS,
1985 DBGFREG_EFLAGS = DBGFREG_FLAGS,
1986 DBGFREG_RFLAGS = DBGFREG_FLAGS,
1987
1988 /* FPU: */
1989 DBGFREG_FCW,
1990 DBGFREG_FSW,
1991 DBGFREG_FTW,
1992 DBGFREG_FOP,
1993 DBGFREG_FPUIP,
1994 DBGFREG_FPUCS,
1995 DBGFREG_FPUDP,
1996 DBGFREG_FPUDS,
1997 DBGFREG_MXCSR,
1998 DBGFREG_MXCSR_MASK,
1999
2000 DBGFREG_ST0,
2001 DBGFREG_ST1,
2002 DBGFREG_ST2,
2003 DBGFREG_ST3,
2004 DBGFREG_ST4,
2005 DBGFREG_ST5,
2006 DBGFREG_ST6,
2007 DBGFREG_ST7,
2008
2009 DBGFREG_MM0,
2010 DBGFREG_MM1,
2011 DBGFREG_MM2,
2012 DBGFREG_MM3,
2013 DBGFREG_MM4,
2014 DBGFREG_MM5,
2015 DBGFREG_MM6,
2016 DBGFREG_MM7,
2017
2018 /* SSE: */
2019 DBGFREG_XMM0,
2020 DBGFREG_XMM1,
2021 DBGFREG_XMM2,
2022 DBGFREG_XMM3,
2023 DBGFREG_XMM4,
2024 DBGFREG_XMM5,
2025 DBGFREG_XMM6,
2026 DBGFREG_XMM7,
2027 DBGFREG_XMM8,
2028 DBGFREG_XMM9,
2029 DBGFREG_XMM10,
2030 DBGFREG_XMM11,
2031 DBGFREG_XMM12,
2032 DBGFREG_XMM13,
2033 DBGFREG_XMM14,
2034 DBGFREG_XMM15,
2035 /** @todo add XMM aliases. */
2036
2037 /* AVX: */
2038 DBGFREG_YMM0,
2039 DBGFREG_YMM1,
2040 DBGFREG_YMM2,
2041 DBGFREG_YMM3,
2042 DBGFREG_YMM4,
2043 DBGFREG_YMM5,
2044 DBGFREG_YMM6,
2045 DBGFREG_YMM7,
2046 DBGFREG_YMM8,
2047 DBGFREG_YMM9,
2048 DBGFREG_YMM10,
2049 DBGFREG_YMM11,
2050 DBGFREG_YMM12,
2051 DBGFREG_YMM13,
2052 DBGFREG_YMM14,
2053 DBGFREG_YMM15,
2054
2055 /* System registers: */
2056 DBGFREG_GDTR_BASE,
2057 DBGFREG_GDTR_LIMIT,
2058 DBGFREG_IDTR_BASE,
2059 DBGFREG_IDTR_LIMIT,
2060 DBGFREG_LDTR,
2061 DBGFREG_LDTR_ATTR,
2062 DBGFREG_LDTR_BASE,
2063 DBGFREG_LDTR_LIMIT,
2064 DBGFREG_TR,
2065 DBGFREG_TR_ATTR,
2066 DBGFREG_TR_BASE,
2067 DBGFREG_TR_LIMIT,
2068
2069 DBGFREG_CR0,
2070 DBGFREG_CR2,
2071 DBGFREG_CR3,
2072 DBGFREG_CR4,
2073 DBGFREG_CR8,
2074
2075 DBGFREG_DR0,
2076 DBGFREG_DR1,
2077 DBGFREG_DR2,
2078 DBGFREG_DR3,
2079 DBGFREG_DR6,
2080 DBGFREG_DR7,
2081
2082 /* MSRs: */
2083 DBGFREG_MSR_IA32_APICBASE,
2084 DBGFREG_MSR_IA32_CR_PAT,
2085 DBGFREG_MSR_IA32_PERF_STATUS,
2086 DBGFREG_MSR_IA32_SYSENTER_CS,
2087 DBGFREG_MSR_IA32_SYSENTER_EIP,
2088 DBGFREG_MSR_IA32_SYSENTER_ESP,
2089 DBGFREG_MSR_IA32_TSC,
2090 DBGFREG_MSR_K6_EFER,
2091 DBGFREG_MSR_K6_STAR,
2092 DBGFREG_MSR_K8_CSTAR,
2093 DBGFREG_MSR_K8_FS_BASE,
2094 DBGFREG_MSR_K8_GS_BASE,
2095 DBGFREG_MSR_K8_KERNEL_GS_BASE,
2096 DBGFREG_MSR_K8_LSTAR,
2097 DBGFREG_MSR_K8_SF_MASK,
2098 DBGFREG_MSR_K8_TSC_AUX,
2099
2100 /** The number of registers to pass to DBGFR3RegQueryAll. */
2101 DBGFREG_ALL_COUNT,
2102
2103 /* Misc aliases that doesn't need be part of the 'all' query: */
2104 DBGFREG_AH = DBGFREG_ALL_COUNT,
2105 DBGFREG_CH,
2106 DBGFREG_DH,
2107 DBGFREG_BH,
2108 DBGFREG_GDTR,
2109 DBGFREG_IDTR,
2110
2111 /** The end of the registers. */
2112 DBGFREG_END,
2113 /** The usual 32-bit type hack. */
2114 DBGFREG_32BIT_HACK = 0x7fffffff
2115} DBGFREG;
2116/** Pointer to a register identifier. */
2117typedef DBGFREG *PDBGFREG;
2118/** Pointer to a const register identifier. */
2119typedef DBGFREG const *PCDBGFREG;
2120
2121/**
2122 * Register value type.
2123 */
2124typedef enum DBGFREGVALTYPE
2125{
2126 DBGFREGVALTYPE_INVALID = 0,
2127 /** Unsigned 8-bit register value. */
2128 DBGFREGVALTYPE_U8,
2129 /** Unsigned 16-bit register value. */
2130 DBGFREGVALTYPE_U16,
2131 /** Unsigned 32-bit register value. */
2132 DBGFREGVALTYPE_U32,
2133 /** Unsigned 64-bit register value. */
2134 DBGFREGVALTYPE_U64,
2135 /** Unsigned 128-bit register value. */
2136 DBGFREGVALTYPE_U128,
2137 /** Unsigned 256-bit register value. */
2138 DBGFREGVALTYPE_U256,
2139 /** Unsigned 512-bit register value. */
2140 DBGFREGVALTYPE_U512,
2141 /** Long double register value. */
2142 DBGFREGVALTYPE_R80,
2143 /** Descriptor table register value. */
2144 DBGFREGVALTYPE_DTR,
2145 /** End of the valid register value types. */
2146 DBGFREGVALTYPE_END,
2147 /** The usual 32-bit type hack. */
2148 DBGFREGVALTYPE_32BIT_HACK = 0x7fffffff
2149} DBGFREGVALTYPE;
2150/** Pointer to a register value type. */
2151typedef DBGFREGVALTYPE *PDBGFREGVALTYPE;
2152
2153/**
2154 * A generic register value type.
2155 */
2156typedef union DBGFREGVAL
2157{
2158 uint64_t au64[8]; /**< The 64-bit array view. First because of the initializer. */
2159 uint32_t au32[16]; /**< The 32-bit array view. */
2160 uint16_t au16[32]; /**< The 16-bit array view. */
2161 uint8_t au8[64]; /**< The 8-bit array view. */
2162
2163 uint8_t u8; /**< The 8-bit view. */
2164 uint16_t u16; /**< The 16-bit view. */
2165 uint32_t u32; /**< The 32-bit view. */
2166 uint64_t u64; /**< The 64-bit view. */
2167 RTUINT128U u128; /**< The 128-bit view. */
2168 RTUINT256U u256; /**< The 256-bit view. */
2169 RTUINT512U u512; /**< The 512-bit view. */
2170 RTFLOAT80U r80; /**< The 80-bit floating point view. */
2171 RTFLOAT80U2 r80Ex; /**< The 80-bit floating point view v2. */
2172 /** GDTR or LDTR (DBGFREGVALTYPE_DTR). */
2173 struct
2174 {
2175 /** The table address. */
2176 uint64_t u64Base;
2177 /** The table limit (length minus 1). */
2178 uint32_t u32Limit; /**< @todo Limit should be uint16_t */
2179 } dtr;
2180} DBGFREGVAL;
2181/** Pointer to a generic register value type. */
2182typedef DBGFREGVAL *PDBGFREGVAL;
2183/** Pointer to a const generic register value type. */
2184typedef DBGFREGVAL const *PCDBGFREGVAL;
2185
2186/** Initialize a DBGFREGVAL variable to all zeros. */
2187#define DBGFREGVAL_INITIALIZE_ZERO { { 0, 0, 0, 0, 0, 0, 0, 0 } }
2188/** Initialize a DBGFREGVAL variable to all bits set . */
2189#define DBGFREGVAL_INITIALIZE_FFFF { { UINT64_MAX, UINT64_MAX, UINT64_MAX, UINT64_MAX, UINT64_MAX, UINT64_MAX, UINT64_MAX, UINT64_MAX } }
2190
2191/**
2192 * Extended register value, including register ID and type.
2193 *
2194 * This is currently only used by the stack walker.
2195 */
2196typedef struct DBGFREGVALEX
2197{
2198 /** The register value. */
2199 DBGFREGVAL Value;
2200 /** The register value type. */
2201 DBGFREGVALTYPE enmType;
2202 /** The register ID, DBGFREG_END if not applicable. */
2203 DBGFREG enmReg;
2204 /** Pointer to read-only register name string if no register ID could be found. */
2205 const char *pszName;
2206} DBGFREGVALEX;
2207/** Pointer to an extended register value struct. */
2208typedef DBGFREGVALEX *PDBGFREGVALEX;
2209/** Pointer to a const extended register value struct. */
2210typedef DBGFREGVALEX const *PCDBGFREGVALEX;
2211
2212
2213VMMDECL(ssize_t) DBGFR3RegFormatValue(char *pszBuf, size_t cbBuf, PCDBGFREGVAL pValue, DBGFREGVALTYPE enmType, bool fSpecial);
2214VMMDECL(ssize_t) DBGFR3RegFormatValueEx(char *pszBuf, size_t cbBuf, PCDBGFREGVAL pValue, DBGFREGVALTYPE enmType,
2215 unsigned uBase, signed int cchWidth, signed int cchPrecision, uint32_t fFlags);
2216
2217/**
2218 * Register sub-field descriptor.
2219 */
2220typedef struct DBGFREGSUBFIELD
2221{
2222 /** The name of the sub-field. NULL is used to terminate the array. */
2223 const char *pszName;
2224 /** The index of the first bit. Ignored if pfnGet is set. */
2225 uint8_t iFirstBit;
2226 /** The number of bits. Mandatory. */
2227 uint8_t cBits;
2228 /** The shift count. Not applied when pfnGet is set, but used to
2229 * calculate the minimum type. */
2230 int8_t cShift;
2231 /** Sub-field flags, DBGFREGSUBFIELD_FLAGS_XXX. */
2232 uint8_t fFlags;
2233 /** Getter (optional).
2234 * @remarks Does not take the device lock or anything like that.
2235 */
2236 DECLCALLBACKMEMBER(int, pfnGet,(void *pvUser, struct DBGFREGSUBFIELD const *pSubField, PRTUINT128U puValue));
2237 /** Setter (optional).
2238 * @remarks Does not take the device lock or anything like that.
2239 */
2240 DECLCALLBACKMEMBER(int, pfnSet,(void *pvUser, struct DBGFREGSUBFIELD const *pSubField, RTUINT128U uValue, RTUINT128U fMask));
2241} DBGFREGSUBFIELD;
2242/** Pointer to a const register sub-field descriptor. */
2243typedef DBGFREGSUBFIELD const *PCDBGFREGSUBFIELD;
2244
2245/** @name DBGFREGSUBFIELD_FLAGS_XXX
2246 * @{ */
2247/** The sub-field is read-only. */
2248#define DBGFREGSUBFIELD_FLAGS_READ_ONLY UINT8_C(0x01)
2249/** @} */
2250
2251/** Macro for creating a read-write sub-field entry without getters. */
2252#define DBGFREGSUBFIELD_RW(a_szName, a_iFirstBit, a_cBits, a_cShift) \
2253 { a_szName, a_iFirstBit, a_cBits, a_cShift, 0 /*fFlags*/, NULL /*pfnGet*/, NULL /*pfnSet*/ }
2254/** Macro for creating a read-write sub-field entry with getters. */
2255#define DBGFREGSUBFIELD_RW_SG(a_szName, a_cBits, a_cShift, a_pfnGet, a_pfnSet) \
2256 { a_szName, 0 /*iFirstBit*/, a_cBits, a_cShift, 0 /*fFlags*/, a_pfnGet, a_pfnSet }
2257/** Macro for creating a read-only sub-field entry without getters. */
2258#define DBGFREGSUBFIELD_RO(a_szName, a_iFirstBit, a_cBits, a_cShift) \
2259 { a_szName, a_iFirstBit, a_cBits, a_cShift, DBGFREGSUBFIELD_FLAGS_READ_ONLY, NULL /*pfnGet*/, NULL /*pfnSet*/ }
2260/** Macro for creating a terminator sub-field entry. */
2261#define DBGFREGSUBFIELD_TERMINATOR() \
2262 { NULL, 0, 0, 0, 0, NULL, NULL }
2263
2264/**
2265 * Register alias descriptor.
2266 */
2267typedef struct DBGFREGALIAS
2268{
2269 /** The alias name. NULL is used to terminate the array. */
2270 const char *pszName;
2271 /** Set to a valid type if the alias has a different type. */
2272 DBGFREGVALTYPE enmType;
2273} DBGFREGALIAS;
2274/** Pointer to a const register alias descriptor. */
2275typedef DBGFREGALIAS const *PCDBGFREGALIAS;
2276
2277/**
2278 * Register descriptor.
2279 */
2280typedef struct DBGFREGDESC
2281{
2282 /** The normal register name. */
2283 const char *pszName;
2284 /** The register identifier if this is a CPU register. */
2285 DBGFREG enmReg;
2286 /** The default register type. */
2287 DBGFREGVALTYPE enmType;
2288 /** Flags, see DBGFREG_FLAGS_XXX. */
2289 uint32_t fFlags;
2290 /** The internal register indicator.
2291 * For CPU registers this is the offset into the CPUMCTX structure,
2292 * thuse the 'off' prefix. */
2293 uint32_t offRegister;
2294 /** Getter.
2295 * @remarks Does not take the device lock or anything like that.
2296 */
2297 DECLCALLBACKMEMBER(int, pfnGet,(void *pvUser, struct DBGFREGDESC const *pDesc, PDBGFREGVAL pValue));
2298 /** Setter.
2299 * @remarks Does not take the device lock or anything like that.
2300 */
2301 DECLCALLBACKMEMBER(int, pfnSet,(void *pvUser, struct DBGFREGDESC const *pDesc, PCDBGFREGVAL pValue, PCDBGFREGVAL pfMask));
2302 /** Aliases (optional). */
2303 PCDBGFREGALIAS paAliases;
2304 /** Sub fields (optional). */
2305 PCDBGFREGSUBFIELD paSubFields;
2306} DBGFREGDESC;
2307
2308/** @name Macros for constructing DBGFREGDESC arrays.
2309 * @{ */
2310#define DBGFREGDESC_RW(a_szName, a_TypeSuff, a_offRegister, a_pfnGet, a_pfnSet) \
2311 { a_szName, DBGFREG_END, DBGFREGVALTYPE_##a_TypeSuff, 0 /*fFlags*/, a_offRegister, a_pfnGet, a_pfnSet, NULL /*paAlises*/, NULL /*paSubFields*/ }
2312#define DBGFREGDESC_RO(a_szName, a_TypeSuff, a_offRegister, a_pfnGet, a_pfnSet) \
2313 { a_szName, DBGFREG_END, DBGFREGVALTYPE_##a_TypeSuff, DBGFREG_FLAGS_READ_ONLY, a_offRegister, a_pfnGet, a_pfnSet, NULL /*paAlises*/, NULL /*paSubFields*/ }
2314#define DBGFREGDESC_RW_A(a_szName, a_TypeSuff, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases) \
2315 { a_szName, DBGFREG_END, DBGFREGVALTYPE_##a_TypeSuff, 0 /*fFlags*/, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases, NULL /*paSubFields*/ }
2316#define DBGFREGDESC_RO_A(a_szName, a_TypeSuff, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases) \
2317 { a_szName, DBGFREG_END, DBGFREGVALTYPE_##a_TypeSuff, DBGFREG_FLAGS_READ_ONLY, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases, NULL /*paSubFields*/ }
2318#define DBGFREGDESC_RW_S(a_szName, a_TypeSuff, a_offRegister, a_pfnGet, a_pfnSet, a_paSubFields) \
2319 { a_szName, DBGFREG_END, DBGFREGVALTYPE_##a_TypeSuff, 0 /*fFlags*/, a_offRegister, a_pfnGet, a_pfnSet, /*paAliases*/, a_paSubFields }
2320#define DBGFREGDESC_RO_S(a_szName, a_TypeSuff, a_offRegister, a_pfnGet, a_pfnSet, a_paSubFields) \
2321 { a_szName, DBGFREG_END, DBGFREGVALTYPE_##a_TypeSuff, DBGFREG_FLAGS_READ_ONLY, a_offRegister, a_pfnGet, a_pfnSet, /*paAliases*/, a_paSubFields }
2322#define DBGFREGDESC_RW_AS(a_szName, a_TypeSuff, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields) \
2323 { a_szName, DBGFREG_END, DBGFREGVALTYPE_##a_TypeSuff, 0 /*fFlags*/, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields }
2324#define DBGFREGDESC_RO_AS(a_szName, a_TypeSuff, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields) \
2325 { a_szName, DBGFREG_END, DBGFREGVALTYPE_##a_TypeSuff, DBGFREG_FLAGS_READ_ONLY, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields }
2326#define DBGFREGDESC_TERMINATOR() \
2327 { NULL, DBGFREG_END, DBGFREGVALTYPE_INVALID, 0, 0, NULL, NULL, NULL, NULL }
2328/** @} */
2329
2330
2331/** @name DBGFREG_FLAGS_XXX
2332 * @{ */
2333/** The register is read-only. */
2334#define DBGFREG_FLAGS_READ_ONLY RT_BIT_32(0)
2335/** @} */
2336
2337/**
2338 * Entry in a batch query or set operation.
2339 */
2340typedef struct DBGFREGENTRY
2341{
2342 /** The register identifier. */
2343 DBGFREG enmReg;
2344 /** The size of the value in bytes. */
2345 DBGFREGVALTYPE enmType;
2346 /** The register value. The valid view is indicated by enmType. */
2347 DBGFREGVAL Val;
2348} DBGFREGENTRY;
2349/** Pointer to a register entry in a batch operation. */
2350typedef DBGFREGENTRY *PDBGFREGENTRY;
2351/** Pointer to a const register entry in a batch operation. */
2352typedef DBGFREGENTRY const *PCDBGFREGENTRY;
2353
2354/** Used with DBGFR3Reg* to indicate the hypervisor register set instead of the
2355 * guest. */
2356#define DBGFREG_HYPER_VMCPUID UINT32_C(0x01000000)
2357
2358VMMR3DECL(int) DBGFR3RegCpuQueryU8( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint8_t *pu8);
2359VMMR3DECL(int) DBGFR3RegCpuQueryU16( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint16_t *pu16);
2360VMMR3DECL(int) DBGFR3RegCpuQueryU32( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint32_t *pu32);
2361VMMR3DECL(int) DBGFR3RegCpuQueryU64( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint64_t *pu64);
2362VMMR3DECL(int) DBGFR3RegCpuQueryU128(PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint128_t *pu128);
2363VMMR3DECL(int) DBGFR3RegCpuQueryLrd( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, long double *plrd);
2364VMMR3DECL(int) DBGFR3RegCpuQueryXdtr(PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint64_t *pu64Base, uint16_t *pu16Limit);
2365#if 0
2366VMMR3DECL(int) DBGFR3RegCpuQueryBatch(PUVM pUVM,VMCPUID idCpu, PDBGFREGENTRY paRegs, size_t cRegs);
2367VMMR3DECL(int) DBGFR3RegCpuQueryAll( PUVM pUVM, VMCPUID idCpu, PDBGFREGENTRY paRegs, size_t cRegs);
2368
2369VMMR3DECL(int) DBGFR3RegCpuSetU8( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint8_t u8);
2370VMMR3DECL(int) DBGFR3RegCpuSetU16( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint16_t u16);
2371VMMR3DECL(int) DBGFR3RegCpuSetU32( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint32_t u32);
2372VMMR3DECL(int) DBGFR3RegCpuSetU64( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint64_t u64);
2373VMMR3DECL(int) DBGFR3RegCpuSetU128( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint128_t u128);
2374VMMR3DECL(int) DBGFR3RegCpuSetLrd( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, long double lrd);
2375VMMR3DECL(int) DBGFR3RegCpuSetBatch( PUVM pUVM, VMCPUID idCpu, PCDBGFREGENTRY paRegs, size_t cRegs);
2376#endif
2377
2378VMMR3DECL(const char *) DBGFR3RegCpuName(PUVM pUVM, DBGFREG enmReg, DBGFREGVALTYPE enmType);
2379
2380VMMR3_INT_DECL(int) DBGFR3RegRegisterCpu(PVM pVM, PVMCPU pVCpu, PCDBGFREGDESC paRegisters, bool fGuestRegs);
2381VMMR3_INT_DECL(int) DBGFR3RegRegisterDevice(PVM pVM, PCDBGFREGDESC paRegisters, PPDMDEVINS pDevIns,
2382 const char *pszPrefix, uint32_t iInstance);
2383
2384/**
2385 * Entry in a named batch query or set operation.
2386 */
2387typedef struct DBGFREGENTRYNM
2388{
2389 /** The register name. */
2390 const char *pszName;
2391 /** The size of the value in bytes. */
2392 DBGFREGVALTYPE enmType;
2393 /** The register value. The valid view is indicated by enmType. */
2394 DBGFREGVAL Val;
2395} DBGFREGENTRYNM;
2396/** Pointer to a named register entry in a batch operation. */
2397typedef DBGFREGENTRYNM *PDBGFREGENTRYNM;
2398/** Pointer to a const named register entry in a batch operation. */
2399typedef DBGFREGENTRYNM const *PCDBGFREGENTRYNM;
2400
2401VMMR3DECL(int) DBGFR3RegNmValidate( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg);
2402
2403VMMR3DECL(int) DBGFR3RegNmQuery( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, PDBGFREGVAL pValue, PDBGFREGVALTYPE penmType);
2404VMMR3DECL(int) DBGFR3RegNmQueryU8( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, uint8_t *pu8);
2405VMMR3DECL(int) DBGFR3RegNmQueryU16( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, uint16_t *pu16);
2406VMMR3DECL(int) DBGFR3RegNmQueryU32( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, uint32_t *pu32);
2407VMMR3DECL(int) DBGFR3RegNmQueryU64( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, uint64_t *pu64);
2408VMMR3DECL(int) DBGFR3RegNmQueryU128(PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, PRTUINT128U pu128);
2409/*VMMR3DECL(int) DBGFR3RegNmQueryLrd( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, long double *plrd);*/
2410VMMR3DECL(int) DBGFR3RegNmQueryXdtr(PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, uint64_t *pu64Base, uint16_t *pu16Limit);
2411VMMR3DECL(int) DBGFR3RegNmQueryBatch(PUVM pUVM,VMCPUID idDefCpu, PDBGFREGENTRYNM paRegs, size_t cRegs);
2412VMMR3DECL(int) DBGFR3RegNmQueryAllCount(PUVM pUVM, size_t *pcRegs);
2413VMMR3DECL(int) DBGFR3RegNmQueryAll( PUVM pUVM, PDBGFREGENTRYNM paRegs, size_t cRegs);
2414
2415VMMR3DECL(int) DBGFR3RegNmSet( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, PCDBGFREGVAL pValue, DBGFREGVALTYPE enmType);
2416VMMR3DECL(int) DBGFR3RegNmSetU8( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, uint8_t u8);
2417VMMR3DECL(int) DBGFR3RegNmSetU16( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, uint16_t u16);
2418VMMR3DECL(int) DBGFR3RegNmSetU32( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, uint32_t u32);
2419VMMR3DECL(int) DBGFR3RegNmSetU64( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, uint64_t u64);
2420VMMR3DECL(int) DBGFR3RegNmSetU128( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, RTUINT128U u128);
2421VMMR3DECL(int) DBGFR3RegNmSetLrd( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, long double lrd);
2422VMMR3DECL(int) DBGFR3RegNmSetBatch( PUVM pUVM, VMCPUID idDefCpu, PCDBGFREGENTRYNM paRegs, size_t cRegs);
2423
2424/** @todo add enumeration methods. */
2425
2426VMMR3DECL(int) DBGFR3RegPrintf( PUVM pUVM, VMCPUID idDefCpu, char *pszBuf, size_t cbBuf, const char *pszFormat, ...);
2427VMMR3DECL(int) DBGFR3RegPrintfV(PUVM pUVM, VMCPUID idDefCpu, char *pszBuf, size_t cbBuf, const char *pszFormat, va_list va);
2428
2429
2430#ifdef IN_RING3
2431
2432/**
2433 * Guest OS digger interface identifier.
2434 *
2435 * This is for use together with PDBGFR3QueryInterface and is used to
2436 * obtain access to optional interfaces.
2437 */
2438typedef enum DBGFOSINTERFACE
2439{
2440 /** The usual invalid entry. */
2441 DBGFOSINTERFACE_INVALID = 0,
2442 /** Process info. */
2443 DBGFOSINTERFACE_PROCESS,
2444 /** Thread info. */
2445 DBGFOSINTERFACE_THREAD,
2446 /** Kernel message log - DBGFOSIDMESG. */
2447 DBGFOSINTERFACE_DMESG,
2448 /** Windows NT specifics (for the communication with the KD debugger stub). */
2449 DBGFOSINTERFACE_WINNT,
2450 /** The end of the valid entries. */
2451 DBGFOSINTERFACE_END,
2452 /** The usual 32-bit type blowup. */
2453 DBGFOSINTERFACE_32BIT_HACK = 0x7fffffff
2454} DBGFOSINTERFACE;
2455/** Pointer to a Guest OS digger interface identifier. */
2456typedef DBGFOSINTERFACE *PDBGFOSINTERFACE;
2457/** Pointer to a const Guest OS digger interface identifier. */
2458typedef DBGFOSINTERFACE const *PCDBGFOSINTERFACE;
2459
2460
2461/**
2462 * Guest OS Digger Registration Record.
2463 *
2464 * This is used with the DBGFR3OSRegister() API.
2465 */
2466typedef struct DBGFOSREG
2467{
2468 /** Magic value (DBGFOSREG_MAGIC). */
2469 uint32_t u32Magic;
2470 /** Flags. Reserved. */
2471 uint32_t fFlags;
2472 /** The size of the instance data. */
2473 uint32_t cbData;
2474 /** Operative System name. */
2475 char szName[24];
2476
2477 /**
2478 * Constructs the instance.
2479 *
2480 * @returns VBox status code.
2481 * @param pUVM The user mode VM handle.
2482 * @param pvData Pointer to the instance data.
2483 */
2484 DECLCALLBACKMEMBER(int, pfnConstruct,(PUVM pUVM, void *pvData));
2485
2486 /**
2487 * Destroys the instance.
2488 *
2489 * @param pUVM The user mode VM handle.
2490 * @param pvData Pointer to the instance data.
2491 */
2492 DECLCALLBACKMEMBER(void, pfnDestruct,(PUVM pUVM, void *pvData));
2493
2494 /**
2495 * Probes the guest memory for OS finger prints.
2496 *
2497 * No setup or so is performed, it will be followed by a call to pfnInit
2498 * or pfnRefresh that should take care of that.
2499 *
2500 * @returns true if is an OS handled by this module, otherwise false.
2501 * @param pUVM The user mode VM handle.
2502 * @param pvData Pointer to the instance data.
2503 */
2504 DECLCALLBACKMEMBER(bool, pfnProbe,(PUVM pUVM, void *pvData));
2505
2506 /**
2507 * Initializes a fresly detected guest, loading symbols and such useful stuff.
2508 *
2509 * This is called after pfnProbe.
2510 *
2511 * @returns VBox status code.
2512 * @param pUVM The user mode VM handle.
2513 * @param pvData Pointer to the instance data.
2514 */
2515 DECLCALLBACKMEMBER(int, pfnInit,(PUVM pUVM, void *pvData));
2516
2517 /**
2518 * Refreshes symbols and stuff following a redetection of the same OS.
2519 *
2520 * This is called after pfnProbe.
2521 *
2522 * @returns VBox status code.
2523 * @param pUVM The user mode VM handle.
2524 * @param pvData Pointer to the instance data.
2525 */
2526 DECLCALLBACKMEMBER(int, pfnRefresh,(PUVM pUVM, void *pvData));
2527
2528 /**
2529 * Terminates an OS when a new (or none) OS has been detected,
2530 * and before destruction.
2531 *
2532 * This is called after pfnProbe and if needed before pfnDestruct.
2533 *
2534 * @param pUVM The user mode VM handle.
2535 * @param pvData Pointer to the instance data.
2536 */
2537 DECLCALLBACKMEMBER(void, pfnTerm,(PUVM pUVM, void *pvData));
2538
2539 /**
2540 * Queries the version of the running OS.
2541 *
2542 * This is only called after pfnInit().
2543 *
2544 * @returns VBox status code.
2545 * @param pUVM The user mode VM handle.
2546 * @param pvData Pointer to the instance data.
2547 * @param pszVersion Where to store the version string.
2548 * @param cchVersion The size of the version string buffer.
2549 */
2550 DECLCALLBACKMEMBER(int, pfnQueryVersion,(PUVM pUVM, void *pvData, char *pszVersion, size_t cchVersion));
2551
2552 /**
2553 * Queries the pointer to a interface.
2554 *
2555 * This is called after pfnProbe.
2556 *
2557 * The returned interface must be valid until pfnDestruct is called. Two calls
2558 * to this method with the same @a enmIf value must return the same pointer.
2559 *
2560 * @returns Pointer to the interface if available, NULL if not available.
2561 * @param pUVM The user mode VM handle.
2562 * @param pvData Pointer to the instance data.
2563 * @param enmIf The interface identifier.
2564 */
2565 DECLCALLBACKMEMBER(void *, pfnQueryInterface,(PUVM pUVM, void *pvData, DBGFOSINTERFACE enmIf));
2566
2567 /**
2568 * Stack unwind assist callback.
2569 *
2570 * This is only called after pfnInit().
2571 *
2572 * @returns VBox status code (allocation error or something of similar fatality).
2573 * @param pUVM The user mode VM handle.
2574 * @param pvData Pointer to the instance data.
2575 * @param idCpu The CPU that's unwinding it's stack.
2576 * @param pFrame The current frame. Okay to modify it a little.
2577 * @param pState The unwind state. Okay to modify it.
2578 * @param pInitialCtx The initial register context.
2579 * @param hAs The address space being used for the unwind.
2580 * @param puScratch Scratch area (initialized to zero, no dtor).
2581 */
2582 DECLCALLBACKMEMBER(int, pfnStackUnwindAssist,(PUVM pUVM, void *pvData, VMCPUID idCpu, PDBGFSTACKFRAME pFrame,
2583 PRTDBGUNWINDSTATE pState, PCCPUMCTX pInitialCtx, RTDBGAS hAs,
2584 uint64_t *puScratch));
2585
2586 /** Trailing magic (DBGFOSREG_MAGIC). */
2587 uint32_t u32EndMagic;
2588} DBGFOSREG;
2589/** Pointer to a Guest OS digger registration record. */
2590typedef DBGFOSREG *PDBGFOSREG;
2591/** Pointer to a const Guest OS digger registration record. */
2592typedef DBGFOSREG const *PCDBGFOSREG;
2593
2594/** Magic value for DBGFOSREG::u32Magic and DBGFOSREG::u32EndMagic. (Hitomi Kanehara) */
2595#define DBGFOSREG_MAGIC 0x19830808
2596
2597
2598/**
2599 * Interface for querying kernel log messages (DBGFOSINTERFACE_DMESG).
2600 */
2601typedef struct DBGFOSIDMESG
2602{
2603 /** Trailing magic (DBGFOSIDMESG_MAGIC). */
2604 uint32_t u32Magic;
2605
2606 /**
2607 * Query the kernel log.
2608 *
2609 * @returns VBox status code.
2610 * @retval VERR_NOT_FOUND if the messages could not be located.
2611 * @retval VERR_INVALID_STATE if the messages was found to have unknown/invalid
2612 * format.
2613 * @retval VERR_BUFFER_OVERFLOW if the buffer isn't large enough, pcbActual
2614 * will be set to the required buffer size. The buffer, however, will
2615 * be filled with as much data as it can hold (properly zero terminated
2616 * of course).
2617 *
2618 * @param pThis Pointer to the interface structure.
2619 * @param pUVM The user mode VM handle.
2620 * @param fFlags Flags reserved for future use, MBZ.
2621 * @param cMessages The number of messages to retrieve, counting from the
2622 * end of the log (i.e. like tail), use UINT32_MAX for all.
2623 * @param pszBuf The output buffer.
2624 * @param cbBuf The buffer size.
2625 * @param pcbActual Where to store the number of bytes actually returned,
2626 * including zero terminator. On VERR_BUFFER_OVERFLOW this
2627 * holds the necessary buffer size. Optional.
2628 */
2629 DECLCALLBACKMEMBER(int, pfnQueryKernelLog,(struct DBGFOSIDMESG *pThis, PUVM pUVM, uint32_t fFlags, uint32_t cMessages,
2630 char *pszBuf, size_t cbBuf, size_t *pcbActual));
2631 /** Trailing magic (DBGFOSIDMESG_MAGIC). */
2632 uint32_t u32EndMagic;
2633} DBGFOSIDMESG;
2634/** Pointer to the interface for query kernel log messages (DBGFOSINTERFACE_DMESG). */
2635typedef DBGFOSIDMESG *PDBGFOSIDMESG;
2636/** Magic value for DBGFOSIDMESG::32Magic and DBGFOSIDMESG::u32EndMagic. (Kenazburo Oe) */
2637#define DBGFOSIDMESG_MAGIC UINT32_C(0x19350131)
2638
2639
2640/**
2641 * Interface for querying Windows NT guest specifics (DBGFOSINTERFACE_WINNT).
2642 */
2643typedef struct DBGFOSIWINNT
2644{
2645 /** Trailing magic (DBGFOSIWINNT_MAGIC). */
2646 uint32_t u32Magic;
2647
2648 /**
2649 * Queries version information.
2650 *
2651 * @returns VBox status code.
2652 * @param pThis Pointer to the interface structure.
2653 * @param pUVM The user mode VM handle.
2654 * @param puVersMajor Where to store the major version part, optional.
2655 * @param puVersMinor Where to store the minor version part, optional.
2656 * @param puBuildNumber Where to store the build number, optional.
2657 * @param pf32Bit Where to store the flag whether this is a 32bit Windows NT, optional.
2658 */
2659 DECLCALLBACKMEMBER(int, pfnQueryVersion,(struct DBGFOSIWINNT *pThis, PUVM pUVM,
2660 uint32_t *puVersMajor, uint32_t *puVersMinor,
2661 uint32_t *puBuildNumber, bool *pf32Bit));
2662
2663 /**
2664 * Queries some base kernel pointers.
2665 *
2666 * @returns VBox status code.
2667 * @param pThis Pointer to the interface structure.
2668 * @param pUVM The user mode VM handle.
2669 * @param pGCPtrKernBase Where to store the kernel base on success.
2670 * @param pGCPtrPsLoadedModuleList Where to store the pointer to the laoded module list head on success.
2671 */
2672 DECLCALLBACKMEMBER(int, pfnQueryKernelPtrs,(struct DBGFOSIWINNT *pThis, PUVM pUVM,
2673 PRTGCUINTPTR pGCPtrKernBase, PRTGCUINTPTR pGCPtrPsLoadedModuleList));
2674
2675 /**
2676 * Queries KPCR and KPCRB pointers for the given vCPU.
2677 *
2678 * @returns VBox status code.
2679 * @param pThis Pointer to the interface structure.
2680 * @param pUVM The user mode VM handle.
2681 * @param idCpu The vCPU to query the KPCR/KPCRB for.
2682 * @param pKpcr Where to store the KPCR pointer on success, optional.
2683 * @param pKpcrb Where to store the KPCR pointer on success, optional.
2684 */
2685 DECLCALLBACKMEMBER(int, pfnQueryKpcrForVCpu,(struct DBGFOSIWINNT *pThis, PUVM pUVM, VMCPUID idCpu,
2686 PRTGCUINTPTR pKpcr, PRTGCUINTPTR pKpcrb));
2687
2688 /**
2689 * Queries the current thread for the given vCPU.
2690 *
2691 * @returns VBox status code.
2692 * @param pThis Pointer to the interface structure.
2693 * @param pUVM The user mode VM handle.
2694 * @param idCpu The vCPU to query the KPCR/KPCRB for.
2695 * @param pCurThrd Where to store the CurrentThread pointer on success.
2696 */
2697 DECLCALLBACKMEMBER(int, pfnQueryCurThrdForVCpu,(struct DBGFOSIWINNT *pThis, PUVM pUVM, VMCPUID idCpu,
2698 PRTGCUINTPTR pCurThrd));
2699
2700 /** Trailing magic (DBGFOSIWINNT_MAGIC). */
2701 uint32_t u32EndMagic;
2702} DBGFOSIWINNT;
2703/** Pointer to the interface for query kernel log messages (DBGFOSINTERFACE_WINNT). */
2704typedef DBGFOSIWINNT *PDBGFOSIWINNT;
2705/** Magic value for DBGFOSIWINNT::32Magic and DBGFOSIWINNT::u32EndMagic. (Dave Cutler) */
2706#define DBGFOSIWINNT_MAGIC UINT32_C(0x19420313)
2707
2708
2709VMMR3DECL(int) DBGFR3OSRegister(PUVM pUVM, PCDBGFOSREG pReg);
2710VMMR3DECL(int) DBGFR3OSDeregister(PUVM pUVM, PCDBGFOSREG pReg);
2711VMMR3DECL(int) DBGFR3OSDetect(PUVM pUVM, char *pszName, size_t cchName);
2712VMMR3DECL(int) DBGFR3OSQueryNameAndVersion(PUVM pUVM, char *pszName, size_t cchName, char *pszVersion, size_t cchVersion);
2713VMMR3DECL(void *) DBGFR3OSQueryInterface(PUVM pUVM, DBGFOSINTERFACE enmIf);
2714
2715
2716VMMR3DECL(int) DBGFR3CoreWrite(PUVM pUVM, const char *pszFilename, bool fReplaceFile);
2717
2718
2719
2720/** @defgroup grp_dbgf_plug_in The DBGF Plug-in Interface
2721 * @{
2722 */
2723
2724/** The plug-in module name prefix. */
2725# define DBGF_PLUG_IN_PREFIX "DbgPlugIn"
2726
2727/** The name of the plug-in entry point (FNDBGFPLUGIN) */
2728# define DBGF_PLUG_IN_ENTRYPOINT "DbgPlugInEntry"
2729
2730/**
2731 * DBGF plug-in operations.
2732 */
2733typedef enum DBGFPLUGINOP
2734{
2735 /** The usual invalid first value. */
2736 DBGFPLUGINOP_INVALID,
2737 /** Initialize the plug-in for a VM, register all the stuff.
2738 * The plug-in will be unloaded on failure.
2739 * uArg: The full VirtualBox version, see VBox/version.h. */
2740 DBGFPLUGINOP_INIT,
2741 /** Terminate the plug-ing for a VM, deregister all the stuff.
2742 * The plug-in will be unloaded after this call regardless of the return
2743 * code. */
2744 DBGFPLUGINOP_TERM,
2745 /** The usual 32-bit hack. */
2746 DBGFPLUGINOP_32BIT_HACK = 0x7fffffff
2747} DBGFPLUGINOP;
2748
2749/**
2750 * DBGF plug-in main entry point.
2751 *
2752 * @returns VBox status code.
2753 *
2754 * @param enmOperation The operation.
2755 * @param pUVM The user mode VM handle. This may be NULL.
2756 * @param uArg Extra argument.
2757 */
2758typedef DECLCALLBACKTYPE(int, FNDBGFPLUGIN,(DBGFPLUGINOP enmOperation, PUVM pUVM, uintptr_t uArg));
2759/** Pointer to a FNDBGFPLUGIN. */
2760typedef FNDBGFPLUGIN *PFNDBGFPLUGIN;
2761
2762/** @copydoc FNDBGFPLUGIN */
2763DECLEXPORT(int) DbgPlugInEntry(DBGFPLUGINOP enmOperation, PUVM pUVM, uintptr_t uArg);
2764
2765VMMR3DECL(int) DBGFR3PlugInLoad(PUVM pUVM, const char *pszPlugIn, char *pszActual, size_t cbActual, PRTERRINFO pErrInfo);
2766VMMR3DECL(int) DBGFR3PlugInUnload(PUVM pUVM, const char *pszName);
2767VMMR3DECL(void) DBGFR3PlugInLoadAll(PUVM pUVM);
2768VMMR3DECL(void) DBGFR3PlugInUnloadAll(PUVM pUVM);
2769
2770/** @} */
2771
2772
2773/** @defgroup grp_dbgf_types The DBGF type system Interface.
2774 * @{
2775 */
2776
2777/** A few forward declarations. */
2778/** Pointer to a type registration structure. */
2779typedef struct DBGFTYPEREG *PDBGFTYPEREG;
2780/** Pointer to a const type registration structure. */
2781typedef const struct DBGFTYPEREG *PCDBGFTYPEREG;
2782/** Pointer to a typed buffer. */
2783typedef struct DBGFTYPEVAL *PDBGFTYPEVAL;
2784
2785/**
2786 * DBGF built-in types.
2787 */
2788typedef enum DBGFTYPEBUILTIN
2789{
2790 /** The usual invalid first value. */
2791 DBGFTYPEBUILTIN_INVALID,
2792 /** Unsigned 8bit integer. */
2793 DBGFTYPEBUILTIN_UINT8,
2794 /** Signed 8bit integer. */
2795 DBGFTYPEBUILTIN_INT8,
2796 /** Unsigned 16bit integer. */
2797 DBGFTYPEBUILTIN_UINT16,
2798 /** Signed 16bit integer. */
2799 DBGFTYPEBUILTIN_INT16,
2800 /** Unsigned 32bit integer. */
2801 DBGFTYPEBUILTIN_UINT32,
2802 /** Signed 32bit integer. */
2803 DBGFTYPEBUILTIN_INT32,
2804 /** Unsigned 64bit integer. */
2805 DBGFTYPEBUILTIN_UINT64,
2806 /** Signed 64bit integer. */
2807 DBGFTYPEBUILTIN_INT64,
2808 /** 32bit Guest pointer */
2809 DBGFTYPEBUILTIN_PTR32,
2810 /** 64bit Guest pointer */
2811 DBGFTYPEBUILTIN_PTR64,
2812 /** Guest pointer - size depends on the guest bitness */
2813 DBGFTYPEBUILTIN_PTR,
2814 /** Type indicating a size, like size_t this can have different sizes
2815 * on 32bit and 64bit systems */
2816 DBGFTYPEBUILTIN_SIZE,
2817 /** 32bit float. */
2818 DBGFTYPEBUILTIN_FLOAT32,
2819 /** 64bit float (also known as double). */
2820 DBGFTYPEBUILTIN_FLOAT64,
2821 /** Compund types like structs and unions. */
2822 DBGFTYPEBUILTIN_COMPOUND,
2823 /** The usual 32-bit hack. */
2824 DBGFTYPEBUILTIN_32BIT_HACK = 0x7fffffff
2825} DBGFTYPEBUILTIN;
2826/** Pointer to a built-in type. */
2827typedef DBGFTYPEBUILTIN *PDBGFTYPEBUILTIN;
2828/** Pointer to a const built-in type. */
2829typedef const DBGFTYPEBUILTIN *PCDBGFTYPEBUILTIN;
2830
2831/**
2832 * DBGF type value buffer.
2833 */
2834typedef union DBGFTYPEVALBUF
2835{
2836 uint8_t u8;
2837 int8_t i8;
2838 uint16_t u16;
2839 int16_t i16;
2840 uint32_t u32;
2841 int32_t i32;
2842 uint64_t u64;
2843 int64_t i64;
2844 float f32;
2845 double f64;
2846 uint64_t size; /* For the built-in size_t which can be either 32-bit or 64-bit. */
2847 RTGCPTR GCPtr;
2848 /** For embedded structs. */
2849 PDBGFTYPEVAL pVal;
2850} DBGFTYPEVALBUF;
2851/** Pointer to a value. */
2852typedef DBGFTYPEVALBUF *PDBGFTYPEVALBUF;
2853
2854/**
2855 * DBGF type value entry.
2856 */
2857typedef struct DBGFTYPEVALENTRY
2858{
2859 /** DBGF built-in type. */
2860 DBGFTYPEBUILTIN enmType;
2861 /** Size of the type. */
2862 size_t cbType;
2863 /** Number of entries, for arrays this can be > 1. */
2864 uint32_t cEntries;
2865 /** Value buffer, depends on whether this is an array. */
2866 union
2867 {
2868 /** Single value. */
2869 DBGFTYPEVALBUF Val;
2870 /** Pointer to the array of values. */
2871 PDBGFTYPEVALBUF pVal;
2872 } Buf;
2873} DBGFTYPEVALENTRY;
2874/** Pointer to a type value entry. */
2875typedef DBGFTYPEVALENTRY *PDBGFTYPEVALENTRY;
2876/** Pointer to a const type value entry. */
2877typedef const DBGFTYPEVALENTRY *PCDBGFTYPEVALENTRY;
2878
2879/**
2880 * DBGF typed value.
2881 */
2882typedef struct DBGFTYPEVAL
2883{
2884 /** Pointer to the registration structure for this type. */
2885 PCDBGFTYPEREG pTypeReg;
2886 /** Number of value entries. */
2887 uint32_t cEntries;
2888 /** Variable sized array of value entries. */
2889 DBGFTYPEVALENTRY aEntries[1];
2890} DBGFTYPEVAL;
2891
2892/**
2893 * DBGF type variant.
2894 */
2895typedef enum DBGFTYPEVARIANT
2896{
2897 /** The usual invalid first value. */
2898 DBGFTYPEVARIANT_INVALID,
2899 /** A struct. */
2900 DBGFTYPEVARIANT_STRUCT,
2901 /** Union. */
2902 DBGFTYPEVARIANT_UNION,
2903 /** Alias for an existing type. */
2904 DBGFTYPEVARIANT_ALIAS,
2905 /** The usual 32-bit hack. */
2906 DBGFTYPEVARIANT_32BIT_HACK = 0x7fffffff
2907} DBGFTYPEVARIANT;
2908
2909/** @name DBGFTYPEREGMEMBER Flags.
2910 * @{ */
2911/** The member is an array with a fixed size. */
2912# define DBGFTYPEREGMEMBER_F_ARRAY RT_BIT_32(0)
2913/** The member denotes a pointer. */
2914# define DBGFTYPEREGMEMBER_F_POINTER RT_BIT_32(1)
2915/** @} */
2916
2917/**
2918 * DBGF type member.
2919 */
2920typedef struct DBGFTYPEREGMEMBER
2921{
2922 /** Name of the member. */
2923 const char *pszName;
2924 /** Flags for this member, see DBGFTYPEREGMEMBER_F_XXX. */
2925 uint32_t fFlags;
2926 /** Type identifier. */
2927 const char *pszType;
2928 /** The number of elements in the array, only valid for arrays. */
2929 uint32_t cElements;
2930} DBGFTYPEREGMEMBER;
2931/** Pointer to a member. */
2932typedef DBGFTYPEREGMEMBER *PDBGFTYPEREGMEMBER;
2933/** Pointer to a const member. */
2934typedef const DBGFTYPEREGMEMBER *PCDBGFTYPEREGMEMBER;
2935
2936/** @name DBGFTYPEREG Flags.
2937 * @{ */
2938/** The type is a packed structure. */
2939# define DBGFTYPEREG_F_PACKED RT_BIT_32(0)
2940/** @} */
2941
2942/**
2943 * New type registration structure.
2944 */
2945typedef struct DBGFTYPEREG
2946{
2947 /** Name of the type. */
2948 const char *pszType;
2949 /** The type variant. */
2950 DBGFTYPEVARIANT enmVariant;
2951 /** Some registration flags, see DBGFTYPEREG_F_XXX. */
2952 uint32_t fFlags;
2953 /** Number of members this type has, only valid for structs or unions. */
2954 uint32_t cMembers;
2955 /** Pointer to the member fields, only valid for structs or unions. */
2956 PCDBGFTYPEREGMEMBER paMembers;
2957 /** Name of the aliased type for aliases. */
2958 const char *pszAliasedType;
2959} DBGFTYPEREG;
2960
2961/**
2962 * DBGF typed value dumper callback.
2963 *
2964 * @returns VBox status code. Any non VINF_SUCCESS status code will abort the dumping.
2965 *
2966 * @param off The byte offset of the entry from the start of the type.
2967 * @param pszField The name of the field for the value.
2968 * @param iLvl The current level.
2969 * @param enmType The type enum.
2970 * @param cbType Size of the type.
2971 * @param pValBuf Pointer to the value buffer.
2972 * @param cValBufs Number of value buffers (for arrays).
2973 * @param pvUser Opaque user data.
2974 */
2975typedef DECLCALLBACKTYPE(int, FNDBGFR3TYPEVALDUMP,(uint32_t off, const char *pszField, uint32_t iLvl,
2976 DBGFTYPEBUILTIN enmType, size_t cbType,
2977 PDBGFTYPEVALBUF pValBuf, uint32_t cValBufs, void *pvUser));
2978/** Pointer to a FNDBGFR3TYPEVALDUMP. */
2979typedef FNDBGFR3TYPEVALDUMP *PFNDBGFR3TYPEVALDUMP;
2980
2981/**
2982 * DBGF type information dumper callback.
2983 *
2984 * @returns VBox status code. Any non VINF_SUCCESS status code will abort the dumping.
2985 *
2986 * @param off The byte offset of the entry from the start of the type.
2987 * @param pszField The name of the field for the value.
2988 * @param iLvl The current level.
2989 * @param pszType The type of the field.
2990 * @param fTypeFlags Flags for this type, see DBGFTYPEREGMEMBER_F_XXX.
2991 * @param cElements Number of for the field ( > 0 for arrays).
2992 * @param pvUser Opaque user data.
2993 */
2994typedef DECLCALLBACKTYPE(int, FNDBGFR3TYPEDUMP,(uint32_t off, const char *pszField, uint32_t iLvl,
2995 const char *pszType, uint32_t fTypeFlags,
2996 uint32_t cElements, void *pvUser));
2997/** Pointer to a FNDBGFR3TYPEDUMP. */
2998typedef FNDBGFR3TYPEDUMP *PFNDBGFR3TYPEDUMP;
2999
3000VMMR3DECL(int) DBGFR3TypeRegister( PUVM pUVM, uint32_t cTypes, PCDBGFTYPEREG paTypes);
3001VMMR3DECL(int) DBGFR3TypeDeregister(PUVM pUVM, const char *pszType);
3002VMMR3DECL(int) DBGFR3TypeQueryReg( PUVM pUVM, const char *pszType, PCDBGFTYPEREG *ppTypeReg);
3003
3004VMMR3DECL(int) DBGFR3TypeQuerySize( PUVM pUVM, const char *pszType, size_t *pcbType);
3005VMMR3DECL(int) DBGFR3TypeSetSize( PUVM pUVM, const char *pszType, size_t cbType);
3006VMMR3DECL(int) DBGFR3TypeDumpEx( PUVM pUVM, const char *pszType, uint32_t fFlags,
3007 uint32_t cLvlMax, PFNDBGFR3TYPEDUMP pfnDump, void *pvUser);
3008VMMR3DECL(int) DBGFR3TypeQueryValByType(PUVM pUVM, PCDBGFADDRESS pAddress, const char *pszType,
3009 PDBGFTYPEVAL *ppVal);
3010VMMR3DECL(void) DBGFR3TypeValFree(PDBGFTYPEVAL pVal);
3011VMMR3DECL(int) DBGFR3TypeValDumpEx(PUVM pUVM, PCDBGFADDRESS pAddress, const char *pszType, uint32_t fFlags,
3012 uint32_t cLvlMax, FNDBGFR3TYPEVALDUMP pfnDump, void *pvUser);
3013
3014/** @} */
3015
3016
3017/** @defgroup grp_dbgf_flow The DBGF control flow graph Interface.
3018 * @{
3019 */
3020
3021/** A DBGF control flow graph handle. */
3022typedef struct DBGFFLOWINT *DBGFFLOW;
3023/** Pointer to a DBGF control flow graph handle. */
3024typedef DBGFFLOW *PDBGFFLOW;
3025/** A DBGF control flow graph basic block handle. */
3026typedef struct DBGFFLOWBBINT *DBGFFLOWBB;
3027/** Pointer to a DBGF control flow graph basic block handle. */
3028typedef DBGFFLOWBB *PDBGFFLOWBB;
3029/** A DBGF control flow graph branch table handle. */
3030typedef struct DBGFFLOWBRANCHTBLINT *DBGFFLOWBRANCHTBL;
3031/** Pointer to a DBGF flow control graph branch table handle. */
3032typedef DBGFFLOWBRANCHTBL *PDBGFFLOWBRANCHTBL;
3033/** A DBGF control flow graph iterator. */
3034typedef struct DBGFFLOWITINT *DBGFFLOWIT;
3035/** Pointer to a control flow graph iterator. */
3036typedef DBGFFLOWIT *PDBGFFLOWIT;
3037/** A DBGF control flow graph branch table iterator. */
3038typedef struct DBGFFLOWBRANCHTBLITINT *DBGFFLOWBRANCHTBLIT;
3039/** Pointer to a control flow graph branch table iterator. */
3040typedef DBGFFLOWBRANCHTBLIT *PDBGFFLOWBRANCHTBLIT;
3041
3042/** @name DBGFFLOWBB Flags.
3043 * @{ */
3044/** The basic block is the entry into the owning control flow graph. */
3045#define DBGF_FLOW_BB_F_ENTRY RT_BIT_32(0)
3046/** The basic block was not populated because the limit was reached. */
3047#define DBGF_FLOW_BB_F_EMPTY RT_BIT_32(1)
3048/** The basic block is not complete because an error happened during disassembly. */
3049#define DBGF_FLOW_BB_F_INCOMPLETE_ERR RT_BIT_32(2)
3050/** The basic block is reached through a branch table. */
3051#define DBGF_FLOW_BB_F_BRANCH_TABLE RT_BIT_32(3)
3052/** @} */
3053
3054/** @name Flags controlling the creating of a control flow graph.
3055 * @{ */
3056/** Default options. */
3057#define DBGF_FLOW_CREATE_F_DEFAULT 0
3058/** Tries to resolve indirect branches, useful for code using
3059 * jump tables generated for large switch statements by some compilers. */
3060#define DBGF_FLOW_CREATE_F_TRY_RESOLVE_INDIRECT_BRANCHES RT_BIT_32(0)
3061/** @} */
3062
3063/**
3064 * DBGF control graph basic block end type.
3065 */
3066typedef enum DBGFFLOWBBENDTYPE
3067{
3068 /** Invalid type. */
3069 DBGFFLOWBBENDTYPE_INVALID = 0,
3070 /** Basic block is the exit block and has no successor. */
3071 DBGFFLOWBBENDTYPE_EXIT,
3072 /** Basic block is the last disassembled block because the
3073 * maximum amount to disassemble was reached but is not an
3074 * exit block - no successors.
3075 */
3076 DBGFFLOWBBENDTYPE_LAST_DISASSEMBLED,
3077 /** Unconditional control flow change because the successor is referenced by multiple
3078 * basic blocks. - 1 successor. */
3079 DBGFFLOWBBENDTYPE_UNCOND,
3080 /** Unconditional control flow change because of an direct branch - 1 successor. */
3081 DBGFFLOWBBENDTYPE_UNCOND_JMP,
3082 /** Unconditional control flow change because of an indirect branch - n successors. */
3083 DBGFFLOWBBENDTYPE_UNCOND_INDIRECT_JMP,
3084 /** Conditional control flow change - 2 successors. */
3085 DBGFFLOWBBENDTYPE_COND,
3086 /** 32bit hack. */
3087 DBGFFLOWBBENDTYPE_32BIT_HACK = 0x7fffffff
3088} DBGFFLOWBBENDTYPE;
3089
3090/**
3091 * DBGF control flow graph iteration order.
3092 */
3093typedef enum DBGFFLOWITORDER
3094{
3095 /** Invalid order. */
3096 DBGFFLOWITORDER_INVALID = 0,
3097 /** From lowest to highest basic block start address. */
3098 DBGFFLOWITORDER_BY_ADDR_LOWEST_FIRST,
3099 /** From highest to lowest basic block start address. */
3100 DBGFFLOWITORDER_BY_ADDR_HIGHEST_FIRST,
3101 /** Depth first traversing starting from the entry block. */
3102 DBGFFLOWITORDER_DEPTH_FRIST,
3103 /** Breadth first traversing starting from the entry block. */
3104 DBGFFLOWITORDER_BREADTH_FIRST,
3105 /** Usual 32bit hack. */
3106 DBGFFLOWITORDER_32BIT_HACK = 0x7fffffff
3107} DBGFFLOWITORDER;
3108/** Pointer to a iteration order enum. */
3109typedef DBGFFLOWITORDER *PDBGFFLOWITORDER;
3110
3111
3112VMMR3DECL(int) DBGFR3FlowCreate(PUVM pUVM, VMCPUID idCpu, PDBGFADDRESS pAddressStart, uint32_t cbDisasmMax,
3113 uint32_t fFlagsFlow, uint32_t fFlagsDisasm, PDBGFFLOW phFlow);
3114VMMR3DECL(uint32_t) DBGFR3FlowRetain(DBGFFLOW hFlow);
3115VMMR3DECL(uint32_t) DBGFR3FlowRelease(DBGFFLOW hFlow);
3116VMMR3DECL(int) DBGFR3FlowQueryStartBb(DBGFFLOW hFlow, PDBGFFLOWBB phFlowBb);
3117VMMR3DECL(int) DBGFR3FlowQueryBbByAddress(DBGFFLOW hFlow, PDBGFADDRESS pAddr, PDBGFFLOWBB phFlowBb);
3118VMMR3DECL(int) DBGFR3FlowQueryBranchTblByAddress(DBGFFLOW hFlow, PDBGFADDRESS pAddr, PDBGFFLOWBRANCHTBL phFlowBranchTbl);
3119VMMR3DECL(uint32_t) DBGFR3FlowGetBbCount(DBGFFLOW hFlow);
3120VMMR3DECL(uint32_t) DBGFR3FlowGetBranchTblCount(DBGFFLOW hFlow);
3121
3122VMMR3DECL(uint32_t) DBGFR3FlowBbRetain(DBGFFLOWBB hFlowBb);
3123VMMR3DECL(uint32_t) DBGFR3FlowBbRelease(DBGFFLOWBB hFlowBb);
3124VMMR3DECL(PDBGFADDRESS) DBGFR3FlowBbGetStartAddress(DBGFFLOWBB hFlowBb, PDBGFADDRESS pAddrStart);
3125VMMR3DECL(PDBGFADDRESS) DBGFR3FlowBbGetEndAddress(DBGFFLOWBB hFlowBb, PDBGFADDRESS pAddrEnd);
3126VMMR3DECL(PDBGFADDRESS) DBGFR3FlowBbGetBranchAddress(DBGFFLOWBB hFlowBb, PDBGFADDRESS pAddrTarget);
3127VMMR3DECL(PDBGFADDRESS) DBGFR3FlowBbGetFollowingAddress(DBGFFLOWBB hFlowBb, PDBGFADDRESS pAddrFollow);
3128VMMR3DECL(DBGFFLOWBBENDTYPE) DBGFR3FlowBbGetType(DBGFFLOWBB hFlowBb);
3129VMMR3DECL(uint32_t) DBGFR3FlowBbGetInstrCount(DBGFFLOWBB hFlowBb);
3130VMMR3DECL(uint32_t) DBGFR3FlowBbGetFlags(DBGFFLOWBB hFlowBb);
3131VMMR3DECL(int) DBGFR3FlowBbQueryBranchTbl(DBGFFLOWBB hFlowBb, PDBGFFLOWBRANCHTBL phBranchTbl);
3132VMMR3DECL(int) DBGFR3FlowBbQueryError(DBGFFLOWBB hFlowBb, const char **ppszErr);
3133VMMR3DECL(int) DBGFR3FlowBbQueryInstr(DBGFFLOWBB hFlowBb, uint32_t idxInstr, PDBGFADDRESS pAddrInstr,
3134 uint32_t *pcbInstr, const char **ppszInstr);
3135VMMR3DECL(int) DBGFR3FlowBbQuerySuccessors(DBGFFLOWBB hFlowBb, PDBGFFLOWBB phFlowBbFollow,
3136 PDBGFFLOWBB phFlowBbTarget);
3137VMMR3DECL(uint32_t) DBGFR3FlowBbGetRefBbCount(DBGFFLOWBB hFlowBb);
3138VMMR3DECL(int) DBGFR3FlowBbGetRefBb(DBGFFLOWBB hFlowBb, PDBGFFLOWBB pahFlowBbRef, uint32_t cRef);
3139
3140VMMR3DECL(uint32_t) DBGFR3FlowBranchTblRetain(DBGFFLOWBRANCHTBL hFlowBranchTbl);
3141VMMR3DECL(uint32_t) DBGFR3FlowBranchTblRelease(DBGFFLOWBRANCHTBL hFlowBranchTbl);
3142VMMR3DECL(uint32_t) DBGFR3FlowBranchTblGetSlots(DBGFFLOWBRANCHTBL hFlowBranchTbl);
3143VMMR3DECL(PDBGFADDRESS) DBGFR3FlowBranchTblGetStartAddress(DBGFFLOWBRANCHTBL hFlowBranchTbl, PDBGFADDRESS pAddrStart);
3144VMMR3DECL(PDBGFADDRESS) DBGFR3FlowBranchTblGetAddrAtSlot(DBGFFLOWBRANCHTBL hFlowBranchTbl, uint32_t idxSlot, PDBGFADDRESS pAddrSlot);
3145VMMR3DECL(int) DBGFR3FlowBranchTblQueryAddresses(DBGFFLOWBRANCHTBL hFlowBranchTbl, PDBGFADDRESS paAddrs, uint32_t cAddrs);
3146
3147VMMR3DECL(int) DBGFR3FlowItCreate(DBGFFLOW hFlow, DBGFFLOWITORDER enmOrder, PDBGFFLOWIT phFlowIt);
3148VMMR3DECL(void) DBGFR3FlowItDestroy(DBGFFLOWIT hFlowIt);
3149VMMR3DECL(DBGFFLOWBB) DBGFR3FlowItNext(DBGFFLOWIT hFlowIt);
3150VMMR3DECL(int) DBGFR3FlowItReset(DBGFFLOWIT hFlowIt);
3151
3152VMMR3DECL(int) DBGFR3FlowBranchTblItCreate(DBGFFLOW hFlow, DBGFFLOWITORDER enmOrder, PDBGFFLOWBRANCHTBLIT phFlowBranchTblIt);
3153VMMR3DECL(void) DBGFR3FlowBranchTblItDestroy(DBGFFLOWBRANCHTBLIT hFlowBranchTblIt);
3154VMMR3DECL(DBGFFLOWBRANCHTBL) DBGFR3FlowBranchTblItNext(DBGFFLOWBRANCHTBLIT hFlowBranchTblIt);
3155VMMR3DECL(int) DBGFR3FlowBranchTblItReset(DBGFFLOWBRANCHTBLIT hFlowBranchTblIt);
3156
3157/** @} */
3158
3159
3160/** @defgroup grp_dbgf_misc Misc DBGF interfaces.
3161 * @{ */
3162VMMR3DECL(VBOXSTRICTRC) DBGFR3ReportBugCheck(PVM pVM, PVMCPU pVCpu, DBGFEVENTTYPE enmEvent, uint64_t uBugCheck,
3163 uint64_t uP1, uint64_t uP2, uint64_t uP3, uint64_t uP4);
3164VMMR3DECL(int) DBGFR3FormatBugCheck(PUVM pUVM, char *pszDetails, size_t cbDetails,
3165 uint64_t uP0, uint64_t uP1, uint64_t uP2, uint64_t uP3, uint64_t uP4);
3166/** @} */
3167#endif /* IN_RING3 */
3168
3169
3170/** @defgroup grp_dbgf_tracer DBGF event tracing.
3171 * @{ */
3172#ifdef IN_RING3
3173VMMR3_INT_DECL(int) DBGFR3TracerRegisterEvtSrc(PVM pVM, const char *pszName, PDBGFTRACEREVTSRC phEvtSrc);
3174VMMR3_INT_DECL(int) DBGFR3TracerDeregisterEvtSrc(PVM pVM, DBGFTRACEREVTSRC hEvtSrc);
3175VMMR3_INT_DECL(int) DBGFR3TracerEvtIoPortCreate(PVM pVM, DBGFTRACEREVTSRC hEvtSrc, uint64_t hRegion, RTIOPORT cPorts, uint32_t fFlags,
3176 uint32_t iPciRegion);
3177VMMR3_INT_DECL(int) DBGFR3TracerEvtMmioCreate(PVM pVM, DBGFTRACEREVTSRC hEvtSrc, uint64_t hRegion, RTGCPHYS cbRegion, uint32_t fFlags,
3178 uint32_t iPciRegion);
3179#endif
3180
3181VMM_INT_DECL(int) DBGFTracerEvtMmioMap(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, uint64_t hRegion, RTGCPHYS GCPhysMmio);
3182VMM_INT_DECL(int) DBGFTracerEvtMmioUnmap(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, uint64_t hRegion);
3183VMM_INT_DECL(int) DBGFTracerEvtMmioRead(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, uint64_t hRegion, RTGCPHYS offMmio, const void *pvVal, size_t cbVal);
3184VMM_INT_DECL(int) DBGFTracerEvtMmioWrite(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, uint64_t hRegion, RTGCPHYS offMmio, const void *pvVal, size_t cbVal);
3185VMM_INT_DECL(int) DBGFTracerEvtMmioFill(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, uint64_t hRegion, RTGCPHYS offMmio, uint32_t u32Item, uint32_t cbItem, uint32_t cItems);
3186VMM_INT_DECL(int) DBGFTracerEvtIoPortMap(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, uint64_t hIoPorts, RTIOPORT IoPortBase);
3187VMM_INT_DECL(int) DBGFTracerEvtIoPortUnmap(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, uint64_t hIoPorts);
3188VMM_INT_DECL(int) DBGFTracerEvtIoPortRead(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, uint64_t hIoPorts, RTIOPORT offPort, const void *pvVal, size_t cbVal);
3189VMM_INT_DECL(int) DBGFTracerEvtIoPortReadStr(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, uint64_t hIoPorts, RTIOPORT offPort, const void *pv, size_t cb,
3190 uint32_t cTransfersReq, uint32_t cTransfersRet);
3191VMM_INT_DECL(int) DBGFTracerEvtIoPortWrite(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, uint64_t hIoPorts, RTIOPORT offPort, const void *pvVal, size_t cbVal);
3192VMM_INT_DECL(int) DBGFTracerEvtIoPortWriteStr(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, uint64_t hIoPorts, RTIOPORT offPort, const void *pv, size_t cb,
3193 uint32_t cTransfersReq, uint32_t cTransfersRet);
3194VMM_INT_DECL(int) DBGFTracerEvtIrq(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, int32_t iIrq, int32_t fIrqLvl);
3195VMM_INT_DECL(int) DBGFTracerEvtIoApicMsi(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, RTGCPHYS GCPhys, uint32_t u32Val);
3196VMM_INT_DECL(int) DBGFTracerEvtGCPhysRead(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, RTGCPHYS GCPhys, const void *pvBuf, size_t cbRead);
3197VMM_INT_DECL(int) DBGFTracerEvtGCPhysWrite(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite);
3198/** @} */
3199
3200/** @} */
3201
3202RT_C_DECLS_END
3203
3204#endif /* !VBOX_INCLUDED_vmm_dbgf_h */
3205
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette