1 | /* $Id: DBGFR0.cpp 4071 2007-08-07 17:07:59Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DBGF - Debugger Facility, R0 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 |
|
---|
18 |
|
---|
19 | /*******************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *******************************************************************************/
|
---|
22 | #include <VBox/dbgf.h>
|
---|
23 | #include <VBox/selm.h>
|
---|
24 | #include <VBox/log.h>
|
---|
25 | #include "DBGFInternal.h"
|
---|
26 | #include <VBox/vm.h>
|
---|
27 | #include <VBox/err.h>
|
---|
28 | #include <iprt/assert.h>
|
---|
29 |
|
---|
30 |
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * \#DB (Debug event) handler.
|
---|
34 | *
|
---|
35 | * @returns VBox status code.
|
---|
36 | * VINF_SUCCESS means we completely handled this trap,
|
---|
37 | * other codes are passed execution to host context.
|
---|
38 | *
|
---|
39 | * @param pVM The VM handle.
|
---|
40 | * @param pRegFrame Pointer to the register frame for the trap.
|
---|
41 | * @param uDr6 The DR6 register value.
|
---|
42 | */
|
---|
43 | DBGFR0DECL(int) DBGFR0Trap01Handler(PVM pVM, PCPUMCTXCORE pRegFrame, RTUINTREG uDr6)
|
---|
44 | {
|
---|
45 | /** @todo Intel docs say that X86_DR6_BS has the highest priority... */
|
---|
46 | /*
|
---|
47 | * A breakpoint?
|
---|
48 | */
|
---|
49 | if (uDr6 & (X86_DR6_B0 | X86_DR6_B1 | X86_DR6_B2 | X86_DR6_B3))
|
---|
50 | {
|
---|
51 | Assert(X86_DR6_B0 == 1 && X86_DR6_B1 == 2 && X86_DR6_B2 == 4 && X86_DR6_B3 == 8);
|
---|
52 | for (unsigned iBp = 0; iBp < ELEMENTS(pVM->dbgf.s.aHwBreakpoints); iBp++)
|
---|
53 | {
|
---|
54 | if ( (uDr6 & BIT(iBp))
|
---|
55 | && pVM->dbgf.s.aHwBreakpoints[iBp].enmType == DBGFBPTYPE_REG)
|
---|
56 | {
|
---|
57 | pVM->dbgf.s.iActiveBp = pVM->dbgf.s.aHwBreakpoints[iBp].iBp;
|
---|
58 | pVM->dbgf.s.fSingleSteppingRaw = false;
|
---|
59 | LogFlow(("DBGFR0Trap03Handler: hit hw breakpoint %d at %04x:%08x\n",
|
---|
60 | pVM->dbgf.s.aHwBreakpoints[iBp].iBp, pRegFrame->cs, pRegFrame->eip));
|
---|
61 |
|
---|
62 | return VINF_EM_DBG_BREAKPOINT;
|
---|
63 | }
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | /*
|
---|
68 | * Single step?
|
---|
69 | * Are we single stepping or is it the guest?
|
---|
70 | */
|
---|
71 | if ( (uDr6 & X86_DR6_BS)
|
---|
72 | && (pVM->dbgf.s.fSingleSteppingRaw))
|
---|
73 | {
|
---|
74 | pVM->dbgf.s.fSingleSteppingRaw = false;
|
---|
75 | LogFlow(("DBGFR0Trap01Handler: single step at %04x:%08x\n", pRegFrame->cs, pRegFrame->eip));
|
---|
76 | return VINF_EM_DBG_STEPPED;
|
---|
77 | }
|
---|
78 |
|
---|
79 | /*
|
---|
80 | * Currently we only implement single stepping in the guest,
|
---|
81 | * so we'll bitch if this is not a BS event.
|
---|
82 | */
|
---|
83 | AssertMsg(uDr6 & X86_DR6_BS, ("hey! we're not doing guest BPs yet! dr6=%RTreg %04x:%08\n",
|
---|
84 | uDr6, pRegFrame->cs, pRegFrame->eip));
|
---|
85 | /** @todo virtualize DRx. */
|
---|
86 | LogFlow(("DBGFR0Trap01Handler: guest debug event %RTreg at %04x:%08x!\n", uDr6, pRegFrame->cs, pRegFrame->eip));
|
---|
87 | return VINF_EM_RAW_GUEST_TRAP;
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * \#BP (Breakpoint) handler.
|
---|
93 | *
|
---|
94 | * @returns VBox status code.
|
---|
95 | * VINF_SUCCESS means we completely handled this trap,
|
---|
96 | * other codes are passed execution to host context.
|
---|
97 | *
|
---|
98 | * @param pVM The VM handle.
|
---|
99 | * @param pRegFrame Pointer to the register frame for the trap.
|
---|
100 | */
|
---|
101 | DBGFR0DECL(int) DBGFR0Trap03Handler(PVM pVM, PCPUMCTXCORE pRegFrame)
|
---|
102 | {
|
---|
103 | /*
|
---|
104 | * Get the trap address and look it up in the breakpoint table.
|
---|
105 | * Don't bother if we don't have any breakpoints.
|
---|
106 | */
|
---|
107 | if (pVM->dbgf.s.cBreakpoints > 0)
|
---|
108 | {
|
---|
109 | RTGCPTR pPc;
|
---|
110 | int rc = SELMValidateAndConvertCSAddr(pVM, pRegFrame->eflags, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid,
|
---|
111 | (RTGCPTR)((RTGCUINTPTR)pRegFrame->eip - 1),
|
---|
112 | &pPc);
|
---|
113 | AssertRCReturn(rc, rc);
|
---|
114 |
|
---|
115 | for (unsigned iBp = 0; iBp < ELEMENTS(pVM->dbgf.s.aBreakpoints); iBp++)
|
---|
116 | {
|
---|
117 | if ( pVM->dbgf.s.aBreakpoints[iBp].GCPtr == (RTGCUINTPTR)pPc
|
---|
118 | && pVM->dbgf.s.aBreakpoints[iBp].enmType == DBGFBPTYPE_INT3)
|
---|
119 | {
|
---|
120 | pVM->dbgf.s.aBreakpoints[iBp].cHits++;
|
---|
121 | pVM->dbgf.s.iActiveBp = pVM->dbgf.s.aBreakpoints[iBp].iBp;
|
---|
122 |
|
---|
123 | LogFlow(("DBGFR0Trap03Handler: hit breakpoint %d at %RGv (%04x:%08x) cHits=0x%RX64\n",
|
---|
124 | pVM->dbgf.s.aBreakpoints[iBp].iBp, pPc, pRegFrame->cs, pRegFrame->eip,
|
---|
125 | pVM->dbgf.s.aBreakpoints[iBp].cHits));
|
---|
126 | return VINF_EM_DBG_BREAKPOINT;
|
---|
127 | }
|
---|
128 | }
|
---|
129 | }
|
---|
130 |
|
---|
131 | return VINF_EM_RAW_GUEST_TRAP;
|
---|
132 | }
|
---|
133 |
|
---|