VirtualBox

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

Last change on this file since 4953 was 4071, checked in by vboxsync, 17 years ago

Biggest check-in ever. New source code headers for all (C) innotek files.

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