a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * DBGF - Debugger Facility, Tracing.
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * Copyright (C) 2011-2012 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);
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync/*******************************************************************************
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync* Global Variables *
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync*******************************************************************************/
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * VMM trace point group translation table.
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsyncstatic const struct
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync /** The group name. */
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync /** The name length. */
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync /** The mask. */
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * Initializes the tracing.
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * @returns VBox status code
4bfa7b58e362a1bca0628643c352c137900bf01avboxsync * @param pVM Pointer to the VM.
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);
1759f65b60e18f669f6d569aebd4fb7217ab414fvboxsync AssertReturn(!RT_SUCCESS_NP(rc), VERR_IPE_UNEXPECTED_INFO_STATUS);
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
4bfa7b58e362a1bca0628643c352c137900bf01avboxsync * @param pVM Pointer to the VM.
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * Initialize the trace buffer handles.
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * Check the config and enable tracing if requested.
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync PCFGMNODE pDbgfNode = CFGMR3GetChild(CFGMR3GetRoot(pVM), "DBGF");
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync int rc = CFGMR3QueryBoolDef(pDbgfNode, "TracingEnabled", &fTracingEnabled, fDefault);
da16291aeb2bc65f199d6e263b823746da1d19dfvboxsync rc = CFGMR3QueryStringAllocDef(pDbgfNode, "TracingConfig", &pszTracingConfig, pszConfigDefault);
da16291aeb2bc65f199d6e263b823746da1d19dfvboxsync rc = VMSetError(pVM, rc, RT_SRC_POS, "TracingConfig=\"%s\" -> %Rrc", pszTracingConfig, rc);
da16291aeb2bc65f199d6e263b823746da1d19dfvboxsync rc = VMSetError(pVM, rc, RT_SRC_POS, "TracingConfig=\"%s\" (default) -> %Rrc", pszConfigDefault, rc);
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.
4bfa7b58e362a1bca0628643c352c137900bf01avboxsync * @param pVM Pointer to the VM.
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync /* nothing to do */
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync * Relocates the trace buffer handle in RC.
4bfa7b58e362a1bca0628643c352c137900bf01avboxsync * @param pVM Pointer to the VM.
a1d83f29ade4c8f9fe95fc75d3fb2642f36081c1vboxsync pVM->hTraceBufRC = MMHyperCCToRC(pVM, pVM->hTraceBufR3);
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * Change the traceing configuration of the VM.
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * @returns VBox status code.
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * @retval VINF_SUCCESS
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * @retval VERR_NOT_FOUND if any of the trace point groups mentioned in the
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * config string cannot be found. (Or if the string cannot be made
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * sense of.) No change made.
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * @retval VERR_INVALID_VM_HANDLE
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * @retval VERR_INVALID_POINTER
4bfa7b58e362a1bca0628643c352c137900bf01avboxsync * @param pVM Pointer to the VM.
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * @param pszConfig The configuration change specification.
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * Trace point group names, optionally prefixed by a '-' to
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * indicate that the group is being disabled. A special
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * group 'all' can be used to enable or disable all trace
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * Drivers, devices and USB devices each have their own
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * trace point group which can be accessed by prefixing
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * their official PDM name by 'drv', 'dev' or 'usb'
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * respectively.
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsyncVMMDECL(int) DBGFR3TraceConfig(PVM pVM, const char *pszConfig)
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * We do this in two passes, the first pass just validates the input string
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * and the second applies the changes.
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * Operation prefix.
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * Extract the name.
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * 'all' - special group that enables or disables all trace points.
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync while (iCpu-- > 0)
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync while (iCpu-- > 0)
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * A specific group, try the VMM first then PDM.
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync while (i-- > 0)
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync && !strncmp(g_aVmmTpGroups[i].pszName, pszName, cchName))
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync while (iCpu-- > 0)
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync pVM->aCpus[iCpu].fTraceGroups |= g_aVmmTpGroups[i].fMask;
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync while (iCpu-- > 0)
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync pVM->aCpus[iCpu].fTraceGroups &= ~g_aVmmTpGroups[i].fMask;
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync int rc = PDMR3TracingConfig(pVM, pszName, cchName, !fNo, uPass > 0);
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * Query the trace configuration specification string.
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * @returns VBox status code.
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * @retval VINF_SUCCESS
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * @retval VERR_INVALID_VM_HANDLE
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * @retval VERR_INVALID_POINTER
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * @retval VERR_BUFFER_OVERFLOW if the buffer is too small. Buffer will be
4bfa7b58e362a1bca0628643c352c137900bf01avboxsync * @param pVM Pointer to the VM.
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * @param pszConfig Pointer to the output buffer.
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync * @param cbConfig The size of the output buffer.
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsyncVMMDECL(int) DBGFR3TraceQueryConfig(PVM pVM, char *pszConfig, size_t cbConfig)
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync uint32_t const fTraceGroups = pVM->aCpus[0].fTraceGroups;
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync else if ( fTraceGroups == 0
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync while (i-- > 0)
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync size_t cchThis = g_aVmmTpGroups[i].cchName + (pszDst != pszConfig);
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync memcpy(pszDst + 1, g_aVmmTpGroups[i].pszName, g_aVmmTpGroups[i].cchName + 1);
a8b31f6b3abd04475d4abcb5292aa22131b5130fvboxsync memcpy(pszDst, g_aVmmTpGroups[i].pszName, g_aVmmTpGroups[i].cchName + 1);
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));