VirtualBox

Changeset 56514 in vbox


Ignore:
Timestamp:
Jun 18, 2015 12:11:56 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
101133
Message:

VMM/DBGF: Dump guest core with a more standardized CPU dump including FPU/SSE/AVX state, version number of core format is bumped.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/vmm/dbgfcorefmt.h

    r56302 r56514  
    4848#define DBGFCORE_MAGIC          UINT32_C(0xc01ac0de)
    4949/** DBGCORECOREDESCRIPTOR::u32FmtVersion. */
    50 #define DBGFCORE_FMT_VERSION    UINT32_C(0x00010001)
     50#define DBGFCORE_FMT_VERSION    UINT32_C(0x00010002)
     51
     52/**
     53 * An x86 segment selector.
     54 */
     55typedef struct DBGFCORESEL
     56{
     57    uint64_t        uBase;
     58    uint32_t        uLimit;
     59    uint32_t        uAttr;
     60    uint16_t        uSel;
     61    uint16_t        uReserved;
     62} VBOXX86SEL;
     63AssertCompileSizeAlignment(DBGFCORESEL, 8);
     64
     65/**
     66 * A gdtr/ldtr descriptor.
     67 */
     68typedef struct DBGFCOREXDTR
     69{
     70    uint64_t        uAddr;
     71    uint32_t        cb;
     72    uint32_t        uReserved0;
     73} DBGFXDTR;
     74AssertCompileSizeAlignment(DBGFCORESEL, 8);
     75
     76/**
     77 * A simpler to parse CPU dump than CPUMCTX.
     78 *
     79 * Please bump DBGFCORE_FMT_VERSION by 1 if you make any changes to this
     80 * structure.
     81 */
     82typedef struct DBGFCORECPU
     83{
     84    uint64_t            rax;
     85    uint64_t            rbx;
     86    uint64_t            rcx;
     87    uint64_t            rdx;
     88    uint64_t            rsi;
     89    uint64_t            rdi;
     90    uint64_t            r8;
     91    uint64_t            r9;
     92    uint64_t            r10;
     93    uint64_t            r11;
     94    uint64_t            r12;
     95    uint64_t            r13;
     96    uint64_t            r14;
     97    uint64_t            r15;
     98    uint64_t            rip;
     99    uint64_t            rsp;
     100    uint64_t            rbp;
     101    DBGFCORESEL         cs;
     102    DBGFCORESEL         ds;
     103    DBGFCORESEL         es;
     104    DBGFCORESEL         fs;
     105    DBGFCORESEL         gs;
     106    DBGFCORESEL         ss;
     107    uint64_t            cr0;
     108    uint64_t            cr2;
     109    uint64_t            cr3;
     110    uint64_t            cr4;
     111    uint64_t            dr[8];
     112    DBGFCOREXDTR        gdtr;
     113    DBGFCOREXDTR        idtr;
     114    VBOXX86SEL          ldtr;
     115    VBOXX86SEL          tr;
     116    union
     117    {
     118        uint64_t        cs;
     119        uint64_t        eip;
     120        uint64_t        esp;
     121    } sysenter;
     122    uint64_t            msrEFER;
     123    uint64_t            msrSTAR;
     124    uint64_t            msrPAT;
     125    uint64_t            msrLSTAR;
     126    uint64_t            msrCSTAR;
     127    uint64_t            msrSFMASK;
     128    uint64_t            msrKernelGSBase;
     129    uint64_t            msrApicBase;
     130    uint64_t            aXcr[2];
     131    X86XSAVEAREA        ext;
     132} DBGFCORECPU;
     133/** Pointer to a DBGF-core CPU. */
     134typedef DBGFCORECPU *PDBGFCORECPU;
     135/** Pointer to the const DBGF-core CPU. */
     136typedef const DBGFCORECPU *PCDBGFCORECPU;
     137AssertCompileMemberAlignment(DBGFCORECPU, cr0,     8);
     138AssertCompileMemberAlignment(DBGFCORECPU, msrEFER, 8);
     139AssertCompileMemberAlignment(DBGFCORECPU, ext,     8);
     140AssertCompileSizeAlignment(DBGFCORECPU, 8);
    51141
    52142/**
  • trunk/include/iprt/x86.h

    r56291 r56514  
    27442744
    27452745
    2746 
     2746/**
     2747 * x86 FPU/SSE/AVX/XXXX state.
     2748 *
     2749 * Please bump DBGFCORE_FMT_VERSION by 1 in dbgfcorefmt.h if you make any
     2750 * changes to this structure.
     2751 */
    27472752typedef struct X86XSAVEAREA
    27482753{
  • trunk/src/VBox/VMM/VMMR3/DBGFCoreWrite.cpp

    r56302 r56514  
    5151#include <iprt/param.h>
    5252#include <iprt/file.h>
     53#include <iprt/mem.h>
    5354
    5455#include "DBGFInternal.h"
     
    310311
    311312/**
     313 * Gets the guest-CPU context suitable for dumping into the core file.
     314 *
     315 * @param   pCtx        Pointer to the guest-CPU context.
     316 * @param   pDbgfCpu    Where to dump the guest-CPU data.
     317 */
     318static void dbgfR3GetCoreCpu(PCPUMCTX pCtx, PDBGFCORECPU pDbgfCpu)
     319{
     320#define DBGFCOPYSEL(a_dbgfsel, a_cpumselreg) \
     321    do { \
     322        (a_dbgfsel).uBase  = (a_cpumselreg).u64Base; \
     323        (a_dbgfsel).uLimit = (a_cpumselreg).u32Limit; \
     324        (a_dbgfsel).uAttr  = (a_cpumselreg).Attr.u; \
     325        (a_dbgfsel).uSel   = (a_cpumselreg).Sel; \
     326    } while (0)
     327
     328    pDbgfCpu->rax             = pCtx->rax;
     329    pDbgfCpu->rbx             = pCtx->rbx;
     330    pDbgfCpu->rcx             = pCtx->rcx;
     331    pDbgfCpu->rdx             = pCtx->rdx;
     332    pDbgfCpu->rsi             = pCtx->rsi;
     333    pDbgfCpu->rdi             = pCtx->rdi;
     334    pDbgfCpu->r8              = pCtx->r8;
     335    pDbgfCpu->r9              = pCtx->r9;
     336    pDbgfCpu->r10             = pCtx->r10;
     337    pDbgfCpu->r11             = pCtx->r11;
     338    pDbgfCpu->r12             = pCtx->r12;
     339    pDbgfCpu->r13             = pCtx->r13;
     340    pDbgfCpu->r14             = pCtx->r14;
     341    pDbgfCpu->r15             = pCtx->r15;
     342    pDbgfCpu->rip             = pCtx->rip;
     343    pDbgfCpu->rsp             = pCtx->rsp;
     344    pDbgfCpu->rbp             = pCtx->rbp;
     345    DBGFCOPYSEL(pDbgfCpu->cs, pCtx->cs);
     346    DBGFCOPYSEL(pDbgfCpu->ds, pCtx->ds);
     347    DBGFCOPYSEL(pDbgfCpu->es, pCtx->es);
     348    DBGFCOPYSEL(pDbgfCpu->fs, pCtx->fs);
     349    DBGFCOPYSEL(pDbgfCpu->gs, pCtx->gs);
     350    DBGFCOPYSEL(pDbgfCpu->ss, pCtx->ss);
     351    pDbgfCpu->cr0             = pCtx->cr0;
     352    pDbgfCpu->cr2             = pCtx->cr2;
     353    pDbgfCpu->cr3             = pCtx->cr3;
     354    pDbgfCpu->cr4             = pCtx->cr4;
     355    AssertCompile(RT_ELEMENTS(pDbgfCpu->dr) == RT_ELEMENTS(pCtx->dr));
     356    for (unsigned i = 0; i < RT_ELEMENTS(pDbgfCpu->dr); i++)
     357        pDbgfCpu->dr[i] = pCtx->dr[i];
     358    pDbgfCpu->gdtr.uAddr      = pCtx->gdtr.pGdt;
     359    pDbgfCpu->gdtr.cb         = pCtx->gdtr.cbGdt;
     360    pDbgfCpu->idtr.uAddr      = pCtx->idtr.pIdt;
     361    pDbgfCpu->idtr.cb         = pCtx->idtr.cbIdt;
     362    DBGFCOPYSEL(pDbgfCpu->ldtr, pCtx->ldtr);
     363    DBGFCOPYSEL(pDbgfCpu->tr,   pCtx->tr);
     364    pDbgfCpu->sysenter.cs     = pCtx->SysEnter.cs;
     365    pDbgfCpu->sysenter.eip    = pCtx->SysEnter.eip;
     366    pDbgfCpu->sysenter.esp    = pCtx->SysEnter.esp;
     367    pDbgfCpu->msrEFER         = pCtx->msrEFER;
     368    pDbgfCpu->msrSTAR         = pCtx->msrSTAR;
     369    pDbgfCpu->msrPAT          = pCtx->msrPAT;
     370    pDbgfCpu->msrLSTAR        = pCtx->msrLSTAR;
     371    pDbgfCpu->msrCSTAR        = pCtx->msrCSTAR;
     372    pDbgfCpu->msrSFMASK       = pCtx->msrSFMASK;
     373    pDbgfCpu->msrKernelGSBase = pCtx->msrKERNELGSBASE;
     374    pDbgfCpu->msrApicBase     = pCtx->msrApicBase;
     375    pDbgfCpu->aXcr[0]         = pCtx->aXcr[0];
     376    pDbgfCpu->aXcr[1]         = pCtx->aXcr[1];
     377    AssertCompile(sizeof(pDbgfCpu->ext) == sizeof(*pCtx->pXStateR3));
     378    memcpy(&pDbgfCpu->ext, pCtx->pXStateR3, sizeof(pDbgfCpu->ext));
     379
     380#undef DBGFCOPYSEL
     381}
     382
     383
     384/**
    312385 * Worker function for dbgfR3CoreWrite() which does the writing.
    313386 *
     
    346419    uint64_t const cbCoreDescriptor   = Elf64NoteSectionSize(g_pcszCoreVBoxCore, sizeof(CoreDescriptor));
    347420    uint64_t const offCpuDumps        = offCoreDescriptor + cbCoreDescriptor;
    348     uint64_t const cbCpuDumps         = pVM->cCpus * Elf64NoteSectionSize(g_pcszCoreVBoxCpu, sizeof(CPUMCTX));
     421    uint64_t const cbCpuDumps         = pVM->cCpus * Elf64NoteSectionSize(g_pcszCoreVBoxCpu, sizeof(DBGFCORECPU));
    349422    uint64_t const offMemory          = offCpuDumps       + cbCpuDumps;
    350423
     
    429502     * Write the CPU context note headers and data.
    430503     */
    431     /** @todo r=ramshankar: Dump a more standardized CPU structure rather than
    432      *        dumping CPUMCTX and bump the core file version number. */
    433504    Assert(RTFileTell(hFile) == offCpuDumps);
     505    PDBGFCORECPU pDbgfCoreCpu = (PDBGFCORECPU)RTMemAlloc(sizeof(*pDbgfCoreCpu));
     506    if (RT_UNLIKELY(!pDbgfCoreCpu))
     507    {
     508        LogRel((DBGFLOG_NAME ": failed to alloc %u bytes for DBGFCORECPU\n", sizeof(*pDbgfCoreCpu)));
     509        return VERR_NO_MEMORY;
     510    }
     511
    434512    for (uint32_t iCpu = 0; iCpu < pVM->cCpus; iCpu++)
    435513    {
    436         PCPUMCTX pCpuCtx = CPUMQueryGuestCtxPtr(&pVM->aCpus[iCpu]);
    437         rc = Elf64WriteNoteHdr(hFile, NT_VBOXCPU, g_pcszCoreVBoxCpu, pCpuCtx, sizeof(CPUMCTX));
     514        PVMCPU      pVCpu = &pVM->aCpus[iCpu];
     515        PCPUMCTX    pCtx  = CPUMQueryGuestCtxPtr(pVCpu);
     516        if (RT_UNLIKELY(!pCtx))
     517        {
     518            LogRel((DBGFLOG_NAME ": CPUMQueryGuestCtxPtr failed for vCPU[%u]\n", iCpu));
     519            RTMemFree(pDbgfCoreCpu);
     520            return VERR_INVALID_POINTER;
     521        }
     522
     523        RT_BZERO(pDbgfCoreCpu, sizeof(*pDbgfCoreCpu));
     524        dbgfR3GetCoreCpu(pCtx, pDbgfCoreCpu);
     525        rc = Elf64WriteNoteHdr(hFile, NT_VBOXCPU, g_pcszCoreVBoxCpu, pDbgfCoreCpu, sizeof(*pDbgfCoreCpu));
    438526        if (RT_FAILURE(rc))
    439527        {
    440528            LogRel((DBGFLOG_NAME ": Elf64WriteNoteHdr failed for vCPU[%u] rc=%Rrc\n", iCpu, rc));
     529            RTMemFree(pDbgfCoreCpu);
    441530            return rc;
    442531        }
    443532    }
     533    RTMemFree(pDbgfCoreCpu);
     534    pDbgfCoreCpu = NULL;
    444535
    445536    /*
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette