1 | /* $Id: VMMGuruMeditation.cpp 39944 2012-02-01 21:16:23Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VMM - The Virtual Machine Monitor, Guru Meditation Code.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2010 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 | * Header Files *
|
---|
20 | *******************************************************************************/
|
---|
21 | #define LOG_GROUP LOG_GROUP_VMM
|
---|
22 | #include <VBox/vmm/vmm.h>
|
---|
23 | #include <VBox/vmm/pdmapi.h>
|
---|
24 | #include <VBox/vmm/pdmcritsect.h>
|
---|
25 | #include <VBox/vmm/trpm.h>
|
---|
26 | #include <VBox/vmm/dbgf.h>
|
---|
27 | #include "VMMInternal.h"
|
---|
28 | #include <VBox/vmm/vm.h>
|
---|
29 | #include <VBox/vmm/mm.h>
|
---|
30 | #include <VBox/vmm/iom.h>
|
---|
31 | #include <VBox/vmm/em.h>
|
---|
32 |
|
---|
33 | #include <VBox/err.h>
|
---|
34 | #include <VBox/param.h>
|
---|
35 | #include <VBox/version.h>
|
---|
36 | #include <VBox/vmm/hwaccm.h>
|
---|
37 | #include <iprt/assert.h>
|
---|
38 | #include <iprt/time.h>
|
---|
39 | #include <iprt/stream.h>
|
---|
40 | #include <iprt/string.h>
|
---|
41 | #include <iprt/stdarg.h>
|
---|
42 |
|
---|
43 |
|
---|
44 | /*******************************************************************************
|
---|
45 | * Structures and Typedefs *
|
---|
46 | *******************************************************************************/
|
---|
47 | /**
|
---|
48 | * Structure to pass to DBGFR3Info() and for doing all other
|
---|
49 | * output during fatal dump.
|
---|
50 | */
|
---|
51 | typedef struct VMMR3FATALDUMPINFOHLP
|
---|
52 | {
|
---|
53 | /** The helper core. */
|
---|
54 | DBGFINFOHLP Core;
|
---|
55 | /** The release logger instance. */
|
---|
56 | PRTLOGGER pRelLogger;
|
---|
57 | /** The saved release logger flags. */
|
---|
58 | uint32_t fRelLoggerFlags;
|
---|
59 | /** The logger instance. */
|
---|
60 | PRTLOGGER pLogger;
|
---|
61 | /** The saved logger flags. */
|
---|
62 | uint32_t fLoggerFlags;
|
---|
63 | /** The saved logger destination flags. */
|
---|
64 | uint32_t fLoggerDestFlags;
|
---|
65 | /** Whether to output to stderr or not. */
|
---|
66 | bool fStdErr;
|
---|
67 | /** Whether we're still recording the summary or not. */
|
---|
68 | bool fRecSummary;
|
---|
69 | /** Buffer for the summary. */
|
---|
70 | char szSummary[4096-2];
|
---|
71 | /** The current summary offset. */
|
---|
72 | size_t offSummary;
|
---|
73 | } VMMR3FATALDUMPINFOHLP, *PVMMR3FATALDUMPINFOHLP;
|
---|
74 | /** Pointer to a VMMR3FATALDUMPINFOHLP structure. */
|
---|
75 | typedef const VMMR3FATALDUMPINFOHLP *PCVMMR3FATALDUMPINFOHLP;
|
---|
76 |
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * Print formatted string.
|
---|
80 | *
|
---|
81 | * @param pHlp Pointer to this structure.
|
---|
82 | * @param pszFormat The format string.
|
---|
83 | * @param ... Arguments.
|
---|
84 | */
|
---|
85 | static DECLCALLBACK(void) vmmR3FatalDumpInfoHlp_pfnPrintf(PCDBGFINFOHLP pHlp, const char *pszFormat, ...)
|
---|
86 | {
|
---|
87 | va_list args;
|
---|
88 | va_start(args, pszFormat);
|
---|
89 | pHlp->pfnPrintfV(pHlp, pszFormat, args);
|
---|
90 | va_end(args);
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * Print formatted string.
|
---|
96 | *
|
---|
97 | * @param pHlp Pointer to this structure.
|
---|
98 | * @param pszFormat The format string.
|
---|
99 | * @param args Argument list.
|
---|
100 | */
|
---|
101 | static DECLCALLBACK(void) vmmR3FatalDumpInfoHlp_pfnPrintfV(PCDBGFINFOHLP pHlp, const char *pszFormat, va_list args)
|
---|
102 | {
|
---|
103 | PVMMR3FATALDUMPINFOHLP pMyHlp = (PVMMR3FATALDUMPINFOHLP)pHlp;
|
---|
104 |
|
---|
105 | if (pMyHlp->pRelLogger)
|
---|
106 | {
|
---|
107 | va_list args2;
|
---|
108 | va_copy(args2, args);
|
---|
109 | RTLogLoggerV(pMyHlp->pRelLogger, pszFormat, args2);
|
---|
110 | va_end(args2);
|
---|
111 | }
|
---|
112 | if (pMyHlp->pLogger)
|
---|
113 | {
|
---|
114 | va_list args2;
|
---|
115 | va_copy(args2, args);
|
---|
116 | RTLogLoggerV(pMyHlp->pLogger, pszFormat, args);
|
---|
117 | va_end(args2);
|
---|
118 | }
|
---|
119 | if (pMyHlp->fStdErr)
|
---|
120 | {
|
---|
121 | va_list args2;
|
---|
122 | va_copy(args2, args);
|
---|
123 | RTStrmPrintfV(g_pStdErr, pszFormat, args);
|
---|
124 | va_end(args2);
|
---|
125 | }
|
---|
126 | if (pMyHlp->fRecSummary)
|
---|
127 | {
|
---|
128 | size_t cchLeft = sizeof(pMyHlp->szSummary) - pMyHlp->offSummary;
|
---|
129 | if (cchLeft > 1)
|
---|
130 | {
|
---|
131 | va_list args2;
|
---|
132 | va_copy(args2, args);
|
---|
133 | size_t cch = RTStrPrintfV(&pMyHlp->szSummary[pMyHlp->offSummary], cchLeft, pszFormat, args);
|
---|
134 | va_end(args2);
|
---|
135 | Assert(cch <= cchLeft);
|
---|
136 | pMyHlp->offSummary += cch;
|
---|
137 | }
|
---|
138 | }
|
---|
139 | }
|
---|
140 |
|
---|
141 |
|
---|
142 | /**
|
---|
143 | * Initializes the fatal dump output helper.
|
---|
144 | *
|
---|
145 | * @param pHlp The structure to initialize.
|
---|
146 | */
|
---|
147 | static void vmmR3FatalDumpInfoHlpInit(PVMMR3FATALDUMPINFOHLP pHlp)
|
---|
148 | {
|
---|
149 | RT_BZERO(pHlp, sizeof(*pHlp));
|
---|
150 |
|
---|
151 | pHlp->Core.pfnPrintf = vmmR3FatalDumpInfoHlp_pfnPrintf;
|
---|
152 | pHlp->Core.pfnPrintfV = vmmR3FatalDumpInfoHlp_pfnPrintfV;
|
---|
153 |
|
---|
154 | /*
|
---|
155 | * The loggers.
|
---|
156 | */
|
---|
157 | pHlp->pRelLogger = RTLogRelDefaultInstance();
|
---|
158 | #ifdef LOG_ENABLED
|
---|
159 | pHlp->pLogger = RTLogDefaultInstance();
|
---|
160 | #else
|
---|
161 | if (pHlp->pRelLogger)
|
---|
162 | pHlp->pLogger = RTLogGetDefaultInstance();
|
---|
163 | else
|
---|
164 | pHlp->pLogger = RTLogDefaultInstance();
|
---|
165 | #endif
|
---|
166 |
|
---|
167 | if (pHlp->pRelLogger)
|
---|
168 | {
|
---|
169 | pHlp->fRelLoggerFlags = pHlp->pRelLogger->fFlags;
|
---|
170 | pHlp->pRelLogger->fFlags &= ~RTLOGFLAGS_DISABLED;
|
---|
171 | pHlp->pRelLogger->fFlags |= RTLOGFLAGS_BUFFERED;
|
---|
172 | }
|
---|
173 |
|
---|
174 | if (pHlp->pLogger)
|
---|
175 | {
|
---|
176 | pHlp->fLoggerFlags = pHlp->pLogger->fFlags;
|
---|
177 | pHlp->fLoggerDestFlags = pHlp->pLogger->fDestFlags;
|
---|
178 | pHlp->pLogger->fFlags &= ~RTLOGFLAGS_DISABLED;
|
---|
179 | pHlp->pLogger->fFlags |= RTLOGFLAGS_BUFFERED;
|
---|
180 | #ifndef DEBUG_sandervl
|
---|
181 | pHlp->pLogger->fDestFlags |= RTLOGDEST_DEBUGGER;
|
---|
182 | #endif
|
---|
183 | }
|
---|
184 |
|
---|
185 | /*
|
---|
186 | * Check if we need write to stderr.
|
---|
187 | */
|
---|
188 | pHlp->fStdErr = (!pHlp->pRelLogger || !(pHlp->pRelLogger->fDestFlags & (RTLOGDEST_STDOUT | RTLOGDEST_STDERR)))
|
---|
189 | && (!pHlp->pLogger || !(pHlp->pLogger->fDestFlags & (RTLOGDEST_STDOUT | RTLOGDEST_STDERR)));
|
---|
190 | #ifdef DEBUG_sandervl
|
---|
191 | pHlp->fStdErr = false; /* takes too long to display here */
|
---|
192 | #endif
|
---|
193 |
|
---|
194 | /*
|
---|
195 | * Init the summary recording.
|
---|
196 | */
|
---|
197 | pHlp->fRecSummary = true;
|
---|
198 | pHlp->offSummary = 0;
|
---|
199 | pHlp->szSummary[0] = '\0';
|
---|
200 | }
|
---|
201 |
|
---|
202 |
|
---|
203 | /**
|
---|
204 | * Deletes the fatal dump output helper.
|
---|
205 | *
|
---|
206 | * @param pHlp The structure to delete.
|
---|
207 | */
|
---|
208 | static void vmmR3FatalDumpInfoHlpDelete(PVMMR3FATALDUMPINFOHLP pHlp)
|
---|
209 | {
|
---|
210 | if (pHlp->pRelLogger)
|
---|
211 | {
|
---|
212 | RTLogFlush(pHlp->pRelLogger);
|
---|
213 | pHlp->pRelLogger->fFlags = pHlp->fRelLoggerFlags;
|
---|
214 | }
|
---|
215 |
|
---|
216 | if (pHlp->pLogger)
|
---|
217 | {
|
---|
218 | RTLogFlush(pHlp->pLogger);
|
---|
219 | pHlp->pLogger->fFlags = pHlp->fLoggerFlags;
|
---|
220 | pHlp->pLogger->fDestFlags = pHlp->fLoggerDestFlags;
|
---|
221 | }
|
---|
222 | }
|
---|
223 |
|
---|
224 |
|
---|
225 | /**
|
---|
226 | * Dumps the VM state on a fatal error.
|
---|
227 | *
|
---|
228 | * @param pVM VM Handle.
|
---|
229 | * @param pVCpu VMCPU Handle.
|
---|
230 | * @param rcErr VBox status code.
|
---|
231 | */
|
---|
232 | VMMR3DECL(void) VMMR3FatalDump(PVM pVM, PVMCPU pVCpu, int rcErr)
|
---|
233 | {
|
---|
234 | /*
|
---|
235 | * Create our output helper and sync it with the log settings.
|
---|
236 | * This helper will be used for all the output.
|
---|
237 | */
|
---|
238 | VMMR3FATALDUMPINFOHLP Hlp;
|
---|
239 | PCDBGFINFOHLP pHlp = &Hlp.Core;
|
---|
240 | vmmR3FatalDumpInfoHlpInit(&Hlp);
|
---|
241 |
|
---|
242 | /* Release owned locks to make sure other VCPUs can continue in case they were waiting for one. */
|
---|
243 | PDMR3CritSectLeaveAll(pVM);
|
---|
244 |
|
---|
245 | /*
|
---|
246 | * Header.
|
---|
247 | */
|
---|
248 | pHlp->pfnPrintf(pHlp,
|
---|
249 | "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
|
---|
250 | "!!\n"
|
---|
251 | "!! Guru Meditation %d (%Rrc)\n"
|
---|
252 | "!!\n",
|
---|
253 | rcErr, rcErr);
|
---|
254 |
|
---|
255 | /*
|
---|
256 | * Continue according to context.
|
---|
257 | */
|
---|
258 | bool fDoneHyper = false;
|
---|
259 | switch (rcErr)
|
---|
260 | {
|
---|
261 | /*
|
---|
262 | * Hypervisor errors.
|
---|
263 | */
|
---|
264 | case VERR_VMM_RING0_ASSERTION:
|
---|
265 | case VINF_EM_DBG_HYPER_ASSERTION:
|
---|
266 | case VERR_VMM_RING3_CALL_DISABLED:
|
---|
267 | {
|
---|
268 | const char *pszMsg1 = VMMR3GetRZAssertMsg1(pVM);
|
---|
269 | while (pszMsg1 && *pszMsg1 == '\n')
|
---|
270 | pszMsg1++;
|
---|
271 | const char *pszMsg2 = VMMR3GetRZAssertMsg2(pVM);
|
---|
272 | while (pszMsg2 && *pszMsg2 == '\n')
|
---|
273 | pszMsg2++;
|
---|
274 | pHlp->pfnPrintf(pHlp,
|
---|
275 | "%s"
|
---|
276 | "%s",
|
---|
277 | pszMsg1,
|
---|
278 | pszMsg2);
|
---|
279 | if ( !pszMsg2
|
---|
280 | || !*pszMsg2
|
---|
281 | || strchr(pszMsg2, '\0')[-1] != '\n')
|
---|
282 | pHlp->pfnPrintf(pHlp, "\n");
|
---|
283 | /* fall thru */
|
---|
284 | }
|
---|
285 | case VERR_TRPM_DONT_PANIC:
|
---|
286 | case VERR_TRPM_PANIC:
|
---|
287 | case VINF_EM_RAW_STALE_SELECTOR:
|
---|
288 | case VINF_EM_RAW_IRET_TRAP:
|
---|
289 | case VINF_EM_DBG_HYPER_BREAKPOINT:
|
---|
290 | case VINF_EM_DBG_HYPER_STEPPED:
|
---|
291 | case VERR_VMM_HYPER_CR3_MISMATCH:
|
---|
292 | {
|
---|
293 | /*
|
---|
294 | * Active trap? This is only of partial interest when in hardware
|
---|
295 | * assisted virtualization mode, thus the different messages.
|
---|
296 | */
|
---|
297 | uint32_t uEIP = CPUMGetHyperEIP(pVCpu);
|
---|
298 | TRPMEVENT enmType;
|
---|
299 | uint8_t u8TrapNo = 0xce;
|
---|
300 | RTGCUINT uErrorCode = 0xdeadface;
|
---|
301 | RTGCUINTPTR uCR2 = 0xdeadface;
|
---|
302 | int rc2 = TRPMQueryTrapAll(pVCpu, &u8TrapNo, &enmType, &uErrorCode, &uCR2);
|
---|
303 | if (!HWACCMIsEnabled(pVM))
|
---|
304 | {
|
---|
305 | if (RT_SUCCESS(rc2))
|
---|
306 | pHlp->pfnPrintf(pHlp,
|
---|
307 | "!! TRAP=%02x ERRCD=%RGv CR2=%RGv EIP=%RX32 Type=%d\n",
|
---|
308 | u8TrapNo, uErrorCode, uCR2, uEIP, enmType);
|
---|
309 | else
|
---|
310 | pHlp->pfnPrintf(pHlp,
|
---|
311 | "!! EIP=%RX32 NOTRAP\n",
|
---|
312 | uEIP);
|
---|
313 | }
|
---|
314 | else if (RT_SUCCESS(rc2))
|
---|
315 | pHlp->pfnPrintf(pHlp,
|
---|
316 | "!! ACTIVE TRAP=%02x ERRCD=%RGv CR2=%RGv PC=%RGr Type=%d (Guest!)\n",
|
---|
317 | u8TrapNo, uErrorCode, uCR2, CPUMGetGuestRIP(pVCpu), enmType);
|
---|
318 |
|
---|
319 | /*
|
---|
320 | * Dump the relevant hypervisor registers and stack.
|
---|
321 | */
|
---|
322 | if (HWACCMIsEnabled(pVM))
|
---|
323 | {
|
---|
324 | if ( rcErr == VERR_VMM_RING0_ASSERTION /* fInRing3Call has already been cleared here. */
|
---|
325 | || pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call)
|
---|
326 | {
|
---|
327 | /* Dump the jmpbuf. */
|
---|
328 | pHlp->pfnPrintf(pHlp,
|
---|
329 | "!!\n"
|
---|
330 | "!! CallRing3JmpBuf:\n"
|
---|
331 | "!!\n");
|
---|
332 | pHlp->pfnPrintf(pHlp,
|
---|
333 | "SavedEsp=%RHv SavedEbp=%RHv SpResume=%RHv SpCheck=%RHv\n",
|
---|
334 | pVCpu->vmm.s.CallRing3JmpBufR0.SavedEsp,
|
---|
335 | pVCpu->vmm.s.CallRing3JmpBufR0.SavedEbp,
|
---|
336 | pVCpu->vmm.s.CallRing3JmpBufR0.SpResume,
|
---|
337 | pVCpu->vmm.s.CallRing3JmpBufR0.SpCheck);
|
---|
338 | pHlp->pfnPrintf(pHlp,
|
---|
339 | "pvSavedStack=%RHv cbSavedStack=%#x fInRing3Call=%RTbool\n",
|
---|
340 | pVCpu->vmm.s.CallRing3JmpBufR0.pvSavedStack,
|
---|
341 | pVCpu->vmm.s.CallRing3JmpBufR0.cbSavedStack,
|
---|
342 | pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call);
|
---|
343 | pHlp->pfnPrintf(pHlp,
|
---|
344 | "cbUsedMax=%#x cbUsedAvg=%#x cbUsedTotal=%#llx cUsedTotal=%#llx\n",
|
---|
345 | pVCpu->vmm.s.CallRing3JmpBufR0.cbUsedMax,
|
---|
346 | pVCpu->vmm.s.CallRing3JmpBufR0.cbUsedAvg,
|
---|
347 | pVCpu->vmm.s.CallRing3JmpBufR0.cbUsedTotal,
|
---|
348 | pVCpu->vmm.s.CallRing3JmpBufR0.cUsedTotal);
|
---|
349 |
|
---|
350 | /* Dump the resume register frame on the stack. */
|
---|
351 | PRTHCUINTPTR pBP;
|
---|
352 | #ifdef VMM_R0_SWITCH_STACK
|
---|
353 | pBP = (PRTHCUINTPTR)&pVCpu->vmm.s.pbEMTStackR3[ pVCpu->vmm.s.CallRing3JmpBufR0.SavedEbp
|
---|
354 | - MMHyperCCToR0(pVM, pVCpu->vmm.s.pbEMTStackR3)];
|
---|
355 | #else
|
---|
356 | pBP = (PRTHCUINTPTR)&pVCpu->vmm.s.pbEMTStackR3[ pVCpu->vmm.s.CallRing3JmpBufR0.cbSavedStack
|
---|
357 | - pVCpu->vmm.s.CallRing3JmpBufR0.SpCheck
|
---|
358 | + pVCpu->vmm.s.CallRing3JmpBufR0.SavedEbp];
|
---|
359 | #endif
|
---|
360 | #if HC_ARCH_BITS == 32
|
---|
361 | pHlp->pfnPrintf(pHlp,
|
---|
362 | "eax=volatile ebx=%08x ecx=volatile edx=volatile esi=%08x edi=%08x\n"
|
---|
363 | "eip=%08x esp=%08x ebp=%08x efl=%08x\n"
|
---|
364 | ,
|
---|
365 | pBP[-3], pBP[-2], pBP[-1],
|
---|
366 | pBP[1], pVCpu->vmm.s.CallRing3JmpBufR0.SavedEbp - 8, pBP[0], pBP[-4]);
|
---|
367 | #else
|
---|
368 | # ifdef RT_OS_WINDOWS
|
---|
369 | pHlp->pfnPrintf(pHlp,
|
---|
370 | "rax=volatile rbx=%016RX64 rcx=volatile rdx=volatile\n"
|
---|
371 | "rsi=%016RX64 rdi=%016RX64 r8=volatile r9=volatile \n"
|
---|
372 | "r10=volatile r11=volatile r12=%016RX64 r13=%016RX64\n"
|
---|
373 | "r14=%016RX64 r15=%016RX64\n"
|
---|
374 | "rip=%016RX64 rsp=%016RX64 rbp=%016RX64 rfl=%08RX64\n"
|
---|
375 | ,
|
---|
376 | pBP[-7],
|
---|
377 | pBP[-6], pBP[-5],
|
---|
378 | pBP[-4], pBP[-3],
|
---|
379 | pBP[-2], pBP[-1],
|
---|
380 | pBP[1], pVCpu->vmm.s.CallRing3JmpBufR0.SavedEbp - 16, pBP[0], pBP[-8]);
|
---|
381 | # else
|
---|
382 | pHlp->pfnPrintf(pHlp,
|
---|
383 | "rax=volatile rbx=%016RX64 rcx=volatile rdx=volatile\n"
|
---|
384 | "rsi=volatile rdi=volatile r8=volatile r9=volatile \n"
|
---|
385 | "r10=volatile r11=volatile r12=%016RX64 r13=%016RX64\n"
|
---|
386 | "r14=%016RX64 r15=%016RX64\n"
|
---|
387 | "rip=%016RX64 rsp=%016RX64 rbp=%016RX64 rflags=%08RX64\n"
|
---|
388 | ,
|
---|
389 | pBP[-5],
|
---|
390 | pBP[-4], pBP[-3],
|
---|
391 | pBP[-2], pBP[-1],
|
---|
392 | pBP[1], pVCpu->vmm.s.CallRing3JmpBufR0.SavedEbp - 16, pBP[0], pBP[-6]);
|
---|
393 | # endif
|
---|
394 | #endif
|
---|
395 |
|
---|
396 | /* Callstack. */
|
---|
397 | DBGFADDRESS pc;
|
---|
398 | pc.fFlags = DBGFADDRESS_FLAGS_RING0 | DBGFADDRESS_FLAGS_VALID;
|
---|
399 | #if HC_ARCH_BITS == 64
|
---|
400 | pc.FlatPtr = pc.off = pVCpu->vmm.s.CallRing3JmpBufR0.rip;
|
---|
401 | #else
|
---|
402 | pc.FlatPtr = pc.off = pVCpu->vmm.s.CallRing3JmpBufR0.eip;
|
---|
403 | #endif
|
---|
404 | pc.Sel = DBGF_SEL_FLAT;
|
---|
405 |
|
---|
406 | DBGFADDRESS ebp;
|
---|
407 | ebp.fFlags = DBGFADDRESS_FLAGS_RING0 | DBGFADDRESS_FLAGS_VALID;
|
---|
408 | ebp.FlatPtr = ebp.off = pVCpu->vmm.s.CallRing3JmpBufR0.SavedEbp;
|
---|
409 | ebp.Sel = DBGF_SEL_FLAT;
|
---|
410 |
|
---|
411 | DBGFADDRESS esp;
|
---|
412 | esp.fFlags = DBGFADDRESS_FLAGS_RING0 | DBGFADDRESS_FLAGS_VALID;
|
---|
413 | esp.Sel = DBGF_SEL_FLAT;
|
---|
414 | esp.FlatPtr = esp.off = pVCpu->vmm.s.CallRing3JmpBufR0.SavedEsp;
|
---|
415 |
|
---|
416 | PCDBGFSTACKFRAME pFirstFrame;
|
---|
417 | rc2 = DBGFR3StackWalkBeginEx(pVM, pVCpu->idCpu, DBGFCODETYPE_RING0, &ebp, &esp, &pc,
|
---|
418 | DBGFRETURNTYPE_INVALID, &pFirstFrame);
|
---|
419 | if (RT_SUCCESS(rc2))
|
---|
420 | {
|
---|
421 | pHlp->pfnPrintf(pHlp,
|
---|
422 | "!!\n"
|
---|
423 | "!! Call Stack:\n"
|
---|
424 | "!!\n");
|
---|
425 | #if HC_ARCH_BITS == 32
|
---|
426 | pHlp->pfnPrintf(pHlp, "EBP Ret EBP Ret CS:EIP Arg0 Arg1 Arg2 Arg3 CS:EIP Symbol [line]\n");
|
---|
427 | #else
|
---|
428 | pHlp->pfnPrintf(pHlp, "RBP Ret RBP Ret RIP RIP Symbol [line]\n");
|
---|
429 | #endif
|
---|
430 | for (PCDBGFSTACKFRAME pFrame = pFirstFrame;
|
---|
431 | pFrame;
|
---|
432 | pFrame = DBGFR3StackWalkNext(pFrame))
|
---|
433 | {
|
---|
434 | #if HC_ARCH_BITS == 32
|
---|
435 | pHlp->pfnPrintf(pHlp,
|
---|
436 | "%RHv %RHv %04RX32:%RHv %RHv %RHv %RHv %RHv",
|
---|
437 | (RTHCUINTPTR)pFrame->AddrFrame.off,
|
---|
438 | (RTHCUINTPTR)pFrame->AddrReturnFrame.off,
|
---|
439 | (RTHCUINTPTR)pFrame->AddrReturnPC.Sel,
|
---|
440 | (RTHCUINTPTR)pFrame->AddrReturnPC.off,
|
---|
441 | pFrame->Args.au32[0],
|
---|
442 | pFrame->Args.au32[1],
|
---|
443 | pFrame->Args.au32[2],
|
---|
444 | pFrame->Args.au32[3]);
|
---|
445 | pHlp->pfnPrintf(pHlp, " %RTsel:%08RHv", pFrame->AddrPC.Sel, pFrame->AddrPC.off);
|
---|
446 | #else
|
---|
447 | pHlp->pfnPrintf(pHlp,
|
---|
448 | "%RHv %RHv %RHv %RHv",
|
---|
449 | (RTHCUINTPTR)pFrame->AddrFrame.off,
|
---|
450 | (RTHCUINTPTR)pFrame->AddrReturnFrame.off,
|
---|
451 | (RTHCUINTPTR)pFrame->AddrReturnPC.off,
|
---|
452 | (RTHCUINTPTR)pFrame->AddrPC.off);
|
---|
453 | #endif
|
---|
454 | if (pFrame->pSymPC)
|
---|
455 | {
|
---|
456 | RTGCINTPTR offDisp = pFrame->AddrPC.FlatPtr - pFrame->pSymPC->Value;
|
---|
457 | if (offDisp > 0)
|
---|
458 | pHlp->pfnPrintf(pHlp, " %s+%llx", pFrame->pSymPC->szName, (int64_t)offDisp);
|
---|
459 | else if (offDisp < 0)
|
---|
460 | pHlp->pfnPrintf(pHlp, " %s-%llx", pFrame->pSymPC->szName, -(int64_t)offDisp);
|
---|
461 | else
|
---|
462 | pHlp->pfnPrintf(pHlp, " %s", pFrame->pSymPC->szName);
|
---|
463 | }
|
---|
464 | if (pFrame->pLinePC)
|
---|
465 | pHlp->pfnPrintf(pHlp, " [%s @ 0i%d]", pFrame->pLinePC->szFilename, pFrame->pLinePC->uLineNo);
|
---|
466 | pHlp->pfnPrintf(pHlp, "\n");
|
---|
467 | }
|
---|
468 | DBGFR3StackWalkEnd(pFirstFrame);
|
---|
469 | }
|
---|
470 |
|
---|
471 | /* raw stack */
|
---|
472 | Hlp.fRecSummary = false;
|
---|
473 | pHlp->pfnPrintf(pHlp,
|
---|
474 | "!!\n"
|
---|
475 | "!! Raw stack (mind the direction). \n"
|
---|
476 | "!! pbEMTStackR0=%RHv pbEMTStackBottomR0=%RHv VMM_STACK_SIZE=%#x\n"
|
---|
477 | "!! pbEmtStackR3=%p\n"
|
---|
478 | "!!\n"
|
---|
479 | "%.*Rhxd\n",
|
---|
480 | MMHyperCCToR0(pVM, pVCpu->vmm.s.pbEMTStackR3),
|
---|
481 | MMHyperCCToR0(pVM, pVCpu->vmm.s.pbEMTStackR3) + VMM_STACK_SIZE,
|
---|
482 | VMM_STACK_SIZE,
|
---|
483 | pVCpu->vmm.s.pbEMTStackR3,
|
---|
484 | VMM_STACK_SIZE, pVCpu->vmm.s.pbEMTStackR3);
|
---|
485 | }
|
---|
486 | else
|
---|
487 | {
|
---|
488 | pHlp->pfnPrintf(pHlp,
|
---|
489 | "!! Skipping ring-0 registers and stack, rcErr=%Rrc\n", rcErr);
|
---|
490 | }
|
---|
491 | }
|
---|
492 | else
|
---|
493 | {
|
---|
494 | /*
|
---|
495 | * Try figure out where eip is.
|
---|
496 | */
|
---|
497 | /* core code? */
|
---|
498 | if (uEIP - (RTGCUINTPTR)pVM->vmm.s.pvCoreCodeRC < pVM->vmm.s.cbCoreCode)
|
---|
499 | pHlp->pfnPrintf(pHlp,
|
---|
500 | "!! EIP is in CoreCode, offset %#x\n",
|
---|
501 | uEIP - (RTGCUINTPTR)pVM->vmm.s.pvCoreCodeRC);
|
---|
502 | else
|
---|
503 | { /* ask PDM */ /** @todo ask DBGFR3Sym later? */
|
---|
504 | char szModName[64];
|
---|
505 | RTRCPTR RCPtrMod;
|
---|
506 | char szNearSym1[260];
|
---|
507 | RTRCPTR RCPtrNearSym1;
|
---|
508 | char szNearSym2[260];
|
---|
509 | RTRCPTR RCPtrNearSym2;
|
---|
510 | int rc = PDMR3LdrQueryRCModFromPC(pVM, uEIP,
|
---|
511 | &szModName[0], sizeof(szModName), &RCPtrMod,
|
---|
512 | &szNearSym1[0], sizeof(szNearSym1), &RCPtrNearSym1,
|
---|
513 | &szNearSym2[0], sizeof(szNearSym2), &RCPtrNearSym2);
|
---|
514 | if (RT_SUCCESS(rc))
|
---|
515 | pHlp->pfnPrintf(pHlp,
|
---|
516 | "!! EIP in %s (%RRv) at rva %x near symbols:\n"
|
---|
517 | "!! %RRv rva %RRv off %08x %s\n"
|
---|
518 | "!! %RRv rva %RRv off -%08x %s\n",
|
---|
519 | szModName, RCPtrMod, (unsigned)(uEIP - RCPtrMod),
|
---|
520 | RCPtrNearSym1, RCPtrNearSym1 - RCPtrMod, (unsigned)(uEIP - RCPtrNearSym1), szNearSym1,
|
---|
521 | RCPtrNearSym2, RCPtrNearSym2 - RCPtrMod, (unsigned)(RCPtrNearSym2 - uEIP), szNearSym2);
|
---|
522 | else
|
---|
523 | pHlp->pfnPrintf(pHlp,
|
---|
524 | "!! EIP is not in any code known to VMM!\n");
|
---|
525 | }
|
---|
526 |
|
---|
527 | /* Disassemble the instruction. */
|
---|
528 | char szInstr[256];
|
---|
529 | rc2 = DBGFR3DisasInstrEx(pVM, pVCpu->idCpu, 0, 0, DBGF_DISAS_FLAGS_CURRENT_HYPER | DBGF_DISAS_FLAGS_DEFAULT_MODE,
|
---|
530 | &szInstr[0], sizeof(szInstr), NULL);
|
---|
531 | if (RT_SUCCESS(rc2))
|
---|
532 | pHlp->pfnPrintf(pHlp,
|
---|
533 | "!! %s\n", szInstr);
|
---|
534 |
|
---|
535 | /* Dump the hypervisor cpu state. */
|
---|
536 | pHlp->pfnPrintf(pHlp,
|
---|
537 | "!!\n"
|
---|
538 | "!!\n"
|
---|
539 | "!!\n");
|
---|
540 | rc2 = DBGFR3Info(pVM, "cpumhyper", "verbose", pHlp);
|
---|
541 | fDoneHyper = true;
|
---|
542 |
|
---|
543 | /* Callstack. */
|
---|
544 | PCDBGFSTACKFRAME pFirstFrame;
|
---|
545 | rc2 = DBGFR3StackWalkBegin(pVM, pVCpu->idCpu, DBGFCODETYPE_HYPER, &pFirstFrame);
|
---|
546 | if (RT_SUCCESS(rc2))
|
---|
547 | {
|
---|
548 | pHlp->pfnPrintf(pHlp,
|
---|
549 | "!!\n"
|
---|
550 | "!! Call Stack:\n"
|
---|
551 | "!!\n"
|
---|
552 | "EBP Ret EBP Ret CS:EIP Arg0 Arg1 Arg2 Arg3 CS:EIP Symbol [line]\n");
|
---|
553 | for (PCDBGFSTACKFRAME pFrame = pFirstFrame;
|
---|
554 | pFrame;
|
---|
555 | pFrame = DBGFR3StackWalkNext(pFrame))
|
---|
556 | {
|
---|
557 | pHlp->pfnPrintf(pHlp,
|
---|
558 | "%08RX32 %08RX32 %04RX32:%08RX32 %08RX32 %08RX32 %08RX32 %08RX32",
|
---|
559 | (uint32_t)pFrame->AddrFrame.off,
|
---|
560 | (uint32_t)pFrame->AddrReturnFrame.off,
|
---|
561 | (uint32_t)pFrame->AddrReturnPC.Sel,
|
---|
562 | (uint32_t)pFrame->AddrReturnPC.off,
|
---|
563 | pFrame->Args.au32[0],
|
---|
564 | pFrame->Args.au32[1],
|
---|
565 | pFrame->Args.au32[2],
|
---|
566 | pFrame->Args.au32[3]);
|
---|
567 | pHlp->pfnPrintf(pHlp, " %RTsel:%08RGv", pFrame->AddrPC.Sel, pFrame->AddrPC.off);
|
---|
568 | if (pFrame->pSymPC)
|
---|
569 | {
|
---|
570 | RTGCINTPTR offDisp = pFrame->AddrPC.FlatPtr - pFrame->pSymPC->Value;
|
---|
571 | if (offDisp > 0)
|
---|
572 | pHlp->pfnPrintf(pHlp, " %s+%llx", pFrame->pSymPC->szName, (int64_t)offDisp);
|
---|
573 | else if (offDisp < 0)
|
---|
574 | pHlp->pfnPrintf(pHlp, " %s-%llx", pFrame->pSymPC->szName, -(int64_t)offDisp);
|
---|
575 | else
|
---|
576 | pHlp->pfnPrintf(pHlp, " %s", pFrame->pSymPC->szName);
|
---|
577 | }
|
---|
578 | if (pFrame->pLinePC)
|
---|
579 | pHlp->pfnPrintf(pHlp, " [%s @ 0i%d]", pFrame->pLinePC->szFilename, pFrame->pLinePC->uLineNo);
|
---|
580 | pHlp->pfnPrintf(pHlp, "\n");
|
---|
581 | }
|
---|
582 | DBGFR3StackWalkEnd(pFirstFrame);
|
---|
583 | }
|
---|
584 |
|
---|
585 | /* raw stack */
|
---|
586 | Hlp.fRecSummary = false;
|
---|
587 | pHlp->pfnPrintf(pHlp,
|
---|
588 | "!!\n"
|
---|
589 | "!! Raw stack (mind the direction). pbEMTStackRC=%RRv pbEMTStackBottomRC=%RRv\n"
|
---|
590 | "!!\n"
|
---|
591 | "%.*Rhxd\n",
|
---|
592 | pVCpu->vmm.s.pbEMTStackRC, pVCpu->vmm.s.pbEMTStackBottomRC,
|
---|
593 | VMM_STACK_SIZE, pVCpu->vmm.s.pbEMTStackR3);
|
---|
594 | } /* !HWACCMIsEnabled */
|
---|
595 | break;
|
---|
596 | }
|
---|
597 |
|
---|
598 | case VERR_IEM_INSTR_NOT_IMPLEMENTED:
|
---|
599 | case VERR_IEM_ASPECT_NOT_IMPLEMENTED:
|
---|
600 | {
|
---|
601 | DBGFR3Info(pVM, "cpumguest", NULL, pHlp);
|
---|
602 | DBGFR3Info(pVM, "cpumguestinstr", NULL, pHlp);
|
---|
603 | break;
|
---|
604 | }
|
---|
605 |
|
---|
606 | default:
|
---|
607 | {
|
---|
608 | break;
|
---|
609 | }
|
---|
610 |
|
---|
611 | } /* switch (rcErr) */
|
---|
612 | Hlp.fRecSummary = false;
|
---|
613 |
|
---|
614 |
|
---|
615 | /*
|
---|
616 | * Generic info dumper loop.
|
---|
617 | */
|
---|
618 | static struct
|
---|
619 | {
|
---|
620 | const char *pszInfo;
|
---|
621 | const char *pszArgs;
|
---|
622 | } const aInfo[] =
|
---|
623 | {
|
---|
624 | { "mappings", NULL },
|
---|
625 | { "hma", NULL },
|
---|
626 | { "cpumguest", "verbose" },
|
---|
627 | { "cpumguestinstr", "verbose" },
|
---|
628 | { "cpumhyper", "verbose" },
|
---|
629 | { "cpumhost", "verbose" },
|
---|
630 | { "mode", "all" },
|
---|
631 | { "cpuid", "verbose" },
|
---|
632 | { "handlers", "phys virt hyper stats" },
|
---|
633 | { "timers", NULL },
|
---|
634 | { "activetimers", NULL },
|
---|
635 | };
|
---|
636 | for (unsigned i = 0; i < RT_ELEMENTS(aInfo); i++)
|
---|
637 | {
|
---|
638 | if (fDoneHyper && !strcmp(aInfo[i].pszInfo, "cpumhyper"))
|
---|
639 | continue;
|
---|
640 | pHlp->pfnPrintf(pHlp,
|
---|
641 | "!!\n"
|
---|
642 | "!! {%s, %s}\n"
|
---|
643 | "!!\n",
|
---|
644 | aInfo[i].pszInfo, aInfo[i].pszArgs);
|
---|
645 | DBGFR3Info(pVM, aInfo[i].pszInfo, aInfo[i].pszArgs, pHlp);
|
---|
646 | }
|
---|
647 |
|
---|
648 | /* All other info items */
|
---|
649 | DBGFR3InfoMulti(pVM,
|
---|
650 | "*",
|
---|
651 | "mappings|hma|cpum|cpumguest|cpumguestinstr|cpumhyper|cpumhost|mode|cpuid"
|
---|
652 | "|pgmpd|pgmcr3|timers|activetimers|handlers|help",
|
---|
653 | "!!\n"
|
---|
654 | "!! {%s}\n"
|
---|
655 | "!!\n",
|
---|
656 | pHlp);
|
---|
657 |
|
---|
658 |
|
---|
659 | /* done */
|
---|
660 | pHlp->pfnPrintf(pHlp,
|
---|
661 | "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
|
---|
662 |
|
---|
663 |
|
---|
664 | /*
|
---|
665 | * Repeat the summary to stderr so we don't have to scroll half a mile up.
|
---|
666 | */
|
---|
667 | if (Hlp.szSummary[0])
|
---|
668 | RTStrmPrintf(g_pStdErr,
|
---|
669 | "%s"
|
---|
670 | "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",
|
---|
671 | Hlp.szSummary);
|
---|
672 |
|
---|
673 | /*
|
---|
674 | * Delete the output instance (flushing and restoring of flags).
|
---|
675 | */
|
---|
676 | vmmR3FatalDumpInfoHlpDelete(&Hlp);
|
---|
677 | }
|
---|
678 |
|
---|