VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMGC/DBGFGC.cpp@ 15203

Last change on this file since 15203 was 14864, checked in by vboxsync, 16 years ago

invalid format type

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.5 KB
Line 
1/* $Id: DBGFGC.cpp 14864 2008-12-01 14:39:11Z vboxsync $ */
2/** @file
3 * DBGF - Debugger Facility, GC part.
4 *
5 * Almost identical to DBGFR0.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#define LOG_GROUP LOG_GROUP_DBGF
29#include <VBox/dbgf.h>
30#include <VBox/selm.h>
31#include <VBox/log.h>
32#include "DBGFInternal.h"
33#include <VBox/vm.h>
34#include <VBox/err.h>
35#include <iprt/assert.h>
36
37
38
39/**
40 * \#DB (Debug event) handler.
41 *
42 * @returns VBox status code.
43 * VINF_SUCCESS means we completely handled this trap,
44 * other codes are passed execution to host context.
45 *
46 * @param pVM The VM handle.
47 * @param pRegFrame Pointer to the register frame for the trap.
48 * @param uDr6 The DR6 register value.
49 */
50VMMRCDECL(int) DBGFGCTrap01Handler(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCUINTREG uDr6)
51{
52 const bool fInHyper = !(pRegFrame->ss & X86_SEL_RPL) && !pRegFrame->eflags.Bits.u1VM;
53
54 /** @todo Intel docs say that X86_DR6_BS has the highest priority... */
55 /*
56 * A breakpoint?
57 */
58 if (uDr6 & (X86_DR6_B0 | X86_DR6_B1 | X86_DR6_B2 | X86_DR6_B3))
59 {
60 Assert(X86_DR6_B0 == 1 && X86_DR6_B1 == 2 && X86_DR6_B2 == 4 && X86_DR6_B3 == 8);
61 for (unsigned iBp = 0; iBp < RT_ELEMENTS(pVM->dbgf.s.aHwBreakpoints); iBp++)
62 {
63 if ( (uDr6 & RT_BIT(iBp))
64 && pVM->dbgf.s.aHwBreakpoints[iBp].enmType == DBGFBPTYPE_REG)
65 {
66 pVM->dbgf.s.iActiveBp = pVM->dbgf.s.aHwBreakpoints[iBp].iBp;
67 pVM->dbgf.s.fSingleSteppingRaw = false;
68 LogFlow(("DBGFGCTrap03Handler: hit hw breakpoint %d at %04x:%08x\n",
69 pVM->dbgf.s.aHwBreakpoints[iBp].iBp, pRegFrame->cs, pRegFrame->eip));
70
71 return fInHyper ? VINF_EM_DBG_HYPER_BREAKPOINT : VINF_EM_DBG_BREAKPOINT;
72 }
73 }
74 }
75
76 /*
77 * Single step?
78 * Are we single stepping or is it the guest?
79 */
80 if ( (uDr6 & X86_DR6_BS)
81 && (fInHyper || pVM->dbgf.s.fSingleSteppingRaw))
82 {
83 pVM->dbgf.s.fSingleSteppingRaw = false;
84 LogFlow(("DBGFGCTrap01Handler: single step at %04x:%08x\n", pRegFrame->cs, pRegFrame->eip));
85 return fInHyper ? VINF_EM_DBG_HYPER_STEPPED : VINF_EM_DBG_STEPPED;
86 }
87
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:%08x\n",
93 uDr6, pRegFrame->cs, pRegFrame->eip));
94 /** @todo virtualize DRx. */
95 LogFlow(("DBGFGCTrap01Handler: guest debug event %RTreg at %04x:%08x!\n", uDr6, pRegFrame->cs, pRegFrame->eip));
96 return fInHyper ? VERR_INTERNAL_ERROR : VINF_EM_RAW_GUEST_TRAP;
97}
98
99
100/**
101 * \#BP (Breakpoint) handler.
102 *
103 * @returns VBox status code.
104 * VINF_SUCCESS means we completely handled this trap,
105 * other codes are passed execution to host context.
106 *
107 * @param pVM The VM handle.
108 * @param pRegFrame Pointer to the register frame for the trap.
109 */
110VMMRCDECL(int) DBGFGCTrap03Handler(PVM pVM, PCPUMCTXCORE pRegFrame)
111{
112 /*
113 * Get the trap address and look it up in the breakpoint table.
114 * Don't bother if we don't have any breakpoints.
115 */
116 if (pVM->dbgf.s.cBreakpoints > 0)
117 {
118 RTGCPTR pPc;
119 int rc = SELMValidateAndConvertCSAddr(pVM, pRegFrame->eflags, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid,
120 (RTGCPTR)((RTGCUINTPTR)pRegFrame->eip - 1),
121 &pPc);
122 AssertRCReturn(rc, rc);
123
124 for (unsigned iBp = 0; iBp < RT_ELEMENTS(pVM->dbgf.s.aBreakpoints); iBp++)
125 {
126 if ( pVM->dbgf.s.aBreakpoints[iBp].GCPtr == (RTGCUINTPTR)pPc
127 && pVM->dbgf.s.aBreakpoints[iBp].enmType == DBGFBPTYPE_INT3)
128 {
129 pVM->dbgf.s.aBreakpoints[iBp].cHits++;
130 pVM->dbgf.s.iActiveBp = pVM->dbgf.s.aBreakpoints[iBp].iBp;
131
132 LogFlow(("DBGFGCTrap03Handler: hit breakpoint %d at %RGv (%04x:%08x) cHits=0x%RX64\n",
133 pVM->dbgf.s.aBreakpoints[iBp].iBp, pPc, pRegFrame->cs, pRegFrame->eip,
134 pVM->dbgf.s.aBreakpoints[iBp].cHits));
135 return !(pRegFrame->ss & X86_SEL_RPL) && !pRegFrame->eflags.Bits.u1VM
136 ? VINF_EM_DBG_HYPER_BREAKPOINT
137 : VINF_EM_DBG_BREAKPOINT;
138 }
139 }
140 }
141
142 return !(pRegFrame->ss & X86_SEL_RPL) && !pRegFrame->eflags.Bits.u1VM
143 ? VINF_EM_DBG_HYPER_ASSERTION
144 : VINF_EM_RAW_GUEST_TRAP;
145}
146
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