VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/DBGFR3Trace.cpp@ 39944

Last change on this file since 39944 was 39405, checked in by vboxsync, 13 years ago

VMM: Don't use generic IPE status codes, use specific ones. Part 2.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.7 KB
Line 
1/* $Id: DBGFR3Trace.cpp 39405 2011-11-23 19:30:29Z vboxsync $ */
2/** @file
3 * DBGF - Debugger Facility, Tracing.
4 */
5
6/*
7 * Copyright (C) 2011 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_DBGF
23#include <VBox/vmm/dbgftrace.h>
24#include <VBox/vmm/cfgm.h>
25#include <VBox/vmm/mm.h>
26#include "DBGFInternal.h"
27#include <VBox/vmm/vm.h>
28
29#include <VBox/err.h>
30#include <VBox/log.h>
31#include <VBox/param.h>
32
33#include <iprt/assert.h>
34#include <iprt/trace.h>
35
36
37/*******************************************************************************
38* Internal Functions *
39*******************************************************************************/
40static DECLCALLBACK(void) dbgfR3TraceInfo(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
41
42
43/**
44 * Initializes the tracing.
45 *
46 * @returns VBox status code
47 * @param pVM The VM handle.
48 */
49static int dbgfR3TraceEnable(PVM pVM, uint32_t cbEntry, uint32_t cEntries)
50{
51 /*
52 * Don't enable it twice.
53 */
54 if (pVM->hTraceBufR3 != NIL_RTTRACEBUF)
55 return VERR_ALREADY_EXISTS;
56
57 /*
58 * Resolve default parameter values.
59 */
60 int rc;
61 if (!cbEntry)
62 {
63 rc = CFGMR3QueryU32Def(CFGMR3GetChild(CFGMR3GetRoot(pVM), "DBGF"), "TraceBufEntrySize", &cbEntry, 128);
64 AssertRCReturn(rc, rc);
65 }
66 if (!cEntries)
67 {
68 rc = CFGMR3QueryU32Def(CFGMR3GetChild(CFGMR3GetRoot(pVM), "DBGF"), "TraceBufEntries", &cEntries, 4096);
69 AssertRCReturn(rc, rc);
70 }
71
72 /*
73 * Figure the required size.
74 */
75 RTTRACEBUF hTraceBuf;
76 size_t cbBlock = 0;
77 rc = RTTraceBufCarve(&hTraceBuf, cEntries, cbEntry, 0 /*fFlags*/, NULL, &cbBlock);
78 if (rc != VERR_BUFFER_OVERFLOW)
79 {
80 AssertReturn(!RT_SUCCESS_NP(rc), VERR_IPE_UNEXPECTED_INFO_STATUS);
81 return rc;
82 }
83
84 /*
85 * Allocate a hyper heap block and carve a trace buffer out of it.
86 *
87 * Note! We ASSUME that the returned trace buffer handle has the same value
88 * as the heap block.
89 */
90 cbBlock = RT_ALIGN_Z(cbBlock, PAGE_SIZE);
91 void *pvBlock;
92 rc = MMR3HyperAllocOnceNoRel(pVM, cbBlock, PAGE_SIZE, MM_TAG_DBGF, &pvBlock);
93 if (RT_FAILURE(rc))
94 return rc;
95
96 rc = RTTraceBufCarve(&hTraceBuf, cEntries, cbEntry, 0 /*fFlags*/, pvBlock, &cbBlock);
97 AssertRCReturn(rc, rc);
98 AssertRelease(hTraceBuf == (RTTRACEBUF)pvBlock && (void *)hTraceBuf == pvBlock);
99
100 pVM->hTraceBufR3 = hTraceBuf;
101 pVM->hTraceBufR0 = MMHyperCCToR0(pVM, hTraceBuf);
102 pVM->hTraceBufRC = MMHyperCCToRC(pVM, hTraceBuf);
103 return VINF_SUCCESS;
104}
105
106
107/**
108 * Initializes the tracing.
109 *
110 * @returns VBox status code
111 * @param pVM The VM handle.
112 */
113int dbgfR3TraceInit(PVM pVM)
114{
115 /*
116 * Initialize the trace buffer handles.
117 */
118 Assert(NIL_RTTRACEBUF == (RTTRACEBUF)NULL);
119 pVM->hTraceBufR3 = NIL_RTTRACEBUF;
120 pVM->hTraceBufRC = NIL_RTRCPTR;
121 pVM->hTraceBufR0 = NIL_RTR0PTR;
122
123 /*
124 * Check the config and enable tracing if requested.
125 */
126#if defined(DEBUG) || defined(RTTRACE_ENABLED)
127 bool const fDefault = true;
128#else
129 bool const fDefault = false;
130#endif
131 bool fTracingEnabled;
132 int rc = CFGMR3QueryBoolDef(CFGMR3GetChild(CFGMR3GetRoot(pVM), "DBGF"), "TracingEnabled",
133 &fTracingEnabled, fDefault);
134 AssertRCReturn(rc, rc);
135 if (fTracingEnabled)
136 rc = dbgfR3TraceEnable(pVM, 0, 0);
137
138 /*
139 * Register a debug info item that will dump the trace buffer content.
140 */
141 if (RT_SUCCESS(rc))
142 rc = DBGFR3InfoRegisterInternal(pVM, "tracebuf", "Display the trace buffer content. No arguments.", dbgfR3TraceInfo);
143
144 return rc;
145}
146
147
148/**
149 * Terminates the tracing.
150 *
151 * @param pVM The VM handle.
152 */
153void dbgfR3TraceTerm(PVM pVM)
154{
155 /* nothing to do */
156 NOREF(pVM);
157}
158
159
160/**
161 * Relocates the trace buffer handle in RC.
162 *
163 * @param pVM The VM handle.
164 */
165void dbgfR3TraceRelocate(PVM pVM)
166{
167 if (pVM->hTraceBufR3 != NIL_RTTRACEBUF)
168 pVM->hTraceBufRC = MMHyperCCToRC(pVM, pVM->hTraceBufR3);
169}
170
171
172/**
173 * @callback_method_impl{FNRTTRACEBUFCALLBACK}
174 */
175static DECLCALLBACK(int)
176dbgfR3TraceInfoDumpEntry(RTTRACEBUF hTraceBuf, uint32_t iEntry, uint64_t NanoTS, RTCPUID idCpu, const char *pszMsg, void *pvUser)
177{
178 PCDBGFINFOHLP pHlp = (PCDBGFINFOHLP)pvUser;
179 pHlp->pfnPrintf(pHlp, "#%04u/%'llu/%02x: %s\n", iEntry, NanoTS, idCpu, pszMsg);
180 NOREF(hTraceBuf);
181 return VINF_SUCCESS;
182}
183
184
185/**
186 * @callback_method_impl{FNDBGFHANDLERINT, Info handler for displaying the trace buffer content.}
187 */
188static DECLCALLBACK(void) dbgfR3TraceInfo(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
189{
190 RTTRACEBUF hTraceBuf = pVM->hTraceBufR3;
191 if (hTraceBuf == NIL_RTTRACEBUF)
192 pHlp->pfnPrintf(pHlp, "Tracing is disable\n");
193 else
194 {
195 pHlp->pfnPrintf(pHlp, "Trace buffer %p - %u entries of %u bytes\n",
196 hTraceBuf, RTTraceBufGetEntryCount(hTraceBuf), RTTraceBufGetEntrySize(hTraceBuf));
197 RTTraceBufEnumEntries(hTraceBuf, dbgfR3TraceInfoDumpEntry, (void *)pHlp);
198 }
199 NOREF(pszArgs);
200}
201
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