Changeset 83078 in vbox for trunk/src/VBox/Runtime/tools/RTDbgSymCache.cpp
- Timestamp:
- Feb 15, 2020 2:20:17 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/tools/RTDbgSymCache.cpp
r82968 r83078 174 174 { 175 175 if (!pszCommand || !strcmp(pszCommand, "add")) 176 RTPrintf("Usage: %s add [-Rno] <cache-root-dir> <file1> [fileN..]\n", pszArg0); 176 RTPrintf("Usage: %s add [-Rno] <cache-root-dir> <file1[=cache-name]> [fileN..]\n" 177 "\n" 178 "Options:\n" 179 " -R, --recursive\n" 180 " Process directory arguments recursively.\n" 181 " -n, --no-recursive\n" 182 " No recursion. (default)\n" 183 " -o, --overwrite-on-conflict\n" 184 " Overwrite existing cache entry.\n" 185 , RTPathFilename(pszArg0)); 177 186 return RTEXITCODE_SUCCESS; 178 187 } … … 239 248 */ 240 249 char szLinkTarget[RTPATH_MAX]; 241 //szMapPath[cch] = '\0';250 szMapPath[cch] = '\0'; 242 251 rc = RTPathCalcRelative(szLinkTarget, sizeof(szLinkTarget), szMapPath, false /*fFromFile*/, pszCacheFile); 243 //szMapPath[cch] = RTPATH_SLASH;252 szMapPath[cch] = RTPATH_SLASH; 244 253 if (RT_FAILURE(rc)) 245 254 return RTMsgErrorRc(rc, "Failed to calculate relative path from '%s' to '%s': %Rrc", szMapPath, pszCacheFile, rc); … … 395 404 * @returns IPRT status code. 396 405 * @param pszPath Path to the image file. 406 * @param pszDstName Add to the cache under this name. Typically the 407 * filename part of @a pszPath. 397 408 * @param pCfg Configuration data. 398 409 * @param hLdrMod Image handle. … … 405 416 * com.apple.DebugSymbols in the user defaults. 406 417 */ 407 static int rtDbgSymCacheAddImageFileWorker(const char *pszPath, PCRTDBGSYMCACHEADDCFG pCfg, RTLDRMOD hLdrMod,408 const char *pszExtrSuff, const char *pszUuidMapDir)418 static int rtDbgSymCacheAddImageFileWorker(const char *pszPath, const char *pszDstName, PCRTDBGSYMCACHEADDCFG pCfg, 419 RTLDRMOD hLdrMod, const char *pszExtrSuff, const char *pszUuidMapDir) 409 420 { 410 421 /* … … 459 470 * Now add it. 460 471 */ 461 return rtDbgSymCacheAddOneFile(pszPath, RTPathFilename(pszPath), pszExtrSuff, 462 szSubDir, pUuid, pszUuidMapDir, pCfg); 472 return rtDbgSymCacheAddOneFile(pszPath, pszDstName, pszExtrSuff, szSubDir, pUuid, pszUuidMapDir, pCfg); 463 473 } 464 474 … … 469 479 * @returns IPRT status code. 470 480 * @param pszPath Path to the image file. 481 * @param pszDstName Add to the cache under this name. Typically the 482 * filename part of @a pszPath. 471 483 * @param pszExtraSuff Optional extra suffix. Mach-O dSYM hack. 472 484 * @param pszUuidMapDir The UUID map subdirectory in the cache, if this is … … 474 486 * @param pCfg Configuration data. 475 487 */ 476 static int rtDbgSymCacheAddImageFile(const char *pszPath, const char *pszExtraSuff, const char *pszUuidMapDir, 477 PCRTDBGSYMCACHEADDCFG pCfg) 478 { 488 static int rtDbgSymCacheAddImageFile(const char *pszPath, const char *pszDstName, const char *pszExtraSuff, 489 const char *pszUuidMapDir, PCRTDBGSYMCACHEADDCFG pCfg) 490 { 491 RTERRINFOSTATIC ErrInfo; 492 479 493 /* 480 494 * Use the loader to open the alleged image file. We need to open it with … … 485 499 /* Open it as AMD64. */ 486 500 RTLDRMOD hLdrMod64; 487 int rc = RTLdrOpen (pszPath, RTLDR_O_FOR_DEBUG, RTLDRARCH_AMD64, &hLdrMod64);501 int rc = RTLdrOpenEx(pszPath, RTLDR_O_FOR_DEBUG, RTLDRARCH_AMD64, &hLdrMod64, RTErrInfoInitStatic(&ErrInfo)); 488 502 if (RT_FAILURE(rc)) 489 503 { … … 491 505 { 492 506 if (rc != VERR_INVALID_EXE_SIGNATURE) 493 return RTMsgErrorRc(rc, "RTLdrOpen failed opening '%s' [arch=amd64]: %Rrc", pszPath, rc); 507 return RTMsgErrorRc(rc, "RTLdrOpen failed opening '%s' [arch=amd64]: %Rrc%s%s", pszPath, rc, 508 RTErrInfoIsSet(&ErrInfo.Core) ? " - " : "", 509 RTErrInfoIsSet(&ErrInfo.Core) ? ErrInfo.Core.pszMsg : ""); 510 494 511 RTMsgInfo("Skipping '%s', no a recognizable image file...", pszPath); 495 512 return VINF_SUCCESS; … … 500 517 /* Open it as X86. */ 501 518 RTLDRMOD hLdrMod32; 502 rc = RTLdrOpen (pszPath, RTLDR_O_FOR_DEBUG, RTLDRARCH_X86_32, &hLdrMod32);519 rc = RTLdrOpenEx(pszPath, RTLDR_O_FOR_DEBUG, RTLDRARCH_X86_32, &hLdrMod32, RTErrInfoInitStatic(&ErrInfo)); 503 520 if (RT_FAILURE(rc)) 504 521 { 505 522 if (rc != VERR_LDR_ARCH_MISMATCH) 506 523 { 507 RTLdrClose(hLdrMod32); 508 return RTMsgErrorRc(rc, "RTLdrOpen failed opening '%s' [arch=x86]: %Rrc", pszPath, rc); 524 RTLdrClose(hLdrMod64); 525 return RTMsgErrorRc(rc, "RTLdrOpen failed opening '%s' [arch=x86]: %Rrc%s%s", pszPath, rc, 526 RTErrInfoIsSet(&ErrInfo.Core) ? " - " : "", 527 RTErrInfoIsSet(&ErrInfo.Core) ? ErrInfo.Core.pszMsg : ""); 509 528 } 510 529 hLdrMod32 = NIL_RTLDRMOD; … … 515 534 */ 516 535 if (hLdrMod32 == NIL_RTLDRMOD) 517 rc = rtDbgSymCacheAddImageFileWorker(pszPath, p Cfg, hLdrMod64, pszExtraSuff, pszUuidMapDir);536 rc = rtDbgSymCacheAddImageFileWorker(pszPath, pszDstName, pCfg, hLdrMod64, pszExtraSuff, pszUuidMapDir); 518 537 else if (hLdrMod64 == NIL_RTLDRMOD) 519 rc = rtDbgSymCacheAddImageFileWorker(pszPath, p Cfg, hLdrMod32, pszExtraSuff, pszUuidMapDir);538 rc = rtDbgSymCacheAddImageFileWorker(pszPath, pszDstName, pCfg, hLdrMod32, pszExtraSuff, pszUuidMapDir); 520 539 else 521 540 { … … 548 567 } 549 568 550 rc = rtDbgSymCacheAddImageFileWorker(pszPath, p Cfg, hLdrMod64, pszExtraSuff, pszUuidMapDir);569 rc = rtDbgSymCacheAddImageFileWorker(pszPath, pszDstName, pCfg, hLdrMod64, pszExtraSuff, pszUuidMapDir); 551 570 if (!fSame) 552 571 { 553 572 /** @todo should symlink or hardlink this second copy. */ 554 int rc2 = rtDbgSymCacheAddImageFileWorker(pszPath, p Cfg, hLdrMod32, pszExtraSuff, pszUuidMapDir);573 int rc2 = rtDbgSymCacheAddImageFileWorker(pszPath, pszDstName, pCfg, hLdrMod32, pszExtraSuff, pszUuidMapDir); 555 574 if (RT_FAILURE(rc2) && RT_SUCCESS(rc)) 556 575 rc = rc2; … … 570 589 * @returns IPRT status code 571 590 * @param pszPath The path to the PDB file. 591 * @param pszDstName Add to the cache under this name. Typically the 592 * filename part of @a pszPath. 572 593 * @param pCfg The configuration. 573 594 * @param hFile Handle to the file. 574 595 */ 575 static int rtDbgSymCacheAddDebugMachO(const char *pszPath, PCRTDBGSYMCACHEADDCFG pCfg)596 static int rtDbgSymCacheAddDebugMachO(const char *pszPath, const char *pszDstName, PCRTDBGSYMCACHEADDCFG pCfg) 576 597 { 577 598 /* This shouldn't happen, figure out what to do if it does. */ 578 RT_NOREF _PV(pCfg);599 RT_NOREF(pCfg, pszDstName); 579 600 return RTMsgErrorRc(VERR_NOT_IMPLEMENTED, 580 601 "'%s' is an OS X image file, did you point me to a file inside a .dSYM or .sym file?", … … 588 609 * @returns IPRT status code 589 610 * @param pszPath The path to the PDB file. 611 * @param pszDstName Add to the cache under this name. Typically the 612 * filename part of @a pszPath. 590 613 * @param pCfg The configuration. 591 614 * @param hFile Handle to the file. 592 615 */ 593 static int rtDbgSymCacheAddDebugPdb(const char *pszPath, PCRTDBGSYMCACHEADDCFG pCfg, RTFILE hFile)594 { 595 RT_NOREF 2(pCfg, hFile);616 static int rtDbgSymCacheAddDebugPdb(const char *pszPath, const char *pszDstName, PCRTDBGSYMCACHEADDCFG pCfg, RTFILE hFile) 617 { 618 RT_NOREF(pCfg, hFile, pszDstName); 596 619 return RTMsgErrorRc(VERR_NOT_IMPLEMENTED, "PDB support not implemented: '%s'", pszPath); 597 620 } … … 603 626 * @returns IPRT status code 604 627 * @param pszPath The path to the debug file in question. 628 * @param pszDstName Add to the cache under this name. Typically the 629 * filename part of @a pszPath. 605 630 * @param pCfg The configuration. 606 631 */ 607 static int rtDbgSymCacheAddDebugFile(const char *pszPath, PCRTDBGSYMCACHEADDCFG pCfg)632 static int rtDbgSymCacheAddDebugFile(const char *pszPath, const char *pszDstName, PCRTDBGSYMCACHEADDCFG pCfg) 608 633 { 609 634 /* … … 634 659 */ 635 660 if (!memcmp(uBuf.ab, RT_STR_TUPLE("Microsoft C/C++ MSF 7.00"))) 636 rc = rtDbgSymCacheAddDebugPdb(pszPath, p Cfg, hFile);661 rc = rtDbgSymCacheAddDebugPdb(pszPath, pszDstName, pCfg, hFile); 637 662 else if ( uBuf.au32[0] == IMAGE_FAT_SIGNATURE 638 663 || uBuf.au32[0] == IMAGE_FAT_SIGNATURE_OE … … 641 666 || uBuf.au32[0] == IMAGE_MACHO32_SIGNATURE_OE 642 667 || uBuf.au32[0] == IMAGE_MACHO64_SIGNATURE_OE) 643 rc = rtDbgSymCacheAddDebugMachO(pszPath, p Cfg);668 rc = rtDbgSymCacheAddDebugMachO(pszPath, pszDstName, pCfg); 644 669 else 645 670 rc = RTMsgErrorRc(VERR_INVALID_MAGIC, "Unsupported debug file '%s' magic: %#010x", pszPath, uBuf.au32[0]); … … 721 746 * 722 747 * @returns IPRT status code. 723 * @param pszPath Path to the bundle. This a RTPATH_MAX size 724 * buffer that we can write to when creating the 725 * path to the file inside the bundle that we're 726 * interested in. 727 * @param cchPath The length of the path up to the bundle name. 728 * @param cchName The length of the bundle name. 729 * @param pDirEntry The directory entry buffer, for handling bundle 730 * within bundle recursion. 731 * @param pCfg The configuration. 732 */ 733 static int rtDbgSymCacheAddImageBundle(char *pszPath, size_t cchPath, size_t cchName, 748 * @param pszPath Path to the bundle. This a RTPATH_MAX size 749 * buffer that we can write to when creating the 750 * path to the file inside the bundle that we're 751 * interested in. 752 * @param cchPath The length of the path up to the bundle name. 753 * @param cchName The length of the bundle name. 754 * @param pszDstName Add to the cache under this name, NULL if not 755 * specified. 756 * @param pDirEntry The directory entry buffer, for handling bundle 757 * within bundle recursion. 758 * @param pCfg The configuration. 759 */ 760 static int rtDbgSymCacheAddImageBundle(char *pszPath, size_t cchPath, size_t cchName, const char *pszDstName, 734 761 PRTDIRENTRYEX pDirEntry, PCRTDBGSYMCACHEADDCFG pCfg) 735 762 { … … 741 768 int rc = rtDbgSymCacheConstructBundlePath(pszPath, cchPath, cchName, "Contents/MacOS/", g_apszBundleSuffixes); 742 769 if (RT_SUCCESS(rc)) 743 rc = rtDbgSymCacheAddImageFile(pszPath, NULL, RTDBG_CACHE_UUID_MAP_DIR_IMAGES, pCfg); 770 { 771 if (!pszDstName) 772 pszDstName = RTPathFilename(pszPath); 773 rc = rtDbgSymCacheAddImageFile(pszPath, pszDstName, NULL, RTDBG_CACHE_UUID_MAP_DIR_IMAGES, pCfg); 774 } 744 775 745 776 /* … … 788 819 * 789 820 * @returns IPRT status code. 790 * @param pszPath Path to the bundle. This a RTPATH_MAX size 791 * buffer that we can write to when creating the 792 * path to the file inside the bundle that we're 793 * interested in. 794 * @param cchPath The length of the path up to the bundle name. 795 * @param cchName The length of the bundle name. 796 * @param pCfg The configuration. 797 */ 798 static int rtDbgSymCacheAddDebugBundle(char *pszPath, size_t cchPath, size_t cchName, PCRTDBGSYMCACHEADDCFG pCfg) 821 * @param pszPath Path to the bundle. This a RTPATH_MAX size 822 * buffer that we can write to when creating the 823 * path to the file inside the bundle that we're 824 * interested in. 825 * @param cchPath The length of the path up to the bundle name. 826 * @param cchName The length of the bundle name. 827 * @param pszDstName Add to the cache under this name, NULL if not 828 * specified. 829 * @param pCfg The configuration. 830 */ 831 static int rtDbgSymCacheAddDebugBundle(char *pszPath, size_t cchPath, size_t cchName, const char *pszDstName, 832 PCRTDBGSYMCACHEADDCFG pCfg) 799 833 { 800 834 /* … … 815 849 int rc = rtDbgSymCacheConstructBundlePath(pszPath, cchPath, cchName, "Contents/Resources/DWARF/", g_apszDSymBundleSuffixes); 816 850 if (RT_SUCCESS(rc)) 817 rc = rtDbgSymCacheAddImageFile(pszPath, RTDBG_CACHE_DSYM_FILE_SUFFIX, RTDBG_CACHE_UUID_MAP_DIR_DSYMS, pCfg); 851 { 852 if (!pszDstName) 853 pszDstName = RTPathFilename(pszPath); 854 rc = rtDbgSymCacheAddImageFile(pszPath, pszDstName, RTDBG_CACHE_DSYM_FILE_SUFFIX, RTDBG_CACHE_UUID_MAP_DIR_DSYMS, pCfg); 855 } 818 856 return rc; 819 857 } … … 1018 1056 1019 1057 case RTDBGSYMCACHEFILETYPE_DEBUG_FILE: 1020 rc2 = rtDbgSymCacheAddDebugFile(pszPath, p Cfg);1058 rc2 = rtDbgSymCacheAddDebugFile(pszPath, pDirEntry->szName, pCfg); 1021 1059 break; 1022 1060 1023 1061 case RTDBGSYMCACHEFILETYPE_IMAGE_FILE: 1024 rc2 = rtDbgSymCacheAddImageFile(pszPath, NULL /*pszExtraSuff*/, RTDBG_CACHE_UUID_MAP_DIR_IMAGES, pCfg);1062 rc2 = rtDbgSymCacheAddImageFile(pszPath, pDirEntry->szName, NULL /*pszExtraSuff*/, RTDBG_CACHE_UUID_MAP_DIR_IMAGES, pCfg); 1025 1063 break; 1026 1064 1027 1065 case RTDBGSYMCACHEFILETYPE_DEBUG_BUNDLE: 1028 rc2 = rtDbgSymCacheAddDebugBundle(pszPath, cchPath, pDirEntry->cbName, pCfg);1066 rc2 = rtDbgSymCacheAddDebugBundle(pszPath, cchPath, pDirEntry->cbName, NULL /*pszDstName*/, pCfg); 1029 1067 break; 1030 1068 1031 1069 case RTDBGSYMCACHEFILETYPE_IMAGE_BUNDLE: 1032 rc2 = rtDbgSymCacheAddImageBundle(pszPath, cchPath, pDirEntry->cbName, pDirEntry, pCfg);1070 rc2 = rtDbgSymCacheAddImageBundle(pszPath, cchPath, pDirEntry->cbName, NULL /*pszDstName*/, pDirEntry, pCfg); 1033 1071 break; 1034 1072 … … 1117 1155 Cfg.pszFilter = NULL; 1118 1156 1157 /* If the filename contains an equal ('=') char, treat the left as the file 1158 to add tne right part as the name to add it under (handy for kernels). */ 1159 char *pszFree = NULL; 1160 const char *pszDstName = RTPathFilename(pszPath); 1161 const char *pszEqual = pszDstName ? strchr(pszDstName, '=') : NULL; 1162 if (pszEqual) 1163 { 1164 pszPath = pszFree = RTStrDupN(pszPath, pszEqual - pszPath); 1165 if (!pszFree) 1166 return RTMsgErrorExitFailure("out of memory!\n"); 1167 pszDstName = pszEqual + 1; 1168 if (!*pszDstName) 1169 return RTMsgErrorExitFailure("add-as filename is empty!\n"); 1170 } 1171 1119 1172 int rc; 1120 1173 RTDBGSYMCACHEFILETYPE enmType = rtDbgSymCacheFigureType(pszPath); … … 1123 1176 default: 1124 1177 case RTDBGSYMCACHEFILETYPE_INVALID: 1125 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Invalid: '%s'", pszPath); 1178 rc = RTMsgErrorRc(VERR_INVALID_PARAMETER, "Invalid: '%s'", pszPath); 1179 break; 1126 1180 1127 1181 case RTDBGSYMCACHEFILETYPE_DIR_FILTER: … … 1129 1183 RT_FALL_THRU(); 1130 1184 case RTDBGSYMCACHEFILETYPE_DIR: 1131 rc = rtDbgSymCacheAddDir(pszPath, &Cfg); 1185 if (!pszEqual) 1186 rc = rtDbgSymCacheAddDir(pszPath, &Cfg); 1187 else 1188 rc = RTMsgErrorRc(VERR_INVALID_PARAMETER, "Add-as filename is not applicable to directories!"); 1132 1189 break; 1133 1190 1134 1191 case RTDBGSYMCACHEFILETYPE_DEBUG_FILE: 1135 rc = rtDbgSymCacheAddDebugFile(pszPath, &Cfg);1192 rc = rtDbgSymCacheAddDebugFile(pszPath, pszDstName, &Cfg); 1136 1193 break; 1137 1194 1138 1195 case RTDBGSYMCACHEFILETYPE_IMAGE_FILE: 1139 rc = rtDbgSymCacheAddImageFile(pszPath, NULL /*pszExtraSuff*/, RTDBG_CACHE_UUID_MAP_DIR_IMAGES, &Cfg);1196 rc = rtDbgSymCacheAddImageFile(pszPath, pszDstName, NULL /*pszExtraSuff*/, RTDBG_CACHE_UUID_MAP_DIR_IMAGES, &Cfg); 1140 1197 break; 1141 1198 … … 1150 1207 memcpy(szPathBuf, pszPath, cchPath + 1); 1151 1208 if (enmType == RTDBGSYMCACHEFILETYPE_DEBUG_BUNDLE) 1152 rc = rtDbgSymCacheAddDebugBundle(szPathBuf, cchPath - cchFilename, cchFilename, &Cfg); 1209 rc = rtDbgSymCacheAddDebugBundle(szPathBuf, cchPath - cchFilename, cchFilename, 1210 pszEqual ? pszDstName : NULL, &Cfg); 1153 1211 else 1154 1212 { 1155 1213 RTDIRENTRYEX DirEntry; 1156 rc = rtDbgSymCacheAddImageBundle(szPathBuf, cchPath - cchFilename, cchFilename, &DirEntry, &Cfg); 1214 rc = rtDbgSymCacheAddImageBundle(szPathBuf, cchPath - cchFilename, cchFilename, 1215 pszEqual ? pszDstName : NULL, &DirEntry, &Cfg); 1157 1216 } 1158 1217 } … … 1166 1225 break; 1167 1226 } 1227 1228 RTStrFree(pszFree); 1168 1229 return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE; 1169 1230 }
Note:
See TracChangeset
for help on using the changeset viewer.