VirtualBox

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

最後變更 在這個檔案從86666是 86666,由 vboxsync 提交於 4 年 前

include/VBox,VMM,DBGF: Some boilerplate for the new breakpoint manager which is disabled by default (can be built with VBOX_WITH_LOTS_OF_DBGF_BPS), bugref:9837

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id Revision
檔案大小: 9.8 KB
 
1/* $Id: DBGFRZ.cpp 86666 2020-10-21 15:01:32Z vboxsync $ */
2/** @file
3 * DBGF - Debugger Facility, RZ part.
4 */
5
6/*
7 * Copyright (C) 2006-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.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#ifdef IN_RC
26# include <VBox/vmm/trpm.h>
27#endif
28#include <VBox/log.h>
29#include "DBGFInternal.h"
30#include <VBox/vmm/vmcc.h>
31#include <VBox/err.h>
32#include <iprt/assert.h>
33
34#ifdef IN_RC
35DECLASM(void) TRPMRCHandlerAsmTrap03(void);
36#endif
37
38
39/**
40 * \#DB (Debug event) handler.
41 *
42 * @returns VBox status code.
43 * VINF_SUCCESS means we completely handled this trap,
44 * other codes are passed execution to host context.
45 *
46 * @param pVM The cross context VM structure.
47 * @param pVCpu The cross context virtual CPU structure.
48 * @param pRegFrame Pointer to the register frame for the trap.
49 * @param uDr6 The DR6 hypervisor register value.
50 * @param fAltStepping Alternative stepping indicator.
51 */
52VMMRZ_INT_DECL(int) DBGFRZTrap01Handler(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, RTGCUINTREG uDr6, bool fAltStepping)
53{
54#ifdef IN_RC
55 const bool fInHyper = !(pRegFrame->ss.Sel & X86_SEL_RPL) && !pRegFrame->eflags.Bits.u1VM;
56#else
57 NOREF(pRegFrame);
58 const bool fInHyper = false;
59#endif
60
61 /** @todo Intel docs say that X86_DR6_BS has the highest priority... */
62 /*
63 * A breakpoint?
64 */
65 AssertCompile(X86_DR6_B0 == 1 && X86_DR6_B1 == 2 && X86_DR6_B2 == 4 && X86_DR6_B3 == 8);
66 if ( (uDr6 & (X86_DR6_B0 | X86_DR6_B1 | X86_DR6_B2 | X86_DR6_B3))
67 && pVM->dbgf.s.cEnabledHwBreakpoints > 0)
68 {
69 for (unsigned iBp = 0; iBp < RT_ELEMENTS(pVM->dbgf.s.aHwBreakpoints); iBp++)
70 {
71#ifndef VBOX_WITH_LOTS_OF_DBGF_BPS
72 if ( ((uint32_t)uDr6 & RT_BIT_32(iBp))
73 && pVM->dbgf.s.aHwBreakpoints[iBp].enmType == DBGFBPTYPE_REG)
74 {
75 pVCpu->dbgf.s.iActiveBp = pVM->dbgf.s.aHwBreakpoints[iBp].iBp;
76 pVCpu->dbgf.s.fSingleSteppingRaw = false;
77 LogFlow(("DBGFRZTrap03Handler: hit hw breakpoint %d at %04x:%RGv\n",
78 pVM->dbgf.s.aHwBreakpoints[iBp].iBp, pRegFrame->cs.Sel, pRegFrame->rip));
79
80 return fInHyper ? VINF_EM_DBG_HYPER_BREAKPOINT : VINF_EM_DBG_BREAKPOINT;
81 }
82#else
83 if ( ((uint32_t)uDr6 & RT_BIT_32(iBp))
84 && pVM->dbgf.s.aHwBreakpoints[iBp].hBp != NIL_DBGFBP)
85 {
86 pVCpu->dbgf.s.hBpActive = pVM->dbgf.s.aHwBreakpoints[iBp].hBp;
87 pVCpu->dbgf.s.fSingleSteppingRaw = false;
88 LogFlow(("DBGFRZTrap03Handler: hit hw breakpoint %x at %04x:%RGv\n",
89 pVM->dbgf.s.aHwBreakpoints[iBp].hBp, pRegFrame->cs.Sel, pRegFrame->rip));
90
91 return fInHyper ? VINF_EM_DBG_HYPER_BREAKPOINT : VINF_EM_DBG_BREAKPOINT;
92 }
93#endif
94 }
95 }
96
97 /*
98 * Single step?
99 * Are we single stepping or is it the guest?
100 */
101 if ( (uDr6 & X86_DR6_BS)
102 && (fInHyper || pVCpu->dbgf.s.fSingleSteppingRaw || fAltStepping))
103 {
104 pVCpu->dbgf.s.fSingleSteppingRaw = false;
105 LogFlow(("DBGFRZTrap01Handler: single step at %04x:%RGv\n", pRegFrame->cs.Sel, pRegFrame->rip));
106 return fInHyper ? VINF_EM_DBG_HYPER_STEPPED : VINF_EM_DBG_STEPPED;
107 }
108
109#ifdef IN_RC
110 /*
111 * Either an ICEBP in hypervisor code or a guest related debug exception
112 * of sorts.
113 */
114 if (RT_UNLIKELY(fInHyper))
115 {
116 /*
117 * Is this a guest debug event that was delayed past a ring transition?
118 *
119 * Since we do no allow sysenter/syscall in raw-mode, the only
120 * non-trap/fault type transitions that can occur are thru interrupt gates.
121 * Of those, only INT3 (#BP) has a DPL other than 0 with a CS.RPL of 0.
122 * See bugref:9171 and bs3-cpu-weird-1 for more details.
123 *
124 * We need to reconstruct the guest register state from the hypervisor one
125 * here, so here is the layout of the IRET frame on the stack:
126 * 20:[8] GS (V86 only)
127 * 1C:[7] FS (V86 only)
128 * 18:[6] DS (V86 only)
129 * 14:[5] ES (V86 only)
130 * 10:[4] SS
131 * 0c:[3] ESP
132 * 08:[2] EFLAGS
133 * 04:[1] CS
134 * 00:[0] EIP
135 */
136 if (pRegFrame->rip == (uintptr_t)TRPMRCHandlerAsmTrap03)
137 {
138 uint32_t const *pu32Stack = (uint32_t const *)pRegFrame->esp;
139 if ( (pu32Stack[2] & X86_EFL_VM)
140 || (pu32Stack[1] & X86_SEL_RPL))
141 {
142 LogFlow(("DBGFRZTrap01Handler: Detected guest #DB delayed past ring transition %04x:%RX32 %#x\n",
143 pu32Stack[1] & 0xffff, pu32Stack[0], pu32Stack[2]));
144 PCPUMCTX pGstCtx = CPUMQueryGuestCtxPtr(pVCpu);
145 pGstCtx->rip = pu32Stack[0];
146 pGstCtx->cs.Sel = pu32Stack[1];
147 pGstCtx->eflags.u = pu32Stack[2];
148 pGstCtx->rsp = pu32Stack[3];
149 pGstCtx->ss.Sel = pu32Stack[4];
150 if (pu32Stack[2] & X86_EFL_VM)
151 {
152 pGstCtx->es.Sel = pu32Stack[5];
153 pGstCtx->ds.Sel = pu32Stack[6];
154 pGstCtx->fs.Sel = pu32Stack[7];
155 pGstCtx->gs.Sel = pu32Stack[8];
156 }
157 else
158 {
159 pGstCtx->es.Sel = pRegFrame->es.Sel;
160 pGstCtx->ds.Sel = pRegFrame->ds.Sel;
161 pGstCtx->fs.Sel = pRegFrame->fs.Sel;
162 pGstCtx->gs.Sel = pRegFrame->gs.Sel;
163 }
164 pGstCtx->rax = pRegFrame->rax;
165 pGstCtx->rcx = pRegFrame->rcx;
166 pGstCtx->rdx = pRegFrame->rdx;
167 pGstCtx->rbx = pRegFrame->rbx;
168 pGstCtx->rsi = pRegFrame->rsi;
169 pGstCtx->rdi = pRegFrame->rdi;
170 pGstCtx->rbp = pRegFrame->rbp;
171
172 /*
173 * We should assert a #BP followed by a #DB here, but TRPM cannot
174 * do that. So, we'll just assert the #BP and ignore the #DB, even
175 * if that isn't strictly correct.
176 */
177 TRPMResetTrap(pVCpu);
178 TRPMAssertTrap(pVCpu, X86_XCPT_BP, TRPM_SOFTWARE_INT);
179 return VINF_EM_RAW_GUEST_TRAP;
180 }
181 }
182
183 LogFlow(("DBGFRZTrap01Handler: Unknown bp at %04x:%RGv\n", pRegFrame->cs.Sel, pRegFrame->rip));
184 return VERR_DBGF_HYPER_DB_XCPT;
185 }
186#endif
187
188 LogFlow(("DBGFRZTrap01Handler: guest debug event %#x at %04x:%RGv!\n", (uint32_t)uDr6, pRegFrame->cs.Sel, pRegFrame->rip));
189 return VINF_EM_RAW_GUEST_TRAP;
190}
191
192
193/**
194 * \#BP (Breakpoint) handler.
195 *
196 * @returns VBox status code.
197 * VINF_SUCCESS means we completely handled this trap,
198 * other codes are passed execution to host context.
199 *
200 * @param pVM The cross context VM structure.
201 * @param pVCpu The cross context virtual CPU structure.
202 * @param pRegFrame Pointer to the register frame for the trap.
203 */
204VMMRZ_INT_DECL(int) DBGFRZTrap03Handler(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame)
205{
206#ifdef IN_RC
207 const bool fInHyper = !(pRegFrame->ss.Sel & X86_SEL_RPL) && !pRegFrame->eflags.Bits.u1VM;
208#else
209 const bool fInHyper = false;
210#endif
211
212#ifndef VBOX_WITH_LOTS_OF_DBGF_BPS
213 /*
214 * Get the trap address and look it up in the breakpoint table.
215 * Don't bother if we don't have any breakpoints.
216 */
217 unsigned cToSearch = pVM->dbgf.s.Int3.cToSearch;
218 if (cToSearch > 0)
219 {
220 RTGCPTR pPc;
221 int rc = SELMValidateAndConvertCSAddr(pVCpu, pRegFrame->eflags, pRegFrame->ss.Sel, pRegFrame->cs.Sel, &pRegFrame->cs,
222# ifdef IN_RC
223 pRegFrame->eip - 1,
224# else
225 pRegFrame->rip /* no -1 in R0 */,
226# endif
227 &pPc);
228 AssertRCReturn(rc, rc);
229
230 unsigned iBp = pVM->dbgf.s.Int3.iStartSearch;
231 while (cToSearch-- > 0)
232 {
233 if ( pVM->dbgf.s.aBreakpoints[iBp].u.GCPtr == (RTGCUINTPTR)pPc
234 && pVM->dbgf.s.aBreakpoints[iBp].enmType == DBGFBPTYPE_INT3)
235 {
236 pVM->dbgf.s.aBreakpoints[iBp].cHits++;
237 pVCpu->dbgf.s.iActiveBp = pVM->dbgf.s.aBreakpoints[iBp].iBp;
238
239 LogFlow(("DBGFRZTrap03Handler: hit breakpoint %d at %RGv (%04x:%RGv) cHits=0x%RX64\n",
240 pVM->dbgf.s.aBreakpoints[iBp].iBp, pPc, pRegFrame->cs.Sel, pRegFrame->rip,
241 pVM->dbgf.s.aBreakpoints[iBp].cHits));
242 return fInHyper
243 ? VINF_EM_DBG_HYPER_BREAKPOINT
244 : VINF_EM_DBG_BREAKPOINT;
245 }
246 iBp++;
247 }
248 }
249#endif /* !VBOX_WITH_LOTS_OF_DBGF_BPS */
250
251 return fInHyper
252 ? VINF_EM_DBG_HYPER_ASSERTION
253 : VINF_EM_RAW_GUEST_TRAP;
254}
255
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette