1 | /* $Id: DBGFGC.cpp 3776 2007-07-23 09:16:56Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DBGF - Debugger Facility, GC part.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License as published by the Free Software Foundation,
|
---|
13 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
14 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
15 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * If you received this file as part of a commercial VirtualBox
|
---|
18 | * distribution, then only the terms of your commercial VirtualBox
|
---|
19 | * license agreement apply instead of the previous paragraph.
|
---|
20 | */
|
---|
21 |
|
---|
22 |
|
---|
23 | /*******************************************************************************
|
---|
24 | * Header Files *
|
---|
25 | *******************************************************************************/
|
---|
26 | #include <VBox/dbgf.h>
|
---|
27 | #include <VBox/selm.h>
|
---|
28 | #include <VBox/log.h>
|
---|
29 | #include "DBGFInternal.h"
|
---|
30 | #include <VBox/vm.h>
|
---|
31 | #include <VBox/err.h>
|
---|
32 | #include <iprt/assert.h>
|
---|
33 |
|
---|
34 |
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * \#DB (Debug event) handler.
|
---|
38 | *
|
---|
39 | * @returns VBox status code.
|
---|
40 | * VINF_SUCCESS means we completely handled this trap,
|
---|
41 | * other codes are passed execution to host context.
|
---|
42 | *
|
---|
43 | * @param pVM The VM handle.
|
---|
44 | * @param pRegFrame Pointer to the register frame for the trap.
|
---|
45 | * @param uDr6 The DR6 register value.
|
---|
46 | */
|
---|
47 | DBGFGCDECL(int) DBGFGCTrap01Handler(PVM pVM, PCPUMCTXCORE pRegFrame, RTUINTREG uDr6)
|
---|
48 | {
|
---|
49 | const bool fInHyper = !(pRegFrame->ss & X86_SEL_RPL) && !pRegFrame->eflags.Bits.u1VM;
|
---|
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 < ELEMENTS(pVM->dbgf.s.aHwBreakpoints); iBp++)
|
---|
59 | {
|
---|
60 | if ( (uDr6 & 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(("DBGFGCTrap03Handler: hit hw breakpoint %d at %04x:%08x\n",
|
---|
66 | pVM->dbgf.s.aHwBreakpoints[iBp].iBp, pRegFrame->cs, pRegFrame->eip));
|
---|
67 |
|
---|
68 | return fInHyper ? VINF_EM_DBG_HYPER_BREAKPOINT : 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 | && (fInHyper || pVM->dbgf.s.fSingleSteppingRaw))
|
---|
79 | {
|
---|
80 | pVM->dbgf.s.fSingleSteppingRaw = false;
|
---|
81 | LogFlow(("DBGFGCTrap01Handler: single step at %04x:%08x\n", pRegFrame->cs, pRegFrame->eip));
|
---|
82 | return fInHyper ? VINF_EM_DBG_HYPER_STEPPED : 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(("DBGFGCTrap01Handler: guest debug event %RTreg at %04x:%08x!\n", uDr6, pRegFrame->cs, pRegFrame->eip));
|
---|
93 | return fInHyper ? VERR_INTERNAL_ERROR : 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 | DBGFGCDECL(int) DBGFGCTrap03Handler(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 < 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(("DBGFGCTrap03Handler: 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 !(pRegFrame->ss & X86_SEL_RPL) && !pRegFrame->eflags.Bits.u1VM
|
---|
133 | ? VINF_EM_DBG_HYPER_BREAKPOINT
|
---|
134 | : VINF_EM_DBG_BREAKPOINT;
|
---|
135 | }
|
---|
136 | }
|
---|
137 | }
|
---|
138 |
|
---|
139 | return !(pRegFrame->ss & X86_SEL_RPL) && !pRegFrame->eflags.Bits.u1VM
|
---|
140 | ? VINF_EM_DBG_HYPER_ASSERTION
|
---|
141 | : VINF_EM_RAW_GUEST_TRAP;
|
---|
142 | }
|
---|
143 |
|
---|