VirtualBox

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