VirtualBox

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

Last change on this file since 104976 was 104976, checked in by vboxsync, 3 months ago

Devices/Trace: Support streaming the tracelog over the network, bugref:10701

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.0 KB
Line 
1/* $Id: DrvIfsTrace.cpp 104976 2024-06-20 10:17:44Z 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 if (pThis->pITpmConBelow)
64 PDMIBASE_RETURN_INTERFACE(pszIID, PDMITPMCONNECTOR, &pThis->ITpmConnector);
65 if (pThis->pITpmPortAbove)
66 PDMIBASE_RETURN_INTERFACE(pszIID, PDMITPMPORT, &pThis->ITpmPort);
67
68 return NULL;
69}
70
71
72/*
73 *
74 * PDMDRVREG Methods
75 *
76 */
77
78/**
79 * Destroys a interface filter driver instance.
80 *
81 * @copydoc FNPDMDRVDESTRUCT
82 */
83static DECLCALLBACK(void) drvIfTrace_Destruct(PPDMDRVINS pDrvIns)
84{
85 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
86 PDRVIFTRACE pThis = PDMINS_2_DATA(pDrvIns, PDRVIFTRACE);
87 LogFlow(("%s: iInstance=%d\n", __FUNCTION__, pDrvIns->iInstance));
88
89 if (pThis->hTraceLog != NIL_RTTRACELOGWR)
90 {
91 RTTraceLogWrDestroy(pThis->hTraceLog);
92 pThis->hTraceLog = NIL_RTTRACELOGWR;
93 }
94}
95
96
97/**
98 * Construct a interface filter driver instance.
99 *
100 * @copydoc FNPDMDRVCONSTRUCT
101 */
102static DECLCALLBACK(int) drvIfTrace_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
103{
104 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
105 PDRVIFTRACE pThis = PDMINS_2_DATA(pDrvIns, PDRVIFTRACE);
106 PCPDMDRVHLPR3 pHlp = pDrvIns->pHlpR3;
107
108
109 /*
110 * Initialize the instance data.
111 */
112 pThis->pDrvIns = pDrvIns;
113 pThis->hTraceLog = NIL_RTTRACELOGWR;
114 pDrvIns->IBase.pfnQueryInterface = drvIfTraceIBase_QueryInterface;
115
116 drvIfsTrace_SerialIfInit(pThis);
117 drvIfsTrace_TpmIfInit(pThis);
118
119 /*
120 * Validate and read config.
121 */
122 PDMDRV_VALIDATE_CONFIG_RETURN(pDrvIns, "TraceFilePath|TraceLocation", "");
123
124 char *pszLocation = NULL;
125 int rc = pHlp->pfnCFGMQueryStringAlloc(pCfg, "TraceFilePath", &pszLocation);
126 if (RT_SUCCESS(rc))
127 {
128 /* Try to create a file based trace log. */
129 rc = RTTraceLogWrCreateFile(&pThis->hTraceLog, RTBldCfgVersion(), pszLocation);
130 PDMDrvHlpMMHeapFree(pDrvIns, pszLocation);
131
132 AssertLogRelRCReturn(rc, rc);
133 }
134 else if (rc == VERR_CFGM_VALUE_NOT_FOUND)
135 {
136 /* Try to connect to an external server. */
137 rc = pHlp->pfnCFGMQueryStringAlloc(pCfg, "TraceLocation", &pszLocation);
138 if (RT_FAILURE(rc))
139 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
140 N_("Configuration error: querying \"TraceLocation\" resulted in %Rrc"), rc);
141
142 char *pszPort = strchr(pszLocation, ':');
143 if (!pszPort)
144 return PDMDrvHlpVMSetError(pDrvIns, VERR_NOT_FOUND, RT_SRC_POS,
145 N_("IfTrace#%d: The location misses the port to connect to"),
146 pDrvIns->iInstance);
147
148 *pszPort = '\0'; /* Overwrite temporarily to avoid copying the hostname into a temporary buffer. */
149 uint32_t uPort = 0;
150 rc = RTStrToUInt32Ex(pszPort + 1, NULL, 10, &uPort);
151 if (RT_FAILURE(rc))
152 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
153 N_("IfTrace#%d: The port part of the location is not a numerical value"),
154 pDrvIns->iInstance);
155
156 rc = RTTraceLogWrCreateTcpClient(&pThis->hTraceLog, RTBldCfgVersion(), pszLocation, uPort);
157 *pszPort = ':'; /* Restore delimiter before checking the status. */
158 if (RT_FAILURE(rc))
159 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
160 N_("IfTrace#%d: Failed to connect to socket %s"),
161 pDrvIns->iInstance, pszLocation);
162
163 PDMDrvHlpMMHeapFree(pDrvIns, pszLocation);
164 }
165
166
167 /*
168 * Query interfaces from the driver/device above us.
169 */
170 pThis->pISerialPortAbove = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMISERIALPORT);
171 pThis->pITpmPortAbove = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMITPMPORT);
172
173 /*
174 * Attach driver below us.
175 */
176 PPDMIBASE pIBaseBelow;
177 rc = PDMDrvHlpAttach(pDrvIns, fFlags, &pIBaseBelow);
178 AssertLogRelRCReturn(rc, rc);
179
180 pThis->pISerialConBelow = PDMIBASE_QUERY_INTERFACE(pIBaseBelow, PDMISERIALCONNECTOR);
181 pThis->pITpmConBelow = PDMIBASE_QUERY_INTERFACE(pIBaseBelow, PDMITPMCONNECTOR);
182
183 return VINF_SUCCESS;
184}
185
186
187/**
188 * Storage filter driver registration record.
189 */
190const PDMDRVREG g_DrvIfTrace =
191{
192 /* u32Version */
193 PDM_DRVREG_VERSION,
194 /* szName */
195 "IfTrace",
196 /* szRCMod */
197 "",
198 /* szR0Mod */
199 "",
200 /* pszDescription */
201 "Interface callback tracing driver",
202 /* fFlags */
203 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
204 /* fClass. */
205 PDM_DRVREG_CLASS_STATUS,
206 /* cMaxInstances */
207 ~0U,
208 /* cbInstance */
209 sizeof(DRVIFTRACE),
210 /* pfnConstruct */
211 drvIfTrace_Construct,
212 /* pfnDestruct */
213 drvIfTrace_Destruct,
214 /* pfnRelocate */
215 NULL,
216 /* pfnIOCtl */
217 NULL,
218 /* pfnPowerOn */
219 NULL,
220 /* pfnReset */
221 NULL,
222 /* pfnSuspend */
223 NULL,
224 /* pfnResume */
225 NULL,
226 /* pfnAttach */
227 NULL,
228 /* pfnDetach */
229 NULL,
230 /* pfnPowerOff */
231 NULL,
232 /* pfnSoftReset */
233 NULL,
234 /* u32EndVersion */
235 PDM_DRVREG_VERSION
236};
237
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