VirtualBox

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

Last change on this file since 47660 was 47660, checked in by vboxsync, 11 years ago

VMM: Debug register handling redo. (only partly tested on AMD-V so far.)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 5.5 KB
Line 
1/* $Id: DBGFRZ.cpp 47660 2013-08-12 00:37:34Z vboxsync $ */
2/** @file
3 * DBGF - Debugger Facility, RZ part.
4 */
5
6/*
7 * Copyright (C) 2006-2013 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 */
45VMMRZ_INT_DECL(int) DBGFRZTrap01Handler(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, RTGCUINTREG uDr6)
46{
47#ifdef IN_RC
48 const bool fInHyper = !(pRegFrame->ss.Sel & X86_SEL_RPL) && !pRegFrame->eflags.Bits.u1VM;
49#else
50 const bool fInHyper = false;
51#endif
52
53 /** @todo Intel docs say that X86_DR6_BS has the highest priority... */
54 /*
55 * A breakpoint?
56 */
57 if (uDr6 & (X86_DR6_B0 | X86_DR6_B1 | X86_DR6_B2 | X86_DR6_B3))
58 {
59 Assert(X86_DR6_B0 == 1 && X86_DR6_B1 == 2 && X86_DR6_B2 == 4 && X86_DR6_B3 == 8);
60 for (unsigned iBp = 0; iBp < RT_ELEMENTS(pVM->dbgf.s.aHwBreakpoints); iBp++)
61 {
62 if ( ((uint32_t)uDr6 & RT_BIT_32(iBp))
63 && pVM->dbgf.s.aHwBreakpoints[iBp].enmType == DBGFBPTYPE_REG)
64 {
65 pVCpu->dbgf.s.iActiveBp = pVM->dbgf.s.aHwBreakpoints[iBp].iBp;
66 pVCpu->dbgf.s.fSingleSteppingRaw = false;
67 LogFlow(("DBGFRZTrap03Handler: hit hw breakpoint %d at %04x:%RGv\n",
68 pVM->dbgf.s.aHwBreakpoints[iBp].iBp, pRegFrame->cs.Sel, pRegFrame->rip));
69
70 return fInHyper ? VINF_EM_DBG_HYPER_BREAKPOINT : VINF_EM_DBG_BREAKPOINT;
71 }
72 }
73 }
74
75 /*
76 * Single step?
77 * Are we single stepping or is it the guest?
78 */
79 if ( (uDr6 & X86_DR6_BS)
80 && (fInHyper || pVCpu->dbgf.s.fSingleSteppingRaw))
81 {
82 pVCpu->dbgf.s.fSingleSteppingRaw = false;
83 LogFlow(("DBGFRZTrap01Handler: single step at %04x:%RGv\n", pRegFrame->cs.Sel, pRegFrame->rip));
84 return fInHyper ? VINF_EM_DBG_HYPER_STEPPED : VINF_EM_DBG_STEPPED;
85 }
86
87 /*
88 * Either an ICEBP in hypervisor code or a guest related debug exception
89 * of sorts.
90 */
91 if (RT_UNLIKELY(fInHyper))
92 {
93 LogFlow(("DBGFRZTrap01Handler: unabled bp at %04x:%RGv\n", pRegFrame->cs.Sel, pRegFrame->rip));
94 return VERR_DBGF_HYPER_DB_XCPT;
95 }
96
97 LogFlow(("DBGFRZTrap01Handler: guest debug event %RTreg at %04x:%RGv!\n", uDr6, pRegFrame->cs.Sel, pRegFrame->rip));
98 return VINF_EM_RAW_GUEST_TRAP;
99}
100
101
102/**
103 * \#BP (Breakpoint) handler.
104 *
105 * @returns VBox status code.
106 * VINF_SUCCESS means we completely handled this trap,
107 * other codes are passed execution to host context.
108 *
109 * @param pVM Pointer to the VM.
110 * @param pVCpu Pointer to the VMCPU.
111 * @param pRegFrame Pointer to the register frame for the trap.
112 */
113VMMRZ_INT_DECL(int) DBGFRZTrap03Handler(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame)
114{
115#ifdef IN_RC
116 const bool fInHyper = !(pRegFrame->ss.Sel & X86_SEL_RPL) && !pRegFrame->eflags.Bits.u1VM;
117#else
118 const bool fInHyper = false;
119#endif
120
121 /*
122 * Get the trap address and look it up in the breakpoint table.
123 * Don't bother if we don't have any breakpoints.
124 */
125 if (pVM->dbgf.s.cBreakpoints > 0)
126 {
127 RTGCPTR pPc;
128 int rc = SELMValidateAndConvertCSAddr(pVCpu, pRegFrame->eflags, pRegFrame->ss.Sel, pRegFrame->cs.Sel, &pRegFrame->cs,
129#ifdef IN_RC
130 pRegFrame->eip - 1,
131#else
132 pRegFrame->rip /* no -1 in R0 */,
133#endif
134 &pPc);
135 AssertRCReturn(rc, rc);
136
137 for (unsigned iBp = 0; iBp < RT_ELEMENTS(pVM->dbgf.s.aBreakpoints); iBp++)
138 {
139 if ( pVM->dbgf.s.aBreakpoints[iBp].GCPtr == (RTGCUINTPTR)pPc
140 && pVM->dbgf.s.aBreakpoints[iBp].enmType == DBGFBPTYPE_INT3)
141 {
142 pVM->dbgf.s.aBreakpoints[iBp].cHits++;
143 pVCpu->dbgf.s.iActiveBp = pVM->dbgf.s.aBreakpoints[iBp].iBp;
144
145 LogFlow(("DBGFRZTrap03Handler: hit breakpoint %d at %RGv (%04x:%RGv) cHits=0x%RX64\n",
146 pVM->dbgf.s.aBreakpoints[iBp].iBp, pPc, pRegFrame->cs.Sel, pRegFrame->rip,
147 pVM->dbgf.s.aBreakpoints[iBp].cHits));
148 return fInHyper
149 ? VINF_EM_DBG_HYPER_BREAKPOINT
150 : VINF_EM_DBG_BREAKPOINT;
151 }
152 }
153 }
154
155 return fInHyper
156 ? VINF_EM_DBG_HYPER_ASSERTION
157 : VINF_EM_RAW_GUEST_TRAP;
158}
159
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