VirtualBox

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

Last change on this file since 80014 was 80014, checked in by vboxsync, 6 years ago

VMM: Kicking out raw-mode (work in progress). bugref:9517

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 110.9 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
911/**
912 * Info helper callback structure.
913 */
914typedef struct DBGFINFOHLP
915{
916 /**
917 * Print formatted string.
918 *
919 * @param pHlp Pointer to this structure.
920 * @param pszFormat The format string.
921 * @param ... Arguments.
922 */
923 DECLCALLBACKMEMBER(void, pfnPrintf)(PCDBGFINFOHLP pHlp, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3);
924
925 /**
926 * Print formatted string.
927 *
928 * @param pHlp Pointer to this structure.
929 * @param pszFormat The format string.
930 * @param args Argument list.
931 */
932 DECLCALLBACKMEMBER(void, pfnPrintfV)(PCDBGFINFOHLP pHlp, const char *pszFormat, va_list args) RT_IPRT_FORMAT_ATTR(2, 0);
933} DBGFINFOHLP;
934
935
936/**
937 * Info handler, device version.
938 *
939 * @param pDevIns The device instance which registered the info.
940 * @param pHlp Callback functions for doing output.
941 * @param pszArgs Argument string. Optional and specific to the handler.
942 */
943typedef DECLCALLBACK(void) FNDBGFHANDLERDEV(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs);
944/** Pointer to a FNDBGFHANDLERDEV function. */
945typedef FNDBGFHANDLERDEV *PFNDBGFHANDLERDEV;
946
947/**
948 * Info handler, USB device version.
949 *
950 * @param pUsbIns The USB device instance which registered the info.
951 * @param pHlp Callback functions for doing output.
952 * @param pszArgs Argument string. Optional and specific to the handler.
953 */
954typedef DECLCALLBACK(void) FNDBGFHANDLERUSB(PPDMUSBINS pUsbIns, PCDBGFINFOHLP pHlp, const char *pszArgs);
955/** Pointer to a FNDBGFHANDLERUSB function. */
956typedef FNDBGFHANDLERUSB *PFNDBGFHANDLERUSB;
957
958/**
959 * Info handler, driver version.
960 *
961 * @param pDrvIns The driver instance which registered the info.
962 * @param pHlp Callback functions for doing output.
963 * @param pszArgs Argument string. Optional and specific to the handler.
964 */
965typedef DECLCALLBACK(void) FNDBGFHANDLERDRV(PPDMDRVINS pDrvIns, PCDBGFINFOHLP pHlp, const char *pszArgs);
966/** Pointer to a FNDBGFHANDLERDRV function. */
967typedef FNDBGFHANDLERDRV *PFNDBGFHANDLERDRV;
968
969/**
970 * Info handler, internal version.
971 *
972 * @param pVM The cross context VM structure.
973 * @param pHlp Callback functions for doing output.
974 * @param pszArgs Argument string. Optional and specific to the handler.
975 */
976typedef DECLCALLBACK(void) FNDBGFHANDLERINT(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
977/** Pointer to a FNDBGFHANDLERINT function. */
978typedef FNDBGFHANDLERINT *PFNDBGFHANDLERINT;
979
980/**
981 * Info handler, external version.
982 *
983 * @param pvUser User argument.
984 * @param pHlp Callback functions for doing output.
985 * @param pszArgs Argument string. Optional and specific to the handler.
986 */
987typedef DECLCALLBACK(void) FNDBGFHANDLEREXT(void *pvUser, PCDBGFINFOHLP pHlp, const char *pszArgs);
988/** Pointer to a FNDBGFHANDLEREXT function. */
989typedef FNDBGFHANDLEREXT *PFNDBGFHANDLEREXT;
990
991
992/** @name Flags for the info registration functions.
993 * @{ */
994/** The handler must run on the EMT. */
995#define DBGFINFO_FLAGS_RUN_ON_EMT RT_BIT(0)
996/** Call on all EMTs when a specific isn't specified. */
997#define DBGFINFO_FLAGS_ALL_EMTS RT_BIT(1)
998/** @} */
999
1000VMMR3_INT_DECL(int) DBGFR3InfoRegisterDevice(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDEV pfnHandler, PPDMDEVINS pDevIns);
1001VMMR3_INT_DECL(int) DBGFR3InfoRegisterDriver(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDRV pfnHandler, PPDMDRVINS pDrvIns);
1002VMMR3_INT_DECL(int) DBGFR3InfoRegisterInternal(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFHANDLERINT pfnHandler);
1003VMMR3_INT_DECL(int) DBGFR3InfoRegisterInternalEx(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFHANDLERINT pfnHandler, uint32_t fFlags);
1004VMMR3DECL(int) DBGFR3InfoRegisterExternal(PUVM pUVM, const char *pszName, const char *pszDesc, PFNDBGFHANDLEREXT pfnHandler, void *pvUser);
1005VMMR3_INT_DECL(int) DBGFR3InfoDeregisterDevice(PVM pVM, PPDMDEVINS pDevIns, const char *pszName);
1006VMMR3_INT_DECL(int) DBGFR3InfoDeregisterDriver(PVM pVM, PPDMDRVINS pDrvIns, const char *pszName);
1007VMMR3_INT_DECL(int) DBGFR3InfoDeregisterInternal(PVM pVM, const char *pszName);
1008VMMR3DECL(int) DBGFR3InfoDeregisterExternal(PUVM pUVM, const char *pszName);
1009VMMR3DECL(int) DBGFR3Info(PUVM pUVM, const char *pszName, const char *pszArgs, PCDBGFINFOHLP pHlp);
1010VMMR3DECL(int) DBGFR3InfoEx(PUVM pUVM, VMCPUID idCpu, const char *pszName, const char *pszArgs, PCDBGFINFOHLP pHlp);
1011VMMR3DECL(int) DBGFR3InfoLogRel(PUVM pUVM, const char *pszName, const char *pszArgs);
1012VMMR3DECL(int) DBGFR3InfoStdErr(PUVM pUVM, const char *pszName, const char *pszArgs);
1013VMMR3_INT_DECL(int) DBGFR3InfoMulti(PVM pVM, const char *pszIncludePat, const char *pszExcludePat,
1014 const char *pszSepFmt, PCDBGFINFOHLP pHlp);
1015
1016/** @def DBGFR3_INFO_LOG
1017 * Display a piece of info writing to the log if enabled.
1018 *
1019 * This is for execution on EMTs and will only show the items on the calling
1020 * EMT. This is to avoid deadlocking against other CPUs if a rendezvous is
1021 * initiated in parallel to this call. (Besides, nobody really wants or need
1022 * info for the other EMTs when using this macro.)
1023 *
1024 * @param a_pVM The shared VM handle.
1025 * @param a_pVCpu The cross context per CPU structure of the calling EMT.
1026 * @param a_pszName The identifier of the info to display.
1027 * @param a_pszArgs Arguments to the info handler.
1028 */
1029#ifdef LOG_ENABLED
1030# define DBGFR3_INFO_LOG(a_pVM, a_pVCpu, a_pszName, a_pszArgs) \
1031 do { \
1032 if (LogIsEnabled()) \
1033 DBGFR3InfoEx((a_pVM)->pUVM, (a_pVCpu)->idCpu, a_pszName, a_pszArgs, NULL); \
1034 } while (0)
1035#else
1036# define DBGFR3_INFO_LOG(a_pVM, a_pVCpu, a_pszName, a_pszArgs) do { } while (0)
1037#endif
1038
1039/** @def DBGFR3_INFO_LOG_SAFE
1040 * Display a piece of info (rendezvous safe) writing to the log if enabled.
1041 *
1042 * @param a_pVM The shared VM handle.
1043 * @param a_pszName The identifier of the info to display.
1044 * @param a_pszArgs Arguments to the info handler.
1045 *
1046 * @remarks Use DBGFR3_INFO_LOG where ever possible!
1047 */
1048#ifdef LOG_ENABLED
1049# define DBGFR3_INFO_LOG_SAFE(a_pVM, a_pszName, a_pszArgs) \
1050 do { \
1051 if (LogIsEnabled()) \
1052 DBGFR3Info((a_pVM)->pUVM, a_pszName, a_pszArgs, NULL); \
1053 } while (0)
1054#else
1055# define DBGFR3_INFO_LOG_SAFE(a_pVM, a_pszName, a_pszArgs) do { } while (0)
1056#endif
1057
1058/**
1059 * Enumeration callback for use with DBGFR3InfoEnum.
1060 *
1061 * @returns VBox status code.
1062 * A status code indicating failure will end the enumeration
1063 * and DBGFR3InfoEnum will return with that status code.
1064 * @param pUVM The user mode VM handle.
1065 * @param pszName Info identifier name.
1066 * @param pszDesc The description.
1067 */
1068typedef DECLCALLBACK(int) FNDBGFINFOENUM(PUVM pUVM, const char *pszName, const char *pszDesc, void *pvUser);
1069/** Pointer to a FNDBGFINFOENUM function. */
1070typedef FNDBGFINFOENUM *PFNDBGFINFOENUM;
1071
1072VMMR3DECL(int) DBGFR3InfoEnum(PUVM pUVM, PFNDBGFINFOENUM pfnCallback, void *pvUser);
1073VMMR3DECL(PCDBGFINFOHLP) DBGFR3InfoLogHlp(void);
1074VMMR3DECL(PCDBGFINFOHLP) DBGFR3InfoLogRelHlp(void);
1075
1076#endif /* IN_RING3 */
1077
1078
1079#ifdef IN_RING3 /* The log contrl API only works in ring-3. */
1080VMMR3DECL(int) DBGFR3LogModifyGroups(PUVM pUVM, const char *pszGroupSettings);
1081VMMR3DECL(int) DBGFR3LogModifyFlags(PUVM pUVM, const char *pszFlagSettings);
1082VMMR3DECL(int) DBGFR3LogModifyDestinations(PUVM pUVM, const char *pszDestSettings);
1083#endif /* IN_RING3 */
1084
1085#ifdef IN_RING3 /* The debug information management APIs only works in ring-3. */
1086
1087/** Max length (including '\\0') of a symbol name. */
1088#define DBGF_SYMBOL_NAME_LENGTH 512
1089
1090/**
1091 * Debug symbol.
1092 */
1093typedef struct DBGFSYMBOL
1094{
1095 /** Symbol value (address). */
1096 RTGCUINTPTR Value;
1097 /** Symbol size. */
1098 uint32_t cb;
1099 /** Symbol Flags. (reserved). */
1100 uint32_t fFlags;
1101 /** Symbol name. */
1102 char szName[DBGF_SYMBOL_NAME_LENGTH];
1103} DBGFSYMBOL;
1104/** Pointer to debug symbol. */
1105typedef DBGFSYMBOL *PDBGFSYMBOL;
1106/** Pointer to const debug symbol. */
1107typedef const DBGFSYMBOL *PCDBGFSYMBOL;
1108
1109/**
1110 * Debug line number information.
1111 */
1112typedef struct DBGFLINE
1113{
1114 /** Address. */
1115 RTGCUINTPTR Address;
1116 /** Line number. */
1117 uint32_t uLineNo;
1118 /** Filename. */
1119 char szFilename[260];
1120} DBGFLINE;
1121/** Pointer to debug line number. */
1122typedef DBGFLINE *PDBGFLINE;
1123/** Pointer to const debug line number. */
1124typedef const DBGFLINE *PCDBGFLINE;
1125
1126/** @name Address spaces aliases.
1127 * @{ */
1128/** The guest global address space. */
1129#define DBGF_AS_GLOBAL ((RTDBGAS)-1)
1130/** The guest kernel address space.
1131 * This is usually resolves to the same as DBGF_AS_GLOBAL. */
1132#define DBGF_AS_KERNEL ((RTDBGAS)-2)
1133/** The physical address space. */
1134#define DBGF_AS_PHYS ((RTDBGAS)-3)
1135/** Raw-mode context. */
1136#define DBGF_AS_RC ((RTDBGAS)-4)
1137/** Ring-0 context. */
1138#define DBGF_AS_R0 ((RTDBGAS)-5)
1139/** Raw-mode context and then global guest context.
1140 * When used for looking up information, it works as if the call was first made
1141 * with DBGF_AS_RC and then on failure with DBGF_AS_GLOBAL. When called for
1142 * making address space changes, it works as if DBGF_AS_RC was used. */
1143#define DBGF_AS_RC_AND_GC_GLOBAL ((RTDBGAS)-6)
1144
1145/** The first special one. */
1146#define DBGF_AS_FIRST DBGF_AS_RC_AND_GC_GLOBAL
1147/** The last special one. */
1148#define DBGF_AS_LAST DBGF_AS_GLOBAL
1149#endif
1150/** The number of special address space handles. */
1151#define DBGF_AS_COUNT (6U)
1152#ifdef IN_RING3
1153/** Converts an alias handle to an array index. */
1154#define DBGF_AS_ALIAS_2_INDEX(hAlias) \
1155 ( (uintptr_t)(hAlias) - (uintptr_t)DBGF_AS_FIRST )
1156/** Predicat macro that check if the specified handle is an alias. */
1157#define DBGF_AS_IS_ALIAS(hAlias) \
1158 ( DBGF_AS_ALIAS_2_INDEX(hAlias) < DBGF_AS_COUNT )
1159/** Predicat macro that check if the specified alias is a fixed one or not. */
1160#define DBGF_AS_IS_FIXED_ALIAS(hAlias) \
1161 ( DBGF_AS_ALIAS_2_INDEX(hAlias) < (uintptr_t)DBGF_AS_PHYS - (uintptr_t)DBGF_AS_FIRST + 1U )
1162
1163/** @} */
1164
1165VMMR3DECL(RTDBGCFG) DBGFR3AsGetConfig(PUVM pUVM);
1166
1167VMMR3DECL(int) DBGFR3AsAdd(PUVM pUVM, RTDBGAS hDbgAs, RTPROCESS ProcId);
1168VMMR3DECL(int) DBGFR3AsDelete(PUVM pUVM, RTDBGAS hDbgAs);
1169VMMR3DECL(int) DBGFR3AsSetAlias(PUVM pUVM, RTDBGAS hAlias, RTDBGAS hAliasFor);
1170VMMR3DECL(RTDBGAS) DBGFR3AsResolve(PUVM pUVM, RTDBGAS hAlias);
1171VMMR3DECL(RTDBGAS) DBGFR3AsResolveAndRetain(PUVM pUVM, RTDBGAS hAlias);
1172VMMR3DECL(RTDBGAS) DBGFR3AsQueryByName(PUVM pUVM, const char *pszName);
1173VMMR3DECL(RTDBGAS) DBGFR3AsQueryByPid(PUVM pUVM, RTPROCESS ProcId);
1174
1175VMMR3DECL(int) DBGFR3AsLoadImage(PUVM pUVM, RTDBGAS hDbgAs, const char *pszFilename, const char *pszModName,
1176 RTLDRARCH enmArch, PCDBGFADDRESS pModAddress, RTDBGSEGIDX iModSeg, uint32_t fFlags);
1177VMMR3DECL(int) DBGFR3AsLoadMap(PUVM pUVM, RTDBGAS hDbgAs, const char *pszFilename, const char *pszModName, PCDBGFADDRESS pModAddress, RTDBGSEGIDX iModSeg, RTGCUINTPTR uSubtrahend, uint32_t fFlags);
1178VMMR3DECL(int) DBGFR3AsLinkModule(PUVM pUVM, RTDBGAS hDbgAs, RTDBGMOD hMod, PCDBGFADDRESS pModAddress, RTDBGSEGIDX iModSeg, uint32_t fFlags);
1179VMMR3DECL(int) DBGFR3AsUnlinkModuleByName(PUVM pUVM, RTDBGAS hDbgAs, const char *pszModName);
1180
1181VMMR3DECL(int) DBGFR3AsSymbolByAddr(PUVM pUVM, RTDBGAS hDbgAs, PCDBGFADDRESS pAddress, uint32_t fFlags,
1182 PRTGCINTPTR poffDisp, PRTDBGSYMBOL pSymbol, PRTDBGMOD phMod);
1183VMMR3DECL(PRTDBGSYMBOL) DBGFR3AsSymbolByAddrA(PUVM pUVM, RTDBGAS hDbgAs, PCDBGFADDRESS pAddress, uint32_t Flags,
1184 PRTGCINTPTR poffDisp, PRTDBGMOD phMod);
1185VMMR3DECL(int) DBGFR3AsSymbolByName(PUVM pUVM, RTDBGAS hDbgAs, const char *pszSymbol, PRTDBGSYMBOL pSymbol, PRTDBGMOD phMod);
1186
1187VMMR3DECL(int) DBGFR3AsLineByAddr(PUVM pUVM, RTDBGAS hDbgAs, PCDBGFADDRESS pAddress,
1188 PRTGCINTPTR poffDisp, PRTDBGLINE pLine, PRTDBGMOD phMod);
1189VMMR3DECL(PRTDBGLINE) DBGFR3AsLineByAddrA(PUVM pUVM, RTDBGAS hDbgAs, PCDBGFADDRESS pAddress,
1190 PRTGCINTPTR poffDisp, PRTDBGMOD phMod);
1191
1192/** @name DBGFMOD_PE_F_XXX - flags for
1193 * @{ */
1194/** NT 3.1 images were a little different, so make allowances for that. */
1195#define DBGFMODINMEM_F_PE_NT31 RT_BIT_32(0)
1196/** No container fallback. */
1197#define DBGFMODINMEM_F_NO_CONTAINER_FALLBACK RT_BIT_32(1)
1198/** No in-memory reader fallback. */
1199#define DBGFMODINMEM_F_NO_READER_FALLBACK RT_BIT_32(2)
1200/** Valid flags. */
1201#define DBGFMODINMEM_F_VALID_MASK UINT32_C(0x00000007)
1202/** @} */
1203VMMR3DECL(int) DBGFR3ModInMem(PUVM pUVM, PCDBGFADDRESS pImageAddr, uint32_t fFlags, const char *pszName,
1204 const char *pszFilename, RTLDRARCH enmArch, uint32_t cbImage,
1205 PRTDBGMOD phDbgMod, PRTERRINFO pErrInfo);
1206
1207#endif /* IN_RING3 */
1208
1209#ifdef IN_RING3 /* The stack API only works in ring-3. */
1210
1211/** Pointer to stack frame info. */
1212typedef struct DBGFSTACKFRAME *PDBGFSTACKFRAME;
1213/** Pointer to const stack frame info. */
1214typedef struct DBGFSTACKFRAME const *PCDBGFSTACKFRAME;
1215/**
1216 * Info about a stack frame.
1217 */
1218typedef struct DBGFSTACKFRAME
1219{
1220 /** Frame number. */
1221 uint32_t iFrame;
1222 /** Frame flags (DBGFSTACKFRAME_FLAGS_XXX). */
1223 uint32_t fFlags;
1224 /** The stack address of the frame.
1225 * The off member is [e|r]sp and the Sel member is ss. */
1226 DBGFADDRESS AddrStack;
1227 /** The program counter (PC) address of the frame.
1228 * The off member is [e|r]ip and the Sel member is cs. */
1229 DBGFADDRESS AddrPC;
1230 /** Pointer to the symbol nearest the program counter (PC). NULL if not found. */
1231 PRTDBGSYMBOL pSymPC;
1232 /** Pointer to the linenumber nearest the program counter (PC). NULL if not found. */
1233 PRTDBGLINE pLinePC;
1234 /** The frame address.
1235 * The off member is [e|r]bp and the Sel member is ss. */
1236 DBGFADDRESS AddrFrame;
1237 /** The way this frame returns to the next one. */
1238 RTDBGRETURNTYPE enmReturnType;
1239
1240 /** The way the next frame returns.
1241 * Only valid when DBGFSTACKFRAME_FLAGS_UNWIND_INFO_RET is set. */
1242 RTDBGRETURNTYPE enmReturnFrameReturnType;
1243 /** The return frame address.
1244 * The off member is [e|r]bp and the Sel member is ss. */
1245 DBGFADDRESS AddrReturnFrame;
1246 /** The return stack address.
1247 * The off member is [e|r]sp and the Sel member is ss. */
1248 DBGFADDRESS AddrReturnStack;
1249
1250 /** The program counter (PC) address which the frame returns to.
1251 * The off member is [e|r]ip and the Sel member is cs. */
1252 DBGFADDRESS AddrReturnPC;
1253 /** Pointer to the symbol nearest the return PC. NULL if not found. */
1254 PRTDBGSYMBOL pSymReturnPC;
1255 /** Pointer to the linenumber nearest the return PC. NULL if not found. */
1256 PRTDBGLINE pLineReturnPC;
1257
1258 /** 32-bytes of stack arguments. */
1259 union
1260 {
1261 /** 64-bit view */
1262 uint64_t au64[4];
1263 /** 32-bit view */
1264 uint32_t au32[8];
1265 /** 16-bit view */
1266 uint16_t au16[16];
1267 /** 8-bit view */
1268 uint8_t au8[32];
1269 } Args;
1270
1271 /** Number of registers values we can be sure about.
1272 * @note This is generally zero in the first frame. */
1273 uint32_t cSureRegs;
1274 /** Registers we can be sure about (length given by cSureRegs). */
1275 struct DBGFREGVALEX *paSureRegs;
1276
1277 /** Pointer to the next frame.
1278 * Might not be used in some cases, so consider it internal. */
1279 PCDBGFSTACKFRAME pNextInternal;
1280 /** Pointer to the first frame.
1281 * Might not be used in some cases, so consider it internal. */
1282 PCDBGFSTACKFRAME pFirstInternal;
1283} DBGFSTACKFRAME;
1284
1285/** @name DBGFSTACKFRAME_FLAGS_XXX - DBGFSTACKFRAME Flags.
1286 * @{ */
1287/** This is the last stack frame we can read.
1288 * This flag is not set if the walk stop because of max dept or recursion. */
1289# define DBGFSTACKFRAME_FLAGS_LAST RT_BIT(1)
1290/** This is the last record because we detected a loop. */
1291# define DBGFSTACKFRAME_FLAGS_LOOP RT_BIT(2)
1292/** This is the last record because we reached the maximum depth. */
1293# define DBGFSTACKFRAME_FLAGS_MAX_DEPTH RT_BIT(3)
1294/** 16-bit frame. */
1295# define DBGFSTACKFRAME_FLAGS_16BIT RT_BIT(4)
1296/** 32-bit frame. */
1297# define DBGFSTACKFRAME_FLAGS_32BIT RT_BIT(5)
1298/** 64-bit frame. */
1299# define DBGFSTACKFRAME_FLAGS_64BIT RT_BIT(6)
1300/** Real mode or V86 frame. */
1301# define DBGFSTACKFRAME_FLAGS_REAL_V86 RT_BIT(7)
1302/** Is a trap frame (NT term). */
1303# define DBGFSTACKFRAME_FLAGS_TRAP_FRAME RT_BIT(8)
1304
1305/** Used Odd/even heuristics for far/near return. */
1306# define DBGFSTACKFRAME_FLAGS_USED_ODD_EVEN RT_BIT(29)
1307/** Set if we used unwind info to construct the frame. (Kind of internal.) */
1308# define DBGFSTACKFRAME_FLAGS_USED_UNWIND_INFO RT_BIT(30)
1309/** Internal: Unwind info used for the return frame. */
1310# define DBGFSTACKFRAME_FLAGS_UNWIND_INFO_RET RT_BIT(31)
1311/** @} */
1312
1313/** @name DBGFCODETYPE
1314 * @{ */
1315typedef enum DBGFCODETYPE
1316{
1317 /** The usual invalid 0 value. */
1318 DBGFCODETYPE_INVALID = 0,
1319 /** Stack walk for guest code. */
1320 DBGFCODETYPE_GUEST,
1321 /** Stack walk for hypervisor code. */
1322 DBGFCODETYPE_HYPER,
1323 /** Stack walk for ring 0 code. */
1324 DBGFCODETYPE_RING0,
1325 /** The usual 32-bit blowup. */
1326 DBGFCODETYPE_32BIT_HACK = 0x7fffffff
1327} DBGFCODETYPE;
1328/** @} */
1329
1330VMMR3DECL(int) DBGFR3StackWalkBegin(PUVM pUVM, VMCPUID idCpu, DBGFCODETYPE enmCodeType,
1331 PCDBGFSTACKFRAME *ppFirstFrame);
1332VMMR3DECL(int) DBGFR3StackWalkBeginEx(PUVM pUVM, VMCPUID idCpu, DBGFCODETYPE enmCodeType, PCDBGFADDRESS pAddrFrame,
1333 PCDBGFADDRESS pAddrStack,PCDBGFADDRESS pAddrPC,
1334 RTDBGRETURNTYPE enmReturnType, PCDBGFSTACKFRAME *ppFirstFrame);
1335VMMR3DECL(PCDBGFSTACKFRAME) DBGFR3StackWalkNext(PCDBGFSTACKFRAME pCurrent);
1336VMMR3DECL(void) DBGFR3StackWalkEnd(PCDBGFSTACKFRAME pFirstFrame);
1337
1338#endif /* IN_RING3 */
1339
1340
1341#ifdef IN_RING3 /* The disassembly API only works in ring-3. */
1342
1343/** @name Flags to pass to DBGFR3DisasInstrEx().
1344 * @{ */
1345/** Disassemble the current guest instruction, with annotations. */
1346#define DBGF_DISAS_FLAGS_CURRENT_GUEST RT_BIT(0)
1347/** No annotations for current context. */
1348#define DBGF_DISAS_FLAGS_NO_ANNOTATION RT_BIT(2)
1349/** No symbol lookup. */
1350#define DBGF_DISAS_FLAGS_NO_SYMBOLS RT_BIT(3)
1351/** No instruction bytes. */
1352#define DBGF_DISAS_FLAGS_NO_BYTES RT_BIT(4)
1353/** No address in the output. */
1354#define DBGF_DISAS_FLAGS_NO_ADDRESS RT_BIT(5)
1355/** Disassemble original unpatched bytes (PATM). */
1356#define DBGF_DISAS_FLAGS_UNPATCHED_BYTES RT_BIT(7)
1357/** Annotate patched instructions. */
1358#define DBGF_DISAS_FLAGS_ANNOTATE_PATCHED RT_BIT(8)
1359/** Disassemble in the default mode of the specific context. */
1360#define DBGF_DISAS_FLAGS_DEFAULT_MODE UINT32_C(0x00000000)
1361/** Disassemble in 16-bit mode. */
1362#define DBGF_DISAS_FLAGS_16BIT_MODE UINT32_C(0x10000000)
1363/** Disassemble in 16-bit mode with real mode address translation. */
1364#define DBGF_DISAS_FLAGS_16BIT_REAL_MODE UINT32_C(0x20000000)
1365/** Disassemble in 32-bit mode. */
1366#define DBGF_DISAS_FLAGS_32BIT_MODE UINT32_C(0x30000000)
1367/** Disassemble in 64-bit mode. */
1368#define DBGF_DISAS_FLAGS_64BIT_MODE UINT32_C(0x40000000)
1369/** The disassembly mode mask. */
1370#define DBGF_DISAS_FLAGS_MODE_MASK UINT32_C(0x70000000)
1371/** Mask containing the valid flags. */
1372#define DBGF_DISAS_FLAGS_VALID_MASK UINT32_C(0x700001ff)
1373/** @} */
1374
1375/** Special flat selector. */
1376#define DBGF_SEL_FLAT 1
1377
1378VMMR3DECL(int) DBGFR3DisasInstrEx(PUVM pUVM, VMCPUID idCpu, RTSEL Sel, RTGCPTR GCPtr, uint32_t fFlags,
1379 char *pszOutput, uint32_t cbOutput, uint32_t *pcbInstr);
1380VMMR3_INT_DECL(int) DBGFR3DisasInstrCurrent(PVMCPU pVCpu, char *pszOutput, uint32_t cbOutput);
1381VMMR3DECL(int) DBGFR3DisasInstrCurrentLogInternal(PVMCPU pVCpu, const char *pszPrefix);
1382
1383/** @def DBGFR3_DISAS_INSTR_CUR_LOG
1384 * Disassembles the current guest context instruction and writes it to the log.
1385 * All registers and data will be displayed. Addresses will be attempted resolved to symbols.
1386 */
1387#ifdef LOG_ENABLED
1388# define DBGFR3_DISAS_INSTR_CUR_LOG(pVCpu, pszPrefix) \
1389 do { \
1390 if (LogIsEnabled()) \
1391 DBGFR3DisasInstrCurrentLogInternal(pVCpu, pszPrefix); \
1392 } while (0)
1393#else
1394# define DBGFR3_DISAS_INSTR_CUR_LOG(pVCpu, pszPrefix) do { } while (0)
1395#endif
1396
1397VMMR3DECL(int) DBGFR3DisasInstrLogInternal(PVMCPU pVCpu, RTSEL Sel, RTGCPTR GCPtr, const char *pszPrefix);
1398
1399/** @def DBGFR3_DISAS_INSTR_LOG
1400 * Disassembles the specified guest context instruction and writes it to the log.
1401 * Addresses will be attempted resolved to symbols.
1402 * @thread Any EMT.
1403 */
1404# ifdef LOG_ENABLED
1405# define DBGFR3_DISAS_INSTR_LOG(pVCpu, Sel, GCPtr, pszPrefix) \
1406 do { \
1407 if (LogIsEnabled()) \
1408 DBGFR3DisasInstrLogInternal(pVCpu, Sel, GCPtr, pszPrefix); \
1409 } while (0)
1410# else
1411# define DBGFR3_DISAS_INSTR_LOG(pVCpu, Sel, GCPtr, pszPrefix) do { } while (0)
1412# endif
1413#endif
1414
1415
1416#ifdef IN_RING3
1417VMMR3DECL(int) DBGFR3MemScan(PUVM pUVM, VMCPUID idCpu, PCDBGFADDRESS pAddress, RTGCUINTPTR cbRange, RTGCUINTPTR uAlign,
1418 const void *pvNeedle, size_t cbNeedle, PDBGFADDRESS pHitAddress);
1419VMMR3DECL(int) DBGFR3MemRead(PUVM pUVM, VMCPUID idCpu, PCDBGFADDRESS pAddress, void *pvBuf, size_t cbRead);
1420VMMR3DECL(int) DBGFR3MemReadString(PUVM pUVM, VMCPUID idCpu, PCDBGFADDRESS pAddress, char *pszBuf, size_t cbBuf);
1421VMMR3DECL(int) DBGFR3MemWrite(PUVM pUVM, VMCPUID idCpu, PCDBGFADDRESS pAddress, void const *pvBuf, size_t cbRead);
1422#endif
1423
1424
1425/** @name Flags for DBGFR3PagingDumpEx, PGMR3DumpHierarchyHCEx and
1426 * PGMR3DumpHierarchyGCEx
1427 * @{ */
1428/** The CR3 from the current CPU state. */
1429#define DBGFPGDMP_FLAGS_CURRENT_CR3 RT_BIT_32(0)
1430/** The current CPU paging mode (PSE, PAE, LM, EPT, NX). */
1431#define DBGFPGDMP_FLAGS_CURRENT_MODE RT_BIT_32(1)
1432/** Whether PSE is enabled (!DBGFPGDMP_FLAGS_CURRENT_STATE).
1433 * Same value as X86_CR4_PSE. */
1434#define DBGFPGDMP_FLAGS_PSE RT_BIT_32(4) /* */
1435/** Whether PAE is enabled (!DBGFPGDMP_FLAGS_CURRENT_STATE).
1436 * Same value as X86_CR4_PAE. */
1437#define DBGFPGDMP_FLAGS_PAE RT_BIT_32(5) /* */
1438/** Whether LME is enabled (!DBGFPGDMP_FLAGS_CURRENT_STATE).
1439 * Same value as MSR_K6_EFER_LME. */
1440#define DBGFPGDMP_FLAGS_LME RT_BIT_32(8)
1441/** Whether nested paging is enabled (!DBGFPGDMP_FLAGS_CURRENT_STATE). */
1442#define DBGFPGDMP_FLAGS_NP RT_BIT_32(9)
1443/** Whether extended nested page tables are enabled
1444 * (!DBGFPGDMP_FLAGS_CURRENT_STATE). */
1445#define DBGFPGDMP_FLAGS_EPT RT_BIT_32(10)
1446/** Whether no-execution is enabled (!DBGFPGDMP_FLAGS_CURRENT_STATE).
1447 * Same value as MSR_K6_EFER_NXE. */
1448#define DBGFPGDMP_FLAGS_NXE RT_BIT_32(11)
1449/** Whether to print the CR3. */
1450#define DBGFPGDMP_FLAGS_PRINT_CR3 RT_BIT_32(27)
1451/** Whether to print the header. */
1452#define DBGFPGDMP_FLAGS_HEADER RT_BIT_32(28)
1453/** Whether to dump additional page information. */
1454#define DBGFPGDMP_FLAGS_PAGE_INFO RT_BIT_32(29)
1455/** Dump the shadow tables if set.
1456 * Cannot be used together with DBGFPGDMP_FLAGS_GUEST. */
1457#define DBGFPGDMP_FLAGS_SHADOW RT_BIT_32(30)
1458/** Dump the guest tables if set.
1459 * Cannot be used together with DBGFPGDMP_FLAGS_SHADOW. */
1460#define DBGFPGDMP_FLAGS_GUEST RT_BIT_32(31)
1461/** Mask of valid bits. */
1462#define DBGFPGDMP_FLAGS_VALID_MASK UINT32_C(0xf8000f33)
1463/** The mask of bits controlling the paging mode. */
1464#define DBGFPGDMP_FLAGS_MODE_MASK UINT32_C(0x00000f32)
1465/** @} */
1466VMMDECL(int) DBGFR3PagingDumpEx(PUVM pUVM, VMCPUID idCpu, uint32_t fFlags, uint64_t cr3, uint64_t u64FirstAddr,
1467 uint64_t u64LastAddr, uint32_t cMaxDepth, PCDBGFINFOHLP pHlp);
1468
1469
1470/** @name DBGFR3SelQueryInfo flags.
1471 * @{ */
1472/** Get the info from the guest descriptor table.
1473 * @note This is more or less a given now when raw-mode was kicked out. */
1474#define DBGFSELQI_FLAGS_DT_GUEST UINT32_C(0)
1475/** If currently executing in in 64-bit mode, blow up data selectors. */
1476#define DBGFSELQI_FLAGS_DT_ADJ_64BIT_MODE UINT32_C(2)
1477/** @} */
1478VMMR3DECL(int) DBGFR3SelQueryInfo(PUVM pUVM, VMCPUID idCpu, RTSEL Sel, uint32_t fFlags, PDBGFSELINFO pSelInfo);
1479
1480
1481/**
1482 * Register identifiers.
1483 */
1484typedef enum DBGFREG
1485{
1486 /* General purpose registers: */
1487 DBGFREG_AL = 0,
1488 DBGFREG_AX = DBGFREG_AL,
1489 DBGFREG_EAX = DBGFREG_AL,
1490 DBGFREG_RAX = DBGFREG_AL,
1491
1492 DBGFREG_CL,
1493 DBGFREG_CX = DBGFREG_CL,
1494 DBGFREG_ECX = DBGFREG_CL,
1495 DBGFREG_RCX = DBGFREG_CL,
1496
1497 DBGFREG_DL,
1498 DBGFREG_DX = DBGFREG_DL,
1499 DBGFREG_EDX = DBGFREG_DL,
1500 DBGFREG_RDX = DBGFREG_DL,
1501
1502 DBGFREG_BL,
1503 DBGFREG_BX = DBGFREG_BL,
1504 DBGFREG_EBX = DBGFREG_BL,
1505 DBGFREG_RBX = DBGFREG_BL,
1506
1507 DBGFREG_SPL,
1508 DBGFREG_SP = DBGFREG_SPL,
1509 DBGFREG_ESP = DBGFREG_SPL,
1510 DBGFREG_RSP = DBGFREG_SPL,
1511
1512 DBGFREG_BPL,
1513 DBGFREG_BP = DBGFREG_BPL,
1514 DBGFREG_EBP = DBGFREG_BPL,
1515 DBGFREG_RBP = DBGFREG_BPL,
1516
1517 DBGFREG_SIL,
1518 DBGFREG_SI = DBGFREG_SIL,
1519 DBGFREG_ESI = DBGFREG_SIL,
1520 DBGFREG_RSI = DBGFREG_SIL,
1521
1522 DBGFREG_DIL,
1523 DBGFREG_DI = DBGFREG_DIL,
1524 DBGFREG_EDI = DBGFREG_DIL,
1525 DBGFREG_RDI = DBGFREG_DIL,
1526
1527 DBGFREG_R8,
1528 DBGFREG_R8B = DBGFREG_R8,
1529 DBGFREG_R8W = DBGFREG_R8,
1530 DBGFREG_R8D = DBGFREG_R8,
1531
1532 DBGFREG_R9,
1533 DBGFREG_R9B = DBGFREG_R9,
1534 DBGFREG_R9W = DBGFREG_R9,
1535 DBGFREG_R9D = DBGFREG_R9,
1536
1537 DBGFREG_R10,
1538 DBGFREG_R10B = DBGFREG_R10,
1539 DBGFREG_R10W = DBGFREG_R10,
1540 DBGFREG_R10D = DBGFREG_R10,
1541
1542 DBGFREG_R11,
1543 DBGFREG_R11B = DBGFREG_R11,
1544 DBGFREG_R11W = DBGFREG_R11,
1545 DBGFREG_R11D = DBGFREG_R11,
1546
1547 DBGFREG_R12,
1548 DBGFREG_R12B = DBGFREG_R12,
1549 DBGFREG_R12W = DBGFREG_R12,
1550 DBGFREG_R12D = DBGFREG_R12,
1551
1552 DBGFREG_R13,
1553 DBGFREG_R13B = DBGFREG_R13,
1554 DBGFREG_R13W = DBGFREG_R13,
1555 DBGFREG_R13D = DBGFREG_R13,
1556
1557 DBGFREG_R14,
1558 DBGFREG_R14B = DBGFREG_R14,
1559 DBGFREG_R14W = DBGFREG_R14,
1560 DBGFREG_R14D = DBGFREG_R14,
1561
1562 DBGFREG_R15,
1563 DBGFREG_R15B = DBGFREG_R15,
1564 DBGFREG_R15W = DBGFREG_R15,
1565 DBGFREG_R15D = DBGFREG_R15,
1566
1567 /* Segments and other special registers: */
1568 DBGFREG_CS,
1569 DBGFREG_CS_ATTR,
1570 DBGFREG_CS_BASE,
1571 DBGFREG_CS_LIMIT,
1572
1573 DBGFREG_DS,
1574 DBGFREG_DS_ATTR,
1575 DBGFREG_DS_BASE,
1576 DBGFREG_DS_LIMIT,
1577
1578 DBGFREG_ES,
1579 DBGFREG_ES_ATTR,
1580 DBGFREG_ES_BASE,
1581 DBGFREG_ES_LIMIT,
1582
1583 DBGFREG_FS,
1584 DBGFREG_FS_ATTR,
1585 DBGFREG_FS_BASE,
1586 DBGFREG_FS_LIMIT,
1587
1588 DBGFREG_GS,
1589 DBGFREG_GS_ATTR,
1590 DBGFREG_GS_BASE,
1591 DBGFREG_GS_LIMIT,
1592
1593 DBGFREG_SS,
1594 DBGFREG_SS_ATTR,
1595 DBGFREG_SS_BASE,
1596 DBGFREG_SS_LIMIT,
1597
1598 DBGFREG_IP,
1599 DBGFREG_EIP = DBGFREG_IP,
1600 DBGFREG_RIP = DBGFREG_IP,
1601
1602 DBGFREG_FLAGS,
1603 DBGFREG_EFLAGS = DBGFREG_FLAGS,
1604 DBGFREG_RFLAGS = DBGFREG_FLAGS,
1605
1606 /* FPU: */
1607 DBGFREG_FCW,
1608 DBGFREG_FSW,
1609 DBGFREG_FTW,
1610 DBGFREG_FOP,
1611 DBGFREG_FPUIP,
1612 DBGFREG_FPUCS,
1613 DBGFREG_FPUDP,
1614 DBGFREG_FPUDS,
1615 DBGFREG_MXCSR,
1616 DBGFREG_MXCSR_MASK,
1617
1618 DBGFREG_ST0,
1619 DBGFREG_ST1,
1620 DBGFREG_ST2,
1621 DBGFREG_ST3,
1622 DBGFREG_ST4,
1623 DBGFREG_ST5,
1624 DBGFREG_ST6,
1625 DBGFREG_ST7,
1626
1627 DBGFREG_MM0,
1628 DBGFREG_MM1,
1629 DBGFREG_MM2,
1630 DBGFREG_MM3,
1631 DBGFREG_MM4,
1632 DBGFREG_MM5,
1633 DBGFREG_MM6,
1634 DBGFREG_MM7,
1635
1636 /* SSE: */
1637 DBGFREG_XMM0,
1638 DBGFREG_XMM1,
1639 DBGFREG_XMM2,
1640 DBGFREG_XMM3,
1641 DBGFREG_XMM4,
1642 DBGFREG_XMM5,
1643 DBGFREG_XMM6,
1644 DBGFREG_XMM7,
1645 DBGFREG_XMM8,
1646 DBGFREG_XMM9,
1647 DBGFREG_XMM10,
1648 DBGFREG_XMM11,
1649 DBGFREG_XMM12,
1650 DBGFREG_XMM13,
1651 DBGFREG_XMM14,
1652 DBGFREG_XMM15,
1653 /** @todo add XMM aliases. */
1654
1655 /* AVX: */
1656 DBGFREG_YMM0,
1657 DBGFREG_YMM1,
1658 DBGFREG_YMM2,
1659 DBGFREG_YMM3,
1660 DBGFREG_YMM4,
1661 DBGFREG_YMM5,
1662 DBGFREG_YMM6,
1663 DBGFREG_YMM7,
1664 DBGFREG_YMM8,
1665 DBGFREG_YMM9,
1666 DBGFREG_YMM10,
1667 DBGFREG_YMM11,
1668 DBGFREG_YMM12,
1669 DBGFREG_YMM13,
1670 DBGFREG_YMM14,
1671 DBGFREG_YMM15,
1672
1673 /* System registers: */
1674 DBGFREG_GDTR_BASE,
1675 DBGFREG_GDTR_LIMIT,
1676 DBGFREG_IDTR_BASE,
1677 DBGFREG_IDTR_LIMIT,
1678 DBGFREG_LDTR,
1679 DBGFREG_LDTR_ATTR,
1680 DBGFREG_LDTR_BASE,
1681 DBGFREG_LDTR_LIMIT,
1682 DBGFREG_TR,
1683 DBGFREG_TR_ATTR,
1684 DBGFREG_TR_BASE,
1685 DBGFREG_TR_LIMIT,
1686
1687 DBGFREG_CR0,
1688 DBGFREG_CR2,
1689 DBGFREG_CR3,
1690 DBGFREG_CR4,
1691 DBGFREG_CR8,
1692
1693 DBGFREG_DR0,
1694 DBGFREG_DR1,
1695 DBGFREG_DR2,
1696 DBGFREG_DR3,
1697 DBGFREG_DR6,
1698 DBGFREG_DR7,
1699
1700 /* MSRs: */
1701 DBGFREG_MSR_IA32_APICBASE,
1702 DBGFREG_MSR_IA32_CR_PAT,
1703 DBGFREG_MSR_IA32_PERF_STATUS,
1704 DBGFREG_MSR_IA32_SYSENTER_CS,
1705 DBGFREG_MSR_IA32_SYSENTER_EIP,
1706 DBGFREG_MSR_IA32_SYSENTER_ESP,
1707 DBGFREG_MSR_IA32_TSC,
1708 DBGFREG_MSR_K6_EFER,
1709 DBGFREG_MSR_K6_STAR,
1710 DBGFREG_MSR_K8_CSTAR,
1711 DBGFREG_MSR_K8_FS_BASE,
1712 DBGFREG_MSR_K8_GS_BASE,
1713 DBGFREG_MSR_K8_KERNEL_GS_BASE,
1714 DBGFREG_MSR_K8_LSTAR,
1715 DBGFREG_MSR_K8_SF_MASK,
1716 DBGFREG_MSR_K8_TSC_AUX,
1717
1718 /** The number of registers to pass to DBGFR3RegQueryAll. */
1719 DBGFREG_ALL_COUNT,
1720
1721 /* Misc aliases that doesn't need be part of the 'all' query: */
1722 DBGFREG_AH = DBGFREG_ALL_COUNT,
1723 DBGFREG_CH,
1724 DBGFREG_DH,
1725 DBGFREG_BH,
1726 DBGFREG_GDTR,
1727 DBGFREG_IDTR,
1728
1729 /** The end of the registers. */
1730 DBGFREG_END,
1731 /** The usual 32-bit type hack. */
1732 DBGFREG_32BIT_HACK = 0x7fffffff
1733} DBGFREG;
1734/** Pointer to a register identifier. */
1735typedef DBGFREG *PDBGFREG;
1736/** Pointer to a const register identifier. */
1737typedef DBGFREG const *PCDBGFREG;
1738
1739/**
1740 * Register value type.
1741 */
1742typedef enum DBGFREGVALTYPE
1743{
1744 DBGFREGVALTYPE_INVALID = 0,
1745 /** Unsigned 8-bit register value. */
1746 DBGFREGVALTYPE_U8,
1747 /** Unsigned 16-bit register value. */
1748 DBGFREGVALTYPE_U16,
1749 /** Unsigned 32-bit register value. */
1750 DBGFREGVALTYPE_U32,
1751 /** Unsigned 64-bit register value. */
1752 DBGFREGVALTYPE_U64,
1753 /** Unsigned 128-bit register value. */
1754 DBGFREGVALTYPE_U128,
1755 /** Unsigned 256-bit register value. */
1756 DBGFREGVALTYPE_U256,
1757 /** Unsigned 512-bit register value. */
1758 DBGFREGVALTYPE_U512,
1759 /** Long double register value. */
1760 DBGFREGVALTYPE_R80,
1761 /** Descriptor table register value. */
1762 DBGFREGVALTYPE_DTR,
1763 /** End of the valid register value types. */
1764 DBGFREGVALTYPE_END,
1765 /** The usual 32-bit type hack. */
1766 DBGFREGVALTYPE_32BIT_HACK = 0x7fffffff
1767} DBGFREGVALTYPE;
1768/** Pointer to a register value type. */
1769typedef DBGFREGVALTYPE *PDBGFREGVALTYPE;
1770
1771/**
1772 * A generic register value type.
1773 */
1774typedef union DBGFREGVAL
1775{
1776 uint64_t au64[8]; /**< The 64-bit array view. First because of the initializer. */
1777 uint32_t au32[16]; /**< The 32-bit array view. */
1778 uint16_t au16[32]; /**< The 16-bit array view. */
1779 uint8_t au8[64]; /**< The 8-bit array view. */
1780
1781 uint8_t u8; /**< The 8-bit view. */
1782 uint16_t u16; /**< The 16-bit view. */
1783 uint32_t u32; /**< The 32-bit view. */
1784 uint64_t u64; /**< The 64-bit view. */
1785 RTUINT128U u128; /**< The 128-bit view. */
1786 RTUINT256U u256; /**< The 256-bit view. */
1787 RTUINT512U u512; /**< The 512-bit view. */
1788 RTFLOAT80U r80; /**< The 80-bit floating point view. */
1789 RTFLOAT80U2 r80Ex; /**< The 80-bit floating point view v2. */
1790 /** GDTR or LDTR (DBGFREGVALTYPE_DTR). */
1791 struct
1792 {
1793 /** The table address. */
1794 uint64_t u64Base;
1795 /** The table limit (length minus 1). */
1796 uint32_t u32Limit; /**< @todo Limit should be uint16_t */
1797 } dtr;
1798} DBGFREGVAL;
1799/** Pointer to a generic register value type. */
1800typedef DBGFREGVAL *PDBGFREGVAL;
1801/** Pointer to a const generic register value type. */
1802typedef DBGFREGVAL const *PCDBGFREGVAL;
1803
1804/** Initialize a DBGFREGVAL variable to all zeros. */
1805#define DBGFREGVAL_INITIALIZE_ZERO { { 0, 0, 0, 0, 0, 0, 0, 0 } }
1806/** Initialize a DBGFREGVAL variable to all bits set . */
1807#define DBGFREGVAL_INITIALIZE_FFFF { { UINT64_MAX, UINT64_MAX, UINT64_MAX, UINT64_MAX, UINT64_MAX, UINT64_MAX, UINT64_MAX, UINT64_MAX } }
1808
1809/**
1810 * Extended register value, including register ID and type.
1811 *
1812 * This is currently only used by the stack walker.
1813 */
1814typedef struct DBGFREGVALEX
1815{
1816 /** The register value. */
1817 DBGFREGVAL Value;
1818 /** The register value type. */
1819 DBGFREGVALTYPE enmType;
1820 /** The register ID, DBGFREG_END if not applicable. */
1821 DBGFREG enmReg;
1822 /** Pointer to read-only register name string if no register ID could be found. */
1823 const char *pszName;
1824} DBGFREGVALEX;
1825/** Pointer to an extended register value struct. */
1826typedef DBGFREGVALEX *PDBGFREGVALEX;
1827/** Pointer to a const extended register value struct. */
1828typedef DBGFREGVALEX const *PCDBGFREGVALEX;
1829
1830
1831VMMDECL(ssize_t) DBGFR3RegFormatValue(char *pszBuf, size_t cbBuf, PCDBGFREGVAL pValue, DBGFREGVALTYPE enmType, bool fSpecial);
1832VMMDECL(ssize_t) DBGFR3RegFormatValueEx(char *pszBuf, size_t cbBuf, PCDBGFREGVAL pValue, DBGFREGVALTYPE enmType,
1833 unsigned uBase, signed int cchWidth, signed int cchPrecision, uint32_t fFlags);
1834
1835/**
1836 * Register sub-field descriptor.
1837 */
1838typedef struct DBGFREGSUBFIELD
1839{
1840 /** The name of the sub-field. NULL is used to terminate the array. */
1841 const char *pszName;
1842 /** The index of the first bit. Ignored if pfnGet is set. */
1843 uint8_t iFirstBit;
1844 /** The number of bits. Mandatory. */
1845 uint8_t cBits;
1846 /** The shift count. Not applied when pfnGet is set, but used to
1847 * calculate the minimum type. */
1848 int8_t cShift;
1849 /** Sub-field flags, DBGFREGSUBFIELD_FLAGS_XXX. */
1850 uint8_t fFlags;
1851 /** Getter (optional).
1852 * @remarks Does not take the device lock or anything like that.
1853 */
1854 DECLCALLBACKMEMBER(int, pfnGet)(void *pvUser, struct DBGFREGSUBFIELD const *pSubField, PRTUINT128U puValue);
1855 /** Setter (optional).
1856 * @remarks Does not take the device lock or anything like that.
1857 */
1858 DECLCALLBACKMEMBER(int, pfnSet)(void *pvUser, struct DBGFREGSUBFIELD const *pSubField, RTUINT128U uValue, RTUINT128U fMask);
1859} DBGFREGSUBFIELD;
1860/** Pointer to a const register sub-field descriptor. */
1861typedef DBGFREGSUBFIELD const *PCDBGFREGSUBFIELD;
1862
1863/** @name DBGFREGSUBFIELD_FLAGS_XXX
1864 * @{ */
1865/** The sub-field is read-only. */
1866#define DBGFREGSUBFIELD_FLAGS_READ_ONLY UINT8_C(0x01)
1867/** @} */
1868
1869/** Macro for creating a read-write sub-field entry without getters. */
1870#define DBGFREGSUBFIELD_RW(a_szName, a_iFirstBit, a_cBits, a_cShift) \
1871 { a_szName, a_iFirstBit, a_cBits, a_cShift, 0 /*fFlags*/, NULL /*pfnGet*/, NULL /*pfnSet*/ }
1872/** Macro for creating a read-write sub-field entry with getters. */
1873#define DBGFREGSUBFIELD_RW_SG(a_szName, a_cBits, a_cShift, a_pfnGet, a_pfnSet) \
1874 { a_szName, 0 /*iFirstBit*/, a_cBits, a_cShift, 0 /*fFlags*/, a_pfnGet, a_pfnSet }
1875/** Macro for creating a read-only sub-field entry without getters. */
1876#define DBGFREGSUBFIELD_RO(a_szName, a_iFirstBit, a_cBits, a_cShift) \
1877 { a_szName, a_iFirstBit, a_cBits, a_cShift, DBGFREGSUBFIELD_FLAGS_READ_ONLY, NULL /*pfnGet*/, NULL /*pfnSet*/ }
1878/** Macro for creating a terminator sub-field entry. */
1879#define DBGFREGSUBFIELD_TERMINATOR() \
1880 { NULL, 0, 0, 0, 0, NULL, NULL }
1881
1882/**
1883 * Register alias descriptor.
1884 */
1885typedef struct DBGFREGALIAS
1886{
1887 /** The alias name. NULL is used to terminate the array. */
1888 const char *pszName;
1889 /** Set to a valid type if the alias has a different type. */
1890 DBGFREGVALTYPE enmType;
1891} DBGFREGALIAS;
1892/** Pointer to a const register alias descriptor. */
1893typedef DBGFREGALIAS const *PCDBGFREGALIAS;
1894
1895/**
1896 * Register descriptor.
1897 */
1898typedef struct DBGFREGDESC
1899{
1900 /** The normal register name. */
1901 const char *pszName;
1902 /** The register identifier if this is a CPU register. */
1903 DBGFREG enmReg;
1904 /** The default register type. */
1905 DBGFREGVALTYPE enmType;
1906 /** Flags, see DBGFREG_FLAGS_XXX. */
1907 uint32_t fFlags;
1908 /** The internal register indicator.
1909 * For CPU registers this is the offset into the CPUMCTX structure,
1910 * thuse the 'off' prefix. */
1911 uint32_t offRegister;
1912 /** Getter.
1913 * @remarks Does not take the device lock or anything like that.
1914 */
1915 DECLCALLBACKMEMBER(int, pfnGet)(void *pvUser, struct DBGFREGDESC const *pDesc, PDBGFREGVAL pValue);
1916 /** Setter.
1917 * @remarks Does not take the device lock or anything like that.
1918 */
1919 DECLCALLBACKMEMBER(int, pfnSet)(void *pvUser, struct DBGFREGDESC const *pDesc, PCDBGFREGVAL pValue, PCDBGFREGVAL pfMask);
1920 /** Aliases (optional). */
1921 PCDBGFREGALIAS paAliases;
1922 /** Sub fields (optional). */
1923 PCDBGFREGSUBFIELD paSubFields;
1924} DBGFREGDESC;
1925
1926/** @name Macros for constructing DBGFREGDESC arrays.
1927 * @{ */
1928#define DBGFREGDESC_RW(a_szName, a_TypeSuff, a_offRegister, a_pfnGet, a_pfnSet) \
1929 { a_szName, DBGFREG_END, DBGFREGVALTYPE_##a_TypeSuff, 0 /*fFlags*/, a_offRegister, a_pfnGet, a_pfnSet, NULL /*paAlises*/, NULL /*paSubFields*/ }
1930#define DBGFREGDESC_RO(a_szName, a_TypeSuff, a_offRegister, a_pfnGet, a_pfnSet) \
1931 { a_szName, DBGFREG_END, DBGFREGVALTYPE_##a_TypeSuff, DBGFREG_FLAGS_READ_ONLY, a_offRegister, a_pfnGet, a_pfnSet, NULL /*paAlises*/, NULL /*paSubFields*/ }
1932#define DBGFREGDESC_RW_A(a_szName, a_TypeSuff, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases) \
1933 { a_szName, DBGFREG_END, DBGFREGVALTYPE_##a_TypeSuff, 0 /*fFlags*/, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases, NULL /*paSubFields*/ }
1934#define DBGFREGDESC_RO_A(a_szName, a_TypeSuff, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases) \
1935 { a_szName, DBGFREG_END, DBGFREGVALTYPE_##a_TypeSuff, DBGFREG_FLAGS_READ_ONLY, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases, NULL /*paSubFields*/ }
1936#define DBGFREGDESC_RW_S(a_szName, a_TypeSuff, a_offRegister, a_pfnGet, a_pfnSet, a_paSubFields) \
1937 { a_szName, DBGFREG_END, DBGFREGVALTYPE_##a_TypeSuff, 0 /*fFlags*/, a_offRegister, a_pfnGet, a_pfnSet, /*paAliases*/, a_paSubFields }
1938#define DBGFREGDESC_RO_S(a_szName, a_TypeSuff, a_offRegister, a_pfnGet, a_pfnSet, a_paSubFields) \
1939 { a_szName, DBGFREG_END, DBGFREGVALTYPE_##a_TypeSuff, DBGFREG_FLAGS_READ_ONLY, a_offRegister, a_pfnGet, a_pfnSet, /*paAliases*/, a_paSubFields }
1940#define DBGFREGDESC_RW_AS(a_szName, a_TypeSuff, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields) \
1941 { a_szName, DBGFREG_END, DBGFREGVALTYPE_##a_TypeSuff, 0 /*fFlags*/, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields }
1942#define DBGFREGDESC_RO_AS(a_szName, a_TypeSuff, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields) \
1943 { a_szName, DBGFREG_END, DBGFREGVALTYPE_##a_TypeSuff, DBGFREG_FLAGS_READ_ONLY, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields }
1944#define DBGFREGDESC_TERMINATOR() \
1945 { NULL, DBGFREG_END, DBGFREGVALTYPE_INVALID, 0, 0, NULL, NULL, NULL, NULL }
1946/** @} */
1947
1948
1949/** @name DBGFREG_FLAGS_XXX
1950 * @{ */
1951/** The register is read-only. */
1952#define DBGFREG_FLAGS_READ_ONLY RT_BIT_32(0)
1953/** @} */
1954
1955/**
1956 * Entry in a batch query or set operation.
1957 */
1958typedef struct DBGFREGENTRY
1959{
1960 /** The register identifier. */
1961 DBGFREG enmReg;
1962 /** The size of the value in bytes. */
1963 DBGFREGVALTYPE enmType;
1964 /** The register value. The valid view is indicated by enmType. */
1965 DBGFREGVAL Val;
1966} DBGFREGENTRY;
1967/** Pointer to a register entry in a batch operation. */
1968typedef DBGFREGENTRY *PDBGFREGENTRY;
1969/** Pointer to a const register entry in a batch operation. */
1970typedef DBGFREGENTRY const *PCDBGFREGENTRY;
1971
1972/** Used with DBGFR3Reg* to indicate the hypervisor register set instead of the
1973 * guest. */
1974#define DBGFREG_HYPER_VMCPUID UINT32_C(0x01000000)
1975
1976VMMR3DECL(int) DBGFR3RegCpuQueryU8( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint8_t *pu8);
1977VMMR3DECL(int) DBGFR3RegCpuQueryU16( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint16_t *pu16);
1978VMMR3DECL(int) DBGFR3RegCpuQueryU32( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint32_t *pu32);
1979VMMR3DECL(int) DBGFR3RegCpuQueryU64( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint64_t *pu64);
1980VMMR3DECL(int) DBGFR3RegCpuQueryU128(PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint128_t *pu128);
1981VMMR3DECL(int) DBGFR3RegCpuQueryLrd( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, long double *plrd);
1982VMMR3DECL(int) DBGFR3RegCpuQueryXdtr(PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint64_t *pu64Base, uint16_t *pu16Limit);
1983#if 0
1984VMMR3DECL(int) DBGFR3RegCpuQueryBatch(PUVM pUVM,VMCPUID idCpu, PDBGFREGENTRY paRegs, size_t cRegs);
1985VMMR3DECL(int) DBGFR3RegCpuQueryAll( PUVM pUVM, VMCPUID idCpu, PDBGFREGENTRY paRegs, size_t cRegs);
1986
1987VMMR3DECL(int) DBGFR3RegCpuSetU8( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint8_t u8);
1988VMMR3DECL(int) DBGFR3RegCpuSetU16( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint16_t u16);
1989VMMR3DECL(int) DBGFR3RegCpuSetU32( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint32_t u32);
1990VMMR3DECL(int) DBGFR3RegCpuSetU64( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint64_t u64);
1991VMMR3DECL(int) DBGFR3RegCpuSetU128( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, uint128_t u128);
1992VMMR3DECL(int) DBGFR3RegCpuSetLrd( PUVM pUVM, VMCPUID idCpu, DBGFREG enmReg, long double lrd);
1993VMMR3DECL(int) DBGFR3RegCpuSetBatch( PUVM pUVM, VMCPUID idCpu, PCDBGFREGENTRY paRegs, size_t cRegs);
1994#endif
1995
1996VMMR3DECL(const char *) DBGFR3RegCpuName(PUVM pUVM, DBGFREG enmReg, DBGFREGVALTYPE enmType);
1997
1998VMMR3_INT_DECL(int) DBGFR3RegRegisterCpu(PVM pVM, PVMCPU pVCpu, PCDBGFREGDESC paRegisters, bool fGuestRegs);
1999VMMR3_INT_DECL(int) DBGFR3RegRegisterDevice(PVM pVM, PCDBGFREGDESC paRegisters, PPDMDEVINS pDevIns,
2000 const char *pszPrefix, uint32_t iInstance);
2001
2002/**
2003 * Entry in a named batch query or set operation.
2004 */
2005typedef struct DBGFREGENTRYNM
2006{
2007 /** The register name. */
2008 const char *pszName;
2009 /** The size of the value in bytes. */
2010 DBGFREGVALTYPE enmType;
2011 /** The register value. The valid view is indicated by enmType. */
2012 DBGFREGVAL Val;
2013} DBGFREGENTRYNM;
2014/** Pointer to a named register entry in a batch operation. */
2015typedef DBGFREGENTRYNM *PDBGFREGENTRYNM;
2016/** Pointer to a const named register entry in a batch operation. */
2017typedef DBGFREGENTRYNM const *PCDBGFREGENTRYNM;
2018
2019VMMR3DECL(int) DBGFR3RegNmValidate( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg);
2020
2021VMMR3DECL(int) DBGFR3RegNmQuery( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, PDBGFREGVAL pValue, PDBGFREGVALTYPE penmType);
2022VMMR3DECL(int) DBGFR3RegNmQueryU8( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, uint8_t *pu8);
2023VMMR3DECL(int) DBGFR3RegNmQueryU16( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, uint16_t *pu16);
2024VMMR3DECL(int) DBGFR3RegNmQueryU32( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, uint32_t *pu32);
2025VMMR3DECL(int) DBGFR3RegNmQueryU64( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, uint64_t *pu64);
2026VMMR3DECL(int) DBGFR3RegNmQueryU128(PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, PRTUINT128U pu128);
2027/*VMMR3DECL(int) DBGFR3RegNmQueryLrd( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, long double *plrd);*/
2028VMMR3DECL(int) DBGFR3RegNmQueryXdtr(PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, uint64_t *pu64Base, uint16_t *pu16Limit);
2029VMMR3DECL(int) DBGFR3RegNmQueryBatch(PUVM pUVM,VMCPUID idDefCpu, PDBGFREGENTRYNM paRegs, size_t cRegs);
2030VMMR3DECL(int) DBGFR3RegNmQueryAllCount(PUVM pUVM, size_t *pcRegs);
2031VMMR3DECL(int) DBGFR3RegNmQueryAll( PUVM pUVM, PDBGFREGENTRYNM paRegs, size_t cRegs);
2032
2033VMMR3DECL(int) DBGFR3RegNmSet( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, PCDBGFREGVAL pValue, DBGFREGVALTYPE enmType);
2034VMMR3DECL(int) DBGFR3RegNmSetU8( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, uint8_t u8);
2035VMMR3DECL(int) DBGFR3RegNmSetU16( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, uint16_t u16);
2036VMMR3DECL(int) DBGFR3RegNmSetU32( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, uint32_t u32);
2037VMMR3DECL(int) DBGFR3RegNmSetU64( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, uint64_t u64);
2038VMMR3DECL(int) DBGFR3RegNmSetU128( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, RTUINT128U u128);
2039VMMR3DECL(int) DBGFR3RegNmSetLrd( PUVM pUVM, VMCPUID idDefCpu, const char *pszReg, long double lrd);
2040VMMR3DECL(int) DBGFR3RegNmSetBatch( PUVM pUVM, VMCPUID idDefCpu, PCDBGFREGENTRYNM paRegs, size_t cRegs);
2041
2042/** @todo add enumeration methods. */
2043
2044VMMR3DECL(int) DBGFR3RegPrintf( PUVM pUVM, VMCPUID idDefCpu, char *pszBuf, size_t cbBuf, const char *pszFormat, ...);
2045VMMR3DECL(int) DBGFR3RegPrintfV(PUVM pUVM, VMCPUID idDefCpu, char *pszBuf, size_t cbBuf, const char *pszFormat, va_list va);
2046
2047
2048#ifdef IN_RING3
2049
2050/**
2051 * Guest OS digger interface identifier.
2052 *
2053 * This is for use together with PDBGFR3QueryInterface and is used to
2054 * obtain access to optional interfaces.
2055 */
2056typedef enum DBGFOSINTERFACE
2057{
2058 /** The usual invalid entry. */
2059 DBGFOSINTERFACE_INVALID = 0,
2060 /** Process info. */
2061 DBGFOSINTERFACE_PROCESS,
2062 /** Thread info. */
2063 DBGFOSINTERFACE_THREAD,
2064 /** Kernel message log - DBGFOSIDMESG. */
2065 DBGFOSINTERFACE_DMESG,
2066 /** The end of the valid entries. */
2067 DBGFOSINTERFACE_END,
2068 /** The usual 32-bit type blowup. */
2069 DBGFOSINTERFACE_32BIT_HACK = 0x7fffffff
2070} DBGFOSINTERFACE;
2071/** Pointer to a Guest OS digger interface identifier. */
2072typedef DBGFOSINTERFACE *PDBGFOSINTERFACE;
2073/** Pointer to a const Guest OS digger interface identifier. */
2074typedef DBGFOSINTERFACE const *PCDBGFOSINTERFACE;
2075
2076
2077/**
2078 * Guest OS Digger Registration Record.
2079 *
2080 * This is used with the DBGFR3OSRegister() API.
2081 */
2082typedef struct DBGFOSREG
2083{
2084 /** Magic value (DBGFOSREG_MAGIC). */
2085 uint32_t u32Magic;
2086 /** Flags. Reserved. */
2087 uint32_t fFlags;
2088 /** The size of the instance data. */
2089 uint32_t cbData;
2090 /** Operative System name. */
2091 char szName[24];
2092
2093 /**
2094 * Constructs the instance.
2095 *
2096 * @returns VBox status code.
2097 * @param pUVM The user mode VM handle.
2098 * @param pvData Pointer to the instance data.
2099 */
2100 DECLCALLBACKMEMBER(int, pfnConstruct)(PUVM pUVM, void *pvData);
2101
2102 /**
2103 * Destroys the instance.
2104 *
2105 * @param pUVM The user mode VM handle.
2106 * @param pvData Pointer to the instance data.
2107 */
2108 DECLCALLBACKMEMBER(void, pfnDestruct)(PUVM pUVM, void *pvData);
2109
2110 /**
2111 * Probes the guest memory for OS finger prints.
2112 *
2113 * No setup or so is performed, it will be followed by a call to pfnInit
2114 * or pfnRefresh that should take care of that.
2115 *
2116 * @returns true if is an OS handled by this module, otherwise false.
2117 * @param pUVM The user mode VM handle.
2118 * @param pvData Pointer to the instance data.
2119 */
2120 DECLCALLBACKMEMBER(bool, pfnProbe)(PUVM pUVM, void *pvData);
2121
2122 /**
2123 * Initializes a fresly detected guest, loading symbols and such useful stuff.
2124 *
2125 * This is called after pfnProbe.
2126 *
2127 * @returns VBox status code.
2128 * @param pUVM The user mode VM handle.
2129 * @param pvData Pointer to the instance data.
2130 */
2131 DECLCALLBACKMEMBER(int, pfnInit)(PUVM pUVM, void *pvData);
2132
2133 /**
2134 * Refreshes symbols and stuff following a redetection of the same OS.
2135 *
2136 * This is called after pfnProbe.
2137 *
2138 * @returns VBox status code.
2139 * @param pUVM The user mode VM handle.
2140 * @param pvData Pointer to the instance data.
2141 */
2142 DECLCALLBACKMEMBER(int, pfnRefresh)(PUVM pUVM, void *pvData);
2143
2144 /**
2145 * Terminates an OS when a new (or none) OS has been detected,
2146 * and before destruction.
2147 *
2148 * This is called after pfnProbe and if needed before pfnDestruct.
2149 *
2150 * @param pUVM The user mode VM handle.
2151 * @param pvData Pointer to the instance data.
2152 */
2153 DECLCALLBACKMEMBER(void, pfnTerm)(PUVM pUVM, void *pvData);
2154
2155 /**
2156 * Queries the version of the running OS.
2157 *
2158 * This is only called after pfnInit().
2159 *
2160 * @returns VBox status code.
2161 * @param pUVM The user mode VM handle.
2162 * @param pvData Pointer to the instance data.
2163 * @param pszVersion Where to store the version string.
2164 * @param cchVersion The size of the version string buffer.
2165 */
2166 DECLCALLBACKMEMBER(int, pfnQueryVersion)(PUVM pUVM, void *pvData, char *pszVersion, size_t cchVersion);
2167
2168 /**
2169 * Queries the pointer to a interface.
2170 *
2171 * This is called after pfnProbe.
2172 *
2173 * The returned interface must be valid until pfnDestruct is called. Two calls
2174 * to this method with the same @a enmIf value must return the same pointer.
2175 *
2176 * @returns Pointer to the interface if available, NULL if not available.
2177 * @param pUVM The user mode VM handle.
2178 * @param pvData Pointer to the instance data.
2179 * @param enmIf The interface identifier.
2180 */
2181 DECLCALLBACKMEMBER(void *, pfnQueryInterface)(PUVM pUVM, void *pvData, DBGFOSINTERFACE enmIf);
2182
2183 /**
2184 * Stack unwind assist callback.
2185 *
2186 * This is only called after pfnInit().
2187 *
2188 * @returns VBox status code (allocation error or something of similar fatality).
2189 * @param pUVM The user mode VM handle.
2190 * @param pvData Pointer to the instance data.
2191 * @param idCpu The CPU that's unwinding it's stack.
2192 * @param pFrame The current frame. Okay to modify it a little.
2193 * @param pState The unwind state. Okay to modify it.
2194 * @param pInitialCtx The initial register context.
2195 * @param hAs The address space being used for the unwind.
2196 * @param puScratch Scratch area (initialized to zero, no dtor).
2197 */
2198 DECLCALLBACKMEMBER(int, pfnStackUnwindAssist)(PUVM pUVM, void *pvData, VMCPUID idCpu, PDBGFSTACKFRAME pFrame,
2199 PRTDBGUNWINDSTATE pState, PCCPUMCTX pInitialCtx, RTDBGAS hAs,
2200 uint64_t *puScratch);
2201
2202 /** Trailing magic (DBGFOSREG_MAGIC). */
2203 uint32_t u32EndMagic;
2204} DBGFOSREG;
2205/** Pointer to a Guest OS digger registration record. */
2206typedef DBGFOSREG *PDBGFOSREG;
2207/** Pointer to a const Guest OS digger registration record. */
2208typedef DBGFOSREG const *PCDBGFOSREG;
2209
2210/** Magic value for DBGFOSREG::u32Magic and DBGFOSREG::u32EndMagic. (Hitomi Kanehara) */
2211#define DBGFOSREG_MAGIC 0x19830808
2212
2213
2214/**
2215 * Interface for querying kernel log messages (DBGFOSINTERFACE_DMESG).
2216 */
2217typedef struct DBGFOSIDMESG
2218{
2219 /** Trailing magic (DBGFOSIDMESG_MAGIC). */
2220 uint32_t u32Magic;
2221
2222 /**
2223 * Query the kernel log.
2224 *
2225 * @returns VBox status code.
2226 * @retval VERR_NOT_FOUND if the messages could not be located.
2227 * @retval VERR_INVALID_STATE if the messages was found to have unknown/invalid
2228 * format.
2229 * @retval VERR_BUFFER_OVERFLOW if the buffer isn't large enough, pcbActual
2230 * will be set to the required buffer size. The buffer, however, will
2231 * be filled with as much data as it can hold (properly zero terminated
2232 * of course).
2233 *
2234 * @param pThis Pointer to the interface structure.
2235 * @param pUVM The user mode VM handle.
2236 * @param fFlags Flags reserved for future use, MBZ.
2237 * @param cMessages The number of messages to retrieve, counting from the
2238 * end of the log (i.e. like tail), use UINT32_MAX for all.
2239 * @param pszBuf The output buffer.
2240 * @param cbBuf The buffer size.
2241 * @param pcbActual Where to store the number of bytes actually returned,
2242 * including zero terminator. On VERR_BUFFER_OVERFLOW this
2243 * holds the necessary buffer size. Optional.
2244 */
2245 DECLCALLBACKMEMBER(int, pfnQueryKernelLog)(struct DBGFOSIDMESG *pThis, PUVM pUVM, uint32_t fFlags, uint32_t cMessages,
2246 char *pszBuf, size_t cbBuf, size_t *pcbActual);
2247 /** Trailing magic (DBGFOSIDMESG_MAGIC). */
2248 uint32_t u32EndMagic;
2249} DBGFOSIDMESG;
2250/** Pointer to the interface for query kernel log messages (DBGFOSINTERFACE_DMESG). */
2251typedef DBGFOSIDMESG *PDBGFOSIDMESG;
2252/** Magic value for DBGFOSIDMESG::32Magic and DBGFOSIDMESG::u32EndMagic. (Kenazburo Oe) */
2253#define DBGFOSIDMESG_MAGIC UINT32_C(0x19350131)
2254
2255
2256VMMR3DECL(int) DBGFR3OSRegister(PUVM pUVM, PCDBGFOSREG pReg);
2257VMMR3DECL(int) DBGFR3OSDeregister(PUVM pUVM, PCDBGFOSREG pReg);
2258VMMR3DECL(int) DBGFR3OSDetect(PUVM pUVM, char *pszName, size_t cchName);
2259VMMR3DECL(int) DBGFR3OSQueryNameAndVersion(PUVM pUVM, char *pszName, size_t cchName, char *pszVersion, size_t cchVersion);
2260VMMR3DECL(void *) DBGFR3OSQueryInterface(PUVM pUVM, DBGFOSINTERFACE enmIf);
2261
2262
2263VMMR3DECL(int) DBGFR3CoreWrite(PUVM pUVM, const char *pszFilename, bool fReplaceFile);
2264
2265
2266
2267/** @defgroup grp_dbgf_plug_in The DBGF Plug-in Interface
2268 * @{
2269 */
2270
2271/** The plug-in module name prefix. */
2272# define DBGF_PLUG_IN_PREFIX "DbgPlugIn"
2273
2274/** The name of the plug-in entry point (FNDBGFPLUGIN) */
2275# define DBGF_PLUG_IN_ENTRYPOINT "DbgPlugInEntry"
2276
2277/**
2278 * DBGF plug-in operations.
2279 */
2280typedef enum DBGFPLUGINOP
2281{
2282 /** The usual invalid first value. */
2283 DBGFPLUGINOP_INVALID,
2284 /** Initialize the plug-in for a VM, register all the stuff.
2285 * The plug-in will be unloaded on failure.
2286 * uArg: The full VirtualBox version, see VBox/version.h. */
2287 DBGFPLUGINOP_INIT,
2288 /** Terminate the plug-ing for a VM, deregister all the stuff.
2289 * The plug-in will be unloaded after this call regardless of the return
2290 * code. */
2291 DBGFPLUGINOP_TERM,
2292 /** The usual 32-bit hack. */
2293 DBGFPLUGINOP_32BIT_HACK = 0x7fffffff
2294} DBGFPLUGINOP;
2295
2296/**
2297 * DBGF plug-in main entry point.
2298 *
2299 * @returns VBox status code.
2300 *
2301 * @param enmOperation The operation.
2302 * @param pUVM The user mode VM handle. This may be NULL.
2303 * @param uArg Extra argument.
2304 */
2305typedef DECLCALLBACK(int) FNDBGFPLUGIN(DBGFPLUGINOP enmOperation, PUVM pUVM, uintptr_t uArg);
2306/** Pointer to a FNDBGFPLUGIN. */
2307typedef FNDBGFPLUGIN *PFNDBGFPLUGIN;
2308
2309/** @copydoc FNDBGFPLUGIN */
2310DECLEXPORT(int) DbgPlugInEntry(DBGFPLUGINOP enmOperation, PUVM pUVM, uintptr_t uArg);
2311
2312VMMR3DECL(int) DBGFR3PlugInLoad(PUVM pUVM, const char *pszPlugIn, char *pszActual, size_t cbActual, PRTERRINFO pErrInfo);
2313VMMR3DECL(int) DBGFR3PlugInUnload(PUVM pUVM, const char *pszName);
2314VMMR3DECL(void) DBGFR3PlugInLoadAll(PUVM pUVM);
2315VMMR3DECL(void) DBGFR3PlugInUnloadAll(PUVM pUVM);
2316
2317/** @} */
2318
2319
2320/** @defgroup grp_dbgf_types The DBGF type system Interface.
2321 * @{
2322 */
2323
2324/** A few forward declarations. */
2325/** Pointer to a type registration structure. */
2326typedef struct DBGFTYPEREG *PDBGFTYPEREG;
2327/** Pointer to a const type registration structure. */
2328typedef const struct DBGFTYPEREG *PCDBGFTYPEREG;
2329/** Pointer to a typed buffer. */
2330typedef struct DBGFTYPEVAL *PDBGFTYPEVAL;
2331
2332/**
2333 * DBGF built-in types.
2334 */
2335typedef enum DBGFTYPEBUILTIN
2336{
2337 /** The usual invalid first value. */
2338 DBGFTYPEBUILTIN_INVALID,
2339 /** Unsigned 8bit integer. */
2340 DBGFTYPEBUILTIN_UINT8,
2341 /** Signed 8bit integer. */
2342 DBGFTYPEBUILTIN_INT8,
2343 /** Unsigned 16bit integer. */
2344 DBGFTYPEBUILTIN_UINT16,
2345 /** Signed 16bit integer. */
2346 DBGFTYPEBUILTIN_INT16,
2347 /** Unsigned 32bit integer. */
2348 DBGFTYPEBUILTIN_UINT32,
2349 /** Signed 32bit integer. */
2350 DBGFTYPEBUILTIN_INT32,
2351 /** Unsigned 64bit integer. */
2352 DBGFTYPEBUILTIN_UINT64,
2353 /** Signed 64bit integer. */
2354 DBGFTYPEBUILTIN_INT64,
2355 /** 32bit Guest pointer */
2356 DBGFTYPEBUILTIN_PTR32,
2357 /** 64bit Guest pointer */
2358 DBGFTYPEBUILTIN_PTR64,
2359 /** Guest pointer - size depends on the guest bitness */
2360 DBGFTYPEBUILTIN_PTR,
2361 /** Type indicating a size, like size_t this can have different sizes
2362 * on 32bit and 64bit systems */
2363 DBGFTYPEBUILTIN_SIZE,
2364 /** 32bit float. */
2365 DBGFTYPEBUILTIN_FLOAT32,
2366 /** 64bit float (also known as double). */
2367 DBGFTYPEBUILTIN_FLOAT64,
2368 /** Compund types like structs and unions. */
2369 DBGFTYPEBUILTIN_COMPOUND,
2370 /** The usual 32-bit hack. */
2371 DBGFTYPEBUILTIN_32BIT_HACK = 0x7fffffff
2372} DBGFTYPEBUILTIN;
2373/** Pointer to a built-in type. */
2374typedef DBGFTYPEBUILTIN *PDBGFTYPEBUILTIN;
2375/** Pointer to a const built-in type. */
2376typedef const DBGFTYPEBUILTIN *PCDBGFTYPEBUILTIN;
2377
2378/**
2379 * DBGF type value buffer.
2380 */
2381typedef union DBGFTYPEVALBUF
2382{
2383 uint8_t u8;
2384 int8_t i8;
2385 uint16_t u16;
2386 int16_t i16;
2387 uint32_t u32;
2388 int32_t i32;
2389 uint64_t u64;
2390 int64_t i64;
2391 float f32;
2392 double f64;
2393 uint64_t size; /* For the built-in size_t which can be either 32-bit or 64-bit. */
2394 RTGCPTR GCPtr;
2395 /** For embedded structs. */
2396 PDBGFTYPEVAL pVal;
2397} DBGFTYPEVALBUF;
2398/** Pointer to a value. */
2399typedef DBGFTYPEVALBUF *PDBGFTYPEVALBUF;
2400
2401/**
2402 * DBGF type value entry.
2403 */
2404typedef struct DBGFTYPEVALENTRY
2405{
2406 /** DBGF built-in type. */
2407 DBGFTYPEBUILTIN enmType;
2408 /** Size of the type. */
2409 size_t cbType;
2410 /** Number of entries, for arrays this can be > 1. */
2411 uint32_t cEntries;
2412 /** Value buffer, depends on whether this is an array. */
2413 union
2414 {
2415 /** Single value. */
2416 DBGFTYPEVALBUF Val;
2417 /** Pointer to the array of values. */
2418 PDBGFTYPEVALBUF pVal;
2419 } Buf;
2420} DBGFTYPEVALENTRY;
2421/** Pointer to a type value entry. */
2422typedef DBGFTYPEVALENTRY *PDBGFTYPEVALENTRY;
2423/** Pointer to a const type value entry. */
2424typedef const DBGFTYPEVALENTRY *PCDBGFTYPEVALENTRY;
2425
2426/**
2427 * DBGF typed value.
2428 */
2429typedef struct DBGFTYPEVAL
2430{
2431 /** Pointer to the registration structure for this type. */
2432 PCDBGFTYPEREG pTypeReg;
2433 /** Number of value entries. */
2434 uint32_t cEntries;
2435 /** Variable sized array of value entries. */
2436 DBGFTYPEVALENTRY aEntries[1];
2437} DBGFTYPEVAL;
2438
2439/**
2440 * DBGF type variant.
2441 */
2442typedef enum DBGFTYPEVARIANT
2443{
2444 /** The usual invalid first value. */
2445 DBGFTYPEVARIANT_INVALID,
2446 /** A struct. */
2447 DBGFTYPEVARIANT_STRUCT,
2448 /** Union. */
2449 DBGFTYPEVARIANT_UNION,
2450 /** Alias for an existing type. */
2451 DBGFTYPEVARIANT_ALIAS,
2452 /** The usual 32-bit hack. */
2453 DBGFTYPEVARIANT_32BIT_HACK = 0x7fffffff
2454} DBGFTYPEVARIANT;
2455
2456/** @name DBGFTYPEREGMEMBER Flags.
2457 * @{ */
2458/** The member is an array with a fixed size. */
2459# define DBGFTYPEREGMEMBER_F_ARRAY RT_BIT_32(0)
2460/** The member denotes a pointer. */
2461# define DBGFTYPEREGMEMBER_F_POINTER RT_BIT_32(1)
2462/** @} */
2463
2464/**
2465 * DBGF type member.
2466 */
2467typedef struct DBGFTYPEREGMEMBER
2468{
2469 /** Name of the member. */
2470 const char *pszName;
2471 /** Flags for this member, see DBGFTYPEREGMEMBER_F_XXX. */
2472 uint32_t fFlags;
2473 /** Type identifier. */
2474 const char *pszType;
2475 /** The number of elements in the array, only valid for arrays. */
2476 uint32_t cElements;
2477} DBGFTYPEREGMEMBER;
2478/** Pointer to a member. */
2479typedef DBGFTYPEREGMEMBER *PDBGFTYPEREGMEMBER;
2480/** Pointer to a const member. */
2481typedef const DBGFTYPEREGMEMBER *PCDBGFTYPEREGMEMBER;
2482
2483/** @name DBGFTYPEREG Flags.
2484 * @{ */
2485/** The type is a packed structure. */
2486# define DBGFTYPEREG_F_PACKED RT_BIT_32(0)
2487/** @} */
2488
2489/**
2490 * New type registration structure.
2491 */
2492typedef struct DBGFTYPEREG
2493{
2494 /** Name of the type. */
2495 const char *pszType;
2496 /** The type variant. */
2497 DBGFTYPEVARIANT enmVariant;
2498 /** Some registration flags, see DBGFTYPEREG_F_XXX. */
2499 uint32_t fFlags;
2500 /** Number of members this type has, only valid for structs or unions. */
2501 uint32_t cMembers;
2502 /** Pointer to the member fields, only valid for structs or unions. */
2503 PCDBGFTYPEREGMEMBER paMembers;
2504 /** Name of the aliased type for aliases. */
2505 const char *pszAliasedType;
2506} DBGFTYPEREG;
2507
2508/**
2509 * DBGF typed value dumper callback.
2510 *
2511 * @returns VBox status code. Any non VINF_SUCCESS status code will abort the dumping.
2512 *
2513 * @param off The byte offset of the entry from the start of the type.
2514 * @param pszField The name of the field for the value.
2515 * @param iLvl The current level.
2516 * @param enmType The type enum.
2517 * @param cbType Size of the type.
2518 * @param pValBuf Pointer to the value buffer.
2519 * @param cValBufs Number of value buffers (for arrays).
2520 * @param pvUser Opaque user data.
2521 */
2522typedef DECLCALLBACK(int) FNDBGFR3TYPEVALDUMP(uint32_t off, const char *pszField, uint32_t iLvl,
2523 DBGFTYPEBUILTIN enmType, size_t cbType,
2524 PDBGFTYPEVALBUF pValBuf, uint32_t cValBufs,
2525 void *pvUser);
2526/** Pointer to a FNDBGFR3TYPEVALDUMP. */
2527typedef FNDBGFR3TYPEVALDUMP *PFNDBGFR3TYPEVALDUMP;
2528
2529/**
2530 * DBGF type information dumper callback.
2531 *
2532 * @returns VBox status code. Any non VINF_SUCCESS status code will abort the dumping.
2533 *
2534 * @param off The byte offset of the entry from the start of the type.
2535 * @param pszField The name of the field for the value.
2536 * @param iLvl The current level.
2537 * @param pszType The type of the field.
2538 * @param fTypeFlags Flags for this type, see DBGFTYPEREGMEMBER_F_XXX.
2539 * @param cElements Number of for the field ( > 0 for arrays).
2540 * @param pvUser Opaque user data.
2541 */
2542typedef DECLCALLBACK(int) FNDBGFR3TYPEDUMP(uint32_t off, const char *pszField, uint32_t iLvl,
2543 const char *pszType, uint32_t fTypeFlags,
2544 uint32_t cElements, void *pvUser);
2545/** Pointer to a FNDBGFR3TYPEDUMP. */
2546typedef FNDBGFR3TYPEDUMP *PFNDBGFR3TYPEDUMP;
2547
2548VMMR3DECL(int) DBGFR3TypeRegister( PUVM pUVM, uint32_t cTypes, PCDBGFTYPEREG paTypes);
2549VMMR3DECL(int) DBGFR3TypeDeregister(PUVM pUVM, const char *pszType);
2550VMMR3DECL(int) DBGFR3TypeQueryReg( PUVM pUVM, const char *pszType, PCDBGFTYPEREG *ppTypeReg);
2551
2552VMMR3DECL(int) DBGFR3TypeQuerySize( PUVM pUVM, const char *pszType, size_t *pcbType);
2553VMMR3DECL(int) DBGFR3TypeSetSize( PUVM pUVM, const char *pszType, size_t cbType);
2554VMMR3DECL(int) DBGFR3TypeDumpEx( PUVM pUVM, const char *pszType, uint32_t fFlags,
2555 uint32_t cLvlMax, PFNDBGFR3TYPEDUMP pfnDump, void *pvUser);
2556VMMR3DECL(int) DBGFR3TypeQueryValByType(PUVM pUVM, PCDBGFADDRESS pAddress, const char *pszType,
2557 PDBGFTYPEVAL *ppVal);
2558VMMR3DECL(void) DBGFR3TypeValFree(PDBGFTYPEVAL pVal);
2559VMMR3DECL(int) DBGFR3TypeValDumpEx(PUVM pUVM, PCDBGFADDRESS pAddress, const char *pszType, uint32_t fFlags,
2560 uint32_t cLvlMax, FNDBGFR3TYPEVALDUMP pfnDump, void *pvUser);
2561
2562/** @} */
2563
2564
2565/** @defgroup grp_dbgf_flow The DBGF control flow graph Interface.
2566 * @{
2567 */
2568
2569/** A DBGF control flow graph handle. */
2570typedef struct DBGFFLOWINT *DBGFFLOW;
2571/** Pointer to a DBGF control flow graph handle. */
2572typedef DBGFFLOW *PDBGFFLOW;
2573/** A DBGF control flow graph basic block handle. */
2574typedef struct DBGFFLOWBBINT *DBGFFLOWBB;
2575/** Pointer to a DBGF control flow graph basic block handle. */
2576typedef DBGFFLOWBB *PDBGFFLOWBB;
2577/** A DBGF control flow graph branch table handle. */
2578typedef struct DBGFFLOWBRANCHTBLINT *DBGFFLOWBRANCHTBL;
2579/** Pointer to a DBGF flow control graph branch table handle. */
2580typedef DBGFFLOWBRANCHTBL *PDBGFFLOWBRANCHTBL;
2581/** A DBGF control flow graph iterator. */
2582typedef struct DBGFFLOWITINT *DBGFFLOWIT;
2583/** Pointer to a control flow graph iterator. */
2584typedef DBGFFLOWIT *PDBGFFLOWIT;
2585/** A DBGF control flow graph branch table iterator. */
2586typedef struct DBGFFLOWBRANCHTBLITINT *DBGFFLOWBRANCHTBLIT;
2587/** Pointer to a control flow graph branch table iterator. */
2588typedef DBGFFLOWBRANCHTBLIT *PDBGFFLOWBRANCHTBLIT;
2589
2590/** @name DBGFFLOWBB Flags.
2591 * @{ */
2592/** The basic block is the entry into the owning control flow graph. */
2593#define DBGF_FLOW_BB_F_ENTRY RT_BIT_32(0)
2594/** The basic block was not populated because the limit was reached. */
2595#define DBGF_FLOW_BB_F_EMPTY RT_BIT_32(1)
2596/** The basic block is not complete because an error happened during disassembly. */
2597#define DBGF_FLOW_BB_F_INCOMPLETE_ERR RT_BIT_32(2)
2598/** The basic block is reached through a branch table. */
2599#define DBGF_FLOW_BB_F_BRANCH_TABLE RT_BIT_32(3)
2600/** @} */
2601
2602/** @name Flags controlling the creating of a control flow graph.
2603 * @{ */
2604/** Default options. */
2605#define DBGF_FLOW_CREATE_F_DEFAULT 0
2606/** Tries to resolve indirect branches, useful for code using
2607 * jump tables generated for large switch statements by some compilers. */
2608#define DBGF_FLOW_CREATE_F_TRY_RESOLVE_INDIRECT_BRANCHES RT_BIT_32(0)
2609/** @} */
2610
2611/**
2612 * DBGF control graph basic block end type.
2613 */
2614typedef enum DBGFFLOWBBENDTYPE
2615{
2616 /** Invalid type. */
2617 DBGFFLOWBBENDTYPE_INVALID = 0,
2618 /** Basic block is the exit block and has no successor. */
2619 DBGFFLOWBBENDTYPE_EXIT,
2620 /** Basic block is the last disassembled block because the
2621 * maximum amount to disassemble was reached but is not an
2622 * exit block - no successors.
2623 */
2624 DBGFFLOWBBENDTYPE_LAST_DISASSEMBLED,
2625 /** Unconditional control flow change because the successor is referenced by multiple
2626 * basic blocks. - 1 successor. */
2627 DBGFFLOWBBENDTYPE_UNCOND,
2628 /** Unconditional control flow change because of an direct branch - 1 successor. */
2629 DBGFFLOWBBENDTYPE_UNCOND_JMP,
2630 /** Unconditional control flow change because of an indirect branch - n successors. */
2631 DBGFFLOWBBENDTYPE_UNCOND_INDIRECT_JMP,
2632 /** Conditional control flow change - 2 successors. */
2633 DBGFFLOWBBENDTYPE_COND,
2634 /** 32bit hack. */
2635 DBGFFLOWBBENDTYPE_32BIT_HACK = 0x7fffffff
2636} DBGFFLOWBBENDTYPE;
2637
2638/**
2639 * DBGF control flow graph iteration order.
2640 */
2641typedef enum DBGFFLOWITORDER
2642{
2643 /** Invalid order. */
2644 DBGFFLOWITORDER_INVALID = 0,
2645 /** From lowest to highest basic block start address. */
2646 DBGFFLOWITORDER_BY_ADDR_LOWEST_FIRST,
2647 /** From highest to lowest basic block start address. */
2648 DBGFFLOWITORDER_BY_ADDR_HIGHEST_FIRST,
2649 /** Depth first traversing starting from the entry block. */
2650 DBGFFLOWITORDER_DEPTH_FRIST,
2651 /** Breadth first traversing starting from the entry block. */
2652 DBGFFLOWITORDER_BREADTH_FIRST,
2653 /** Usual 32bit hack. */
2654 DBGFFLOWITORDER_32BIT_HACK = 0x7fffffff
2655} DBGFFLOWITORDER;
2656/** Pointer to a iteration order enum. */
2657typedef DBGFFLOWITORDER *PDBGFFLOWITORDER;
2658
2659
2660VMMR3DECL(int) DBGFR3FlowCreate(PUVM pUVM, VMCPUID idCpu, PDBGFADDRESS pAddressStart, uint32_t cbDisasmMax,
2661 uint32_t fFlagsFlow, uint32_t fFlagsDisasm, PDBGFFLOW phFlow);
2662VMMR3DECL(uint32_t) DBGFR3FlowRetain(DBGFFLOW hFlow);
2663VMMR3DECL(uint32_t) DBGFR3FlowRelease(DBGFFLOW hFlow);
2664VMMR3DECL(int) DBGFR3FlowQueryStartBb(DBGFFLOW hFlow, PDBGFFLOWBB phFlowBb);
2665VMMR3DECL(int) DBGFR3FlowQueryBbByAddress(DBGFFLOW hFlow, PDBGFADDRESS pAddr, PDBGFFLOWBB phFlowBb);
2666VMMR3DECL(int) DBGFR3FlowQueryBranchTblByAddress(DBGFFLOW hFlow, PDBGFADDRESS pAddr, PDBGFFLOWBRANCHTBL phFlowBranchTbl);
2667VMMR3DECL(uint32_t) DBGFR3FlowGetBbCount(DBGFFLOW hFlow);
2668VMMR3DECL(uint32_t) DBGFR3FlowGetBranchTblCount(DBGFFLOW hFlow);
2669
2670VMMR3DECL(uint32_t) DBGFR3FlowBbRetain(DBGFFLOWBB hFlowBb);
2671VMMR3DECL(uint32_t) DBGFR3FlowBbRelease(DBGFFLOWBB hFlowBb);
2672VMMR3DECL(PDBGFADDRESS) DBGFR3FlowBbGetStartAddress(DBGFFLOWBB hFlowBb, PDBGFADDRESS pAddrStart);
2673VMMR3DECL(PDBGFADDRESS) DBGFR3FlowBbGetEndAddress(DBGFFLOWBB hFlowBb, PDBGFADDRESS pAddrEnd);
2674VMMR3DECL(PDBGFADDRESS) DBGFR3FlowBbGetBranchAddress(DBGFFLOWBB hFlowBb, PDBGFADDRESS pAddrTarget);
2675VMMR3DECL(PDBGFADDRESS) DBGFR3FlowBbGetFollowingAddress(DBGFFLOWBB hFlowBb, PDBGFADDRESS pAddrFollow);
2676VMMR3DECL(DBGFFLOWBBENDTYPE) DBGFR3FlowBbGetType(DBGFFLOWBB hFlowBb);
2677VMMR3DECL(uint32_t) DBGFR3FlowBbGetInstrCount(DBGFFLOWBB hFlowBb);
2678VMMR3DECL(uint32_t) DBGFR3FlowBbGetFlags(DBGFFLOWBB hFlowBb);
2679VMMR3DECL(int) DBGFR3FlowBbQueryBranchTbl(DBGFFLOWBB hFlowBb, PDBGFFLOWBRANCHTBL phBranchTbl);
2680VMMR3DECL(int) DBGFR3FlowBbQueryError(DBGFFLOWBB hFlowBb, const char **ppszErr);
2681VMMR3DECL(int) DBGFR3FlowBbQueryInstr(DBGFFLOWBB hFlowBb, uint32_t idxInstr, PDBGFADDRESS pAddrInstr,
2682 uint32_t *pcbInstr, const char **ppszInstr);
2683VMMR3DECL(int) DBGFR3FlowBbQuerySuccessors(DBGFFLOWBB hFlowBb, PDBGFFLOWBB phFlowBbFollow,
2684 PDBGFFLOWBB phFlowBbTarget);
2685VMMR3DECL(uint32_t) DBGFR3FlowBbGetRefBbCount(DBGFFLOWBB hFlowBb);
2686VMMR3DECL(int) DBGFR3FlowBbGetRefBb(DBGFFLOWBB hFlowBb, PDBGFFLOWBB pahFlowBbRef, uint32_t cRef);
2687
2688VMMR3DECL(uint32_t) DBGFR3FlowBranchTblRetain(DBGFFLOWBRANCHTBL hFlowBranchTbl);
2689VMMR3DECL(uint32_t) DBGFR3FlowBranchTblRelease(DBGFFLOWBRANCHTBL hFlowBranchTbl);
2690VMMR3DECL(uint32_t) DBGFR3FlowBranchTblGetSlots(DBGFFLOWBRANCHTBL hFlowBranchTbl);
2691VMMR3DECL(PDBGFADDRESS) DBGFR3FlowBranchTblGetStartAddress(DBGFFLOWBRANCHTBL hFlowBranchTbl, PDBGFADDRESS pAddrStart);
2692VMMR3DECL(PDBGFADDRESS) DBGFR3FlowBranchTblGetAddrAtSlot(DBGFFLOWBRANCHTBL hFlowBranchTbl, uint32_t idxSlot, PDBGFADDRESS pAddrSlot);
2693VMMR3DECL(int) DBGFR3FlowBranchTblQueryAddresses(DBGFFLOWBRANCHTBL hFlowBranchTbl, PDBGFADDRESS paAddrs, uint32_t cAddrs);
2694
2695VMMR3DECL(int) DBGFR3FlowItCreate(DBGFFLOW hFlow, DBGFFLOWITORDER enmOrder, PDBGFFLOWIT phFlowIt);
2696VMMR3DECL(void) DBGFR3FlowItDestroy(DBGFFLOWIT hFlowIt);
2697VMMR3DECL(DBGFFLOWBB) DBGFR3FlowItNext(DBGFFLOWIT hFlowIt);
2698VMMR3DECL(int) DBGFR3FlowItReset(DBGFFLOWIT hFlowIt);
2699
2700VMMR3DECL(int) DBGFR3FlowBranchTblItCreate(DBGFFLOW hFlow, DBGFFLOWITORDER enmOrder, PDBGFFLOWBRANCHTBLIT phFlowBranchTblIt);
2701VMMR3DECL(void) DBGFR3FlowBranchTblItDestroy(DBGFFLOWBRANCHTBLIT hFlowBranchTblIt);
2702VMMR3DECL(DBGFFLOWBRANCHTBL) DBGFR3FlowBranchTblItNext(DBGFFLOWBRANCHTBLIT hFlowBranchTblIt);
2703VMMR3DECL(int) DBGFR3FlowBranchTblItReset(DBGFFLOWBRANCHTBLIT hFlowBranchTblIt);
2704
2705/** @} */
2706
2707
2708/** @defgroup grp_dbgf_misc Misc DBGF interfaces.
2709 * @{ */
2710VMMR3DECL(VBOXSTRICTRC) DBGFR3ReportBugCheck(PVM pVM, PVMCPU pVCpu, DBGFEVENTTYPE enmEvent, uint64_t uBugCheck,
2711 uint64_t uP1, uint64_t uP2, uint64_t uP3, uint64_t uP4);
2712VMMR3DECL(int) DBGFR3FormatBugCheck(PUVM pUVM, char *pszDetails, size_t cbDetails,
2713 uint64_t uP0, uint64_t uP1, uint64_t uP2, uint64_t uP3, uint64_t uP4);
2714/** @} */
2715#endif /* IN_RING3 */
2716
2717/** @} */
2718
2719
2720RT_C_DECLS_END
2721
2722#endif /* !VBOX_INCLUDED_vmm_dbgf_h */
2723
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