Changeset 85367 in vbox for trunk/src/VBox/Debugger
- Timestamp:
- Jul 17, 2020 8:50:59 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Debugger/DBGCGdbRemoteStub.cpp
r85177 r85367 96 96 GDBSTUBRECVSTATE_32BIT_HACK = 0x7fffffff 97 97 } GDBSTUBRECVSTATE; 98 99 100 /** 101 * GDB target register descriptor. 102 */ 103 typedef 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. */ 117 typedef GDBREGDESC *PGDBREGDESC; 118 /** Pointer to a const GDB target register descriptor. */ 119 typedef const GDBREGDESC *PCGDBREGDESC; 98 120 99 121 … … 145 167 /** Size of the XML target description. */ 146 168 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; 147 173 /** Flag whether the stub is in extended mode. */ 148 174 bool fExtendedMode; … … 726 752 cbThisVal = pbDelim - pbVal; 727 753 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))) 730 758 { 731 759 /* Set the flag to support the qXfer:features:read packet. */ … … 977 1005 978 1006 979 /**980 * GDB registers.981 */982 static const struct GDBREGDESC983 {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 {996 1007 #define DBGREG_DESC_INIT_INT64(a_Name, a_enmDbgfReg) { a_Name, a_enmDbgfReg, 64, "int64", NULL } 997 1008 #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 } 1000 1013 #define DBGREG_DESC_INIT_X87(a_Name, a_enmDbgfReg) { a_Name, a_enmDbgfReg, 80, "i387_ext", NULL } 1001 1014 #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 */ 1020 static 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 */ 1070 static 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 1047 1112 #undef DBGREG_DESC_INIT_INT32 1048 1113 #undef DBGREG_DESC_INIT_INT64 1049 }; 1114 #undef DBGREG_DESC_INIT_X87 1115 #undef DBGREG_DESC_INIT_X87_CTRL 1050 1116 1051 1117 … … 1058 1124 static int dbgcGdbStubCtxTgtXmlDescCreate(PGDBSTUBCTX pThis) 1059 1125 { 1060 static const char s_szXmlTgtHdr [] =1126 static const char s_szXmlTgtHdr64[] = 1061 1127 "<?xml version=\"1.0\"?>\n" 1062 1128 "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">\n" … … 1064 1130 " <architecture>i386:x86-64</architecture>\n" 1065 1131 " <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"; 1066 1138 static const char s_szXmlTgtFooter[] = 1067 1139 " </feature>\n" … … 1077 1149 pThis->cbTgtXmlDesc = cbLeft; 1078 1150 1079 rc = RTStrCatP(&pachXmlCur, &cbLeft, &s_szXmlTgtHdr[0]);1151 rc = RTStrCatP(&pachXmlCur, &cbLeft, pThis->paRegs == &g_aGdbRegs64[0] ? &s_szXmlTgtHdr64[0] : &s_szXmlTgtHdr32[0]); 1080 1152 if (RT_SUCCESS(rc)) 1081 1153 { 1082 1154 /* 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]; 1086 1158 1087 1159 ssize_t cchStr = 0; … … 1121 1193 * 1122 1194 * @returns Pointer to the GDB register descriptor or NULL if not found. 1195 * @param pThis The GDB stub context. 1123 1196 * @param idxReg The register to look for. 1124 1197 */ 1125 static const GDBREGDESC *dbgcGdbStubRegGet( uint32_t idxReg)1126 { 1127 if (RT_LIKELY(idxReg < RT_ELEMENTS(g_aGdbRegs)))1128 return & g_aGdbRegs[idxReg];1198 static const GDBREGDESC *dbgcGdbStubRegGet(PGDBSTUBCTX pThis, uint32_t idxReg) 1199 { 1200 if (RT_LIKELY(idxReg < pThis->cRegs)) 1201 return &pThis->paRegs[idxReg]; 1129 1202 1130 1203 return NULL; … … 1679 1752 for (;;) 1680 1753 { 1681 const GDBREGDESC *pReg = & g_aGdbRegs[idxRegMax++];1754 const GDBREGDESC *pReg = &pThis->paRegs[idxRegMax++]; 1682 1755 cbRegs += pReg->cBits / 8; 1683 1756 if (pReg->enmReg == DBGFREG_SS) /* Up to this seems to belong to the general register set. */ … … 1694 1767 for (uint32_t i = 0; i < idxRegMax && RT_SUCCESS(rc); i++) 1695 1768 { 1696 const GDBREGDESC *pReg = & g_aGdbRegs[i];1769 const GDBREGDESC *pReg = &pThis->paRegs[i]; 1697 1770 size_t cbReg = pReg->cBits / 8; 1698 1771 union … … 1842 1915 DBGFREGVAL RegVal; 1843 1916 DBGFREGVALTYPE enmType; 1844 const GDBREGDESC *pReg = dbgcGdbStubRegGet( uReg);1917 const GDBREGDESC *pReg = dbgcGdbStubRegGet(pThis, uReg); 1845 1918 if (RT_LIKELY(pReg)) 1846 1919 { … … 1882 1955 if (RT_SUCCESS(rc)) 1883 1956 { 1884 const GDBREGDESC *pReg = dbgcGdbStubRegGet( uReg);1957 const GDBREGDESC *pReg = dbgcGdbStubRegGet(pThis, uReg); 1885 1958 1886 1959 if (pReg) … … 2474 2547 int dbgcGdbStubRun(PGDBSTUBCTX pThis) 2475 2548 { 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 2476 2566 /* 2477 2567 * We're ready for commands now.
Note:
See TracChangeset
for help on using the changeset viewer.