VirtualBox

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

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

Implemented some search commands in the debugger.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use