VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR0/DBGFR0.cpp@ 2376

Last change on this file since 2376 was 2294, checked in by vboxsync, 18 years ago

svn:eol-style and keywords.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.9 KB
Line 
1/* $Id: DBGFR0.cpp 2294 2007-04-20 23:37:07Z vboxsync $ */
2/** @file
3 * DBGF - Debugger Facility, R0 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 */
46DBGFR0DECL(int) DBGFR0Trap01Handler(PVM pVM, PCPUMCTXCORE pRegFrame, RTUINTREG uDr6)
47{
48 /** @todo Intel docs say that X86_DR6_BS has the highest priority... */
49 /*
50 * A breakpoint?
51 */
52 if (uDr6 & (X86_DR6_B0 | X86_DR6_B1 | X86_DR6_B2 | X86_DR6_B3))
53 {
54 Assert(X86_DR6_B0 == 1 && X86_DR6_B1 == 2 && X86_DR6_B2 == 4 && X86_DR6_B3 == 8);
55 for (unsigned iBp = 0; iBp < ELEMENTS(pVM->dbgf.s.aHwBreakpoints); iBp++)
56 {
57 if ( (uDr6 & BIT(iBp))
58 && pVM->dbgf.s.aHwBreakpoints[iBp].enmType == DBGFBPTYPE_REG)
59 {
60 pVM->dbgf.s.iActiveBp = pVM->dbgf.s.aHwBreakpoints[iBp].iBp;
61 pVM->dbgf.s.fSingleSteppingRaw = false;
62 LogFlow(("DBGFR0Trap03Handler: hit hw breakpoint %d at %04x:%08x\n",
63 pVM->dbgf.s.aHwBreakpoints[iBp].iBp, pRegFrame->cs, pRegFrame->eip));
64
65 return VINF_EM_DBG_BREAKPOINT;
66 }
67 }
68 }
69
70 /*
71 * Single step?
72 * Are we single stepping or is it the guest?
73 */
74 if ( (uDr6 & X86_DR6_BS)
75 && (pVM->dbgf.s.fSingleSteppingRaw))
76 {
77 pVM->dbgf.s.fSingleSteppingRaw = false;
78 LogFlow(("DBGFR0Trap01Handler: single step at %04x:%08x\n", pRegFrame->cs, pRegFrame->eip));
79 return VINF_EM_DBG_STEPPED;
80 }
81
82 /*
83 * Currently we only implement single stepping in the guest,
84 * so we'll bitch if this is not a BS event.
85 */
86 AssertMsg(uDr6 & X86_DR6_BS, ("hey! we're not doing guest BPs yet! dr6=%RTreg %04x:%08\n",
87 uDr6, pRegFrame->cs, pRegFrame->eip));
88 /** @todo virtualize DRx. */
89 LogFlow(("DBGFR0Trap01Handler: guest debug event %RTreg at %04x:%08x!\n", uDr6, pRegFrame->cs, pRegFrame->eip));
90 return VINF_EM_RAW_GUEST_TRAP;
91}
92
93
94/**
95 * \#BP (Breakpoint) handler.
96 *
97 * @returns VBox status code.
98 * VINF_SUCCESS means we completely handled this trap,
99 * other codes are passed execution to host context.
100 *
101 * @param pVM The VM handle.
102 * @param pRegFrame Pointer to the register frame for the trap.
103 */
104DBGFR0DECL(int) DBGFR0Trap03Handler(PVM pVM, PCPUMCTXCORE pRegFrame)
105{
106 /*
107 * Get the trap address and look it up in the breakpoint table.
108 * Don't bother if we don't have any breakpoints.
109 */
110 if (pVM->dbgf.s.cBreakpoints > 0)
111 {
112 RTGCPTR pPc;
113 int rc = SELMValidateAndConvertCSAddr(pVM, pRegFrame->eflags, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid,
114 (RTGCPTR)((RTGCUINTPTR)pRegFrame->eip - 1),
115 &pPc);
116 AssertRCReturn(rc, rc);
117
118 for (unsigned iBp = 0; iBp < ELEMENTS(pVM->dbgf.s.aBreakpoints); iBp++)
119 {
120 if ( pVM->dbgf.s.aBreakpoints[iBp].GCPtr == (RTGCUINTPTR)pPc
121 && pVM->dbgf.s.aBreakpoints[iBp].enmType == DBGFBPTYPE_INT3)
122 {
123 pVM->dbgf.s.aBreakpoints[iBp].cHits++;
124 pVM->dbgf.s.iActiveBp = pVM->dbgf.s.aBreakpoints[iBp].iBp;
125
126 LogFlow(("DBGFR0Trap03Handler: hit breakpoint %d at %RGv (%04x:%08x) cHits=0x%RX64\n",
127 pVM->dbgf.s.aBreakpoints[iBp].iBp, pPc, pRegFrame->cs, pRegFrame->eip,
128 pVM->dbgf.s.aBreakpoints[iBp].cHits));
129 return VINF_EM_DBG_BREAKPOINT;
130 }
131 }
132 }
133
134 return VINF_EM_RAW_GUEST_TRAP;
135}
136
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