VirtualBox

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

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

VMM/DBGFTracer: Support string I/O port accesses, bugref:9210

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

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