VirtualBox

Changeset 104966 in vbox


Ignore:
Timestamp:
Jun 19, 2024 3:40:02 PM (3 months ago)
Author:
vboxsync
Message:

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

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/tracelog-decoder-plugin.h

    r104921 r104966  
    6060
    6161
     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
    6294/**
    6395 * Helper functions for decoders.
     
    92124
    93125
     126    /** @name Decoder state related callbacks.
     127     * @{ */
     128
    94129    /**
    95130     * Creates a new decoder state and associates it with the given helper structure.
     
    125160    DECLCALLBACKMEMBER(void*, pfnDecoderStateGet, (PRTTRACELOGDECODERHLP pHlp));
    126161
     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    /** @} */
    127351
    128352    /** End marker (DBGCCMDHLP_MAGIC). */
  • trunk/src/VBox/Devices/Trace/VBoxTraceLogDecoders.cpp

    r104961 r104966  
    123123 * Algorithm ID to string mapping array.
    124124 */
    125 static const TPMALGID2STR g_aAlgId2Str[] =
     125static const RTTRACELOGDECODERSTRUCTBLDENUM g_aAlgId2Str[] =
    126126{
    127127#define TPM_ALGID_2_STR(a_AlgId) { a_AlgId, #a_AlgId, 0 }
     
    187187    TPM_ALGID_2_STR(TPM2_ALG_KMACXOF256),
    188188    TPM_ALGID_2_STR(TPM2_ALG_KMAC128),
    189     TPM_ALGID_2_STR(TPM2_ALG_KMAC256)
     189    TPM_ALGID_2_STR(TPM2_ALG_KMAC256),
     190    { 0, NULL, 0 }
    190191#undef TPM_ALGID_2_STR
    191192};
     
    320321{
    321322    for (uint32_t i = 0; i < RT_ELEMENTS(g_aAlgId2Str); i++)
    322         if (g_aAlgId2Str[i].u16AlgId == u16AlgId)
    323             return g_aAlgId2Str[i].pszAlgId;
     323        if (g_aAlgId2Str[i].u64EnumVal == u16AlgId)
     324            return g_aAlgId2Str[i].pszString;
    324325
    325326    return "<UNKNOWN>";
     
    330331{
    331332    for (uint32_t i = 0; i < RT_ELEMENTS(g_aAlgId2Str); i++)
    332         if (g_aAlgId2Str[i].u16AlgId == u16AlgId)
    333             return g_aAlgId2Str[i].cbDigest;
     333        if (g_aAlgId2Str[i].u64EnumVal == u16AlgId)
     334            return g_aAlgId2Str[i].uPtrUser;
    334335
    335336    return 0;
     
    343344    if (pCtx->fError) return
    344345
     346#define TPM_DECODE_BOOL(a_Var, a_Name) \
     347    uint8_t a_Var = vboxTraceLogDecodeEvtTpmDecodeCtxGetU8(pCtx, pHlp, #a_Name); \
     348    if (pCtx->fError) break; \
     349    pHlp->pfnStructBldAddBool(pHlp, #a_Name, 0 /*fFlags*/, RT_BOOL(a_Var))
     350
    345351#define TPM_DECODE_U8(a_Var, a_Name) \
    346352    uint8_t a_Var = vboxTraceLogDecodeEvtTpmDecodeCtxGetU8(pCtx, pHlp, #a_Name); \
    347     if (pCtx->fError) break
     353    if (pCtx->fError) break; \
     354    pHlp->pfnStructBldAddU8(pHlp, #a_Name, 0 /*fFlags*/, a_Var)
    348355
    349356#define TPM_DECODE_U16(a_Var, a_Name) \
    350357    uint16_t a_Var = vboxTraceLogDecodeEvtTpmDecodeCtxGetU16(pCtx, pHlp, #a_Name); \
    351     if (pCtx->fError) break
     358    if (pCtx->fError) break; \
     359    pHlp->pfnStructBldAddU16(pHlp, #a_Name, 0 /*fFlags*/, a_Var)
    352360
    353361#define TPM_DECODE_U32(a_Var, a_Name) \
    354362    uint32_t a_Var = vboxTraceLogDecodeEvtTpmDecodeCtxGetU32(pCtx, pHlp, #a_Name); \
    355     if (pCtx->fError) break
     363    if (pCtx->fError) break; \
     364    pHlp->pfnStructBldAddU32(pHlp, #a_Name, 0 /*fFlags*/, a_Var)
    356365
    357366#define TPM_DECODE_U64(a_Var, a_Name) \
    358367    uint64_t a_Var = vboxTraceLogDecodeEvtTpmDecodeCtxGetU64(pCtx, pHlp, #a_Name); \
    359     if (pCtx->fError) break
     368    if (pCtx->fError) break; \
     369    pHlp->pfnStructBldAddU64(pHlp, #a_Name, 0 /*fFlags*/, a_Var)
    360370
    361371#define TPM_DECODE_I32(a_Var, a_Name) \
    362372    int32_t a_Var = vboxTraceLogDecodeEvtTpmDecodeCtxGetI32(pCtx, pHlp, #a_Name); \
     373    if (pCtx->fError) break; \
     374    pHlp->pfnStructBldAddS32(pHlp, #a_Name, 0 /*fFlags*/, a_Var)
     375
     376#define TPM_DECODE_U8_HEX(a_Var, a_Name) \
     377    uint8_t a_Var = vboxTraceLogDecodeEvtTpmDecodeCtxGetU8(pCtx, pHlp, #a_Name); \
     378    if (pCtx->fError) break; \
     379    pHlp->pfnStructBldAddU8(pHlp, #a_Name, RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_HEX, a_Var)
     380
     381#define TPM_DECODE_U16_HEX(a_Var, a_Name) \
     382    uint16_t a_Var = vboxTraceLogDecodeEvtTpmDecodeCtxGetU16(pCtx, pHlp, #a_Name); \
     383    if (pCtx->fError) break; \
     384    pHlp->pfnStructBldAddU16(pHlp, #a_Name, RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_HEX, a_Var)
     385
     386#define TPM_DECODE_U32_HEX(a_Var, a_Name) \
     387    uint32_t a_Var = vboxTraceLogDecodeEvtTpmDecodeCtxGetU32(pCtx, pHlp, #a_Name); \
     388    if (pCtx->fError) break; \
     389    pHlp->pfnStructBldAddU32(pHlp, #a_Name, RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_HEX, a_Var)
     390
     391#define TPM_DECODE_U32_HEX_STR(a_Var, a_pszName) \
     392    uint32_t a_Var = vboxTraceLogDecodeEvtTpmDecodeCtxGetU32(pCtx, pHlp, a_pszName); \
     393    if (pCtx->fError) break; \
     394    pHlp->pfnStructBldAddU32(pHlp, a_pszName, RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_HEX, a_Var)
     395
     396#define TPM_DECODE_U64_HEX(a_Var, a_Name) \
     397    uint64_t a_Var = vboxTraceLogDecodeEvtTpmDecodeCtxGetU64(pCtx, pHlp, #a_Name); \
     398    if (pCtx->fError) break; \
     399    pHlp->pfnStructBldAddU64(pHlp, #a_Name, RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_HEX, a_Var)
     400
     401#define TPM_DECODE_I32_HEX(a_Var, a_Name) \
     402    int32_t a_Var = vboxTraceLogDecodeEvtTpmDecodeCtxGetI32(pCtx, pHlp, #a_Name); \
     403    if (pCtx->fError) break; \
     404    pHlp->pfnStructBldAddS32(pHlp, #a_Name, 0 /*fFlags*/, a_Var)
     405
     406#define TPM_DECODE_BUF_EX(a_Var, a_Name, a_cb) \
     407    const uint8_t *a_Var = vboxTraceLogDecodeEvtTpmDecodeCtxGetBuf(pCtx, pHlp, #a_Name, a_cb); \
    363408    if (pCtx->fError) break
    364409
    365410#define TPM_DECODE_BUF(a_Var, a_Name, a_cb) \
    366411    const uint8_t *a_Var = vboxTraceLogDecodeEvtTpmDecodeCtxGetBuf(pCtx, pHlp, #a_Name, a_cb); \
    367     if (pCtx->fError) break
     412    if (pCtx->fError) break; \
     413    if (a_Var) \
     414        pHlp->pfnStructBldAddBuf(pHlp, #a_Name, 0 /*fFlags*/, a_Var, a_cb);
     415
     416#define TPM_DECODE_BUF_HEX_STRING(a_Var, a_Name, a_cb) \
     417    const uint8_t *a_Var = vboxTraceLogDecodeEvtTpmDecodeCtxGetBuf(pCtx, pHlp, #a_Name, a_cb); \
     418    if (pCtx->fError) break; \
     419    if (a_Var) \
     420        pHlp->pfnStructBldAddBuf(pHlp, #a_Name, RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_HEX_DUMP_STR, a_Var, a_cb);
     421
     422#define TPM_DECODE_U16_ENUM(a_Var, a_Name, a_aEnums) \
     423    uint16_t a_Var = vboxTraceLogDecodeEvtTpmDecodeCtxGetU16(pCtx, pHlp, #a_Name); \
     424    if (pCtx->fError) break; \
     425    pHlp->pfnStructBldAddEnum(pHlp, #a_Name, RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_HEX, 16, a_aEnums, a_Var)
     426
     427#define TPM_DECODE_U32_ENUM(a_Var, a_Name, a_aEnums) \
     428    uint32_t a_Var = vboxTraceLogDecodeEvtTpmDecodeCtxGetU32(pCtx, pHlp, #a_Name); \
     429    if (pCtx->fError) break; \
     430    pHlp->pfnStructBldAddEnum(pHlp, #a_Name, RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_HEX, 32, a_aEnums, a_Var)
    368431
    369432#define TPM_DECODE_BUF_STR(a_Var, a_pszName, a_cb) \
    370433    const uint8_t *a_Var = vboxTraceLogDecodeEvtTpmDecodeCtxGetBuf(pCtx, pHlp, a_pszName, a_cb); \
    371     if (pCtx->fError) break
     434    if (pCtx->fError) break; \
     435    if (a_Var) \
     436        pHlp->pfnStructBldAddBuf(pHlp, a_pszName, RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_HEX_DUMP_STR, a_Var, a_cb);
    372437
    373438#define TPM_DECODE_END_IF_ERROR() \
     
    377442{
    378443    TPM_DECODE_INIT();
    379         TPM_DECODE_U16(u16AlgId,      u16AlgId);
    380         TPM_DECODE_U8(cbPcrSelection, u8SizeOfSelect);
    381         TPM_DECODE_BUF(pb,            PCRs,           cbPcrSelection);
    382 
    383         pHlp->pfnPrintf(pHlp, "            u16AlgId:      %s\n", vboxTraceLogDecodeEvtTpmAlgId2Str(u16AlgId));
    384         pHlp->pfnPrintf(pHlp, "            u8SizeOfSlect: %u\n", cbPcrSelection);
    385         pHlp->pfnPrintf(pHlp, "            PCRs:          ");
     444        TPM_DECODE_U16_ENUM(u16AlgId,       u16AlgId,        g_aAlgId2Str  );
     445        TPM_DECODE_U8(      cbPcrSelection, u8SizeOfSelect                 );
     446        TPM_DECODE_BUF_EX(  pb,             PCRs,            cbPcrSelection);
     447
     448        pHlp->pfnStructBldArrayBegin(pHlp, "PCRs");
    386449
    387450        for (uint8_t idxPcr = 0; idxPcr < cbPcrSelection * 8; idxPcr++)
    388451            if (RT_BOOL(*(pb + (idxPcr / 8)) & RT_BIT(idxPcr % 8)))
    389                 pHlp->pfnPrintf(pHlp, "%u ", idxPcr);
    390 
    391         pHlp->pfnPrintf(pHlp, "\n");
     452                pHlp->pfnStructBldAddU8(pHlp, NULL, 0 /*fFlags*/, idxPcr);
     453
     454        pHlp->pfnStructBldArrayEnd(pHlp);
     455
    392456    TPM_DECODE_END();
    393457}
     
    398462    TPM_DECODE_INIT();
    399463        TPM_DECODE_U32(u32Count, u32Count);
    400         pHlp->pfnPrintf(pHlp, "        u32Count:  %u\n", u32Count);
     464
     465        pHlp->pfnStructBldBegin(pHlp, "aPcrSelection");
    401466
    402467        /* Walk the list of PCR selection entries. */
     
    406471            TPM_DECODE_END_IF_ERROR();
    407472        }
     473
     474        pHlp->pfnStructBldEnd(pHlp);
     475
    408476    TPM_DECODE_END();
    409477}
     
    414482    TPM_DECODE_INIT();
    415483        TPM_DECODE_U32(u32DigestCount, u32DigestCount);
    416         pHlp->pfnPrintf(pHlp, "        u32DigestCount:      %u\n", u32DigestCount);
     484
     485        pHlp->pfnStructBldBegin(pHlp, "aDigests");
     486
    417487        for (uint32_t i = 0; i < u32DigestCount; i++)
    418488        {
    419489            TPM_DECODE_U16(u16DigestSize, u16DigestSize);
    420             TPM_DECODE_BUF(pbDigest, abDigest, u16DigestSize);
    421             pHlp->pfnPrintf(pHlp, "            u16DigestSize:      %u\n", u16DigestSize);
    422             pHlp->pfnPrintf(pHlp, "            abDigest:           %.*Rhxs\n", u16DigestSize, pbDigest);
     490            TPM_DECODE_BUF_HEX_STRING(pbDigest, abDigest, u16DigestSize);
    423491        }
     492
     493        pHlp->pfnStructBldEnd(pHlp);
     494
    424495    TPM_DECODE_END();
    425496}
     
    430501    TPM_DECODE_INIT();
    431502        TPM_DECODE_U32(u32DigestCount, u32DigestCount);
    432         pHlp->pfnPrintf(pHlp, "        u32DigestCount:      %u\n", u32DigestCount);
     503
     504        pHlp->pfnStructBldBegin(pHlp, "aDigests");
     505
    433506        for (uint32_t i = 0; i < u32DigestCount; i++)
    434507        {
    435             TPM_DECODE_U16(u16HashAlg, u16HashAlg);
     508            TPM_DECODE_U16_ENUM(u16HashAlg, u16HashAlg, g_aAlgId2Str);
    436509
    437510            size_t cbDigest = vboxTraceLogDecodeEvtTpmAlgId2DigestSize(u16HashAlg);
    438             TPM_DECODE_BUF(pb, abDigest, cbDigest);
    439 
    440             pHlp->pfnPrintf(pHlp, "            u16HashAlg:         %s\n", vboxTraceLogDecodeEvtTpmAlgId2Str(u16HashAlg));
    441             pHlp->pfnPrintf(pHlp, "            abDigest:           %.*Rhxs\n", cbDigest, pb);
     511            TPM_DECODE_BUF_HEX_STRING(pb, abDigest, cbDigest);
    442512        }
     513
     514        pHlp->pfnStructBldEnd(pHlp);
     515
    443516    TPM_DECODE_END();
    444517}
     
    447520static void vboxTraceLogDecodeEvtTpmAuthSessionReq(PRTTRACELOGDECODERHLP pHlp, PTPMDECODECTX pCtx)
    448521{
    449     TPM_DECODE_INIT();
    450         TPM_DECODE_U32(u32Size,          u32Size);
    451         TPM_DECODE_U32(u32SessionHandle, u32SessionHandle);
    452         TPM_DECODE_U16(u16NonceSize,     u16NonceSize);
    453         TPM_DECODE_BUF(pbNonce,          abNonce, u16NonceSize);
    454         TPM_DECODE_U8( u8Attr,           u8Attr);
    455         TPM_DECODE_U16(u16HmacSize,      u16HmacSize);
    456         TPM_DECODE_BUF(pbHmac,           abHmac,  u16HmacSize);
    457 
    458         pHlp->pfnPrintf(pHlp, "        u32AuthSize:      %u\n", u32Size);
    459         pHlp->pfnPrintf(pHlp, "        u32SessionHandle: %#x\n", u32SessionHandle);
    460         pHlp->pfnPrintf(pHlp, "        u16NonceSize:     %u\n", u16NonceSize);
    461         if (u16NonceSize)
    462             pHlp->pfnPrintf(pHlp, "        abNonce:          %.*Rhxs\n", u16NonceSize, pbNonce);
    463         pHlp->pfnPrintf(pHlp, "        u8Attr:           %u\n", u8Attr);
    464         pHlp->pfnPrintf(pHlp, "        u16HmacSize:      %u\n", u16HmacSize);
    465         if (u16HmacSize)
    466             pHlp->pfnPrintf(pHlp, "        abHmac:           %.*Rhxs\n", u16HmacSize, pbHmac);
    467     TPM_DECODE_END();
     522    pHlp->pfnStructBldBegin(pHlp, "AuthArea");
     523    TPM_DECODE_INIT();
     524        TPM_DECODE_U32(    u32Size,          u32Size);
     525        TPM_DECODE_U32_HEX(u32SessionHandle, u32SessionHandle);
     526        TPM_DECODE_U16(    u16NonceSize,     u16NonceSize);
     527        TPM_DECODE_BUF(    pbNonce,          abNonce, u16NonceSize);
     528        TPM_DECODE_U8(     u8Attr,           u8Attr);
     529        TPM_DECODE_U16(    u16HmacSize,      u16HmacSize);
     530        TPM_DECODE_BUF(    pbHmac,           abHmac,  u16HmacSize);
     531    TPM_DECODE_END();
     532    pHlp->pfnStructBldEnd(pHlp);
    468533}
    469534
     
    471536static void vboxTraceLogDecodeEvtTpmAuthSessionResp(PRTTRACELOGDECODERHLP pHlp, PTPMDECODECTX pCtx)
    472537{
     538    pHlp->pfnStructBldBegin(pHlp, "AuthArea");
    473539    TPM_DECODE_INIT();
    474540        TPM_DECODE_U16(u16NonceSize,     u16NonceSize);
     
    477543        TPM_DECODE_U16(u16AckSize,       u16AckSize);
    478544        TPM_DECODE_BUF(pbAck,            abAck,  u16AckSize);
    479 
    480         pHlp->pfnPrintf(pHlp, "        u16NonceSize:     %u\n", u16NonceSize);
    481         if (u16NonceSize)
    482             pHlp->pfnPrintf(pHlp, "        abNonce:          %.*Rhxs\n", u16NonceSize, pbNonce);
    483         pHlp->pfnPrintf(pHlp, "        u8Attr:           %u\n", u8Attr);
    484         pHlp->pfnPrintf(pHlp, "        u16AckSize:       %u\n", u16AckSize);
    485         if (u16AckSize)
    486             pHlp->pfnPrintf(pHlp, "        abAck:            %.*Rhxs\n", u16AckSize, pbAck);
    487     TPM_DECODE_END();
     545    TPM_DECODE_END();
     546    pHlp->pfnStructBldEnd(pHlp);
    488547}
    489548
     
    491550static void vboxTraceLogDecodeSizedBufU16(PRTTRACELOGDECODERHLP pHlp, PTPMDECODECTX pCtx, const char *pszName)
    492551{
    493     TPM_DECODE_INIT();
    494         pHlp->pfnPrintf(pHlp, "        %s:\n", pszName);
     552    pHlp->pfnStructBldBegin(pHlp, pszName);
     553    TPM_DECODE_INIT();
    495554        TPM_DECODE_U16(u16Size, u16Size);
    496         pHlp->pfnPrintf(pHlp, "            u16Size:  %u\n", u16Size);
    497555        if (u16Size)
    498556        {
    499557            TPM_DECODE_BUF_STR(pb, pszName, u16Size);
    500             pHlp->pfnPrintf(pHlp, "            %s:\n"
    501                                   "%.*Rhxd\n", pszName, u16Size, pb);
    502558        }
    503559    TPM_DECODE_END();
     560    pHlp->pfnStructBldEnd(pHlp);
    504561}
    505562
     
    507564static void vboxTraceLogDecodeSymEncDef(PRTTRACELOGDECODERHLP pHlp, PTPMDECODECTX pCtx, const char *pszName)
    508565{
    509     RT_NOREF(pszName);
    510 
    511     TPM_DECODE_INIT();
    512         pHlp->pfnPrintf(pHlp, "        %s:\n", pszName);
    513         TPM_DECODE_U16(u16HashAlg, u16HashAlg);
    514         pHlp->pfnPrintf(pHlp, "            u16Alg:             %s\n", vboxTraceLogDecodeEvtTpmAlgId2Str(u16HashAlg));
     566    pHlp->pfnStructBldBegin(pHlp, pszName);
     567    TPM_DECODE_INIT();
     568        TPM_DECODE_U16_ENUM(u16HashAlg, u16HashAlg, g_aAlgId2Str);
    515569        if (u16HashAlg != TPM2_ALG_NULL)
    516570        {
    517571            TPM_DECODE_U16(u16KeyBits, u16KeyBits);
    518             pHlp->pfnPrintf(pHlp, "            u16KeyBits:         %u\n", u16KeyBits);
    519             TPM_DECODE_U16(u16SymMode, u16SymMode);
    520             pHlp->pfnPrintf(pHlp, "            u16SymMode:         %s\n", vboxTraceLogDecodeEvtTpmAlgId2Str(u16SymMode));
     572            TPM_DECODE_U16_ENUM(u16SymMode, u16SymMode, g_aAlgId2Str);
    521573            /* Symmetric details are not required as of now. */
    522574        }
    523575    TPM_DECODE_END();
     576    pHlp->pfnStructBldEnd(pHlp);
    524577}
    525578
     
    527580static void vboxTraceLogDecodeNvPublic(PRTTRACELOGDECODERHLP pHlp, PTPMDECODECTX pCtx, const char *pszName)
    528581{
    529     TPM_DECODE_INIT();
    530         pHlp->pfnPrintf(pHlp, "        %s:\n", pszName);
     582    pHlp->pfnStructBldBegin(pHlp, pszName);
     583    TPM_DECODE_INIT();
    531584        TPM_DECODE_U16(u16Size, u16Size);
    532         pHlp->pfnPrintf(pHlp, "            u16Size:  %u\n", u16Size);
    533585        if (u16Size)
    534586        {
    535             TPM_DECODE_U32(hNvIndex,        hNvIndex);
     587            TPM_DECODE_U32_HEX(hNvIndex,    hNvIndex);
    536588            TPM_DECODE_U16(u16HashAlgName,  u16HashAlgName);
    537589            TPM_DECODE_U32(u32Attr,         fAttr);
    538 
    539             pHlp->pfnPrintf(pHlp, "            hNvIndex:         %#x\n", hNvIndex);
    540             pHlp->pfnPrintf(pHlp, "            u16HashAlgName:   %u\n",  u16HashAlgName);
    541             pHlp->pfnPrintf(pHlp, "            u32Attr:          %#x\n", u32Attr);
    542 
    543590            vboxTraceLogDecodeSizedBufU16(pHlp, pCtx, "AuthPolicy");
    544591            TPM_DECODE_U16(u16DataSize, u16DataSize);
    545             pHlp->pfnPrintf(pHlp, "            u16DataSize:      %u\n",  u16DataSize);
    546592        }
    547593    TPM_DECODE_END();
     594    pHlp->pfnStructBldEnd(pHlp);
    548595}
    549596
     
    551598static void vboxTraceLogDecodeTicket(PRTTRACELOGDECODERHLP pHlp, PTPMDECODECTX pCtx, const char *pszName)
    552599{
    553     TPM_DECODE_INIT();
    554         pHlp->pfnPrintf(pHlp, "        %s:\n", pszName);
    555 
    556         TPM_DECODE_U16(u16Tag,      u16Tag);
    557         TPM_DECODE_U32(hHierarchy,  hHierarchy);
    558         pHlp->pfnPrintf(pHlp, "            u16Tag:       %#x\n", u16Tag);
    559         pHlp->pfnPrintf(pHlp, "            hHierarchy:   %#x\n", hHierarchy);
     600    pHlp->pfnStructBldBegin(pHlp, pszName);
     601    TPM_DECODE_INIT();
     602        TPM_DECODE_U16_HEX(u16Tag,      u16Tag);
     603        TPM_DECODE_U32_HEX(hHierarchy,  hHierarchy);
    560604        vboxTraceLogDecodeSizedBufU16(pHlp, pCtx, "Digest");
    561605    TPM_DECODE_END();
    562 }
     606    pHlp->pfnStructBldEnd(pHlp);
     607}
     608
     609
     610static RTTRACELOGDECODERSTRUCTBLDENUM g_aStartupShutdownParam[] =
     611{
     612    RT_TRACELOG_DECODER_STRUCT_BLD_ENUM_INIT(TPM2_SU_CLEAR),
     613    RT_TRACELOG_DECODER_STRUCT_BLD_ENUM_INIT(TPM2_SU_STATE)
     614};
    563615
    564616static DECLCALLBACK(void) vboxTraceLogDecodeEvtTpmDecodeStartupShutdownReq(PRTTRACELOGDECODERHLP pHlp, PTPMSTATE pThis, PTPMDECODECTX pCtx)
     
    567619
    568620    TPM_DECODE_INIT();
    569         TPM_DECODE_U16(u16TpmSu, u16State);
    570 
    571         if (u16TpmSu == TPM2_SU_CLEAR)
    572             pHlp->pfnPrintf(pHlp, "        TPM2_SU_CLEAR\n");
    573         else if (u16TpmSu == TPM2_SU_STATE)
    574             pHlp->pfnPrintf(pHlp, "        TPM2_SU_STATE\n");
    575         else
    576             pHlp->pfnPrintf(pHlp, "        Unknown: %#x\n", u16TpmSu);
    577     TPM_DECODE_END();
    578 }
    579 
    580 
    581 static struct
    582 {
    583     const char     *pszCap;
    584     const uint32_t *paProperties;
    585 } s_aTpm2Caps[] =
    586 {
    587     { RT_STR(TPM2_CAP_ALGS),            NULL },
    588     { RT_STR(TPM2_CAP_HANDLES),         NULL },
    589     { RT_STR(TPM2_CAP_COMMANDS),        NULL },
    590     { RT_STR(TPM2_CAP_PP_COMMANDS),     NULL },
    591     { RT_STR(TPM2_CAP_AUDIT_COMMANDS),  NULL },
    592     { RT_STR(TPM2_CAP_PCRS),            NULL },
    593     { RT_STR(TPM2_CAP_TPM_PROPERTIES),  NULL },
    594     { RT_STR(TPM2_CAP_PCR_PROPERTIES),  NULL },
    595     { RT_STR(TPM2_CAP_ECC_CURVES),      NULL },
    596     { RT_STR(TPM2_CAP_AUTH_POLICIES),   NULL },
    597     { RT_STR(TPM2_CAP_ACT),             NULL },
     621        TPM_DECODE_U16_ENUM(u16TpmSu, u16State, g_aStartupShutdownParam);
     622    TPM_DECODE_END();
     623}
     624
     625
     626static RTTRACELOGDECODERSTRUCTBLDENUM g_aTpm2Caps[] =
     627{
     628    RT_TRACELOG_DECODER_STRUCT_BLD_ENUM_INIT(TPM2_CAP_ALGS),
     629    RT_TRACELOG_DECODER_STRUCT_BLD_ENUM_INIT(TPM2_CAP_HANDLES),
     630    RT_TRACELOG_DECODER_STRUCT_BLD_ENUM_INIT(TPM2_CAP_COMMANDS),
     631    RT_TRACELOG_DECODER_STRUCT_BLD_ENUM_INIT(TPM2_CAP_PP_COMMANDS),
     632    RT_TRACELOG_DECODER_STRUCT_BLD_ENUM_INIT(TPM2_CAP_AUDIT_COMMANDS),
     633    RT_TRACELOG_DECODER_STRUCT_BLD_ENUM_INIT(TPM2_CAP_PCRS),
     634    RT_TRACELOG_DECODER_STRUCT_BLD_ENUM_INIT(TPM2_CAP_TPM_PROPERTIES),
     635    RT_TRACELOG_DECODER_STRUCT_BLD_ENUM_INIT(TPM2_CAP_PCR_PROPERTIES),
     636    RT_TRACELOG_DECODER_STRUCT_BLD_ENUM_INIT(TPM2_CAP_ECC_CURVES),
     637    RT_TRACELOG_DECODER_STRUCT_BLD_ENUM_INIT(TPM2_CAP_AUTH_POLICIES),
     638    RT_TRACELOG_DECODER_STRUCT_BLD_ENUM_INIT(TPM2_CAP_ACT)
    598639};
    599640
     
    601642{
    602643    TPM_DECODE_INIT();
    603         TPM_DECODE_U32(u32Cap,      u32Cap);
    604         TPM_DECODE_U32(u32Property, u32Property);
    605         TPM_DECODE_U32(u32Count,    u32Count);
     644        TPM_DECODE_U32_ENUM(u32Cap,      u32Cap,      g_aTpm2Caps);
     645        TPM_DECODE_U32_HEX( u32Property, u32Property             );
     646        TPM_DECODE_U32(     u32Count,    u32Count                );
    606647
    607648        pThis->u.GetCapability.u32Cap      = u32Cap;
    608649        pThis->u.GetCapability.u32Property = u32Property;
    609650        pThis->u.GetCapability.u32Count    = u32Count;
    610 
    611         if (u32Cap < RT_ELEMENTS(s_aTpm2Caps))
    612             pHlp->pfnPrintf(pHlp, "        u32Cap:      %s\n"
    613                                   "        u32Property: %#x\n"
    614                                   "        u32Count:    %#x\n",
    615                             s_aTpm2Caps[u32Cap].pszCap, u32Property, u32Count);
    616         else
    617             pHlp->pfnPrintf(pHlp, "        u32Cap:      %#x (UNKNOWN)\n"
    618                                   "        u32Property: %#x\n"
    619                                   "        u32Count:    %#x\n",
    620                             u32Cap, u32Property, u32Count);
    621651    TPM_DECODE_END();
    622652}
     
    628658
    629659    TPM_DECODE_INIT();
    630         TPM_DECODE_U8( fMoreData,   fMoreData);
    631         TPM_DECODE_U32(u32Cap,      u32Cap);
    632 
    633         pHlp->pfnPrintf(pHlp, "        fMoreData: %RTbool\n", fMoreData);
    634         if (u32Cap < RT_ELEMENTS(s_aTpm2Caps))
     660        TPM_DECODE_BOOL(    fMoreData,   fMoreData);
     661        TPM_DECODE_U32_ENUM(u32Cap,      u32Cap,      g_aTpm2Caps);
     662
     663        switch (u32Cap)
    635664        {
    636             pHlp->pfnPrintf(pHlp, "        u32Cap:    %s\n", s_aTpm2Caps[u32Cap]);
    637             switch (u32Cap)
     665            case TPM2_CAP_PCRS:
    638666            {
    639                 case TPM2_CAP_PCRS:
    640                 {
    641                     vboxTraceLogDecodePcrSelectionList(pHlp, pCtx);
    642                     break;
    643                 }
    644                 default:
    645                     break;
     667                vboxTraceLogDecodePcrSelectionList(pHlp, pCtx);
     668                break;
    646669            }
     670            default:
     671                break;
    647672        }
    648         else
    649             pHlp->pfnPrintf(pHlp, "        u32Cap:    %#x (UNKNOWN)\n", u32Cap);
    650673    TPM_DECODE_END();
    651674}
     
    679702        TPM_DECODE_U16(u16RandomBytes, u16RandomBytes);
    680703        pThis->u.GetRandom.cbRnd = u16RandomBytes;
    681         pHlp->pfnPrintf(pHlp, "        u16RandomBytes: %u\n", pThis->u.GetRandom.cbRnd);
    682704    TPM_DECODE_END();
    683705}
     
    696718
    697719        TPM_DECODE_BUF(pb, RndBuf, cbBuf);
    698         pHlp->pfnPrintf(pHlp, "%.*Rhxd\n", cbBuf, pb);
    699720    TPM_DECODE_END();
    700721}
     
    717738    TPM_DECODE_INIT();
    718739        TPM_DECODE_U32(u32PcrUpdateCounter, u32PcrUpdateCounter);
    719         pHlp->pfnPrintf(pHlp, "        u32PcrUpdateCounter: %u\n", u32PcrUpdateCounter);
    720 
    721740        vboxTraceLogDecodePcrSelectionList(pHlp, pCtx);
    722741        TPM_DECODE_END_IF_ERROR();
     
    749768    TPM_DECODE_INIT();
    750769        TPM_DECODE_U64(u64Time, u64Time);
    751         pHlp->pfnPrintf(pHlp, "        u64Time: %RX64\n", u64Time);
    752770
    753771        /* Decode TPMS_CLOCK_INFO. */
    754         TPM_DECODE_U64(u64Clock,        u64Clock);
    755         TPM_DECODE_U32(u32ResetCount,   u32ResetCount);
    756         TPM_DECODE_U32(u32RestartCount, u32RestartCount);
    757         TPM_DECODE_U8( fSafe,           fSafe);
    758         pHlp->pfnPrintf(pHlp, "        u64Clock:         %RX64\n",   u64Clock);
    759         pHlp->pfnPrintf(pHlp, "        u32ResetCount:    %u\n",      u32ResetCount);
    760         pHlp->pfnPrintf(pHlp, "        u32RestartCount:  %u\n",      u32RestartCount);
    761         pHlp->pfnPrintf(pHlp, "        fSafe:            %RTbool\n", fSafe);
    762 
     772        TPM_DECODE_U64( u64Clock,        u64Clock);
     773        TPM_DECODE_U32( u32ResetCount,   u32ResetCount);
     774        TPM_DECODE_U32( u32RestartCount, u32RestartCount);
     775        TPM_DECODE_BOOL(fSafe,           fSafe);
    763776    TPM_DECODE_END();
    764777}
     
    800813        TPM_DECODE_END_IF_ERROR();
    801814
    802         TPM_DECODE_U8(u8SessionType, u8SessionType);
    803         pHlp->pfnPrintf(pHlp, "        u8SessionType:  %#x\n", u8SessionType);
     815        TPM_DECODE_U8_HEX(u8SessionType, u8SessionType);
    804816
    805817        vboxTraceLogDecodeSymEncDef(pHlp, pCtx, "Symmetric");
     818        TPM_DECODE_END_IF_ERROR();
     819
     820        TPM_DECODE_U16_ENUM(u16HashAlg, u16HashAlg, g_aAlgId2Str);
     821    TPM_DECODE_END();
     822}
     823
     824
     825static const char *g_apszHandlesStartAuthSessionResp[] =
     826{
     827    "hSession",
     828    NULL
     829};
     830
     831
     832static DECLCALLBACK(void) vboxTraceLogDecodeEvtTpmDecodeStartAuthSessionResp(PRTTRACELOGDECODERHLP pHlp, PTPMSTATE pThis, PTPMDECODECTX pCtx)
     833{
     834    RT_NOREF(pThis);
     835
     836    TPM_DECODE_INIT();
     837        vboxTraceLogDecodeSizedBufU16(pHlp, pCtx, "NonceTpm");
     838    TPM_DECODE_END();
     839}
     840
     841
     842static const char *g_apszHandlesHierarchyChangeAuthReq[] =
     843{
     844    "hAuth",
     845    NULL
     846};
     847
     848static DECLCALLBACK(void) vboxTraceLogDecodeEvtTpmDecodeHierarchyChangeAuthReq(PRTTRACELOGDECODERHLP pHlp, PTPMSTATE pThis, PTPMDECODECTX pCtx)
     849{
     850    RT_NOREF(pThis);
     851
     852    TPM_DECODE_INIT();
     853        vboxTraceLogDecodeSizedBufU16(pHlp, pCtx, "NewAuth");
     854    TPM_DECODE_END();
     855}
     856
     857
     858static const char *g_apszHandlesNvDefineSpaceReq[] =
     859{
     860    "hAuth",
     861    NULL
     862};
     863
     864static DECLCALLBACK(void) vboxTraceLogDecodeEvtTpmDecodeNvDefineSpaceReq(PRTTRACELOGDECODERHLP pHlp, PTPMSTATE pThis, PTPMDECODECTX pCtx)
     865{
     866    RT_NOREF(pThis);
     867
     868    TPM_DECODE_INIT();
     869        vboxTraceLogDecodeSizedBufU16(pHlp, pCtx, "Auth");
     870        TPM_DECODE_END_IF_ERROR();
     871
     872        vboxTraceLogDecodeNvPublic(pHlp, pCtx, "PublicInfo");
     873    TPM_DECODE_END();
     874}
     875
     876
     877static const char *g_apszHandlesSetPrimaryPolicyReq[] =
     878{
     879    "hAuth",
     880    NULL
     881};
     882
     883static DECLCALLBACK(void) vboxTraceLogDecodeEvtTpmDecodeSetPrimaryPolicyReq(PRTTRACELOGDECODERHLP pHlp, PTPMSTATE pThis, PTPMDECODECTX pCtx)
     884{
     885    RT_NOREF(pThis);
     886
     887    TPM_DECODE_INIT();
     888        vboxTraceLogDecodeSizedBufU16(pHlp, pCtx, "AuthPolicy");
    806889        TPM_DECODE_END_IF_ERROR();
    807890
     
    812895
    813896
    814 static const char *g_apszHandlesStartAuthSessionResp[] =
    815 {
    816     "hSession",
    817     NULL
    818 };
    819 
    820 
    821 static DECLCALLBACK(void) vboxTraceLogDecodeEvtTpmDecodeStartAuthSessionResp(PRTTRACELOGDECODERHLP pHlp, PTPMSTATE pThis, PTPMDECODECTX pCtx)
    822 {
    823     RT_NOREF(pThis);
    824 
    825     TPM_DECODE_INIT();
    826         vboxTraceLogDecodeSizedBufU16(pHlp, pCtx, "NonceTpm");
    827     TPM_DECODE_END();
    828 }
    829 
    830 
    831 static const char *g_apszHandlesHierarchyChangeAuthReq[] =
    832 {
    833     "hAuth",
    834     NULL
    835 };
    836 
    837 static DECLCALLBACK(void) vboxTraceLogDecodeEvtTpmDecodeHierarchyChangeAuthReq(PRTTRACELOGDECODERHLP pHlp, PTPMSTATE pThis, PTPMDECODECTX pCtx)
    838 {
    839     RT_NOREF(pThis);
    840 
    841     TPM_DECODE_INIT();
    842         vboxTraceLogDecodeSizedBufU16(pHlp, pCtx, "NewAuth");
    843     TPM_DECODE_END();
    844 }
    845 
    846 
    847 static const char *g_apszHandlesNvDefineSpaceReq[] =
    848 {
    849     "hAuth",
    850     NULL
    851 };
    852 
    853 static DECLCALLBACK(void) vboxTraceLogDecodeEvtTpmDecodeNvDefineSpaceReq(PRTTRACELOGDECODERHLP pHlp, PTPMSTATE pThis, PTPMDECODECTX pCtx)
    854 {
    855     RT_NOREF(pThis);
    856 
    857     TPM_DECODE_INIT();
    858         vboxTraceLogDecodeSizedBufU16(pHlp, pCtx, "Auth");
    859         TPM_DECODE_END_IF_ERROR();
    860 
    861         vboxTraceLogDecodeNvPublic(pHlp, pCtx, "PublicInfo");
    862     TPM_DECODE_END();
    863 }
    864 
    865 
    866 static const char *g_apszHandlesSetPrimaryPolicyReq[] =
    867 {
    868     "hAuth",
    869     NULL
    870 };
    871 
    872 static DECLCALLBACK(void) vboxTraceLogDecodeEvtTpmDecodeSetPrimaryPolicyReq(PRTTRACELOGDECODERHLP pHlp, PTPMSTATE pThis, PTPMDECODECTX pCtx)
    873 {
    874     RT_NOREF(pThis);
    875 
    876     TPM_DECODE_INIT();
    877         vboxTraceLogDecodeSizedBufU16(pHlp, pCtx, "AuthPolicy");
    878         TPM_DECODE_END_IF_ERROR();
    879 
    880         TPM_DECODE_U16(u16HashAlg, u16HashAlg);
    881         pHlp->pfnPrintf(pHlp, "        u16HashAlg: %s\n", vboxTraceLogDecodeEvtTpmAlgId2Str(u16HashAlg));
    882     TPM_DECODE_END();
    883 }
    884 
    885 
    886897static const char *g_apszHandlesCreatePrimaryReq[] =
    887898{
     
    961972
    962973    TPM_DECODE_INIT();
    963         TPM_DECODE_U64(u64BitsOr, u64BitsOr);
    964         pHlp->pfnPrintf(pHlp, "        u64BitsOr:  %#RX64\n", u64BitsOr);
     974        TPM_DECODE_U64_HEX(u64BitsOr, u64BitsOr);
    965975    TPM_DECODE_END();
    966976}
     
    983993
    984994        TPM_DECODE_U16(u16Offset, u16Offset);
    985         pHlp->pfnPrintf(pHlp, "        u16Offset:  %u\n", u16Offset);
    986995    TPM_DECODE_END();
    987996}
     
    10021011        TPM_DECODE_U32(u32NewRecoveryTime,  u32NewRecoveryTime);
    10031012        TPM_DECODE_U32(u32LockoutRecovery,  u32LockoutRecovery);
    1004 
    1005         pHlp->pfnPrintf(pHlp, "        u32NewMaxTries:      %u\n", u32NewMaxTries);
    1006         pHlp->pfnPrintf(pHlp, "        u32NewRecoveryTime:  %u\n", u32NewRecoveryTime);
    1007         pHlp->pfnPrintf(pHlp, "        u32LockoutRecovery:  %u\n", u32LockoutRecovery);
    10081013    TPM_DECODE_END();
    10091014}
     
    10271032        TPM_DECODE_END_IF_ERROR();
    10281033
    1029         TPM_DECODE_U16(u16SigningScheme, u16SigningScheme);
    1030         pHlp->pfnPrintf(pHlp, "        u16SigningScheme: %s\n", vboxTraceLogDecodeEvtTpmAlgId2Str(u16SigningScheme));
    1031 
     1034        TPM_DECODE_U16_ENUM(u16SigningScheme, u16SigningScheme, g_aAlgId2Str);
    10321035        vboxTraceLogDecodeTicket(pHlp, pCtx, "CreationTicket");
    10331036    TPM_DECODE_END();
     
    10431046
    10441047        /* Decode TPMT_SIGNATURE */
    1045         TPM_DECODE_U16(u16SigningAlg, u16SigningAlg);
    1046         pHlp->pfnPrintf(pHlp, "        u16SigningAlg: %s\n", vboxTraceLogDecodeEvtTpmAlgId2Str(u16SigningAlg));
    1047         TPM_DECODE_U16(u16HashAlg, u16HashAlg);
    1048         pHlp->pfnPrintf(pHlp, "        u16HashAlg:    %s\n", vboxTraceLogDecodeEvtTpmAlgId2Str(u16HashAlg));
    1049 
     1048        TPM_DECODE_U16_ENUM(u16SigningAlg, u16SigningAlg, g_aAlgId2Str);
     1049        TPM_DECODE_U16_ENUM(u16HashAlg, u16HashAlg, g_aAlgId2Str);
    10501050    TPM_DECODE_END();
    10511051}
     
    10651065    TPM_DECODE_INIT();
    10661066        TPM_DECODE_U16(u16Size,   u16Size);
    1067         pHlp->pfnPrintf(pHlp, "        u16Size:   %u\n", u16Size);
    10681067        TPM_DECODE_U16(u16Offset, u16Offset);
    1069         pHlp->pfnPrintf(pHlp, "        u16Offset: %u\n", u16Offset);
    10701068    TPM_DECODE_END();
    10711069}
     
    11021100
    11031101        TPM_DECODE_I32(i32Expiration,   i32Expiration);
    1104         pHlp->pfnPrintf(pHlp, "        i32Expiration: %u\n", i32Expiration);
    11051102    TPM_DECODE_END();
    11061103}
     
    11751172    TPM_DECODE_INIT();
    11761173        TPM_DECODE_U16(u16CurveId, u16CurveId);
    1177         pHlp->pfnPrintf(pHlp, "        u16CurveId:   %#x\n", u16CurveId);
    11781174    TPM_DECODE_END();
    11791175}
     
    11851181
    11861182    TPM_DECODE_INIT();
    1187         TPM_DECODE_U16(u16CurveId,       u16CurveId);
    1188         TPM_DECODE_U16(u16KeySize,       u16KeySize);
    1189         TPM_DECODE_U16(u16KdfScheme,     u16KdfScheme);
    1190         TPM_DECODE_U16(u16KdfSchemeHash, u16KdfSchemeHash);
    1191         TPM_DECODE_U16(u16EccScheme,     u16EccScheme);
    1192 
    1193         pHlp->pfnPrintf(pHlp, "        u16CurveId:       %#x\n", u16CurveId);
    1194         pHlp->pfnPrintf(pHlp, "        u16KeySize:       %u\n",  u16KeySize);
    1195         pHlp->pfnPrintf(pHlp, "        u16KdfScheme:     %s\n",  vboxTraceLogDecodeEvtTpmAlgId2Str(u16KdfScheme));
    1196         pHlp->pfnPrintf(pHlp, "        u16KdfSchemeHash: %s\n",  vboxTraceLogDecodeEvtTpmAlgId2Str(u16KdfSchemeHash));
    1197         pHlp->pfnPrintf(pHlp, "        u16EccScheme:     %s\n",  vboxTraceLogDecodeEvtTpmAlgId2Str(u16EccScheme));
     1183        TPM_DECODE_U16_HEX( u16CurveId,       u16CurveId);
     1184        TPM_DECODE_U16(     u16KeySize,       u16KeySize);
     1185        TPM_DECODE_U16_ENUM(u16KdfScheme,     u16KdfScheme,     g_aAlgId2Str);
     1186        TPM_DECODE_U16_ENUM(u16KdfSchemeHash, u16KdfSchemeHash, g_aAlgId2Str);
     1187        TPM_DECODE_U16_ENUM(u16EccScheme,     u16EccScheme,     g_aAlgId2Str);
    11981188        if (u16EccScheme != TPM2_ALG_NULL)
    11991189        {
    1200             TPM_DECODE_U16(u16EccSchemeHash, u16EccSchemeHash);
    1201             pHlp->pfnPrintf(pHlp, "        u16EccSchemeHash: %s\n",  vboxTraceLogDecodeEvtTpmAlgId2Str(u16EccSchemeHash));
     1190            TPM_DECODE_U16_ENUM(u16EccSchemeHash, u16EccSchemeHash, g_aAlgId2Str);
    12021191        }
    12031192        vboxTraceLogDecodeSizedBufU16(pHlp, pCtx, "p");
     
    12341223        TPM_DECODE_END_IF_ERROR();
    12351224
    1236         TPM_DECODE_U16(u16SigScheme,     u16SigScheme);
    1237         pHlp->pfnPrintf(pHlp, "        u16SigScheme:     %s\n",  vboxTraceLogDecodeEvtTpmAlgId2Str(u16SigScheme));
     1225        TPM_DECODE_U16_ENUM(u16SigScheme, u16SigScheme, g_aAlgId2Str);
    12381226        if (u16SigScheme != TPM2_ALG_NULL)
    12391227        {
    1240             TPM_DECODE_U16(u16SigSchemeHash, u16SigSchemeHash);
    1241             pHlp->pfnPrintf(pHlp, "        u16SigSchemeHash: %s\n",  vboxTraceLogDecodeEvtTpmAlgId2Str(u16SigSchemeHash));
     1228            TPM_DECODE_U16_ENUM(u16SigSchemeHash, u16SigSchemeHash, g_aAlgId2Str);
    12421229        }
    12431230
     
    12551242        TPM_DECODE_END_IF_ERROR();
    12561243
    1257         TPM_DECODE_U16(u16SigAlg,     u16SigAlg);
    1258         pHlp->pfnPrintf(pHlp, "        u16SigAlg:        %s\n",  vboxTraceLogDecodeEvtTpmAlgId2Str(u16SigAlg));
     1244        TPM_DECODE_U16_ENUM(u16SigAlg, u16SigAlg, g_aAlgId2Str);
    12591245        if (u16SigAlg != TPM2_ALG_NULL)
    12601246        {
    1261             TPM_DECODE_U16(u16SigAlgHash, u16SigAlgHash);
    1262             pHlp->pfnPrintf(pHlp, "        u16SigAlgHash:    %s\n",  vboxTraceLogDecodeEvtTpmAlgId2Str(u16SigAlgHash));
     1247            TPM_DECODE_U16_ENUM(u16SigAlgHash, u16SigAlgHash, g_aAlgId2Str);
    12631248        }
    12641249    TPM_DECODE_END();
     
    12811266        TPM_DECODE_END_IF_ERROR();
    12821267
    1283         TPM_DECODE_U16(u16HashAlg,     u16HashAlg);
    1284         pHlp->pfnPrintf(pHlp, "        u16HashAlg:     %s\n",  vboxTraceLogDecodeEvtTpmAlgId2Str(u16HashAlg));
     1268        TPM_DECODE_U16_ENUM(u16HashAlg, u16HashAlg, g_aAlgId2Str);
    12851269    TPM_DECODE_END();
    12861270}
     
    15081492            if (s_aTpmCmdCodes[i].u32CmdCode == u32CmdCode)
    15091493            {
    1510                 pHlp->pfnPrintf(pHlp, "    %s (%u bytes):\n", s_aTpmCmdCodes[i].pszCmdCode, cbReqPayload);
    1511                 pHlp->pfnPrintf(pHlp, "    u16Tag:      %#x\n", u16Tag);
    1512 
     1494                pHlp->pfnStructBldBegin(pHlp, "Command");
     1495                pHlp->pfnStructBldAddStr(pHlp, "CmdCode",     0 /*fFlags*/, s_aTpmCmdCodes[i].pszCmdCode);
     1496                pHlp->pfnStructBldAddU32(pHlp, "PayloadSize", 0 /*fFlags*/, cbReqPayload);
     1497                pHlp->pfnStructBldAddU16(pHlp, "u16Tag",      RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_HEX, u16Tag);
    15131498
    15141499                TPMDECODECTX Ctx;
     
    15191504                if (s_aTpmCmdCodes[i].papszHandlesReq)
    15201505                {
    1521                     pHlp->pfnPrintf(pHlp, "    Handles:\n");
     1506                    pHlp->pfnStructBldBegin(pHlp, "Handles");
    15221507
    15231508                    const char **papszHnd = s_aTpmCmdCodes[i].papszHandlesReq;
    15241509                    while (*papszHnd)
    15251510                    {
    1526                         TPM_DECODE_U32(u32Hnd, u32Hnd);
    1527                         pHlp->pfnPrintf(pHlp, "       %s: %#x\n", *papszHnd, u32Hnd);
     1511                        TPM_DECODE_U32_HEX_STR(u32Hnd, *papszHnd);
    15281512                        papszHnd++;
    15291513                    }
     1514
     1515                    pHlp->pfnStructBldEnd(pHlp);
    15301516                }
    15311517
    15321518                /* Decode authorization area if available. */
    15331519                if (u16Tag == TPM2_ST_SESSIONS)
    1534                 {
    1535                     pHlp->pfnPrintf(pHlp, "    Authorization Area:\n");
    15361520                    vboxTraceLogDecodeEvtTpmAuthSessionReq(pHlp, pCtx);
    1537                 }
    15381521
    15391522                /* Decode parameters. */
    15401523                if (s_aTpmCmdCodes[i].pfnDecodeReq)
    15411524                {
    1542                     pHlp->pfnPrintf(pHlp, "    Parameters:\n");
     1525                    pHlp->pfnStructBldBegin(pHlp, "Parameters");
    15431526                    s_aTpmCmdCodes[i].pfnDecodeReq(pHlp, pTpmState, &Ctx);
     1527                    pHlp->pfnStructBldEnd(pHlp);
    15441528                }
    15451529
     
    15471531                    pHlp->pfnPrintf(pHlp, "    Leftover undecoded data:\n"
    15481532                                          "%.*Rhxd\n", pCtx->cbLeft, pCtx->pbBuf);
     1533
     1534                pHlp->pfnStructBldEnd(pHlp);
    15491535                return;
    15501536            }
     
    15711557        uint16_t u16Tag        = RT_BE2H_U16(pHdr->u16Tag);
    15721558
    1573         pHlp->pfnPrintf(pHlp, "    Status code: %#x (%u bytes)\n", u32ErrCode, cbRespPayload);
    1574         pHlp->pfnPrintf(pHlp, "    u16Tag:      %#x\n", u16Tag);
     1559        pHlp->pfnStructBldBegin(pHlp, "Response");
     1560
     1561        pHlp->pfnStructBldAddU16(pHlp, "u16Tag", RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_HEX, u16Tag);
     1562        pHlp->pfnStructBldAddU32(pHlp, "u32ErrCode", 0 /*fFlags*/, u32ErrCode);
     1563        pHlp->pfnStructBldAddU32(pHlp, "cbResponse", 0 /*fFlags*/, cbRespPayload);
     1564
    15751565        PTPMSTATE pTpmState = (PTPMSTATE)pHlp->pfnDecoderStateGet(pHlp);
    15761566
     
    15901580                    if (s_aTpmCmdCodes[i].papszHandlesResp)
    15911581                    {
    1592                         pHlp->pfnPrintf(pHlp, "    Handles:\n");
     1582                        pHlp->pfnStructBldBegin(pHlp, "Handles");
    15931583
    15941584                        const char **papszHnd = s_aTpmCmdCodes[i].papszHandlesResp;
    15951585                        while (*papszHnd)
    15961586                        {
    1597                             TPM_DECODE_U32(u32Hnd, u32Hnd);
    1598                             pHlp->pfnPrintf(pHlp, "       %s: %#x\n", *papszHnd, u32Hnd);
     1587                            TPM_DECODE_U32_HEX_STR(u32Hnd, *papszHnd);
    15991588                            papszHnd++;
    16001589                        }
     1590
     1591                        pHlp->pfnStructBldEnd(pHlp);
    16011592                    }
    16021593
     
    16051596                        TPM_DECODE_INIT();
    16061597                            TPM_DECODE_U32(u32ParamSz, u32ParamSize);
    1607                             pHlp->pfnPrintf(pHlp, "    u32ParamSize: %#x\n", u32ParamSz);
    16081598                        TPM_DECODE_END();
    16091599                    }
     
    16111601                    /* Decode parameters. */
    16121602                    if (s_aTpmCmdCodes[i].pfnDecodeResp)
     1603                    {
     1604                        pHlp->pfnStructBldBegin(pHlp, "Parameters");
    16131605                        s_aTpmCmdCodes[i].pfnDecodeResp(pHlp, pTpmState, pCtx);
     1606                        pHlp->pfnStructBldEnd(pHlp);
     1607                    }
    16141608
    16151609                    /* Decode authorization area if available. */
    16161610                    if (u16Tag == TPM2_ST_SESSIONS)
    1617                     {
    1618                         pHlp->pfnPrintf(pHlp, "    Authorization Area:\n");
    16191611                        vboxTraceLogDecodeEvtTpmAuthSessionResp(pHlp, pCtx);
    1620                     }
    16211612
    16221613                    if (pCtx->cbLeft)
    1623                         pHlp->pfnPrintf(pHlp, "    Leftover undecoded data:\n"
    1624                                               "%.*Rhxd\n", pCtx->cbLeft, pCtx->pbBuf);
    1625 
     1614                        pHlp->pfnStructBldAddBuf(pHlp, "Leftover undecoded data", 0 /*fFlags*/, pCtx->pbBuf, pCtx->cbLeft);
     1615                    pHlp->pfnStructBldEnd(pHlp);
    16261616                    return;
    16271617                }
     
    16301620
    16311621        if (cbRespPayload)
    1632             pHlp->pfnPrintf(pHlp, "%.*Rhxd\n", cbRespPayload, pHdr + 1);
     1622            pHlp->pfnStructBldAddBuf(pHlp, "Data", 0 /*fFlags*/, (const uint8_t *)(pHdr + 1), cbRespPayload);
     1623
     1624        pHlp->pfnStructBldEnd(pHlp);
    16331625    }
    16341626    else
  • trunk/src/VBox/Runtime/tools/RTTraceLogTool.cpp

    r104923 r104966  
    6565    /** The free callback of any attached decoder state. */
    6666    PFNTRACELOGDECODERSTATEFREE pfnDecoderStateFree;
     67    /** Current struct nesting level. */
     68    uint32_t                    cStructNesting;
     69    /** Current array level nesting. */
     70    uint32_t                    cArrayNesting;
    6771} RTTRACELOGDECODER;
    6872typedef RTTRACELOGDECODER *PRTTRACELOGDECODER;
     
    277281
    278282
     283static DECLCALLBACK(int) rtTraceLogToolDecoderHlpStructBldBegin(PRTTRACELOGDECODERHLP pHlp, const char *pszName)
     284{
     285    PRTTRACELOGDECODER pDecoder = RT_FROM_MEMBER(pHlp, RTTRACELOGDECODER, Hlp);
     286
     287    RTPrintf("%*s%s:\n", pDecoder->cStructNesting * 4, "", pszName);
     288    pDecoder->cStructNesting++;
     289    return VINF_SUCCESS;
     290}
     291
     292
     293static DECLCALLBACK(int) rtTraceLogToolDecoderHlpStructBldEnd(PRTTRACELOGDECODERHLP pHlp)
     294{
     295    PRTTRACELOGDECODER pDecoder = RT_FROM_MEMBER(pHlp, RTTRACELOGDECODER, Hlp);
     296
     297    pDecoder->cStructNesting--;
     298    return VINF_SUCCESS;
     299}
     300
     301
     302static DECLCALLBACK(int) rtTraceLogToolDecoderHlpStructBldAddBool(PRTTRACELOGDECODERHLP pHlp, const char *pszName, uint32_t fFlags, bool f)
     303{
     304    PRTTRACELOGDECODER pDecoder = RT_FROM_MEMBER(pHlp, RTTRACELOGDECODER, Hlp);
     305
     306    RT_NOREF(fFlags);
     307    RTPrintf("%*s%-16s %32RTbool\n", pDecoder->cStructNesting * 4, "", pszName, f);
     308    return VINF_SUCCESS;
     309}
     310
     311
     312static DECLCALLBACK(int) rtTraceLogToolDecoderHlpStructBldAddU8(PRTTRACELOGDECODERHLP pHlp, const char *pszName, uint32_t fFlags, uint8_t u8)
     313{
     314    PRTTRACELOGDECODER pDecoder = RT_FROM_MEMBER(pHlp, RTTRACELOGDECODER, Hlp);
     315
     316    if (pszName)
     317    {
     318        if (fFlags & RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_HEX)
     319            RTPrintf("%*s%-16s %#32RX8\n", pDecoder->cStructNesting * 4, "", pszName, u8);
     320        else
     321            RTPrintf("%*s%-16s %32RU8\n", pDecoder->cStructNesting * 4, "", pszName, u8);
     322    }
     323    else
     324    {
     325        Assert(pDecoder->cArrayNesting > 0);
     326        if (fFlags & RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_HEX)
     327            RTPrintf(" %#02RX8", u8);
     328        else
     329            RTPrintf(" %02RU8", u8);
     330    }
     331    return VINF_SUCCESS;
     332}
     333
     334
     335static DECLCALLBACK(int) rtTraceLogToolDecoderHlpStructBldAddU16(PRTTRACELOGDECODERHLP pHlp, const char *pszName, uint32_t fFlags, uint16_t u16)
     336{
     337    PRTTRACELOGDECODER pDecoder = RT_FROM_MEMBER(pHlp, RTTRACELOGDECODER, Hlp);
     338
     339    if (fFlags & RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_HEX)
     340        RTPrintf("%*s%-16s %#32RX16\n", pDecoder->cStructNesting * 4, "", pszName, u16);
     341    else
     342        RTPrintf("%*s%-16s %32RU16\n", pDecoder->cStructNesting * 4, "", pszName, u16);
     343    return VINF_SUCCESS;
     344}
     345
     346
     347static DECLCALLBACK(int) rtTraceLogToolDecoderHlpStructBldAddU32(PRTTRACELOGDECODERHLP pHlp, const char *pszName, uint32_t fFlags, uint32_t u32)
     348{
     349    PRTTRACELOGDECODER pDecoder = RT_FROM_MEMBER(pHlp, RTTRACELOGDECODER, Hlp);
     350
     351    if (fFlags & RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_HEX)
     352        RTPrintf("%*s%-16s %#32RX32\n", pDecoder->cStructNesting * 4, "", pszName, u32);
     353    else
     354        RTPrintf("%*s%-16s %32RU32\n", pDecoder->cStructNesting * 4, "", pszName, u32);
     355    return VINF_SUCCESS;
     356}
     357
     358
     359static DECLCALLBACK(int) rtTraceLogToolDecoderHlpStructBldAddU64(PRTTRACELOGDECODERHLP pHlp, const char *pszName, uint32_t fFlags, uint64_t u64)
     360{
     361    PRTTRACELOGDECODER pDecoder = RT_FROM_MEMBER(pHlp, RTTRACELOGDECODER, Hlp);
     362
     363    if (fFlags & RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_HEX)
     364        RTPrintf("%*s%-16s %#32RX64\n", pDecoder->cStructNesting * 4, "", pszName, u64);
     365    else
     366        RTPrintf("%*s%-16s %32RU64\n", pDecoder->cStructNesting * 4, "", pszName, u64);
     367    return VINF_SUCCESS;
     368}
     369
     370
     371static DECLCALLBACK(int) rtTraceLogToolDecoderHlpStructBldAddS8(PRTTRACELOGDECODERHLP pHlp, const char *pszName, uint32_t fFlags, int8_t i8)
     372{
     373    PRTTRACELOGDECODER pDecoder = RT_FROM_MEMBER(pHlp, RTTRACELOGDECODER, Hlp);
     374
     375    if (fFlags & RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_HEX)
     376        RTPrintf("%*s%-16s %#32RX8\n", pDecoder->cStructNesting * 4, "", pszName, i8);
     377    else
     378        RTPrintf("%*s%-16s %32RI8\n", pDecoder->cStructNesting * 4, "", pszName, i8);
     379    return VINF_SUCCESS;
     380}
     381
     382
     383static DECLCALLBACK(int) rtTraceLogToolDecoderHlpStructBldAddS16(PRTTRACELOGDECODERHLP pHlp, const char *pszName, uint32_t fFlags, int16_t i16)
     384{
     385    PRTTRACELOGDECODER pDecoder = RT_FROM_MEMBER(pHlp, RTTRACELOGDECODER, Hlp);
     386
     387    if (fFlags & RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_HEX)
     388        RTPrintf("%*s%-16s %#32RX16\n", pDecoder->cStructNesting * 4, "", pszName, i16);
     389    else
     390        RTPrintf("%*s%-16s %32RI16\n", pDecoder->cStructNesting * 4, "", pszName, i16);
     391    return VINF_SUCCESS;
     392}
     393
     394
     395static DECLCALLBACK(int) rtTraceLogToolDecoderHlpStructBldAddS32(PRTTRACELOGDECODERHLP pHlp, const char *pszName, uint32_t fFlags, int32_t i32)
     396{
     397    PRTTRACELOGDECODER pDecoder = RT_FROM_MEMBER(pHlp, RTTRACELOGDECODER, Hlp);
     398
     399    if (fFlags & RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_HEX)
     400        RTPrintf("%*s%-16s %#RX32\n", pDecoder->cStructNesting * 4, "", pszName, i32);
     401    else
     402        RTPrintf("%*s%-16s %RI32\n", pDecoder->cStructNesting * 4, "", pszName, i32);
     403    return VINF_SUCCESS;
     404}
     405
     406
     407static DECLCALLBACK(int) rtTraceLogToolDecoderHlpStructBldAddS64(PRTTRACELOGDECODERHLP pHlp, const char *pszName, uint32_t fFlags, int64_t i64)
     408{
     409    PRTTRACELOGDECODER pDecoder = RT_FROM_MEMBER(pHlp, RTTRACELOGDECODER, Hlp);
     410
     411    if (fFlags & RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_HEX)
     412        RTPrintf("%*s%-16s %#RX64\n", pDecoder->cStructNesting * 4, "", pszName, i64);
     413    else
     414        RTPrintf("%*s%-16s %RI64\n", pDecoder->cStructNesting * 4, "", pszName, i64);
     415    return VINF_SUCCESS;
     416}
     417
     418
     419static DECLCALLBACK(int) rtTraceLogToolDecoderHlpStructBldAddStr(PRTTRACELOGDECODERHLP pHlp, const char *pszName, uint32_t fFlags, const char *pszStr)
     420{
     421    PRTTRACELOGDECODER pDecoder = RT_FROM_MEMBER(pHlp, RTTRACELOGDECODER, Hlp);
     422
     423    RT_NOREF(fFlags);
     424    RTPrintf("%*s%-16s %32s\n", pDecoder->cStructNesting * 4, "", pszName, pszStr);
     425    return VINF_SUCCESS;
     426}
     427
     428
     429static DECLCALLBACK(int) rtTraceLogToolDecoderHlpStructBldAddBuf(PRTTRACELOGDECODERHLP pHlp, const char *pszName, uint32_t fFlags, const uint8_t *pb, size_t cb)
     430{
     431    PRTTRACELOGDECODER pDecoder = RT_FROM_MEMBER(pHlp, RTTRACELOGDECODER, Hlp);
     432
     433    if (fFlags & RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_HEX_DUMP_STR)
     434        RTPrintf("%*s%-16s %.*Rhxs\n", pDecoder->cStructNesting * 4, "", pszName, cb, pb);
     435    else
     436        RTPrintf("%*s%-16s\n"
     437                 "%.*Rhxd\n", pDecoder->cStructNesting * 4, "", pszName, cb, pb);
     438    return VINF_SUCCESS;
     439}
     440
     441
     442static DECLCALLBACK(int) rtTraceLogToolDecoderHlpStructBldAddEnum(PRTTRACELOGDECODERHLP pHlp, const char *pszName, uint32_t fFlags, uint8_t cBits,
     443                                                                  PCRTTRACELOGDECODERSTRUCTBLDENUM paEnums, uint64_t u64Val)
     444{
     445    PRTTRACELOGDECODER pDecoder = RT_FROM_MEMBER(pHlp, RTTRACELOGDECODER, Hlp);
     446
     447    const char *pszEnum = "<UNKNOWN>";
     448    while (paEnums->pszString)
     449    {
     450        if (paEnums->u64EnumVal == u64Val)
     451        {
     452            pszEnum = paEnums->pszString;
     453            break;
     454        }
     455        paEnums++;
     456    }
     457
     458    RT_NOREF(cBits);
     459    if (fFlags & RTTRACELOG_DECODER_HLP_STRUCT_BLD_F_HEX)
     460        RTPrintf("%*s%-16s 0x%0*RX64 (%s)\n", pDecoder->cStructNesting * 4, "", pszName, cBits / 4, u64Val, pszEnum);
     461    else
     462        RTPrintf("%*s%-16s %RU64 (%s)\n", pDecoder->cStructNesting * 4, "", pszName, u64Val, pszEnum);
     463    return VINF_SUCCESS;
     464}
     465
     466
     467static DECLCALLBACK(int) rtTraceLogToolDecoderHlpStructBldArrayBegin(PRTTRACELOGDECODERHLP pHlp, const char *pszName)
     468{
     469    PRTTRACELOGDECODER pDecoder = RT_FROM_MEMBER(pHlp, RTTRACELOGDECODER, Hlp);
     470
     471    RTPrintf("%*s%-16s [", pDecoder->cStructNesting * 4, "", pszName);
     472    Assert(!pDecoder->cArrayNesting);
     473    pDecoder->cArrayNesting++;
     474    return VINF_SUCCESS;
     475}
     476
     477
     478static DECLCALLBACK(int) rtTraceLogToolDecoderHlpStructBldArrayEnd(PRTTRACELOGDECODERHLP pHlp)
     479{
     480    PRTTRACELOGDECODER pDecoder = RT_FROM_MEMBER(pHlp, RTTRACELOGDECODER, Hlp);
     481    RTPrintf(" ]\n");
     482    Assert(pDecoder->cArrayNesting > 0);
     483    pDecoder->cArrayNesting--;
     484    return VINF_SUCCESS;
     485}
     486
     487
    279488static DECLCALLBACK(int) rtTraceLogToolRegisterDecoders(void *pvUser, PCRTTRACELOGDECODERREG paDecoders, uint32_t cDecoders)
    280489{
     
    299508        pDecoder->pvDecoderState             = NULL;
    300509        pDecoder->pfnDecoderStateFree        = NULL;
     510        pDecoder->cStructNesting             = 0;
     511        pDecoder->cArrayNesting              = 0;
    301512        pDecoder->Hlp.pfnPrintf              = rtTraceLogToolDecoderHlpPrintf;
    302513        pDecoder->Hlp.pfnErrorMsg            = rtTraceLogToolDecoderHlpErrorMsg;
     
    304515        pDecoder->Hlp.pfnDecoderStateDestroy = rtTraceLogToolDecoderHlpStateDestroy;
    305516        pDecoder->Hlp.pfnDecoderStateGet     = rtTraceLogToolDecoderHlpStateGet;
     517        pDecoder->Hlp.pfnStructBldBegin      = rtTraceLogToolDecoderHlpStructBldBegin;
     518        pDecoder->Hlp.pfnStructBldEnd        = rtTraceLogToolDecoderHlpStructBldEnd;
     519        pDecoder->Hlp.pfnStructBldAddBool    = rtTraceLogToolDecoderHlpStructBldAddBool;
     520        pDecoder->Hlp.pfnStructBldAddU8      = rtTraceLogToolDecoderHlpStructBldAddU8;
     521        pDecoder->Hlp.pfnStructBldAddU16     = rtTraceLogToolDecoderHlpStructBldAddU16;
     522        pDecoder->Hlp.pfnStructBldAddU32     = rtTraceLogToolDecoderHlpStructBldAddU32;
     523        pDecoder->Hlp.pfnStructBldAddU64     = rtTraceLogToolDecoderHlpStructBldAddU64;
     524        pDecoder->Hlp.pfnStructBldAddS8      = rtTraceLogToolDecoderHlpStructBldAddS8;
     525        pDecoder->Hlp.pfnStructBldAddS16     = rtTraceLogToolDecoderHlpStructBldAddS16;
     526        pDecoder->Hlp.pfnStructBldAddS32     = rtTraceLogToolDecoderHlpStructBldAddS32;
     527        pDecoder->Hlp.pfnStructBldAddS64     = rtTraceLogToolDecoderHlpStructBldAddS64;
     528        pDecoder->Hlp.pfnStructBldAddStr     = rtTraceLogToolDecoderHlpStructBldAddStr;
     529        pDecoder->Hlp.pfnStructBldAddBuf     = rtTraceLogToolDecoderHlpStructBldAddBuf;
     530        pDecoder->Hlp.pfnStructBldAddEnum    = rtTraceLogToolDecoderHlpStructBldAddEnum;
     531        pDecoder->Hlp.pfnStructBldArrayBegin = rtTraceLogToolDecoderHlpStructBldArrayBegin;
     532        pDecoder->Hlp.pfnStructBldArrayEnd   = rtTraceLogToolDecoderHlpStructBldArrayEnd;
    306533    }
    307534
     
    470697                                    || cVals != pEvtDesc->cEvtItems)
    471698                                {
     699                                    pDecoder->cStructNesting = 0;
     700                                    pDecoder->cArrayNesting  = 0;
    472701                                    rc = pDecoder->pReg->pfnDecode(&pDecoder->Hlp, pDecodeEvt->idDecodeEvt, hTraceLogEvt,
    473702                                                                   pEvtDesc, &aVals[0], cVals);
Note: See TracChangeset for help on using the changeset viewer.

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