VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMGuruMeditation.cpp@ 24760

Last change on this file since 24760 was 20875, checked in by vboxsync, 15 years ago

VMM: Renamed almost all references to CallHost to CallRing3.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 20.2 KB
Line 
1/* $Id: VMMGuruMeditation.cpp 20875 2009-06-24 02:29:17Z vboxsync $ */
2/** @file
3 * VMM - The Virtual Machine Monitor, Guru Meditation Code.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22/*******************************************************************************
23* Header Files *
24*******************************************************************************/
25#define LOG_GROUP LOG_GROUP_VMM
26#include <VBox/vmm.h>
27#include <VBox/pdmapi.h>
28#include <VBox/pdmcritsect.h>
29#include <VBox/trpm.h>
30#include <VBox/dbgf.h>
31#include "VMMInternal.h"
32#include <VBox/vm.h>
33#include <VBox/mm.h>
34#include <VBox/iom.h>
35#include <VBox/em.h>
36
37#include <VBox/err.h>
38#include <VBox/param.h>
39#include <VBox/version.h>
40#include <VBox/hwaccm.h>
41#include <iprt/assert.h>
42#include <iprt/time.h>
43#include <iprt/stream.h>
44#include <iprt/string.h>
45#include <iprt/stdarg.h>
46
47
48/*******************************************************************************
49* Structures and Typedefs *
50*******************************************************************************/
51/**
52 * Structure to pass to DBGFR3Info() and for doing all other
53 * output during fatal dump.
54 */
55typedef struct VMMR3FATALDUMPINFOHLP
56{
57 /** The helper core. */
58 DBGFINFOHLP Core;
59 /** The release logger instance. */
60 PRTLOGGER pRelLogger;
61 /** The saved release logger flags. */
62 RTUINT fRelLoggerFlags;
63 /** The logger instance. */
64 PRTLOGGER pLogger;
65 /** The saved logger flags. */
66 RTUINT fLoggerFlags;
67 /** The saved logger destination flags. */
68 RTUINT fLoggerDestFlags;
69 /** Whether to output to stderr or not. */
70 bool fStdErr;
71} VMMR3FATALDUMPINFOHLP, *PVMMR3FATALDUMPINFOHLP;
72/** Pointer to a VMMR3FATALDUMPINFOHLP structure. */
73typedef const VMMR3FATALDUMPINFOHLP *PCVMMR3FATALDUMPINFOHLP;
74
75
76/**
77 * Print formatted string.
78 *
79 * @param pHlp Pointer to this structure.
80 * @param pszFormat The format string.
81 * @param ... Arguments.
82 */
83static DECLCALLBACK(void) vmmR3FatalDumpInfoHlp_pfnPrintf(PCDBGFINFOHLP pHlp, const char *pszFormat, ...)
84{
85 va_list args;
86 va_start(args, pszFormat);
87 pHlp->pfnPrintfV(pHlp, pszFormat, args);
88 va_end(args);
89}
90
91
92/**
93 * Print formatted string.
94 *
95 * @param pHlp Pointer to this structure.
96 * @param pszFormat The format string.
97 * @param args Argument list.
98 */
99static DECLCALLBACK(void) vmmR3FatalDumpInfoHlp_pfnPrintfV(PCDBGFINFOHLP pHlp, const char *pszFormat, va_list args)
100{
101 PCVMMR3FATALDUMPINFOHLP pMyHlp = (PCVMMR3FATALDUMPINFOHLP)pHlp;
102
103 if (pMyHlp->pRelLogger)
104 {
105 va_list args2;
106 va_copy(args2, args);
107 RTLogLoggerV(pMyHlp->pRelLogger, pszFormat, args2);
108 va_end(args2);
109 }
110 if (pMyHlp->pLogger)
111 {
112 va_list args2;
113 va_copy(args2, args);
114 RTLogLoggerV(pMyHlp->pLogger, pszFormat, args);
115 va_end(args2);
116 }
117 if (pMyHlp->fStdErr)
118 {
119 va_list args2;
120 va_copy(args2, args);
121 RTStrmPrintfV(g_pStdErr, pszFormat, args);
122 va_end(args2);
123 }
124}
125
126
127/**
128 * Initializes the fatal dump output helper.
129 *
130 * @param pHlp The structure to initialize.
131 */
132static void vmmR3FatalDumpInfoHlpInit(PVMMR3FATALDUMPINFOHLP pHlp)
133{
134 memset(pHlp, 0, sizeof(*pHlp));
135
136 pHlp->Core.pfnPrintf = vmmR3FatalDumpInfoHlp_pfnPrintf;
137 pHlp->Core.pfnPrintfV = vmmR3FatalDumpInfoHlp_pfnPrintfV;
138
139 /*
140 * The loggers.
141 */
142 pHlp->pRelLogger = RTLogRelDefaultInstance();
143#ifndef LOG_ENABLED
144 if (!pHlp->pRelLogger)
145#endif
146 pHlp->pLogger = RTLogDefaultInstance();
147
148 if (pHlp->pRelLogger)
149 {
150 pHlp->fRelLoggerFlags = pHlp->pRelLogger->fFlags;
151 pHlp->pRelLogger->fFlags &= ~(RTLOGFLAGS_BUFFERED | RTLOGFLAGS_DISABLED);
152 }
153
154 if (pHlp->pLogger)
155 {
156 pHlp->fLoggerFlags = pHlp->pLogger->fFlags;
157 pHlp->fLoggerDestFlags = pHlp->pLogger->fDestFlags;
158 pHlp->pLogger->fFlags &= ~(RTLOGFLAGS_BUFFERED | RTLOGFLAGS_DISABLED);
159#ifndef DEBUG_sandervl
160 pHlp->pLogger->fDestFlags |= RTLOGDEST_DEBUGGER;
161#endif
162 }
163
164 /*
165 * Check if we need write to stderr.
166 */
167#ifdef DEBUG_sandervl
168 pHlp->fStdErr = false; /* takes too long to display here */
169#else
170 pHlp->fStdErr = (!pHlp->pRelLogger || !(pHlp->pRelLogger->fDestFlags & (RTLOGDEST_STDOUT | RTLOGDEST_STDERR)))
171 && (!pHlp->pLogger || !(pHlp->pLogger->fDestFlags & (RTLOGDEST_STDOUT | RTLOGDEST_STDERR)));
172#endif
173}
174
175
176/**
177 * Deletes the fatal dump output helper.
178 *
179 * @param pHlp The structure to delete.
180 */
181static void vmmR3FatalDumpInfoHlpDelete(PVMMR3FATALDUMPINFOHLP pHlp)
182{
183 if (pHlp->pRelLogger)
184 {
185 RTLogFlush(pHlp->pRelLogger);
186 pHlp->pRelLogger->fFlags = pHlp->fRelLoggerFlags;
187 }
188
189 if (pHlp->pLogger)
190 {
191 RTLogFlush(pHlp->pLogger);
192 pHlp->pLogger->fFlags = pHlp->fLoggerFlags;
193 pHlp->pLogger->fDestFlags = pHlp->fLoggerDestFlags;
194 }
195}
196
197
198/**
199 * Dumps the VM state on a fatal error.
200 *
201 * @param pVM VM Handle.
202 * @param pVCpu VMCPU Handle.
203 * @param rcErr VBox status code.
204 */
205VMMR3DECL(void) VMMR3FatalDump(PVM pVM, PVMCPU pVCpu, int rcErr)
206{
207 /*
208 * Create our output helper and sync it with the log settings.
209 * This helper will be used for all the output.
210 */
211 VMMR3FATALDUMPINFOHLP Hlp;
212 PCDBGFINFOHLP pHlp = &Hlp.Core;
213 vmmR3FatalDumpInfoHlpInit(&Hlp);
214
215 /* Release owned locks to make sure other VCPUs can continue in case they were waiting for one. */
216#if 1
217 PDMR3CritSectLeaveAll(pVM);
218#else
219 MMR3ReleaseOwnedLocks(pVM);
220 PGMR3ReleaseOwnedLocks(pVM);
221 PDMR3ReleaseOwnedLocks(pVM);
222 IOMR3ReleaseOwnedLocks(pVM);
223 EMR3ReleaseOwnedLocks(pVM);
224#endif
225
226 /*
227 * Header.
228 */
229 pHlp->pfnPrintf(pHlp,
230 "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
231 "!!\n"
232 "!! Guru Meditation %d (%Rrc)\n"
233 "!!\n",
234 rcErr, rcErr);
235
236 /*
237 * Continue according to context.
238 */
239 bool fDoneHyper = false;
240 switch (rcErr)
241 {
242 /*
243 * Hypervisor errors.
244 */
245 case VERR_VMM_RING0_ASSERTION:
246 case VINF_EM_DBG_HYPER_ASSERTION:
247 case VERR_VMM_RING3_CALL_DISABLED:
248 {
249 const char *pszMsg1 = VMMR3GetRZAssertMsg1(pVM);
250 while (pszMsg1 && *pszMsg1 == '\n')
251 pszMsg1++;
252 const char *pszMsg2 = VMMR3GetRZAssertMsg2(pVM);
253 while (pszMsg2 && *pszMsg2 == '\n')
254 pszMsg2++;
255 pHlp->pfnPrintf(pHlp,
256 "%s"
257 "%s",
258 pszMsg1,
259 pszMsg2);
260 if ( !pszMsg2
261 || !*pszMsg2
262 || strchr(pszMsg2, '\0')[-1] != '\n')
263 pHlp->pfnPrintf(pHlp, "\n");
264 pHlp->pfnPrintf(pHlp, "!!\n");
265 /* fall thru */
266 }
267 case VERR_TRPM_DONT_PANIC:
268 case VERR_TRPM_PANIC:
269 case VINF_EM_RAW_STALE_SELECTOR:
270 case VINF_EM_RAW_IRET_TRAP:
271 case VINF_EM_DBG_HYPER_BREAKPOINT:
272 case VINF_EM_DBG_HYPER_STEPPED:
273 case VERR_VMM_HYPER_CR3_MISMATCH:
274 {
275 /*
276 * Active trap? This is only of partial interest when in hardware
277 * assisted virtualization mode, thus the different messages.
278 */
279 uint32_t uEIP = CPUMGetHyperEIP(pVCpu);
280 TRPMEVENT enmType;
281 uint8_t u8TrapNo = 0xce;
282 RTGCUINT uErrorCode = 0xdeadface;
283 RTGCUINTPTR uCR2 = 0xdeadface;
284 int rc2 = TRPMQueryTrapAll(pVCpu, &u8TrapNo, &enmType, &uErrorCode, &uCR2);
285 if (!HWACCMIsEnabled(pVM))
286 {
287 if (RT_SUCCESS(rc2))
288 pHlp->pfnPrintf(pHlp,
289 "!! TRAP=%02x ERRCD=%RGv CR2=%RGv EIP=%RX32 Type=%d\n",
290 u8TrapNo, uErrorCode, uCR2, uEIP, enmType);
291 else
292 pHlp->pfnPrintf(pHlp,
293 "!! EIP=%RX32 NOTRAP\n",
294 uEIP);
295 }
296 else if (RT_SUCCESS(rc2))
297 pHlp->pfnPrintf(pHlp,
298 "!! ACTIVE TRAP=%02x ERRCD=%RGv CR2=%RGv PC=%RGr Type=%d (Guest!)\n",
299 u8TrapNo, uErrorCode, uCR2, CPUMGetGuestRIP(pVCpu), enmType);
300
301 /*
302 * The hypervisor dump is not relevant when we're in VT-x/AMD-V mode.
303 */
304 if (HWACCMIsEnabled(pVM))
305 {
306 pHlp->pfnPrintf(pHlp, "\n");
307#if defined(RT_OS_WINDOWS) && HC_ARCH_BITS == 32
308 /* Callstack. */
309 PCDBGFSTACKFRAME pFirstFrame;
310 DBGFADDRESS eip, ebp, esp;
311
312 eip.fFlags = DBGFADDRESS_FLAGS_RING0 | DBGFADDRESS_FLAGS_VALID;
313#if HC_ARCH_BITS == 64
314 eip.FlatPtr = eip.off = pVCpu->vmm.s.CallRing3JmpBufR0.rip;
315#else
316 eip.FlatPtr = eip.off = pVCpu->vmm.s.CallRing3JmpBufR0.eip;
317#endif
318 eip.Sel = DBGF_SEL_FLAT;
319 ebp.fFlags = DBGFADDRESS_FLAGS_RING0 | DBGFADDRESS_FLAGS_VALID;
320 ebp.FlatPtr = ebp.off = pVCpu->vmm.s.CallRing3JmpBufR0.SavedEbp;
321 ebp.Sel = DBGF_SEL_FLAT;
322 esp.fFlags = DBGFADDRESS_FLAGS_RING0 | DBGFADDRESS_FLAGS_VALID;
323 esp.Sel = DBGF_SEL_FLAT;
324 esp.FlatPtr = esp.off = pVCpu->vmm.s.CallRing3JmpBufR0.SavedEsp;
325
326 rc2 = DBGFR3StackWalkBeginEx(pVM, pVCpu->idCpu, DBGFCODETYPE_RING0, &ebp, &esp, &eip,
327 DBGFRETURNTYPE_INVALID, &pFirstFrame);
328 if (RT_SUCCESS(rc2))
329 {
330 pHlp->pfnPrintf(pHlp,
331 "!!\n"
332 "!! Call Stack:\n"
333 "!!\n"
334 "EBP Ret EBP Ret CS:EIP Arg0 Arg1 Arg2 Arg3 CS:EIP Symbol [line]\n");
335 for (PCDBGFSTACKFRAME pFrame = pFirstFrame;
336 pFrame;
337 pFrame = DBGFR3StackWalkNext(pFrame))
338 {
339 pHlp->pfnPrintf(pHlp,
340 "%08RX32 %08RX32 %04RX32:%08RX32 %08RX32 %08RX32 %08RX32 %08RX32",
341 (uint32_t)pFrame->AddrFrame.off,
342 (uint32_t)pFrame->AddrReturnFrame.off,
343 (uint32_t)pFrame->AddrReturnPC.Sel,
344 (uint32_t)pFrame->AddrReturnPC.off,
345 pFrame->Args.au32[0],
346 pFrame->Args.au32[1],
347 pFrame->Args.au32[2],
348 pFrame->Args.au32[3]);
349 pHlp->pfnPrintf(pHlp, " %RTsel:%08RGv", pFrame->AddrPC.Sel, pFrame->AddrPC.off);
350 if (pFrame->pSymPC)
351 {
352 RTGCINTPTR offDisp = pFrame->AddrPC.FlatPtr - pFrame->pSymPC->Value;
353 if (offDisp > 0)
354 pHlp->pfnPrintf(pHlp, " %s+%llx", pFrame->pSymPC->szName, (int64_t)offDisp);
355 else if (offDisp < 0)
356 pHlp->pfnPrintf(pHlp, " %s-%llx", pFrame->pSymPC->szName, -(int64_t)offDisp);
357 else
358 pHlp->pfnPrintf(pHlp, " %s", pFrame->pSymPC->szName);
359 }
360 if (pFrame->pLinePC)
361 pHlp->pfnPrintf(pHlp, " [%s @ 0i%d]", pFrame->pLinePC->szFilename, pFrame->pLinePC->uLineNo);
362 pHlp->pfnPrintf(pHlp, "\n");
363 }
364 DBGFR3StackWalkEnd(pFirstFrame);
365 }
366#endif /* defined(RT_OS_WINDOWS) && HC_ARCH_BITS == 32 */
367 }
368 else
369 {
370 /*
371 * Try figure out where eip is.
372 */
373 /* core code? */
374 if (uEIP - (RTGCUINTPTR)pVM->vmm.s.pvCoreCodeRC < pVM->vmm.s.cbCoreCode)
375 pHlp->pfnPrintf(pHlp,
376 "!! EIP is in CoreCode, offset %#x\n",
377 uEIP - (RTGCUINTPTR)pVM->vmm.s.pvCoreCodeRC);
378 else
379 { /* ask PDM */ /** @todo ask DBGFR3Sym later? */
380 char szModName[64];
381 RTRCPTR RCPtrMod;
382 char szNearSym1[260];
383 RTRCPTR RCPtrNearSym1;
384 char szNearSym2[260];
385 RTRCPTR RCPtrNearSym2;
386 int rc = PDMR3LdrQueryRCModFromPC(pVM, uEIP,
387 &szModName[0], sizeof(szModName), &RCPtrMod,
388 &szNearSym1[0], sizeof(szNearSym1), &RCPtrNearSym1,
389 &szNearSym2[0], sizeof(szNearSym2), &RCPtrNearSym2);
390 if (RT_SUCCESS(rc))
391 pHlp->pfnPrintf(pHlp,
392 "!! EIP in %s (%RRv) at rva %x near symbols:\n"
393 "!! %RRv rva %RRv off %08x %s\n"
394 "!! %RRv rva %RRv off -%08x %s\n",
395 szModName, RCPtrMod, (unsigned)(uEIP - RCPtrMod),
396 RCPtrNearSym1, RCPtrNearSym1 - RCPtrMod, (unsigned)(uEIP - RCPtrNearSym1), szNearSym1,
397 RCPtrNearSym2, RCPtrNearSym2 - RCPtrMod, (unsigned)(RCPtrNearSym2 - uEIP), szNearSym2);
398 else
399 pHlp->pfnPrintf(pHlp,
400 "!! EIP is not in any code known to VMM!\n");
401 }
402
403 /* Disassemble the instruction. */
404 char szInstr[256];
405 rc2 = DBGFR3DisasInstrEx(pVM, pVCpu->idCpu, 0, 0, DBGF_DISAS_FLAGS_CURRENT_HYPER, &szInstr[0], sizeof(szInstr), NULL);
406 if (RT_SUCCESS(rc2))
407 pHlp->pfnPrintf(pHlp,
408 "!! %s\n", szInstr);
409
410 /* Dump the hypervisor cpu state. */
411 pHlp->pfnPrintf(pHlp,
412 "!!\n"
413 "!!\n"
414 "!!\n");
415 rc2 = DBGFR3Info(pVM, "cpumhyper", "verbose", pHlp);
416 fDoneHyper = true;
417
418 /* Callstack. */
419 PCDBGFSTACKFRAME pFirstFrame;
420 rc2 = DBGFR3StackWalkBegin(pVM, pVCpu->idCpu, DBGFCODETYPE_HYPER, &pFirstFrame);
421 if (RT_SUCCESS(rc2))
422 {
423 pHlp->pfnPrintf(pHlp,
424 "!!\n"
425 "!! Call Stack:\n"
426 "!!\n"
427 "EBP Ret EBP Ret CS:EIP Arg0 Arg1 Arg2 Arg3 CS:EIP Symbol [line]\n");
428 for (PCDBGFSTACKFRAME pFrame = pFirstFrame;
429 pFrame;
430 pFrame = DBGFR3StackWalkNext(pFrame))
431 {
432 pHlp->pfnPrintf(pHlp,
433 "%08RX32 %08RX32 %04RX32:%08RX32 %08RX32 %08RX32 %08RX32 %08RX32",
434 (uint32_t)pFrame->AddrFrame.off,
435 (uint32_t)pFrame->AddrReturnFrame.off,
436 (uint32_t)pFrame->AddrReturnPC.Sel,
437 (uint32_t)pFrame->AddrReturnPC.off,
438 pFrame->Args.au32[0],
439 pFrame->Args.au32[1],
440 pFrame->Args.au32[2],
441 pFrame->Args.au32[3]);
442 pHlp->pfnPrintf(pHlp, " %RTsel:%08RGv", pFrame->AddrPC.Sel, pFrame->AddrPC.off);
443 if (pFrame->pSymPC)
444 {
445 RTGCINTPTR offDisp = pFrame->AddrPC.FlatPtr - pFrame->pSymPC->Value;
446 if (offDisp > 0)
447 pHlp->pfnPrintf(pHlp, " %s+%llx", pFrame->pSymPC->szName, (int64_t)offDisp);
448 else if (offDisp < 0)
449 pHlp->pfnPrintf(pHlp, " %s-%llx", pFrame->pSymPC->szName, -(int64_t)offDisp);
450 else
451 pHlp->pfnPrintf(pHlp, " %s", pFrame->pSymPC->szName);
452 }
453 if (pFrame->pLinePC)
454 pHlp->pfnPrintf(pHlp, " [%s @ 0i%d]", pFrame->pLinePC->szFilename, pFrame->pLinePC->uLineNo);
455 pHlp->pfnPrintf(pHlp, "\n");
456 }
457 DBGFR3StackWalkEnd(pFirstFrame);
458 }
459
460 /* raw stack */
461 pHlp->pfnPrintf(pHlp,
462 "!!\n"
463 "!! Raw stack (mind the direction). pbEMTStackRC=%RRv pbEMTStackBottomRC=%RRv\n"
464 "!!\n"
465 "%.*Rhxd\n",
466 pVCpu->vmm.s.pbEMTStackRC, pVCpu->vmm.s.pbEMTStackBottomRC,
467 VMM_STACK_SIZE, pVCpu->vmm.s.pbEMTStackR3);
468 } /* !HWACCMIsEnabled */
469 break;
470 }
471
472 default:
473 {
474 break;
475 }
476
477 } /* switch (rcErr) */
478
479
480 /*
481 * Generic info dumper loop.
482 */
483 static struct
484 {
485 const char *pszInfo;
486 const char *pszArgs;
487 } const aInfo[] =
488 {
489 { "mappings", NULL },
490 { "hma", NULL },
491 { "cpumguest", "verbose" },
492 { "cpumguestinstr", "verbose" },
493 { "cpumhyper", "verbose" },
494 { "cpumhost", "verbose" },
495 { "mode", "all" },
496 { "cpuid", "verbose" },
497 { "gdt", NULL },
498 { "ldt", NULL },
499 //{ "tss", NULL },
500 { "ioport", NULL },
501 { "mmio", NULL },
502 { "phys", NULL },
503 //{ "pgmpd", NULL }, - doesn't always work at init time...
504 { "timers", NULL },
505 { "activetimers", NULL },
506 { "handlers", "phys virt hyper stats" },
507 { "cfgm", NULL },
508 };
509 for (unsigned i = 0; i < RT_ELEMENTS(aInfo); i++)
510 {
511 if (fDoneHyper && !strcmp(aInfo[i].pszInfo, "cpumhyper"))
512 continue;
513 pHlp->pfnPrintf(pHlp,
514 "!!\n"
515 "!! {%s, %s}\n"
516 "!!\n",
517 aInfo[i].pszInfo, aInfo[i].pszArgs);
518 DBGFR3Info(pVM, aInfo[i].pszInfo, aInfo[i].pszArgs, pHlp);
519 }
520
521 /* done */
522 pHlp->pfnPrintf(pHlp,
523 "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
524
525
526 /*
527 * Delete the output instance (flushing and restoring of flags).
528 */
529 vmmR3FatalDumpInfoHlpDelete(&Hlp);
530
531 /*
532 * Reset the ring-0 long jump buffer and stack.
533 */
534 /** @todo reset the R0 for the calling virtual cpu. We'll assert (luckily) in
535 * PGMPhys.cpp otherwise. */
536}
537
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