VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMRZ/DBGFRZ.cpp@ 57066

Last change on this file since 57066 was 56287, checked in by vboxsync, 9 years ago

VMM: Updated (C) year.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 5.7 KB
Line 
1/* $Id: DBGFRZ.cpp 56287 2015-06-09 11:15:22Z vboxsync $ */
2/** @file
3 * DBGF - Debugger Facility, RZ part.
4 */
5
6/*
7 * Copyright (C) 2006-2015 Oracle Corporation
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 (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#define LOG_GROUP LOG_GROUP_DBGF
23#include <VBox/vmm/dbgf.h>
24#include <VBox/vmm/selm.h>
25#include <VBox/log.h>
26#include "DBGFInternal.h"
27#include <VBox/vmm/vm.h>
28#include <VBox/err.h>
29#include <iprt/assert.h>
30
31
32
33/**
34 * \#DB (Debug event) handler.
35 *
36 * @returns VBox status code.
37 * VINF_SUCCESS means we completely handled this trap,
38 * other codes are passed execution to host context.
39 *
40 * @param pVM Pointer to the VM.
41 * @param pVCpu Pointer to the VMCPU.
42 * @param pRegFrame Pointer to the register frame for the trap.
43 * @param uDr6 The DR6 hypervisor register value.
44 * @param fAltStepping Alternative stepping indicator.
45 */
46VMMRZ_INT_DECL(int) DBGFRZTrap01Handler(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, RTGCUINTREG uDr6, bool fAltStepping)
47{
48#ifdef IN_RC
49 const bool fInHyper = !(pRegFrame->ss.Sel & X86_SEL_RPL) && !pRegFrame->eflags.Bits.u1VM;
50#else
51 const bool fInHyper = false;
52#endif
53
54 /** @todo Intel docs say that X86_DR6_BS has the highest priority... */
55 /*
56 * A breakpoint?
57 */
58 if (uDr6 & (X86_DR6_B0 | X86_DR6_B1 | X86_DR6_B2 | X86_DR6_B3))
59 {
60 Assert(X86_DR6_B0 == 1 && X86_DR6_B1 == 2 && X86_DR6_B2 == 4 && X86_DR6_B3 == 8);
61 for (unsigned iBp = 0; iBp < RT_ELEMENTS(pVM->dbgf.s.aHwBreakpoints); iBp++)
62 {
63 if ( ((uint32_t)uDr6 & RT_BIT_32(iBp))
64 && pVM->dbgf.s.aHwBreakpoints[iBp].enmType == DBGFBPTYPE_REG)
65 {
66 pVCpu->dbgf.s.iActiveBp = pVM->dbgf.s.aHwBreakpoints[iBp].iBp;
67 pVCpu->dbgf.s.fSingleSteppingRaw = false;
68 LogFlow(("DBGFRZTrap03Handler: hit hw breakpoint %d at %04x:%RGv\n",
69 pVM->dbgf.s.aHwBreakpoints[iBp].iBp, pRegFrame->cs.Sel, pRegFrame->rip));
70
71 return fInHyper ? VINF_EM_DBG_HYPER_BREAKPOINT : VINF_EM_DBG_BREAKPOINT;
72 }
73 }
74 }
75
76 /*
77 * Single step?
78 * Are we single stepping or is it the guest?
79 */
80 if ( (uDr6 & X86_DR6_BS)
81 && (fInHyper || pVCpu->dbgf.s.fSingleSteppingRaw || fAltStepping))
82 {
83 pVCpu->dbgf.s.fSingleSteppingRaw = false;
84 LogFlow(("DBGFRZTrap01Handler: single step at %04x:%RGv\n", pRegFrame->cs.Sel, pRegFrame->rip));
85 return fInHyper ? VINF_EM_DBG_HYPER_STEPPED : VINF_EM_DBG_STEPPED;
86 }
87
88 /*
89 * Either an ICEBP in hypervisor code or a guest related debug exception
90 * of sorts.
91 */
92 if (RT_UNLIKELY(fInHyper))
93 {
94 LogFlow(("DBGFRZTrap01Handler: unabled bp at %04x:%RGv\n", pRegFrame->cs.Sel, pRegFrame->rip));
95 return VERR_DBGF_HYPER_DB_XCPT;
96 }
97
98 LogFlow(("DBGFRZTrap01Handler: guest debug event %#x at %04x:%RGv!\n", (uint32_t)uDr6, pRegFrame->cs.Sel, pRegFrame->rip));
99 return VINF_EM_RAW_GUEST_TRAP;
100}
101
102
103/**
104 * \#BP (Breakpoint) handler.
105 *
106 * @returns VBox status code.
107 * VINF_SUCCESS means we completely handled this trap,
108 * other codes are passed execution to host context.
109 *
110 * @param pVM Pointer to the VM.
111 * @param pVCpu Pointer to the VMCPU.
112 * @param pRegFrame Pointer to the register frame for the trap.
113 */
114VMMRZ_INT_DECL(int) DBGFRZTrap03Handler(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame)
115{
116#ifdef IN_RC
117 const bool fInHyper = !(pRegFrame->ss.Sel & X86_SEL_RPL) && !pRegFrame->eflags.Bits.u1VM;
118#else
119 const bool fInHyper = false;
120#endif
121
122 /*
123 * Get the trap address and look it up in the breakpoint table.
124 * Don't bother if we don't have any breakpoints.
125 */
126 if (pVM->dbgf.s.cBreakpoints > 0)
127 {
128 RTGCPTR pPc;
129 int rc = SELMValidateAndConvertCSAddr(pVCpu, pRegFrame->eflags, pRegFrame->ss.Sel, pRegFrame->cs.Sel, &pRegFrame->cs,
130#ifdef IN_RC
131 pRegFrame->eip - 1,
132#else
133 pRegFrame->rip /* no -1 in R0 */,
134#endif
135 &pPc);
136 AssertRCReturn(rc, rc);
137
138 for (unsigned iBp = 0; iBp < RT_ELEMENTS(pVM->dbgf.s.aBreakpoints); iBp++)
139 {
140 if ( pVM->dbgf.s.aBreakpoints[iBp].GCPtr == (RTGCUINTPTR)pPc
141 && pVM->dbgf.s.aBreakpoints[iBp].enmType == DBGFBPTYPE_INT3)
142 {
143 pVM->dbgf.s.aBreakpoints[iBp].cHits++;
144 pVCpu->dbgf.s.iActiveBp = pVM->dbgf.s.aBreakpoints[iBp].iBp;
145
146 LogFlow(("DBGFRZTrap03Handler: hit breakpoint %d at %RGv (%04x:%RGv) cHits=0x%RX64\n",
147 pVM->dbgf.s.aBreakpoints[iBp].iBp, pPc, pRegFrame->cs.Sel, pRegFrame->rip,
148 pVM->dbgf.s.aBreakpoints[iBp].cHits));
149 return fInHyper
150 ? VINF_EM_DBG_HYPER_BREAKPOINT
151 : VINF_EM_DBG_BREAKPOINT;
152 }
153 }
154 }
155
156 return fInHyper
157 ? VINF_EM_DBG_HYPER_ASSERTION
158 : VINF_EM_RAW_GUEST_TRAP;
159}
160
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