VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/DBGFCpu.cpp@ 85972

Last change on this file since 85972 was 84710, checked in by vboxsync, 5 years ago

VMM/DBGF: Add DBGFR3GetCpuState() to return the current CPU state as a human readable string [Windows build fix]

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.5 KB
Line 
1/* $Id: DBGFCpu.cpp 84710 2020-06-05 18:32:02Z vboxsync $ */
2/** @file
3 * DBGF - Debugger Facility, CPU State Accessors.
4 */
5
6/*
7 * Copyright (C) 2009-2020 Oracle Corporation
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 (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#define VMCPU_INCL_CPUM_GST_CTX /* For CPUM_IMPORT_EXTRN_RET(). */
24#include <VBox/vmm/dbgf.h>
25#include <VBox/vmm/cpum.h>
26#include "DBGFInternal.h"
27#include <VBox/vmm/vm.h>
28#include <VBox/vmm/uvm.h>
29#include <iprt/errcore.h>
30#include <VBox/log.h>
31#include <VBox/param.h>
32#include <iprt/assert.h>
33
34
35/**
36 * Wrapper around CPUMGetGuestMode.
37 *
38 * @returns VINF_SUCCESS.
39 * @param pVM The cross context VM structure.
40 * @param idCpu The current CPU ID.
41 * @param penmMode Where to return the mode.
42 */
43static DECLCALLBACK(int) dbgfR3CpuGetMode(PVM pVM, VMCPUID idCpu, CPUMMODE *penmMode)
44{
45 Assert(idCpu == VMMGetCpuId(pVM));
46 PVMCPU pVCpu = VMMGetCpuById(pVM, idCpu);
47 CPUM_IMPORT_EXTRN_RET(pVCpu, CPUMCTX_EXTRN_CR0 | CPUMCTX_EXTRN_EFER);
48 *penmMode = CPUMGetGuestMode(pVCpu);
49 return VINF_SUCCESS;
50}
51
52
53/**
54 * Get the current CPU mode.
55 *
56 * @returns The CPU mode on success, CPUMMODE_INVALID on failure.
57 * @param pUVM The user mode VM handle.
58 * @param idCpu The target CPU ID.
59 */
60VMMR3DECL(CPUMMODE) DBGFR3CpuGetMode(PUVM pUVM, VMCPUID idCpu)
61{
62 UVM_ASSERT_VALID_EXT_RETURN(pUVM, CPUMMODE_INVALID);
63 VM_ASSERT_VALID_EXT_RETURN(pUVM->pVM, CPUMMODE_INVALID);
64 AssertReturn(idCpu < pUVM->pVM->cCpus, CPUMMODE_INVALID);
65
66 CPUMMODE enmMode;
67 int rc = VMR3ReqPriorityCallWaitU(pUVM, idCpu, (PFNRT)dbgfR3CpuGetMode, 3, pUVM->pVM, idCpu, &enmMode);
68 if (RT_FAILURE(rc))
69 return CPUMMODE_INVALID;
70 return enmMode;
71}
72
73
74/**
75 * Wrapper around CPUMIsGuestIn64BitCode.
76 *
77 * @returns VINF_SUCCESS.
78 * @param pVM The cross context VM structure.
79 * @param idCpu The current CPU ID.
80 * @param pfIn64BitCode Where to return the result.
81 */
82static DECLCALLBACK(int) dbgfR3CpuIn64BitCode(PVM pVM, VMCPUID idCpu, bool *pfIn64BitCode)
83{
84 Assert(idCpu == VMMGetCpuId(pVM));
85 PVMCPU pVCpu = VMMGetCpuById(pVM, idCpu);
86 CPUM_IMPORT_EXTRN_RET(pVCpu, CPUMCTX_EXTRN_CS | CPUMCTX_EXTRN_EFER);
87 *pfIn64BitCode = CPUMIsGuestIn64BitCode(pVCpu);
88 return VINF_SUCCESS;
89}
90
91
92/**
93 * Checks if the given CPU is executing 64-bit code or not.
94 *
95 * @returns true / false accordingly.
96 * @param pUVM The user mode VM handle.
97 * @param idCpu The target CPU ID.
98 */
99VMMR3DECL(bool) DBGFR3CpuIsIn64BitCode(PUVM pUVM, VMCPUID idCpu)
100{
101 UVM_ASSERT_VALID_EXT_RETURN(pUVM, false);
102 VM_ASSERT_VALID_EXT_RETURN(pUVM->pVM, false);
103 AssertReturn(idCpu < pUVM->pVM->cCpus, false);
104
105 bool fIn64BitCode;
106 int rc = VMR3ReqPriorityCallWaitU(pUVM, idCpu, (PFNRT)dbgfR3CpuIn64BitCode, 3, pUVM->pVM, idCpu, &fIn64BitCode);
107 if (RT_FAILURE(rc))
108 return false;
109 return fIn64BitCode;
110}
111
112
113/**
114 * Wrapper around CPUMIsGuestInV86Code.
115 *
116 * @returns VINF_SUCCESS.
117 * @param pVM The cross context VM structure.
118 * @param idCpu The current CPU ID.
119 * @param pfInV86Code Where to return the result.
120 */
121static DECLCALLBACK(int) dbgfR3CpuInV86Code(PVM pVM, VMCPUID idCpu, bool *pfInV86Code)
122{
123 Assert(idCpu == VMMGetCpuId(pVM));
124 PVMCPU pVCpu = VMMGetCpuById(pVM, idCpu);
125 CPUM_IMPORT_EXTRN_RET(pVCpu, CPUMCTX_EXTRN_RFLAGS);
126 *pfInV86Code = CPUMIsGuestInV86ModeEx(CPUMQueryGuestCtxPtr(pVCpu));
127 return VINF_SUCCESS;
128}
129
130
131/**
132 * Checks if the given CPU is executing V8086 code or not.
133 *
134 * @returns true / false accordingly.
135 * @param pUVM The user mode VM handle.
136 * @param idCpu The target CPU ID.
137 */
138VMMR3DECL(bool) DBGFR3CpuIsInV86Code(PUVM pUVM, VMCPUID idCpu)
139{
140 UVM_ASSERT_VALID_EXT_RETURN(pUVM, false);
141 VM_ASSERT_VALID_EXT_RETURN(pUVM->pVM, false);
142 AssertReturn(idCpu < pUVM->pVM->cCpus, false);
143
144 bool fInV86Code;
145 int rc = VMR3ReqPriorityCallWaitU(pUVM, idCpu, (PFNRT)dbgfR3CpuInV86Code, 3, pUVM->pVM, idCpu, &fInV86Code);
146 if (RT_FAILURE(rc))
147 return false;
148 return fInV86Code;
149}
150
151
152/**
153 * Get the number of CPUs (or threads if you insist).
154 *
155 * @returns The number of CPUs
156 * @param pUVM The user mode VM handle.
157 */
158VMMR3DECL(VMCPUID) DBGFR3CpuGetCount(PUVM pUVM)
159{
160 UVM_ASSERT_VALID_EXT_RETURN(pUVM, 1);
161 return pUVM->cCpus;
162}
163
164
165/**
166 * Returns the state of the given CPU as a human readable string.
167 *
168 * @returns Pointer to the human readable CPU state string.
169 * @param pUVM The user mode VM handle.
170 * @param idCpu The target CPU ID.
171 */
172VMMR3DECL(const char *) DBGFR3CpuGetState(PUVM pUVM, VMCPUID idCpu)
173{
174 UVM_ASSERT_VALID_EXT_RETURN(pUVM, NULL);
175 VM_ASSERT_VALID_EXT_RETURN(pUVM->pVM, NULL);
176 AssertReturn(idCpu < pUVM->pVM->cCpus, NULL);
177
178 PVMCPU pVCpu = VMMGetCpuById(pUVM->pVM, idCpu);
179 VMCPUSTATE enmCpuState = (VMCPUSTATE)ASMAtomicReadU32((volatile uint32_t *)&pVCpu->enmState);
180
181 switch (enmCpuState)
182 {
183 case VMCPUSTATE_INVALID: return "<INVALID>";
184 case VMCPUSTATE_STOPPED: return "Stopped";
185 case VMCPUSTATE_STARTED: return "Started";
186 case VMCPUSTATE_STARTED_HM: return "Started (HM)";
187 case VMCPUSTATE_STARTED_EXEC: return "Started (Exec)";
188 case VMCPUSTATE_STARTED_EXEC_NEM: return "Started (Exec NEM)";
189 case VMCPUSTATE_STARTED_EXEC_NEM_WAIT: return "Started (Exec NEM Wait)";
190 case VMCPUSTATE_STARTED_EXEC_NEM_CANCELED: return "Started (Exec NEM Canceled)";
191 case VMCPUSTATE_STARTED_HALTED: return "Started (Halted)";
192 case VMCPUSTATE_END: return "END";
193 default: break;
194 }
195
196 AssertMsgFailedReturn(("Unknown CPU state %u\n", enmCpuState), "<UNKNOWN>");
197}
198
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