VirtualBox

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

Last change on this file since 86098 was 86098, checked in by vboxsync, 5 years ago

VMM/DBGF: Rework part 1 to make it work well with SMP VMs. bugref:9822

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

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