VirtualBox

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

Last change on this file since 90347 was 89980, checked in by vboxsync, 4 years ago

VMM/HMVMX: Add debug event and dtrace probe for the split-lock #ACs. bugref:10052

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

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