VirtualBox

Changeset 73460 in vbox for trunk/include/iprt


Ignore:
Timestamp:
Aug 2, 2018 9:06:59 PM (6 years ago)
Author:
vboxsync
Message:

IPRT,DBGF,Diggers: Moved DBGFRETURNTYPE and the unwind state structure to IPRT (dbg.h) in prep for debug module interface and more. Added stack unwind assist callback for the OS diggers so they can identify special stack frames and supply more info via the sure-register-value array and frame flags. Identify and decode NT/AMD64 trap frames.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/dbg.h

    r73375 r73460  
    107107/** Pointer to a const debug module segment. */
    108108typedef RTDBGSEGMENT const *PCRTDBGSEGMENT;
     109
     110
     111/**
     112 * Return type.
     113 */
     114typedef enum RTDBGRETURNTYPE
     115{
     116    /** The usual invalid 0 value. */
     117    RTDBGRETURNTYPE_INVALID = 0,
     118    /** Near 16-bit return. */
     119    RTDBGRETURNTYPE_NEAR16,
     120    /** Near 32-bit return. */
     121    RTDBGRETURNTYPE_NEAR32,
     122    /** Near 64-bit return. */
     123    RTDBGRETURNTYPE_NEAR64,
     124    /** Far 16:16 return. */
     125    RTDBGRETURNTYPE_FAR16,
     126    /** Far 16:32 return. */
     127    RTDBGRETURNTYPE_FAR32,
     128    /** Far 16:64 return. */
     129    RTDBGRETURNTYPE_FAR64,
     130    /** 16-bit iret return (e.g. real or 286 protect mode). */
     131    RTDBGRETURNTYPE_IRET16,
     132    /** 32-bit iret return. */
     133    RTDBGRETURNTYPE_IRET32,
     134    /** 32-bit iret return. */
     135    RTDBGRETURNTYPE_IRET32_PRIV,
     136    /** 32-bit iret return to V86 mode. */
     137    RTDBGRETURNTYPE_IRET32_V86,
     138    /** @todo 64-bit iret return. */
     139    RTDBGRETURNTYPE_IRET64,
     140    /** The end of the valid return types. */
     141    RTDBGRETURNTYPE_END,
     142    /** The usual 32-bit blowup. */
     143    RTDBGRETURNTYPE_32BIT_HACK = 0x7fffffff
     144} RTDBGRETURNTYPE;
     145
     146/**
     147 * Figures the size of the return state on the stack.
     148 *
     149 * @returns number of bytes. 0 if invalid parameter.
     150 * @param   enmRetType  The type of return.
     151 */
     152DECLINLINE(unsigned) RTDbgReturnTypeSize(RTDBGRETURNTYPE enmRetType)
     153{
     154    switch (enmRetType)
     155    {
     156        case RTDBGRETURNTYPE_NEAR16:         return 2;
     157        case RTDBGRETURNTYPE_NEAR32:         return 4;
     158        case RTDBGRETURNTYPE_NEAR64:         return 8;
     159        case RTDBGRETURNTYPE_FAR16:          return 4;
     160        case RTDBGRETURNTYPE_FAR32:          return 4;
     161        case RTDBGRETURNTYPE_FAR64:          return 8;
     162        case RTDBGRETURNTYPE_IRET16:         return 6;
     163        case RTDBGRETURNTYPE_IRET32:         return 4*3;
     164        case RTDBGRETURNTYPE_IRET32_PRIV:    return 4*5;
     165        case RTDBGRETURNTYPE_IRET32_V86:     return 4*9;
     166        case RTDBGRETURNTYPE_IRET64:         return 5*8;
     167
     168        case RTDBGRETURNTYPE_INVALID:
     169        case RTDBGRETURNTYPE_END:
     170        case RTDBGRETURNTYPE_32BIT_HACK:
     171            break;
     172    }
     173    return 0;
     174}
     175
     176/**
     177 * Check if near return.
     178 *
     179 * @returns true if near, false if far or iret.
     180 * @param   enmRetType  The type of return.
     181 */
     182DECLINLINE(bool) RTDbgReturnTypeIsNear(RTDBGRETURNTYPE enmRetType)
     183{
     184    return enmRetType == RTDBGRETURNTYPE_NEAR32
     185        || enmRetType == RTDBGRETURNTYPE_NEAR64
     186        || enmRetType == RTDBGRETURNTYPE_NEAR16;
     187}
     188
     189
     190
     191/** Magic value for RTDBGUNWINDSTATE::u32Magic (James Moody). */
     192#define RTDBGUNWINDSTATE_MAGIC          UINT32_C(0x19250326)
     193/** Magic value for RTDBGUNWINDSTATE::u32Magic after use. */
     194#define RTDBGUNWINDSTATE_MAGIC_DEAD     UINT32_C(0x20101209)
     195
     196/**
     197 * Unwind machine state.
     198 */
     199typedef struct RTDBGUNWINDSTATE
     200{
     201    /** Structure magic (RTDBGUNWINDSTATE_MAGIC) */
     202    uint32_t            u32Magic;
     203    /** The state architecture. */
     204    RTLDRARCH           enmArch;
     205
     206    /** The program counter register.
     207     * amd64/x86: RIP/EIP/IP
     208     * sparc: PC
     209     * arm32: PC / R15
     210     */
     211    uint64_t            uPc;
     212
     213    /** Return type. */
     214    RTDBGRETURNTYPE     enmRetType;
     215
     216    /** Register state (see enmArch). */
     217    union
     218    {
     219        /** RTLDRARCH_AMD64, RTLDRARCH_X86_32 and RTLDRARCH_X86_16. */
     220        struct
     221        {
     222            /** General purpose registers indexed by X86_GREG_XXX. */
     223            uint64_t    auRegs[16];
     224            /** The frame address. */
     225            RTFAR64     FrameAddr;
     226            /** Set if we're in real or virtual 8086 mode. */
     227            bool        fRealOrV86;
     228            /** The flags register. */
     229            uint64_t    uRFlags;
     230            /** Trap error code. */
     231            uint64_t    uErrCd;
     232            /** Segment registers (indexed by X86_SREG_XXX). */
     233            uint16_t    auSegs[6];
     234
     235            /** Bitmap tracking register we've loaded and which content can possibly be trusted. */
     236            union
     237            {
     238                /** For effective clearing of the bits. */
     239                uint32_t    fAll;
     240                /** Detailed view. */
     241                struct
     242                {
     243                    /** Bitmap indicating whether a GPR was loaded (parallel to auRegs). */
     244                    uint16_t    fRegs;
     245                    /** Bitmap indicating whether a segment register was loaded (parallel to auSegs). */
     246                    uint8_t     fSegs;
     247                    /** Set if uPc was loaded. */
     248                    uint8_t     fPc : 1;
     249                    /** Set if FrameAddr was loaded. */
     250                    uint8_t     fFrameAddr : 1;
     251                    /** Set if uRFlags was loaded. */
     252                    uint8_t     fRFlags : 1;
     253                    /** Set if uErrCd was loaded. */
     254                    uint8_t     fErrCd : 1;
     255                } s;
     256            } Loaded;
     257        } x86;
     258
     259        /** @todo add ARM and others as needed. */
     260    } u;
     261
     262    /**
     263     * Stack read callback.
     264     *
     265     * @returns IPRT status code.
     266     * @param   pThis       Pointer to this structure.
     267     * @param   uSp         The stack pointer address.
     268     * @param   cbToRead    The number of bytes to read.
     269     * @param   pvDst       Where to put the bytes we read.
     270     */
     271    DECLCALLBACKMEMBER(int, pfnReadStack)(struct RTDBGUNWINDSTATE *pThis, RTUINTPTR uSp, size_t cbToRead, void *pvDst);
     272    /** User argument (usefule for pfnReadStack). */
     273    void               *pvUser;
     274
     275} RTDBGUNWINDSTATE;
     276/** Pointer to an unwind machine state. */
     277typedef struct RTDBGUNWINDSTATE *PRTDBGUNWINDSTATE;
     278/** Pointer to a const unwind machine state. */
     279typedef struct RTDBGUNWINDSTATE const *PCRTDBGUNWINDSTATE;
    109280
    110281
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