VirtualBox

source: vbox/trunk/include/iprt/tracelog-decoder-plugin.h@ 104923

Last change on this file since 104923 was 104921, checked in by vboxsync, 7 months ago

Runtime/tools/RTTraceLogTool,Devices/VBoxTraceLogDecoders.cpp: Allow attaching a state for a decoder to enable analysis spanning multiple events, bugref:10701 [build fix]

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.0 KB
Line 
1/** @file
2 * IPRT: Tracelog decoder plugin API for RTTraceLogTool.
3 */
4
5/*
6 * Copyright (C) 2024 Oracle and/or its affiliates.
7 *
8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, in version 3 of the
14 * License.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses>.
23 *
24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
26 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27 * in the VirtualBox distribution, in which case the provisions of the
28 * CDDL are applicable instead of those of the GPL.
29 *
30 * You may elect to license modified versions of this file under the
31 * terms and conditions of either the GPL or the CDDL or both.
32 *
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
34 */
35
36#ifndef IPRT_INCLUDED_tracelog_decoder_plugin_h
37#define IPRT_INCLUDED_tracelog_decoder_plugin_h
38#ifndef RT_WITHOUT_PRAGMA_ONCE
39# pragma once
40#endif
41
42#include <iprt/cdefs.h>
43#include <iprt/tracelog.h>
44#include <iprt/types.h>
45
46
47/** Pointer to helper functions for decoders. */
48typedef struct RTTRACELOGDECODERHLP *PRTTRACELOGDECODERHLP;
49
50
51/**
52 * Decoder state free callback.
53 *
54 * @param pHlp Pointer to the callback structure.
55 * @param pvState Pointer to the decoder state.
56 */
57typedef DECLCALLBACKTYPE(void, FNTRACELOGDECODERSTATEFREE,(PRTTRACELOGDECODERHLP pHlp, void *pvState));
58/** Pointer to an event decode callback. */
59typedef FNTRACELOGDECODERSTATEFREE *PFNTRACELOGDECODERSTATEFREE;
60
61
62/**
63 * Helper functions for decoders.
64 */
65typedef struct RTTRACELOGDECODERHLP
66{
67 /** Magic value (RTTRACELOGDECODERHLP_MAGIC). */
68 uint32_t u32Magic;
69
70 /**
71 * Helper for writing formatted text to the output.
72 *
73 * @returns IPRT status.
74 * @param pHlp Pointer to the callback structure.
75 * @param pszFormat The format string. This may use all IPRT extensions as
76 * well as the debugger ones.
77 * @param ... Arguments specified in the format string.
78 */
79 DECLCALLBACKMEMBER(int, pfnPrintf, (PRTTRACELOGDECODERHLP pHlp, const char *pszFormat, ...)) RT_IPRT_FORMAT_ATTR(2, 3);
80
81
82 /**
83 * Helper for writing formatted error message to the output.
84 *
85 * @returns IPRT status.
86 * @param pHlp Pointer to the callback structure.
87 * @param pszFormat The format string. This may use all IPRT extensions as
88 * well as the debugger ones.
89 * @param ... Arguments specified in the format string.
90 */
91 DECLCALLBACKMEMBER(int, pfnErrorMsg, (PRTTRACELOGDECODERHLP pHlp, const char *pszFormat, ...)) RT_IPRT_FORMAT_ATTR(2, 3);
92
93
94 /**
95 * Creates a new decoder state and associates it with the given helper structure.
96 *
97 * @returns IPRT status.
98 * @param pHlp Pointer to the callback structure.
99 * @param cbState Size of the state in bytes.
100 * @param pfnFree Callback which is called before the decoder state is freed to give the decoder
101 * a chance to do some necessary cleanup, optional.
102 * @param ppvState Where to return the pointer to the state on success.
103 *
104 * @note This will destroy and free any previously created decoder state as there can be only one currently for
105 * a decoder.
106 */
107 DECLCALLBACKMEMBER(int, pfnDecoderStateCreate, (PRTTRACELOGDECODERHLP pHlp, size_t cbState, PFNTRACELOGDECODERSTATEFREE pfnFree,
108 void **ppvState));
109
110
111 /**
112 * Destroys any currently attached decoder state.
113 *
114 * @param pHlp Pointer to the callback structure.
115 */
116 DECLCALLBACKMEMBER(void, pfnDecoderStateDestroy, (PRTTRACELOGDECODERHLP pHlp));
117
118
119 /**
120 * Returns any decoder state created previously with RTTRACELOGDECODERHLP::pfnDecoderStateCreate().
121 *
122 * @returns Pointer to the decoder state or NULL if none was created yet.
123 * @param pHlp Pointer to the callback structure.
124 */
125 DECLCALLBACKMEMBER(void*, pfnDecoderStateGet, (PRTTRACELOGDECODERHLP pHlp));
126
127
128 /** End marker (DBGCCMDHLP_MAGIC). */
129 uint32_t u32EndMarker;
130} RTTRACELOGDECODERHLP;
131
132/** Magic value for RTTRACELOGDECODERHLP::u32Magic and RTTRACELOGDECODERHLP::u32EndMarker. (Bernhard-Viktor Christoph-Carl von Buelow) */
133#define DBGCCMDHLP_MAGIC UINT32_C(0x19231112)
134
135
136/** Makes a IPRT tracelog decoder structure version out of an unique magic value and major &
137 * minor version numbers.
138 *
139 * @returns 32-bit structure version number.
140 *
141 * @param uMagic 16-bit magic value. This must be unique.
142 * @param uMajor 12-bit major version number. Structures with different
143 * major numbers are not compatible.
144 * @param uMinor 4-bit minor version number. When only the minor version
145 * differs, the structures will be 100% backwards
146 * compatible.
147 */
148#define RT_TRACELOG_DECODER_VERSION_MAKE(uMagic, uMajor, uMinor) \
149 ( ((uint32_t)(uMagic) << 16) | ((uint32_t)((uMajor) & 0xff) << 4) | ((uint32_t)((uMinor) & 0xf) << 0) )
150
151/** Checks if @a uVerMagic1 is compatible with @a uVerMagic2.
152 *
153 * @returns true / false.
154 * @param uVerMagic1 Typically the runtime version of the struct. This must
155 * have the same magic and major version as @a uVerMagic2
156 * and the minor version must be greater or equal to that
157 * of @a uVerMagic2.
158 * @param uVerMagic2 Typically the version the code was compiled against.
159 *
160 * @remarks The parameters will be referenced more than once.
161 */
162#define RT_TRACELOG_DECODER_VERSION_ARE_COMPATIBLE(uVerMagic1, uVerMagic2) \
163 ( (uVerMagic1) == (uVerMagic2) \
164 || ( (uVerMagic1) >= (uVerMagic2) \
165 && ((uVerMagic1) & UINT32_C(0xfffffff0)) == ((uVerMagic2) & UINT32_C(0xfffffff0)) ) \
166 )
167
168
169/**
170 * Decoder callback for an event.
171 *
172 * @returns IPRT status code.
173 * @param pHlp The decoder helper callback table.
174 * @param idDecodeEvt Event decoder ID given in RTTRACELOGDECODEEVT::idDecodeEvt for the particular event ID.
175 * @param hTraceLogEvt The tracelog event handle called for decoding.
176 * @param pEvtDesc The event descriptor.
177 * @param paVals Pointer to the array of values.
178 * @param cVals Number of values in the array.
179 */
180typedef DECLCALLBACKTYPE(int, FNTRACELOGDECODEREVENTDECODE,(PRTTRACELOGDECODERHLP pHlp, uint32_t idDecodeEvt,
181 RTTRACELOGRDREVT hTraceLogEvt, PCRTTRACELOGEVTDESC pEvtDesc,
182 PRTTRACELOGEVTVAL paVals, uint32_t cVals));
183/** Pointer to an event decode callback. */
184typedef FNTRACELOGDECODEREVENTDECODE *PFNTRACELOGDECODEREVENTDECODE;
185
186
187/**
188 * Event decoder entry.
189 */
190typedef struct RTTRACELOGDECODEEVT
191{
192 /** The event ID name. */
193 const char *pszEvtId;
194 /** The decoder event ID ordinal to pass to in the decode callback for
195 * faster lookup. */
196 uint32_t idDecodeEvt;
197} RTTRACELOGDECODEEVT;
198/** Pointer to an event decoder entry. */
199typedef RTTRACELOGDECODEEVT *PRTTRACELOGDECODEEVT;
200/** Pointer to a const event decoder entry. */
201typedef const RTTRACELOGDECODEEVT *PCRTTRACELOGDECODEEVT;
202
203
204/**
205 * A decoder registration structure.
206 */
207typedef struct RTTRACELOGDECODERREG
208{
209 /** Decoder name. */
210 const char *pszName;
211 /** Decoder description. */
212 const char *pszDesc;
213 /** The event IDs to register the decoder for. */
214 PCRTTRACELOGDECODEEVT paEvtIds;
215 /** The decode callback. */
216 PFNTRACELOGDECODEREVENTDECODE pfnDecode;
217} RTTRACELOGDECODERREG;
218/** Pointer to a decoder registration structure. */
219typedef RTTRACELOGDECODERREG *PRTTRACELOGDECODERREG;
220/** Pointer to a const decoder registration structure. */
221typedef const RTTRACELOGDECODERREG *PCRTTRACELOGDECODERREG;
222
223
224/**
225 * Decoder register callbacks structure.
226 */
227typedef struct RTTRACELOGDECODERREGISTER
228{
229 /** Interface version.
230 * This is set to RT_TRACELOG_DECODERREG_CB_VERSION. */
231 uint32_t u32Version;
232
233 /**
234 * Registers a new decoders.
235 *
236 * @returns VBox status code.
237 * @param pvUser Opaque user data given in the plugin load callback.
238 * @param paDecoders Pointer to an array of decoders to register.
239 * @param cDecoders Number of entries in the array.
240 */
241 DECLR3CALLBACKMEMBER(int, pfnRegisterDecoders, (void *pvUser, PCRTTRACELOGDECODERREG paDecoders, uint32_t cDecoders));
242
243} RTTRACELOGDECODERREGISTER;
244/** Pointer to a backend register callbacks structure. */
245typedef RTTRACELOGDECODERREGISTER *PRTTRACELOGDECODERREGISTER;
246
247/** Current version of the RTTRACELOGDECODERREGISTER structure. */
248#define RT_TRACELOG_DECODERREG_CB_VERSION RT_TRACELOG_DECODER_VERSION_MAKE(0xfeed, 1, 0)
249
250/**
251 * Initialization entry point called by the tracelog layer when
252 * a plugin is loaded.
253 *
254 * @returns IPRT status code.
255 * @param pvUser Opaque user data passed in the register callbacks.
256 * @param pRegisterCallbacks Pointer to the register callbacks structure.
257 */
258typedef DECLCALLBACKTYPE(int, FNTRACELOGDECODERPLUGINLOAD,(void *pvUser, PRTTRACELOGDECODERREGISTER pRegisterCallbacks));
259typedef FNTRACELOGDECODERPLUGINLOAD *PFNTRACELOGDECODERPLUGINLOAD;
260#define RT_TRACELOG_DECODER_PLUGIN_LOAD "RTTraceLogDecoderLoad"
261
262#endif /* !IPRT_INCLUDED_tracelog_decoder_plugin_h */
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