1 | /* $Id: DrvIfsTrace.cpp 93115 2022-01-01 11:31:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox interface callback tracing driver.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2020-2022 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 |
|
---|
42 | static 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 | */
|
---|
68 | static 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 | PDMDrvHlpMMHeapFree(pDrvIns, pThis->pszTraceFilePath);
|
---|
83 | pThis->pszTraceFilePath = NULL;
|
---|
84 | }
|
---|
85 | }
|
---|
86 |
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * Construct a interface filter driver instance.
|
---|
90 | *
|
---|
91 | * @copydoc FNPDMDRVCONSTRUCT
|
---|
92 | */
|
---|
93 | static DECLCALLBACK(int) drvIfTrace_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
|
---|
94 | {
|
---|
95 | PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
|
---|
96 | PDRVIFTRACE pThis = PDMINS_2_DATA(pDrvIns, PDRVIFTRACE);
|
---|
97 | PCPDMDRVHLPR3 pHlp = pDrvIns->pHlpR3;
|
---|
98 |
|
---|
99 |
|
---|
100 | /*
|
---|
101 | * Initialize the instance data.
|
---|
102 | */
|
---|
103 | pThis->pDrvIns = pDrvIns;
|
---|
104 | pThis->hTraceLog = NIL_RTTRACELOGWR;
|
---|
105 | pDrvIns->IBase.pfnQueryInterface = drvIfTraceIBase_QueryInterface;
|
---|
106 |
|
---|
107 | drvIfsTrace_SerialIfInit(pThis);
|
---|
108 |
|
---|
109 | /*
|
---|
110 | * Validate and read config.
|
---|
111 | */
|
---|
112 | PDMDRV_VALIDATE_CONFIG_RETURN(pDrvIns, "TraceFilePath|", "");
|
---|
113 |
|
---|
114 | int rc = pHlp->pfnCFGMQueryStringAlloc(pCfg, "TraceFilePath", &pThis->pszTraceFilePath);
|
---|
115 | AssertLogRelRCReturn(rc, rc);
|
---|
116 |
|
---|
117 | /* Try to create a file based trace log. */
|
---|
118 | rc = RTTraceLogWrCreateFile(&pThis->hTraceLog, RTBldCfgVersion(), pThis->pszTraceFilePath);
|
---|
119 | AssertLogRelRCReturn(rc, rc);
|
---|
120 |
|
---|
121 | /*
|
---|
122 | * Query interfaces from the driver/device above us.
|
---|
123 | */
|
---|
124 | pThis->pISerialPortAbove = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMISERIALPORT);
|
---|
125 |
|
---|
126 | /*
|
---|
127 | * Attach driver below us.
|
---|
128 | */
|
---|
129 | PPDMIBASE pIBaseBelow;
|
---|
130 | rc = PDMDrvHlpAttach(pDrvIns, fFlags, &pIBaseBelow);
|
---|
131 | AssertLogRelRCReturn(rc, rc);
|
---|
132 |
|
---|
133 | pThis->pISerialConBelow = PDMIBASE_QUERY_INTERFACE(pIBaseBelow, PDMISERIALCONNECTOR);
|
---|
134 |
|
---|
135 | return VINF_SUCCESS;
|
---|
136 | }
|
---|
137 |
|
---|
138 |
|
---|
139 | /**
|
---|
140 | * Storage filter driver registration record.
|
---|
141 | */
|
---|
142 | const PDMDRVREG g_DrvIfTrace =
|
---|
143 | {
|
---|
144 | /* u32Version */
|
---|
145 | PDM_DRVREG_VERSION,
|
---|
146 | /* szName */
|
---|
147 | "IfTrace",
|
---|
148 | /* szRCMod */
|
---|
149 | "",
|
---|
150 | /* szR0Mod */
|
---|
151 | "",
|
---|
152 | /* pszDescription */
|
---|
153 | "Interface callback tracing driver",
|
---|
154 | /* fFlags */
|
---|
155 | PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
|
---|
156 | /* fClass. */
|
---|
157 | PDM_DRVREG_CLASS_STATUS,
|
---|
158 | /* cMaxInstances */
|
---|
159 | ~0U,
|
---|
160 | /* cbInstance */
|
---|
161 | sizeof(DRVIFTRACE),
|
---|
162 | /* pfnConstruct */
|
---|
163 | drvIfTrace_Construct,
|
---|
164 | /* pfnDestruct */
|
---|
165 | drvIfTrace_Destruct,
|
---|
166 | /* pfnRelocate */
|
---|
167 | NULL,
|
---|
168 | /* pfnIOCtl */
|
---|
169 | NULL,
|
---|
170 | /* pfnPowerOn */
|
---|
171 | NULL,
|
---|
172 | /* pfnReset */
|
---|
173 | NULL,
|
---|
174 | /* pfnSuspend */
|
---|
175 | NULL,
|
---|
176 | /* pfnResume */
|
---|
177 | NULL,
|
---|
178 | /* pfnAttach */
|
---|
179 | NULL,
|
---|
180 | /* pfnDetach */
|
---|
181 | NULL,
|
---|
182 | /* pfnPowerOff */
|
---|
183 | NULL,
|
---|
184 | /* pfnSoftReset */
|
---|
185 | NULL,
|
---|
186 | /* u32EndVersion */
|
---|
187 | PDM_DRVREG_VERSION
|
---|
188 | };
|
---|
189 |
|
---|