VirtualBox

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

Last change on this file since 2705 was 2171, checked in by vboxsync, 18 years ago

Added @todo

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.4 KB
Line 
1/* $Id: DBGFGC.cpp 2171 2007-04-18 13:11:53Z vboxsync $ */
2/** @file
3 * DBGF - Debugger Facility, GC part.
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#include <VBox/dbgf.h>
27#include <VBox/selm.h>
28#include "DBGFInternal.h"
29#include <VBox/vm.h>
30#include <VBox/err.h>
31#include <iprt/assert.h>
32
33
34
35/**
36 * \#DB (Debug event) handler.
37 *
38 * @returns VBox status code.
39 * VINF_SUCCESS means we completely handled this trap,
40 * other codes are passed execution to host context.
41 *
42 * @param pVM The VM handle.
43 * @param pRegFrame Pointer to the register frame for the trap.
44 * @param uDr6 The DR6 register value.
45 */
46DBGFGCDECL(int) DBGFGCTrap01Handler(PVM pVM, PCPUMCTXCORE pRegFrame, RTUINTREG uDr6)
47{
48 const bool fInHyper = !(pRegFrame->ss & X86_SEL_RPL) && !pRegFrame->eflags.Bits.u1VM;
49
50 /** @todo Intel docs say that X86_DR6_BS has the highest priority... */
51 /*
52 * A breakpoint?
53 */
54 if (uDr6 & (X86_DR6_B0 | X86_DR6_B1 | X86_DR6_B2 | X86_DR6_B3))
55 {
56 Assert(X86_DR6_B0 == 1 && X86_DR6_B1 == 2 && X86_DR6_B2 == 4 && X86_DR6_B3 == 8);
57 for (unsigned iBp = 0; iBp < ELEMENTS(pVM->dbgf.s.aHwBreakpoints); iBp++)
58 {
59 if ( (uDr6 & BIT(iBp))
60 && pVM->dbgf.s.aHwBreakpoints[iBp].enmType == DBGFBPTYPE_REG)
61 {
62 pVM->dbgf.s.iActiveBp = pVM->dbgf.s.aHwBreakpoints[iBp].iBp;
63 pVM->dbgf.s.fSingleSteppingRaw = false;
64 LogFlow(("DBGFGCTrap03Handler: hit hw breakpoint %d at %04x:%08x\n",
65 pVM->dbgf.s.aHwBreakpoints[iBp].iBp, pRegFrame->cs, pRegFrame->eip));
66
67 return fInHyper ? VINF_EM_DBG_HYPER_BREAKPOINT : VINF_EM_DBG_BREAKPOINT;
68 }
69 }
70 }
71
72 /*
73 * Single step?
74 * Are we single stepping or is it the guest?
75 */
76 if ( (uDr6 & X86_DR6_BS)
77 && (fInHyper || pVM->dbgf.s.fSingleSteppingRaw))
78 {
79 pVM->dbgf.s.fSingleSteppingRaw = false;
80 LogFlow(("DBGFGCTrap01Handler: single step at %04x:%08x\n", pRegFrame->cs, pRegFrame->eip));
81 return fInHyper ? VINF_EM_DBG_HYPER_STEPPED : VINF_EM_DBG_STEPPED;
82 }
83
84 /*
85 * Currently we only implement single stepping in the guest,
86 * so we'll bitch if this is not a BS event.
87 */
88 AssertMsg(uDr6 & X86_DR6_BS, ("hey! we're not doing guest BPs yet! dr6=%RTreg %04x:%08\n",
89 uDr6, pRegFrame->cs, pRegFrame->eip));
90 /** @todo virtualize DRx. */
91 LogFlow(("DBGFGCTrap01Handler: guest debug event %RTreg at %04x:%08x!\n", uDr6, pRegFrame->cs, pRegFrame->eip));
92 return fInHyper ? VERR_INTERNAL_ERROR : VINF_EM_RAW_GUEST_TRAP;
93}
94
95
96/**
97 * \#BP (Breakpoint) handler.
98 *
99 * @returns VBox status code.
100 * VINF_SUCCESS means we completely handled this trap,
101 * other codes are passed execution to host context.
102 *
103 * @param pVM The VM handle.
104 * @param pRegFrame Pointer to the register frame for the trap.
105 */
106DBGFGCDECL(int) DBGFGCTrap03Handler(PVM pVM, PCPUMCTXCORE pRegFrame)
107{
108 /*
109 * Get the trap address and look it up in the breakpoint table.
110 * Don't bother if we don't have any breakpoints.
111 */
112 if (pVM->dbgf.s.cBreakpoints > 0)
113 {
114 RTGCPTR pPc;
115 int rc = SELMValidateAndConvertCSAddr(pVM, pRegFrame->eflags, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid,
116 (RTGCPTR)((RTGCUINTPTR)pRegFrame->eip - 1),
117 &pPc);
118 AssertRCReturn(rc, rc);
119
120 for (unsigned iBp = 0; iBp < 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(("DBGFGCTrap03Handler: hit breakpoint %d at %RGv (%04x:%08x) cHits=0x%RX64\n",
129 pVM->dbgf.s.aBreakpoints[iBp].iBp, pPc, pRegFrame->cs, pRegFrame->eip,
130 pVM->dbgf.s.aBreakpoints[iBp].cHits));
131 return !(pRegFrame->ss & X86_SEL_RPL) && !pRegFrame->eflags.Bits.u1VM
132 ? VINF_EM_DBG_HYPER_BREAKPOINT
133 : VINF_EM_DBG_BREAKPOINT;
134 }
135 }
136 }
137
138 return !(pRegFrame->ss & X86_SEL_RPL) && !pRegFrame->eflags.Bits.u1VM
139 ? VINF_EM_DBG_HYPER_ASSERTION
140 : VINF_EM_RAW_GUEST_TRAP;
141}
142
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