VirtualBox

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

Last change on this file since 30060 was 30060, checked in by vboxsync, 14 years ago

VMM: Dump all info items into the guru meditation log.

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