VirtualBox

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

Last change on this file since 92341 was 90829, checked in by vboxsync, 3 years ago

IPRT,VMM,SUPDrv,++: Reworked the IPRT logger structure and how the VMM ring-0 uses it. bugref:10086

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