DBGFR3Trace.cpp revision 2afbe132eb7931e0125141eabe3a48e08f1ffab5
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * DBGF - Debugger Facility, Tracing.
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * Copyright (C) 2011 Oracle Corporation
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * available from http://www.virtualbox.org. This file is free software;
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * you can redistribute it and/or modify it under the terms of the GNU
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * General Public License (GPL) as published by the Free Software
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync/*******************************************************************************
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync* Header Files *
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync*******************************************************************************/
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync/*******************************************************************************
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync* Internal Functions *
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync*******************************************************************************/
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsyncstatic DECLCALLBACK(void) dbgfR3TraceInfo(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * Initializes the tracing.
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * @returns VBox status code
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * @param pVM The VM handle.
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsyncstatic int dbgfR3TraceEnable(PVM pVM, uint32_t cbEntry, uint32_t cEntries)
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * Don't enable it twice.
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * Resolve default parameter values.
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync rc = CFGMR3QueryU32Def(CFGMR3GetChild(CFGMR3GetRoot(pVM), "DBGF"), "TraceBufEntrySize", &cbEntry, 128);
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync rc = CFGMR3QueryU32Def(CFGMR3GetChild(CFGMR3GetRoot(pVM), "DBGF"), "TraceBufEntries", &cEntries, 4096);
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * Figure the required size.
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync rc = RTTraceBufCarve(&hTraceBuf, cEntries, cbEntry, 0 /*fFlags*/, NULL, &cbBlock);
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync AssertReturn(!RT_SUCCESS_NP(rc), VERR_INTERNAL_ERROR_4);
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * Allocate a hyper heap block and carve a trace buffer out of it.
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * Note! We ASSUME that the returned trace buffer handle has the same value
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * as the heap block.
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync rc = MMR3HyperAllocOnceNoRel(pVM, cbBlock, PAGE_SIZE, MM_TAG_DBGF, &pvBlock);
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync rc = RTTraceBufCarve(&hTraceBuf, cEntries, cbEntry, 0 /*fFlags*/, pvBlock, &cbBlock);
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync AssertRelease(hTraceBuf == (RTTRACEBUF)pvBlock && (void *)hTraceBuf == pvBlock);
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * Initializes the tracing.
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * @returns VBox status code
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * @param pVM The VM handle.
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * Initialize the trace buffer handles.
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * Check the config and enable tracing if requested.
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync bool const fDefault = true;
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync bool const fDefault = false;
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync int rc = CFGMR3QueryBoolDef(CFGMR3GetChild(CFGMR3GetRoot(pVM), "DBGF"), "TracingEnabled",
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * Register a debug info item that will dump the trace buffer content.
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync rc = DBGFR3InfoRegisterInternal(pVM, "tracebuf", "Display the trace buffer content. No arguments.", dbgfR3TraceInfo);
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * Terminates the tracing.
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * @param pVM The VM handle.
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync /* nothing to do */
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * Relocates the trace buffer handle in RC.
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * @param pVM The VM handle.
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync pVM->hTraceBufRC = MMHyperCCToRC(pVM, pVM->hTraceBufR3);
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * @callback_method_impl{FNRTTRACEBUFCALLBACK}
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsyncdbgfR3TraceInfoDumpEntry(RTTRACEBUF hTraceBuf, uint32_t iEntry, uint64_t NanoTS, RTCPUID idCpu, const char *pszMsg, void *pvUser)
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync pHlp->pfnPrintf(pHlp, "#%04u/%'llu/%02x: %s\n", iEntry, NanoTS, idCpu, pszMsg);
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * @callback_method_impl{FNDBGFHANDLERINT, Info handler for displaying the trace buffer content.}
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsyncstatic DECLCALLBACK(void) dbgfR3TraceInfo(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync pHlp->pfnPrintf(pHlp, "Trace buffer %p - %u entries of %u bytes\n",
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync hTraceBuf, RTTraceBufGetEntryCount(hTraceBuf), RTTraceBufGetEntrySize(hTraceBuf));