VirtualBox

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

最後變更 在這個檔案從104966是 104966,由 vboxsync 提交於 9 月 前

Runtime/tools/RTTraceLogTool,Devices/Trace: Decouple decoding from outputting by introducing a structure building interface, this simplifies the decoding plugin and allows outputting to different formats (later), bugref:10701

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 19.2 KB
 
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.alldomusa.eu.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/** The integer value should be dumped as a hex number instead. */
63#define RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_HEX RT_BIT_32(0)
64/** The hexdump should be dumped as an inline string (Rhxs). */
65#define RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_HEX_DUMP_STR RT_BIT_32(1)
66
67
68/**
69 * An enum entry for the struct builder.
70 */
71typedef struct RTTRACELOGDECODERSTRUCTBLDENUM
72{
73 /** The raw enum value. */
74 uint64_t u64EnumVal;
75 /** String version of the enum value. */
76 const char *pszString;
77 /** Some opaque user data not used by RTTRACELOGDECODERHLP::pfnStructBldAddEnum. */
78 uintptr_t uPtrUser;
79} RTTRACELOGDECODERSTRUCTBLDENUM;
80/** Pointer to a struct build enum entry. */
81typedef RTTRACELOGDECODERSTRUCTBLDENUM *PRTTRACELOGDECODERSTRUCTBLDENUM;
82/** Pointer to a const struct build enum entry. */
83typedef const RTTRACELOGDECODERSTRUCTBLDENUM *PCRTTRACELOGDECODERSTRUCTBLDENUM;
84
85
86/** Initializes a enum entry, extended version. */
87#define RT_TRACELOG_DECODER_STRUCT_BLD_ENUM_INIT_EX(a_enmVal, a_uPtrUser) \
88 { a_enmVal, #a_enmVal, a_uPtrUser }
89/** Initializes a enum entry, extended version. */
90#define RT_TRACELOG_DECODER_STRUCT_BLD_ENUM_INIT(a_enmVal) \
91 RT_TRACELOG_DECODER_STRUCT_BLD_ENUM_INIT_EX(a_enmVal, 0)
92
93
94/**
95 * Helper functions for decoders.
96 */
97typedef struct RTTRACELOGDECODERHLP
98{
99 /** Magic value (RTTRACELOGDECODERHLP_MAGIC). */
100 uint32_t u32Magic;
101
102 /**
103 * Helper for writing formatted text to the output.
104 *
105 * @returns IPRT status.
106 * @param pHlp Pointer to the callback structure.
107 * @param pszFormat The format string. This may use all IPRT extensions as
108 * well as the debugger ones.
109 * @param ... Arguments specified in the format string.
110 */
111 DECLCALLBACKMEMBER(int, pfnPrintf, (PRTTRACELOGDECODERHLP pHlp, const char *pszFormat, ...)) RT_IPRT_FORMAT_ATTR(2, 3);
112
113
114 /**
115 * Helper for writing formatted error message to the output.
116 *
117 * @returns IPRT status.
118 * @param pHlp Pointer to the callback structure.
119 * @param pszFormat The format string. This may use all IPRT extensions as
120 * well as the debugger ones.
121 * @param ... Arguments specified in the format string.
122 */
123 DECLCALLBACKMEMBER(int, pfnErrorMsg, (PRTTRACELOGDECODERHLP pHlp, const char *pszFormat, ...)) RT_IPRT_FORMAT_ATTR(2, 3);
124
125
126 /** @name Decoder state related callbacks.
127 * @{ */
128
129 /**
130 * Creates a new decoder state and associates it with the given helper structure.
131 *
132 * @returns IPRT status.
133 * @param pHlp Pointer to the callback structure.
134 * @param cbState Size of the state in bytes.
135 * @param pfnFree Callback which is called before the decoder state is freed to give the decoder
136 * a chance to do some necessary cleanup, optional.
137 * @param ppvState Where to return the pointer to the state on success.
138 *
139 * @note This will destroy and free any previously created decoder state as there can be only one currently for
140 * a decoder.
141 */
142 DECLCALLBACKMEMBER(int, pfnDecoderStateCreate, (PRTTRACELOGDECODERHLP pHlp, size_t cbState, PFNTRACELOGDECODERSTATEFREE pfnFree,
143 void **ppvState));
144
145
146 /**
147 * Destroys any currently attached decoder state.
148 *
149 * @param pHlp Pointer to the callback structure.
150 */
151 DECLCALLBACKMEMBER(void, pfnDecoderStateDestroy, (PRTTRACELOGDECODERHLP pHlp));
152
153
154 /**
155 * Returns any decoder state created previously with RTTRACELOGDECODERHLP::pfnDecoderStateCreate().
156 *
157 * @returns Pointer to the decoder state or NULL if none was created yet.
158 * @param pHlp Pointer to the callback structure.
159 */
160 DECLCALLBACKMEMBER(void*, pfnDecoderStateGet, (PRTTRACELOGDECODERHLP pHlp));
161
162 /** @} */
163
164 /** @name Structure builder callbacks.
165 * @{ */
166
167 /**
168 * Begins a new (sub-)structure with the given name.
169 *
170 * @returns IPRT status code.
171 * @param pHlp Pointer to the callback structure.
172 * @param pszName Name of the structure.
173 */
174 DECLCALLBACKMEMBER(int, pfnStructBldBegin, (PRTTRACELOGDECODERHLP pHlp, const char *pszName));
175
176
177 /**
178 * Ends the current (sub-)structure and returns to the parent.
179 *
180 * @returns IPRT status code.
181 * @param pHlp Pointer to the callback structure.
182 */
183 DECLCALLBACKMEMBER(int, pfnStructBldEnd, (PRTTRACELOGDECODERHLP pHlp));
184
185
186 /**
187 * Adds a boolean member to the current (sub-)structure with the given name and value.
188 *
189 * @returns IPRT status code.
190 * @param pHlp Pointer to the callback structure.
191 * @param pszName Name of the member.
192 * @param fFlags Combination of RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_XXX.
193 * @param f The boolean value to record.
194 */
195 DECLCALLBACKMEMBER(int, pfnStructBldAddBool, (PRTTRACELOGDECODERHLP pHlp, const char *pszName, uint32_t fFlags, bool f));
196
197
198 /**
199 * Adds an unsigned byte (uint8_t) member to the current (sub-)structure with the given name and value.
200 *
201 * @returns IPRT status code.
202 * @param pHlp Pointer to the callback structure.
203 * @param pszName Name of the member.
204 * @param fFlags Combination of RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_XXX.
205 * @param u8 The value to record.
206 */
207 DECLCALLBACKMEMBER(int, pfnStructBldAddU8, (PRTTRACELOGDECODERHLP pHlp, const char *pszName, uint32_t fFlags, uint8_t u8));
208
209
210 /**
211 * Adds an unsigned 16-bit (uint16_t) member to the current (sub-)structure with the given name and value.
212 *
213 * @returns IPRT status code.
214 * @param pHlp Pointer to the callback structure.
215 * @param pszName Name of the member.
216 * @param fFlags Combination of RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_XXX.
217 * @param u16 The value to record.
218 */
219 DECLCALLBACKMEMBER(int, pfnStructBldAddU16, (PRTTRACELOGDECODERHLP pHlp, const char *pszName, uint32_t fFlags, uint16_t u16));
220
221
222 /**
223 * Adds an unsigned 32-bit (uint32_t) member to the current (sub-)structure with the given name and value.
224 *
225 * @returns IPRT status code.
226 * @param pHlp Pointer to the callback structure.
227 * @param pszName Name of the member.
228 * @param fFlags Combination of RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_XXX.
229 * @param u32 The value to record.
230 */
231 DECLCALLBACKMEMBER(int, pfnStructBldAddU32, (PRTTRACELOGDECODERHLP pHlp, const char *pszName, uint32_t fFlags, uint32_t u32));
232
233
234 /**
235 * Adds an unsigned 64-bit (uint64_t) member to the current (sub-)structure with the given name and value.
236 *
237 * @returns IPRT status code.
238 * @param pHlp Pointer to the callback structure.
239 * @param pszName Name of the member.
240 * @param fFlags Combination of RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_XXX.
241 * @param u64 The value to record.
242 */
243 DECLCALLBACKMEMBER(int, pfnStructBldAddU64, (PRTTRACELOGDECODERHLP pHlp, const char *pszName, uint32_t fFlags, uint64_t u64));
244
245
246 /**
247 * Adds a signed byte (int8_t) member to the current (sub-)structure with the given name and value.
248 *
249 * @returns IPRT status code.
250 * @param pHlp Pointer to the callback structure.
251 * @param pszName Name of the member.
252 * @param fFlags Combination of RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_XXX.
253 * @param i8 The value to record.
254 */
255 DECLCALLBACKMEMBER(int, pfnStructBldAddS8, (PRTTRACELOGDECODERHLP pHlp, const char *pszName, uint32_t fFlags, int8_t i8));
256
257
258 /**
259 * Adds a signed 16-bit (int16_t) member to the current (sub-)structure with the given name and value.
260 *
261 * @returns IPRT status code.
262 * @param pHlp Pointer to the callback structure.
263 * @param pszName Name of the member.
264 * @param fFlags Combination of RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_XXX.
265 * @param i16 The value to record.
266 */
267 DECLCALLBACKMEMBER(int, pfnStructBldAddS16, (PRTTRACELOGDECODERHLP pHlp, const char *pszName, uint32_t fFlags, int16_t i16));
268
269
270 /**
271 * Adds a signed 32-bit (int32_t) member to the current (sub-)structure with the given name and value.
272 *
273 * @returns IPRT status code.
274 * @param pHlp Pointer to the callback structure.
275 * @param pszName Name of the member.
276 * @param fFlags Combination of RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_XXX.
277 * @param i32 The value to record.
278 */
279 DECLCALLBACKMEMBER(int, pfnStructBldAddS32, (PRTTRACELOGDECODERHLP pHlp, const char *pszName, uint32_t fFlags, int32_t i32));
280
281
282 /**
283 * Adds a signed 64-bit (int64_t) member to the current (sub-)structure with the given name and value.
284 *
285 * @returns IPRT status code.
286 * @param pHlp Pointer to the callback structure.
287 * @param pszName Name of the member.
288 * @param fFlags Combination of RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_XXX.
289 * @param i32 The value to record.
290 */
291 DECLCALLBACKMEMBER(int, pfnStructBldAddS64, (PRTTRACELOGDECODERHLP pHlp, const char *pszName, uint32_t fFlags, int64_t i64));
292
293
294 /**
295 * Adds a string member to the current (sub-)structure with the given name and string.
296 *
297 * @returns IPRT status code.
298 * @param pHlp Pointer to the callback structure.
299 * @param pszName Name of the member.
300 * @param fFlags Combination of RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_XXX.
301 * @param pszStr The string to add.
302 */
303 DECLCALLBACKMEMBER(int, pfnStructBldAddStr, (PRTTRACELOGDECODERHLP pHlp, const char *pszName, uint32_t fFlags, const char *pszStr));
304
305
306 /**
307 * Adds a data buffer member to the current (sub-)structure with the given name and content.
308 *
309 * @returns IPRT status code.
310 * @param pHlp Pointer to the callback structure.
311 * @param pszName Name of the member.
312 * @param fFlags Combination of RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_XXX.
313 * @param pb The buffer to add.
314 * @param cb Size of the buffer in bytes.
315 */
316 DECLCALLBACKMEMBER(int, pfnStructBldAddBuf, (PRTTRACELOGDECODERHLP pHlp, const char *pszName, uint32_t fFlags, const uint8_t *pb, size_t cb));
317
318
319 /**
320 * Adds a enum member to the current (sub-)structure with the given name and value.
321 *
322 * @returns IPRT status code.
323 * @param pHlp Pointer to the callback structure.
324 * @param pszName Name of the member.
325 * @param fFlags Combination of RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_XXX.
326 * @param cBits Size of the enum data type in bits.
327 * @param paEnums Pointer to an erray of enum entries mapping a value to the description.
328 */
329 DECLCALLBACKMEMBER(int, pfnStructBldAddEnum, (PRTTRACELOGDECODERHLP pHlp, const char *pszName, uint32_t fFlags, uint8_t cBits,
330 PCRTTRACELOGDECODERSTRUCTBLDENUM paEnums, uint64_t u64Val));
331
332 /**
333 * Begins a new array member in the current (sub-)structure with the given name.
334 *
335 * @returns IPRT status code.
336 * @param pHlp Pointer to the callback structure.
337 * @param pszName Name of the array member.
338 */
339 DECLCALLBACKMEMBER(int, pfnStructBldArrayBegin, (PRTTRACELOGDECODERHLP pHlp, const char *pszName));
340
341
342 /**
343 * Ends the current array member in the current (sub-)structure.
344 *
345 * @returns IPRT status code.
346 * @param pHlp Pointer to the callback structure.
347 */
348 DECLCALLBACKMEMBER(int, pfnStructBldArrayEnd, (PRTTRACELOGDECODERHLP pHlp));
349
350 /** @} */
351
352 /** End marker (DBGCCMDHLP_MAGIC). */
353 uint32_t u32EndMarker;
354} RTTRACELOGDECODERHLP;
355
356/** Magic value for RTTRACELOGDECODERHLP::u32Magic and RTTRACELOGDECODERHLP::u32EndMarker. (Bernhard-Viktor Christoph-Carl von Buelow) */
357#define DBGCCMDHLP_MAGIC UINT32_C(0x19231112)
358
359
360/** Makes a IPRT tracelog decoder structure version out of an unique magic value and major &
361 * minor version numbers.
362 *
363 * @returns 32-bit structure version number.
364 *
365 * @param uMagic 16-bit magic value. This must be unique.
366 * @param uMajor 12-bit major version number. Structures with different
367 * major numbers are not compatible.
368 * @param uMinor 4-bit minor version number. When only the minor version
369 * differs, the structures will be 100% backwards
370 * compatible.
371 */
372#define RT_TRACELOG_DECODER_VERSION_MAKE(uMagic, uMajor, uMinor) \
373 ( ((uint32_t)(uMagic) << 16) | ((uint32_t)((uMajor) & 0xff) << 4) | ((uint32_t)((uMinor) & 0xf) << 0) )
374
375/** Checks if @a uVerMagic1 is compatible with @a uVerMagic2.
376 *
377 * @returns true / false.
378 * @param uVerMagic1 Typically the runtime version of the struct. This must
379 * have the same magic and major version as @a uVerMagic2
380 * and the minor version must be greater or equal to that
381 * of @a uVerMagic2.
382 * @param uVerMagic2 Typically the version the code was compiled against.
383 *
384 * @remarks The parameters will be referenced more than once.
385 */
386#define RT_TRACELOG_DECODER_VERSION_ARE_COMPATIBLE(uVerMagic1, uVerMagic2) \
387 ( (uVerMagic1) == (uVerMagic2) \
388 || ( (uVerMagic1) >= (uVerMagic2) \
389 && ((uVerMagic1) & UINT32_C(0xfffffff0)) == ((uVerMagic2) & UINT32_C(0xfffffff0)) ) \
390 )
391
392
393/**
394 * Decoder callback for an event.
395 *
396 * @returns IPRT status code.
397 * @param pHlp The decoder helper callback table.
398 * @param idDecodeEvt Event decoder ID given in RTTRACELOGDECODEEVT::idDecodeEvt for the particular event ID.
399 * @param hTraceLogEvt The tracelog event handle called for decoding.
400 * @param pEvtDesc The event descriptor.
401 * @param paVals Pointer to the array of values.
402 * @param cVals Number of values in the array.
403 */
404typedef DECLCALLBACKTYPE(int, FNTRACELOGDECODEREVENTDECODE,(PRTTRACELOGDECODERHLP pHlp, uint32_t idDecodeEvt,
405 RTTRACELOGRDREVT hTraceLogEvt, PCRTTRACELOGEVTDESC pEvtDesc,
406 PRTTRACELOGEVTVAL paVals, uint32_t cVals));
407/** Pointer to an event decode callback. */
408typedef FNTRACELOGDECODEREVENTDECODE *PFNTRACELOGDECODEREVENTDECODE;
409
410
411/**
412 * Event decoder entry.
413 */
414typedef struct RTTRACELOGDECODEEVT
415{
416 /** The event ID name. */
417 const char *pszEvtId;
418 /** The decoder event ID ordinal to pass to in the decode callback for
419 * faster lookup. */
420 uint32_t idDecodeEvt;
421} RTTRACELOGDECODEEVT;
422/** Pointer to an event decoder entry. */
423typedef RTTRACELOGDECODEEVT *PRTTRACELOGDECODEEVT;
424/** Pointer to a const event decoder entry. */
425typedef const RTTRACELOGDECODEEVT *PCRTTRACELOGDECODEEVT;
426
427
428/**
429 * A decoder registration structure.
430 */
431typedef struct RTTRACELOGDECODERREG
432{
433 /** Decoder name. */
434 const char *pszName;
435 /** Decoder description. */
436 const char *pszDesc;
437 /** The event IDs to register the decoder for. */
438 PCRTTRACELOGDECODEEVT paEvtIds;
439 /** The decode callback. */
440 PFNTRACELOGDECODEREVENTDECODE pfnDecode;
441} RTTRACELOGDECODERREG;
442/** Pointer to a decoder registration structure. */
443typedef RTTRACELOGDECODERREG *PRTTRACELOGDECODERREG;
444/** Pointer to a const decoder registration structure. */
445typedef const RTTRACELOGDECODERREG *PCRTTRACELOGDECODERREG;
446
447
448/**
449 * Decoder register callbacks structure.
450 */
451typedef struct RTTRACELOGDECODERREGISTER
452{
453 /** Interface version.
454 * This is set to RT_TRACELOG_DECODERREG_CB_VERSION. */
455 uint32_t u32Version;
456
457 /**
458 * Registers a new decoders.
459 *
460 * @returns VBox status code.
461 * @param pvUser Opaque user data given in the plugin load callback.
462 * @param paDecoders Pointer to an array of decoders to register.
463 * @param cDecoders Number of entries in the array.
464 */
465 DECLR3CALLBACKMEMBER(int, pfnRegisterDecoders, (void *pvUser, PCRTTRACELOGDECODERREG paDecoders, uint32_t cDecoders));
466
467} RTTRACELOGDECODERREGISTER;
468/** Pointer to a backend register callbacks structure. */
469typedef RTTRACELOGDECODERREGISTER *PRTTRACELOGDECODERREGISTER;
470
471/** Current version of the RTTRACELOGDECODERREGISTER structure. */
472#define RT_TRACELOG_DECODERREG_CB_VERSION RT_TRACELOG_DECODER_VERSION_MAKE(0xfeed, 1, 0)
473
474/**
475 * Initialization entry point called by the tracelog layer when
476 * a plugin is loaded.
477 *
478 * @returns IPRT status code.
479 * @param pvUser Opaque user data passed in the register callbacks.
480 * @param pRegisterCallbacks Pointer to the register callbacks structure.
481 */
482typedef DECLCALLBACKTYPE(int, FNTRACELOGDECODERPLUGINLOAD,(void *pvUser, PRTTRACELOGDECODERREGISTER pRegisterCallbacks));
483typedef FNTRACELOGDECODERPLUGINLOAD *PFNTRACELOGDECODERPLUGINLOAD;
484#define RT_TRACELOG_DECODER_PLUGIN_LOAD "RTTraceLogDecoderLoad"
485
486#endif /* !IPRT_INCLUDED_tracelog_decoder_plugin_h */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette