VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMRZ/DBGFRZ.cpp@ 22890

Last change on this file since 22890 was 19288, checked in by vboxsync, 15 years ago

DBGF,TRPM,HWACCM: Merged DBGFR0.cpp and DBGFGC.cpp into VMMRZ/DBGFRZ.cpp (new directory for things that are common to both R0 and RC).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.7 KB
Line 
1/* $Id: DBGFRZ.cpp 19288 2009-05-01 13:09:18Z vboxsync $ */
2/** @file
3 * DBGF - Debugger Facility, RZ part.
4 */
5
6/*
7 * Copyright (C) 2006-2009 Sun Microsystems, Inc.
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 (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#define LOG_GROUP LOG_GROUP_DBGF
27#include <VBox/dbgf.h>
28#include <VBox/selm.h>
29#include <VBox/log.h>
30#include "DBGFInternal.h"
31#include <VBox/vm.h>
32#include <VBox/err.h>
33#include <iprt/assert.h>
34
35
36
37/**
38 * \#DB (Debug event) handler.
39 *
40 * @returns VBox status code.
41 * VINF_SUCCESS means we completely handled this trap,
42 * other codes are passed execution to host context.
43 *
44 * @param pVM The VM handle.
45 * @param pVCpu The virtual CPU handle.
46 * @param pRegFrame Pointer to the register frame for the trap.
47 * @param uDr6 The DR6 register value.
48 */
49VMMRZDECL(int) DBGFRZTrap01Handler(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, RTGCUINTREG uDr6)
50{
51#ifdef IN_RC
52 const bool fInHyper = !(pRegFrame->ss & X86_SEL_RPL) && !pRegFrame->eflags.Bits.u1VM;
53#else
54 const bool fInHyper = false;
55#endif
56
57 /** @todo Intel docs say that X86_DR6_BS has the highest priority... */
58 /*
59 * A breakpoint?
60 */
61 if (uDr6 & (X86_DR6_B0 | X86_DR6_B1 | X86_DR6_B2 | X86_DR6_B3))
62 {
63 Assert(X86_DR6_B0 == 1 && X86_DR6_B1 == 2 && X86_DR6_B2 == 4 && X86_DR6_B3 == 8);
64 for (unsigned iBp = 0; iBp < RT_ELEMENTS(pVM->dbgf.s.aHwBreakpoints); iBp++)
65 {
66 if ( ((uint32_t)uDr6 & RT_BIT_32(iBp))
67 && pVM->dbgf.s.aHwBreakpoints[iBp].enmType == DBGFBPTYPE_REG)
68 {
69 pVCpu->dbgf.s.iActiveBp = pVM->dbgf.s.aHwBreakpoints[iBp].iBp;
70 pVCpu->dbgf.s.fSingleSteppingRaw = false;
71 LogFlow(("DBGFRZTrap03Handler: hit hw breakpoint %d at %04x:%RGv\n",
72 pVM->dbgf.s.aHwBreakpoints[iBp].iBp, pRegFrame->cs, pRegFrame->rip));
73
74 return fInHyper ? VINF_EM_DBG_HYPER_BREAKPOINT : VINF_EM_DBG_BREAKPOINT;
75 }
76 }
77 }
78
79 /*
80 * Single step?
81 * Are we single stepping or is it the guest?
82 */
83 if ( (uDr6 & X86_DR6_BS)
84 && (fInHyper || pVCpu->dbgf.s.fSingleSteppingRaw))
85 {
86 pVCpu->dbgf.s.fSingleSteppingRaw = false;
87 LogFlow(("DBGFRZTrap01Handler: single step at %04x:%RGv\n", pRegFrame->cs, pRegFrame->rip));
88 return fInHyper ? VINF_EM_DBG_HYPER_STEPPED : VINF_EM_DBG_STEPPED;
89 }
90
91 /*
92 * Currently we only implement single stepping in the guest,
93 * so we'll bitch if this is not a BS event.
94 */
95 AssertMsg(uDr6 & X86_DR6_BS, ("hey! we're not doing guest BPs yet! dr6=%RTreg %04x:%RGv\n",
96 uDr6, pRegFrame->cs, pRegFrame->rip));
97
98 LogFlow(("DBGFRZTrap01Handler: guest debug event %RTreg at %04x:%RGv!\n", uDr6, pRegFrame->cs, pRegFrame->rip));
99 return fInHyper ? VERR_INTERNAL_ERROR : VINF_EM_RAW_GUEST_TRAP;
100}
101
102
103/**
104 * \#BP (Breakpoint) handler.
105 *
106 * @returns VBox status code.
107 * VINF_SUCCESS means we completely handled this trap,
108 * other codes are passed execution to host context.
109 *
110 * @param pVM The VM handle.
111 * @param pVCpu The virtual CPU handle.
112 * @param pRegFrame Pointer to the register frame for the trap.
113 */
114VMMRZDECL(int) DBGFRZTrap03Handler(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame)
115{
116#ifdef IN_RC
117 const bool fInHyper = !(pRegFrame->ss & X86_SEL_RPL) && !pRegFrame->eflags.Bits.u1VM;
118#else
119 const bool fInHyper = false;
120#endif
121
122 /*
123 * Get the trap address and look it up in the breakpoint table.
124 * Don't bother if we don't have any breakpoints.
125 */
126 if (pVM->dbgf.s.cBreakpoints > 0)
127 {
128 RTGCPTR pPc;
129 int rc = SELMValidateAndConvertCSAddr(pVM, pRegFrame->eflags, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid,
130#ifdef IN_RC
131 (RTGCPTR)((RTGCUINTPTR)pRegFrame->eip - 1),
132#else
133 (RTGCPTR)pRegFrame->rip /* no -1 in R0 */,
134#endif
135 &pPc);
136 AssertRCReturn(rc, rc);
137
138 for (unsigned iBp = 0; iBp < RT_ELEMENTS(pVM->dbgf.s.aBreakpoints); iBp++)
139 {
140 if ( pVM->dbgf.s.aBreakpoints[iBp].GCPtr == (RTGCUINTPTR)pPc
141 && pVM->dbgf.s.aBreakpoints[iBp].enmType == DBGFBPTYPE_INT3)
142 {
143 pVM->dbgf.s.aBreakpoints[iBp].cHits++;
144 pVCpu->dbgf.s.iActiveBp = pVM->dbgf.s.aBreakpoints[iBp].iBp;
145
146 LogFlow(("DBGFRZTrap03Handler: hit breakpoint %d at %RGv (%04x:%RGv) cHits=0x%RX64\n",
147 pVM->dbgf.s.aBreakpoints[iBp].iBp, pPc, pRegFrame->cs, pRegFrame->rip,
148 pVM->dbgf.s.aBreakpoints[iBp].cHits));
149 return fInHyper
150 ? VINF_EM_DBG_HYPER_BREAKPOINT
151 : VINF_EM_DBG_BREAKPOINT;
152 }
153 }
154 }
155
156 return fInHyper
157 ? VINF_EM_DBG_HYPER_ASSERTION
158 : VINF_EM_RAW_GUEST_TRAP;
159}
160
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