Changeset 41338 in vbox for trunk/src/bldprogs
- Timestamp:
- May 16, 2012 2:39:21 PM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 78009
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bldprogs/VBoxTpG.cpp
r41311 r41338 58 58 { 59 59 RTLISTNODE ListEntry; 60 /** The argument name. (heap) */ 60 61 char *pszName; 61 const char *pszType; 62 /** The type presented to the tracer (in string table). */ 63 const char *pszTracerType; 64 /** The argument type used in the probe method in that context. (heap) */ 65 char *pszCtxType; 66 /** Argument passing format string. First and only argument is the name. 67 * (const string) */ 68 const char *pszArgPassingFmt; 69 /** The type flags. */ 62 70 uint32_t fType; 63 71 } VTGARG; … … 119 127 /** List of providers created by the parser. */ 120 128 static RTLISTANCHOR g_ProviderHead; 121 122 129 /** The number of type errors. */ 123 static uint32_t g_cTypeErrors = 0; 130 static uint32_t g_cTypeErrors = 0; 131 124 132 125 133 /** @name Options … … 131 139 kVBoxTpGAction_GenerateObject 132 140 } g_enmAction = kVBoxTpGAction_Nothing; 133 static uint32_t g_cBits = ARCH_BITS; 141 static uint32_t g_cBits = HC_ARCH_BITS; 142 static uint32_t g_cHostBits = HC_ARCH_BITS; 143 static uint32_t g_fTypeContext = VTG_TYPE_CTX_R0; 134 144 static bool g_fApplyCpp = false; 135 145 static uint32_t g_cVerbosity = 0; … … 174 184 # endif 175 185 #endif 176 static const char *g_pszAssemblerFmtVal = RT_CONCAT(g_szAssemblerFmtVal, ARCH_BITS);186 static const char *g_pszAssemblerFmtVal = RT_CONCAT(g_szAssemblerFmtVal, HC_ARCH_BITS); 177 187 static const char *g_pszAssemblerDefOpt = "-D"; 178 188 static const char *g_pszAssemblerIncOpt = "-I"; … … 274 284 apszArgs[iArg++] = "ARCH_BITS=64"; 275 285 apszArgs[iArg++] = g_pszAssemblerDefOpt; 286 if (g_cHostBits == 32) 287 apszArgs[iArg++] = "HC_ARCH_BITS=32"; 288 else 289 apszArgs[iArg++] = "HC_ARCH_BITS=64"; 290 apszArgs[iArg++] = g_pszAssemblerDefOpt; 276 291 if (g_cBits == 32) 277 292 apszArgs[iArg++] = "RT_ARCH_X86"; 278 293 else 279 294 apszArgs[iArg++] = "RT_ARCH_AMD64"; 295 apszArgs[iArg++] = g_pszAssemblerDefOpt; 296 if (g_fTypeContext == VTG_TYPE_CTX_R0) 297 apszArgs[iArg++] = "IN_RING0"; 298 else if (g_fTypeContext == VTG_TYPE_CTX_R3) 299 apszArgs[iArg++] = "IN_RING3"; 300 else if (g_fTypeContext == VTG_TYPE_CTX_RC) 301 apszArgs[iArg++] = "IN_RC"; 302 else 303 apszArgs[iArg++] = "IN_UNKNOWN"; 280 304 if (g_szAssemblerOsDef[0]) 281 305 { … … 442 466 " ; With the ld64-97.17 linker there was a problem with it determin the section\n" 443 467 " ; order based on symbol references. The references to the start and end of the\n" 444 " ; __VTGPrLc section forced it in front of __VTGObj. 468 " ; __VTGPrLc section forced it in front of __VTGObj.\n" 445 469 " extern section$start$__VTG$__VTGObj\n" 446 470 " extern section$end$__VTG$__VTGObj\n" … … 474 498 "VTG_GLOBAL g_aVTGPrLc_End, data\n" 475 499 " dd 0,0,0,0, 0,0,0,0\n" 476 " [section .VTGData progbits alloc noexec write align=4096]\n"500 " [section .VTGData]\n" 477 501 "\n" 478 502 "%%else\n" … … 585 609 " dd %8u ; type '%s' (name '%s')\n" 586 610 " dd 0%08xh ; type flags\n", 587 strtabGetOff(pArg->pszT ype), pArg->pszType, pArg->pszName,611 strtabGetOff(pArg->pszTracerType), pArg->pszTracerType, pArg->pszName, 588 612 pArg->fType); 589 613 off += 8; … … 607 631 int32_t cArgs = pProbe->cArgs; 608 632 while ( cArgs-- > 0 609 && pArg2->pszT ype == pArg->pszType610 && pArg2->fType == pArg->fType)633 && pArg2->pszTracerType == pArg->pszTracerType 634 && pArg2->fType == pArg->fType) 611 635 { 612 636 pArg = RTListNodeGetNext(&pArg->ListEntry, VTGARG, ListEntry); … … 765 789 RTListForEach(&pProbe->ArgHead, pArg, VTGARG, ListEntry) 766 790 { 767 ScmStreamPrintf(pStrm, ", %s %s", pArg->pszT ype, pArg->pszName);791 ScmStreamPrintf(pStrm, ", %s %s", pArg->pszTracerType, pArg->pszName); 768 792 } 769 793 ScmStreamPrintf(pStrm, … … 878 902 } 879 903 904 /** 905 * Called via generateFile to generate the header file. 906 * 907 * @returns Exit code status. 908 * @param pStrm The output stream. 909 */ 880 910 static RTEXITCODE generateHeaderInner(PSCMSTREAM pStrm) 881 911 { … … 904 934 } 905 935 936 const char *pszCtxDefine = "UNKNOWN_DEFINE"; 937 if (g_fTypeContext == VTG_TYPE_CTX_R0) 938 pszCtxDefine = "IN_RING0"; 939 else if (g_fTypeContext == VTG_TYPE_CTX_R3) 940 pszCtxDefine = "IN_RING3"; 941 else if (g_fTypeContext == VTG_TYPE_CTX_RC) 942 pszCtxDefine = "IN_RC"; 943 else 944 AssertFailed(); 945 906 946 ScmStreamPrintf(pStrm, 907 947 "/* $Id$ */\n" 908 948 "/** @file\n" 909 " * Automatically generated from %s. Do NOT edit!\n"949 " * Automatically generated from %s. Do NOT edit!\n" 910 950 " */\n" 911 951 "\n" … … 914 954 "\n" 915 955 "#include <VBox/VBoxTpG.h>\n" 956 "\n" 957 "#ifndef %s\n" 958 "# error \"Expected '%s' to be defined\"\n" 959 "#endif\n" 916 960 "\n" 917 961 "RT_C_DECLS_BEGIN\n" … … 927 971 g_pszScript, 928 972 szTmp, 929 szTmp); 973 szTmp, 974 pszCtxDefine); 930 975 931 976 /* … … 939 984 RTListForEach(&pProv->ProbeHead, pProbe, VTGPROBE, ListEntry) 940 985 { 986 PVTGARG const pFirstArg = RTListGetFirst(&pProbe->ArgHead, VTGARG, ListEntry); 987 941 988 ScmStreamPrintf(pStrm, 942 989 "extern uint32_t g_cVTGProbeEnabled_%s_%s;\n" … … 948 995 RTListForEach(&pProbe->ArgHead, pArg, VTGARG, ListEntry) 949 996 { 950 ScmStreamPrintf(pStrm, ", %s", pArg->psz Type);997 ScmStreamPrintf(pStrm, ", %s", pArg->pszCtxType); 951 998 } 952 999 generateProbeDefineName(szTmp, sizeof(szTmp), pProv->pszName, pProbe->pszMangledName); … … 979 1026 RTListForEach(&pProbe->ArgHead, pArg, VTGARG, ListEntry) 980 1027 { 981 ScmStreamPrintf(pStrm, ", %s", pArg->pszName);1028 ScmStreamPrintf(pStrm, pArg->pszArgPassingFmt, pArg->pszName); 982 1029 } 983 1030 ScmStreamPrintf(pStrm, … … 988 1035 RTListForEach(&pProbe->ArgHead, pArg, VTGARG, ListEntry) 989 1036 { 990 if ( pArg->fType &VTG_TYPE_FIXED_SIZED)1037 if ((pArg->fType & (VTG_TYPE_FIXED_SIZED | VTG_TYPE_AUTO_CONV_PTR)) == VTG_TYPE_FIXED_SIZED) 991 1038 ScmStreamPrintf(pStrm, 992 1039 " AssertCompile(sizeof(%s) == %u); \\\n" 993 1040 " AssertCompile(sizeof(%s) <= %u); \\\n", 994 pArg->pszT ype, pArg->fType & VTG_TYPE_SIZE_MASK,1041 pArg->pszTracerType, pArg->fType & VTG_TYPE_SIZE_MASK, 995 1042 pArg->pszName, pArg->fType & VTG_TYPE_SIZE_MASK); 996 1043 else if (pArg->fType & (VTG_TYPE_POINTER | VTG_TYPE_HC_ARCH_SIZED)) … … 999 1046 " AssertCompile(sizeof(%s) <= sizeof(uintptr_t)); \\\n", 1000 1047 pArg->pszName, 1001 pArg->pszT ype);1048 pArg->pszTracerType); 1002 1049 iArg++; 1003 1050 } … … 1542 1589 * The special VBox types. 1543 1590 */ 1544 if (MY_STRMATCH("PVM")) return VTG_TYPE_CTX_POINTER; 1545 if (MY_STRMATCH("PVMCPU")) return VTG_TYPE_CTX_POINTER; 1591 if (MY_STRMATCH("PVM")) return VTG_TYPE_POINTER; 1592 if (MY_STRMATCH("PVMCPU")) return VTG_TYPE_POINTER; 1593 if (MY_STRMATCH("PCPUMCTX")) return VTG_TYPE_POINTER; 1546 1594 1547 1595 /* … … 1605 1653 1606 1654 /** 1655 * Initializes the members of an argument. 1656 * 1657 * @returns RTEXITCODE_SUCCESS or RTEXITCODE_FAILURE+msg. 1658 * @param pProbe The probe. 1659 * @param pArg The argument. 1660 * @param pStrm The input stream (for errors). 1661 * @param pchType The type. 1662 * @param cchType The type length. 1663 * @param pchName The name. 1664 * @param cchName The name length. 1665 */ 1666 static RTEXITCODE parseInitArgument(PVTGPROBE pProbe, PVTGARG pArg, PSCMSTREAM pStrm, 1667 char *pchType, size_t cchType, char *pchName, size_t cchName) 1668 { 1669 Assert(!pArg->pszName); Assert(!pArg->pszTracerType); Assert(!pArg->pszCtxType); Assert(!pArg->fType); 1670 1671 pArg->pszArgPassingFmt = ", %s"; 1672 pArg->pszName = RTStrDupN(pchName, cchName); 1673 pArg->pszTracerType = strtabInsertN(pchType, cchType); 1674 if (!pArg->pszTracerType || !pArg->pszName) 1675 return parseError(pStrm, 1, "Out of memory"); 1676 pArg->fType = parseTypeExpression(pArg->pszTracerType); 1677 1678 if ( (pArg->fType & VTG_TYPE_POINTER) 1679 && !(g_fTypeContext & VTG_TYPE_CTX_R0) ) 1680 { 1681 pArg->fType &= ~VTG_TYPE_POINTER; 1682 if ( !strcmp(pArg->pszTracerType, "struct VM *") || !strcmp(pArg->pszTracerType, "PVM") 1683 || !strcmp(pArg->pszTracerType, "struct VMCPU *") || !strcmp(pArg->pszTracerType, "PVMCPU") 1684 || !strcmp(pArg->pszTracerType, "struct CPUMCTX *") || !strcmp(pArg->pszTracerType, "PCPUMCTX") 1685 ) 1686 { 1687 pArg->fType |= VTG_TYPE_CTX_POINTER | VTG_TYPE_CTX_R0 1688 | VTG_TYPE_FIXED_SIZED | (g_cHostBits / 8) 1689 | VTG_TYPE_AUTO_CONV_PTR; 1690 pArg->pszCtxType = RTStrDup("RTR0PTR"); 1691 1692 if (!strcmp(pArg->pszTracerType, "struct VM *") || !strcmp(pArg->pszTracerType, "PVM")) 1693 pArg->pszArgPassingFmt = ", VTG_VM_TO_R0(%s)"; 1694 else if (!strcmp(pArg->pszTracerType, "struct VMCPU *") || !strcmp(pArg->pszTracerType, "PVMCPU")) 1695 pArg->pszArgPassingFmt = ", VTG_VMCPU_TO_R0(%s)"; 1696 else 1697 { 1698 PVTGARG pFirstArg = RTListGetFirst(&pProbe->ArgHead, VTGARG, ListEntry); 1699 if ( !pFirstArg 1700 || pFirstArg == pArg 1701 || strcmp(pFirstArg->pszName, "a_pVCpu") 1702 || ( strcmp(pFirstArg->pszTracerType, "struct VMCPU *") 1703 && strcmp(pFirstArg->pszTracerType, "PVMCPU *")) ) 1704 return parseError(pStrm, 1, "The automatic ring-0 pointer conversion requires 'a_pVCpu' with type 'struct VMCPU *' as the first argument"); 1705 1706 if (!strcmp(pArg->pszTracerType, "struct CPUMCTX *")|| !strcmp(pArg->pszTracerType, "PCPUMCTX")) 1707 pArg->pszArgPassingFmt = ", VTG_CPUMCTX_TO_R0(a_pVCpu, %s)"; 1708 else 1709 pArg->pszArgPassingFmt = ", VBoxTpG-Is-Buggy!!"; 1710 } 1711 } 1712 else 1713 { 1714 pArg->fType |= VTG_TYPE_CTX_POINTER | g_fTypeContext | VTG_TYPE_FIXED_SIZED | (g_cBits / 8); 1715 pArg->pszCtxType = RTStrDupN(pchType, cchType); 1716 } 1717 } 1718 else 1719 pArg->pszCtxType = RTStrDupN(pchType, cchType); 1720 if (!pArg->pszCtxType) 1721 return parseError(pStrm, 1, "Out of memory"); 1722 1723 return RTEXITCODE_SUCCESS; 1724 } 1725 1726 1727 /** 1607 1728 * Unmangles the probe name. 1608 1729 * … … 1693 1814 if (cchArg - cchName - 1 >= 128) 1694 1815 return parseError(pStrm, 1, "Argument type too long"); 1695 pArg->pszType = strtabInsertN(szArg, cchArg - cchName - 1);1696 pArg->pszName = RTStrDupN(&szArg[cchArg - cchName], cchName);1697 if (!pArg->pszType || !pArg->pszName)1698 return parseError(pStrm, 1, "Out of memory");1699 pArg->fType = parseTypeExpression(pArg->pszType);1816 RTEXITCODE rcExit = parseInitArgument(pProbe, pArg, pStrm, 1817 szArg, cchArg - cchName - 1, 1818 &szArg[cchArg - cchName], cchName); 1819 if (rcExit != RTEXITCODE_SUCCESS) 1820 return rcExit; 1700 1821 if (VTG_TYPE_IS_LARGE(pArg->fType)) 1701 1822 pProbe->fHaveLargeArgs = true; 1702 1703 1823 pArg = NULL; 1704 1824 cchName = cchArg = 0; … … 1936 2056 kVBoxTpGOpt_ProbeFnImported, 1937 2057 kVBoxTpGOpt_ProbeFnNotImported, 2058 kVBoxTpGOpt_Host32Bit, 2059 kVBoxTpGOpt_Host64Bit, 2060 kVBoxTpGOpt_RawModeContext, 2061 kVBoxTpGOpt_Ring0Context, 2062 kVBoxTpGOpt_Ring3Context, 1938 2063 kVBoxTpGOpt_End 1939 2064 }; … … 1960 2085 { "--probe-fn-imported", kVBoxTpGOpt_ProbeFnImported, RTGETOPT_REQ_NOTHING }, 1961 2086 { "--probe-fn-not-imported", kVBoxTpGOpt_ProbeFnNotImported, RTGETOPT_REQ_NOTHING }, 2087 { "--host-32-bit", kVBoxTpGOpt_Host32Bit, RTGETOPT_REQ_NOTHING }, 2088 { "--host-64-bit", kVBoxTpGOpt_Host64Bit, RTGETOPT_REQ_NOTHING }, 2089 { "--raw-mode-context", kVBoxTpGOpt_RawModeContext, RTGETOPT_REQ_NOTHING }, 2090 { "--ring-0-context", kVBoxTpGOpt_Ring0Context, RTGETOPT_REQ_NOTHING }, 2091 { "--ring-3-context", kVBoxTpGOpt_Ring3Context, RTGETOPT_REQ_NOTHING }, 1962 2092 /** @todo We're missing a bunch of assembler options! */ 1963 2093 }; … … 1979 2109 */ 1980 2110 case kVBoxTpGOpt_32Bit: 1981 g_c Bits = 32;2111 g_cHostBits = g_cBits = 32; 1982 2112 g_pszAssemblerFmtVal = g_szAssemblerFmtVal32; 1983 2113 break; 1984 2114 1985 2115 case kVBoxTpGOpt_64Bit: 1986 g_c Bits = 64;2116 g_cHostBits = g_cBits = 64; 1987 2117 g_pszAssemblerFmtVal = g_szAssemblerFmtVal64; 1988 2118 break; … … 2098 2228 break; 2099 2229 2230 case kVBoxTpGOpt_Host32Bit: 2231 g_cHostBits = 32; 2232 break; 2233 2234 case kVBoxTpGOpt_Host64Bit: 2235 g_cHostBits = 64; 2236 break; 2237 2238 case kVBoxTpGOpt_RawModeContext: 2239 g_fTypeContext = VTG_TYPE_CTX_RC; 2240 break; 2241 2242 case kVBoxTpGOpt_Ring0Context: 2243 g_fTypeContext = VTG_TYPE_CTX_R0; 2244 break; 2245 2246 case kVBoxTpGOpt_Ring3Context: 2247 g_fTypeContext = VTG_TYPE_CTX_R3; 2248 break; 2249 2250 2100 2251 /* 2101 2252 * Errors and bugs.
Note:
See TracChangeset
for help on using the changeset viewer.