VirtualBox

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

Last change on this file since 1 was 1, checked in by vboxsync, 55 years ago

import

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