VirtualBox

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

Last change on this file since 58700 was 58123, checked in by vboxsync, 9 years ago

VMM: Made @param pVCpu more uniform and to the point.

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