VirtualBox

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

Last change on this file since 101539 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.1 KB
Line 
1/* $Id: DrvIfsTrace.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBox interface callback tracing driver.
4 */
5
6/*
7 * Copyright (C) 2020-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#define LOG_GROUP LOG_GROUP_MISC
33#include <VBox/log.h>
34#include <VBox/version.h>
35
36#include <iprt/errcore.h>
37#include <iprt/buildconfig.h>
38#include <iprt/tracelog.h>
39#include <iprt/uuid.h>
40
41#include "VBoxDD.h"
42#include "DrvIfsTraceInternal.h"
43
44
45/*
46 *
47 * IBase Implementation.
48 *
49 */
50
51
52static DECLCALLBACK(void *) drvIfTraceIBase_QueryInterface(PPDMIBASE pInterface, const char *pszIID)
53{
54 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
55 PDRVIFTRACE pThis = PDMINS_2_DATA(pDrvIns, PDRVIFTRACE);
56
57 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
58 if (pThis->pISerialConBelow)
59 PDMIBASE_RETURN_INTERFACE(pszIID, PDMISERIALCONNECTOR, &pThis->ISerialConnector);
60 if (pThis->pISerialPortAbove)
61 PDMIBASE_RETURN_INTERFACE(pszIID, PDMISERIALPORT, &pThis->ISerialPort);
62
63 return NULL;
64}
65
66
67/*
68 *
69 * PDMDRVREG Methods
70 *
71 */
72
73/**
74 * Destroys a interface filter driver instance.
75 *
76 * @copydoc FNPDMDRVDESTRUCT
77 */
78static DECLCALLBACK(void) drvIfTrace_Destruct(PPDMDRVINS pDrvIns)
79{
80 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
81 PDRVIFTRACE pThis = PDMINS_2_DATA(pDrvIns, PDRVIFTRACE);
82 LogFlow(("%s: iInstance=%d\n", __FUNCTION__, pDrvIns->iInstance));
83
84 if (pThis->hTraceLog != NIL_RTTRACELOGWR)
85 {
86 RTTraceLogWrDestroy(pThis->hTraceLog);
87 pThis->hTraceLog = NIL_RTTRACELOGWR;
88 }
89
90 if (pThis->pszTraceFilePath)
91 {
92 PDMDrvHlpMMHeapFree(pDrvIns, pThis->pszTraceFilePath);
93 pThis->pszTraceFilePath = NULL;
94 }
95}
96
97
98/**
99 * Construct a interface filter driver instance.
100 *
101 * @copydoc FNPDMDRVCONSTRUCT
102 */
103static DECLCALLBACK(int) drvIfTrace_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
104{
105 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
106 PDRVIFTRACE pThis = PDMINS_2_DATA(pDrvIns, PDRVIFTRACE);
107 PCPDMDRVHLPR3 pHlp = pDrvIns->pHlpR3;
108
109
110 /*
111 * Initialize the instance data.
112 */
113 pThis->pDrvIns = pDrvIns;
114 pThis->hTraceLog = NIL_RTTRACELOGWR;
115 pDrvIns->IBase.pfnQueryInterface = drvIfTraceIBase_QueryInterface;
116
117 drvIfsTrace_SerialIfInit(pThis);
118
119 /*
120 * Validate and read config.
121 */
122 PDMDRV_VALIDATE_CONFIG_RETURN(pDrvIns, "TraceFilePath|", "");
123
124 int rc = pHlp->pfnCFGMQueryStringAlloc(pCfg, "TraceFilePath", &pThis->pszTraceFilePath);
125 AssertLogRelRCReturn(rc, rc);
126
127 /* Try to create a file based trace log. */
128 rc = RTTraceLogWrCreateFile(&pThis->hTraceLog, RTBldCfgVersion(), pThis->pszTraceFilePath);
129 AssertLogRelRCReturn(rc, rc);
130
131 /*
132 * Query interfaces from the driver/device above us.
133 */
134 pThis->pISerialPortAbove = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMISERIALPORT);
135
136 /*
137 * Attach driver below us.
138 */
139 PPDMIBASE pIBaseBelow;
140 rc = PDMDrvHlpAttach(pDrvIns, fFlags, &pIBaseBelow);
141 AssertLogRelRCReturn(rc, rc);
142
143 pThis->pISerialConBelow = PDMIBASE_QUERY_INTERFACE(pIBaseBelow, PDMISERIALCONNECTOR);
144
145 return VINF_SUCCESS;
146}
147
148
149/**
150 * Storage filter driver registration record.
151 */
152const PDMDRVREG g_DrvIfTrace =
153{
154 /* u32Version */
155 PDM_DRVREG_VERSION,
156 /* szName */
157 "IfTrace",
158 /* szRCMod */
159 "",
160 /* szR0Mod */
161 "",
162 /* pszDescription */
163 "Interface callback tracing driver",
164 /* fFlags */
165 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
166 /* fClass. */
167 PDM_DRVREG_CLASS_STATUS,
168 /* cMaxInstances */
169 ~0U,
170 /* cbInstance */
171 sizeof(DRVIFTRACE),
172 /* pfnConstruct */
173 drvIfTrace_Construct,
174 /* pfnDestruct */
175 drvIfTrace_Destruct,
176 /* pfnRelocate */
177 NULL,
178 /* pfnIOCtl */
179 NULL,
180 /* pfnPowerOn */
181 NULL,
182 /* pfnReset */
183 NULL,
184 /* pfnSuspend */
185 NULL,
186 /* pfnResume */
187 NULL,
188 /* pfnAttach */
189 NULL,
190 /* pfnDetach */
191 NULL,
192 /* pfnPowerOff */
193 NULL,
194 /* pfnSoftReset */
195 NULL,
196 /* u32EndVersion */
197 PDM_DRVREG_VERSION
198};
199
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