VirtualBox

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

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

DBGFInfo: Added a getopt error reporter helper.

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