VirtualBox

source: vbox/trunk/include/VBox/dbgf.h@ 2166

Last change on this file since 2166 was 2165, checked in by vboxsync, 18 years ago

IN_RING0

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 48.2 KB
Line 
1/** @file
2 * DBGF - Debugging Facility.
3 */
4
5/*
6 * Copyright (C) 2006 InnoTek Systemberatung GmbH
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 as published by the Free Software Foundation,
12 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
13 * distribution. VirtualBox OSE is distributed in the hope that it will
14 * be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * If you received this file as part of a commercial VirtualBox
17 * distribution, then only the terms of your commercial VirtualBox
18 * license agreement apply instead of the previous paragraph.
19 */
20
21#ifndef __VBox_dbgf_h__
22#define __VBox_dbgf_h__
23
24
25#include <VBox/cdefs.h>
26#include <VBox/types.h>
27#include <VBox/vmm.h>
28#include <VBox/log.h>
29
30#include <iprt/stdarg.h>
31
32__BEGIN_DECLS
33
34
35/** @defgroup grp_dbgf The Debugging Facility API
36 * @{
37 */
38
39#ifdef IN_GC
40/** @addgroup grp_dbgf_gc The GC DBGF API
41 * @ingroup grp_dbgf
42 * @{
43 */
44
45/**
46 * \#DB (Debug event) handler.
47 *
48 * @returns VBox status code.
49 * VINF_SUCCESS means we completely handled this trap,
50 * other codes are passed execution to host context.
51 *
52 * @param pVM The VM handle.
53 * @param pRegFrame Pointer to the register frame for the trap.
54 * @param uDr6 The DR6 register value.
55 */
56DBGFGCDECL(int) DBGFGCTrap01Handler(PVM pVM, PCPUMCTXCORE pRegFrame, RTUINTREG uDr6);
57
58/**
59 * \#BP (Breakpoint) handler.
60 *
61 * @returns VBox status code.
62 * VINF_SUCCESS means we completely handled this trap,
63 * other codes are passed execution to host context.
64 *
65 * @param pVM The VM handle.
66 * @param pRegFrame Pointer to the register frame for the trap.
67 */
68DBGFGCDECL(int) DBGFGCTrap03Handler(PVM pVM, PCPUMCTXCORE pRegFrame);
69
70/** @} */
71#endif
72
73#ifdef IN_RING0
74/** @addgroup grp_dbgf_gc The R0 DBGF API
75 * @ingroup grp_dbgf
76 * @{
77 */
78
79/**
80 * \#DB (Debug event) handler.
81 *
82 * @returns VBox status code.
83 * VINF_SUCCESS means we completely handled this trap,
84 * other codes are passed execution to host context.
85 *
86 * @param pVM The VM handle.
87 * @param pRegFrame Pointer to the register frame for the trap.
88 * @param uDr6 The DR6 register value.
89 */
90DBGFR0DECL(int) DBGFR0Trap01Handler(PVM pVM, PCPUMCTXCORE pRegFrame, RTUINTREG uDr6);
91
92/**
93 * \#BP (Breakpoint) handler.
94 *
95 * @returns VBox status code.
96 * VINF_SUCCESS means we completely handled this trap,
97 * other codes are passed execution to host context.
98 *
99 * @param pVM The VM handle.
100 * @param pRegFrame Pointer to the register frame for the trap.
101 */
102DBGFR0DECL(int) DBGFR0Trap03Handler(PVM pVM, PCPUMCTXCORE pRegFrame);
103
104/** @} */
105#endif
106
107
108
109/**
110 * Mixed address.
111 */
112typedef struct DBGFADDRESS
113{
114 /** The flat address. */
115 RTGCUINTPTR FlatPtr;
116 /** The selector offset address. */
117 RTGCUINTPTR off;
118 /** The selector. DBGF_SEL_FLAT is a legal value. */
119 RTSEL Sel;
120 /** Flags describing further details about the address. */
121 uint16_t fFlags;
122} DBGFADDRESS;
123/** Pointer to a mixed address. */
124typedef DBGFADDRESS *PDBGFADDRESS;
125/** Pointer to a const mixed address. */
126typedef const DBGFADDRESS *PCDBGFADDRESS;
127
128/** @name DBGFADDRESS Flags.
129 * @{ */
130/** A 16:16 far address. */
131#define DBGFADDRESS_FLAGS_FAR16 0
132/** A 16:32 far address. */
133#define DBGFADDRESS_FLAGS_FAR32 1
134/** A 16:64 far address. */
135#define DBGFADDRESS_FLAGS_FAR64 2
136/** A flat address. */
137#define DBGFADDRESS_FLAGS_FLAT 3
138/** The address type mask. */
139#define DBGFADDRESS_FLAGS_TYPE_MASK 3
140
141/** Set if the address is valid. */
142#define DBGFADDRESS_FLAGS_VALID BIT(2)
143
144/** The address is within the hypervisor memoary area (HMA).
145 * If not set, the address can be assumed to be a guest address. */
146#define DBGFADDRESS_FLAGS_HMA BIT(3)
147
148/** Checks if the mixed address is flat or not. */
149#define DBGFADDRESS_IS_FLAT(pAddress) ( ((pAddress)->fFlags & DBGFADDRESS_FLAGS_TYPE_MASK) == DBGFADDRESS_FLAGS_FLAT )
150/** Checks if the mixed address is far 16:16 or not. */
151#define DBGFADDRESS_IS_FAR16(pAddress) ( ((pAddress)->fFlags & DBGFADDRESS_FLAGS_TYPE_MASK) == DBGFADDRESS_FLAGS_FAR16 )
152/** Checks if the mixed address is far 16:32 or not. */
153#define DBGFADDRESS_IS_FAR32(pAddress) ( ((pAddress)->fFlags & DBGFADDRESS_FLAGS_TYPE_MASK) == DBGFADDRESS_FLAGS_FAR32 )
154/** Checks if the mixed address is far 16:64 or not. */
155#define DBGFADDRESS_IS_FAR64(pAddress) ( ((pAddress)->fFlags & DBGFADDRESS_FLAGS_TYPE_MASK) == DBGFADDRESS_FLAGS_FAR64 )
156/** Checks if the mixed address is valid. */
157#define DBGFADDRESS_IS_VALID(pAddress) ( (pAddress)->fFlags & DBGFADDRESS_FLAGS_VALID )
158/** @} */
159
160/**
161 * Creates a mixed address from a Sel:off pair.
162 *
163 * @returns VBox status code.
164 * @param pVM The VM handle.
165 * @param pAddress Where to store the mixed address.
166 * @param Sel The selector part.
167 * @param off The offset part.
168 */
169DBGFR3DECL(int) DBGFR3AddrFromSelOff(PVM pVM, PDBGFADDRESS pAddress, RTSEL Sel, RTUINTPTR off);
170
171/**
172 * Creates a mixed address from a flat address.
173 *
174 * @param pVM The VM handle.
175 * @param pAddress Where to store the mixed address.
176 * @param FlatPtr The flat pointer.
177 */
178DBGFR3DECL(void) DBGFR3AddrFromFlat(PVM pVM, PDBGFADDRESS pAddress, RTGCUINTPTR FlatPtr);
179
180/**
181 * Checks if the specified address is valid (checks the structure pointer too).
182 *
183 * @returns true if valid.
184 * @returns false if invalid.
185 * @param pVM The VM handle.
186 * @param pAddress The address to validate.
187 */
188DBGFR3DECL(bool) DBGFR3AddrIsValid(PVM pVM, PCDBGFADDRESS pAddress);
189
190
191
192
193/**
194 * VMM Debug Event Type.
195 */
196typedef enum DBGFEVENTTYPE
197{
198 /** Halt completed.
199 * This notifies that a halt command have been successfully completed.
200 */
201 DBGFEVENT_HALT_DONE = 0,
202 /** Detach completed.
203 * This notifies that the detach command have been successfully completed.
204 */
205 DBGFEVENT_DETACH_DONE,
206 /** The command from the debugger is not recognized.
207 * This means internal error or half implemented features.
208 */
209 DBGFEVENT_INVALID_COMMAND,
210
211
212 /** Fatal error.
213 * This notifies a fatal error in the VMM and that the debugger get's a
214 * chance to first hand information about the the problem.
215 */
216 DBGFEVENT_FATAL_ERROR = 100,
217 /** Breakpoint Hit.
218 * This notifies that a breakpoint installed by the debugger was hit. The
219 * identifier of the breakpoint can be found in the DBGFEVENT::u::Bp::iBp member.
220 */
221 DBGFEVENT_BREAKPOINT,
222 /** Breakpoint Hit in the Hypervisor.
223 * This notifies that a breakpoint installed by the debugger was hit. The
224 * identifier of the breakpoint can be found in the DBGFEVENT::u::Bp::iBp member.
225 */
226 DBGFEVENT_BREAKPOINT_HYPER,
227 /** Assertion in the Hypervisor (breakpoint instruction).
228 * This notifies that a breakpoint instruction was hit in the hypervisor context.
229 */
230 DBGFEVENT_ASSERTION_HYPER,
231 /** Single Stepped.
232 * This notifies that a single step operation was completed.
233 */
234 DBGFEVENT_STEPPED,
235 /** Single Stepped.
236 * This notifies that a hypervisor single step operation was completed.
237 */
238 DBGFEVENT_STEPPED_HYPER,
239 /** The developer have used the DBGFSTOP macro or the PDMDeviceDBGFSTOP function
240 * to bring up the debugger at a specific place.
241 */
242 DBGFEVENT_DEV_STOP,
243 /** The VM is terminating.
244 * When this notification is received, the debugger thread should detach ASAP.
245 */
246 DBGFEVENT_TERMINATING,
247
248 /** The usual 32-bit hack. */
249 DBGFEVENT_32BIT_HACK = 0x7fffffff
250} DBGFEVENTTYPE;
251
252
253/**
254 * The context of an event.
255 */
256typedef enum DBGFEVENTCTX
257{
258 /** The usual invalid entry. */
259 DBGFEVENTCTX_INVALID = 0,
260 /** Raw mode. */
261 DBGFEVENTCTX_RAW,
262 /** Recompiled mode. */
263 DBGFEVENTCTX_REM,
264 /** VMX / AVT mode. */
265 DBGFEVENTCTX_HWACCL,
266 /** Hypervisor context. */
267 DBGFEVENTCTX_HYPER,
268 /** Other mode */
269 DBGFEVENTCTX_OTHER,
270
271 /** The usual 32-bit hack */
272 DBGFEVENTCTX_32BIT_HACK = 0x7fffffff
273} DBGFEVENTCTX;
274
275/**
276 * VMM Debug Event.
277 */
278typedef struct DBGFEVENT
279{
280 /** Type. */
281 DBGFEVENTTYPE enmType;
282 /** Context */
283 DBGFEVENTCTX enmCtx;
284 /** Type specific data. */
285 union
286 {
287 /** Fatal error details. */
288 struct
289 {
290 /** The GC return code. */
291 int rc;
292 } FatalError;
293
294 /** Source location. */
295 struct
296 {
297 /** File name. */
298 R3PTRTYPE(const char *) pszFile;
299 /** Function name. */
300 R3PTRTYPE(const char *) pszFunction;
301 /** Message. */
302 R3PTRTYPE(const char *) pszMessage;
303 /** Line number. */
304 unsigned uLine;
305 } Src;
306
307 /** Assertion messages. */
308 struct
309 {
310 /** The first message. */
311 R3PTRTYPE(const char *) pszMsg1;
312 /** The second message. */
313 R3PTRTYPE(const char *) pszMsg2;
314 } Assert;
315
316 /** Breakpoint. */
317 struct DBGFEVENTBP
318 {
319 /** The identifier of the breakpoint which was hit. */
320 RTUINT iBp;
321 } Bp;
322 /** Padding for ensuring that the structure is 8 byte aligned. */
323 uint64_t au64Padding[4];
324 } u;
325} DBGFEVENT;
326/** Pointer to VMM Debug Event. */
327typedef DBGFEVENT *PDBGFEVENT;
328/** Pointer to const VMM Debug Event. */
329typedef const DBGFEVENT *PCDBGFEVENT;
330
331
332/** @def DBGFSTOP
333 * Stops the debugger raising a DBGFEVENT_DEVELOPER_STOP event.
334 *
335 * @returns VBox status code which must be propagated up to EM if not VINF_SUCCESS.
336 * @param pVM VM Handle.
337 */
338#ifdef VBOX_STRICT
339# define DBGFSTOP(pVM) DBGFR3EventSrc(pVM, DBGFEVENT_DEV_STOP, __FILE__, __LINE__, __PRETTY_FUNCTION__, NULL)
340#else
341# define DBGFSTOP(pVM) VINF_SUCCESS
342#endif
343
344/**
345 * Initializes the DBGF.
346 *
347 * @returns VBox status code.
348 * @param pVM VM handle.
349 */
350DBGFR3DECL(int) DBGFR3Init(PVM pVM);
351
352/**
353 * Termiantes and cleans up resources allocated by the DBGF.
354 *
355 * @returns VBox status code.
356 * @param pVM VM Handle.
357 */
358DBGFR3DECL(int) DBGFR3Term(PVM pVM);
359
360/**
361 * Applies relocations to data and code managed by this
362 * component. This function will be called at init and
363 * whenever the VMM need to relocate it self inside the GC.
364 *
365 * @param pVM VM handle.
366 * @param offDelta Relocation delta relative to old location.
367 */
368DBGFR3DECL(void) DBGFR3Relocate(PVM pVM, RTGCINTPTR offDelta);
369
370/**
371 * Forced action callback.
372 * The VMM will call this from it's main loop when VM_FF_DBGF is set.
373 *
374 * The function checks and executes pending commands from the debugger.
375 *
376 * @returns VINF_SUCCESS normally.
377 * @returns VERR_DBGF_RAISE_FATAL_ERROR to pretend a fatal error happend.
378 * @param pVM VM Handle.
379 */
380DBGFR3DECL(int) DBGFR3VMMForcedAction(PVM pVM);
381
382/**
383 * Send a generic debugger event which takes no data.
384 *
385 * @returns VBox status.
386 * @param pVM The VM handle.
387 * @param enmEvent The event to send.
388 */
389DBGFR3DECL(int) DBGFR3Event(PVM pVM, DBGFEVENTTYPE enmEvent);
390
391/**
392 * Send a debugger event which takes the full source file location.
393 *
394 * @returns VBox status.
395 * @param pVM The VM handle.
396 * @param enmEvent The event to send.
397 * @param pszFile Source file.
398 * @param uLine Line number in source file.
399 * @param pszFunction Function name.
400 * @param pszFormat Message which accompanies the event.
401 * @param ... Message arguments.
402 */
403DBGFR3DECL(int) DBGFR3EventSrc(PVM pVM, DBGFEVENTTYPE enmEvent, const char *pszFile, unsigned uLine, const char *pszFunction, const char *pszFormat, ...);
404
405/**
406 * Send a debugger event which takes the full source file location.
407 *
408 * @returns VBox status.
409 * @param pVM The VM handle.
410 * @param enmEvent The event to send.
411 * @param pszFile Source file.
412 * @param uLine Line number in source file.
413 * @param pszFunction Function name.
414 * @param pszFormat Message which accompanies the event.
415 * @param args Message arguments.
416 */
417DBGFR3DECL(int) DBGFR3EventSrcV(PVM pVM, DBGFEVENTTYPE enmEvent, const char *pszFile, unsigned uLine, const char *pszFunction, const char *pszFormat, va_list args);
418
419/**
420 * Send a debugger event which takes the two assertion messages.
421 *
422 * @returns VBox status.
423 * @param pVM The VM handle.
424 * @param enmEvent The event to send.
425 * @param pszMsg1 First assertion message.
426 * @param pszMsg2 Second assertion message.
427 */
428DBGFR3DECL(int) DBGFR3EventAssertion(PVM pVM, DBGFEVENTTYPE enmEvent, const char *pszMsg1, const char *pszMsg2);
429
430/**
431 * Breakpoint was hit somewhere.
432 * Figure out which breakpoint it is and notify the debugger.
433 *
434 * @returns VBox status.
435 * @param pVM The VM handle.
436 * @param enmEvent DBGFEVENT_BREAKPOINT_HYPER or DBGFEVENT_BREAKPOINT.
437 */
438DBGFR3DECL(int) DBGFR3EventBreakpoint(PVM pVM, DBGFEVENTTYPE enmEvent);
439
440/**
441 * Attaches a debugger to the specified VM.
442 *
443 * Only one debugger at a time.
444 *
445 * @returns VBox status code.
446 * @param pVM VM Handle.
447 */
448DBGFR3DECL(int) DBGFR3Attach(PVM pVM);
449
450/**
451 * Detaches a debugger from the specified VM.
452 *
453 * Caller must be attached to the VM.
454 *
455 * @returns VBox status code.
456 * @param pVM VM Handle.
457 */
458DBGFR3DECL(int) DBGFR3Detach(PVM pVM);
459
460/**
461 * Wait for a debug event.
462 *
463 * @returns VBox status. Will not return VBOX_INTERRUPTED.
464 * @param pVM VM handle.
465 * @param cMillies Number of millies to wait.
466 * @param ppEvent Where to store the event pointer.
467 */
468DBGFR3DECL(int) DBGFR3EventWait(PVM pVM, unsigned cMillies, PCDBGFEVENT *ppEvent);
469
470/**
471 * Halts VM execution.
472 *
473 * After calling this the VM isn't actually halted till an DBGFEVENT_HALT_DONE
474 * arrives. Until that time it's not possible to issue any new commands.
475 *
476 * @returns VBox status.
477 * @param pVM VM handle.
478 */
479DBGFR3DECL(int) DBGFR3Halt(PVM pVM);
480
481/**
482 * Checks if the VM is halted by the debugger.
483 *
484 * @returns True if halted.
485 * @returns False if not halted.
486 * @param pVM VM handle.
487 */
488DBGFR3DECL(bool) DBGFR3IsHalted(PVM pVM);
489
490/**
491 * Checks if the the debugger can wait for events or not.
492 *
493 * This function is only used by lazy, multiplexing debuggers. :-)
494 *
495 * @returns True if waitable.
496 * @returns False if not waitable.
497 * @param pVM VM handle.
498 */
499DBGFR3DECL(bool) DBGFR3CanWait(PVM pVM);
500
501/**
502 * Resumes VM execution.
503 *
504 * There is no receipt event on this command.
505 *
506 * @returns VBox status.
507 * @param pVM VM handle.
508 */
509DBGFR3DECL(int) DBGFR3Resume(PVM pVM);
510
511/**
512 * Step Into.
513 *
514 * A single step event is generated from this command.
515 * The current implementation is not reliable, so don't rely on the event comming.
516 *
517 * @returns VBox status.
518 * @param pVM VM handle.
519 */
520DBGFR3DECL(int) DBGFR3Step(PVM pVM);
521
522/**
523 * Call this to single step rawmode or recompiled mode.
524 *
525 * You must pass down the return code to the EM loop! That's
526 * where the actual single stepping take place (at least in the
527 * current implementation).
528 *
529 * @returns VINF_EM_DBG_STEP
530 * @thread EMT
531 */
532DBGFR3DECL(int) DBGFR3PrgStep(PVM pVM);
533
534
535/** Breakpoint type. */
536typedef enum DBGFBPTYPE
537{
538 /** Free breakpoint entry. */
539 DBGFBPTYPE_FREE = 0,
540 /** Debug register. */
541 DBGFBPTYPE_REG,
542 /** INT 3 instruction. */
543 DBGFBPTYPE_INT3,
544 /** Recompiler. */
545 DBGFBPTYPE_REM,
546 /** ensure 32-bit size. */
547 DBGFBPTYPE_32BIT_HACK = 0x7fffffff
548} DBGFBPTYPE;
549
550
551/**
552 * A Breakpoint.
553 */
554typedef struct DBGFBP
555{
556 /** The number of breakpoint hits. */
557 uint64_t cHits;
558 /** The hit number which starts to trigger the breakpoint. */
559 uint64_t iHitTrigger;
560 /** The hit number which stops triggering the breakpoint (disables it).
561 * Use ~(uint64_t)0 if it should never stop. */
562 uint64_t iHitDisable;
563 /** The Flat GC address of the breakpoint.
564 * (PC register value if REM type?) */
565 RTGCUINTPTR GCPtr;
566 /** The breakpoint id. */
567 RTUINT iBp;
568 /** The breakpoint status - enabled or disabled. */
569 bool fEnabled;
570
571 /** The breakpoint type. */
572 DBGFBPTYPE enmType;
573 /** Union of type specific data. */
574 union
575 {
576 /** Debug register data. */
577 struct DBGFBPREG
578 {
579 /** The debug register number. */
580 uint8_t iReg;
581 /** The access type (one of the X86_DR7_RW_* value). */
582 uint8_t fType;
583 /** The access size. */
584 uint8_t cb;
585 } Reg;
586 /** Recompiler breakpoint data. */
587 struct DBGFBPINT3
588 {
589 /** The byte value we replaced by the INT 3 instruction. */
590 uint8_t bOrg;
591 } Int3;
592
593 /** Recompiler breakpoint data. */
594 struct DBGFBPREM
595 {
596 /** nothing yet */
597 uint8_t fDummy;
598 } Rem;
599 /** Paddind to ensure that the size is identical on win32 and linux. */
600 uint64_t u64Padding;
601 } u;
602} DBGFBP;
603
604/** Pointer to a breakpoint. */
605typedef DBGFBP *PDBGFBP;
606/** Pointer to a const breakpoint. */
607typedef const DBGFBP *PCDBGFBP;
608
609
610/**
611 * Sets a breakpoint (int 3 based).
612 *
613 * @returns VBox status code.
614 * @param pVM The VM handle.
615 * @param pAddress The address of the breakpoint.
616 * @param iHitTrigger The hit count at which the breakpoint start triggering.
617 * Use 0 (or 1) if it's gonna trigger at once.
618 * @param iHitDisable The hit count which disables the breakpoint.
619 * Use ~(uint64_t) if it's never gonna be disabled.
620 * @param piBp Where to store the breakpoint id. (optional)
621 * @thread Any thread.
622 */
623DBGFR3DECL(int) DBGFR3BpSet(PVM pVM, PCDBGFADDRESS pAddress, uint64_t iHitTrigger, uint64_t iHitDisable, PRTUINT piBp);
624
625/**
626 * Sets a register breakpoint.
627 *
628 * @returns VBox status code.
629 * @param pVM The VM handle.
630 * @param pAddress The address of the breakpoint.
631 * @param iHitTrigger The hit count at which the breakpoint start triggering.
632 * Use 0 (or 1) if it's gonna trigger at once.
633 * @param iHitDisable The hit count which disables the breakpoint.
634 * Use ~(uint64_t) if it's never gonna be disabled.
635 * @param fType The access type (one of the X86_DR7_RW_* defines).
636 * @param cb The access size - 1,2,4 or 8 (the latter is AMD64 long mode only.
637 * Must be 1 if fType is X86_DR7_RW_EO.
638 * @param piBp Where to store the breakpoint id. (optional)
639 * @thread Any thread.
640 */
641DBGFR3DECL(int) DBGFR3BpSetReg(PVM pVM, PCDBGFADDRESS pAddress, uint64_t iHitTrigger, uint64_t iHitDisable,
642 uint8_t fType, uint8_t cb, PRTUINT piBp);
643
644/**
645 * Sets a recompiler breakpoint.
646 *
647 * @returns VBox status code.
648 * @param pVM The VM handle.
649 * @param pAddress The address of the breakpoint.
650 * @param iHitTrigger The hit count at which the breakpoint start triggering.
651 * Use 0 (or 1) if it's gonna trigger at once.
652 * @param iHitDisable The hit count which disables the breakpoint.
653 * Use ~(uint64_t) if it's never gonna be disabled.
654 * @param piBp Where to store the breakpoint id. (optional)
655 * @thread Any thread.
656 */
657DBGFR3DECL(int) DBGFR3BpSetREM(PVM pVM, PCDBGFADDRESS pAddress, uint64_t iHitTrigger, uint64_t iHitDisable, PRTUINT piBp);
658
659/**
660 * Clears a breakpoint.
661 *
662 * @returns VBox status code.
663 * @param pVM The VM handle.
664 * @param iBp The id of the breakpoint which should be removed (cleared).
665 * @thread Any thread.
666 */
667DBGFR3DECL(int) DBGFR3BpClear(PVM pVM, RTUINT iBp);
668
669/**
670 * Enables a breakpoint.
671 *
672 * @returns VBox status code.
673 * @param pVM The VM handle.
674 * @param iBp The id of the breakpoint which should be enabled.
675 * @thread Any thread.
676 */
677DBGFR3DECL(int) DBGFR3BpEnable(PVM pVM, RTUINT iBp);
678
679/**
680 * Disables a breakpoint.
681 *
682 * @returns VBox status code.
683 * @param pVM The VM handle.
684 * @param iBp The id of the breakpoint which should be disabled.
685 * @thread Any thread.
686 */
687DBGFR3DECL(int) DBGFR3BpDisable(PVM pVM, RTUINT iBp);
688
689/**
690 * Breakpoint enumeration callback function.
691 *
692 * @returns VBox status code. Any failure will stop the enumeration.
693 * @param pVM The VM handle.
694 * @param pvUser The user argument.
695 * @param pBp Pointer to the breakpoint information. (readonly)
696 */
697typedef DECLCALLBACK(int) FNDBGFBPENUM(PVM pVM, void *pvUser, PCDBGFBP pBp);
698/** Pointer to a breakpoint enumeration callback function. */
699typedef FNDBGFBPENUM *PFNDBGFBPENUM;
700
701/**
702 * Enumerate the breakpoints.
703 *
704 * @returns VBox status code.
705 * @param pVM The VM handle.
706 * @param pfnCallback The callback function.
707 * @param pvUser The user argument to pass to the callback.
708 * @thread Any thread but the callback will be called from EMT.
709 */
710DBGFR3DECL(int) DBGFR3BpEnum(PVM pVM, PFNDBGFBPENUM pfnCallback, void *pvUser);
711
712
713/**
714 * Gets the hardware breakpoint configuration as DR7.
715 *
716 * @returns DR7 from the DBGF point of view.
717 * @param pVM The VM handle.
718 */
719DBGFDECL(RTGCUINTREG) DBGFBpGetDR7(PVM pVM);
720
721/**
722 * Gets the address of the hardware breakpoint number 0.
723 *
724 * @returns DR0 from the DBGF point of view.
725 * @param pVM The VM handle.
726 */
727DBGFDECL(RTGCUINTREG) DBGFBpGetDR0(PVM pVM);
728
729/**
730 * Gets the address of the hardware breakpoint number 1.
731 *
732 * @returns DR1 from the DBGF point of view.
733 * @param pVM The VM handle.
734 */
735DBGFDECL(RTGCUINTREG) DBGFBpGetDR1(PVM pVM);
736
737/**
738 * Gets the address of the hardware breakpoint number 2.
739 *
740 * @returns DR2 from the DBGF point of view.
741 * @param pVM The VM handle.
742 */
743DBGFDECL(RTGCUINTREG) DBGFBpGetDR2(PVM pVM);
744
745/**
746 * Gets the address of the hardware breakpoint number 3.
747 *
748 * @returns DR3 from the DBGF point of view.
749 * @param pVM The VM handle.
750 */
751DBGFDECL(RTGCUINTREG) DBGFBpGetDR3(PVM pVM);
752
753
754
755/** Pointer to a info helper callback structure. */
756typedef struct DBGFINFOHLP *PDBGFINFOHLP;
757/** Pointer to a const info helper callback structure. */
758typedef const struct DBGFINFOHLP *PCDBGFINFOHLP;
759
760/**
761 * Info helper callback structure.
762 */
763typedef struct DBGFINFOHLP
764{
765 /**
766 * Print formatted string.
767 *
768 * @param pHlp Pointer to this structure.
769 * @param pszFormat The format string.
770 * @param ... Arguments.
771 */
772 DECLCALLBACKMEMBER(void, pfnPrintf)(PCDBGFINFOHLP pHlp, const char *pszFormat, ...);
773
774 /**
775 * Print formatted string.
776 *
777 * @param pHlp Pointer to this structure.
778 * @param pszFormat The format string.
779 * @param args Argument list.
780 */
781 DECLCALLBACKMEMBER(void, pfnPrintfV)(PCDBGFINFOHLP pHlp, const char *pszFormat, va_list args);
782} DBGFINFOHLP;
783
784
785/**
786 * Info handler, device version.
787 *
788 * @param pDevIns Device instance which registered the info.
789 * @param pHlp Callback functions for doing output.
790 * @param pszArgs Argument string. Optional and specific to the handler.
791 */
792typedef DECLCALLBACK(void) FNDBGFHANDLERDEV(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs);
793/** Pointer to a FNDBGFHANDLERDEV function. */
794typedef FNDBGFHANDLERDEV *PFNDBGFHANDLERDEV;
795
796/**
797 * Info handler, driver version.
798 *
799 * @param pDrvIns Driver instance which registered the info.
800 * @param pHlp Callback functions for doing output.
801 * @param pszArgs Argument string. Optional and specific to the handler.
802 */
803typedef DECLCALLBACK(void) FNDBGFHANDLERDRV(PPDMDRVINS pDrvIns, PCDBGFINFOHLP pHlp, const char *pszArgs);
804/** Pointer to a FNDBGFHANDLERDRV function. */
805typedef FNDBGFHANDLERDRV *PFNDBGFHANDLERDRV;
806
807/**
808 * Info handler, internal version.
809 *
810 * @param pVM The VM handle.
811 * @param pHlp Callback functions for doing output.
812 * @param pszArgs Argument string. Optional and specific to the handler.
813 */
814typedef DECLCALLBACK(void) FNDBGFHANDLERINT(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
815/** Pointer to a FNDBGFHANDLERINT function. */
816typedef FNDBGFHANDLERINT *PFNDBGFHANDLERINT;
817
818/**
819 * Info handler, external version.
820 *
821 * @param pvUser User argument.
822 * @param pHlp Callback functions for doing output.
823 * @param pszArgs Argument string. Optional and specific to the handler.
824 */
825typedef DECLCALLBACK(void) FNDBGFHANDLEREXT(void *pvUser, PCDBGFINFOHLP pHlp, const char *pszArgs);
826/** Pointer to a FNDBGFHANDLEREXT function. */
827typedef FNDBGFHANDLEREXT *PFNDBGFHANDLEREXT;
828
829
830/**
831 * Register a info handler owned by a device.
832 *
833 * @returns VBox status code.
834 * @param pVM VM handle.
835 * @param pszName The identifier of the info.
836 * @param pszDesc The description of the info and any arguments the handler may take.
837 * @param pfnHandler The handler function to be called to display the info.
838 * @param pDevIns The device instance owning the info.
839 */
840DBGFR3DECL(int) DBGFR3InfoRegisterDevice(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDEV pfnHandler, PPDMDEVINS pDevIns);
841
842/**
843 * Register a info handler owned by a driver.
844 *
845 * @returns VBox status code.
846 * @param pVM VM handle.
847 * @param pszName The identifier of the info.
848 * @param pszDesc The description of the info and any arguments the handler may take.
849 * @param pfnHandler The handler function to be called to display the info.
850 * @param pDrvIns The driver instance owning the info.
851 */
852DBGFR3DECL(int) DBGFR3InfoRegisterDriver(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDRV pfnHandler, PPDMDRVINS pDrvIns);
853
854/**
855 * Register a info handler owned by an internal component.
856 *
857 * @returns VBox status code.
858 * @param pVM VM handle.
859 * @param pszName The identifier of the info.
860 * @param pszDesc The description of the info and any arguments the handler may take.
861 * @param pfnHandler The handler function to be called to display the info.
862 */
863DBGFR3DECL(int) DBGFR3InfoRegisterInternal(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFHANDLERINT pfnHandler);
864
865/**
866 * Register a info handler owned by an external component.
867 *
868 * @returns VBox status code.
869 * @param pVM VM handle.
870 * @param pszName The identifier of the info.
871 * @param pszDesc The description of the info and any arguments the handler may take.
872 * @param pfnHandler The handler function to be called to display the info.
873 * @param pvUser User argument to be passed to the handler.
874 */
875DBGFR3DECL(int) DBGFR3InfoRegisterExternal(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFHANDLEREXT pfnHandler, void *pvUser);
876
877/**
878 * Deregister one(/all) info handler(s) owned by a device.
879 *
880 * @returns VBox status code.
881 * @param pVM VM Handle.
882 * @param pDevIns Device instance.
883 * @param pszName The identifier of the info. If NULL all owned by the device.
884 */
885DBGFR3DECL(int) DBGFR3InfoDeregisterDevice(PVM pVM, PPDMDEVINS pDevIns, const char *pszName);
886
887/**
888 * Deregister one(/all) info handler(s) owned by a driver.
889 *
890 * @returns VBox status code.
891 * @param pVM VM Handle.
892 * @param pDrvIns Driver instance.
893 * @param pszName The identifier of the info. If NULL all owned by the driver.
894 */
895DBGFR3DECL(int) DBGFR3InfoDeregisterDriver(PVM pVM, PPDMDRVINS pDrvIns, const char *pszName);
896
897/**
898 * Deregister a info handler owned by an internal component.
899 *
900 * @returns VBox status code.
901 * @param pVM VM Handle.
902 * @param pszName The identifier of the info. If NULL all owned by the device.
903 */
904DBGFR3DECL(int) DBGFR3InfoDeregisterInternal(PVM pVM, const char *pszName);
905
906/**
907 * Deregister a info handler owned by an external component.
908 *
909 * @returns VBox status code.
910 * @param pVM VM Handle.
911 * @param pszName The identifier of the info. If NULL all owned by the device.
912 */
913DBGFR3DECL(int) DBGFR3InfoDeregisterExternal(PVM pVM, const char *pszName);
914
915/**
916 * Display a piece of info writing to the supplied handler.
917 *
918 * @returns VBox status code.
919 * @param pVM VM handle.
920 * @param pszName The identifier of the info to display.
921 * @param pszArgs Arguments to the info handler.
922 * @param pHlp The output helper functions. If NULL the logger will be used.
923 */
924DBGFR3DECL(int) DBGFR3Info(PVM pVM, const char *pszName, const char *pszArgs, PCDBGFINFOHLP pHlp);
925
926/** @def DBGFR3InfoLog
927 * Display a piece of info writing to the log if enabled.
928 *
929 * @param pVM VM handle.
930 * @param pszName The identifier of the info to display.
931 * @param pszArgs Arguments to the info handler.
932 */
933#ifdef LOG_ENABLED
934#define DBGFR3InfoLog(pVM, pszName, pszArgs) \
935 do { \
936 if (LogIsEnabled()) \
937 DBGFR3Info(pVM, pszName, pszArgs, NULL); \
938 } while (0)
939#else
940#define DBGFR3InfoLog(pVM, pszName, pszArgs) do { } while (0)
941#endif
942
943
944/**
945 * Changes the logger group settings.
946 *
947 * @returns VBox status code.
948 * @param pVM The VM handle.
949 * @param pszGroupSettings The group settings string. (VBOX_LOG)
950 */
951DBGFR3DECL(int) DBGFR3LogModifyGroups(PVM pVM, const char *pszGroupSettings);
952
953/**
954 * Changes the logger flag settings.
955 *
956 * @returns VBox status code.
957 * @param pVM The VM handle.
958 * @param pszFlagSettings The flag settings string. (VBOX_LOG_FLAGS)
959 */
960DBGFR3DECL(int) DBGFR3LogModifyFlags(PVM pVM, const char *pszFlagSettings);
961
962/**
963 * Changes the logger destination settings.
964 *
965 * @returns VBox status code.
966 * @param pVM The VM handle.
967 * @param pszDestSettings The destination settings string. (VBOX_LOG_DEST)
968 */
969DBGFR3DECL(int) DBGFR3LogModifyDestinations(PVM pVM, const char *pszDestSettings);
970
971
972/**
973 * Enumeration callback for use with DBGFR3InfoEnum.
974 *
975 * @returns VBox status code.
976 * A status code indicating failure will end the enumeration
977 * and DBGFR3InfoEnum will return with that status code.
978 * @param pVM VM handle.
979 * @param pszName Info identifier name.
980 * @param pszDesc The description.
981 */
982typedef DECLCALLBACK(int) FNDBGFINFOENUM(PVM pVM, const char *pszName, const char *pszDesc, void *pvUser);
983/** Pointer to a FNDBGFINFOENUM function. */
984typedef FNDBGFINFOENUM *PFNDBGFINFOENUM;
985
986/**
987 * Enumerate all the register info handlers.
988 *
989 * @returns VBox status code.
990 * @param pVM VM handle.
991 * @param pfnCallback Pointer to callback function.
992 * @param pvUser User argument to pass to the callback.
993 */
994DBGFR3DECL(int) DBGFR3InfoEnum(PVM pVM, PFNDBGFINFOENUM pfnCallback, void *pvUser);
995
996/**
997 * Gets the logger info helper.
998 * The returned info helper will unconditionally write all output to the log.
999 *
1000 * @returns Pointer to the logger info helper.
1001 */
1002DBGFR3DECL(PCDBGFINFOHLP) DBGFR3InfoLogHlp(void);
1003
1004/**
1005 * Gets the release logger info helper.
1006 * The returned info helper will unconditionally write all output to the release log.
1007 *
1008 * @returns Pointer to the release logger info helper.
1009 */
1010DBGFR3DECL(PCDBGFINFOHLP) DBGFR3InfoLogRelHlp(void);
1011
1012
1013
1014/** Max length (including '\\0') of a symbol name. */
1015#define DBGF_SYMBOL_NAME_LENGTH 512
1016
1017/**
1018 * Debug symbol.
1019 */
1020typedef struct DBGFSYMBOL
1021{
1022 /** Symbol value (address). */
1023 RTGCUINTPTR Value;
1024 /** Symbol size. */
1025 uint32_t cb;
1026 /** Symbol Flags. (reserved). */
1027 uint32_t fFlags;
1028 /** Symbol name. */
1029 char szName[DBGF_SYMBOL_NAME_LENGTH];
1030} DBGFSYMBOL;
1031/** Pointer to debug symbol. */
1032typedef DBGFSYMBOL *PDBGFSYMBOL;
1033/** Pointer to const debug symbol. */
1034typedef const DBGFSYMBOL *PCDBGFSYMBOL;
1035
1036/**
1037 * Debug line number information.
1038 */
1039typedef struct DBGFLINE
1040{
1041 /** Address. */
1042 RTGCUINTPTR Address;
1043 /** Line number. */
1044 uint32_t uLineNo;
1045 /** Filename. */
1046 char szFilename[260];
1047} DBGFLINE;
1048/** Pointer to debug line number. */
1049typedef DBGFLINE *PDBGFLINE;
1050/** Pointer to const debug line number. */
1051typedef const DBGFLINE *PCDBGFLINE;
1052
1053
1054/**
1055 * Load debug info, optionally related to a specific module.
1056 *
1057 * @returns VBox status.
1058 * @param pVM VM Handle.
1059 * @param pszFilename Path to the file containing the symbol information.
1060 * This can be the executable image, a flat symbol file of some kind or stripped debug info.
1061 * @param AddressDelta The value to add to the loaded symbols.
1062 * @param pszName Short hand name for the module. If not related to a module specify NULL.
1063 * @param Address Address which the image is loaded at. This will be used to reference the module other places in the api.
1064 * Ignored when pszName is NULL.
1065 * @param cbImage Size of the image.
1066 * Ignored when pszName is NULL.
1067 */
1068DBGFR3DECL(int) DBGFR3ModuleLoad(PVM pVM, const char *pszFilename, RTGCUINTPTR AddressDelta, const char *pszName, RTGCUINTPTR ModuleAddress, unsigned cbImage);
1069
1070/**
1071 * Interface used by PDMR3LdrRelocate for telling us that a GC module has been relocated.
1072 *
1073 * @param pVM The VM handle.
1074 * @param OldImageBase The old image base.
1075 * @param NewImageBase The new image base.
1076 * @param cbImage The image size.
1077 * @param pszFilename The image filename.
1078 * @param pszName The module name.
1079 */
1080DBGFR3DECL(void) DBGFR3ModuleRelocate(PVM pVM, RTGCUINTPTR OldImageBase, RTGCUINTPTR NewImageBase, unsigned cbImage,
1081 const char *pszFilename, const char *pszName);
1082
1083/**
1084 * Adds a symbol to the debug info manager.
1085 *
1086 * @returns VBox status.
1087 * @param pVM VM Handle.
1088 * @param ModuleAddress Module address. Use 0 if no module.
1089 * @param SymbolAddress Symbol address
1090 * @param cbSymbol Size of the symbol. Use 0 if info not available.
1091 * @param pszSymbol Symbol name.
1092 */
1093DBGFR3DECL(int) DBGFR3SymbolAdd(PVM pVM, RTGCUINTPTR ModuleAddress, RTGCUINTPTR SymbolAddress, RTUINT cbSymbol, const char *pszSymbol);
1094
1095/**
1096 * Find symbol by address (nearest).
1097 *
1098 * @returns VBox status.
1099 * @param pVM VM handle.
1100 * @param Address Address.
1101 * @param poffDisplacement Where to store the symbol displacement from Address.
1102 * @param pSymbol Where to store the symbol info.
1103 */
1104DBGFR3DECL(int) DBGFR3SymbolByAddr(PVM pVM, RTGCUINTPTR Address, PRTGCINTPTR poffDisplacement, PDBGFSYMBOL pSymbol);
1105
1106/**
1107 * Find symbol by name (first).
1108 *
1109 * @returns VBox status.
1110 * @param pVM VM handle.
1111 * @param pszSymbol Symbol name.
1112 * @param pSymbol Where to store the symbol info.
1113 */
1114DBGFR3DECL(int) DBGFR3SymbolByName(PVM pVM, const char *pszSymbol, PDBGFSYMBOL pSymbol);
1115
1116/**
1117 * Find symbol by address (nearest), allocate return buffer.
1118 *
1119 * @returns Pointer to the symbol. Must be freed using DBGFR3SymbolFree().
1120 * @returns NULL if the symbol was not found or if we're out of memory.
1121 * @param pVM VM handle.
1122 * @param Address Address.
1123 * @param poffDisplacement Where to store the symbol displacement from Address.
1124 */
1125DBGFR3DECL(PDBGFSYMBOL) DBGFR3SymbolByAddrAlloc(PVM pVM, RTGCUINTPTR Address, PRTGCINTPTR poffDisplacement);
1126
1127/**
1128 * Find symbol by name (first), allocate return buffer.
1129 *
1130 * @returns Pointer to the symbol. Must be freed using DBGFR3SymbolFree().
1131 * @returns NULL if the symbol was not found or if we're out of memory.
1132 * @param pVM VM handle.
1133 * @param pszSymbol Symbol name.
1134 * @param ppSymbol Where to store the pointer to the symbol info.
1135 */
1136DBGFR3DECL(PDBGFSYMBOL) DBGFR3SymbolByNameAlloc(PVM pVM, const char *pszSymbol);
1137
1138/**
1139 * Frees a symbol returned by DBGFR3SymbolbyNameAlloc() or DBGFR3SymbolByAddressAlloc().
1140 *
1141 * @param pSymbol Pointer to the symbol.
1142 */
1143DBGFR3DECL(void) DBGFR3SymbolFree(PDBGFSYMBOL pSymbol);
1144
1145/**
1146 * Find line by address (nearest).
1147 *
1148 * @returns VBox status.
1149 * @param pVM VM handle.
1150 * @param Address Address.
1151 * @param poffDisplacement Where to store the line displacement from Address.
1152 * @param pLine Where to store the line info.
1153 */
1154DBGFR3DECL(int) DBGFR3LineByAddr(PVM pVM, RTGCUINTPTR Address, PRTGCINTPTR poffDisplacement, PDBGFLINE pLine);
1155
1156/**
1157 * Find line by address (nearest), allocate return buffer.
1158 *
1159 * @returns Pointer to the line. Must be freed using DBGFR3LineFree().
1160 * @returns NULL if the line was not found or if we're out of memory.
1161 * @param pVM VM handle.
1162 * @param Address Address.
1163 * @param poffDisplacement Where to store the line displacement from Address.
1164 */
1165DBGFR3DECL(PDBGFLINE) DBGFR3LineByAddrAlloc(PVM pVM, RTGCUINTPTR Address, PRTGCINTPTR poffDisplacement);
1166
1167/**
1168 * Frees a line returned by DBGFR3LineByAddressAlloc().
1169 *
1170 * @param pLine Pointer to the line.
1171 */
1172DBGFR3DECL(void) DBGFR3LineFree(PDBGFLINE pLine);
1173
1174/**
1175 * Return type.
1176 */
1177typedef enum DBGFRETRUNTYPE
1178{
1179 /** The usual invalid 0 value. */
1180 DBGFRETURNTYPE_INVALID = 0,
1181 /** Near 16-bit return. */
1182 DBGFRETURNTYPE_NEAR16,
1183 /** Near 32-bit return. */
1184 DBGFRETURNTYPE_NEAR32,
1185 /** Near 64-bit return. */
1186 DBGFRETURNTYPE_NEAR64,
1187 /** Far 16:16 return. */
1188 DBGFRETURNTYPE_FAR16,
1189 /** Far 16:32 return. */
1190 DBGFRETURNTYPE_FAR32,
1191 /** Far 16:64 return. */
1192 DBGFRETURNTYPE_FAR64,
1193 /** 16-bit iret return (e.g. real or 286 protect mode). */
1194 DBGFRETURNTYPE_IRET16,
1195 /** 32-bit iret return. */
1196 DBGFRETURNTYPE_IRET32,
1197 /** 32-bit iret return. */
1198 DBGFRETURNTYPE_IRET32_PRIV,
1199 /** 32-bit iret return to V86 mode. */
1200 DBGFRETURNTYPE_IRET32_V86,
1201 /** @todo 64-bit iret return. */
1202 DBGFRETURNTYPE_IRET64,
1203 /** The usual 32-bit blowup. */
1204 DBGFRETURNTYPE_32BIT_HACK = 0x7fffffff
1205} DBGFRETURNTYPE;
1206
1207
1208/**
1209 * Figures the size of the return state on the stack.
1210 *
1211 * @returns number of bytes. 0 if invalid parameter.
1212 * @param enmRetType The type of return.
1213 */
1214DECLINLINE(unsigned) DBGFReturnTypeSize(DBGFRETURNTYPE enmRetType)
1215{
1216 switch (enmRetType)
1217 {
1218 case DBGFRETURNTYPE_NEAR16: return 2;
1219 case DBGFRETURNTYPE_NEAR32: return 4;
1220 case DBGFRETURNTYPE_NEAR64: return 8;
1221 case DBGFRETURNTYPE_FAR16: return 4;
1222 case DBGFRETURNTYPE_FAR32: return 4;
1223 case DBGFRETURNTYPE_FAR64: return 8;
1224 case DBGFRETURNTYPE_IRET16: return 6;
1225 case DBGFRETURNTYPE_IRET32: return 4*3;
1226 case DBGFRETURNTYPE_IRET32_PRIV: return 4*5;
1227 case DBGFRETURNTYPE_IRET32_V86: return 4*9;
1228 case DBGFRETURNTYPE_IRET64:
1229 default:
1230 return 0;
1231 }
1232}
1233
1234
1235/** Pointer to stack frame info. */
1236typedef struct DBGFSTACKFRAME *PDBGFSTACKFRAME;
1237/**
1238 * Info about a stack frame.
1239 */
1240typedef struct DBGFSTACKFRAME
1241{
1242 /** Frame number. */
1243 RTUINT iFrame;
1244 /** Frame flags. */
1245 RTUINT fFlags;
1246 /** The frame address.
1247 * The off member is [e|r]bp and the Sel member is ss. */
1248 DBGFADDRESS AddrFrame;
1249 /** The stack address of the frame.
1250 * The off member is [e|r]sp and the Sel member is ss. */
1251 DBGFADDRESS AddrStack;
1252 /** The program counter (PC) address of the frame.
1253 * The off member is [e|r]ip and the Sel member is cs. */
1254 DBGFADDRESS AddrPC;
1255 /** Pointer to the symbol nearest the program counter (PC). NULL if not found. */
1256 PDBGFSYMBOL pSymPC;
1257 /** Pointer to the linnumber nearest the program counter (PC). NULL if not found. */
1258 PDBGFLINE pLinePC;
1259
1260 /** The return frame address.
1261 * The off member is [e|r]bp and the Sel member is ss. */
1262 DBGFADDRESS AddrReturnFrame;
1263 /** The return stack address.
1264 * The off member is [e|r]sp and the Sel member is ss. */
1265 DBGFADDRESS AddrReturnStack;
1266 /** The way this frame returns to the next one. */
1267 DBGFRETURNTYPE enmReturnType;
1268
1269 /** The program counter (PC) address which the frame returns to.
1270 * The off member is [e|r]ip and the Sel member is cs. */
1271 DBGFADDRESS AddrReturnPC;
1272 /** Pointer to the symbol nearest the return PC. NULL if not found. */
1273 PDBGFSYMBOL pSymReturnPC;
1274 /** Pointer to the linnumber nearest the return PC. NULL if not found. */
1275 PDBGFLINE pLineReturnPC;
1276
1277 /** 32-bytes of stack arguments. */
1278 union
1279 {
1280 /** 64-bit view */
1281 uint64_t au64[4];
1282 /** 32-bit view */
1283 uint32_t au32[8];
1284 /** 16-bit view */
1285 uint16_t au16[16];
1286 /** 8-bit view */
1287 uint8_t au8[32];
1288 } Args;
1289
1290 /** Pointer to the next frame.
1291 * Might not be used in some cases, so consider it internal. */
1292 PDBGFSTACKFRAME pNext;
1293 /** Pointer to the first frame.
1294 * Might not be used in some cases, so consider it internal. */
1295 PDBGFSTACKFRAME pFirst;
1296} DBGFSTACKFRAME;
1297
1298/** @name DBGFSTACKFRAME Flags.
1299 * @{ */
1300/** Set if the content of the frame is filled in by DBGFR3StackWalk() and can be used
1301 * to construct the next frame. */
1302#define DBGFSTACKFRAME_FLAGS_ALL_VALID BIT(0)
1303/** This is the last stack frame we can read.
1304 * This flag is not set if the walk stop because of max dept or recursion. */
1305#define DBGFSTACKFRAME_FLAGS_LAST BIT(1)
1306/** This is the last record because we detected a loop. */
1307#define DBGFSTACKFRAME_FLAGS_LOOP BIT(2)
1308/** This is the last record because we reached the maximum depth. */
1309#define DBGFSTACKFRAME_FLAGS_MAX_DEPTH BIT(3)
1310/** @} */
1311
1312/**
1313 * Begins a stack walk.
1314 * This will construct and obtain the first frame.
1315 *
1316 * @returns VINF_SUCCESS on success.
1317 * @returns VERR_NO_MEMORY if we're out of memory.
1318 * @param pVM The VM handle.
1319 * @param pFrame The stack frame info structure.
1320 * On input this structure must be memset to zero.
1321 * If wanted, the AddrPC, AddrStack and AddrFrame fields may be set
1322 * to valid addresses after memsetting it. Any of those fields not set
1323 * will be fetched from the guest CPU state.
1324 * On output the structure will contain all the information we were able to
1325 * obtain about the stack frame.
1326 */
1327DBGFR3DECL(int) DBGFR3StackWalkBeginGuest(PVM pVM, PDBGFSTACKFRAME pFrame);
1328
1329/**
1330 * Begins a stack walk.
1331 * This will construct and obtain the first frame.
1332 *
1333 * @returns VINF_SUCCESS on success.
1334 * @returns VERR_NO_MEMORY if we're out of memory.
1335 * @param pVM The VM handle.
1336 * @param pFrame The stack frame info structure.
1337 * On input this structure must be memset to zero.
1338 * If wanted, the AddrPC, AddrStack and AddrFrame fields may be set
1339 * to valid addresses after memsetting it. Any of those fields not set
1340 * will be fetched from the hypervisor CPU state.
1341 * On output the structure will contain all the information we were able to
1342 * obtain about the stack frame.
1343 */
1344DBGFR3DECL(int) DBGFR3StackWalkBeginHyper(PVM pVM, PDBGFSTACKFRAME pFrame);
1345
1346/**
1347 * Gets the next stack frame.
1348 *
1349 * @returns VINF_SUCCESS
1350 * @returns VERR_NO_MORE_FILES if not more stack frames.
1351 * @param pVM The VM handle.
1352 * @param pFrame Pointer to the current frame on input, content is replaced with the next frame on successful return.
1353 */
1354DBGFR3DECL(int) DBGFR3StackWalkNext(PVM pVM, PDBGFSTACKFRAME pFrame);
1355
1356/**
1357 * Ends a stack walk process.
1358 *
1359 * This *must* be called after a successful first call to any of the stack
1360 * walker functions. If not called we will leak memory or other resources.
1361 *
1362 * @param pVM The VM handle.
1363 * @param pFrame The stackframe as returned by the last stack walk call.
1364 */
1365DBGFR3DECL(void) DBGFR3StackWalkEnd(PVM pVM, PDBGFSTACKFRAME pFrame);
1366
1367
1368
1369
1370/** Flags to pass to DBGFR3DisasInstrEx().
1371 * @{ */
1372/** Disassemble the current guest instruction, with annotations. */
1373#define DBGF_DISAS_FLAGS_CURRENT_GUEST BIT(0)
1374/** Disassemble the current hypervisor instruction, with annotations. */
1375#define DBGF_DISAS_FLAGS_CURRENT_HYPER BIT(1)
1376/** No annotations for current context. */
1377#define DBGF_DISAS_FLAGS_NO_ANNOTATION BIT(2)
1378/** No symbol lookup. */
1379#define DBGF_DISAS_FLAGS_NO_SYMBOLS BIT(3)
1380/** No instruction bytes. */
1381#define DBGF_DISAS_FLAGS_NO_BYTES BIT(4)
1382/** No address in the output. */
1383#define DBGF_DISAS_FLAGS_NO_ADDRESS BIT(5)
1384/** @} */
1385
1386/** Special flat selector. */
1387#define DBGF_SEL_FLAT 1
1388
1389/**
1390 * Disassembles the one instruction according to the specified flags and address.
1391 *
1392 * @returns VBox status code.
1393 * @param pVM VM handle.
1394 * @param Sel The code selector. This used to determin the 32/16 bit ness and
1395 * calculation of the actual instruction address.
1396 * Use DBGF_SEL_FLAT for specifying a flat address.
1397 * @param GCPtr The code address relative to the base of Sel.
1398 * @param fFlags Flags controlling where to start and how to format.
1399 * A combination of the DBGF_DISAS_FLAGS_* #defines.
1400 * @param pszOutput Output buffer.
1401 * @param cchOutput Size of the output buffer.
1402 * @param pcbInstr Where to return the size of the instruction.
1403 */
1404DBGFR3DECL(int) DBGFR3DisasInstrEx(PVM pVM, RTSEL Sel, RTGCPTR GCPtr, unsigned fFlags, char *pszOutput, uint32_t cchOutput, uint32_t *pcbInstr);
1405
1406/**
1407 * Disassembles the current instruction.
1408 * Addresses will be tried resolved to symbols
1409 *
1410 * @returns VBox status code.
1411 * @param pVM VM handle.
1412 * @param Sel The code selector. This used to determin the 32/16 bit ness and
1413 * calculation of the actual instruction address.
1414 * Use DBGF_SEL_FLAT for specifying a flat address.
1415 * @param GCPtr The code address relative to the base of Sel.
1416 * @param pszOutput Output buffer.
1417 * @param cbOutput Size of the output buffer.
1418 */
1419DBGFR3DECL(int) DBGFR3DisasInstr(PVM pVM, RTSEL Sel, RTGCPTR GCPtr, char *pszOutput, uint32_t cbOutput);
1420
1421/**
1422 * Disassembles the current instruction.
1423 * All registers and data will be displayed. Addresses will be attempted resolved to symbols
1424 *
1425 * @returns VBox status code.
1426 * @param pVM VM handle.
1427 * @param pszOutput Output buffer.
1428 * @param cbOutput Size of the output buffer.
1429 */
1430DBGFR3DECL(int) DBGFR3DisasInstrCurrent(PVM pVM, char *pszOutput, uint32_t cbOutput);
1431
1432/**
1433 * Disassembles the current guest context instruction and writes it to the log.
1434 * All registers and data will be displayed. Addresses will be attempted resolved to symbols.
1435 *
1436 * @returns VBox status code.
1437 * @param pVM VM handle.
1438 * @param pszPrefix Short prefix string to the dissassembly string. (optional)
1439 */
1440DBGFR3DECL(int) DBGFR3DisasInstrCurrentLogInternal(PVM pVM, const char *pszPrefix);
1441
1442/** @def DBGFR3DisasInstrCurrentLog
1443 * Disassembles the current guest context instruction and writes it to the log.
1444 * All registers and data will be displayed. Addresses will be attempted resolved to symbols.
1445 */
1446#ifdef LOG_ENABLED
1447# define DBGFR3DisasInstrCurrentLog(pVM, pszPrefix) \
1448 do { \
1449 if (LogIsEnabled()) \
1450 DBGFR3DisasInstrCurrentLogInternal(pVM, pszPrefix); \
1451 } while (0)
1452#else
1453# define DBGFR3DisasInstrCurrentLog(pVM, pszPrefix) do { } while (0)
1454#endif
1455
1456/**
1457 * Disassembles the specified guest context instruction and writes it to the log.
1458 * Addresses will be attempted resolved to symbols.
1459 *
1460 * @returns VBox status code.
1461 * @param pVM VM handle.
1462 * @param Sel The code selector. This used to determin the 32/16 bit-ness and
1463 * calculation of the actual instruction address.
1464 * @param GCPtr The code address relative to the base of Sel.
1465 */
1466DBGFR3DECL(int) DBGFR3DisasInstrLogInternal(PVM pVM, RTSEL Sel, RTGCPTR GCPtr);
1467
1468/** @def DBGFR3DisasInstrLog
1469 * Disassembles the specified guest context instruction and writes it to the log.
1470 * Addresses will be attempted resolved to symbols.
1471 */
1472#ifdef LOG_ENABLED
1473# define DBGFR3DisasInstrLog(pVM, Sel, GCPtr) \
1474 do { \
1475 if (LogIsEnabled()) \
1476 DBGFR3DisasInstrLogInternal(pVM, Sel, GCPtr); \
1477 } while (0)
1478#else
1479# define DBGFR3DisasInstrLog(pVM, Sel, GCPtr) do { } while (0)
1480#endif
1481
1482/** @} */
1483
1484__END_DECLS
1485
1486#endif
Note: See TracBrowser for help on using the repository browser.

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