VirtualBox

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

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

The Big Sun Rebranding Header Change

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