VirtualBox

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

Last change on this file since 3810 was 3810, checked in by vboxsync, 17 years ago

Put back log.h as it's required for the correct LOG_ENABLE define.

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