VirtualBox

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

Last change on this file since 90828 was 90549, checked in by vboxsync, 3 years ago

VMM,*: s/DBGFR3InfoGenricGetOptError/DBGFR3InfoGenericGetOptError/g

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 133.7 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(int) DBGFR0BpOwnerSetUpContext(PGVM pGVM, DBGFBPOWNER hBpOwner, PFNDBGFBPHIT pfnBpHit, PFNDBGFBPIOHIT pfnBpIoHit);
1098VMMR0_INT_DECL(int) DBGFR0BpOwnerDestroyContext(PGVM pGVM, DBGFBPOWNER hBpOwner);
1099
1100VMMR0_INT_DECL(int) DBGFR0BpSetUpContext(PGVM pGVM, DBGFBP hBp, void *pvUser);
1101VMMR0_INT_DECL(int) DBGFR0BpDestroyContext(PGVM pGVM, DBGFBP hBp);
1102/** @} */
1103#endif /* IN_RING0 || DOXYGEN_RUNNING */
1104
1105VMM_INT_DECL(RTGCUINTREG) DBGFBpGetDR7(PVM pVM);
1106VMM_INT_DECL(RTGCUINTREG) DBGFBpGetDR0(PVM pVM);
1107VMM_INT_DECL(RTGCUINTREG) DBGFBpGetDR1(PVM pVM);
1108VMM_INT_DECL(RTGCUINTREG) DBGFBpGetDR2(PVM pVM);
1109VMM_INT_DECL(RTGCUINTREG) DBGFBpGetDR3(PVM pVM);
1110VMM_INT_DECL(bool) DBGFBpIsHwArmed(PVM pVM);
1111VMM_INT_DECL(bool) DBGFBpIsHwIoArmed(PVM pVM);
1112VMM_INT_DECL(bool) DBGFBpIsInt3Armed(PVM pVM);
1113VMM_INT_DECL(bool) DBGFIsStepping(PVMCPU pVCpu);
1114VMM_INT_DECL(VBOXSTRICTRC) DBGFBpCheckIo(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, RTIOPORT uIoPort, uint8_t cbValue);
1115VMM_INT_DECL(VBOXSTRICTRC) DBGFBpCheckPortIo(PVMCC pVM, PVMCPU pVCpu, RTIOPORT uIoPort,
1116 uint32_t fAccess, uint32_t uValue, bool fBefore);
1117VMM_INT_DECL(VBOXSTRICTRC) DBGFEventGenericWithArgs(PVM pVM, PVMCPU pVCpu, DBGFEVENTTYPE enmEvent, DBGFEVENTCTX enmCtx,
1118 unsigned cArgs, ...);
1119VMM_INT_DECL(int) DBGFTrap01Handler(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, RTGCUINTREG uDr6, bool fAltStepping);
1120VMM_INT_DECL(int) DBGFTrap03Handler(PVMCC pVM, PVMCPUCC pVCpu, PCPUMCTXCORE pRegFrame);
1121
1122
1123#ifdef IN_RING3 /* The CPU mode API only works in ring-3. */
1124VMMR3DECL(CPUMMODE) DBGFR3CpuGetMode(PUVM pUVM, VMCPUID idCpu);
1125VMMR3DECL(VMCPUID) DBGFR3CpuGetCount(PUVM pUVM);
1126VMMR3DECL(bool) DBGFR3CpuIsIn64BitCode(PUVM pUVM, VMCPUID idCpu);
1127VMMR3DECL(bool) DBGFR3CpuIsInV86Code(PUVM pUVM, VMCPUID idCpu);
1128VMMR3DECL(const char *) DBGFR3CpuGetState(PUVM pUVM, VMCPUID idCpu);
1129#endif
1130
1131
1132
1133#ifdef IN_RING3 /* The info callbacks API only works in ring-3. */
1134
1135struct RTGETOPTSTATE;
1136union RTGETOPTUNION;
1137
1138/**
1139 * Info helper callback structure.
1140 */
1141typedef struct DBGFINFOHLP
1142{
1143 /**
1144 * Print formatted string.
1145 *
1146 * @param pHlp Pointer to this structure.
1147 * @param pszFormat The format string.
1148 * @param ... Arguments.
1149 */
1150 DECLCALLBACKMEMBER(void, pfnPrintf,(PCDBGFINFOHLP pHlp, const char *pszFormat, ...)) RT_IPRT_FORMAT_ATTR(2, 3);
1151
1152 /**
1153 * Print formatted string.
1154 *
1155 * @param pHlp Pointer to this structure.
1156 * @param pszFormat The format string.
1157 * @param args Argument list.
1158 */
1159 DECLCALLBACKMEMBER(void, pfnPrintfV,(PCDBGFINFOHLP pHlp, const char *pszFormat, va_list args)) RT_IPRT_FORMAT_ATTR(2, 0);
1160
1161 /**
1162 * Report getopt parsing trouble
1163 *
1164 * @param pHlp Pointer to this structure.
1165 * @param rc The RTGetOpt return value.
1166 * @param pValueUnion The value union.
1167 * @param pState The getopt state.
1168 */
1169 DECLCALLBACKMEMBER(void, pfnGetOptError,(PCDBGFINFOHLP pHlp, int rc, union RTGETOPTUNION *pValueUnion,
1170 struct RTGETOPTSTATE *pState));
1171} DBGFINFOHLP;
1172
1173
1174/**
1175 * Info handler, device version.
1176 *
1177 * @param pDevIns The device instance which registered the info.
1178 * @param pHlp Callback functions for doing output.
1179 * @param pszArgs Argument string. Optional and specific to the handler.
1180 */
1181typedef DECLCALLBACKTYPE(void, FNDBGFHANDLERDEV,(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs));
1182/** Pointer to a FNDBGFHANDLERDEV function. */
1183typedef FNDBGFHANDLERDEV *PFNDBGFHANDLERDEV;
1184
1185/**
1186 * Info handler, driver version.
1187 *
1188 * @param pDrvIns The driver instance which registered the info.
1189 * @param pHlp Callback functions for doing output.
1190 * @param pszArgs Argument string. Optional and specific to the handler.
1191 */
1192typedef DECLCALLBACKTYPE(void, FNDBGFHANDLERDRV,(PPDMDRVINS pDrvIns, PCDBGFINFOHLP pHlp, const char *pszArgs));
1193/** Pointer to a FNDBGFHANDLERDRV function. */
1194typedef FNDBGFHANDLERDRV *PFNDBGFHANDLERDRV;
1195
1196/**
1197 * Info handler, internal version.
1198 *
1199 * @param pVM The cross context VM structure.
1200 * @param pHlp Callback functions for doing output.
1201 * @param pszArgs Argument string. Optional and specific to the handler.
1202 */
1203typedef DECLCALLBACKTYPE(void, FNDBGFHANDLERINT,(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs));
1204/** Pointer to a FNDBGFHANDLERINT function. */
1205typedef FNDBGFHANDLERINT *PFNDBGFHANDLERINT;
1206
1207/**
1208 * Info handler, external version.
1209 *
1210 * @param pvUser User argument.
1211 * @param pHlp Callback functions for doing output.
1212 * @param pszArgs Argument string. Optional and specific to the handler.
1213 */
1214typedef DECLCALLBACKTYPE(void, FNDBGFHANDLEREXT,(void *pvUser, PCDBGFINFOHLP pHlp, const char *pszArgs));
1215/** Pointer to a FNDBGFHANDLEREXT function. */
1216typedef FNDBGFHANDLEREXT *PFNDBGFHANDLEREXT;
1217
1218/**
1219 * Info handler, device version with argv.
1220 *
1221 * @param pDevIns The device instance which registered the info.
1222 * @param pHlp Callback functions for doing output.
1223 * @param cArgs Number of arguments.
1224 * @param papszArgs Argument vector.
1225 */
1226typedef DECLCALLBACKTYPE(void, FNDBGFINFOARGVDEV,(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, int cArgs, char **papszArgs));
1227/** Pointer to a FNDBGFINFOARGVDEV function. */
1228typedef FNDBGFINFOARGVDEV *PFNDBGFINFOARGVDEV;
1229
1230/**
1231 * Info handler, USB device version with argv.
1232 *
1233 * @param pUsbIns The USB device instance which registered the info.
1234 * @param pHlp Callback functions for doing output.
1235 * @param cArgs Number of arguments.
1236 * @param papszArgs Argument vector.
1237 */
1238typedef DECLCALLBACKTYPE(void, FNDBGFINFOARGVUSB,(PPDMUSBINS pUsbIns, PCDBGFINFOHLP pHlp, int cArgs, char **papszArgs));
1239/** Pointer to a FNDBGFINFOARGVUSB function. */
1240typedef FNDBGFINFOARGVUSB *PFNDBGFINFOARGVUSB;
1241
1242/**
1243 * Info handler, driver version with argv.
1244 *
1245 * @param pDrvIns The driver instance which registered the info.
1246 * @param pHlp Callback functions for doing output.
1247 * @param cArgs Number of arguments.
1248 * @param papszArgs Argument vector.
1249 */
1250typedef DECLCALLBACKTYPE(void, FNDBGFINFOARGVDRV,(PPDMDRVINS pDrvIns, PCDBGFINFOHLP pHlp, int cArgs, char **papszArgs));
1251/** Pointer to a FNDBGFINFOARGVDRV function. */
1252typedef FNDBGFINFOARGVDRV *PFNDBGFINFOARGVDRV;
1253
1254/**
1255 * Info handler, internal version with argv.
1256 *
1257 * @param pVM The cross context VM structure.
1258 * @param pHlp Callback functions for doing output.
1259 * @param cArgs Number of arguments.
1260 * @param papszArgs Argument vector.
1261 */
1262typedef DECLCALLBACKTYPE(void, FNDBGFINFOARGVINT,(PVM pVM, PCDBGFINFOHLP pHlp, int cArgs, char **papszArgs));
1263/** Pointer to a FNDBGFINFOARGVINT function. */
1264typedef FNDBGFINFOARGVINT *PFNDBGFINFOARGVINT;
1265
1266/**
1267 * Info handler, external version with argv.
1268 *
1269 * @param pvUser User argument.
1270 * @param pHlp Callback functions for doing output.
1271 * @param cArgs Number of arguments.
1272 * @param papszArgs Argument vector.
1273 */
1274typedef DECLCALLBACKTYPE(void, FNDBGFINFOARGVEXT,(void *pvUser, PCDBGFINFOHLP pHlp, int cArgs, char **papszArgs));
1275/** Pointer to a FNDBGFINFOARGVEXT function. */
1276typedef FNDBGFINFOARGVEXT *PFNDBGFINFOARGVEXT;
1277
1278
1279/** @name Flags for the info registration functions.
1280 * @{ */
1281/** The handler must run on the EMT. */
1282#define DBGFINFO_FLAGS_RUN_ON_EMT RT_BIT(0)
1283/** Call on all EMTs when a specific isn't specified. */
1284#define DBGFINFO_FLAGS_ALL_EMTS RT_BIT(1)
1285/** @} */
1286
1287VMMR3_INT_DECL(int) DBGFR3InfoRegisterDevice(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDEV pfnHandler, PPDMDEVINS pDevIns);
1288VMMR3_INT_DECL(int) DBGFR3InfoRegisterDriver(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDRV pfnHandler, PPDMDRVINS pDrvIns);
1289VMMR3_INT_DECL(int) DBGFR3InfoRegisterInternal(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFHANDLERINT pfnHandler);
1290VMMR3_INT_DECL(int) DBGFR3InfoRegisterInternalEx(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFHANDLERINT pfnHandler, uint32_t fFlags);
1291VMMR3DECL(int) DBGFR3InfoRegisterExternal(PUVM pUVM, const char *pszName, const char *pszDesc, PFNDBGFHANDLEREXT pfnHandler, void *pvUser);
1292
1293VMMR3_INT_DECL(int) DBGFR3InfoRegisterDeviceArgv(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFINFOARGVDEV pfnHandler, PPDMDEVINS pDevIns);
1294VMMR3_INT_DECL(int) DBGFR3InfoRegisterDriverArgv(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFINFOARGVDRV pfnHandler, PPDMDRVINS pDrvIns);
1295VMMR3_INT_DECL(int) DBGFR3InfoRegisterUsbArgv(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFINFOARGVUSB pfnHandler, PPDMUSBINS pUsbIns);
1296VMMR3_INT_DECL(int) DBGFR3InfoRegisterInternalArgv(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFINFOARGVINT pfnHandler, uint32_t fFlags);
1297VMMR3DECL(int) DBGFR3InfoRegisterExternalArgv(PUVM pUVM, const char *pszName, const char *pszDesc, PFNDBGFINFOARGVEXT pfnHandler, void *pvUser);
1298
1299VMMR3_INT_DECL(int) DBGFR3InfoDeregisterDevice(PVM pVM, PPDMDEVINS pDevIns, const char *pszName);
1300VMMR3_INT_DECL(int) DBGFR3InfoDeregisterDriver(PVM pVM, PPDMDRVINS pDrvIns, const char *pszName);
1301VMMR3_INT_DECL(int) DBGFR3InfoDeregisterUsb(PVM pVM, PPDMUSBINS pDrvIns, const char *pszName);
1302VMMR3_INT_DECL(int) DBGFR3InfoDeregisterInternal(PVM pVM, const char *pszName);
1303VMMR3DECL(int) DBGFR3InfoDeregisterExternal(PUVM pUVM, const char *pszName);
1304
1305VMMR3DECL(int) DBGFR3Info(PUVM pUVM, const char *pszName, const char *pszArgs, PCDBGFINFOHLP pHlp);
1306VMMR3DECL(int) DBGFR3InfoEx(PUVM pUVM, VMCPUID idCpu, const char *pszName, const char *pszArgs, PCDBGFINFOHLP pHlp);
1307VMMR3DECL(int) DBGFR3InfoLogRel(PUVM pUVM, const char *pszName, const char *pszArgs);
1308VMMR3DECL(int) DBGFR3InfoStdErr(PUVM pUVM, const char *pszName, const char *pszArgs);
1309VMMR3_INT_DECL(int) DBGFR3InfoMulti(PVM pVM, const char *pszIncludePat, const char *pszExcludePat,
1310 const char *pszSepFmt, PCDBGFINFOHLP pHlp);
1311
1312/** @def DBGFR3_INFO_LOG
1313 * Display a piece of info writing to the log if enabled.
1314 *
1315 * This is for execution on EMTs and will only show the items on the calling
1316 * EMT. This is to avoid deadlocking against other CPUs if a rendezvous is
1317 * initiated in parallel to this call. (Besides, nobody really wants or need
1318 * info for the other EMTs when using this macro.)
1319 *
1320 * @param a_pVM The shared VM handle.
1321 * @param a_pVCpu The cross context per CPU structure of the calling EMT.
1322 * @param a_pszName The identifier of the info to display.
1323 * @param a_pszArgs Arguments to the info handler.
1324 */
1325#ifdef LOG_ENABLED
1326# define DBGFR3_INFO_LOG(a_pVM, a_pVCpu, a_pszName, a_pszArgs) \
1327 do { \
1328 if (LogIsEnabled()) \
1329 DBGFR3InfoEx((a_pVM)->pUVM, (a_pVCpu)->idCpu, a_pszName, a_pszArgs, NULL); \
1330 } while (0)
1331#else
1332# define DBGFR3_INFO_LOG(a_pVM, a_pVCpu, a_pszName, a_pszArgs) do { } while (0)
1333#endif
1334
1335/** @def DBGFR3_INFO_LOG_SAFE
1336 * Display a piece of info (rendezvous safe) writing to the log if enabled.
1337 *
1338 * @param a_pVM The shared VM handle.
1339 * @param a_pszName The identifier of the info to display.
1340 * @param a_pszArgs Arguments to the info handler.
1341 *
1342 * @remarks Use DBGFR3_INFO_LOG where ever possible!
1343 */
1344#ifdef LOG_ENABLED
1345# define DBGFR3_INFO_LOG_SAFE(a_pVM, a_pszName, a_pszArgs) \
1346 do { \
1347 if (LogIsEnabled()) \
1348 DBGFR3Info((a_pVM)->pUVM, a_pszName, a_pszArgs, NULL); \
1349 } while (0)
1350#else
1351# define DBGFR3_INFO_LOG_SAFE(a_pVM, a_pszName, a_pszArgs) do { } while (0)
1352#endif
1353
1354/**
1355 * Enumeration callback for use with DBGFR3InfoEnum.
1356 *
1357 * @returns VBox status code.
1358 * A status code indicating failure will end the enumeration
1359 * and DBGFR3InfoEnum will return with that status code.
1360 * @param pUVM The user mode VM handle.
1361 * @param pszName Info identifier name.
1362 * @param pszDesc The description.
1363 */
1364typedef DECLCALLBACKTYPE(int, FNDBGFINFOENUM,(PUVM pUVM, const char *pszName, const char *pszDesc, void *pvUser));
1365/** Pointer to a FNDBGFINFOENUM function. */
1366typedef FNDBGFINFOENUM *PFNDBGFINFOENUM;
1367
1368VMMR3DECL(int) DBGFR3InfoEnum(PUVM pUVM, PFNDBGFINFOENUM pfnCallback, void *pvUser);
1369VMMR3DECL(PCDBGFINFOHLP) DBGFR3InfoLogHlp(void);
1370VMMR3DECL(PCDBGFINFOHLP) DBGFR3InfoLogRelHlp(void);
1371VMMR3DECL(void) DBGFR3InfoGenericGetOptError(PCDBGFINFOHLP pHlp, int rc, union RTGETOPTUNION *pValueUnion,
1372 struct RTGETOPTSTATE *pState);
1373
1374#endif /* IN_RING3 */
1375
1376
1377#ifdef IN_RING3 /* The log contrl API only works in ring-3. */
1378VMMR3DECL(int) DBGFR3LogModifyGroups(PUVM pUVM, const char *pszGroupSettings);
1379VMMR3DECL(int) DBGFR3LogModifyFlags(PUVM pUVM, const char *pszFlagSettings);
1380VMMR3DECL(int) DBGFR3LogModifyDestinations(PUVM pUVM, const char *pszDestSettings);
1381#endif /* IN_RING3 */
1382
1383#ifdef IN_RING3 /* The debug information management APIs only works in ring-3. */
1384
1385/** Max length (including '\\0') of a symbol name. */
1386#define DBGF_SYMBOL_NAME_LENGTH 512
1387
1388/**
1389 * Debug symbol.
1390 */
1391typedef struct DBGFSYMBOL
1392{
1393 /** Symbol value (address). */
1394 RTGCUINTPTR Value;
1395 /** Symbol size. */
1396 uint32_t cb;
1397 /** Symbol Flags. (reserved). */
1398 uint32_t fFlags;
1399 /** Symbol name. */
1400 char szName[DBGF_SYMBOL_NAME_LENGTH];
1401} DBGFSYMBOL;
1402/** Pointer to debug symbol. */
1403typedef DBGFSYMBOL *PDBGFSYMBOL;
1404/** Pointer to const debug symbol. */
1405typedef const DBGFSYMBOL *PCDBGFSYMBOL;
1406
1407/**
1408 * Debug line number information.
1409 */
1410typedef struct DBGFLINE
1411{
1412 /** Address. */
1413 RTGCUINTPTR Address;
1414 /** Line number. */
1415 uint32_t uLineNo;
1416 /** Filename. */
1417 char szFilename[260];
1418} DBGFLINE;
1419/** Pointer to debug line number. */
1420typedef DBGFLINE *PDBGFLINE;
1421/** Pointer to const debug line number. */
1422typedef const DBGFLINE *PCDBGFLINE;
1423
1424/** @name Address spaces aliases.
1425 * @{ */
1426/** The guest global address space. */
1427#define DBGF_AS_GLOBAL ((RTDBGAS)-1)
1428/** The guest kernel address space.
1429 * This is usually resolves to the same as DBGF_AS_GLOBAL. */
1430#define DBGF_AS_KERNEL ((RTDBGAS)-2)
1431/** The physical address space. */
1432#define DBGF_AS_PHYS ((RTDBGAS)-3)
1433/** Raw-mode context. */
1434#define DBGF_AS_RC ((RTDBGAS)-4)
1435/** Ring-0 context. */
1436#define DBGF_AS_R0 ((RTDBGAS)-5)
1437/** Raw-mode context and then global guest context.
1438 * When used for looking up information, it works as if the call was first made
1439 * with DBGF_AS_RC and then on failure with DBGF_AS_GLOBAL. When called for
1440 * making address space changes, it works as if DBGF_AS_RC was used. */
1441#define DBGF_AS_RC_AND_GC_GLOBAL ((RTDBGAS)-6)
1442
1443/** The first special one. */
1444#define DBGF_AS_FIRST DBGF_AS_RC_AND_GC_GLOBAL
1445/** The last special one. */
1446#define DBGF_AS_LAST DBGF_AS_GLOBAL
1447#endif
1448/** The number of special address space handles. */
1449#define DBGF_AS_COUNT (6U)
1450#ifdef IN_RING3
1451/** Converts an alias handle to an array index. */
1452#define DBGF_AS_ALIAS_2_INDEX(hAlias) \
1453 ( (uintptr_t)(hAlias) - (uintptr_t)DBGF_AS_FIRST )
1454/** Predicat macro that check if the specified handle is an alias. */
1455#define DBGF_AS_IS_ALIAS(hAlias) \
1456 ( DBGF_AS_ALIAS_2_INDEX(hAlias) < DBGF_AS_COUNT )
1457/** Predicat macro that check if the specified alias is a fixed one or not. */
1458#define DBGF_AS_IS_FIXED_ALIAS(hAlias) \
1459 ( DBGF_AS_ALIAS_2_INDEX(hAlias) < (uintptr_t)DBGF_AS_PHYS - (uintptr_t)DBGF_AS_FIRST + 1U )
1460
1461/** @} */
1462
1463VMMR3DECL(RTDBGCFG) DBGFR3AsGetConfig(PUVM pUVM);
1464
1465VMMR3DECL(int) DBGFR3AsAdd(PUVM pUVM, RTDBGAS hDbgAs, RTPROCESS ProcId);
1466VMMR3DECL(int) DBGFR3AsDelete(PUVM pUVM, RTDBGAS hDbgAs);
1467VMMR3DECL(int) DBGFR3AsSetAlias(PUVM pUVM, RTDBGAS hAlias, RTDBGAS hAliasFor);
1468VMMR3DECL(RTDBGAS) DBGFR3AsResolve(PUVM pUVM, RTDBGAS hAlias);
1469VMMR3DECL(RTDBGAS) DBGFR3AsResolveAndRetain(PUVM pUVM, RTDBGAS hAlias);
1470VMMR3DECL(RTDBGAS) DBGFR3AsQueryByName(PUVM pUVM, const char *pszName);
1471VMMR3DECL(RTDBGAS) DBGFR3AsQueryByPid(PUVM pUVM, RTPROCESS ProcId);
1472
1473VMMR3DECL(int) DBGFR3AsLoadImage(PUVM pUVM, RTDBGAS hDbgAs, const char *pszFilename, const char *pszModName,
1474 RTLDRARCH enmArch, PCDBGFADDRESS pModAddress, RTDBGSEGIDX iModSeg, uint32_t fFlags);
1475VMMR3DECL(int) DBGFR3AsLoadMap(PUVM pUVM, RTDBGAS hDbgAs, const char *pszFilename, const char *pszModName, PCDBGFADDRESS pModAddress, RTDBGSEGIDX iModSeg, RTGCUINTPTR uSubtrahend, uint32_t fFlags);
1476VMMR3DECL(int) DBGFR3AsLinkModule(PUVM pUVM, RTDBGAS hDbgAs, RTDBGMOD hMod, PCDBGFADDRESS pModAddress, RTDBGSEGIDX iModSeg, uint32_t fFlags);
1477VMMR3DECL(int) DBGFR3AsUnlinkModuleByName(PUVM pUVM, RTDBGAS hDbgAs, const char *pszModName);
1478
1479VMMR3DECL(int) DBGFR3AsSymbolByAddr(PUVM pUVM, RTDBGAS hDbgAs, PCDBGFADDRESS pAddress, uint32_t fFlags,
1480 PRTGCINTPTR poffDisp, PRTDBGSYMBOL pSymbol, PRTDBGMOD phMod);
1481VMMR3DECL(PRTDBGSYMBOL) DBGFR3AsSymbolByAddrA(PUVM pUVM, RTDBGAS hDbgAs, PCDBGFADDRESS pAddress, uint32_t Flags,
1482 PRTGCINTPTR poffDisp, PRTDBGMOD phMod);
1483VMMR3DECL(int) DBGFR3AsSymbolByName(PUVM pUVM, RTDBGAS hDbgAs, const char *pszSymbol, PRTDBGSYMBOL pSymbol, PRTDBGMOD phMod);
1484
1485VMMR3DECL(int) DBGFR3AsLineByAddr(PUVM pUVM, RTDBGAS hDbgAs, PCDBGFADDRESS pAddress,
1486 PRTGCINTPTR poffDisp, PRTDBGLINE pLine, PRTDBGMOD phMod);
1487VMMR3DECL(PRTDBGLINE) DBGFR3AsLineByAddrA(PUVM pUVM, RTDBGAS hDbgAs, PCDBGFADDRESS pAddress,
1488 PRTGCINTPTR poffDisp, PRTDBGMOD phMod);
1489
1490/** @name DBGFMOD_PE_F_XXX - flags for
1491 * @{ */
1492/** NT 3.1 images were a little different, so make allowances for that. */
1493#define DBGFMODINMEM_F_PE_NT31 RT_BIT_32(0)
1494/** No container fallback. */
1495#define DBGFMODINMEM_F_NO_CONTAINER_FALLBACK RT_BIT_32(1)
1496/** No in-memory reader fallback. */
1497#define DBGFMODINMEM_F_NO_READER_FALLBACK RT_BIT_32(2)
1498/** Valid flags. */
1499#define DBGFMODINMEM_F_VALID_MASK UINT32_C(0x00000007)
1500/** @} */
1501VMMR3DECL(int) DBGFR3ModInMem(PUVM pUVM, PCDBGFADDRESS pImageAddr, uint32_t fFlags, const char *pszName,
1502 const char *pszFilename, RTLDRARCH enmArch, uint32_t cbImage,
1503 PRTDBGMOD phDbgMod, PRTERRINFO pErrInfo);
1504
1505#endif /* IN_RING3 */
1506
1507#ifdef IN_RING3 /* The stack API only works in ring-3. */
1508
1509/** Pointer to stack frame info. */
1510typedef struct DBGFSTACKFRAME *PDBGFSTACKFRAME;
1511/** Pointer to const stack frame info. */
1512typedef struct DBGFSTACKFRAME const *PCDBGFSTACKFRAME;
1513/**
1514 * Info about a stack frame.
1515 */
1516typedef struct DBGFSTACKFRAME
1517{
1518 /** Frame number. */
1519 uint32_t iFrame;
1520 /** Frame flags (DBGFSTACKFRAME_FLAGS_XXX). */
1521 uint32_t fFlags;
1522 /** The stack address of the frame.
1523 * The off member is [e|r]sp and the Sel member is ss. */
1524 DBGFADDRESS AddrStack;
1525 /** The program counter (PC) address of the frame.
1526 * The off member is [e|r]ip and the Sel member is cs. */
1527 DBGFADDRESS AddrPC;
1528 /** Pointer to the symbol nearest the program counter (PC). NULL if not found. */
1529 PRTDBGSYMBOL pSymPC;
1530 /** Pointer to the linenumber nearest the program counter (PC). NULL if not found. */
1531 PRTDBGLINE pLinePC;
1532 /** The frame address.
1533 * The off member is [e|r]bp and the Sel member is ss. */
1534 DBGFADDRESS AddrFrame;
1535 /** The way this frame returns to the next one. */
1536 RTDBGRETURNTYPE enmReturnType;
1537
1538 /** The way the next frame returns.
1539 * Only valid when DBGFSTACKFRAME_FLAGS_UNWIND_INFO_RET is set. */
1540 RTDBGRETURNTYPE enmReturnFrameReturnType;
1541 /** The return frame address.
1542 * The off member is [e|r]bp and the Sel member is ss. */
1543 DBGFADDRESS AddrReturnFrame;
1544 /** The return stack address.
1545 * The off member is [e|r]sp and the Sel member is ss. */
1546 DBGFADDRESS AddrReturnStack;
1547
1548 /** The program counter (PC) address which the frame returns to.
1549 * The off member is [e|r]ip and the Sel member is cs. */
1550 DBGFADDRESS AddrReturnPC;
1551 /** Pointer to the symbol nearest the return PC. NULL if not found. */
1552 PRTDBGSYMBOL pSymReturnPC;
1553 /** Pointer to the linenumber nearest the return PC. NULL if not found. */
1554 PRTDBGLINE pLineReturnPC;
1555
1556 /** 32-bytes of stack arguments. */
1557 union
1558 {
1559 /** 64-bit view */
1560 uint64_t au64[4];
1561 /** 32-bit view */
1562 uint32_t au32[8];
1563 /** 16-bit view */
1564 uint16_t au16[16];
1565 /** 8-bit view */
1566 uint8_t au8[32];
1567 } Args;
1568
1569 /** Number of registers values we can be sure about.
1570 * @note This is generally zero in the first frame. */
1571 uint32_t cSureRegs;
1572 /** Registers we can be sure about (length given by cSureRegs). */
1573 struct DBGFREGVALEX *paSureRegs;
1574
1575 /** Pointer to the next frame.
1576 * Might not be used in some cases, so consider it internal. */
1577 PCDBGFSTACKFRAME pNextInternal;
1578 /** Pointer to the first frame.
1579 * Might not be used in some cases, so consider it internal. */
1580 PCDBGFSTACKFRAME pFirstInternal;
1581} DBGFSTACKFRAME;
1582
1583/** @name DBGFSTACKFRAME_FLAGS_XXX - DBGFSTACKFRAME Flags.
1584 * @{ */
1585/** This is the last stack frame we can read.
1586 * This flag is not set if the walk stop because of max dept or recursion. */
1587# define DBGFSTACKFRAME_FLAGS_LAST RT_BIT(1)
1588/** This is the last record because we detected a loop. */
1589# define DBGFSTACKFRAME_FLAGS_LOOP RT_BIT(2)
1590/** This is the last record because we reached the maximum depth. */
1591# define DBGFSTACKFRAME_FLAGS_MAX_DEPTH RT_BIT(3)
1592/** 16-bit frame. */
1593# define DBGFSTACKFRAME_FLAGS_16BIT RT_BIT(4)
1594/** 32-bit frame. */
1595# define DBGFSTACKFRAME_FLAGS_32BIT RT_BIT(5)
1596/** 64-bit frame. */
1597# define DBGFSTACKFRAME_FLAGS_64BIT RT_BIT(6)
1598/** Real mode or V86 frame. */
1599# define DBGFSTACKFRAME_FLAGS_REAL_V86 RT_BIT(7)
1600/** Is a trap frame (NT term). */
1601# define DBGFSTACKFRAME_FLAGS_TRAP_FRAME RT_BIT(8)
1602
1603/** Used Odd/even heuristics for far/near return. */
1604# define DBGFSTACKFRAME_FLAGS_USED_ODD_EVEN RT_BIT(29)
1605/** Set if we used unwind info to construct the frame. (Kind of internal.) */
1606# define DBGFSTACKFRAME_FLAGS_USED_UNWIND_INFO RT_BIT(30)
1607/** Internal: Unwind info used for the return frame. */
1608# define DBGFSTACKFRAME_FLAGS_UNWIND_INFO_RET RT_BIT(31)
1609/** @} */
1610
1611/** @name DBGFCODETYPE
1612 * @{ */
1613typedef enum DBGFCODETYPE
1614{
1615 /** The usual invalid 0 value. */
1616 DBGFCODETYPE_INVALID = 0,
1617 /** Stack walk for guest code. */
1618 DBGFCODETYPE_GUEST,
1619 /** Stack walk for hypervisor code. */
1620 DBGFCODETYPE_HYPER,
1621 /** Stack walk for ring 0 code. */
1622 DBGFCODETYPE_RING0,
1623 /** The usual 32-bit blowup. */
1624 DBGFCODETYPE_32BIT_HACK = 0x7fffffff
1625} DBGFCODETYPE;
1626/** @} */
1627
1628VMMR3DECL(int) DBGFR3StackWalkBegin(PUVM pUVM, VMCPUID idCpu, DBGFCODETYPE enmCodeType,
1629 PCDBGFSTACKFRAME *ppFirstFrame);
1630VMMR3DECL(int) DBGFR3StackWalkBeginEx(PUVM pUVM, VMCPUID idCpu, DBGFCODETYPE enmCodeType, PCDBGFADDRESS pAddrFrame,
1631 PCDBGFADDRESS pAddrStack,PCDBGFADDRESS pAddrPC,
1632 RTDBGRETURNTYPE enmReturnType, PCDBGFSTACKFRAME *ppFirstFrame);
1633VMMR3DECL(PCDBGFSTACKFRAME) DBGFR3StackWalkNext(PCDBGFSTACKFRAME pCurrent);
1634VMMR3DECL(void) DBGFR3StackWalkEnd(PCDBGFSTACKFRAME pFirstFrame);
1635
1636#endif /* IN_RING3 */
1637
1638
1639#ifdef IN_RING3 /* The disassembly API only works in ring-3. */
1640
1641/** @name Flags to pass to DBGFR3DisasInstrEx().
1642 * @{ */
1643/** Disassemble the current guest instruction, with annotations. */
1644#define DBGF_DISAS_FLAGS_CURRENT_GUEST RT_BIT(0)
1645/** No annotations for current context. */
1646#define DBGF_DISAS_FLAGS_NO_ANNOTATION RT_BIT(2)
1647/** No symbol lookup. */
1648#define DBGF_DISAS_FLAGS_NO_SYMBOLS RT_BIT(3)
1649/** No instruction bytes. */
1650#define DBGF_DISAS_FLAGS_NO_BYTES RT_BIT(4)
1651/** No address in the output. */
1652#define DBGF_DISAS_FLAGS_NO_ADDRESS RT_BIT(5)
1653/** Disassemble original unpatched bytes (PATM). */
1654#define DBGF_DISAS_FLAGS_UNPATCHED_BYTES RT_BIT(7)
1655/** Annotate patched instructions. */
1656#define DBGF_DISAS_FLAGS_ANNOTATE_PATCHED RT_BIT(8)
1657/** Disassemble in the default mode of the specific context. */
1658#define DBGF_DISAS_FLAGS_DEFAULT_MODE UINT32_C(0x00000000)
1659/** Disassemble in 16-bit mode. */
1660#define DBGF_DISAS_FLAGS_16BIT_MODE UINT32_C(0x10000000)
1661/** Disassemble in 16-bit mode with real mode address translation. */
1662#define DBGF_DISAS_FLAGS_16BIT_REAL_MODE UINT32_C(0x20000000)
1663/** Disassemble in 32-bit mode. */
1664#define DBGF_DISAS_FLAGS_32BIT_MODE UINT32_C(0x30000000)
1665/** Disassemble in 64-bit mode. */
1666#define DBGF_DISAS_FLAGS_64BIT_MODE UINT32_C(0x40000000)
1667/** The disassembly mode mask. */
1668#define DBGF_DISAS_FLAGS_MODE_MASK UINT32_C(0x70000000)
1669/** Mask containing the valid flags. */
1670#define DBGF_DISAS_FLAGS_VALID_MASK UINT32_C(0x700001ff)
1671/** @} */
1672
1673/** Special flat selector. */
1674#define DBGF_SEL_FLAT 1
1675
1676VMMR3DECL(int) DBGFR3DisasInstrEx(PUVM pUVM, VMCPUID idCpu, RTSEL Sel, RTGCPTR GCPtr, uint32_t fFlags,
1677 char *pszOutput, uint32_t cbOutput, uint32_t *pcbInstr);
1678VMMR3_INT_DECL(int) DBGFR3DisasInstrCurrent(PVMCPU pVCpu, char *pszOutput, uint32_t cbOutput);
1679VMMR3DECL(int) DBGFR3DisasInstrCurrentLogInternal(PVMCPU pVCpu, const char *pszPrefix);
1680
1681/** @def DBGFR3_DISAS_INSTR_CUR_LOG
1682 * Disassembles the current guest context instruction and writes it to the log.
1683 * All registers and data will be displayed. Addresses will be attempted resolved to symbols.
1684 */
1685#ifdef LOG_ENABLED
1686# define DBGFR3_DISAS_INSTR_CUR_LOG(pVCpu, pszPrefix) \
1687 do { \
1688 if (LogIsEnabled()) \
1689 DBGFR3DisasInstrCurrentLogInternal(pVCpu, pszPrefix); \
1690 } while (0)
1691#else
1692# define DBGFR3_DISAS_INSTR_CUR_LOG(pVCpu, pszPrefix) do { } while (0)
1693#endif
1694
1695VMMR3DECL(int) DBGFR3DisasInstrLogInternal(PVMCPU pVCpu, RTSEL Sel, RTGCPTR GCPtr, const char *pszPrefix);
1696
1697/** @def DBGFR3_DISAS_INSTR_LOG
1698 * Disassembles the specified guest context instruction and writes it to the log.
1699 * Addresses will be attempted resolved to symbols.
1700 * @thread Any EMT.
1701 */
1702# ifdef LOG_ENABLED
1703# define DBGFR3_DISAS_INSTR_LOG(pVCpu, Sel, GCPtr, pszPrefix) \
1704 do { \
1705 if (LogIsEnabled()) \
1706 DBGFR3DisasInstrLogInternal(pVCpu, Sel, GCPtr, pszPrefix); \
1707 } while (0)
1708# else
1709# define DBGFR3_DISAS_INSTR_LOG(pVCpu, Sel, GCPtr, pszPrefix) do { } while (0)
1710# endif
1711#endif
1712
1713
1714#ifdef IN_RING3
1715VMMR3DECL(int) DBGFR3MemScan(PUVM pUVM, VMCPUID idCpu, PCDBGFADDRESS pAddress, RTGCUINTPTR cbRange, RTGCUINTPTR uAlign,
1716 const void *pvNeedle, size_t cbNeedle, PDBGFADDRESS pHitAddress);
1717VMMR3DECL(int) DBGFR3MemRead(PUVM pUVM, VMCPUID idCpu, PCDBGFADDRESS pAddress, void *pvBuf, size_t cbRead);
1718VMMR3DECL(int) DBGFR3MemReadString(PUVM pUVM, VMCPUID idCpu, PCDBGFADDRESS pAddress, char *pszBuf, size_t cbBuf);
1719VMMR3DECL(int) DBGFR3MemWrite(PUVM pUVM, VMCPUID idCpu, PCDBGFADDRESS pAddress, void const *pvBuf, size_t cbRead);
1720#endif
1721
1722
1723/** @name Flags for DBGFR3PagingDumpEx, PGMR3DumpHierarchyHCEx and
1724 * PGMR3DumpHierarchyGCEx
1725 * @{ */
1726/** The CR3 from the current CPU state. */
1727#define DBGFPGDMP_FLAGS_CURRENT_CR3 RT_BIT_32(0)
1728/** The current CPU paging mode (PSE, PAE, LM, EPT, NX). */
1729#define DBGFPGDMP_FLAGS_CURRENT_MODE RT_BIT_32(1)
1730/** Whether PSE is enabled (!DBGFPGDMP_FLAGS_CURRENT_STATE).
1731 * Same value as X86_CR4_PSE. */
1732#define DBGFPGDMP_FLAGS_PSE RT_BIT_32(4) /* */
1733/** Whether PAE is enabled (!DBGFPGDMP_FLAGS_CURRENT_STATE).
1734 * Same value as X86_CR4_PAE. */
1735#define DBGFPGDMP_FLAGS_PAE RT_BIT_32(5) /* */
1736/** Whether LME is enabled (!DBGFPGDMP_FLAGS_CURRENT_STATE).
1737 * Same value as MSR_K6_EFER_LME. */
1738#define DBGFPGDMP_FLAGS_LME RT_BIT_32(8)
1739/** Whether nested paging is enabled (!DBGFPGDMP_FLAGS_CURRENT_STATE). */
1740#define DBGFPGDMP_FLAGS_NP RT_BIT_32(9)
1741/** Whether extended nested page tables are enabled
1742 * (!DBGFPGDMP_FLAGS_CURRENT_STATE). */
1743#define DBGFPGDMP_FLAGS_EPT RT_BIT_32(10)
1744/** Whether no-execution is enabled (!DBGFPGDMP_FLAGS_CURRENT_STATE).
1745 * Same value as MSR_K6_EFER_NXE. */
1746#define DBGFPGDMP_FLAGS_NXE RT_BIT_32(11)
1747/** Whether to print the CR3. */
1748#define DBGFPGDMP_FLAGS_PRINT_CR3 RT_BIT_32(27)
1749/** Whether to print the header. */
1750#define DBGFPGDMP_FLAGS_HEADER RT_BIT_32(28)
1751/** Whether to dump additional page information. */
1752#define DBGFPGDMP_FLAGS_PAGE_INFO RT_BIT_32(29)
1753/** Dump the shadow tables if set.
1754 * Cannot be used together with DBGFPGDMP_FLAGS_GUEST. */
1755#define DBGFPGDMP_FLAGS_SHADOW RT_BIT_32(30)
1756/** Dump the guest tables if set.
1757 * Cannot be used together with DBGFPGDMP_FLAGS_SHADOW. */
1758#define DBGFPGDMP_FLAGS_GUEST RT_BIT_32(31)
1759/** Mask of valid bits. */
1760#define DBGFPGDMP_FLAGS_VALID_MASK UINT32_C(0xf8000f33)
1761/** The mask of bits controlling the paging mode. */
1762#define DBGFPGDMP_FLAGS_MODE_MASK UINT32_C(0x00000f32)
1763/** @} */
1764VMMDECL(int) DBGFR3PagingDumpEx(PUVM pUVM, VMCPUID idCpu, uint32_t fFlags, uint64_t cr3, uint64_t u64FirstAddr,
1765 uint64_t u64LastAddr, uint32_t cMaxDepth, PCDBGFINFOHLP pHlp);
1766
1767
1768/** @name DBGFR3SelQueryInfo flags.
1769 * @{ */
1770/** Get the info from the guest descriptor table.
1771 * @note This is more or less a given now when raw-mode was kicked out. */
1772#define DBGFSELQI_FLAGS_DT_GUEST UINT32_C(0)
1773/** If currently executing in in 64-bit mode, blow up data selectors. */
1774#define DBGFSELQI_FLAGS_DT_ADJ_64BIT_MODE UINT32_C(2)
1775/** @} */
1776VMMR3DECL(int) DBGFR3SelQueryInfo(PUVM pUVM, VMCPUID idCpu, RTSEL Sel, uint32_t fFlags, PDBGFSELINFO pSelInfo);
1777
1778
1779/**
1780 * Register identifiers.
1781 */
1782typedef enum DBGFREG
1783{
1784 /* General purpose registers: */
1785 DBGFREG_AL = 0,
1786 DBGFREG_AX = DBGFREG_AL,
1787 DBGFREG_EAX = DBGFREG_AL,
1788 DBGFREG_RAX = DBGFREG_AL,
1789
1790 DBGFREG_CL,
1791 DBGFREG_CX = DBGFREG_CL,
1792 DBGFREG_ECX = DBGFREG_CL,
1793 DBGFREG_RCX = DBGFREG_CL,
1794
1795 DBGFREG_DL,
1796 DBGFREG_DX = DBGFREG_DL,
1797 DBGFREG_EDX = DBGFREG_DL,
1798 DBGFREG_RDX = DBGFREG_DL,
1799
1800 DBGFREG_BL,
1801 DBGFREG_BX = DBGFREG_BL,
1802 DBGFREG_EBX = DBGFREG_BL,
1803 DBGFREG_RBX = DBGFREG_BL,
1804
1805 DBGFREG_SPL,
1806 DBGFREG_SP = DBGFREG_SPL,
1807 DBGFREG_ESP = DBGFREG_SPL,
1808 DBGFREG_RSP = DBGFREG_SPL,
1809
1810 DBGFREG_BPL,
1811 DBGFREG_BP = DBGFREG_BPL,
1812 DBGFREG_EBP = DBGFREG_BPL,
1813 DBGFREG_RBP = DBGFREG_BPL,
1814
1815 DBGFREG_SIL,
1816 DBGFREG_SI = DBGFREG_SIL,
1817 DBGFREG_ESI = DBGFREG_SIL,
1818 DBGFREG_RSI = DBGFREG_SIL,
1819
1820 DBGFREG_DIL,
1821 DBGFREG_DI = DBGFREG_DIL,
1822 DBGFREG_EDI = DBGFREG_DIL,
1823 DBGFREG_RDI = DBGFREG_DIL,
1824
1825 DBGFREG_R8,
1826 DBGFREG_R8B = DBGFREG_R8,
1827 DBGFREG_R8W = DBGFREG_R8,
1828 DBGFREG_R8D = DBGFREG_R8,
1829
1830 DBGFREG_R9,
1831 DBGFREG_R9B = DBGFREG_R9,
1832 DBGFREG_R9W = DBGFREG_R9,
1833 DBGFREG_R9D = DBGFREG_R9,
1834
1835 DBGFREG_R10,
1836 DBGFREG_R10B = DBGFREG_R10,
1837 DBGFREG_R10W = DBGFREG_R10,
1838 DBGFREG_R10D = DBGFREG_R10,
1839
1840 DBGFREG_R11,
1841 DBGFREG_R11B = DBGFREG_R11,
1842 DBGFREG_R11W = DBGFREG_R11,
1843 DBGFREG_R11D = DBGFREG_R11,
1844
1845 DBGFREG_R12,
1846 DBGFREG_R12B = DBGFREG_R12,
1847 DBGFREG_R12W = DBGFREG_R12,
1848 DBGFREG_R12D = DBGFREG_R12,
1849
1850 DBGFREG_R13,
1851 DBGFREG_R13B = DBGFREG_R13,
1852 DBGFREG_R13W = DBGFREG_R13,
1853 DBGFREG_R13D = DBGFREG_R13,
1854
1855 DBGFREG_R14,
1856 DBGFREG_R14B = DBGFREG_R14,
1857 DBGFREG_R14W = DBGFREG_R14,
1858 DBGFREG_R14D = DBGFREG_R14,
1859
1860 DBGFREG_R15,
1861 DBGFREG_R15B = DBGFREG_R15,
1862 DBGFREG_R15W = DBGFREG_R15,
1863 DBGFREG_R15D = DBGFREG_R15,
1864
1865 /* Segments and other special registers: */
1866 DBGFREG_CS,
1867 DBGFREG_CS_ATTR,
1868 DBGFREG_CS_BASE,
1869 DBGFREG_CS_LIMIT,
1870
1871 DBGFREG_DS,
1872 DBGFREG_DS_ATTR,
1873 DBGFREG_DS_BASE,
1874 DBGFREG_DS_LIMIT,
1875
1876 DBGFREG_ES,
1877 DBGFREG_ES_ATTR,
1878 DBGFREG_ES_BASE,
1879 DBGFREG_ES_LIMIT,
1880
1881 DBGFREG_FS,
1882 DBGFREG_FS_ATTR,
1883 DBGFREG_FS_BASE,
1884 DBGFREG_FS_LIMIT,
1885
1886 DBGFREG_GS,
1887 DBGFREG_GS_ATTR,
1888 DBGFREG_GS_BASE,
1889 DBGFREG_GS_LIMIT,
1890
1891 DBGFREG_SS,
1892 DBGFREG_SS_ATTR,
1893 DBGFREG_SS_BASE,
1894 DBGFREG_SS_LIMIT,
1895
1896 DBGFREG_IP,
1897 DBGFREG_EIP = DBGFREG_IP,
1898 DBGFREG_RIP = DBGFREG_IP,
1899
1900 DBGFREG_FLAGS,
1901 DBGFREG_EFLAGS = DBGFREG_FLAGS,
1902 DBGFREG_RFLAGS = DBGFREG_FLAGS,
1903
1904 /* FPU: */
1905 DBGFREG_FCW,
1906 DBGFREG_FSW,
1907 DBGFREG_FTW,
1908 DBGFREG_FOP,
1909 DBGFREG_FPUIP,
1910 DBGFREG_FPUCS,
1911 DBGFREG_FPUDP,
1912 DBGFREG_FPUDS,
1913 DBGFREG_MXCSR,
1914 DBGFREG_MXCSR_MASK,
1915
1916 DBGFREG_ST0,
1917 DBGFREG_ST1,
1918 DBGFREG_ST2,
1919 DBGFREG_ST3,
1920 DBGFREG_ST4,
1921 DBGFREG_ST5,
1922 DBGFREG_ST6,
1923 DBGFREG_ST7,
1924
1925 DBGFREG_MM0,
1926 DBGFREG_MM1,
1927 DBGFREG_MM2,
1928 DBGFREG_MM3,
1929 DBGFREG_MM4,
1930 DBGFREG_MM5,
1931 DBGFREG_MM6,
1932 DBGFREG_MM7,
1933
1934 /* SSE: */
1935 DBGFREG_XMM0,
1936 DBGFREG_XMM1,
1937 DBGFREG_XMM2,
1938 DBGFREG_XMM3,
1939 DBGFREG_XMM4,
1940 DBGFREG_XMM5,
1941 DBGFREG_XMM6,
1942 DBGFREG_XMM7,
1943 DBGFREG_XMM8,
1944 DBGFREG_XMM9,
1945 DBGFREG_XMM10,
1946 DBGFREG_XMM11,
1947 DBGFREG_XMM12,
1948 DBGFREG_XMM13,
1949 DBGFREG_XMM14,
1950 DBGFREG_XMM15,
1951 /** @todo add XMM aliases. */
1952
1953 /* AVX: */
1954 DBGFREG_YMM0,
1955 DBGFREG_YMM1,
1956 DBGFREG_YMM2,
1957 DBGFREG_YMM3,
1958 DBGFREG_YMM4,
1959 DBGFREG_YMM5,
1960 DBGFREG_YMM6,
1961 DBGFREG_YMM7,
1962 DBGFREG_YMM8,
1963 DBGFREG_YMM9,
1964 DBGFREG_YMM10,
1965 DBGFREG_YMM11,
1966 DBGFREG_YMM12,
1967 DBGFREG_YMM13,
1968 DBGFREG_YMM14,
1969 DBGFREG_YMM15,
1970
1971 /* System registers: */
1972 DBGFREG_GDTR_BASE,
1973 DBGFREG_GDTR_LIMIT,
1974 DBGFREG_IDTR_BASE,
1975 DBGFREG_IDTR_LIMIT,
1976 DBGFREG_LDTR,
1977 DBGFREG_LDTR_ATTR,
1978 DBGFREG_LDTR_BASE,
1979 DBGFREG_LDTR_LIMIT,
1980 DBGFREG_TR,
1981 DBGFREG_TR_ATTR,
1982 DBGFREG_TR_BASE,
1983 DBGFREG_TR_LIMIT,
1984
1985 DBGFREG_CR0,
1986 DBGFREG_CR2,
1987 DBGFREG_CR3,
1988 DBGFREG_CR4,
1989 DBGFREG_CR8,
1990
1991 DBGFREG_DR0,
1992 DBGFREG_DR1,
1993 DBGFREG_DR2,
1994 DBGFREG_DR3,
1995 DBGFREG_DR6,
1996 DBGFREG_DR7,
1997
1998 /* MSRs: */
1999 DBGFREG_MSR_IA32_APICBASE,
2000 DBGFREG_MSR_IA32_CR_PAT,
2001 DBGFREG_MSR_IA32_PERF_STATUS,
2002 DBGFREG_MSR_IA32_SYSENTER_CS,
2003 DBGFREG_MSR_IA32_SYSENTER_EIP,
2004 DBGFREG_MSR_IA32_SYSENTER_ESP,
2005 DBGFREG_MSR_IA32_TSC,
2006 DBGFREG_MSR_K6_EFER,
2007 DBGFREG_MSR_K6_STAR,
2008 DBGFREG_MSR_K8_CSTAR,
2009 DBGFREG_MSR_K8_FS_BASE,
2010 DBGFREG_MSR_K8_GS_BASE,
2011 DBGFREG_MSR_K8_KERNEL_GS_BASE,
2012 DBGFREG_MSR_K8_LSTAR,
2013 DBGFREG_MSR_K8_SF_MASK,
2014 DBGFREG_MSR_K8_TSC_AUX,
2015
2016 /** The number of registers to pass to DBGFR3RegQueryAll. */
2017 DBGFREG_ALL_COUNT,
2018
2019 /* Misc aliases that doesn't need be part of the 'all' query: */
2020 DBGFREG_AH = DBGFREG_ALL_COUNT,
2021 DBGFREG_CH,
2022 DBGFREG_DH,
2023 DBGFREG_BH,
2024 DBGFREG_GDTR,
2025 DBGFREG_IDTR,
2026
2027 /** The end of the registers. */
2028 DBGFREG_END,
2029 /** The usual 32-bit type hack. */
2030 DBGFREG_32BIT_HACK = 0x7fffffff
2031} DBGFREG;
2032/** Pointer to a register identifier. */
2033typedef DBGFREG *PDBGFREG;
2034/** Pointer to a const register identifier. */
2035typedef DBGFREG const *PCDBGFREG;
2036
2037/**
2038 * Register value type.
2039 */
2040typedef enum DBGFREGVALTYPE
2041{
2042 DBGFREGVALTYPE_INVALID = 0,
2043 /** Unsigned 8-bit register value. */
2044 DBGFREGVALTYPE_U8,
2045 /** Unsigned 16-bit register value. */
2046 DBGFREGVALTYPE_U16,
2047 /** Unsigned 32-bit register value. */
2048 DBGFREGVALTYPE_U32,
2049 /** Unsigned 64-bit register value. */
2050 DBGFREGVALTYPE_U64,
2051 /** Unsigned 128-bit register value. */
2052 DBGFREGVALTYPE_U128,
2053 /** Unsigned 256-bit register value. */
2054 DBGFREGVALTYPE_U256,
2055 /** Unsigned 512-bit register value. */
2056 DBGFREGVALTYPE_U512,
2057 /** Long double register value. */
2058 DBGFREGVALTYPE_R80,
2059 /** Descriptor table register value. */
2060 DBGFREGVALTYPE_DTR,
2061 /** End of the valid register value types. */
2062 DBGFREGVALTYPE_END,
2063 /** The usual 32-bit type hack. */
2064 DBGFREGVALTYPE_32BIT_HACK = 0x7fffffff
2065} DBGFREGVALTYPE;
2066/** Pointer to a register value type. */
2067typedef DBGFREGVALTYPE *PDBGFREGVALTYPE;
2068
2069/**
2070 * A generic register value type.
2071 */
2072typedef union DBGFREGVAL
2073{
2074 uint64_t au64[8]; /**< The 64-bit array view. First because of the initializer. */
2075 uint32_t au32[16]; /**< The 32-bit array view. */
2076 uint16_t au16[32]; /**< The 16-bit array view. */
2077 uint8_t au8[64]; /**< The 8-bit array view. */
2078
2079 uint8_t u8; /**< The 8-bit view. */
2080 uint16_t u16; /**< The 16-bit view. */
2081 uint32_t u32; /**< The 32-bit view. */
2082 uint64_t u64; /**< The 64-bit view. */
2083 RTUINT128U u128; /**< The 128-bit view. */
2084 RTUINT256U u256; /**< The 256-bit view. */
2085 RTUINT512U u512; /**< The 512-bit view. */
2086 RTFLOAT80U r80; /**< The 80-bit floating point view. */
2087 RTFLOAT80U2 r80Ex; /**< The 80-bit floating point view v2. */
2088 /** GDTR or LDTR (DBGFREGVALTYPE_DTR). */
2089 struct
2090 {
2091 /** The table address. */
2092 uint64_t u64Base;
2093 /** The table limit (length minus 1). */
2094 uint32_t u32Limit; /**< @todo Limit should be uint16_t */
2095 } dtr;
2096} DBGFREGVAL;
2097/** Pointer to a generic register value type. */
2098typedef DBGFREGVAL *PDBGFREGVAL;
2099/** Pointer to a const generic register value type. */
2100typedef DBGFREGVAL const *PCDBGFREGVAL;
2101
2102/** Initialize a DBGFREGVAL variable to all zeros. */
2103#define DBGFREGVAL_INITIALIZE_ZERO { { 0, 0, 0, 0, 0, 0, 0, 0 } }
2104/** Initialize a DBGFREGVAL variable to all bits set . */
2105#define DBGFREGVAL_INITIALIZE_FFFF { { UINT64_MAX, UINT64_MAX, UINT64_MAX, UINT64_MAX, UINT64_MAX, UINT64_MAX, UINT64_MAX, UINT64_MAX } }
2106
2107/**
2108 * Extended register value, including register ID and type.
2109 *
2110 * This is currently only used by the stack walker.
2111 */
2112typedef struct DBGFREGVALEX
2113{
2114 /** The register value. */
2115 DBGFREGVAL Value;
2116 /** The register value type. */
2117 DBGFREGVALTYPE enmType;
2118 /** The register ID, DBGFREG_END if not applicable. */
2119 DBGFREG enmReg;
2120 /** Pointer to read-only register name string if no register ID could be found. */
2121 const char *pszName;
2122} DBGFREGVALEX;
2123/** Pointer to an extended register value struct. */
2124typedef DBGFREGVALEX *PDBGFREGVALEX;
2125/** Pointer to a const extended register value struct. */
2126typedef DBGFREGVALEX const *PCDBGFREGVALEX;
2127
2128
2129VMMDECL(ssize_t) DBGFR3RegFormatValue(char *pszBuf, size_t cbBuf, PCDBGFREGVAL pValue, DBGFREGVALTYPE enmType, bool fSpecial);
2130VMMDECL(ssize_t) DBGFR3RegFormatValueEx(char *pszBuf, size_t cbBuf, PCDBGFREGVAL pValue, DBGFREGVALTYPE enmType,
2131 unsigned uBase, signed int cchWidth, signed int cchPrecision, uint32_t fFlags);
2132
2133/**
2134 * Register sub-field descriptor.
2135 */
2136typedef struct DBGFREGSUBFIELD
2137{
2138 /** The name of the sub-field. NULL is used to terminate the array. */
2139 const char *pszName;
2140 /** The index of the first bit. Ignored if pfnGet is set. */
2141 uint8_t iFirstBit;
2142 /** The number of bits. Mandatory. */
2143 uint8_t cBits;
2144 /** The shift count. Not applied when pfnGet is set, but used to
2145 * calculate the minimum type. */
2146 int8_t cShift;
2147 /** Sub-field flags, DBGFREGSUBFIELD_FLAGS_XXX. */
2148 uint8_t fFlags;
2149 /** Getter (optional).
2150 * @remarks Does not take the device lock or anything like that.
2151 */
2152 DECLCALLBACKMEMBER(int, pfnGet,(void *pvUser, struct DBGFREGSUBFIELD const *pSubField, PRTUINT128U puValue));
2153 /** Setter (optional).
2154 * @remarks Does not take the device lock or anything like that.
2155 */
2156 DECLCALLBACKMEMBER(int, pfnSet,(void *pvUser, struct DBGFREGSUBFIELD const *pSubField, RTUINT128U uValue, RTUINT128U fMask));
2157} DBGFREGSUBFIELD;
2158/** Pointer to a const register sub-field descriptor. */
2159typedef DBGFREGSUBFIELD const *PCDBGFREGSUBFIELD;
2160
2161/** @name DBGFREGSUBFIELD_FLAGS_XXX
2162 * @{ */
2163/** The sub-field is read-only. */
2164#define DBGFREGSUBFIELD_FLAGS_READ_ONLY UINT8_C(0x01)
2165/** @} */
2166
2167/** Macro for creating a read-write sub-field entry without getters. */
2168#define DBGFREGSUBFIELD_RW(a_szName, a_iFirstBit, a_cBits, a_cShift) \
2169 { a_szName, a_iFirstBit, a_cBits, a_cShift, 0 /*fFlags*/, NULL /*pfnGet*/, NULL /*pfnSet*/ }
2170/** Macro for creating a read-write sub-field entry with getters. */
2171#define DBGFREGSUBFIELD_RW_SG(a_szName, a_cBits, a_cShift, a_pfnGet, a_pfnSet) \
2172 { a_szName, 0 /*iFirstBit*/, a_cBits, a_cShift, 0 /*fFlags*/, a_pfnGet, a_pfnSet }
2173/** Macro for creating a read-only sub-field entry without getters. */
2174#define DBGFREGSUBFIELD_RO(a_szName, a_iFirstBit, a_cBits, a_cShift) \
2175 { a_szName, a_iFirstBit, a_cBits, a_cShift, DBGFREGSUBFIELD_FLAGS_READ_ONLY, NULL /*pfnGet*/, NULL /*pfnSet*/ }
2176/** Macro for creating a terminator sub-field entry. */
2177#define DBGFREGSUBFIELD_TERMINATOR() \
2178 { NULL, 0, 0, 0, 0, NULL, NULL }
2179
2180/**
2181 * Register alias descriptor.
2182 */
2183typedef struct DBGFREGALIAS
2184{
2185 /** The alias name. NULL is used to terminate the array. */
2186 const char *pszName;
2187 /** Set to a valid type if the alias has a different type. */
2188 DBGFREGVALTYPE enmType;
2189} DBGFREGALIAS;
2190/** Pointer to a const register alias descriptor. */
2191typedef DBGFREGALIAS const *PCDBGFREGALIAS;
2192
2193/**
2194 * Register descriptor.
2195 */
2196typedef struct DBGFREGDESC
2197{
2198 /** The normal register name. */
2199 const char *pszName;
2200 /** The register identifier if this is a CPU register. */
2201 DBGFREG enmReg;
2202 /** The default register type. */
2203 DBGFREGVALTYPE enmType;
2204 /** Flags, see DBGFREG_FLAGS_XXX. */
2205 uint32_t fFlags;
2206 /** The internal register indicator.
2207 * For CPU registers this is the offset into the CPUMCTX structure,
2208 * thuse the 'off' prefix. */
2209 uint32_t offRegister;
2210 /** Getter.
2211 * @remarks Does not take the device lock or anything like that.
2212 */
2213 DECLCALLBACKMEMBER(int, pfnGet,(void *pvUser, struct DBGFREGDESC const *pDesc, PDBGFREGVAL pValue));
2214 /** Setter.
2215 * @remarks Does not take the device lock or anything like that.
2216 */
2217 DECLCALLBACKMEMBER(int, pfnSet,(void *pvUser, struct DBGFREGDESC const *pDesc, PCDBGFREGVAL pValue, PCDBGFREGVAL pfMask));
2218 /** Aliases (optional). */
2219 PCDBGFREGALIAS paAliases;
2220 /** Sub fields (optional). */
2221 PCDBGFREGSUBFIELD paSubFields;
2222} DBGFREGDESC;
2223
2224/** @name Macros for constructing DBGFREGDESC arrays.
2225 * @{ */
2226#define DBGFREGDESC_RW(a_szName, a_TypeSuff, a_offRegister, a_pfnGet, a_pfnSet) \
2227 { a_szName, DBGFREG_END, DBGFREGVALTYPE_##a_TypeSuff, 0 /*fFlags*/, a_offRegister, a_pfnGet, a_pfnSet, NULL /*paAlises*/, NULL /*paSubFields*/ }
2228#define DBGFREGDESC_RO(a_szName, a_TypeSuff, a_offRegister, a_pfnGet, a_pfnSet) \
2229 { a_szName, DBGFREG_END, DBGFREGVALTYPE_##a_TypeSuff, DBGFREG_FLAGS_READ_ONLY, a_offRegister, a_pfnGet, a_pfnSet, NULL /*paAlises*/, NULL /*paSubFields*/ }
2230#define DBGFREGDESC_RW_A(a_szName, a_TypeSuff, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases) \
2231 { a_szName, DBGFREG_END, DBGFREGVALTYPE_##a_TypeSuff, 0 /*fFlags*/, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases, NULL /*paSubFields*/ }
2232#define DBGFREGDESC_RO_A(a_szName, a_TypeSuff, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases) \
2233 { a_szName, DBGFREG_END, DBGFREGVALTYPE_##a_TypeSuff, DBGFREG_FLAGS_READ_ONLY, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases, NULL /*paSubFields*/ }
2234#define DBGFREGDESC_RW_S(a_szName, a_TypeSuff, a_offRegister, a_pfnGet, a_pfnSet, a_paSubFields) \
2235 { a_szName, DBGFREG_END, DBGFREGVALTYPE_##a_TypeSuff, 0 /*fFlags*/, a_offRegister, a_pfnGet, a_pfnSet, /*paAliases*/, a_paSubFields }
2236#define DBGFREGDESC_RO_S(a_szName, a_TypeSuff, a_offRegister, a_pfnGet, a_pfnSet, a_paSubFields) \
2237 { a_szName, DBGFREG_END, DBGFREGVALTYPE_##a_TypeSuff, DBGFREG_FLAGS_READ_ONLY, a_offRegister, a_pfnGet, a_pfnSet, /*paAliases*/, a_paSubFields }
2238#define DBGFREGDESC_RW_AS(a_szName, a_TypeSuff, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields) \
2239 { a_szName, DBGFREG_END, DBGFREGVALTYPE_##a_TypeSuff, 0 /*fFlags*/, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields }
2240#define DBGFREGDESC_RO_AS(a_szName, a_TypeSuff, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields) \
2241 { a_szName, DBGFREG_END, DBGFREGVALTYPE_##a_TypeSuff, DBGFREG_FLAGS_READ_ONLY, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields }
2242#define DBGFREGDESC_TERMINATOR() \
2243 { NULL, DBGFREG_END, DBGFREGVALTYPE_INVALID, 0, 0, NULL, NULL, NULL, NULL }
2244/** @} */
2245
2246
2247/** @name DBGFREG_FLAGS_XXX
2248 * @{ */
2249/** The register is read-only. */
2250#define DBGFREG_FLAGS_READ_ONLY RT_BIT_32(0)
2251/** @} */
2252
2253/**
2254 * Entry in a batch query or set operation.
2255 */
2256typedef struct DBGFREGENTRY
2257{
2258 /** The register identifier. */
2259 DBGFREG enmReg;
2260 /** The size of the value in bytes. */
2261 DBGFREGVALTYPE enmType;
2262 /** The register value. The valid view is indicated by enmType. */
2263 DBGFREGVAL Val;
2264} DBGFREGENTRY;
2265/** Pointer to a register entry in a batch operation. */
2266typedef DBGFREGENTRY *PDBGFREGENTRY;
2267/** Pointer to a const register entry in a batch operation. */
2268typedef DBGFREGENTRY const *PCDBGFREGENTRY;
2269
2270/** Used with DBGFR3Reg* to indicate the hypervisor register set instead of the
2271 * guest. */
2272#define DBGFREG_HYPER_VMCPUID UINT32_C(0x01000000)
2273
2274VMMR3DECL(int) DBGFR3RegCpuQueryU8( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint8_t *pu8);
2275VMMR3DECL(int) DBGFR3RegCpuQueryU16( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint16_t *pu16);
2276VMMR3DECL(int) DBGFR3RegCpuQueryU32( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint32_t *pu32);
2277VMMR3DECL(int) DBGFR3RegCpuQueryU64( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint64_t *pu64);
2278VMMR3DECL(int) DBGFR3RegCpuQueryU128(PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint128_t *pu128);
2279VMMR3DECL(int) DBGFR3RegCpuQueryLrd( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, long double *plrd);
2280VMMR3DECL(int) DBGFR3RegCpuQueryXdtr(PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint64_t *pu64Base, uint16_t *pu16Limit);
2281#if 0
2282VMMR3DECL(int) DBGFR3RegCpuQueryBatch(PUVM pUVM,VMCPUID idCpu, PDBGFREGENTRY paRegs, size_t cRegs);
2283VMMR3DECL(int) DBGFR3RegCpuQueryAll( PUVM pUVM, VMCPUID idCpu, PDBGFREGENTRY paRegs, size_t cRegs);
2284
2285VMMR3DECL(int) DBGFR3RegCpuSetU8( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint8_t u8);
2286VMMR3DECL(int) DBGFR3RegCpuSetU16( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint16_t u16);
2287VMMR3DECL(int) DBGFR3RegCpuSetU32( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint32_t u32);
2288VMMR3DECL(int) DBGFR3RegCpuSetU64( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint64_t u64);
2289VMMR3DECL(int) DBGFR3RegCpuSetU128( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint128_t u128);
2290VMMR3DECL(int) DBGFR3RegCpuSetLrd( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, long double lrd);
2291VMMR3DECL(int) DBGFR3RegCpuSetBatch( PUVM pUVM, VMCPUID idCpu, PCDBGFREGENTRY paRegs, size_t cRegs);
2292#endif
2293
2294VMMR3DECL(const char *) DBGFR3RegCpuName(PUVM pUVM, DBGFREG enmReg, DBGFREGVALTYPE enmType);
2295
2296VMMR3_INT_DECL(int) DBGFR3RegRegisterCpu(PVM pVM, PVMCPU pVCpu, PCDBGFREGDESC paRegisters, bool fGuestRegs);
2297VMMR3_INT_DECL(int) DBGFR3RegRegisterDevice(PVM pVM, PCDBGFREGDESC paRegisters, PPDMDEVINS pDevIns,
2298 const char *pszPrefix, uint32_t iInstance);
2299
2300/**
2301 * Entry in a named batch query or set operation.
2302 */
2303typedef struct DBGFREGENTRYNM
2304{
2305 /** The register name. */
2306 const char *pszName;
2307 /** The size of the value in bytes. */
2308 DBGFREGVALTYPE enmType;
2309 /** The register value. The valid view is indicated by enmType. */
2310 DBGFREGVAL Val;
2311} DBGFREGENTRYNM;
2312/** Pointer to a named register entry in a batch operation. */
2313typedef DBGFREGENTRYNM *PDBGFREGENTRYNM;
2314/** Pointer to a const named register entry in a batch operation. */
2315typedef DBGFREGENTRYNM const *PCDBGFREGENTRYNM;
2316
2317VMMR3DECL(int) DBGFR3RegNmValidate( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg);
2318
2319VMMR3DECL(int) DBGFR3RegNmQuery( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, PDBGFREGVAL pValue, PDBGFREGVALTYPE penmType);
2320VMMR3DECL(int) DBGFR3RegNmQueryU8( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, uint8_t *pu8);
2321VMMR3DECL(int) DBGFR3RegNmQueryU16( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, uint16_t *pu16);
2322VMMR3DECL(int) DBGFR3RegNmQueryU32( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, uint32_t *pu32);
2323VMMR3DECL(int) DBGFR3RegNmQueryU64( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, uint64_t *pu64);
2324VMMR3DECL(int) DBGFR3RegNmQueryU128(PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, PRTUINT128U pu128);
2325/*VMMR3DECL(int) DBGFR3RegNmQueryLrd( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, long double *plrd);*/
2326VMMR3DECL(int) DBGFR3RegNmQueryXdtr(PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, uint64_t *pu64Base, uint16_t *pu16Limit);
2327VMMR3DECL(int) DBGFR3RegNmQueryBatch(PUVM pUVM,VMCPUID idDefCpu, PDBGFREGENTRYNM paRegs, size_t cRegs);
2328VMMR3DECL(int) DBGFR3RegNmQueryAllCount(PUVM pUVM, size_t *pcRegs);
2329VMMR3DECL(int) DBGFR3RegNmQueryAll( PUVM pUVM, PDBGFREGENTRYNM paRegs, size_t cRegs);
2330
2331VMMR3DECL(int) DBGFR3RegNmSet( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, PCDBGFREGVAL pValue, DBGFREGVALTYPE enmType);
2332VMMR3DECL(int) DBGFR3RegNmSetU8( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, uint8_t u8);
2333VMMR3DECL(int) DBGFR3RegNmSetU16( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, uint16_t u16);
2334VMMR3DECL(int) DBGFR3RegNmSetU32( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, uint32_t u32);
2335VMMR3DECL(int) DBGFR3RegNmSetU64( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, uint64_t u64);
2336VMMR3DECL(int) DBGFR3RegNmSetU128( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, RTUINT128U u128);
2337VMMR3DECL(int) DBGFR3RegNmSetLrd( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, long double lrd);
2338VMMR3DECL(int) DBGFR3RegNmSetBatch( PUVM pUVM, VMCPUID idDefCpu, PCDBGFREGENTRYNM paRegs, size_t cRegs);
2339
2340/** @todo add enumeration methods. */
2341
2342VMMR3DECL(int) DBGFR3RegPrintf( PUVM pUVM, VMCPUID idDefCpu, char *pszBuf, size_t cbBuf, const char *pszFormat, ...);
2343VMMR3DECL(int) DBGFR3RegPrintfV(PUVM pUVM, VMCPUID idDefCpu, char *pszBuf, size_t cbBuf, const char *pszFormat, va_list va);
2344
2345
2346#ifdef IN_RING3
2347
2348/**
2349 * Guest OS digger interface identifier.
2350 *
2351 * This is for use together with PDBGFR3QueryInterface and is used to
2352 * obtain access to optional interfaces.
2353 */
2354typedef enum DBGFOSINTERFACE
2355{
2356 /** The usual invalid entry. */
2357 DBGFOSINTERFACE_INVALID = 0,
2358 /** Process info. */
2359 DBGFOSINTERFACE_PROCESS,
2360 /** Thread info. */
2361 DBGFOSINTERFACE_THREAD,
2362 /** Kernel message log - DBGFOSIDMESG. */
2363 DBGFOSINTERFACE_DMESG,
2364 /** Windows NT specifics (for the communication with the KD debugger stub). */
2365 DBGFOSINTERFACE_WINNT,
2366 /** The end of the valid entries. */
2367 DBGFOSINTERFACE_END,
2368 /** The usual 32-bit type blowup. */
2369 DBGFOSINTERFACE_32BIT_HACK = 0x7fffffff
2370} DBGFOSINTERFACE;
2371/** Pointer to a Guest OS digger interface identifier. */
2372typedef DBGFOSINTERFACE *PDBGFOSINTERFACE;
2373/** Pointer to a const Guest OS digger interface identifier. */
2374typedef DBGFOSINTERFACE const *PCDBGFOSINTERFACE;
2375
2376
2377/**
2378 * Guest OS Digger Registration Record.
2379 *
2380 * This is used with the DBGFR3OSRegister() API.
2381 */
2382typedef struct DBGFOSREG
2383{
2384 /** Magic value (DBGFOSREG_MAGIC). */
2385 uint32_t u32Magic;
2386 /** Flags. Reserved. */
2387 uint32_t fFlags;
2388 /** The size of the instance data. */
2389 uint32_t cbData;
2390 /** Operative System name. */
2391 char szName[24];
2392
2393 /**
2394 * Constructs the instance.
2395 *
2396 * @returns VBox status code.
2397 * @param pUVM The user mode VM handle.
2398 * @param pvData Pointer to the instance data.
2399 */
2400 DECLCALLBACKMEMBER(int, pfnConstruct,(PUVM pUVM, void *pvData));
2401
2402 /**
2403 * Destroys the instance.
2404 *
2405 * @param pUVM The user mode VM handle.
2406 * @param pvData Pointer to the instance data.
2407 */
2408 DECLCALLBACKMEMBER(void, pfnDestruct,(PUVM pUVM, void *pvData));
2409
2410 /**
2411 * Probes the guest memory for OS finger prints.
2412 *
2413 * No setup or so is performed, it will be followed by a call to pfnInit
2414 * or pfnRefresh that should take care of that.
2415 *
2416 * @returns true if is an OS handled by this module, otherwise false.
2417 * @param pUVM The user mode VM handle.
2418 * @param pvData Pointer to the instance data.
2419 */
2420 DECLCALLBACKMEMBER(bool, pfnProbe,(PUVM pUVM, void *pvData));
2421
2422 /**
2423 * Initializes a fresly detected guest, loading symbols and such useful stuff.
2424 *
2425 * This is called after pfnProbe.
2426 *
2427 * @returns VBox status code.
2428 * @param pUVM The user mode VM handle.
2429 * @param pvData Pointer to the instance data.
2430 */
2431 DECLCALLBACKMEMBER(int, pfnInit,(PUVM pUVM, void *pvData));
2432
2433 /**
2434 * Refreshes symbols and stuff following a redetection of the same OS.
2435 *
2436 * This is called after pfnProbe.
2437 *
2438 * @returns VBox status code.
2439 * @param pUVM The user mode VM handle.
2440 * @param pvData Pointer to the instance data.
2441 */
2442 DECLCALLBACKMEMBER(int, pfnRefresh,(PUVM pUVM, void *pvData));
2443
2444 /**
2445 * Terminates an OS when a new (or none) OS has been detected,
2446 * and before destruction.
2447 *
2448 * This is called after pfnProbe and if needed before pfnDestruct.
2449 *
2450 * @param pUVM The user mode VM handle.
2451 * @param pvData Pointer to the instance data.
2452 */
2453 DECLCALLBACKMEMBER(void, pfnTerm,(PUVM pUVM, void *pvData));
2454
2455 /**
2456 * Queries the version of the running OS.
2457 *
2458 * This is only called after pfnInit().
2459 *
2460 * @returns VBox status code.
2461 * @param pUVM The user mode VM handle.
2462 * @param pvData Pointer to the instance data.
2463 * @param pszVersion Where to store the version string.
2464 * @param cchVersion The size of the version string buffer.
2465 */
2466 DECLCALLBACKMEMBER(int, pfnQueryVersion,(PUVM pUVM, void *pvData, char *pszVersion, size_t cchVersion));
2467
2468 /**
2469 * Queries the pointer to a interface.
2470 *
2471 * This is called after pfnProbe.
2472 *
2473 * The returned interface must be valid until pfnDestruct is called. Two calls
2474 * to this method with the same @a enmIf value must return the same pointer.
2475 *
2476 * @returns Pointer to the interface if available, NULL if not available.
2477 * @param pUVM The user mode VM handle.
2478 * @param pvData Pointer to the instance data.
2479 * @param enmIf The interface identifier.
2480 */
2481 DECLCALLBACKMEMBER(void *, pfnQueryInterface,(PUVM pUVM, void *pvData, DBGFOSINTERFACE enmIf));
2482
2483 /**
2484 * Stack unwind assist callback.
2485 *
2486 * This is only called after pfnInit().
2487 *
2488 * @returns VBox status code (allocation error or something of similar fatality).
2489 * @param pUVM The user mode VM handle.
2490 * @param pvData Pointer to the instance data.
2491 * @param idCpu The CPU that's unwinding it's stack.
2492 * @param pFrame The current frame. Okay to modify it a little.
2493 * @param pState The unwind state. Okay to modify it.
2494 * @param pInitialCtx The initial register context.
2495 * @param hAs The address space being used for the unwind.
2496 * @param puScratch Scratch area (initialized to zero, no dtor).
2497 */
2498 DECLCALLBACKMEMBER(int, pfnStackUnwindAssist,(PUVM pUVM, void *pvData, VMCPUID idCpu, PDBGFSTACKFRAME pFrame,
2499 PRTDBGUNWINDSTATE pState, PCCPUMCTX pInitialCtx, RTDBGAS hAs,
2500 uint64_t *puScratch));
2501
2502 /** Trailing magic (DBGFOSREG_MAGIC). */
2503 uint32_t u32EndMagic;
2504} DBGFOSREG;
2505/** Pointer to a Guest OS digger registration record. */
2506typedef DBGFOSREG *PDBGFOSREG;
2507/** Pointer to a const Guest OS digger registration record. */
2508typedef DBGFOSREG const *PCDBGFOSREG;
2509
2510/** Magic value for DBGFOSREG::u32Magic and DBGFOSREG::u32EndMagic. (Hitomi Kanehara) */
2511#define DBGFOSREG_MAGIC 0x19830808
2512
2513
2514/**
2515 * Interface for querying kernel log messages (DBGFOSINTERFACE_DMESG).
2516 */
2517typedef struct DBGFOSIDMESG
2518{
2519 /** Trailing magic (DBGFOSIDMESG_MAGIC). */
2520 uint32_t u32Magic;
2521
2522 /**
2523 * Query the kernel log.
2524 *
2525 * @returns VBox status code.
2526 * @retval VERR_NOT_FOUND if the messages could not be located.
2527 * @retval VERR_INVALID_STATE if the messages was found to have unknown/invalid
2528 * format.
2529 * @retval VERR_BUFFER_OVERFLOW if the buffer isn't large enough, pcbActual
2530 * will be set to the required buffer size. The buffer, however, will
2531 * be filled with as much data as it can hold (properly zero terminated
2532 * of course).
2533 *
2534 * @param pThis Pointer to the interface structure.
2535 * @param pUVM The user mode VM handle.
2536 * @param fFlags Flags reserved for future use, MBZ.
2537 * @param cMessages The number of messages to retrieve, counting from the
2538 * end of the log (i.e. like tail), use UINT32_MAX for all.
2539 * @param pszBuf The output buffer.
2540 * @param cbBuf The buffer size.
2541 * @param pcbActual Where to store the number of bytes actually returned,
2542 * including zero terminator. On VERR_BUFFER_OVERFLOW this
2543 * holds the necessary buffer size. Optional.
2544 */
2545 DECLCALLBACKMEMBER(int, pfnQueryKernelLog,(struct DBGFOSIDMESG *pThis, PUVM pUVM, uint32_t fFlags, uint32_t cMessages,
2546 char *pszBuf, size_t cbBuf, size_t *pcbActual));
2547 /** Trailing magic (DBGFOSIDMESG_MAGIC). */
2548 uint32_t u32EndMagic;
2549} DBGFOSIDMESG;
2550/** Pointer to the interface for query kernel log messages (DBGFOSINTERFACE_DMESG). */
2551typedef DBGFOSIDMESG *PDBGFOSIDMESG;
2552/** Magic value for DBGFOSIDMESG::32Magic and DBGFOSIDMESG::u32EndMagic. (Kenazburo Oe) */
2553#define DBGFOSIDMESG_MAGIC UINT32_C(0x19350131)
2554
2555
2556/**
2557 * Interface for querying Windows NT guest specifics (DBGFOSINTERFACE_WINNT).
2558 */
2559typedef struct DBGFOSIWINNT
2560{
2561 /** Trailing magic (DBGFOSIWINNT_MAGIC). */
2562 uint32_t u32Magic;
2563
2564 /**
2565 * Queries version information.
2566 *
2567 * @returns VBox status code.
2568 * @param pThis Pointer to the interface structure.
2569 * @param pUVM The user mode VM handle.
2570 * @param puVersMajor Where to store the major version part, optional.
2571 * @param puVersMinor Where to store the minor version part, optional.
2572 * @param puBuildNumber Where to store the build number, optional.
2573 * @param pf32Bit Where to store the flag whether this is a 32bit Windows NT, optional.
2574 */
2575 DECLCALLBACKMEMBER(int, pfnQueryVersion,(struct DBGFOSIWINNT *pThis, PUVM pUVM,
2576 uint32_t *puVersMajor, uint32_t *puVersMinor,
2577 uint32_t *puBuildNumber, bool *pf32Bit));
2578
2579 /**
2580 * Queries some base kernel pointers.
2581 *
2582 * @returns VBox status code.
2583 * @param pThis Pointer to the interface structure.
2584 * @param pUVM The user mode VM handle.
2585 * @param pGCPtrKernBase Where to store the kernel base on success.
2586 * @param pGCPtrPsLoadedModuleList Where to store the pointer to the laoded module list head on success.
2587 */
2588 DECLCALLBACKMEMBER(int, pfnQueryKernelPtrs,(struct DBGFOSIWINNT *pThis, PUVM pUVM,
2589 PRTGCUINTPTR pGCPtrKernBase, PRTGCUINTPTR pGCPtrPsLoadedModuleList));
2590
2591 /**
2592 * Queries KPCR and KPCRB pointers for the given vCPU.
2593 *
2594 * @returns VBox status code.
2595 * @param pThis Pointer to the interface structure.
2596 * @param pUVM The user mode VM handle.
2597 * @param idCpu The vCPU to query the KPCR/KPCRB for.
2598 * @param pKpcr Where to store the KPCR pointer on success, optional.
2599 * @param pKpcrb Where to store the KPCR pointer on success, optional.
2600 */
2601 DECLCALLBACKMEMBER(int, pfnQueryKpcrForVCpu,(struct DBGFOSIWINNT *pThis, PUVM pUVM, VMCPUID idCpu,
2602 PRTGCUINTPTR pKpcr, PRTGCUINTPTR pKpcrb));
2603
2604 /**
2605 * Queries the current thread for the given vCPU.
2606 *
2607 * @returns VBox status code.
2608 * @param pThis Pointer to the interface structure.
2609 * @param pUVM The user mode VM handle.
2610 * @param idCpu The vCPU to query the KPCR/KPCRB for.
2611 * @param pCurThrd Where to store the CurrentThread pointer on success.
2612 */
2613 DECLCALLBACKMEMBER(int, pfnQueryCurThrdForVCpu,(struct DBGFOSIWINNT *pThis, PUVM pUVM, VMCPUID idCpu,
2614 PRTGCUINTPTR pCurThrd));
2615
2616 /** Trailing magic (DBGFOSIWINNT_MAGIC). */
2617 uint32_t u32EndMagic;
2618} DBGFOSIWINNT;
2619/** Pointer to the interface for query kernel log messages (DBGFOSINTERFACE_WINNT). */
2620typedef DBGFOSIWINNT *PDBGFOSIWINNT;
2621/** Magic value for DBGFOSIWINNT::32Magic and DBGFOSIWINNT::u32EndMagic. (Dave Cutler) */
2622#define DBGFOSIWINNT_MAGIC UINT32_C(0x19420313)
2623
2624
2625VMMR3DECL(int) DBGFR3OSRegister(PUVM pUVM, PCDBGFOSREG pReg);
2626VMMR3DECL(int) DBGFR3OSDeregister(PUVM pUVM, PCDBGFOSREG pReg);
2627VMMR3DECL(int) DBGFR3OSDetect(PUVM pUVM, char *pszName, size_t cchName);
2628VMMR3DECL(int) DBGFR3OSQueryNameAndVersion(PUVM pUVM, char *pszName, size_t cchName, char *pszVersion, size_t cchVersion);
2629VMMR3DECL(void *) DBGFR3OSQueryInterface(PUVM pUVM, DBGFOSINTERFACE enmIf);
2630
2631
2632VMMR3DECL(int) DBGFR3CoreWrite(PUVM pUVM, const char *pszFilename, bool fReplaceFile);
2633
2634
2635
2636/** @defgroup grp_dbgf_plug_in The DBGF Plug-in Interface
2637 * @{
2638 */
2639
2640/** The plug-in module name prefix. */
2641# define DBGF_PLUG_IN_PREFIX "DbgPlugIn"
2642
2643/** The name of the plug-in entry point (FNDBGFPLUGIN) */
2644# define DBGF_PLUG_IN_ENTRYPOINT "DbgPlugInEntry"
2645
2646/**
2647 * DBGF plug-in operations.
2648 */
2649typedef enum DBGFPLUGINOP
2650{
2651 /** The usual invalid first value. */
2652 DBGFPLUGINOP_INVALID,
2653 /** Initialize the plug-in for a VM, register all the stuff.
2654 * The plug-in will be unloaded on failure.
2655 * uArg: The full VirtualBox version, see VBox/version.h. */
2656 DBGFPLUGINOP_INIT,
2657 /** Terminate the plug-ing for a VM, deregister all the stuff.
2658 * The plug-in will be unloaded after this call regardless of the return
2659 * code. */
2660 DBGFPLUGINOP_TERM,
2661 /** The usual 32-bit hack. */
2662 DBGFPLUGINOP_32BIT_HACK = 0x7fffffff
2663} DBGFPLUGINOP;
2664
2665/**
2666 * DBGF plug-in main entry point.
2667 *
2668 * @returns VBox status code.
2669 *
2670 * @param enmOperation The operation.
2671 * @param pUVM The user mode VM handle. This may be NULL.
2672 * @param uArg Extra argument.
2673 */
2674typedef DECLCALLBACKTYPE(int, FNDBGFPLUGIN,(DBGFPLUGINOP enmOperation, PUVM pUVM, uintptr_t uArg));
2675/** Pointer to a FNDBGFPLUGIN. */
2676typedef FNDBGFPLUGIN *PFNDBGFPLUGIN;
2677
2678/** @copydoc FNDBGFPLUGIN */
2679DECLEXPORT(int) DbgPlugInEntry(DBGFPLUGINOP enmOperation, PUVM pUVM, uintptr_t uArg);
2680
2681VMMR3DECL(int) DBGFR3PlugInLoad(PUVM pUVM, const char *pszPlugIn, char *pszActual, size_t cbActual, PRTERRINFO pErrInfo);
2682VMMR3DECL(int) DBGFR3PlugInUnload(PUVM pUVM, const char *pszName);
2683VMMR3DECL(void) DBGFR3PlugInLoadAll(PUVM pUVM);
2684VMMR3DECL(void) DBGFR3PlugInUnloadAll(PUVM pUVM);
2685
2686/** @} */
2687
2688
2689/** @defgroup grp_dbgf_types The DBGF type system Interface.
2690 * @{
2691 */
2692
2693/** A few forward declarations. */
2694/** Pointer to a type registration structure. */
2695typedef struct DBGFTYPEREG *PDBGFTYPEREG;
2696/** Pointer to a const type registration structure. */
2697typedef const struct DBGFTYPEREG *PCDBGFTYPEREG;
2698/** Pointer to a typed buffer. */
2699typedef struct DBGFTYPEVAL *PDBGFTYPEVAL;
2700
2701/**
2702 * DBGF built-in types.
2703 */
2704typedef enum DBGFTYPEBUILTIN
2705{
2706 /** The usual invalid first value. */
2707 DBGFTYPEBUILTIN_INVALID,
2708 /** Unsigned 8bit integer. */
2709 DBGFTYPEBUILTIN_UINT8,
2710 /** Signed 8bit integer. */
2711 DBGFTYPEBUILTIN_INT8,
2712 /** Unsigned 16bit integer. */
2713 DBGFTYPEBUILTIN_UINT16,
2714 /** Signed 16bit integer. */
2715 DBGFTYPEBUILTIN_INT16,
2716 /** Unsigned 32bit integer. */
2717 DBGFTYPEBUILTIN_UINT32,
2718 /** Signed 32bit integer. */
2719 DBGFTYPEBUILTIN_INT32,
2720 /** Unsigned 64bit integer. */
2721 DBGFTYPEBUILTIN_UINT64,
2722 /** Signed 64bit integer. */
2723 DBGFTYPEBUILTIN_INT64,
2724 /** 32bit Guest pointer */
2725 DBGFTYPEBUILTIN_PTR32,
2726 /** 64bit Guest pointer */
2727 DBGFTYPEBUILTIN_PTR64,
2728 /** Guest pointer - size depends on the guest bitness */
2729 DBGFTYPEBUILTIN_PTR,
2730 /** Type indicating a size, like size_t this can have different sizes
2731 * on 32bit and 64bit systems */
2732 DBGFTYPEBUILTIN_SIZE,
2733 /** 32bit float. */
2734 DBGFTYPEBUILTIN_FLOAT32,
2735 /** 64bit float (also known as double). */
2736 DBGFTYPEBUILTIN_FLOAT64,
2737 /** Compund types like structs and unions. */
2738 DBGFTYPEBUILTIN_COMPOUND,
2739 /** The usual 32-bit hack. */
2740 DBGFTYPEBUILTIN_32BIT_HACK = 0x7fffffff
2741} DBGFTYPEBUILTIN;
2742/** Pointer to a built-in type. */
2743typedef DBGFTYPEBUILTIN *PDBGFTYPEBUILTIN;
2744/** Pointer to a const built-in type. */
2745typedef const DBGFTYPEBUILTIN *PCDBGFTYPEBUILTIN;
2746
2747/**
2748 * DBGF type value buffer.
2749 */
2750typedef union DBGFTYPEVALBUF
2751{
2752 uint8_t u8;
2753 int8_t i8;
2754 uint16_t u16;
2755 int16_t i16;
2756 uint32_t u32;
2757 int32_t i32;
2758 uint64_t u64;
2759 int64_t i64;
2760 float f32;
2761 double f64;
2762 uint64_t size; /* For the built-in size_t which can be either 32-bit or 64-bit. */
2763 RTGCPTR GCPtr;
2764 /** For embedded structs. */
2765 PDBGFTYPEVAL pVal;
2766} DBGFTYPEVALBUF;
2767/** Pointer to a value. */
2768typedef DBGFTYPEVALBUF *PDBGFTYPEVALBUF;
2769
2770/**
2771 * DBGF type value entry.
2772 */
2773typedef struct DBGFTYPEVALENTRY
2774{
2775 /** DBGF built-in type. */
2776 DBGFTYPEBUILTIN enmType;
2777 /** Size of the type. */
2778 size_t cbType;
2779 /** Number of entries, for arrays this can be > 1. */
2780 uint32_t cEntries;
2781 /** Value buffer, depends on whether this is an array. */
2782 union
2783 {
2784 /** Single value. */
2785 DBGFTYPEVALBUF Val;
2786 /** Pointer to the array of values. */
2787 PDBGFTYPEVALBUF pVal;
2788 } Buf;
2789} DBGFTYPEVALENTRY;
2790/** Pointer to a type value entry. */
2791typedef DBGFTYPEVALENTRY *PDBGFTYPEVALENTRY;
2792/** Pointer to a const type value entry. */
2793typedef const DBGFTYPEVALENTRY *PCDBGFTYPEVALENTRY;
2794
2795/**
2796 * DBGF typed value.
2797 */
2798typedef struct DBGFTYPEVAL
2799{
2800 /** Pointer to the registration structure for this type. */
2801 PCDBGFTYPEREG pTypeReg;
2802 /** Number of value entries. */
2803 uint32_t cEntries;
2804 /** Variable sized array of value entries. */
2805 DBGFTYPEVALENTRY aEntries[1];
2806} DBGFTYPEVAL;
2807
2808/**
2809 * DBGF type variant.
2810 */
2811typedef enum DBGFTYPEVARIANT
2812{
2813 /** The usual invalid first value. */
2814 DBGFTYPEVARIANT_INVALID,
2815 /** A struct. */
2816 DBGFTYPEVARIANT_STRUCT,
2817 /** Union. */
2818 DBGFTYPEVARIANT_UNION,
2819 /** Alias for an existing type. */
2820 DBGFTYPEVARIANT_ALIAS,
2821 /** The usual 32-bit hack. */
2822 DBGFTYPEVARIANT_32BIT_HACK = 0x7fffffff
2823} DBGFTYPEVARIANT;
2824
2825/** @name DBGFTYPEREGMEMBER Flags.
2826 * @{ */
2827/** The member is an array with a fixed size. */
2828# define DBGFTYPEREGMEMBER_F_ARRAY RT_BIT_32(0)
2829/** The member denotes a pointer. */
2830# define DBGFTYPEREGMEMBER_F_POINTER RT_BIT_32(1)
2831/** @} */
2832
2833/**
2834 * DBGF type member.
2835 */
2836typedef struct DBGFTYPEREGMEMBER
2837{
2838 /** Name of the member. */
2839 const char *pszName;
2840 /** Flags for this member, see DBGFTYPEREGMEMBER_F_XXX. */
2841 uint32_t fFlags;
2842 /** Type identifier. */
2843 const char *pszType;
2844 /** The number of elements in the array, only valid for arrays. */
2845 uint32_t cElements;
2846} DBGFTYPEREGMEMBER;
2847/** Pointer to a member. */
2848typedef DBGFTYPEREGMEMBER *PDBGFTYPEREGMEMBER;
2849/** Pointer to a const member. */
2850typedef const DBGFTYPEREGMEMBER *PCDBGFTYPEREGMEMBER;
2851
2852/** @name DBGFTYPEREG Flags.
2853 * @{ */
2854/** The type is a packed structure. */
2855# define DBGFTYPEREG_F_PACKED RT_BIT_32(0)
2856/** @} */
2857
2858/**
2859 * New type registration structure.
2860 */
2861typedef struct DBGFTYPEREG
2862{
2863 /** Name of the type. */
2864 const char *pszType;
2865 /** The type variant. */
2866 DBGFTYPEVARIANT enmVariant;
2867 /** Some registration flags, see DBGFTYPEREG_F_XXX. */
2868 uint32_t fFlags;
2869 /** Number of members this type has, only valid for structs or unions. */
2870 uint32_t cMembers;
2871 /** Pointer to the member fields, only valid for structs or unions. */
2872 PCDBGFTYPEREGMEMBER paMembers;
2873 /** Name of the aliased type for aliases. */
2874 const char *pszAliasedType;
2875} DBGFTYPEREG;
2876
2877/**
2878 * DBGF typed value dumper callback.
2879 *
2880 * @returns VBox status code. Any non VINF_SUCCESS status code will abort the dumping.
2881 *
2882 * @param off The byte offset of the entry from the start of the type.
2883 * @param pszField The name of the field for the value.
2884 * @param iLvl The current level.
2885 * @param enmType The type enum.
2886 * @param cbType Size of the type.
2887 * @param pValBuf Pointer to the value buffer.
2888 * @param cValBufs Number of value buffers (for arrays).
2889 * @param pvUser Opaque user data.
2890 */
2891typedef DECLCALLBACKTYPE(int, FNDBGFR3TYPEVALDUMP,(uint32_t off, const char *pszField, uint32_t iLvl,
2892 DBGFTYPEBUILTIN enmType, size_t cbType,
2893 PDBGFTYPEVALBUF pValBuf, uint32_t cValBufs, void *pvUser));
2894/** Pointer to a FNDBGFR3TYPEVALDUMP. */
2895typedef FNDBGFR3TYPEVALDUMP *PFNDBGFR3TYPEVALDUMP;
2896
2897/**
2898 * DBGF type information dumper callback.
2899 *
2900 * @returns VBox status code. Any non VINF_SUCCESS status code will abort the dumping.
2901 *
2902 * @param off The byte offset of the entry from the start of the type.
2903 * @param pszField The name of the field for the value.
2904 * @param iLvl The current level.
2905 * @param pszType The type of the field.
2906 * @param fTypeFlags Flags for this type, see DBGFTYPEREGMEMBER_F_XXX.
2907 * @param cElements Number of for the field ( > 0 for arrays).
2908 * @param pvUser Opaque user data.
2909 */
2910typedef DECLCALLBACKTYPE(int, FNDBGFR3TYPEDUMP,(uint32_t off, const char *pszField, uint32_t iLvl,
2911 const char *pszType, uint32_t fTypeFlags,
2912 uint32_t cElements, void *pvUser));
2913/** Pointer to a FNDBGFR3TYPEDUMP. */
2914typedef FNDBGFR3TYPEDUMP *PFNDBGFR3TYPEDUMP;
2915
2916VMMR3DECL(int) DBGFR3TypeRegister( PUVM pUVM, uint32_t cTypes, PCDBGFTYPEREG paTypes);
2917VMMR3DECL(int) DBGFR3TypeDeregister(PUVM pUVM, const char *pszType);
2918VMMR3DECL(int) DBGFR3TypeQueryReg( PUVM pUVM, const char *pszType, PCDBGFTYPEREG *ppTypeReg);
2919
2920VMMR3DECL(int) DBGFR3TypeQuerySize( PUVM pUVM, const char *pszType, size_t *pcbType);
2921VMMR3DECL(int) DBGFR3TypeSetSize( PUVM pUVM, const char *pszType, size_t cbType);
2922VMMR3DECL(int) DBGFR3TypeDumpEx( PUVM pUVM, const char *pszType, uint32_t fFlags,
2923 uint32_t cLvlMax, PFNDBGFR3TYPEDUMP pfnDump, void *pvUser);
2924VMMR3DECL(int) DBGFR3TypeQueryValByType(PUVM pUVM, PCDBGFADDRESS pAddress, const char *pszType,
2925 PDBGFTYPEVAL *ppVal);
2926VMMR3DECL(void) DBGFR3TypeValFree(PDBGFTYPEVAL pVal);
2927VMMR3DECL(int) DBGFR3TypeValDumpEx(PUVM pUVM, PCDBGFADDRESS pAddress, const char *pszType, uint32_t fFlags,
2928 uint32_t cLvlMax, FNDBGFR3TYPEVALDUMP pfnDump, void *pvUser);
2929
2930/** @} */
2931
2932
2933/** @defgroup grp_dbgf_flow The DBGF control flow graph Interface.
2934 * @{
2935 */
2936
2937/** A DBGF control flow graph handle. */
2938typedef struct DBGFFLOWINT *DBGFFLOW;
2939/** Pointer to a DBGF control flow graph handle. */
2940typedef DBGFFLOW *PDBGFFLOW;
2941/** A DBGF control flow graph basic block handle. */
2942typedef struct DBGFFLOWBBINT *DBGFFLOWBB;
2943/** Pointer to a DBGF control flow graph basic block handle. */
2944typedef DBGFFLOWBB *PDBGFFLOWBB;
2945/** A DBGF control flow graph branch table handle. */
2946typedef struct DBGFFLOWBRANCHTBLINT *DBGFFLOWBRANCHTBL;
2947/** Pointer to a DBGF flow control graph branch table handle. */
2948typedef DBGFFLOWBRANCHTBL *PDBGFFLOWBRANCHTBL;
2949/** A DBGF control flow graph iterator. */
2950typedef struct DBGFFLOWITINT *DBGFFLOWIT;
2951/** Pointer to a control flow graph iterator. */
2952typedef DBGFFLOWIT *PDBGFFLOWIT;
2953/** A DBGF control flow graph branch table iterator. */
2954typedef struct DBGFFLOWBRANCHTBLITINT *DBGFFLOWBRANCHTBLIT;
2955/** Pointer to a control flow graph branch table iterator. */
2956typedef DBGFFLOWBRANCHTBLIT *PDBGFFLOWBRANCHTBLIT;
2957
2958/** @name DBGFFLOWBB Flags.
2959 * @{ */
2960/** The basic block is the entry into the owning control flow graph. */
2961#define DBGF_FLOW_BB_F_ENTRY RT_BIT_32(0)
2962/** The basic block was not populated because the limit was reached. */
2963#define DBGF_FLOW_BB_F_EMPTY RT_BIT_32(1)
2964/** The basic block is not complete because an error happened during disassembly. */
2965#define DBGF_FLOW_BB_F_INCOMPLETE_ERR RT_BIT_32(2)
2966/** The basic block is reached through a branch table. */
2967#define DBGF_FLOW_BB_F_BRANCH_TABLE RT_BIT_32(3)
2968/** The basic block consists only of a single call instruction because
2969 * DBGF_FLOW_CREATE_F_CALL_INSN_SEPARATE_BB was given. */
2970#define DBGF_FLOW_BB_F_CALL_INSN RT_BIT_32(4)
2971/** The branch target of the call instruction could be deduced and can be queried with
2972 * DBGFR3FlowBbGetBranchAddress(). May only be available when DBGF_FLOW_BB_F_CALL_INSN
2973 * is set. */
2974#define DBGF_FLOW_BB_F_CALL_INSN_TARGET_KNOWN RT_BIT_32(5)
2975/** @} */
2976
2977/** @name Flags controlling the creating of a control flow graph.
2978 * @{ */
2979/** Default options. */
2980#define DBGF_FLOW_CREATE_F_DEFAULT 0
2981/** Tries to resolve indirect branches, useful for code using
2982 * jump tables generated for large switch statements by some compilers. */
2983#define DBGF_FLOW_CREATE_F_TRY_RESOLVE_INDIRECT_BRANCHES RT_BIT_32(0)
2984/** Call instructions are placed in a separate basic block. */
2985#define DBGF_FLOW_CREATE_F_CALL_INSN_SEPARATE_BB RT_BIT_32(1)
2986/** @} */
2987
2988/**
2989 * DBGF control graph basic block end type.
2990 */
2991typedef enum DBGFFLOWBBENDTYPE
2992{
2993 /** Invalid type. */
2994 DBGFFLOWBBENDTYPE_INVALID = 0,
2995 /** Basic block is the exit block and has no successor. */
2996 DBGFFLOWBBENDTYPE_EXIT,
2997 /** Basic block is the last disassembled block because the
2998 * maximum amount to disassemble was reached but is not an
2999 * exit block - no successors.
3000 */
3001 DBGFFLOWBBENDTYPE_LAST_DISASSEMBLED,
3002 /** Unconditional control flow change because the successor is referenced by multiple
3003 * basic blocks. - 1 successor. */
3004 DBGFFLOWBBENDTYPE_UNCOND,
3005 /** Unconditional control flow change because of an direct branch - 1 successor. */
3006 DBGFFLOWBBENDTYPE_UNCOND_JMP,
3007 /** Unconditional control flow change because of an indirect branch - n successors. */
3008 DBGFFLOWBBENDTYPE_UNCOND_INDIRECT_JMP,
3009 /** Conditional control flow change - 2 successors. */
3010 DBGFFLOWBBENDTYPE_COND,
3011 /** 32bit hack. */
3012 DBGFFLOWBBENDTYPE_32BIT_HACK = 0x7fffffff
3013} DBGFFLOWBBENDTYPE;
3014
3015/**
3016 * DBGF control flow graph iteration order.
3017 */
3018typedef enum DBGFFLOWITORDER
3019{
3020 /** Invalid order. */
3021 DBGFFLOWITORDER_INVALID = 0,
3022 /** From lowest to highest basic block start address. */
3023 DBGFFLOWITORDER_BY_ADDR_LOWEST_FIRST,
3024 /** From highest to lowest basic block start address. */
3025 DBGFFLOWITORDER_BY_ADDR_HIGHEST_FIRST,
3026 /** Depth first traversing starting from the entry block. */
3027 DBGFFLOWITORDER_DEPTH_FRIST,
3028 /** Breadth first traversing starting from the entry block. */
3029 DBGFFLOWITORDER_BREADTH_FIRST,
3030 /** Usual 32bit hack. */
3031 DBGFFLOWITORDER_32BIT_HACK = 0x7fffffff
3032} DBGFFLOWITORDER;
3033/** Pointer to a iteration order enum. */
3034typedef DBGFFLOWITORDER *PDBGFFLOWITORDER;
3035
3036
3037VMMR3DECL(int) DBGFR3FlowCreate(PUVM pUVM, VMCPUID idCpu, PDBGFADDRESS pAddressStart, uint32_t cbDisasmMax,
3038 uint32_t fFlagsFlow, uint32_t fFlagsDisasm, PDBGFFLOW phFlow);
3039VMMR3DECL(uint32_t) DBGFR3FlowRetain(DBGFFLOW hFlow);
3040VMMR3DECL(uint32_t) DBGFR3FlowRelease(DBGFFLOW hFlow);
3041VMMR3DECL(int) DBGFR3FlowQueryStartBb(DBGFFLOW hFlow, PDBGFFLOWBB phFlowBb);
3042VMMR3DECL(int) DBGFR3FlowQueryBbByAddress(DBGFFLOW hFlow, PDBGFADDRESS pAddr, PDBGFFLOWBB phFlowBb);
3043VMMR3DECL(int) DBGFR3FlowQueryBranchTblByAddress(DBGFFLOW hFlow, PDBGFADDRESS pAddr, PDBGFFLOWBRANCHTBL phFlowBranchTbl);
3044VMMR3DECL(uint32_t) DBGFR3FlowGetBbCount(DBGFFLOW hFlow);
3045VMMR3DECL(uint32_t) DBGFR3FlowGetBranchTblCount(DBGFFLOW hFlow);
3046VMMR3DECL(uint32_t) DBGFR3FlowGetCallInsnCount(DBGFFLOW hFlow);
3047
3048VMMR3DECL(uint32_t) DBGFR3FlowBbRetain(DBGFFLOWBB hFlowBb);
3049VMMR3DECL(uint32_t) DBGFR3FlowBbRelease(DBGFFLOWBB hFlowBb);
3050VMMR3DECL(PDBGFADDRESS) DBGFR3FlowBbGetStartAddress(DBGFFLOWBB hFlowBb, PDBGFADDRESS pAddrStart);
3051VMMR3DECL(PDBGFADDRESS) DBGFR3FlowBbGetEndAddress(DBGFFLOWBB hFlowBb, PDBGFADDRESS pAddrEnd);
3052VMMR3DECL(PDBGFADDRESS) DBGFR3FlowBbGetBranchAddress(DBGFFLOWBB hFlowBb, PDBGFADDRESS pAddrTarget);
3053VMMR3DECL(PDBGFADDRESS) DBGFR3FlowBbGetFollowingAddress(DBGFFLOWBB hFlowBb, PDBGFADDRESS pAddrFollow);
3054VMMR3DECL(DBGFFLOWBBENDTYPE) DBGFR3FlowBbGetType(DBGFFLOWBB hFlowBb);
3055VMMR3DECL(uint32_t) DBGFR3FlowBbGetInstrCount(DBGFFLOWBB hFlowBb);
3056VMMR3DECL(uint32_t) DBGFR3FlowBbGetFlags(DBGFFLOWBB hFlowBb);
3057VMMR3DECL(int) DBGFR3FlowBbQueryBranchTbl(DBGFFLOWBB hFlowBb, PDBGFFLOWBRANCHTBL phBranchTbl);
3058VMMR3DECL(int) DBGFR3FlowBbQueryError(DBGFFLOWBB hFlowBb, const char **ppszErr);
3059VMMR3DECL(int) DBGFR3FlowBbQueryInstr(DBGFFLOWBB hFlowBb, uint32_t idxInstr, PDBGFADDRESS pAddrInstr,
3060 uint32_t *pcbInstr, const char **ppszInstr);
3061VMMR3DECL(int) DBGFR3FlowBbQuerySuccessors(DBGFFLOWBB hFlowBb, PDBGFFLOWBB phFlowBbFollow,
3062 PDBGFFLOWBB phFlowBbTarget);
3063VMMR3DECL(uint32_t) DBGFR3FlowBbGetRefBbCount(DBGFFLOWBB hFlowBb);
3064VMMR3DECL(int) DBGFR3FlowBbGetRefBb(DBGFFLOWBB hFlowBb, PDBGFFLOWBB pahFlowBbRef, uint32_t cRef);
3065
3066VMMR3DECL(uint32_t) DBGFR3FlowBranchTblRetain(DBGFFLOWBRANCHTBL hFlowBranchTbl);
3067VMMR3DECL(uint32_t) DBGFR3FlowBranchTblRelease(DBGFFLOWBRANCHTBL hFlowBranchTbl);
3068VMMR3DECL(uint32_t) DBGFR3FlowBranchTblGetSlots(DBGFFLOWBRANCHTBL hFlowBranchTbl);
3069VMMR3DECL(PDBGFADDRESS) DBGFR3FlowBranchTblGetStartAddress(DBGFFLOWBRANCHTBL hFlowBranchTbl, PDBGFADDRESS pAddrStart);
3070VMMR3DECL(PDBGFADDRESS) DBGFR3FlowBranchTblGetAddrAtSlot(DBGFFLOWBRANCHTBL hFlowBranchTbl, uint32_t idxSlot, PDBGFADDRESS pAddrSlot);
3071VMMR3DECL(int) DBGFR3FlowBranchTblQueryAddresses(DBGFFLOWBRANCHTBL hFlowBranchTbl, PDBGFADDRESS paAddrs, uint32_t cAddrs);
3072
3073VMMR3DECL(int) DBGFR3FlowItCreate(DBGFFLOW hFlow, DBGFFLOWITORDER enmOrder, PDBGFFLOWIT phFlowIt);
3074VMMR3DECL(void) DBGFR3FlowItDestroy(DBGFFLOWIT hFlowIt);
3075VMMR3DECL(DBGFFLOWBB) DBGFR3FlowItNext(DBGFFLOWIT hFlowIt);
3076VMMR3DECL(int) DBGFR3FlowItReset(DBGFFLOWIT hFlowIt);
3077
3078VMMR3DECL(int) DBGFR3FlowBranchTblItCreate(DBGFFLOW hFlow, DBGFFLOWITORDER enmOrder, PDBGFFLOWBRANCHTBLIT phFlowBranchTblIt);
3079VMMR3DECL(void) DBGFR3FlowBranchTblItDestroy(DBGFFLOWBRANCHTBLIT hFlowBranchTblIt);
3080VMMR3DECL(DBGFFLOWBRANCHTBL) DBGFR3FlowBranchTblItNext(DBGFFLOWBRANCHTBLIT hFlowBranchTblIt);
3081VMMR3DECL(int) DBGFR3FlowBranchTblItReset(DBGFFLOWBRANCHTBLIT hFlowBranchTblIt);
3082
3083/** @} */
3084
3085
3086/** @defgroup grp_dbgf_misc Misc DBGF interfaces.
3087 * @{ */
3088VMMR3DECL(VBOXSTRICTRC) DBGFR3ReportBugCheck(PVM pVM, PVMCPU pVCpu, DBGFEVENTTYPE enmEvent, uint64_t uBugCheck,
3089 uint64_t uP1, uint64_t uP2, uint64_t uP3, uint64_t uP4);
3090VMMR3DECL(int) DBGFR3FormatBugCheck(PUVM pUVM, char *pszDetails, size_t cbDetails,
3091 uint64_t uP0, uint64_t uP1, uint64_t uP2, uint64_t uP3, uint64_t uP4);
3092/** @} */
3093#endif /* IN_RING3 */
3094
3095
3096/** @defgroup grp_dbgf_tracer DBGF event tracing.
3097 * @{ */
3098#ifdef IN_RING3
3099VMMR3_INT_DECL(int) DBGFR3TracerRegisterEvtSrc(PVM pVM, const char *pszName, PDBGFTRACEREVTSRC phEvtSrc);
3100VMMR3_INT_DECL(int) DBGFR3TracerDeregisterEvtSrc(PVM pVM, DBGFTRACEREVTSRC hEvtSrc);
3101VMMR3_INT_DECL(int) DBGFR3TracerEvtIoPortCreate(PVM pVM, DBGFTRACEREVTSRC hEvtSrc, uint64_t hRegion, RTIOPORT cPorts, uint32_t fFlags,
3102 uint32_t iPciRegion);
3103VMMR3_INT_DECL(int) DBGFR3TracerEvtMmioCreate(PVM pVM, DBGFTRACEREVTSRC hEvtSrc, uint64_t hRegion, RTGCPHYS cbRegion, uint32_t fFlags,
3104 uint32_t iPciRegion);
3105#endif
3106
3107VMM_INT_DECL(int) DBGFTracerEvtMmioMap(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, uint64_t hRegion, RTGCPHYS GCPhysMmio);
3108VMM_INT_DECL(int) DBGFTracerEvtMmioUnmap(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, uint64_t hRegion);
3109VMM_INT_DECL(int) DBGFTracerEvtMmioRead(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, uint64_t hRegion, RTGCPHYS offMmio, const void *pvVal, size_t cbVal);
3110VMM_INT_DECL(int) DBGFTracerEvtMmioWrite(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, uint64_t hRegion, RTGCPHYS offMmio, const void *pvVal, size_t cbVal);
3111VMM_INT_DECL(int) DBGFTracerEvtMmioFill(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, uint64_t hRegion, RTGCPHYS offMmio, uint32_t u32Item, uint32_t cbItem, uint32_t cItems);
3112VMM_INT_DECL(int) DBGFTracerEvtIoPortMap(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, uint64_t hIoPorts, RTIOPORT IoPortBase);
3113VMM_INT_DECL(int) DBGFTracerEvtIoPortUnmap(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, uint64_t hIoPorts);
3114VMM_INT_DECL(int) DBGFTracerEvtIoPortRead(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, uint64_t hIoPorts, RTIOPORT offPort, const void *pvVal, size_t cbVal);
3115VMM_INT_DECL(int) DBGFTracerEvtIoPortReadStr(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, uint64_t hIoPorts, RTIOPORT offPort, const void *pv, size_t cb,
3116 uint32_t cTransfersReq, uint32_t cTransfersRet);
3117VMM_INT_DECL(int) DBGFTracerEvtIoPortWrite(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, uint64_t hIoPorts, RTIOPORT offPort, const void *pvVal, size_t cbVal);
3118VMM_INT_DECL(int) DBGFTracerEvtIoPortWriteStr(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) DBGFTracerEvtIrq(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, int32_t iIrq, int32_t fIrqLvl);
3121VMM_INT_DECL(int) DBGFTracerEvtIoApicMsi(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, RTGCPHYS GCPhys, uint32_t u32Val);
3122VMM_INT_DECL(int) DBGFTracerEvtGCPhysRead(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, RTGCPHYS GCPhys, const void *pvBuf, size_t cbRead);
3123VMM_INT_DECL(int) DBGFTracerEvtGCPhysWrite(PVMCC pVM, DBGFTRACEREVTSRC hEvtSrc, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite);
3124/** @} */
3125
3126
3127/** @defgroup grp_dbgf_sample_report DBGF sample report.
3128 * @{ */
3129
3130/**
3131 * Callback which provides progress information about a currently running
3132 * lengthy operation.
3133 *
3134 * @return VBox status code.
3135 * @retval VERR_DBGF_CANCELLED to cancel the operation.
3136 * @param pvUser The opaque user data associated with this interface.
3137 * @param uPercentage Completion percentage.
3138 */
3139typedef DECLCALLBACKTYPE(int, FNDBGFPROGRESS,(void *pvUser, unsigned uPercentage));
3140/** Pointer to FNDBGFPROGRESS() */
3141typedef FNDBGFPROGRESS *PFNDBGFPROGRESS;
3142
3143/** @name Flags to pass to DBGFR3SampleReportCreate().
3144 * @{ */
3145/** The report creates the call stack in reverse order (bottom to top). */
3146#define DBGF_SAMPLE_REPORT_F_STACK_REVERSE RT_BIT(0)
3147/** Mask containing the valid flags. */
3148#define DBGF_SAMPLE_REPORT_F_VALID_MASK UINT32_C(0x00000001)
3149/** @} */
3150
3151VMMR3DECL(int) DBGFR3SampleReportCreate(PUVM pUVM, uint32_t cSampleIntervalMs, uint32_t fFlags, PDBGFSAMPLEREPORT phSample);
3152VMMR3DECL(uint32_t) DBGFR3SampleReportRetain(DBGFSAMPLEREPORT hSample);
3153VMMR3DECL(uint32_t) DBGFR3SampleReportRelease(DBGFSAMPLEREPORT hSample);
3154VMMR3DECL(int) DBGFR3SampleReportStart(DBGFSAMPLEREPORT hSample, uint64_t cSampleUs, PFNDBGFPROGRESS pfnProgress, void *pvUser);
3155VMMR3DECL(int) DBGFR3SampleReportStop(DBGFSAMPLEREPORT hSample);
3156VMMR3DECL(int) DBGFR3SampleReportDumpToFile(DBGFSAMPLEREPORT hSample, const char *pszFilename);
3157/** @} */
3158
3159/** @} */
3160
3161RT_C_DECLS_END
3162
3163#endif /* !VBOX_INCLUDED_vmm_dbgf_h */
3164
Note: See TracBrowser for help on using the repository browser.

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