VirtualBox

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

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

VMM,VBoxDbg: SMP refactoring, part 1.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.6 KB
Line 
1/* $Id: DBGFGC.cpp 19286 2009-05-01 12:41:07Z 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 pVCpu The virtual CPU handle.
48 * @param pRegFrame Pointer to the register frame for the trap.
49 * @param uDr6 The DR6 register value.
50 */
51VMMRCDECL(int) DBGFGCTrap01Handler(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, RTGCUINTREG uDr6)
52{
53 const bool fInHyper = !(pRegFrame->ss & X86_SEL_RPL) && !pRegFrame->eflags.Bits.u1VM;
54
55 /** @todo Intel docs say that X86_DR6_BS has the highest priority... */
56 /*
57 * A breakpoint?
58 */
59 if (uDr6 & (X86_DR6_B0 | X86_DR6_B1 | X86_DR6_B2 | X86_DR6_B3))
60 {
61 Assert(X86_DR6_B0 == 1 && X86_DR6_B1 == 2 && X86_DR6_B2 == 4 && X86_DR6_B3 == 8);
62 for (unsigned iBp = 0; iBp < RT_ELEMENTS(pVM->dbgf.s.aHwBreakpoints); iBp++)
63 {
64 if ( ((uint32_t)uDr6 & RT_BIT_32(iBp))
65 && pVM->dbgf.s.aHwBreakpoints[iBp].enmType == DBGFBPTYPE_REG)
66 {
67 pVCpu->dbgf.s.iActiveBp = pVM->dbgf.s.aHwBreakpoints[iBp].iBp;
68 pVCpu->dbgf.s.fSingleSteppingRaw = false;
69 LogFlow(("DBGFGCTrap03Handler: hit hw breakpoint %d at %04x:%08x\n",
70 pVM->dbgf.s.aHwBreakpoints[iBp].iBp, pRegFrame->cs, pRegFrame->eip));
71
72 return fInHyper ? VINF_EM_DBG_HYPER_BREAKPOINT : VINF_EM_DBG_BREAKPOINT;
73 }
74 }
75 }
76
77 /*
78 * Single step?
79 * Are we single stepping or is it the guest?
80 */
81 if ( (uDr6 & X86_DR6_BS)
82 && (fInHyper || pVCpu->dbgf.s.fSingleSteppingRaw))
83 {
84 pVCpu->dbgf.s.fSingleSteppingRaw = false;
85 LogFlow(("DBGFGCTrap01Handler: single step at %04x:%08x\n", pRegFrame->cs, pRegFrame->eip));
86 return fInHyper ? VINF_EM_DBG_HYPER_STEPPED : VINF_EM_DBG_STEPPED;
87 }
88
89 /*
90 * Currently we only implement single stepping in the guest,
91 * so we'll bitch if this is not a BS event.
92 */
93 AssertMsg(uDr6 & X86_DR6_BS, ("hey! we're not doing guest BPs yet! dr6=%RTreg %04x:%08x\n",
94 uDr6, pRegFrame->cs, pRegFrame->eip));
95 /** @todo virtualize DRx. */
96 LogFlow(("DBGFGCTrap01Handler: guest debug event %RTreg at %04x:%08x!\n", uDr6, pRegFrame->cs, pRegFrame->eip));
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 */
112VMMRCDECL(int) DBGFGCTrap03Handler(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame)
113{
114 /*
115 * Get the trap address and look it up in the breakpoint table.
116 * Don't bother if we don't have any breakpoints.
117 */
118 if (pVM->dbgf.s.cBreakpoints > 0)
119 {
120 RTGCPTR pPc;
121 int rc = SELMValidateAndConvertCSAddr(pVM, pRegFrame->eflags, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid,
122 (RTGCPTR)((RTGCUINTPTR)pRegFrame->eip - 1),
123 &pPc);
124 AssertRCReturn(rc, rc);
125
126 for (unsigned iBp = 0; iBp < RT_ELEMENTS(pVM->dbgf.s.aBreakpoints); iBp++)
127 {
128 if ( pVM->dbgf.s.aBreakpoints[iBp].GCPtr == (RTGCUINTPTR)pPc
129 && pVM->dbgf.s.aBreakpoints[iBp].enmType == DBGFBPTYPE_INT3)
130 {
131 pVM->dbgf.s.aBreakpoints[iBp].cHits++;
132 pVCpu->dbgf.s.iActiveBp = pVM->dbgf.s.aBreakpoints[iBp].iBp;
133
134 LogFlow(("DBGFGCTrap03Handler: hit breakpoint %d at %RGv (%04x:%08x) cHits=0x%RX64\n",
135 pVM->dbgf.s.aBreakpoints[iBp].iBp, pPc, pRegFrame->cs, pRegFrame->eip,
136 pVM->dbgf.s.aBreakpoints[iBp].cHits));
137 return !(pRegFrame->ss & X86_SEL_RPL) && !pRegFrame->eflags.Bits.u1VM
138 ? VINF_EM_DBG_HYPER_BREAKPOINT
139 : VINF_EM_DBG_BREAKPOINT;
140 }
141 }
142 }
143
144 return !(pRegFrame->ss & X86_SEL_RPL) && !pRegFrame->eflags.Bits.u1VM
145 ? VINF_EM_DBG_HYPER_ASSERTION
146 : VINF_EM_RAW_GUEST_TRAP;
147}
148
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette