bool MachineBridge::lockMachine() { // std::cout << "[" << getName().toStdString() << "] Trying to lock machine..." << std::endl; nsresult rc; uint32_t state; uint32_t machineState = getState(); if(machineState == MachineState::Starting || machineState == MachineState::Running || machineState == MachineState::Paused) return false; if(session != nsnull) { // Try to unlock session, then check if this action succeeded NS_CHECK_AND_DEBUG_ERROR(session, UnlockMachine(), rc); nsresult rc_tmp; GET_AND_DEBUG_MACHINE_STATE(session, state, rc_tmp); // If Session is not unlocked, VM is still running if(NS_FAILED(rc) || state != SessionState::Unlocked) { // std::cout << "[" << getName().toStdString() << "] Session already locked!" << std::endl; return false; } } session = vboxbridge->newSession(); GET_AND_DEBUG_MACHINE_STATE(session, state, rc); if(state == SessionState::Unlocked) NS_CHECK_AND_DEBUG_ERROR(machine, LockMachine(session, LockType::Write), rc); GET_AND_DEBUG_MACHINE_STATE(session, state, rc); if(NS_SUCCEEDED(rc) && state == SessionState::Locked) NS_CHECK_AND_DEBUG_ERROR(session, GetMachine(&machine), rc); // if(NS_SUCCEEDED(rc) && state == SessionState::Locked) // std::cout << "[" << getName().toStdString() << "] Machine locked" << std::endl; // else // std::cout << "[" << getName().toStdString() << "] Failed to lock machine (rc: 0x" << std::hex << rc << std::dec << ")" << std::endl; return NS_SUCCEEDED(rc); }
RTEXITCODE handleDebugVM(HandlerArg *pArgs) { RTEXITCODE rcExit = RTEXITCODE_FAILURE; /* * The first argument is the VM name or UUID. Open a session to it. */ if (pArgs->argc < 2) return errorNoSubcommand(); ComPtr<IMachine> ptrMachine; CHECK_ERROR2I_RET(pArgs->virtualBox, FindMachine(com::Bstr(pArgs->argv[0]).raw(), ptrMachine.asOutParam()), RTEXITCODE_FAILURE); CHECK_ERROR2I_RET(ptrMachine, LockMachine(pArgs->session, LockType_Shared), RTEXITCODE_FAILURE); /* * Get the associated console and machine debugger. */ HRESULT rc; ComPtr<IConsole> ptrConsole; CHECK_ERROR(pArgs->session, COMGETTER(Console)(ptrConsole.asOutParam())); if (SUCCEEDED(rc)) { if (ptrConsole.isNotNull()) { ComPtr<IMachineDebugger> ptrDebugger; CHECK_ERROR(ptrConsole, COMGETTER(Debugger)(ptrDebugger.asOutParam())); if (SUCCEEDED(rc)) { /* * String switch on the sub-command. */ const char *pszSubCmd = pArgs->argv[1]; if (!strcmp(pszSubCmd, "dumpvmcore")) { setCurrentSubcommand(HELP_SCOPE_DEBUGVM_DUMPVMCORE); rcExit = handleDebugVM_DumpVMCore(pArgs, ptrDebugger); } else if (!strcmp(pszSubCmd, "getregisters")) { setCurrentSubcommand(HELP_SCOPE_DEBUGVM_GETREGISTERS); rcExit = handleDebugVM_GetRegisters(pArgs, ptrDebugger); } else if (!strcmp(pszSubCmd, "info")) { setCurrentSubcommand(HELP_SCOPE_DEBUGVM_INFO); rcExit = handleDebugVM_Info(pArgs, ptrDebugger); } else if (!strcmp(pszSubCmd, "injectnmi")) { setCurrentSubcommand(HELP_SCOPE_DEBUGVM_INJECTNMI); rcExit = handleDebugVM_InjectNMI(pArgs, ptrDebugger); } else if (!strcmp(pszSubCmd, "log")) { setCurrentSubcommand(HELP_SCOPE_DEBUGVM_LOG); rcExit = handleDebugVM_LogXXXX(pArgs, ptrDebugger, pszSubCmd); } else if (!strcmp(pszSubCmd, "logdest")) { setCurrentSubcommand(HELP_SCOPE_DEBUGVM_LOGDEST); rcExit = handleDebugVM_LogXXXX(pArgs, ptrDebugger, pszSubCmd); } else if (!strcmp(pszSubCmd, "logflags")) { setCurrentSubcommand(HELP_SCOPE_DEBUGVM_LOGFLAGS); rcExit = handleDebugVM_LogXXXX(pArgs, ptrDebugger, pszSubCmd); } else if (!strcmp(pszSubCmd, "osdetect")) { setCurrentSubcommand(HELP_SCOPE_DEBUGVM_OSDETECT); rcExit = handleDebugVM_OSDetect(pArgs, ptrDebugger); } else if (!strcmp(pszSubCmd, "osinfo")) { setCurrentSubcommand(HELP_SCOPE_DEBUGVM_OSINFO); rcExit = handleDebugVM_OSInfo(pArgs, ptrDebugger); } else if (!strcmp(pszSubCmd, "osdmesg")) { setCurrentSubcommand(HELP_SCOPE_DEBUGVM_OSDMESG); rcExit = handleDebugVM_OSDmesg(pArgs, ptrDebugger); } else if (!strcmp(pszSubCmd, "setregisters")) { setCurrentSubcommand(HELP_SCOPE_DEBUGVM_SETREGISTERS); rcExit = handleDebugVM_SetRegisters(pArgs, ptrDebugger); } else if (!strcmp(pszSubCmd, "show")) { setCurrentSubcommand(HELP_SCOPE_DEBUGVM_SHOW); rcExit = handleDebugVM_Show(pArgs, ptrDebugger); } else if (!strcmp(pszSubCmd, "statistics")) { setCurrentSubcommand(HELP_SCOPE_DEBUGVM_STATISTICS); rcExit = handleDebugVM_Statistics(pArgs, ptrDebugger); } else errorUnknownSubcommand(pszSubCmd); } } else RTMsgError("Machine '%s' is not currently running.\n", pArgs->argv[0]); } pArgs->session->UnlockMachine(); return rcExit; }