VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR0/DBGFR0.cpp@ 18768

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

DBGFR0.cpp: 32->64 bit propagation warning.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.0 KB
Line 
1/* $Id: DBGFR0.cpp 18469 2009-03-28 23:23:56Z 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 pRegFrame Pointer to the register frame for the trap.
47 * @param uDr6 The DR6 register value.
48 */
49VMMR0DECL(int) DBGFR0Trap01Handler(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCUINTREG uDr6)
50{
51 /** @todo Intel docs say that X86_DR6_BS has the highest priority... */
52 /*
53 * A breakpoint?
54 */
55 if (uDr6 & (X86_DR6_B0 | X86_DR6_B1 | X86_DR6_B2 | X86_DR6_B3))
56 {
57 Assert(X86_DR6_B0 == 1 && X86_DR6_B1 == 2 && X86_DR6_B2 == 4 && X86_DR6_B3 == 8);
58 for (unsigned iBp = 0; iBp < RT_ELEMENTS(pVM->dbgf.s.aHwBreakpoints); iBp++)
59 {
60 if ( ((uint32_t)uDr6 & RT_BIT_32(iBp))
61 && pVM->dbgf.s.aHwBreakpoints[iBp].enmType == DBGFBPTYPE_REG)
62 {
63 pVM->dbgf.s.iActiveBp = pVM->dbgf.s.aHwBreakpoints[iBp].iBp;
64 pVM->dbgf.s.fSingleSteppingRaw = false;
65 LogFlow(("DBGFR0Trap03Handler: hit hw breakpoint %d at %04x:%RGv\n",
66 pVM->dbgf.s.aHwBreakpoints[iBp].iBp, pRegFrame->cs, pRegFrame->rip));
67
68 return VINF_EM_DBG_BREAKPOINT;
69 }
70 }
71 }
72
73 /*
74 * Single step?
75 * Are we single stepping or is it the guest?
76 */
77 if ( (uDr6 & X86_DR6_BS)
78 && (pVM->dbgf.s.fSingleSteppingRaw))
79 {
80 pVM->dbgf.s.fSingleSteppingRaw = false;
81 LogFlow(("DBGFR0Trap01Handler: single step at %04x:%RGv\n", pRegFrame->cs, pRegFrame->rip));
82 return VINF_EM_DBG_STEPPED;
83 }
84
85 /*
86 * Currently we only implement single stepping in the guest,
87 * so we'll bitch if this is not a BS event.
88 */
89 AssertMsg(uDr6 & X86_DR6_BS, ("hey! we're not doing guest BPs yet! dr6=%RTreg %04x:%RGv\n",
90 uDr6, pRegFrame->cs, pRegFrame->rip));
91 /** @todo virtualize DRx. */
92 LogFlow(("DBGFR0Trap01Handler: guest debug event %RTreg at %04x:%RGv!\n", uDr6, pRegFrame->cs, pRegFrame->rip));
93 return VINF_EM_RAW_GUEST_TRAP;
94}
95
96
97/**
98 * \#BP (Breakpoint) handler.
99 *
100 * @returns VBox status code.
101 * VINF_SUCCESS means we completely handled this trap,
102 * other codes are passed execution to host context.
103 *
104 * @param pVM The VM handle.
105 * @param pRegFrame Pointer to the register frame for the trap.
106 */
107VMMR0DECL(int) DBGFR0Trap03Handler(PVM pVM, PCPUMCTXCORE pRegFrame)
108{
109 /*
110 * Get the trap address and look it up in the breakpoint table.
111 * Don't bother if we don't have any breakpoints.
112 */
113 if (pVM->dbgf.s.cBreakpoints > 0)
114 {
115 RTGCPTR pPc;
116 int rc = SELMValidateAndConvertCSAddr(pVM, pRegFrame->eflags, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid,
117 (RTGCPTR)pRegFrame->rip /* no -1 in R0 */, &pPc);
118 AssertRCReturn(rc, rc);
119
120 for (unsigned iBp = 0; iBp < RT_ELEMENTS(pVM->dbgf.s.aBreakpoints); iBp++)
121 {
122 if ( pVM->dbgf.s.aBreakpoints[iBp].GCPtr == (RTGCUINTPTR)pPc
123 && pVM->dbgf.s.aBreakpoints[iBp].enmType == DBGFBPTYPE_INT3)
124 {
125 pVM->dbgf.s.aBreakpoints[iBp].cHits++;
126 pVM->dbgf.s.iActiveBp = pVM->dbgf.s.aBreakpoints[iBp].iBp;
127
128 LogFlow(("DBGFR0Trap03Handler: hit breakpoint %d at %RGv (%04x:%RGv) cHits=0x%RX64\n",
129 pVM->dbgf.s.aBreakpoints[iBp].iBp, pPc, pRegFrame->cs, pRegFrame->rip,
130 pVM->dbgf.s.aBreakpoints[iBp].cHits));
131 return VINF_EM_DBG_BREAKPOINT;
132 }
133 }
134 }
135
136 return VINF_EM_RAW_GUEST_TRAP;
137}
138
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