VirtualBox

Changeset 85367 in vbox for trunk/src/VBox/Debugger


Ignore:
Timestamp:
Jul 17, 2020 8:50:59 AM (5 years ago)
Author:
vboxsync
Message:

Debugger/GDBStub: Support 32bit mode as well

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Debugger/DBGCGdbRemoteStub.cpp

    r85177 r85367  
    9696    GDBSTUBRECVSTATE_32BIT_HACK = 0x7fffffff
    9797} GDBSTUBRECVSTATE;
     98
     99
     100/**
     101 * GDB target register descriptor.
     102 */
     103typedef struct GDBREGDESC
     104{
     105    /** Register name. */
     106    const char                  *pszName;
     107    /** DBGF register index. */
     108    DBGFREG                     enmReg;
     109    /** Bitsize */
     110    uint32_t                    cBits;
     111    /** Type. */
     112    const char                  *pszType;
     113    /** Group. */
     114    const char                  *pszGroup;
     115} GDBREGDESC;
     116/** Pointer to a GDB target register descriptor. */
     117typedef GDBREGDESC *PGDBREGDESC;
     118/** Pointer to a const GDB target register descriptor. */
     119typedef const GDBREGDESC *PCGDBREGDESC;
    98120
    99121
     
    145167    /** Size of the XML target description. */
    146168    size_t                      cbTgtXmlDesc;
     169    /** Pointer to the selected GDB register set. */
     170    PCGDBREGDESC                paRegs;
     171    /** Number of entries in the register set. */
     172    uint32_t                    cRegs;
    147173    /** Flag whether the stub is in extended mode. */
    148174    bool                        fExtendedMode;
     
    726752            cbThisVal = pbDelim - pbVal;
    727753
    728         size_t cchArch = sizeof("i386:x86-64") - 1;
    729         if (!memcmp(pbVal, "i386:x86-64", RT_MIN(cbVal, cchArch)))
     754        const size_t cchArch64 = sizeof("i386:x86-64") - 1;
     755        const size_t cchArch32 = sizeof("i386") - 1;
     756        if (   !memcmp(pbVal, "i386:x86-64", RT_MIN(cbVal, cchArch64))
     757            || !memcmp(pbVal, "i386", RT_MIN(cbVal, cchArch32)))
    730758        {
    731759            /* Set the flag to support the qXfer:features:read packet. */
     
    9771005
    9781006
    979 /**
    980  * GDB registers.
    981  */
    982 static const struct GDBREGDESC
    983 {
    984     /** Register name. */
    985     const char                  *pszName;
    986     /** DBGF register index. */
    987     DBGFREG                     enmReg;
    988     /** Bitsize */
    989     uint32_t                    cBits;
    990     /** Type. */
    991     const char                  *pszType;
    992     /** Group. */
    993     const char                  *pszGroup;
    994 } g_aGdbRegs[] =
    995 {
    9961007#define DBGREG_DESC_INIT_INT64(a_Name, a_enmDbgfReg)    { a_Name, a_enmDbgfReg, 64, "int64",    NULL }
    9971008#define DBGREG_DESC_INIT_INT32(a_Name, a_enmDbgfReg)    { a_Name, a_enmDbgfReg, 32, "int32",    NULL }
    998 #define DBGREG_DESC_INIT_DATA_PTR(a_Name, a_enmDbgfReg) { a_Name, a_enmDbgfReg, 64, "data_ptr", NULL }
    999 #define DBGREG_DESC_INIT_CODE_PTR(a_Name, a_enmDbgfReg) { a_Name, a_enmDbgfReg, 64, "code_ptr", NULL }
     1009#define DBGREG_DESC_INIT_DATA_PTR64(a_Name, a_enmDbgfReg) { a_Name, a_enmDbgfReg, 64, "data_ptr", NULL }
     1010#define DBGREG_DESC_INIT_CODE_PTR64(a_Name, a_enmDbgfReg) { a_Name, a_enmDbgfReg, 64, "code_ptr", NULL }
     1011#define DBGREG_DESC_INIT_DATA_PTR32(a_Name, a_enmDbgfReg) { a_Name, a_enmDbgfReg, 32, "data_ptr", NULL }
     1012#define DBGREG_DESC_INIT_CODE_PTR32(a_Name, a_enmDbgfReg) { a_Name, a_enmDbgfReg, 32, "code_ptr", NULL }
    10001013#define DBGREG_DESC_INIT_X87(a_Name, a_enmDbgfReg)      { a_Name, a_enmDbgfReg, 80, "i387_ext", NULL }
    10011014#define DBGREG_DESC_INIT_X87_CTRL(a_Name, a_enmDbgfReg) { a_Name, a_enmDbgfReg, 32, "int",      "float" }
    1002     DBGREG_DESC_INIT_INT64(   "rax",    DBGFREG_RAX),
    1003     DBGREG_DESC_INIT_INT64(   "rbx",    DBGFREG_RBX),
    1004     DBGREG_DESC_INIT_INT64(   "rcx",    DBGFREG_RCX),
    1005     DBGREG_DESC_INIT_INT64(   "rdx",    DBGFREG_RDX),
    1006     DBGREG_DESC_INIT_INT64(   "rsi",    DBGFREG_RSI),
    1007     DBGREG_DESC_INIT_INT64(   "rdi",    DBGFREG_RDI),
    1008     DBGREG_DESC_INIT_DATA_PTR("rbp",    DBGFREG_RBP),
    1009     DBGREG_DESC_INIT_DATA_PTR("rsp",    DBGFREG_RSP),
    1010     DBGREG_DESC_INIT_INT64(   "r8",     DBGFREG_R8),
    1011     DBGREG_DESC_INIT_INT64(   "r9",     DBGFREG_R9),
    1012     DBGREG_DESC_INIT_INT64(   "r10",    DBGFREG_R10),
    1013     DBGREG_DESC_INIT_INT64(   "r11",    DBGFREG_R11),
    1014     DBGREG_DESC_INIT_INT64(   "r12",    DBGFREG_R12),
    1015     DBGREG_DESC_INIT_INT64(   "r13",    DBGFREG_R13),
    1016     DBGREG_DESC_INIT_INT64(   "r14",    DBGFREG_R14),
    1017     DBGREG_DESC_INIT_INT64(   "r15",    DBGFREG_R15),
    1018     DBGREG_DESC_INIT_CODE_PTR("rip",    DBGFREG_RIP),
    1019     DBGREG_DESC_INIT_INT32(   "eflags", DBGFREG_FLAGS),
    1020     DBGREG_DESC_INIT_INT32(   "cs",     DBGFREG_CS),
    1021     DBGREG_DESC_INIT_INT32(   "ss",     DBGFREG_SS),
    1022     DBGREG_DESC_INIT_INT32(   "ds",     DBGFREG_DS),
    1023     DBGREG_DESC_INIT_INT32(   "es",     DBGFREG_ES),
    1024     DBGREG_DESC_INIT_INT32(   "fs",     DBGFREG_FS),
    1025     DBGREG_DESC_INIT_INT32(   "gs",     DBGFREG_GS),
    1026 
    1027     DBGREG_DESC_INIT_X87(     "st0",    DBGFREG_ST0),
    1028     DBGREG_DESC_INIT_X87(     "st1",    DBGFREG_ST1),
    1029     DBGREG_DESC_INIT_X87(     "st2",    DBGFREG_ST2),
    1030     DBGREG_DESC_INIT_X87(     "st3",    DBGFREG_ST3),
    1031     DBGREG_DESC_INIT_X87(     "st4",    DBGFREG_ST4),
    1032     DBGREG_DESC_INIT_X87(     "st5",    DBGFREG_ST5),
    1033     DBGREG_DESC_INIT_X87(     "st6",    DBGFREG_ST6),
    1034     DBGREG_DESC_INIT_X87(     "st7",    DBGFREG_ST7),
    1035 
    1036     DBGREG_DESC_INIT_X87_CTRL("fctrl",  DBGFREG_FCW),
    1037     DBGREG_DESC_INIT_X87_CTRL("fstat",  DBGFREG_FSW),
    1038     DBGREG_DESC_INIT_X87_CTRL("ftag",   DBGFREG_FTW),
    1039     DBGREG_DESC_INIT_X87_CTRL("fop",    DBGFREG_FOP),
    1040     DBGREG_DESC_INIT_X87_CTRL("fioff",  DBGFREG_FPUIP),
    1041     DBGREG_DESC_INIT_X87_CTRL("fiseg",  DBGFREG_FPUCS),
    1042     DBGREG_DESC_INIT_X87_CTRL("fooff",  DBGFREG_FPUDP),
    1043     DBGREG_DESC_INIT_X87_CTRL("foseg",  DBGFREG_FPUDS)
    1044 
    1045 #undef DBGREG_DESC_INIT_CODE_PTR
    1046 #undef DBGREG_DESC_INIT_DATA_PTR
     1015
     1016
     1017/**
     1018 * amd64 GDB register set.
     1019 */
     1020static const GDBREGDESC g_aGdbRegs64[] =
     1021{
     1022    DBGREG_DESC_INIT_INT64(     "rax",    DBGFREG_RAX),
     1023    DBGREG_DESC_INIT_INT64(     "rbx",    DBGFREG_RBX),
     1024    DBGREG_DESC_INIT_INT64(     "rcx",    DBGFREG_RCX),
     1025    DBGREG_DESC_INIT_INT64(     "rdx",    DBGFREG_RDX),
     1026    DBGREG_DESC_INIT_INT64(     "rsi",    DBGFREG_RSI),
     1027    DBGREG_DESC_INIT_INT64(     "rdi",    DBGFREG_RDI),
     1028    DBGREG_DESC_INIT_DATA_PTR64("rbp",    DBGFREG_RBP),
     1029    DBGREG_DESC_INIT_DATA_PTR64("rsp",    DBGFREG_RSP),
     1030    DBGREG_DESC_INIT_INT64(     "r8",     DBGFREG_R8),
     1031    DBGREG_DESC_INIT_INT64(     "r9",     DBGFREG_R9),
     1032    DBGREG_DESC_INIT_INT64(     "r10",    DBGFREG_R10),
     1033    DBGREG_DESC_INIT_INT64(     "r11",    DBGFREG_R11),
     1034    DBGREG_DESC_INIT_INT64(     "r12",    DBGFREG_R12),
     1035    DBGREG_DESC_INIT_INT64(     "r13",    DBGFREG_R13),
     1036    DBGREG_DESC_INIT_INT64(     "r14",    DBGFREG_R14),
     1037    DBGREG_DESC_INIT_INT64(     "r15",    DBGFREG_R15),
     1038    DBGREG_DESC_INIT_CODE_PTR64("rip",    DBGFREG_RIP),
     1039    DBGREG_DESC_INIT_INT32(     "eflags", DBGFREG_FLAGS),
     1040    DBGREG_DESC_INIT_INT32(     "cs",     DBGFREG_CS),
     1041    DBGREG_DESC_INIT_INT32(     "ss",     DBGFREG_SS),
     1042    DBGREG_DESC_INIT_INT32(     "ds",     DBGFREG_DS),
     1043    DBGREG_DESC_INIT_INT32(     "es",     DBGFREG_ES),
     1044    DBGREG_DESC_INIT_INT32(     "fs",     DBGFREG_FS),
     1045    DBGREG_DESC_INIT_INT32(     "gs",     DBGFREG_GS),
     1046
     1047    DBGREG_DESC_INIT_X87(       "st0",    DBGFREG_ST0),
     1048    DBGREG_DESC_INIT_X87(       "st1",    DBGFREG_ST1),
     1049    DBGREG_DESC_INIT_X87(       "st2",    DBGFREG_ST2),
     1050    DBGREG_DESC_INIT_X87(       "st3",    DBGFREG_ST3),
     1051    DBGREG_DESC_INIT_X87(       "st4",    DBGFREG_ST4),
     1052    DBGREG_DESC_INIT_X87(       "st5",    DBGFREG_ST5),
     1053    DBGREG_DESC_INIT_X87(       "st6",    DBGFREG_ST6),
     1054    DBGREG_DESC_INIT_X87(       "st7",    DBGFREG_ST7),
     1055
     1056    DBGREG_DESC_INIT_X87_CTRL(  "fctrl",  DBGFREG_FCW),
     1057    DBGREG_DESC_INIT_X87_CTRL(  "fstat",  DBGFREG_FSW),
     1058    DBGREG_DESC_INIT_X87_CTRL(  "ftag",   DBGFREG_FTW),
     1059    DBGREG_DESC_INIT_X87_CTRL(  "fop",    DBGFREG_FOP),
     1060    DBGREG_DESC_INIT_X87_CTRL(  "fioff",  DBGFREG_FPUIP),
     1061    DBGREG_DESC_INIT_X87_CTRL(  "fiseg",  DBGFREG_FPUCS),
     1062    DBGREG_DESC_INIT_X87_CTRL(  "fooff",  DBGFREG_FPUDP),
     1063    DBGREG_DESC_INIT_X87_CTRL(  "foseg",  DBGFREG_FPUDS)
     1064};
     1065
     1066
     1067/**
     1068 * i386 GDB register set.
     1069 */
     1070static const GDBREGDESC g_aGdbRegs32[] =
     1071{
     1072    DBGREG_DESC_INIT_INT32(     "eax",    DBGFREG_EAX),
     1073    DBGREG_DESC_INIT_INT32(     "ebx",    DBGFREG_EBX),
     1074    DBGREG_DESC_INIT_INT32(     "ecx",    DBGFREG_ECX),
     1075    DBGREG_DESC_INIT_INT32(     "edx",    DBGFREG_EDX),
     1076    DBGREG_DESC_INIT_INT32(     "esi",    DBGFREG_ESI),
     1077    DBGREG_DESC_INIT_INT32(     "edi",    DBGFREG_EDI),
     1078    DBGREG_DESC_INIT_DATA_PTR32("ebp",    DBGFREG_EBP),
     1079    DBGREG_DESC_INIT_DATA_PTR32("esp",    DBGFREG_ESP),
     1080    DBGREG_DESC_INIT_CODE_PTR32("eip",    DBGFREG_EIP),
     1081    DBGREG_DESC_INIT_INT32(     "eflags", DBGFREG_FLAGS),
     1082    DBGREG_DESC_INIT_INT32(     "cs",     DBGFREG_CS),
     1083    DBGREG_DESC_INIT_INT32(     "ss",     DBGFREG_SS),
     1084    DBGREG_DESC_INIT_INT32(     "ds",     DBGFREG_DS),
     1085    DBGREG_DESC_INIT_INT32(     "es",     DBGFREG_ES),
     1086    DBGREG_DESC_INIT_INT32(     "fs",     DBGFREG_FS),
     1087    DBGREG_DESC_INIT_INT32(     "gs",     DBGFREG_GS),
     1088
     1089    DBGREG_DESC_INIT_X87(       "st0",    DBGFREG_ST0),
     1090    DBGREG_DESC_INIT_X87(       "st1",    DBGFREG_ST1),
     1091    DBGREG_DESC_INIT_X87(       "st2",    DBGFREG_ST2),
     1092    DBGREG_DESC_INIT_X87(       "st3",    DBGFREG_ST3),
     1093    DBGREG_DESC_INIT_X87(       "st4",    DBGFREG_ST4),
     1094    DBGREG_DESC_INIT_X87(       "st5",    DBGFREG_ST5),
     1095    DBGREG_DESC_INIT_X87(       "st6",    DBGFREG_ST6),
     1096    DBGREG_DESC_INIT_X87(       "st7",    DBGFREG_ST7),
     1097
     1098    DBGREG_DESC_INIT_X87_CTRL(  "fctrl",  DBGFREG_FCW),
     1099    DBGREG_DESC_INIT_X87_CTRL(  "fstat",  DBGFREG_FSW),
     1100    DBGREG_DESC_INIT_X87_CTRL(  "ftag",   DBGFREG_FTW),
     1101    DBGREG_DESC_INIT_X87_CTRL(  "fop",    DBGFREG_FOP),
     1102    DBGREG_DESC_INIT_X87_CTRL(  "fioff",  DBGFREG_FPUIP),
     1103    DBGREG_DESC_INIT_X87_CTRL(  "fiseg",  DBGFREG_FPUCS),
     1104    DBGREG_DESC_INIT_X87_CTRL(  "fooff",  DBGFREG_FPUDP),
     1105    DBGREG_DESC_INIT_X87_CTRL(  "foseg",  DBGFREG_FPUDS)
     1106};
     1107
     1108#undef DBGREG_DESC_INIT_CODE_PTR64
     1109#undef DBGREG_DESC_INIT_DATA_PTR64
     1110#undef DBGREG_DESC_INIT_CODE_PTR32
     1111#undef DBGREG_DESC_INIT_DATA_PTR32
    10471112#undef DBGREG_DESC_INIT_INT32
    10481113#undef DBGREG_DESC_INIT_INT64
    1049 };
     1114#undef DBGREG_DESC_INIT_X87
     1115#undef DBGREG_DESC_INIT_X87_CTRL
    10501116
    10511117
     
    10581124static int dbgcGdbStubCtxTgtXmlDescCreate(PGDBSTUBCTX pThis)
    10591125{
    1060     static const char s_szXmlTgtHdr[] =
     1126    static const char s_szXmlTgtHdr64[] =
    10611127        "<?xml version=\"1.0\"?>\n"
    10621128        "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">\n"
     
    10641130        "    <architecture>i386:x86-64</architecture>\n"
    10651131        "    <feature name=\"org.gnu.gdb.i386.core\">\n";
     1132    static const char s_szXmlTgtHdr32[] =
     1133        "<?xml version=\"1.0\"?>\n"
     1134        "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">\n"
     1135        "<target version=\"1.0\">\n"
     1136        "    <architecture>i386</architecture>\n"
     1137        "    <feature name=\"org.gnu.gdb.i386.core\">\n";
    10661138    static const char s_szXmlTgtFooter[] =
    10671139        "    </feature>\n"
     
    10771149        pThis->cbTgtXmlDesc = cbLeft;
    10781150
    1079         rc = RTStrCatP(&pachXmlCur, &cbLeft, &s_szXmlTgtHdr[0]);
     1151        rc = RTStrCatP(&pachXmlCur, &cbLeft, pThis->paRegs == &g_aGdbRegs64[0] ? &s_szXmlTgtHdr64[0] : &s_szXmlTgtHdr32[0]);
    10801152        if (RT_SUCCESS(rc))
    10811153        {
    10821154            /* Register */
    1083             for (uint32_t i = 0; i < RT_ELEMENTS(g_aGdbRegs) && RT_SUCCESS(rc); i++)
    1084             {
    1085                 const struct GDBREGDESC *pReg = &g_aGdbRegs[i];
     1155            for (uint32_t i = 0; i < pThis->cRegs && RT_SUCCESS(rc); i++)
     1156            {
     1157                const struct GDBREGDESC *pReg = &pThis->paRegs[i];
    10861158
    10871159                ssize_t cchStr = 0;
     
    11211193 *
    11221194 * @returns Pointer to the GDB register descriptor or NULL if not found.
     1195 * @param   pThis               The GDB stub context.
    11231196 * @param   idxReg              The register to look for.
    11241197 */
    1125 static const GDBREGDESC *dbgcGdbStubRegGet(uint32_t idxReg)
    1126 {
    1127     if (RT_LIKELY(idxReg < RT_ELEMENTS(g_aGdbRegs)))
    1128         return &g_aGdbRegs[idxReg];
     1198static const GDBREGDESC *dbgcGdbStubRegGet(PGDBSTUBCTX pThis, uint32_t idxReg)
     1199{
     1200    if (RT_LIKELY(idxReg < pThis->cRegs))
     1201        return &pThis->paRegs[idxReg];
    11291202
    11301203    return NULL;
     
    16791752                for (;;)
    16801753                {
    1681                     const GDBREGDESC *pReg = &g_aGdbRegs[idxRegMax++];
     1754                    const GDBREGDESC *pReg = &pThis->paRegs[idxRegMax++];
    16821755                    cbRegs += pReg->cBits / 8;
    16831756                    if (pReg->enmReg == DBGFREG_SS) /* Up to this seems to belong to the general register set. */
     
    16941767                    for (uint32_t i = 0; i < idxRegMax && RT_SUCCESS(rc); i++)
    16951768                    {
    1696                         const GDBREGDESC *pReg = &g_aGdbRegs[i];
     1769                        const GDBREGDESC *pReg = &pThis->paRegs[i];
    16971770                        size_t cbReg = pReg->cBits / 8;
    16981771                        union
     
    18421915                    DBGFREGVAL RegVal;
    18431916                    DBGFREGVALTYPE enmType;
    1844                     const GDBREGDESC *pReg = dbgcGdbStubRegGet(uReg);
     1917                    const GDBREGDESC *pReg = dbgcGdbStubRegGet(pThis, uReg);
    18451918                    if (RT_LIKELY(pReg))
    18461919                    {
     
    18821955                if (RT_SUCCESS(rc))
    18831956                {
    1884                     const GDBREGDESC *pReg = dbgcGdbStubRegGet(uReg);
     1957                    const GDBREGDESC *pReg = dbgcGdbStubRegGet(pThis, uReg);
    18851958
    18861959                    if (pReg)
     
    24742547int dbgcGdbStubRun(PGDBSTUBCTX pThis)
    24752548{
     2549    /* Select the register set based on the CPU mode. */
     2550    CPUMMODE enmMode   = DBGCCmdHlpGetCpuMode(&pThis->Dbgc.CmdHlp);
     2551    switch (enmMode)
     2552    {
     2553        case CPUMMODE_PROTECTED:
     2554            pThis->paRegs = &g_aGdbRegs32[0];
     2555            pThis->cRegs  = RT_ELEMENTS(g_aGdbRegs32);
     2556            break;
     2557        case CPUMMODE_LONG:
     2558            pThis->paRegs = &g_aGdbRegs64[0];
     2559            pThis->cRegs  = RT_ELEMENTS(g_aGdbRegs64);
     2560            break;
     2561        case CPUMMODE_REAL:
     2562        default:
     2563            return DBGCCmdHlpPrintf(&pThis->Dbgc.CmdHlp, "error: Invalid CPU mode %d.\n", enmMode);
     2564    }
     2565
    24762566    /*
    24772567     * We're ready for commands now.
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