VirtualBox

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

Last change on this file since 20776 was 20754, checked in by vboxsync, 16 years ago

todo

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 20.1 KB
Line 
1/* $Id: VMMGuruMeditation.cpp 20754 2009-06-21 23:18:45Z 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 {
248 const char *pszMsg1 = VMMR3GetRZAssertMsg1(pVM);
249 while (pszMsg1 && *pszMsg1 == '\n')
250 pszMsg1++;
251 const char *pszMsg2 = VMMR3GetRZAssertMsg2(pVM);
252 while (pszMsg2 && *pszMsg2 == '\n')
253 pszMsg2++;
254 pHlp->pfnPrintf(pHlp,
255 "%s"
256 "%s",
257 pszMsg1,
258 pszMsg2);
259 if ( !pszMsg2
260 || !*pszMsg2
261 || strchr(pszMsg2, '\0')[-1] != '\n')
262 pHlp->pfnPrintf(pHlp, "\n");
263 pHlp->pfnPrintf(pHlp, "!!\n");
264 /* fall thru */
265 }
266 case VERR_TRPM_DONT_PANIC:
267 case VERR_TRPM_PANIC:
268 case VINF_EM_RAW_STALE_SELECTOR:
269 case VINF_EM_RAW_IRET_TRAP:
270 case VINF_EM_DBG_HYPER_BREAKPOINT:
271 case VINF_EM_DBG_HYPER_STEPPED:
272 {
273 /*
274 * Active trap? This is only of partial interest when in hardware
275 * assisted virtualization mode, thus the different messages.
276 */
277 uint32_t uEIP = CPUMGetHyperEIP(pVCpu);
278 TRPMEVENT enmType;
279 uint8_t u8TrapNo = 0xce;
280 RTGCUINT uErrorCode = 0xdeadface;
281 RTGCUINTPTR uCR2 = 0xdeadface;
282 int rc2 = TRPMQueryTrapAll(pVCpu, &u8TrapNo, &enmType, &uErrorCode, &uCR2);
283 if (!HWACCMIsEnabled(pVM))
284 {
285 if (RT_SUCCESS(rc2))
286 pHlp->pfnPrintf(pHlp,
287 "!! TRAP=%02x ERRCD=%RGv CR2=%RGv EIP=%RX32 Type=%d\n",
288 u8TrapNo, uErrorCode, uCR2, uEIP, enmType);
289 else
290 pHlp->pfnPrintf(pHlp,
291 "!! EIP=%RX32 NOTRAP\n",
292 uEIP);
293 }
294 else if (RT_SUCCESS(rc2))
295 pHlp->pfnPrintf(pHlp,
296 "!! ACTIVE TRAP=%02x ERRCD=%RGv CR2=%RGv PC=%RGr Type=%d (Guest!)\n",
297 u8TrapNo, uErrorCode, uCR2, CPUMGetGuestRIP(pVCpu), enmType);
298
299 /*
300 * The hypervisor dump is not relevant when we're in VT-x/AMD-V mode.
301 */
302 if (HWACCMIsEnabled(pVM))
303 {
304 pHlp->pfnPrintf(pHlp, "\n");
305#if defined(RT_OS_WINDOWS) && HC_ARCH_BITS == 32
306 /* Callstack. */
307 PCDBGFSTACKFRAME pFirstFrame;
308 DBGFADDRESS eip, ebp, esp;
309
310 eip.fFlags = DBGFADDRESS_FLAGS_RING0 | DBGFADDRESS_FLAGS_VALID;
311#if HC_ARCH_BITS == 64
312 eip.FlatPtr = eip.off = pVCpu->vmm.s.CallHostR0JmpBuf.rip;
313#else
314 eip.FlatPtr = eip.off = pVCpu->vmm.s.CallHostR0JmpBuf.eip;
315#endif
316 eip.Sel = DBGF_SEL_FLAT;
317 ebp.fFlags = DBGFADDRESS_FLAGS_RING0 | DBGFADDRESS_FLAGS_VALID;
318 ebp.FlatPtr = ebp.off = pVCpu->vmm.s.CallHostR0JmpBuf.SavedEbp;
319 ebp.Sel = DBGF_SEL_FLAT;
320 esp.fFlags = DBGFADDRESS_FLAGS_RING0 | DBGFADDRESS_FLAGS_VALID;
321 esp.Sel = DBGF_SEL_FLAT;
322 esp.FlatPtr = esp.off = pVCpu->vmm.s.CallHostR0JmpBuf.SavedEsp;
323
324 rc2 = DBGFR3StackWalkBeginEx(pVM, pVCpu->idCpu, DBGFCODETYPE_RING0, &ebp, &esp, &eip,
325 DBGFRETURNTYPE_INVALID, &pFirstFrame);
326 if (RT_SUCCESS(rc2))
327 {
328 pHlp->pfnPrintf(pHlp,
329 "!!\n"
330 "!! Call Stack:\n"
331 "!!\n"
332 "EBP Ret EBP Ret CS:EIP Arg0 Arg1 Arg2 Arg3 CS:EIP Symbol [line]\n");
333 for (PCDBGFSTACKFRAME pFrame = pFirstFrame;
334 pFrame;
335 pFrame = DBGFR3StackWalkNext(pFrame))
336 {
337 pHlp->pfnPrintf(pHlp,
338 "%08RX32 %08RX32 %04RX32:%08RX32 %08RX32 %08RX32 %08RX32 %08RX32",
339 (uint32_t)pFrame->AddrFrame.off,
340 (uint32_t)pFrame->AddrReturnFrame.off,
341 (uint32_t)pFrame->AddrReturnPC.Sel,
342 (uint32_t)pFrame->AddrReturnPC.off,
343 pFrame->Args.au32[0],
344 pFrame->Args.au32[1],
345 pFrame->Args.au32[2],
346 pFrame->Args.au32[3]);
347 pHlp->pfnPrintf(pHlp, " %RTsel:%08RGv", pFrame->AddrPC.Sel, pFrame->AddrPC.off);
348 if (pFrame->pSymPC)
349 {
350 RTGCINTPTR offDisp = pFrame->AddrPC.FlatPtr - pFrame->pSymPC->Value;
351 if (offDisp > 0)
352 pHlp->pfnPrintf(pHlp, " %s+%llx", pFrame->pSymPC->szName, (int64_t)offDisp);
353 else if (offDisp < 0)
354 pHlp->pfnPrintf(pHlp, " %s-%llx", pFrame->pSymPC->szName, -(int64_t)offDisp);
355 else
356 pHlp->pfnPrintf(pHlp, " %s", pFrame->pSymPC->szName);
357 }
358 if (pFrame->pLinePC)
359 pHlp->pfnPrintf(pHlp, " [%s @ 0i%d]", pFrame->pLinePC->szFilename, pFrame->pLinePC->uLineNo);
360 pHlp->pfnPrintf(pHlp, "\n");
361 }
362 DBGFR3StackWalkEnd(pFirstFrame);
363 }
364#endif /* defined(RT_OS_WINDOWS) && HC_ARCH_BITS == 32 */
365 }
366 else
367 {
368 /*
369 * Try figure out where eip is.
370 */
371 /* core code? */
372 if (uEIP - (RTGCUINTPTR)pVM->vmm.s.pvCoreCodeRC < pVM->vmm.s.cbCoreCode)
373 pHlp->pfnPrintf(pHlp,
374 "!! EIP is in CoreCode, offset %#x\n",
375 uEIP - (RTGCUINTPTR)pVM->vmm.s.pvCoreCodeRC);
376 else
377 { /* ask PDM */ /** @todo ask DBGFR3Sym later? */
378 char szModName[64];
379 RTRCPTR RCPtrMod;
380 char szNearSym1[260];
381 RTRCPTR RCPtrNearSym1;
382 char szNearSym2[260];
383 RTRCPTR RCPtrNearSym2;
384 int rc = PDMR3LdrQueryRCModFromPC(pVM, uEIP,
385 &szModName[0], sizeof(szModName), &RCPtrMod,
386 &szNearSym1[0], sizeof(szNearSym1), &RCPtrNearSym1,
387 &szNearSym2[0], sizeof(szNearSym2), &RCPtrNearSym2);
388 if (RT_SUCCESS(rc))
389 pHlp->pfnPrintf(pHlp,
390 "!! EIP in %s (%RRv) at rva %x near symbols:\n"
391 "!! %RRv rva %RRv off %08x %s\n"
392 "!! %RRv rva %RRv off -%08x %s\n",
393 szModName, RCPtrMod, (unsigned)(uEIP - RCPtrMod),
394 RCPtrNearSym1, RCPtrNearSym1 - RCPtrMod, (unsigned)(uEIP - RCPtrNearSym1), szNearSym1,
395 RCPtrNearSym2, RCPtrNearSym2 - RCPtrMod, (unsigned)(RCPtrNearSym2 - uEIP), szNearSym2);
396 else
397 pHlp->pfnPrintf(pHlp,
398 "!! EIP is not in any code known to VMM!\n");
399 }
400
401 /* Disassemble the instruction. */
402 char szInstr[256];
403 rc2 = DBGFR3DisasInstrEx(pVM, pVCpu->idCpu, 0, 0, DBGF_DISAS_FLAGS_CURRENT_HYPER, &szInstr[0], sizeof(szInstr), NULL);
404 if (RT_SUCCESS(rc2))
405 pHlp->pfnPrintf(pHlp,
406 "!! %s\n", szInstr);
407
408 /* Dump the hypervisor cpu state. */
409 pHlp->pfnPrintf(pHlp,
410 "!!\n"
411 "!!\n"
412 "!!\n");
413 rc2 = DBGFR3Info(pVM, "cpumhyper", "verbose", pHlp);
414 fDoneHyper = true;
415
416 /* Callstack. */
417 PCDBGFSTACKFRAME pFirstFrame;
418 rc2 = DBGFR3StackWalkBegin(pVM, pVCpu->idCpu, DBGFCODETYPE_HYPER, &pFirstFrame);
419 if (RT_SUCCESS(rc2))
420 {
421 pHlp->pfnPrintf(pHlp,
422 "!!\n"
423 "!! Call Stack:\n"
424 "!!\n"
425 "EBP Ret EBP Ret CS:EIP Arg0 Arg1 Arg2 Arg3 CS:EIP Symbol [line]\n");
426 for (PCDBGFSTACKFRAME pFrame = pFirstFrame;
427 pFrame;
428 pFrame = DBGFR3StackWalkNext(pFrame))
429 {
430 pHlp->pfnPrintf(pHlp,
431 "%08RX32 %08RX32 %04RX32:%08RX32 %08RX32 %08RX32 %08RX32 %08RX32",
432 (uint32_t)pFrame->AddrFrame.off,
433 (uint32_t)pFrame->AddrReturnFrame.off,
434 (uint32_t)pFrame->AddrReturnPC.Sel,
435 (uint32_t)pFrame->AddrReturnPC.off,
436 pFrame->Args.au32[0],
437 pFrame->Args.au32[1],
438 pFrame->Args.au32[2],
439 pFrame->Args.au32[3]);
440 pHlp->pfnPrintf(pHlp, " %RTsel:%08RGv", pFrame->AddrPC.Sel, pFrame->AddrPC.off);
441 if (pFrame->pSymPC)
442 {
443 RTGCINTPTR offDisp = pFrame->AddrPC.FlatPtr - pFrame->pSymPC->Value;
444 if (offDisp > 0)
445 pHlp->pfnPrintf(pHlp, " %s+%llx", pFrame->pSymPC->szName, (int64_t)offDisp);
446 else if (offDisp < 0)
447 pHlp->pfnPrintf(pHlp, " %s-%llx", pFrame->pSymPC->szName, -(int64_t)offDisp);
448 else
449 pHlp->pfnPrintf(pHlp, " %s", pFrame->pSymPC->szName);
450 }
451 if (pFrame->pLinePC)
452 pHlp->pfnPrintf(pHlp, " [%s @ 0i%d]", pFrame->pLinePC->szFilename, pFrame->pLinePC->uLineNo);
453 pHlp->pfnPrintf(pHlp, "\n");
454 }
455 DBGFR3StackWalkEnd(pFirstFrame);
456 }
457
458 /* raw stack */
459 pHlp->pfnPrintf(pHlp,
460 "!!\n"
461 "!! Raw stack (mind the direction). pbEMTStackRC=%RRv pbEMTStackBottomRC=%RRv\n"
462 "!!\n"
463 "%.*Rhxd\n",
464 pVCpu->vmm.s.pbEMTStackRC, pVCpu->vmm.s.pbEMTStackBottomRC,
465 VMM_STACK_SIZE, pVCpu->vmm.s.pbEMTStackR3);
466 } /* !HWACCMIsEnabled */
467 break;
468 }
469
470 default:
471 {
472 break;
473 }
474
475 } /* switch (rcErr) */
476
477
478 /*
479 * Generic info dumper loop.
480 */
481 static struct
482 {
483 const char *pszInfo;
484 const char *pszArgs;
485 } const aInfo[] =
486 {
487 { "mappings", NULL },
488 { "hma", NULL },
489 { "cpumguest", "verbose" },
490 { "cpumguestinstr", "verbose" },
491 { "cpumhyper", "verbose" },
492 { "cpumhost", "verbose" },
493 { "mode", "all" },
494 { "cpuid", "verbose" },
495 { "gdt", NULL },
496 { "ldt", NULL },
497 //{ "tss", NULL },
498 { "ioport", NULL },
499 { "mmio", NULL },
500 { "phys", NULL },
501 //{ "pgmpd", NULL }, - doesn't always work at init time...
502 { "timers", NULL },
503 { "activetimers", NULL },
504 { "handlers", "phys virt hyper stats" },
505 { "cfgm", NULL },
506 };
507 for (unsigned i = 0; i < RT_ELEMENTS(aInfo); i++)
508 {
509 if (fDoneHyper && !strcmp(aInfo[i].pszInfo, "cpumhyper"))
510 continue;
511 pHlp->pfnPrintf(pHlp,
512 "!!\n"
513 "!! {%s, %s}\n"
514 "!!\n",
515 aInfo[i].pszInfo, aInfo[i].pszArgs);
516 DBGFR3Info(pVM, aInfo[i].pszInfo, aInfo[i].pszArgs, pHlp);
517 }
518
519 /* done */
520 pHlp->pfnPrintf(pHlp,
521 "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
522
523
524 /*
525 * Delete the output instance (flushing and restoring of flags).
526 */
527 vmmR3FatalDumpInfoHlpDelete(&Hlp);
528
529 /*
530 * Reset the ring-0 long jump buffer and stack.
531 */
532 /** @todo reset the R0 for the calling virtual cpu. We'll assert (luckily) in
533 * PGMPhys.cpp otherwise. */
534}
535
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