[23] | 1 | /* $Id: DBGF.cpp 46420 2013-06-06 16:27:25Z vboxsync $ */
|
---|
[1] | 2 | /** @file
|
---|
[12677] | 3 | * DBGF - Debugger Facility.
|
---|
[1] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[44528] | 7 | * Copyright (C) 2006-2013 Oracle Corporation
|
---|
[1] | 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
|
---|
[5999] | 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.
|
---|
[1] | 16 | */
|
---|
| 17 |
|
---|
| 18 |
|
---|
[12663] | 19 | /** @page pg_dbgf DBGF - The Debugger Facility
|
---|
[1] | 20 | *
|
---|
[12663] | 21 | * The purpose of the DBGF is to provide an interface for debuggers to
|
---|
| 22 | * manipulate the VMM without having to mess up the source code for each of
|
---|
| 23 | * them. The DBGF is always built in and will always work when a debugger
|
---|
| 24 | * attaches to the VM. The DBGF provides the basic debugger features, such as
|
---|
| 25 | * halting execution, handling breakpoints, single step execution, instruction
|
---|
| 26 | * disassembly, info querying, OS specific diggers, symbol and module
|
---|
| 27 | * management.
|
---|
[1] | 28 | *
|
---|
| 29 | * The interface is working in a manner similar to the win32, linux and os2
|
---|
[32049] | 30 | * debugger interfaces. The interface has an asynchronous nature. This comes
|
---|
| 31 | * from the fact that the VMM and the Debugger are running in different threads.
|
---|
[33540] | 32 | * They are referred to as the "emulation thread" and the "debugger thread", or
|
---|
[32049] | 33 | * as the "ping thread" and the "pong thread, respectivly. (The last set of
|
---|
| 34 | * names comes from the use of the Ping-Pong synchronization construct from the
|
---|
| 35 | * RTSem API.)
|
---|
[1] | 36 | *
|
---|
[13005] | 37 | * @see grp_dbgf
|
---|
[1] | 38 | *
|
---|
| 39 | *
|
---|
[12663] | 40 | * @section sec_dbgf_scenario Usage Scenario
|
---|
[1] | 41 | *
|
---|
[33540] | 42 | * The debugger starts by attaching to the VM. For practical reasons we limit the
|
---|
[12663] | 43 | * number of concurrently attached debuggers to 1 per VM. The action of
|
---|
| 44 | * attaching to the VM causes the VM to check and generate debug events.
|
---|
[1] | 45 | *
|
---|
| 46 | * The debugger then will wait/poll for debug events and issue commands.
|
---|
| 47 | *
|
---|
| 48 | * The waiting and polling is done by the DBGFEventWait() function. It will wait
|
---|
| 49 | * for the emulation thread to send a ping, thus indicating that there is an
|
---|
| 50 | * event waiting to be processed.
|
---|
| 51 | *
|
---|
[33540] | 52 | * An event can be a response to a command issued previously, the hitting of a
|
---|
[32049] | 53 | * breakpoint, or running into a bad/fatal VMM condition. The debugger now has
|
---|
[12663] | 54 | * the ping and must respond to the event at hand - the VMM is waiting. This
|
---|
[1] | 55 | * usually means that the user of the debugger must do something, but it doesn't
|
---|
| 56 | * have to. The debugger is free to call any DBGF function (nearly at least)
|
---|
| 57 | * while processing the event.
|
---|
| 58 | *
|
---|
| 59 | * Typically the user will issue a request for the execution to be resumed, so
|
---|
| 60 | * the debugger calls DBGFResume() and goes back to waiting/polling for events.
|
---|
| 61 | *
|
---|
| 62 | * When the user eventually terminates the debugging session or selects another
|
---|
[12663] | 63 | * VM, the debugger detaches from the VM. This means that breakpoints are
|
---|
| 64 | * disabled and that the emulation thread no longer polls for debugger commands.
|
---|
[1] | 65 | *
|
---|
| 66 | */
|
---|
| 67 |
|
---|
| 68 |
|
---|
| 69 | /*******************************************************************************
|
---|
| 70 | * Header Files *
|
---|
| 71 | *******************************************************************************/
|
---|
| 72 | #define LOG_GROUP LOG_GROUP_DBGF
|
---|
[35346] | 73 | #include <VBox/vmm/dbgf.h>
|
---|
| 74 | #include <VBox/vmm/selm.h>
|
---|
[40274] | 75 | #ifdef VBOX_WITH_REM
|
---|
| 76 | # include <VBox/vmm/rem.h>
|
---|
| 77 | #endif
|
---|
[35346] | 78 | #include <VBox/vmm/em.h>
|
---|
[43387] | 79 | #include <VBox/vmm/hm.h>
|
---|
[1] | 80 | #include "DBGFInternal.h"
|
---|
[35346] | 81 | #include <VBox/vmm/vm.h>
|
---|
[44373] | 82 | #include <VBox/vmm/uvm.h>
|
---|
[1] | 83 | #include <VBox/err.h>
|
---|
| 84 |
|
---|
| 85 | #include <VBox/log.h>
|
---|
| 86 | #include <iprt/semaphore.h>
|
---|
| 87 | #include <iprt/thread.h>
|
---|
| 88 | #include <iprt/asm.h>
|
---|
| 89 | #include <iprt/time.h>
|
---|
| 90 | #include <iprt/assert.h>
|
---|
| 91 | #include <iprt/stream.h>
|
---|
[14660] | 92 | #include <iprt/env.h>
|
---|
[1] | 93 |
|
---|
| 94 |
|
---|
| 95 | /*******************************************************************************
|
---|
| 96 | * Internal Functions *
|
---|
| 97 | *******************************************************************************/
|
---|
[12663] | 98 | static int dbgfR3VMMWait(PVM pVM);
|
---|
| 99 | static int dbgfR3VMMCmd(PVM pVM, DBGFCMD enmCmd, PDBGFCMDDATA pCmdData, bool *pfResumeExecution);
|
---|
[12875] | 100 | static DECLCALLBACK(int) dbgfR3Attach(PVM pVM);
|
---|
[1] | 101 |
|
---|
| 102 |
|
---|
| 103 | /**
|
---|
| 104 | * Sets the VMM Debug Command variable.
|
---|
| 105 | *
|
---|
| 106 | * @returns Previous command.
|
---|
[41800] | 107 | * @param pVM Pointer to the VM.
|
---|
[1] | 108 | * @param enmCmd The command.
|
---|
| 109 | */
|
---|
[12663] | 110 | DECLINLINE(DBGFCMD) dbgfR3SetCmd(PVM pVM, DBGFCMD enmCmd)
|
---|
[1] | 111 | {
|
---|
[23] | 112 | DBGFCMD rc;
|
---|
[1] | 113 | if (enmCmd == DBGFCMD_NO_COMMAND)
|
---|
| 114 | {
|
---|
| 115 | Log2(("DBGF: Setting command to %d (DBGFCMD_NO_COMMAND)\n", enmCmd));
|
---|
[23] | 116 | rc = (DBGFCMD)ASMAtomicXchgU32((uint32_t volatile *)(void *)&pVM->dbgf.s.enmVMMCmd, enmCmd);
|
---|
[1] | 117 | VM_FF_CLEAR(pVM, VM_FF_DBGF);
|
---|
| 118 | }
|
---|
| 119 | else
|
---|
| 120 | {
|
---|
| 121 | Log2(("DBGF: Setting command to %d\n", enmCmd));
|
---|
| 122 | AssertMsg(pVM->dbgf.s.enmVMMCmd == DBGFCMD_NO_COMMAND, ("enmCmd=%d enmVMMCmd=%d\n", enmCmd, pVM->dbgf.s.enmVMMCmd));
|
---|
[23] | 123 | rc = (DBGFCMD)ASMAtomicXchgU32((uint32_t volatile *)(void *)&pVM->dbgf.s.enmVMMCmd, enmCmd);
|
---|
[1] | 124 | VM_FF_SET(pVM, VM_FF_DBGF);
|
---|
[19400] | 125 | VMR3NotifyGlobalFFU(pVM->pUVM, 0 /* didn't notify REM */);
|
---|
[1] | 126 | }
|
---|
[23] | 127 | return rc;
|
---|
[1] | 128 | }
|
---|
| 129 |
|
---|
| 130 |
|
---|
| 131 | /**
|
---|
| 132 | * Initializes the DBGF.
|
---|
| 133 | *
|
---|
| 134 | * @returns VBox status code.
|
---|
[41800] | 135 | * @param pVM Pointer to the VM.
|
---|
[1] | 136 | */
|
---|
[44399] | 137 | VMMR3_INT_DECL(int) DBGFR3Init(PVM pVM)
|
---|
[1] | 138 | {
|
---|
[44399] | 139 | PUVM pUVM = pVM->pUVM;
|
---|
[44404] | 140 | AssertCompile(sizeof(pUVM->dbgf.s) <= sizeof(pUVM->dbgf.padding));
|
---|
| 141 | AssertCompile(sizeof(pUVM->aCpus[0].dbgf.s) <= sizeof(pUVM->aCpus[0].dbgf.padding));
|
---|
| 142 |
|
---|
[44399] | 143 | int rc = dbgfR3InfoInit(pUVM);
|
---|
[13816] | 144 | if (RT_SUCCESS(rc))
|
---|
[37410] | 145 | rc = dbgfR3TraceInit(pVM);
|
---|
| 146 | if (RT_SUCCESS(rc))
|
---|
[44399] | 147 | rc = dbgfR3RegInit(pUVM);
|
---|
[35466] | 148 | if (RT_SUCCESS(rc))
|
---|
[44399] | 149 | rc = dbgfR3AsInit(pUVM);
|
---|
[19757] | 150 | if (RT_SUCCESS(rc))
|
---|
[1] | 151 | rc = dbgfR3BpInit(pVM);
|
---|
| 152 | return rc;
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 |
|
---|
| 156 | /**
|
---|
[33540] | 157 | * Terminates and cleans up resources allocated by the DBGF.
|
---|
[1] | 158 | *
|
---|
| 159 | * @returns VBox status code.
|
---|
[41800] | 160 | * @param pVM Pointer to the VM.
|
---|
[1] | 161 | */
|
---|
[44399] | 162 | VMMR3_INT_DECL(int) DBGFR3Term(PVM pVM)
|
---|
[1] | 163 | {
|
---|
[44399] | 164 | PUVM pUVM = pVM->pUVM;
|
---|
[1] | 165 |
|
---|
[45006] | 166 | dbgfR3OSTerm(pUVM);
|
---|
| 167 | dbgfR3AsTerm(pUVM);
|
---|
| 168 | dbgfR3RegTerm(pUVM);
|
---|
| 169 | dbgfR3TraceTerm(pVM);
|
---|
| 170 | dbgfR3InfoTerm(pUVM);
|
---|
| 171 |
|
---|
| 172 | return VINF_SUCCESS;
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 |
|
---|
| 176 | /**
|
---|
| 177 | * Called when the VM is powered off to detach debuggers.
|
---|
| 178 | *
|
---|
| 179 | * @param pVM The VM handle.
|
---|
| 180 | */
|
---|
| 181 | VMMR3_INT_DECL(void) DBGFR3PowerOff(PVM pVM)
|
---|
| 182 | {
|
---|
| 183 |
|
---|
[1] | 184 | /*
|
---|
[12875] | 185 | * Send a termination event to any attached debugger.
|
---|
[1] | 186 | */
|
---|
[12875] | 187 | /* wait to become the speaker (we should already be that). */
|
---|
[1] | 188 | if ( pVM->dbgf.s.fAttached
|
---|
[12875] | 189 | && RTSemPingShouldWait(&pVM->dbgf.s.PingPong))
|
---|
| 190 | RTSemPingWait(&pVM->dbgf.s.PingPong, 5000);
|
---|
[1] | 191 |
|
---|
[45006] | 192 | if (pVM->dbgf.s.fAttached)
|
---|
[1] | 193 | {
|
---|
[45006] | 194 | /* Just mark it as detached if we're not in a position to send a power
|
---|
| 195 | off event. It should fail later on. */
|
---|
| 196 | if (!RTSemPingIsSpeaker(&pVM->dbgf.s.PingPong))
|
---|
[1] | 197 | {
|
---|
[45006] | 198 | ASMAtomicWriteBool(&pVM->dbgf.s.fAttached, false);
|
---|
| 199 | if (RTSemPingIsSpeaker(&pVM->dbgf.s.PingPong))
|
---|
| 200 | ASMAtomicWriteBool(&pVM->dbgf.s.fAttached, true);
|
---|
[12875] | 201 | }
|
---|
| 202 |
|
---|
[45006] | 203 | if (RTSemPingIsSpeaker(&pVM->dbgf.s.PingPong))
|
---|
[12875] | 204 | {
|
---|
[45006] | 205 | /* Try send the power off event. */
|
---|
| 206 | int rc;
|
---|
| 207 | DBGFCMD enmCmd = dbgfR3SetCmd(pVM, DBGFCMD_NO_COMMAND);
|
---|
| 208 | if (enmCmd == DBGFCMD_DETACH_DEBUGGER)
|
---|
| 209 | /* the debugger beat us to initiating the detaching. */
|
---|
| 210 | rc = VINF_SUCCESS;
|
---|
| 211 | else
|
---|
[1] | 212 | {
|
---|
[45006] | 213 | /* ignore the command (if any). */
|
---|
[12875] | 214 | enmCmd = DBGFCMD_NO_COMMAND;
|
---|
[45006] | 215 | pVM->dbgf.s.DbgEvent.enmType = DBGFEVENT_POWERING_OFF;
|
---|
| 216 | pVM->dbgf.s.DbgEvent.enmCtx = DBGFEVENTCTX_OTHER;
|
---|
| 217 | rc = RTSemPing(&pVM->dbgf.s.PingPong);
|
---|
[1] | 218 | }
|
---|
[45006] | 219 |
|
---|
| 220 | /*
|
---|
| 221 | * Process commands and priority requests until we get a command
|
---|
| 222 | * indicating that the debugger has detached.
|
---|
| 223 | */
|
---|
| 224 | uint32_t cPollHack = 1;
|
---|
| 225 | PVMCPU pVCpu = VMMGetCpu(pVM);
|
---|
| 226 | while (RT_SUCCESS(rc))
|
---|
[12875] | 227 | {
|
---|
[45006] | 228 | if (enmCmd != DBGFCMD_NO_COMMAND)
|
---|
| 229 | {
|
---|
| 230 | /* process command */
|
---|
| 231 | bool fResumeExecution;
|
---|
| 232 | DBGFCMDDATA CmdData = pVM->dbgf.s.VMMCmdData;
|
---|
| 233 | rc = dbgfR3VMMCmd(pVM, enmCmd, &CmdData, &fResumeExecution);
|
---|
| 234 | if (enmCmd == DBGFCMD_DETACHED_DEBUGGER)
|
---|
| 235 | break;
|
---|
| 236 | enmCmd = DBGFCMD_NO_COMMAND;
|
---|
| 237 | }
|
---|
| 238 | else
|
---|
| 239 | {
|
---|
| 240 | /* Wait for new command, processing pending priority requests
|
---|
| 241 | first. The request processing is a bit crazy, but
|
---|
| 242 | unfortunately required by plugin unloading. */
|
---|
[46420] | 243 | if ( VM_FF_IS_PENDING(pVM, VM_FF_REQUEST)
|
---|
| 244 | || VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_REQUEST))
|
---|
[45006] | 245 | {
|
---|
| 246 | LogFlow(("DBGFR3PowerOff: Processes priority requests...\n"));
|
---|
| 247 | rc = VMR3ReqProcessU(pVM->pUVM, VMCPUID_ANY, true /*fPriorityOnly*/);
|
---|
| 248 | if (rc == VINF_SUCCESS)
|
---|
| 249 | rc = VMR3ReqProcessU(pVM->pUVM, pVCpu->idCpu, true /*fPriorityOnly*/);
|
---|
| 250 | LogFlow(("DBGFR3PowerOff: VMR3ReqProcess -> %Rrc\n", rc));
|
---|
| 251 | cPollHack = 1;
|
---|
| 252 | }
|
---|
| 253 | else if (cPollHack < 120)
|
---|
| 254 | cPollHack++;
|
---|
| 255 |
|
---|
| 256 | rc = RTSemPingWait(&pVM->dbgf.s.PingPong, cPollHack);
|
---|
| 257 | if (RT_SUCCESS(rc))
|
---|
| 258 | enmCmd = dbgfR3SetCmd(pVM, DBGFCMD_NO_COMMAND);
|
---|
| 259 | else if (rc == VERR_TIMEOUT)
|
---|
| 260 | rc = VINF_SUCCESS;
|
---|
| 261 | }
|
---|
[12875] | 262 | }
|
---|
[45006] | 263 |
|
---|
| 264 | /*
|
---|
| 265 | * Clear the FF so we won't get confused later on.
|
---|
| 266 | */
|
---|
| 267 | VM_FF_CLEAR(pVM, VM_FF_DBGF);
|
---|
[1] | 268 | }
|
---|
| 269 | }
|
---|
| 270 | }
|
---|
| 271 |
|
---|
| 272 |
|
---|
| 273 | /**
|
---|
| 274 | * Applies relocations to data and code managed by this
|
---|
| 275 | * component. This function will be called at init and
|
---|
| 276 | * whenever the VMM need to relocate it self inside the GC.
|
---|
| 277 | *
|
---|
[41800] | 278 | * @param pVM Pointer to the VM.
|
---|
[1] | 279 | * @param offDelta Relocation delta relative to old location.
|
---|
| 280 | */
|
---|
[44399] | 281 | VMMR3_INT_DECL(void) DBGFR3Relocate(PVM pVM, RTGCINTPTR offDelta)
|
---|
[1] | 282 | {
|
---|
[37410] | 283 | dbgfR3TraceRelocate(pVM);
|
---|
[44399] | 284 | dbgfR3AsRelocate(pVM->pUVM, offDelta);
|
---|
[1] | 285 | }
|
---|
| 286 |
|
---|
| 287 |
|
---|
| 288 | /**
|
---|
| 289 | * Waits a little while for a debuggger to attach.
|
---|
| 290 | *
|
---|
| 291 | * @returns True is a debugger have attached.
|
---|
[41800] | 292 | * @param pVM Pointer to the VM.
|
---|
[1] | 293 | * @param enmEvent Event.
|
---|
| 294 | */
|
---|
| 295 | bool dbgfR3WaitForAttach(PVM pVM, DBGFEVENTTYPE enmEvent)
|
---|
| 296 | {
|
---|
| 297 | /*
|
---|
| 298 | * First a message.
|
---|
| 299 | */
|
---|
[3697] | 300 | #ifndef RT_OS_L4
|
---|
[2261] | 301 |
|
---|
[36768] | 302 | # if !defined(DEBUG) || defined(DEBUG_sandervl) || defined(DEBUG_frank) || defined(IEM_VERIFICATION_MODE)
|
---|
[1] | 303 | int cWait = 10;
|
---|
[2261] | 304 | # else
|
---|
[43387] | 305 | int cWait = HMIsEnabled(pVM)
|
---|
[14660] | 306 | && ( enmEvent == DBGFEVENT_ASSERTION_HYPER
|
---|
| 307 | || enmEvent == DBGFEVENT_FATAL_ERROR)
|
---|
| 308 | && !RTEnvExist("VBOX_DBGF_WAIT_FOR_ATTACH")
|
---|
| 309 | ? 10
|
---|
| 310 | : 150;
|
---|
[2261] | 311 | # endif
|
---|
[12832] | 312 | RTStrmPrintf(g_pStdErr, "DBGF: No debugger attached, waiting %d second%s for one to attach (event=%d)\n",
|
---|
| 313 | cWait / 10, cWait != 10 ? "s" : "", enmEvent);
|
---|
[12830] | 314 | RTStrmFlush(g_pStdErr);
|
---|
[1] | 315 | while (cWait > 0)
|
---|
| 316 | {
|
---|
| 317 | RTThreadSleep(100);
|
---|
| 318 | if (pVM->dbgf.s.fAttached)
|
---|
| 319 | {
|
---|
[23] | 320 | RTStrmPrintf(g_pStdErr, "Attached!\n");
|
---|
| 321 | RTStrmFlush(g_pStdErr);
|
---|
[1] | 322 | return true;
|
---|
| 323 | }
|
---|
| 324 |
|
---|
| 325 | /* next */
|
---|
| 326 | if (!(cWait % 10))
|
---|
| 327 | {
|
---|
[23] | 328 | RTStrmPrintf(g_pStdErr, "%d.", cWait / 10);
|
---|
| 329 | RTStrmFlush(g_pStdErr);
|
---|
[1] | 330 | }
|
---|
| 331 | cWait--;
|
---|
| 332 | }
|
---|
[2261] | 333 | #endif
|
---|
[1] | 334 |
|
---|
[23] | 335 | RTStrmPrintf(g_pStdErr, "Stopping the VM!\n");
|
---|
| 336 | RTStrmFlush(g_pStdErr);
|
---|
[1] | 337 | return false;
|
---|
| 338 | }
|
---|
| 339 |
|
---|
| 340 |
|
---|
| 341 | /**
|
---|
| 342 | * Forced action callback.
|
---|
| 343 | * The VMM will call this from it's main loop when VM_FF_DBGF is set.
|
---|
| 344 | *
|
---|
| 345 | * The function checks and executes pending commands from the debugger.
|
---|
| 346 | *
|
---|
| 347 | * @returns VINF_SUCCESS normally.
|
---|
[33540] | 348 | * @returns VERR_DBGF_RAISE_FATAL_ERROR to pretend a fatal error happened.
|
---|
[41800] | 349 | * @param pVM Pointer to the VM.
|
---|
[1] | 350 | */
|
---|
[44399] | 351 | VMMR3_INT_DECL(int) DBGFR3VMMForcedAction(PVM pVM)
|
---|
[1] | 352 | {
|
---|
[19423] | 353 | int rc = VINF_SUCCESS;
|
---|
[18927] | 354 |
|
---|
[46420] | 355 | if (VM_FF_TEST_AND_CLEAR(pVM, VM_FF_DBGF))
|
---|
[1] | 356 | {
|
---|
[19423] | 357 | PVMCPU pVCpu = VMMGetCpu(pVM);
|
---|
[1] | 358 |
|
---|
| 359 | /*
|
---|
[45701] | 360 | * Command pending? Process it.
|
---|
[1] | 361 | */
|
---|
[19423] | 362 | if (pVM->dbgf.s.enmVMMCmd != DBGFCMD_NO_COMMAND)
|
---|
| 363 | {
|
---|
| 364 | bool fResumeExecution;
|
---|
| 365 | DBGFCMDDATA CmdData = pVM->dbgf.s.VMMCmdData;
|
---|
| 366 | DBGFCMD enmCmd = dbgfR3SetCmd(pVM, DBGFCMD_NO_COMMAND);
|
---|
| 367 | rc = dbgfR3VMMCmd(pVM, enmCmd, &CmdData, &fResumeExecution);
|
---|
| 368 | if (!fResumeExecution)
|
---|
| 369 | rc = dbgfR3VMMWait(pVM);
|
---|
| 370 | }
|
---|
[1] | 371 | }
|
---|
| 372 | return rc;
|
---|
| 373 | }
|
---|
| 374 |
|
---|
| 375 |
|
---|
| 376 | /**
|
---|
| 377 | * Flag whether the event implies that we're stopped in the hypervisor code
|
---|
| 378 | * and have to block certain operations.
|
---|
| 379 | *
|
---|
[41783] | 380 | * @param pVM Pointer to the VM.
|
---|
[1] | 381 | * @param enmEvent The event.
|
---|
| 382 | */
|
---|
| 383 | static void dbgfR3EventSetStoppedInHyperFlag(PVM pVM, DBGFEVENTTYPE enmEvent)
|
---|
| 384 | {
|
---|
| 385 | switch (enmEvent)
|
---|
| 386 | {
|
---|
| 387 | case DBGFEVENT_STEPPED_HYPER:
|
---|
| 388 | case DBGFEVENT_ASSERTION_HYPER:
|
---|
| 389 | case DBGFEVENT_BREAKPOINT_HYPER:
|
---|
| 390 | pVM->dbgf.s.fStoppedInHyper = true;
|
---|
| 391 | break;
|
---|
| 392 | default:
|
---|
| 393 | pVM->dbgf.s.fStoppedInHyper = false;
|
---|
| 394 | break;
|
---|
| 395 | }
|
---|
| 396 | }
|
---|
| 397 |
|
---|
| 398 |
|
---|
| 399 | /**
|
---|
[18927] | 400 | * Try to determine the event context.
|
---|
[1] | 401 | *
|
---|
| 402 | * @returns debug event context.
|
---|
[41783] | 403 | * @param pVM Pointer to the VM.
|
---|
[1] | 404 | */
|
---|
| 405 | static DBGFEVENTCTX dbgfR3FigureEventCtx(PVM pVM)
|
---|
| 406 | {
|
---|
[18927] | 407 | /** @todo SMP support! */
|
---|
| 408 | PVMCPU pVCpu = &pVM->aCpus[0];
|
---|
| 409 |
|
---|
| 410 | switch (EMGetState(pVCpu))
|
---|
[1] | 411 | {
|
---|
| 412 | case EMSTATE_RAW:
|
---|
| 413 | case EMSTATE_DEBUG_GUEST_RAW:
|
---|
| 414 | return DBGFEVENTCTX_RAW;
|
---|
| 415 |
|
---|
| 416 | case EMSTATE_REM:
|
---|
| 417 | case EMSTATE_DEBUG_GUEST_REM:
|
---|
| 418 | return DBGFEVENTCTX_REM;
|
---|
| 419 |
|
---|
| 420 | case EMSTATE_DEBUG_HYPER:
|
---|
| 421 | case EMSTATE_GURU_MEDITATION:
|
---|
| 422 | return DBGFEVENTCTX_HYPER;
|
---|
| 423 |
|
---|
| 424 | default:
|
---|
| 425 | return DBGFEVENTCTX_OTHER;
|
---|
| 426 | }
|
---|
| 427 | }
|
---|
| 428 |
|
---|
| 429 | /**
|
---|
| 430 | * The common event prologue code.
|
---|
[33540] | 431 | * It will set the 'stopped-in-hyper' flag, make sure someone is attached,
|
---|
[1] | 432 | * and perhaps process any high priority pending actions (none yet).
|
---|
| 433 | *
|
---|
| 434 | * @returns VBox status.
|
---|
[41783] | 435 | * @param pVM Pointer to the VM.
|
---|
[1] | 436 | * @param enmEvent The event to be sent.
|
---|
| 437 | */
|
---|
| 438 | static int dbgfR3EventPrologue(PVM pVM, DBGFEVENTTYPE enmEvent)
|
---|
| 439 | {
|
---|
[19286] | 440 | /** @todo SMP */
|
---|
[19259] | 441 | PVMCPU pVCpu = VMMGetCpu(pVM);
|
---|
[18927] | 442 |
|
---|
[1] | 443 | /*
|
---|
| 444 | * Check if a debugger is attached.
|
---|
| 445 | */
|
---|
| 446 | if ( !pVM->dbgf.s.fAttached
|
---|
| 447 | && !dbgfR3WaitForAttach(pVM, enmEvent))
|
---|
| 448 | {
|
---|
| 449 | Log(("DBGFR3VMMEventSrc: enmEvent=%d - debugger not attached\n", enmEvent));
|
---|
| 450 | return VERR_DBGF_NOT_ATTACHED;
|
---|
| 451 | }
|
---|
| 452 |
|
---|
| 453 | /*
|
---|
| 454 | * Sync back the state from the REM.
|
---|
| 455 | */
|
---|
| 456 | dbgfR3EventSetStoppedInHyperFlag(pVM, enmEvent);
|
---|
[40274] | 457 | #ifdef VBOX_WITH_REM
|
---|
[1] | 458 | if (!pVM->dbgf.s.fStoppedInHyper)
|
---|
[18927] | 459 | REMR3StateUpdate(pVM, pVCpu);
|
---|
[40274] | 460 | #endif
|
---|
[1] | 461 |
|
---|
| 462 | /*
|
---|
| 463 | * Look thru pending commands and finish those which make sense now.
|
---|
| 464 | */
|
---|
| 465 | /** @todo Process/purge pending commands. */
|
---|
| 466 | //int rc = DBGFR3VMMForcedAction(pVM);
|
---|
| 467 | return VINF_SUCCESS;
|
---|
| 468 | }
|
---|
| 469 |
|
---|
| 470 |
|
---|
| 471 | /**
|
---|
| 472 | * Sends the event in the event buffer.
|
---|
| 473 | *
|
---|
| 474 | * @returns VBox status code.
|
---|
[41783] | 475 | * @param pVM Pointer to the VM.
|
---|
[1] | 476 | */
|
---|
| 477 | static int dbgfR3SendEvent(PVM pVM)
|
---|
| 478 | {
|
---|
| 479 | int rc = RTSemPing(&pVM->dbgf.s.PingPong);
|
---|
[13816] | 480 | if (RT_SUCCESS(rc))
|
---|
[12663] | 481 | rc = dbgfR3VMMWait(pVM);
|
---|
[1] | 482 |
|
---|
| 483 | pVM->dbgf.s.fStoppedInHyper = false;
|
---|
| 484 | /** @todo sync VMM -> REM after exitting the debugger. everything may change while in the debugger! */
|
---|
| 485 | return rc;
|
---|
| 486 | }
|
---|
| 487 |
|
---|
| 488 |
|
---|
| 489 | /**
|
---|
| 490 | * Send a generic debugger event which takes no data.
|
---|
| 491 | *
|
---|
| 492 | * @returns VBox status.
|
---|
[41783] | 493 | * @param pVM Pointer to the VM.
|
---|
[1] | 494 | * @param enmEvent The event to send.
|
---|
[44399] | 495 | * @internal
|
---|
[1] | 496 | */
|
---|
[12989] | 497 | VMMR3DECL(int) DBGFR3Event(PVM pVM, DBGFEVENTTYPE enmEvent)
|
---|
[1] | 498 | {
|
---|
| 499 | int rc = dbgfR3EventPrologue(pVM, enmEvent);
|
---|
[13816] | 500 | if (RT_FAILURE(rc))
|
---|
[1] | 501 | return rc;
|
---|
| 502 |
|
---|
| 503 | /*
|
---|
| 504 | * Send the event and process the reply communication.
|
---|
| 505 | */
|
---|
| 506 | pVM->dbgf.s.DbgEvent.enmType = enmEvent;
|
---|
| 507 | pVM->dbgf.s.DbgEvent.enmCtx = dbgfR3FigureEventCtx(pVM);
|
---|
| 508 | return dbgfR3SendEvent(pVM);
|
---|
| 509 | }
|
---|
| 510 |
|
---|
| 511 |
|
---|
| 512 | /**
|
---|
| 513 | * Send a debugger event which takes the full source file location.
|
---|
| 514 | *
|
---|
| 515 | * @returns VBox status.
|
---|
[41783] | 516 | * @param pVM Pointer to the VM.
|
---|
[1] | 517 | * @param enmEvent The event to send.
|
---|
| 518 | * @param pszFile Source file.
|
---|
| 519 | * @param uLine Line number in source file.
|
---|
| 520 | * @param pszFunction Function name.
|
---|
| 521 | * @param pszFormat Message which accompanies the event.
|
---|
| 522 | * @param ... Message arguments.
|
---|
[44399] | 523 | * @internal
|
---|
[1] | 524 | */
|
---|
[12989] | 525 | VMMR3DECL(int) DBGFR3EventSrc(PVM pVM, DBGFEVENTTYPE enmEvent, const char *pszFile, unsigned uLine, const char *pszFunction, const char *pszFormat, ...)
|
---|
[1] | 526 | {
|
---|
| 527 | va_list args;
|
---|
| 528 | va_start(args, pszFormat);
|
---|
| 529 | int rc = DBGFR3EventSrcV(pVM, enmEvent, pszFile, uLine, pszFunction, pszFormat, args);
|
---|
| 530 | va_end(args);
|
---|
| 531 | return rc;
|
---|
| 532 | }
|
---|
| 533 |
|
---|
| 534 |
|
---|
| 535 | /**
|
---|
| 536 | * Send a debugger event which takes the full source file location.
|
---|
| 537 | *
|
---|
| 538 | * @returns VBox status.
|
---|
[41783] | 539 | * @param pVM Pointer to the VM.
|
---|
[1] | 540 | * @param enmEvent The event to send.
|
---|
| 541 | * @param pszFile Source file.
|
---|
| 542 | * @param uLine Line number in source file.
|
---|
| 543 | * @param pszFunction Function name.
|
---|
| 544 | * @param pszFormat Message which accompanies the event.
|
---|
| 545 | * @param args Message arguments.
|
---|
[44399] | 546 | * @internal
|
---|
[1] | 547 | */
|
---|
[12989] | 548 | VMMR3DECL(int) DBGFR3EventSrcV(PVM pVM, DBGFEVENTTYPE enmEvent, const char *pszFile, unsigned uLine, const char *pszFunction, const char *pszFormat, va_list args)
|
---|
[1] | 549 | {
|
---|
| 550 | int rc = dbgfR3EventPrologue(pVM, enmEvent);
|
---|
[13816] | 551 | if (RT_FAILURE(rc))
|
---|
[1] | 552 | return rc;
|
---|
| 553 |
|
---|
| 554 | /*
|
---|
| 555 | * Format the message.
|
---|
| 556 | */
|
---|
| 557 | char *pszMessage = NULL;
|
---|
| 558 | char szMessage[8192];
|
---|
| 559 | if (pszFormat && *pszFormat)
|
---|
| 560 | {
|
---|
| 561 | pszMessage = &szMessage[0];
|
---|
| 562 | RTStrPrintfV(szMessage, sizeof(szMessage), pszFormat, args);
|
---|
| 563 | }
|
---|
| 564 |
|
---|
| 565 | /*
|
---|
| 566 | * Send the event and process the reply communication.
|
---|
| 567 | */
|
---|
| 568 | pVM->dbgf.s.DbgEvent.enmType = enmEvent;
|
---|
| 569 | pVM->dbgf.s.DbgEvent.enmCtx = dbgfR3FigureEventCtx(pVM);
|
---|
| 570 | pVM->dbgf.s.DbgEvent.u.Src.pszFile = pszFile;
|
---|
| 571 | pVM->dbgf.s.DbgEvent.u.Src.uLine = uLine;
|
---|
| 572 | pVM->dbgf.s.DbgEvent.u.Src.pszFunction = pszFunction;
|
---|
| 573 | pVM->dbgf.s.DbgEvent.u.Src.pszMessage = pszMessage;
|
---|
| 574 | return dbgfR3SendEvent(pVM);
|
---|
| 575 | }
|
---|
| 576 |
|
---|
| 577 |
|
---|
| 578 | /**
|
---|
| 579 | * Send a debugger event which takes the two assertion messages.
|
---|
| 580 | *
|
---|
| 581 | * @returns VBox status.
|
---|
[41783] | 582 | * @param pVM Pointer to the VM.
|
---|
[1] | 583 | * @param enmEvent The event to send.
|
---|
| 584 | * @param pszMsg1 First assertion message.
|
---|
| 585 | * @param pszMsg2 Second assertion message.
|
---|
| 586 | */
|
---|
[44399] | 587 | VMMR3_INT_DECL(int) DBGFR3EventAssertion(PVM pVM, DBGFEVENTTYPE enmEvent, const char *pszMsg1, const char *pszMsg2)
|
---|
[1] | 588 | {
|
---|
| 589 | int rc = dbgfR3EventPrologue(pVM, enmEvent);
|
---|
[13816] | 590 | if (RT_FAILURE(rc))
|
---|
[1] | 591 | return rc;
|
---|
| 592 |
|
---|
| 593 | /*
|
---|
| 594 | * Send the event and process the reply communication.
|
---|
| 595 | */
|
---|
| 596 | pVM->dbgf.s.DbgEvent.enmType = enmEvent;
|
---|
| 597 | pVM->dbgf.s.DbgEvent.enmCtx = dbgfR3FigureEventCtx(pVM);
|
---|
| 598 | pVM->dbgf.s.DbgEvent.u.Assert.pszMsg1 = pszMsg1;
|
---|
| 599 | pVM->dbgf.s.DbgEvent.u.Assert.pszMsg2 = pszMsg2;
|
---|
| 600 | return dbgfR3SendEvent(pVM);
|
---|
| 601 | }
|
---|
| 602 |
|
---|
| 603 |
|
---|
| 604 | /**
|
---|
| 605 | * Breakpoint was hit somewhere.
|
---|
| 606 | * Figure out which breakpoint it is and notify the debugger.
|
---|
| 607 | *
|
---|
| 608 | * @returns VBox status.
|
---|
[41783] | 609 | * @param pVM Pointer to the VM.
|
---|
[1] | 610 | * @param enmEvent DBGFEVENT_BREAKPOINT_HYPER or DBGFEVENT_BREAKPOINT.
|
---|
| 611 | */
|
---|
[44399] | 612 | VMMR3_INT_DECL(int) DBGFR3EventBreakpoint(PVM pVM, DBGFEVENTTYPE enmEvent)
|
---|
[1] | 613 | {
|
---|
| 614 | int rc = dbgfR3EventPrologue(pVM, enmEvent);
|
---|
[13816] | 615 | if (RT_FAILURE(rc))
|
---|
[1] | 616 | return rc;
|
---|
| 617 |
|
---|
| 618 | /*
|
---|
| 619 | * Send the event and process the reply communication.
|
---|
| 620 | */
|
---|
[19286] | 621 | /** @todo SMP */
|
---|
| 622 | PVMCPU pVCpu = VMMGetCpu0(pVM);
|
---|
| 623 |
|
---|
[1] | 624 | pVM->dbgf.s.DbgEvent.enmType = enmEvent;
|
---|
[19286] | 625 | RTUINT iBp = pVM->dbgf.s.DbgEvent.u.Bp.iBp = pVCpu->dbgf.s.iActiveBp;
|
---|
| 626 | pVCpu->dbgf.s.iActiveBp = ~0U;
|
---|
[1] | 627 | if (iBp != ~0U)
|
---|
| 628 | pVM->dbgf.s.DbgEvent.enmCtx = DBGFEVENTCTX_RAW;
|
---|
| 629 | else
|
---|
| 630 | {
|
---|
| 631 | /* REM breakpoints has be been searched for. */
|
---|
| 632 | #if 0 /** @todo get flat PC api! */
|
---|
| 633 | uint32_t eip = CPUMGetGuestEIP(pVM);
|
---|
| 634 | #else
|
---|
[18927] | 635 | /* @todo SMP support!! */
|
---|
| 636 | PCPUMCTX pCtx = CPUMQueryGuestCtxPtr(VMMGetCpu(pVM));
|
---|
[41906] | 637 | RTGCPTR eip = pCtx->rip + pCtx->cs.u64Base;
|
---|
[1] | 638 | #endif
|
---|
[42833] | 639 | for (size_t i = 0; i < RT_ELEMENTS(pVM->dbgf.s.aBreakpoints); i++)
|
---|
| 640 | if ( pVM->dbgf.s.aBreakpoints[i].enmType == DBGFBPTYPE_REM
|
---|
| 641 | && pVM->dbgf.s.aBreakpoints[i].GCPtr == eip)
|
---|
[1] | 642 | {
|
---|
[42833] | 643 | pVM->dbgf.s.DbgEvent.u.Bp.iBp = pVM->dbgf.s.aBreakpoints[i].iBp;
|
---|
[1] | 644 | break;
|
---|
| 645 | }
|
---|
| 646 | AssertMsg(pVM->dbgf.s.DbgEvent.u.Bp.iBp != ~0U, ("eip=%08x\n", eip));
|
---|
| 647 | pVM->dbgf.s.DbgEvent.enmCtx = DBGFEVENTCTX_REM;
|
---|
| 648 | }
|
---|
| 649 | return dbgfR3SendEvent(pVM);
|
---|
| 650 | }
|
---|
| 651 |
|
---|
| 652 |
|
---|
| 653 | /**
|
---|
| 654 | * Waits for the debugger to respond.
|
---|
| 655 | *
|
---|
| 656 | * @returns VBox status. (clearify)
|
---|
[41800] | 657 | * @param pVM Pointer to the VM.
|
---|
[1] | 658 | */
|
---|
[12663] | 659 | static int dbgfR3VMMWait(PVM pVM)
|
---|
[1] | 660 | {
|
---|
[18927] | 661 | PVMCPU pVCpu = VMMGetCpu(pVM);
|
---|
| 662 |
|
---|
[12663] | 663 | LogFlow(("dbgfR3VMMWait:\n"));
|
---|
[1] | 664 | int rcRet = VINF_SUCCESS;
|
---|
| 665 |
|
---|
| 666 | /*
|
---|
| 667 | * Waits for the debugger to reply (i.e. issue an command).
|
---|
| 668 | */
|
---|
| 669 | for (;;)
|
---|
| 670 | {
|
---|
| 671 | /*
|
---|
| 672 | * Wait.
|
---|
| 673 | */
|
---|
[23925] | 674 | uint32_t cPollHack = 1; /** @todo this interface is horrible now that we're using lots of VMR3ReqCall stuff all over DBGF. */
|
---|
[1] | 675 | for (;;)
|
---|
| 676 | {
|
---|
[23145] | 677 | int rc;
|
---|
[46420] | 678 | if ( !VM_FF_IS_PENDING(pVM, VM_FF_EMT_RENDEZVOUS | VM_FF_REQUEST)
|
---|
| 679 | && !VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_REQUEST))
|
---|
[1] | 680 | {
|
---|
[24999] | 681 | rc = RTSemPingWait(&pVM->dbgf.s.PingPong, cPollHack);
|
---|
[23145] | 682 | if (RT_SUCCESS(rc))
|
---|
| 683 | break;
|
---|
| 684 | if (rc != VERR_TIMEOUT)
|
---|
| 685 | {
|
---|
| 686 | LogFlow(("dbgfR3VMMWait: returns %Rrc\n", rc));
|
---|
| 687 | return rc;
|
---|
| 688 | }
|
---|
[1] | 689 | }
|
---|
| 690 |
|
---|
[46420] | 691 | if (VM_FF_IS_PENDING(pVM, VM_FF_EMT_RENDEZVOUS))
|
---|
[23925] | 692 | {
|
---|
[23145] | 693 | rc = VMMR3EmtRendezvousFF(pVM, pVCpu);
|
---|
[23925] | 694 | cPollHack = 1;
|
---|
| 695 | }
|
---|
[46420] | 696 | else if ( VM_FF_IS_PENDING(pVM, VM_FF_REQUEST)
|
---|
| 697 | || VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_REQUEST))
|
---|
[1] | 698 | {
|
---|
[12663] | 699 | LogFlow(("dbgfR3VMMWait: Processes requests...\n"));
|
---|
[38838] | 700 | rc = VMR3ReqProcessU(pVM->pUVM, VMCPUID_ANY, false /*fPriorityOnly*/);
|
---|
[19306] | 701 | if (rc == VINF_SUCCESS)
|
---|
[38838] | 702 | rc = VMR3ReqProcessU(pVM->pUVM, pVCpu->idCpu, false /*fPriorityOnly*/);
|
---|
[13818] | 703 | LogFlow(("dbgfR3VMMWait: VMR3ReqProcess -> %Rrc rcRet=%Rrc\n", rc, rcRet));
|
---|
[23925] | 704 | cPollHack = 1;
|
---|
[23145] | 705 | }
|
---|
| 706 | else
|
---|
[23925] | 707 | {
|
---|
[23145] | 708 | rc = VINF_SUCCESS;
|
---|
[23925] | 709 | if (cPollHack < 120)
|
---|
| 710 | cPollHack++;
|
---|
| 711 | }
|
---|
[23145] | 712 |
|
---|
| 713 | if (rc >= VINF_EM_FIRST && rc <= VINF_EM_LAST)
|
---|
| 714 | {
|
---|
| 715 | switch (rc)
|
---|
[1] | 716 | {
|
---|
[23145] | 717 | case VINF_EM_DBG_BREAKPOINT:
|
---|
| 718 | case VINF_EM_DBG_STEPPED:
|
---|
| 719 | case VINF_EM_DBG_STEP:
|
---|
| 720 | case VINF_EM_DBG_STOP:
|
---|
| 721 | AssertMsgFailed(("rc=%Rrc\n", rc));
|
---|
| 722 | break;
|
---|
[1] | 723 |
|
---|
[23145] | 724 | /* return straight away */
|
---|
| 725 | case VINF_EM_TERMINATE:
|
---|
| 726 | case VINF_EM_OFF:
|
---|
| 727 | LogFlow(("dbgfR3VMMWait: returns %Rrc\n", rc));
|
---|
| 728 | return rc;
|
---|
[1] | 729 |
|
---|
[23145] | 730 | /* remember return code. */
|
---|
| 731 | default:
|
---|
| 732 | AssertReleaseMsgFailed(("rc=%Rrc is not in the switch!\n", rc));
|
---|
| 733 | case VINF_EM_RESET:
|
---|
| 734 | case VINF_EM_SUSPEND:
|
---|
| 735 | case VINF_EM_HALT:
|
---|
| 736 | case VINF_EM_RESUME:
|
---|
| 737 | case VINF_EM_RESCHEDULE:
|
---|
| 738 | case VINF_EM_RESCHEDULE_REM:
|
---|
| 739 | case VINF_EM_RESCHEDULE_RAW:
|
---|
| 740 | if (rc < rcRet || rcRet == VINF_SUCCESS)
|
---|
| 741 | rcRet = rc;
|
---|
| 742 | break;
|
---|
[1] | 743 | }
|
---|
| 744 | }
|
---|
[23145] | 745 | else if (RT_FAILURE(rc))
|
---|
| 746 | {
|
---|
| 747 | LogFlow(("dbgfR3VMMWait: returns %Rrc\n", rc));
|
---|
| 748 | return rc;
|
---|
| 749 | }
|
---|
[1] | 750 | }
|
---|
| 751 |
|
---|
| 752 | /*
|
---|
| 753 | * Process the command.
|
---|
| 754 | */
|
---|
| 755 | bool fResumeExecution;
|
---|
| 756 | DBGFCMDDATA CmdData = pVM->dbgf.s.VMMCmdData;
|
---|
[12663] | 757 | DBGFCMD enmCmd = dbgfR3SetCmd(pVM, DBGFCMD_NO_COMMAND);
|
---|
| 758 | int rc = dbgfR3VMMCmd(pVM, enmCmd, &CmdData, &fResumeExecution);
|
---|
[1] | 759 | if (fResumeExecution)
|
---|
| 760 | {
|
---|
[13816] | 761 | if (RT_FAILURE(rc))
|
---|
[1] | 762 | rcRet = rc;
|
---|
| 763 | else if ( rc >= VINF_EM_FIRST
|
---|
[2507] | 764 | && rc <= VINF_EM_LAST
|
---|
[1] | 765 | && (rc < rcRet || rcRet == VINF_SUCCESS))
|
---|
| 766 | rcRet = rc;
|
---|
[13818] | 767 | LogFlow(("dbgfR3VMMWait: returns %Rrc\n", rcRet));
|
---|
[1] | 768 | return rcRet;
|
---|
| 769 | }
|
---|
| 770 | }
|
---|
| 771 | }
|
---|
| 772 |
|
---|
| 773 |
|
---|
| 774 | /**
|
---|
| 775 | * Executes command from debugger.
|
---|
| 776 | * The caller is responsible for waiting or resuming execution based on the
|
---|
| 777 | * value returned in the *pfResumeExecution indicator.
|
---|
| 778 | *
|
---|
| 779 | * @returns VBox status. (clearify!)
|
---|
[41800] | 780 | * @param pVM Pointer to the VM.
|
---|
[1] | 781 | * @param enmCmd The command in question.
|
---|
| 782 | * @param pCmdData Pointer to the command data.
|
---|
| 783 | * @param pfResumeExecution Where to store the resume execution / continue waiting indicator.
|
---|
| 784 | */
|
---|
[12663] | 785 | static int dbgfR3VMMCmd(PVM pVM, DBGFCMD enmCmd, PDBGFCMDDATA pCmdData, bool *pfResumeExecution)
|
---|
[1] | 786 | {
|
---|
| 787 | bool fSendEvent;
|
---|
| 788 | bool fResume;
|
---|
| 789 | int rc = VINF_SUCCESS;
|
---|
| 790 |
|
---|
[39078] | 791 | NOREF(pCmdData); /* for later */
|
---|
| 792 |
|
---|
[1] | 793 | switch (enmCmd)
|
---|
| 794 | {
|
---|
| 795 | /*
|
---|
| 796 | * Halt is answered by an event say that we've halted.
|
---|
| 797 | */
|
---|
| 798 | case DBGFCMD_HALT:
|
---|
| 799 | {
|
---|
| 800 | pVM->dbgf.s.DbgEvent.enmType = DBGFEVENT_HALT_DONE;
|
---|
| 801 | pVM->dbgf.s.DbgEvent.enmCtx = dbgfR3FigureEventCtx(pVM);
|
---|
| 802 | fSendEvent = true;
|
---|
| 803 | fResume = false;
|
---|
| 804 | break;
|
---|
| 805 | }
|
---|
| 806 |
|
---|
| 807 |
|
---|
| 808 | /*
|
---|
| 809 | * Resume is not answered we'll just resume execution.
|
---|
| 810 | */
|
---|
| 811 | case DBGFCMD_GO:
|
---|
| 812 | {
|
---|
[45692] | 813 | /** @todo SMP */
|
---|
| 814 | PVMCPU pVCpu = VMMGetCpu0(pVM);
|
---|
| 815 | pVCpu->dbgf.s.fSingleSteppingRaw = false;
|
---|
[1] | 816 | fSendEvent = false;
|
---|
| 817 | fResume = true;
|
---|
| 818 | break;
|
---|
| 819 | }
|
---|
| 820 |
|
---|
| 821 | /** @todo implement (and define) the rest of the commands. */
|
---|
| 822 |
|
---|
| 823 | /*
|
---|
| 824 | * Disable breakpoints and stuff.
|
---|
| 825 | * Send an everythings cool event to the debugger thread and resume execution.
|
---|
| 826 | */
|
---|
| 827 | case DBGFCMD_DETACH_DEBUGGER:
|
---|
| 828 | {
|
---|
[12875] | 829 | ASMAtomicWriteBool(&pVM->dbgf.s.fAttached, false);
|
---|
[1] | 830 | pVM->dbgf.s.DbgEvent.enmType = DBGFEVENT_DETACH_DONE;
|
---|
| 831 | pVM->dbgf.s.DbgEvent.enmCtx = DBGFEVENTCTX_OTHER;
|
---|
| 832 | fSendEvent = true;
|
---|
| 833 | fResume = true;
|
---|
| 834 | break;
|
---|
| 835 | }
|
---|
| 836 |
|
---|
| 837 | /*
|
---|
[12875] | 838 | * The debugger has detached successfully.
|
---|
| 839 | * There is no reply to this event.
|
---|
| 840 | */
|
---|
| 841 | case DBGFCMD_DETACHED_DEBUGGER:
|
---|
| 842 | {
|
---|
| 843 | fSendEvent = false;
|
---|
| 844 | fResume = true;
|
---|
| 845 | break;
|
---|
| 846 | }
|
---|
| 847 |
|
---|
| 848 | /*
|
---|
[1] | 849 | * Single step, with trace into.
|
---|
| 850 | */
|
---|
| 851 | case DBGFCMD_SINGLE_STEP:
|
---|
| 852 | {
|
---|
| 853 | Log2(("Single step\n"));
|
---|
| 854 | rc = VINF_EM_DBG_STEP;
|
---|
[19286] | 855 | /** @todo SMP */
|
---|
| 856 | PVMCPU pVCpu = VMMGetCpu0(pVM);
|
---|
| 857 | pVCpu->dbgf.s.fSingleSteppingRaw = true;
|
---|
[1] | 858 | fSendEvent = false;
|
---|
| 859 | fResume = true;
|
---|
| 860 | break;
|
---|
| 861 | }
|
---|
| 862 |
|
---|
| 863 | /*
|
---|
| 864 | * Default is to send an invalid command event.
|
---|
| 865 | */
|
---|
| 866 | default:
|
---|
| 867 | {
|
---|
| 868 | pVM->dbgf.s.DbgEvent.enmType = DBGFEVENT_INVALID_COMMAND;
|
---|
| 869 | pVM->dbgf.s.DbgEvent.enmCtx = dbgfR3FigureEventCtx(pVM);
|
---|
| 870 | fSendEvent = true;
|
---|
| 871 | fResume = false;
|
---|
| 872 | break;
|
---|
| 873 | }
|
---|
| 874 | }
|
---|
| 875 |
|
---|
| 876 | /*
|
---|
| 877 | * Send pending event.
|
---|
| 878 | */
|
---|
| 879 | if (fSendEvent)
|
---|
| 880 | {
|
---|
| 881 | Log2(("DBGF: Emulation thread: sending event %d\n", pVM->dbgf.s.DbgEvent.enmType));
|
---|
| 882 | int rc2 = RTSemPing(&pVM->dbgf.s.PingPong);
|
---|
[13816] | 883 | if (RT_FAILURE(rc2))
|
---|
[1] | 884 | {
|
---|
| 885 | AssertRC(rc2);
|
---|
| 886 | *pfResumeExecution = true;
|
---|
| 887 | return rc2;
|
---|
| 888 | }
|
---|
| 889 | }
|
---|
| 890 |
|
---|
| 891 | /*
|
---|
| 892 | * Return.
|
---|
| 893 | */
|
---|
| 894 | *pfResumeExecution = fResume;
|
---|
| 895 | return rc;
|
---|
| 896 | }
|
---|
| 897 |
|
---|
| 898 |
|
---|
| 899 | /**
|
---|
| 900 | * Attaches a debugger to the specified VM.
|
---|
| 901 | *
|
---|
| 902 | * Only one debugger at a time.
|
---|
| 903 | *
|
---|
| 904 | * @returns VBox status code.
|
---|
[44399] | 905 | * @param pUVM The user mode VM handle.
|
---|
[1] | 906 | */
|
---|
[44399] | 907 | VMMR3DECL(int) DBGFR3Attach(PUVM pUVM)
|
---|
[1] | 908 | {
|
---|
[45006] | 909 | UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
|
---|
[44399] | 910 | PVM pVM = pUVM->pVM;
|
---|
[45006] | 911 | VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
|
---|
[12875] | 912 |
|
---|
| 913 | /*
|
---|
| 914 | * Call the VM, use EMT for serialization.
|
---|
| 915 | */
|
---|
[23012] | 916 | /** @todo SMP */
|
---|
| 917 | return VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)dbgfR3Attach, 1, pVM);
|
---|
[12875] | 918 | }
|
---|
| 919 |
|
---|
| 920 |
|
---|
| 921 | /**
|
---|
| 922 | * EMT worker for DBGFR3Attach.
|
---|
| 923 | *
|
---|
| 924 | * @returns VBox status code.
|
---|
[41777] | 925 | * @param pVM Pointer to the VM.
|
---|
[12875] | 926 | */
|
---|
| 927 | static DECLCALLBACK(int) dbgfR3Attach(PVM pVM)
|
---|
| 928 | {
|
---|
[1] | 929 | if (pVM->dbgf.s.fAttached)
|
---|
| 930 | {
|
---|
[12875] | 931 | Log(("dbgR3Attach: Debugger already attached\n"));
|
---|
[1] | 932 | return VERR_DBGF_ALREADY_ATTACHED;
|
---|
| 933 | }
|
---|
| 934 |
|
---|
| 935 | /*
|
---|
| 936 | * Create the Ping-Pong structure.
|
---|
| 937 | */
|
---|
| 938 | int rc = RTSemPingPongInit(&pVM->dbgf.s.PingPong);
|
---|
[12875] | 939 | AssertRCReturn(rc, rc);
|
---|
[1] | 940 |
|
---|
| 941 | /*
|
---|
| 942 | * Set the attached flag.
|
---|
| 943 | */
|
---|
[12875] | 944 | ASMAtomicWriteBool(&pVM->dbgf.s.fAttached, true);
|
---|
[1] | 945 | return VINF_SUCCESS;
|
---|
| 946 | }
|
---|
| 947 |
|
---|
| 948 |
|
---|
| 949 | /**
|
---|
| 950 | * Detaches a debugger from the specified VM.
|
---|
| 951 | *
|
---|
| 952 | * Caller must be attached to the VM.
|
---|
| 953 | *
|
---|
| 954 | * @returns VBox status code.
|
---|
[44399] | 955 | * @param pUVM The user mode VM handle.
|
---|
[1] | 956 | */
|
---|
[44399] | 957 | VMMR3DECL(int) DBGFR3Detach(PUVM pUVM)
|
---|
[1] | 958 | {
|
---|
[12875] | 959 | LogFlow(("DBGFR3Detach:\n"));
|
---|
| 960 | int rc;
|
---|
[8823] | 961 |
|
---|
[1] | 962 | /*
|
---|
[46155] | 963 | * Validate input. The UVM handle shall be valid, the VM handle might be
|
---|
| 964 | * in the processes of being destroyed already, so deal quietly with that.
|
---|
[1] | 965 | */
|
---|
[45006] | 966 | UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
|
---|
[44399] | 967 | PVM pVM = pUVM->pVM;
|
---|
[46155] | 968 | if (!VM_IS_VALID_EXT(pVM))
|
---|
| 969 | return VERR_INVALID_VM_HANDLE;
|
---|
| 970 |
|
---|
| 971 | /*
|
---|
| 972 | * Check if attached.
|
---|
| 973 | */
|
---|
[46159] | 974 | if (!pVM->dbgf.s.fAttached)
|
---|
| 975 | return VERR_DBGF_NOT_ATTACHED;
|
---|
[1] | 976 |
|
---|
| 977 | /*
|
---|
[12877] | 978 | * Try send the detach command.
|
---|
| 979 | * Keep in mind that we might be racing EMT, so, be extra careful.
|
---|
[12875] | 980 | */
|
---|
[12877] | 981 | DBGFCMD enmCmd = dbgfR3SetCmd(pVM, DBGFCMD_DETACH_DEBUGGER);
|
---|
[12875] | 982 | if (RTSemPongIsSpeaker(&pVM->dbgf.s.PingPong))
|
---|
[1] | 983 | {
|
---|
[12875] | 984 | rc = RTSemPong(&pVM->dbgf.s.PingPong);
|
---|
| 985 | AssertMsgRCReturn(rc, ("Failed to signal emulation thread. rc=%Rrc\n", rc), rc);
|
---|
[12877] | 986 | LogRel(("DBGFR3Detach: enmCmd=%d (pong -> ping)\n", enmCmd));
|
---|
[1] | 987 | }
|
---|
| 988 |
|
---|
| 989 | /*
|
---|
[12875] | 990 | * Wait for the OK event.
|
---|
[1] | 991 | */
|
---|
[12881] | 992 | rc = RTSemPongWait(&pVM->dbgf.s.PingPong, RT_INDEFINITE_WAIT);
|
---|
[12875] | 993 | AssertLogRelMsgRCReturn(rc, ("Wait on detach command failed, rc=%Rrc\n", rc), rc);
|
---|
[1] | 994 |
|
---|
| 995 | /*
|
---|
[12875] | 996 | * Send the notification command indicating that we're really done.
|
---|
[1] | 997 | */
|
---|
[12875] | 998 | enmCmd = dbgfR3SetCmd(pVM, DBGFCMD_DETACHED_DEBUGGER);
|
---|
| 999 | rc = RTSemPong(&pVM->dbgf.s.PingPong);
|
---|
| 1000 | AssertMsgRCReturn(rc, ("Failed to signal emulation thread. rc=%Rrc\n", rc), rc);
|
---|
[1] | 1001 |
|
---|
[8823] | 1002 | LogFlowFunc(("returns VINF_SUCCESS\n"));
|
---|
[1] | 1003 | return VINF_SUCCESS;
|
---|
| 1004 | }
|
---|
| 1005 |
|
---|
| 1006 |
|
---|
| 1007 | /**
|
---|
| 1008 | * Wait for a debug event.
|
---|
| 1009 | *
|
---|
| 1010 | * @returns VBox status. Will not return VBOX_INTERRUPTED.
|
---|
[44399] | 1011 | * @param pUVM The user mode VM handle.
|
---|
[33540] | 1012 | * @param cMillies Number of millis to wait.
|
---|
[1] | 1013 | * @param ppEvent Where to store the event pointer.
|
---|
| 1014 | */
|
---|
[44399] | 1015 | VMMR3DECL(int) DBGFR3EventWait(PUVM pUVM, RTMSINTERVAL cMillies, PCDBGFEVENT *ppEvent)
|
---|
[1] | 1016 | {
|
---|
| 1017 | /*
|
---|
| 1018 | * Check state.
|
---|
| 1019 | */
|
---|
[45006] | 1020 | UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
|
---|
[44399] | 1021 | PVM pVM = pUVM->pVM;
|
---|
[45006] | 1022 | VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
|
---|
[12875] | 1023 | AssertReturn(pVM->dbgf.s.fAttached, VERR_DBGF_NOT_ATTACHED);
|
---|
[1] | 1024 | *ppEvent = NULL;
|
---|
| 1025 |
|
---|
| 1026 | /*
|
---|
| 1027 | * Wait.
|
---|
| 1028 | */
|
---|
| 1029 | int rc = RTSemPongWait(&pVM->dbgf.s.PingPong, cMillies);
|
---|
[13816] | 1030 | if (RT_SUCCESS(rc))
|
---|
[1] | 1031 | {
|
---|
| 1032 | *ppEvent = &pVM->dbgf.s.DbgEvent;
|
---|
| 1033 | Log2(("DBGF: Debugger thread: receiving event %d\n", (*ppEvent)->enmType));
|
---|
| 1034 | return VINF_SUCCESS;
|
---|
| 1035 | }
|
---|
| 1036 |
|
---|
| 1037 | return rc;
|
---|
| 1038 | }
|
---|
| 1039 |
|
---|
| 1040 |
|
---|
| 1041 | /**
|
---|
| 1042 | * Halts VM execution.
|
---|
| 1043 | *
|
---|
| 1044 | * After calling this the VM isn't actually halted till an DBGFEVENT_HALT_DONE
|
---|
| 1045 | * arrives. Until that time it's not possible to issue any new commands.
|
---|
| 1046 | *
|
---|
| 1047 | * @returns VBox status.
|
---|
[44399] | 1048 | * @param pUVM The user mode VM handle.
|
---|
[1] | 1049 | */
|
---|
[44399] | 1050 | VMMR3DECL(int) DBGFR3Halt(PUVM pUVM)
|
---|
[1] | 1051 | {
|
---|
| 1052 | /*
|
---|
| 1053 | * Check state.
|
---|
| 1054 | */
|
---|
[45006] | 1055 | UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
|
---|
[44399] | 1056 | PVM pVM = pUVM->pVM;
|
---|
[45006] | 1057 | VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
|
---|
[12875] | 1058 | AssertReturn(pVM->dbgf.s.fAttached, VERR_DBGF_NOT_ATTACHED);
|
---|
| 1059 | RTPINGPONGSPEAKER enmSpeaker = pVM->dbgf.s.PingPong.enmSpeaker;
|
---|
| 1060 | if ( enmSpeaker == RTPINGPONGSPEAKER_PONG
|
---|
| 1061 | || enmSpeaker == RTPINGPONGSPEAKER_PONG_SIGNALED)
|
---|
[1] | 1062 | return VWRN_DBGF_ALREADY_HALTED;
|
---|
| 1063 |
|
---|
| 1064 | /*
|
---|
| 1065 | * Send command.
|
---|
| 1066 | */
|
---|
[12663] | 1067 | dbgfR3SetCmd(pVM, DBGFCMD_HALT);
|
---|
[1] | 1068 |
|
---|
| 1069 | return VINF_SUCCESS;
|
---|
| 1070 | }
|
---|
| 1071 |
|
---|
| 1072 |
|
---|
| 1073 | /**
|
---|
| 1074 | * Checks if the VM is halted by the debugger.
|
---|
| 1075 | *
|
---|
| 1076 | * @returns True if halted.
|
---|
| 1077 | * @returns False if not halted.
|
---|
[44399] | 1078 | * @param pUVM The user mode VM handle.
|
---|
[1] | 1079 | */
|
---|
[44399] | 1080 | VMMR3DECL(bool) DBGFR3IsHalted(PUVM pUVM)
|
---|
[1] | 1081 | {
|
---|
[44399] | 1082 | UVM_ASSERT_VALID_EXT_RETURN(pUVM, false);
|
---|
| 1083 | PVM pVM = pUVM->pVM;
|
---|
| 1084 | VM_ASSERT_VALID_EXT_RETURN(pVM, false);
|
---|
[12896] | 1085 | AssertReturn(pVM->dbgf.s.fAttached, false);
|
---|
[44399] | 1086 |
|
---|
[1] | 1087 | RTPINGPONGSPEAKER enmSpeaker = pVM->dbgf.s.PingPong.enmSpeaker;
|
---|
[12875] | 1088 | return enmSpeaker == RTPINGPONGSPEAKER_PONG_SIGNALED
|
---|
| 1089 | || enmSpeaker == RTPINGPONGSPEAKER_PONG;
|
---|
[1] | 1090 | }
|
---|
| 1091 |
|
---|
| 1092 |
|
---|
| 1093 | /**
|
---|
[14299] | 1094 | * Checks if the debugger can wait for events or not.
|
---|
[1] | 1095 | *
|
---|
| 1096 | * This function is only used by lazy, multiplexing debuggers. :-)
|
---|
| 1097 | *
|
---|
[45006] | 1098 | * @returns VBox status code.
|
---|
| 1099 | * @retval VINF_SUCCESS if waitable.
|
---|
| 1100 | * @retval VERR_SEM_OUT_OF_TURN if not waitable.
|
---|
| 1101 | * @retval VERR_INVALID_VM_HANDLE if the VM is being (/ has been) destroyed
|
---|
| 1102 | * (not asserted) or if the handle is invalid (asserted).
|
---|
| 1103 | * @retval VERR_DBGF_NOT_ATTACHED if not attached.
|
---|
| 1104 | *
|
---|
[44399] | 1105 | * @param pUVM The user mode VM handle.
|
---|
[1] | 1106 | */
|
---|
[45006] | 1107 | VMMR3DECL(int) DBGFR3QueryWaitable(PUVM pUVM)
|
---|
[1] | 1108 | {
|
---|
[45006] | 1109 | UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
|
---|
| 1110 |
|
---|
| 1111 | /* Note! There is a slight race here, unfortunately. */
|
---|
[44399] | 1112 | PVM pVM = pUVM->pVM;
|
---|
[45006] | 1113 | if (!RT_VALID_PTR(pVM))
|
---|
| 1114 | return VERR_INVALID_VM_HANDLE;
|
---|
| 1115 | if (pVM->enmVMState >= VMSTATE_DESTROYING)
|
---|
| 1116 | return VERR_INVALID_VM_HANDLE;
|
---|
[46159] | 1117 | if (!pVM->dbgf.s.fAttached)
|
---|
| 1118 | return VERR_DBGF_NOT_ATTACHED;
|
---|
[44399] | 1119 |
|
---|
[45006] | 1120 | if (!RTSemPongShouldWait(&pVM->dbgf.s.PingPong))
|
---|
| 1121 | return VERR_SEM_OUT_OF_TURN;
|
---|
| 1122 |
|
---|
| 1123 | return VINF_SUCCESS;
|
---|
[1] | 1124 | }
|
---|
| 1125 |
|
---|
| 1126 |
|
---|
| 1127 | /**
|
---|
| 1128 | * Resumes VM execution.
|
---|
| 1129 | *
|
---|
| 1130 | * There is no receipt event on this command.
|
---|
| 1131 | *
|
---|
| 1132 | * @returns VBox status.
|
---|
[44399] | 1133 | * @param pUVM The user mode VM handle.
|
---|
[1] | 1134 | */
|
---|
[44399] | 1135 | VMMR3DECL(int) DBGFR3Resume(PUVM pUVM)
|
---|
[1] | 1136 | {
|
---|
| 1137 | /*
|
---|
| 1138 | * Check state.
|
---|
| 1139 | */
|
---|
[44399] | 1140 | UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
|
---|
| 1141 | PVM pVM = pUVM->pVM;
|
---|
| 1142 | VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
|
---|
[12875] | 1143 | AssertReturn(pVM->dbgf.s.fAttached, VERR_DBGF_NOT_ATTACHED);
|
---|
| 1144 | AssertReturn(RTSemPongIsSpeaker(&pVM->dbgf.s.PingPong), VERR_SEM_OUT_OF_TURN);
|
---|
[1] | 1145 |
|
---|
| 1146 | /*
|
---|
| 1147 | * Send the ping back to the emulation thread telling it to run.
|
---|
| 1148 | */
|
---|
[12663] | 1149 | dbgfR3SetCmd(pVM, DBGFCMD_GO);
|
---|
[1] | 1150 | int rc = RTSemPong(&pVM->dbgf.s.PingPong);
|
---|
| 1151 | AssertRC(rc);
|
---|
| 1152 |
|
---|
| 1153 | return rc;
|
---|
| 1154 | }
|
---|
| 1155 |
|
---|
| 1156 |
|
---|
| 1157 | /**
|
---|
| 1158 | * Step Into.
|
---|
| 1159 | *
|
---|
| 1160 | * A single step event is generated from this command.
|
---|
[33540] | 1161 | * The current implementation is not reliable, so don't rely on the event coming.
|
---|
[1] | 1162 | *
|
---|
| 1163 | * @returns VBox status.
|
---|
[44399] | 1164 | * @param pUVM The user mode VM handle.
|
---|
[19286] | 1165 | * @param idCpu The ID of the CPU to single step on.
|
---|
[1] | 1166 | */
|
---|
[44399] | 1167 | VMMR3DECL(int) DBGFR3Step(PUVM pUVM, VMCPUID idCpu)
|
---|
[1] | 1168 | {
|
---|
| 1169 | /*
|
---|
| 1170 | * Check state.
|
---|
| 1171 | */
|
---|
[44399] | 1172 | UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
|
---|
| 1173 | PVM pVM = pUVM->pVM;
|
---|
| 1174 | VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
|
---|
[12875] | 1175 | AssertReturn(pVM->dbgf.s.fAttached, VERR_DBGF_NOT_ATTACHED);
|
---|
| 1176 | AssertReturn(RTSemPongIsSpeaker(&pVM->dbgf.s.PingPong), VERR_SEM_OUT_OF_TURN);
|
---|
[22890] | 1177 | AssertReturn(idCpu < pVM->cCpus, VERR_INVALID_PARAMETER);
|
---|
[1] | 1178 |
|
---|
| 1179 | /*
|
---|
| 1180 | * Send the ping back to the emulation thread telling it to run.
|
---|
| 1181 | */
|
---|
[19286] | 1182 | /** @todo SMP (idCpu) */
|
---|
[12663] | 1183 | dbgfR3SetCmd(pVM, DBGFCMD_SINGLE_STEP);
|
---|
[1] | 1184 | int rc = RTSemPong(&pVM->dbgf.s.PingPong);
|
---|
| 1185 | AssertRC(rc);
|
---|
| 1186 | return rc;
|
---|
| 1187 | }
|
---|
| 1188 |
|
---|
| 1189 |
|
---|
| 1190 | /**
|
---|
[33540] | 1191 | * Call this to single step programmatically.
|
---|
[1] | 1192 | *
|
---|
| 1193 | * You must pass down the return code to the EM loop! That's
|
---|
| 1194 | * where the actual single stepping take place (at least in the
|
---|
| 1195 | * current implementation).
|
---|
| 1196 | *
|
---|
| 1197 | * @returns VINF_EM_DBG_STEP
|
---|
[19286] | 1198 | *
|
---|
[41801] | 1199 | * @param pVCpu Pointer to the VMCPU.
|
---|
[19286] | 1200 | *
|
---|
| 1201 | * @thread VCpu EMT
|
---|
[44399] | 1202 | * @internal
|
---|
[1] | 1203 | */
|
---|
[44399] | 1204 | VMMR3_INT_DECL(int) DBGFR3PrgStep(PVMCPU pVCpu)
|
---|
[1] | 1205 | {
|
---|
[19286] | 1206 | VMCPU_ASSERT_EMT(pVCpu);
|
---|
[1] | 1207 |
|
---|
[19286] | 1208 | pVCpu->dbgf.s.fSingleSteppingRaw = true;
|
---|
[1] | 1209 | return VINF_EM_DBG_STEP;
|
---|
| 1210 | }
|
---|
| 1211 |
|
---|
[44373] | 1212 |
|
---|
| 1213 | /**
|
---|
| 1214 | * Inject an NMI into a running VM (only VCPU 0!)
|
---|
| 1215 | *
|
---|
| 1216 | * @returns VBox status code.
|
---|
| 1217 | * @param pVM Pointer to the VM.
|
---|
| 1218 | */
|
---|
| 1219 | VMMR3DECL(int) DBGFR3InjectNMI(PUVM pUVM, VMCPUID idCpu)
|
---|
| 1220 | {
|
---|
| 1221 | UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
|
---|
| 1222 | PVM pVM = pUVM->pVM;
|
---|
| 1223 | VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
|
---|
| 1224 | AssertReturn(idCpu < pVM->cCpus, VERR_INVALID_CPU_ID);
|
---|
| 1225 |
|
---|
| 1226 | /** @todo Implement generic NMI injection. */
|
---|
| 1227 | if (!HMIsEnabled(pVM))
|
---|
| 1228 | return VERR_NOT_SUP_IN_RAW_MODE;
|
---|
| 1229 |
|
---|
| 1230 | VMCPU_FF_SET(&pVM->aCpus[idCpu], VMCPU_FF_INTERRUPT_NMI);
|
---|
| 1231 | return VINF_SUCCESS;
|
---|
| 1232 | }
|
---|
| 1233 |
|
---|