VirtualBox

source: vbox/trunk/src/VBox/Devices/Trace/DrvIfsTrace.cpp@ 88621

Last change on this file since 88621 was 82789, checked in by vboxsync, 5 years ago

Devices/Trace: Tracing driver to log execution of interface callbacks between devices and drivers (for debugging user reported issues), see README on how to use

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1/* $Id: DrvIfsTrace.cpp 82789 2020-01-19 12:19:24Z vboxsync $ */
2/** @file
3 * VBox interface callback tracing driver.
4 */
5
6/*
7 * Copyright (C) 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_MISC
23#include <VBox/log.h>
24#include <VBox/version.h>
25
26#include <iprt/errcore.h>
27#include <iprt/buildconfig.h>
28#include <iprt/tracelog.h>
29#include <iprt/uuid.h>
30
31#include "VBoxDD.h"
32#include "DrvIfsTraceInternal.h"
33
34
35/*
36 *
37 * IBase Implementation.
38 *
39 */
40
41
42static DECLCALLBACK(void *) drvIfTraceIBase_QueryInterface(PPDMIBASE pInterface, const char *pszIID)
43{
44 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
45 PDRVIFTRACE pThis = PDMINS_2_DATA(pDrvIns, PDRVIFTRACE);
46
47 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
48 if (pThis->pISerialConBelow)
49 PDMIBASE_RETURN_INTERFACE(pszIID, PDMISERIALCONNECTOR, &pThis->ISerialConnector);
50 if (pThis->pISerialPortAbove)
51 PDMIBASE_RETURN_INTERFACE(pszIID, PDMISERIALPORT, &pThis->ISerialPort);
52
53 return NULL;
54}
55
56
57/*
58 *
59 * PDMDRVREG Methods
60 *
61 */
62
63/**
64 * Destroys a interface filter driver instance.
65 *
66 * @copydoc FNPDMDRVDESTRUCT
67 */
68static DECLCALLBACK(void) drvIfTrace_Destruct(PPDMDRVINS pDrvIns)
69{
70 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
71 PDRVIFTRACE pThis = PDMINS_2_DATA(pDrvIns, PDRVIFTRACE);
72 LogFlow(("%s: iInstance=%d\n", __FUNCTION__, pDrvIns->iInstance));
73
74 if (pThis->hTraceLog != NIL_RTTRACELOGWR)
75 {
76 RTTraceLogWrDestroy(pThis->hTraceLog);
77 pThis->hTraceLog = NIL_RTTRACELOGWR;
78 }
79
80 if (pThis->pszTraceFilePath)
81 {
82 MMR3HeapFree(pThis->pszTraceFilePath);
83 pThis->pszTraceFilePath = NULL;
84 }
85}
86
87
88/**
89 * Construct a interface filter driver instance.
90 *
91 * @copydoc FNPDMDRVCONSTRUCT
92 */
93static DECLCALLBACK(int) drvIfTrace_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
94{
95 PDRVIFTRACE pThis = PDMINS_2_DATA(pDrvIns, PDRVIFTRACE);
96
97 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
98
99 /*
100 * Initialize the instance data.
101 */
102 pThis->pDrvIns = pDrvIns;
103 pThis->hTraceLog = NIL_RTTRACELOGWR;
104 pDrvIns->IBase.pfnQueryInterface = drvIfTraceIBase_QueryInterface;
105
106 drvIfsTrace_SerialIfInit(pThis);
107
108 /*
109 * Validate and read config.
110 */
111 PDMDRV_VALIDATE_CONFIG_RETURN(pDrvIns, "TraceFilePath|", "");
112
113 int rc = CFGMR3QueryStringAlloc(pCfg, "TraceFilePath", &pThis->pszTraceFilePath);
114 AssertLogRelRCReturn(rc, rc);
115
116 /* Try to create a file based trace log. */
117 rc = RTTraceLogWrCreateFile(&pThis->hTraceLog, RTBldCfgVersion(), pThis->pszTraceFilePath);
118 AssertLogRelRCReturn(rc, rc);
119
120 /*
121 * Query interfaces from the driver/device above us.
122 */
123 pThis->pISerialPortAbove = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMISERIALPORT);
124
125 /*
126 * Attach driver below us.
127 */
128 PPDMIBASE pIBaseBelow;
129 rc = PDMDrvHlpAttach(pDrvIns, fFlags, &pIBaseBelow);
130 AssertLogRelRCReturn(rc, rc);
131
132 pThis->pISerialConBelow = PDMIBASE_QUERY_INTERFACE(pIBaseBelow, PDMISERIALCONNECTOR);
133
134 return VINF_SUCCESS;
135}
136
137
138/**
139 * Storage filter driver registration record.
140 */
141const PDMDRVREG g_DrvIfTrace =
142{
143 /* u32Version */
144 PDM_DRVREG_VERSION,
145 /* szName */
146 "IfTrace",
147 /* szRCMod */
148 "",
149 /* szR0Mod */
150 "",
151 /* pszDescription */
152 "Interface callback tracing driver",
153 /* fFlags */
154 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
155 /* fClass. */
156 PDM_DRVREG_CLASS_STATUS,
157 /* cMaxInstances */
158 ~0U,
159 /* cbInstance */
160 sizeof(DRVIFTRACE),
161 /* pfnConstruct */
162 drvIfTrace_Construct,
163 /* pfnDestruct */
164 drvIfTrace_Destruct,
165 /* pfnRelocate */
166 NULL,
167 /* pfnIOCtl */
168 NULL,
169 /* pfnPowerOn */
170 NULL,
171 /* pfnReset */
172 NULL,
173 /* pfnSuspend */
174 NULL,
175 /* pfnResume */
176 NULL,
177 /* pfnAttach */
178 NULL,
179 /* pfnDetach */
180 NULL,
181 /* pfnPowerOff */
182 NULL,
183 /* pfnSoftReset */
184 NULL,
185 /* u32EndVersion */
186 PDM_DRVREG_VERSION
187};
188
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