VirtualBox

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

Last change on this file since 34079 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

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