1 | /* $Id: DBGFR0.cpp 12663 2008-09-23 10:16:45Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DBGF - Debugger Facility, R0 part.
|
---|
4 | *
|
---|
5 | * Almost identical to DBGFGC.cpp, except for the fInHyper stuff.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | *
|
---|
19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
20 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
21 | * additional information or have any questions.
|
---|
22 | */
|
---|
23 |
|
---|
24 |
|
---|
25 | /*******************************************************************************
|
---|
26 | * Header Files *
|
---|
27 | *******************************************************************************/
|
---|
28 | #include <VBox/dbgf.h>
|
---|
29 | #include <VBox/selm.h>
|
---|
30 | #include <VBox/log.h>
|
---|
31 | #include "DBGFInternal.h"
|
---|
32 | #include <VBox/vm.h>
|
---|
33 | #include <VBox/err.h>
|
---|
34 | #include <iprt/assert.h>
|
---|
35 |
|
---|
36 |
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * \#DB (Debug event) handler.
|
---|
40 | *
|
---|
41 | * @returns VBox status code.
|
---|
42 | * VINF_SUCCESS means we completely handled this trap,
|
---|
43 | * other codes are passed execution to host context.
|
---|
44 | *
|
---|
45 | * @param pVM The VM handle.
|
---|
46 | * @param pRegFrame Pointer to the register frame for the trap.
|
---|
47 | * @param uDr6 The DR6 register value.
|
---|
48 | */
|
---|
49 | DBGFR0DECL(int) DBGFR0Trap01Handler(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCUINTREG uDr6)
|
---|
50 | {
|
---|
51 | /** @todo Intel docs say that X86_DR6_BS has the highest priority... */
|
---|
52 | /*
|
---|
53 | * A breakpoint?
|
---|
54 | */
|
---|
55 | if (uDr6 & (X86_DR6_B0 | X86_DR6_B1 | X86_DR6_B2 | X86_DR6_B3))
|
---|
56 | {
|
---|
57 | Assert(X86_DR6_B0 == 1 && X86_DR6_B1 == 2 && X86_DR6_B2 == 4 && X86_DR6_B3 == 8);
|
---|
58 | for (unsigned iBp = 0; iBp < RT_ELEMENTS(pVM->dbgf.s.aHwBreakpoints); iBp++)
|
---|
59 | {
|
---|
60 | if ( (uDr6 & RT_BIT(iBp))
|
---|
61 | && pVM->dbgf.s.aHwBreakpoints[iBp].enmType == DBGFBPTYPE_REG)
|
---|
62 | {
|
---|
63 | pVM->dbgf.s.iActiveBp = pVM->dbgf.s.aHwBreakpoints[iBp].iBp;
|
---|
64 | pVM->dbgf.s.fSingleSteppingRaw = false;
|
---|
65 | LogFlow(("DBGFR0Trap03Handler: hit hw breakpoint %d at %04x:%08x\n",
|
---|
66 | pVM->dbgf.s.aHwBreakpoints[iBp].iBp, pRegFrame->cs, pRegFrame->eip));
|
---|
67 |
|
---|
68 | return VINF_EM_DBG_BREAKPOINT;
|
---|
69 | }
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | /*
|
---|
74 | * Single step?
|
---|
75 | * Are we single stepping or is it the guest?
|
---|
76 | */
|
---|
77 | if ( (uDr6 & X86_DR6_BS)
|
---|
78 | && (pVM->dbgf.s.fSingleSteppingRaw))
|
---|
79 | {
|
---|
80 | pVM->dbgf.s.fSingleSteppingRaw = false;
|
---|
81 | LogFlow(("DBGFR0Trap01Handler: single step at %04x:%08x\n", pRegFrame->cs, pRegFrame->eip));
|
---|
82 | return VINF_EM_DBG_STEPPED;
|
---|
83 | }
|
---|
84 |
|
---|
85 | /*
|
---|
86 | * Currently we only implement single stepping in the guest,
|
---|
87 | * so we'll bitch if this is not a BS event.
|
---|
88 | */
|
---|
89 | AssertMsg(uDr6 & X86_DR6_BS, ("hey! we're not doing guest BPs yet! dr6=%RTreg %04x:%08\n",
|
---|
90 | uDr6, pRegFrame->cs, pRegFrame->eip));
|
---|
91 | /** @todo virtualize DRx. */
|
---|
92 | LogFlow(("DBGFR0Trap01Handler: guest debug event %RTreg at %04x:%08x!\n", uDr6, pRegFrame->cs, pRegFrame->eip));
|
---|
93 | return VINF_EM_RAW_GUEST_TRAP;
|
---|
94 | }
|
---|
95 |
|
---|
96 |
|
---|
97 | /**
|
---|
98 | * \#BP (Breakpoint) handler.
|
---|
99 | *
|
---|
100 | * @returns VBox status code.
|
---|
101 | * VINF_SUCCESS means we completely handled this trap,
|
---|
102 | * other codes are passed execution to host context.
|
---|
103 | *
|
---|
104 | * @param pVM The VM handle.
|
---|
105 | * @param pRegFrame Pointer to the register frame for the trap.
|
---|
106 | */
|
---|
107 | DBGFR0DECL(int) DBGFR0Trap03Handler(PVM pVM, PCPUMCTXCORE pRegFrame)
|
---|
108 | {
|
---|
109 | /*
|
---|
110 | * Get the trap address and look it up in the breakpoint table.
|
---|
111 | * Don't bother if we don't have any breakpoints.
|
---|
112 | */
|
---|
113 | if (pVM->dbgf.s.cBreakpoints > 0)
|
---|
114 | {
|
---|
115 | RTGCPTR pPc;
|
---|
116 | int rc = SELMValidateAndConvertCSAddr(pVM, pRegFrame->eflags, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid,
|
---|
117 | (RTGCPTR)((RTGCUINTPTR)pRegFrame->eip - 1),
|
---|
118 | &pPc);
|
---|
119 | AssertRCReturn(rc, rc);
|
---|
120 |
|
---|
121 | for (unsigned iBp = 0; iBp < RT_ELEMENTS(pVM->dbgf.s.aBreakpoints); iBp++)
|
---|
122 | {
|
---|
123 | if ( pVM->dbgf.s.aBreakpoints[iBp].GCPtr == (RTGCUINTPTR)pPc
|
---|
124 | && pVM->dbgf.s.aBreakpoints[iBp].enmType == DBGFBPTYPE_INT3)
|
---|
125 | {
|
---|
126 | pVM->dbgf.s.aBreakpoints[iBp].cHits++;
|
---|
127 | pVM->dbgf.s.iActiveBp = pVM->dbgf.s.aBreakpoints[iBp].iBp;
|
---|
128 |
|
---|
129 | LogFlow(("DBGFR0Trap03Handler: hit breakpoint %d at %RGv (%04x:%08x) cHits=0x%RX64\n",
|
---|
130 | pVM->dbgf.s.aBreakpoints[iBp].iBp, pPc, pRegFrame->cs, pRegFrame->eip,
|
---|
131 | pVM->dbgf.s.aBreakpoints[iBp].cHits));
|
---|
132 | return VINF_EM_DBG_BREAKPOINT;
|
---|
133 | }
|
---|
134 | }
|
---|
135 | }
|
---|
136 |
|
---|
137 | return VINF_EM_RAW_GUEST_TRAP;
|
---|
138 | }
|
---|
139 |
|
---|