VirtualBox

Ignore:
Timestamp:
Feb 15, 2020 2:20:17 AM (5 years ago)
Author:
vboxsync
Message:

RTDbgSymCache: Added way to specify filename to use in the cache. Corrected UUID symlinks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/tools/RTDbgSymCache.cpp

    r82968 r83078  
    174174{
    175175    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));
    177186    return RTEXITCODE_SUCCESS;
    178187}
     
    239248     */
    240249    char szLinkTarget[RTPATH_MAX];
    241     //szMapPath[cch] = '\0';
     250    szMapPath[cch] = '\0';
    242251    rc = RTPathCalcRelative(szLinkTarget, sizeof(szLinkTarget), szMapPath, false /*fFromFile*/, pszCacheFile);
    243     //szMapPath[cch] = RTPATH_SLASH;
     252    szMapPath[cch] = RTPATH_SLASH;
    244253    if (RT_FAILURE(rc))
    245254        return RTMsgErrorRc(rc, "Failed to calculate relative path from '%s' to '%s': %Rrc", szMapPath, pszCacheFile, rc);
     
    395404 * @returns IPRT status code.
    396405 * @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.
    397408 * @param   pCfg                Configuration data.
    398409 * @param   hLdrMod             Image handle.
     
    405416 *                              com.apple.DebugSymbols in the user defaults.
    406417 */
    407 static int rtDbgSymCacheAddImageFileWorker(const char *pszPath, PCRTDBGSYMCACHEADDCFG pCfg, RTLDRMOD hLdrMod,
    408                                            const char *pszExtrSuff, const char *pszUuidMapDir)
     418static int rtDbgSymCacheAddImageFileWorker(const char *pszPath, const char *pszDstName, PCRTDBGSYMCACHEADDCFG pCfg,
     419                                           RTLDRMOD hLdrMod, const char *pszExtrSuff, const char *pszUuidMapDir)
    409420{
    410421    /*
     
    459470     * Now add it.
    460471     */
    461     return rtDbgSymCacheAddOneFile(pszPath, RTPathFilename(pszPath), pszExtrSuff,
    462                                    szSubDir, pUuid, pszUuidMapDir, pCfg);
     472    return rtDbgSymCacheAddOneFile(pszPath, pszDstName, pszExtrSuff, szSubDir, pUuid, pszUuidMapDir, pCfg);
    463473}
    464474
     
    469479 * @returns IPRT status code.
    470480 * @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.
    471483 * @param   pszExtraSuff    Optional extra suffix. Mach-O dSYM hack.
    472484 * @param   pszUuidMapDir   The UUID map subdirectory in the cache, if this is
     
    474486 * @param   pCfg            Configuration data.
    475487 */
    476 static int rtDbgSymCacheAddImageFile(const char *pszPath, const char *pszExtraSuff, const char *pszUuidMapDir,
    477                                      PCRTDBGSYMCACHEADDCFG pCfg)
    478 {
     488static int rtDbgSymCacheAddImageFile(const char *pszPath, const char *pszDstName, const char *pszExtraSuff,
     489                                     const char *pszUuidMapDir, PCRTDBGSYMCACHEADDCFG pCfg)
     490{
     491    RTERRINFOSTATIC ErrInfo;
     492
    479493    /*
    480494     * Use the loader to open the alleged image file.  We need to open it with
     
    485499    /* Open it as AMD64. */
    486500    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));
    488502    if (RT_FAILURE(rc))
    489503    {
     
    491505        {
    492506            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
    494511            RTMsgInfo("Skipping '%s', no a recognizable image file...", pszPath);
    495512            return VINF_SUCCESS;
     
    500517    /* Open it as X86. */
    501518    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));
    503520    if (RT_FAILURE(rc))
    504521    {
    505522        if (rc != VERR_LDR_ARCH_MISMATCH)
    506523        {
    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 : "");
    509528        }
    510529        hLdrMod32 = NIL_RTLDRMOD;
     
    515534     */
    516535    if (hLdrMod32 == NIL_RTLDRMOD)
    517         rc = rtDbgSymCacheAddImageFileWorker(pszPath, pCfg, hLdrMod64, pszExtraSuff, pszUuidMapDir);
     536        rc = rtDbgSymCacheAddImageFileWorker(pszPath, pszDstName, pCfg, hLdrMod64, pszExtraSuff, pszUuidMapDir);
    518537    else if (hLdrMod64 == NIL_RTLDRMOD)
    519         rc = rtDbgSymCacheAddImageFileWorker(pszPath, pCfg, hLdrMod32, pszExtraSuff, pszUuidMapDir);
     538        rc = rtDbgSymCacheAddImageFileWorker(pszPath, pszDstName, pCfg, hLdrMod32, pszExtraSuff, pszUuidMapDir);
    520539    else
    521540    {
     
    548567        }
    549568
    550         rc = rtDbgSymCacheAddImageFileWorker(pszPath, pCfg, hLdrMod64, pszExtraSuff, pszUuidMapDir);
     569        rc = rtDbgSymCacheAddImageFileWorker(pszPath, pszDstName, pCfg, hLdrMod64, pszExtraSuff, pszUuidMapDir);
    551570        if (!fSame)
    552571        {
    553572            /** @todo should symlink or hardlink this second copy. */
    554             int rc2 = rtDbgSymCacheAddImageFileWorker(pszPath, pCfg, hLdrMod32, pszExtraSuff, pszUuidMapDir);
     573            int rc2 = rtDbgSymCacheAddImageFileWorker(pszPath, pszDstName, pCfg, hLdrMod32, pszExtraSuff, pszUuidMapDir);
    555574            if (RT_FAILURE(rc2) && RT_SUCCESS(rc))
    556575                rc = rc2;
     
    570589 * @returns IPRT status code
    571590 * @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.
    572593 * @param   pCfg                The configuration.
    573594 * @param   hFile               Handle to the file.
    574595 */
    575 static int rtDbgSymCacheAddDebugMachO(const char *pszPath, PCRTDBGSYMCACHEADDCFG pCfg)
     596static int rtDbgSymCacheAddDebugMachO(const char *pszPath, const char *pszDstName, PCRTDBGSYMCACHEADDCFG pCfg)
    576597{
    577598    /* This shouldn't happen, figure out what to do if it does. */
    578     RT_NOREF_PV(pCfg);
     599    RT_NOREF(pCfg, pszDstName);
    579600    return RTMsgErrorRc(VERR_NOT_IMPLEMENTED,
    580601                        "'%s' is an OS X image file, did you point me to a file inside a .dSYM or .sym file?",
     
    588609 * @returns IPRT status code
    589610 * @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.
    590613 * @param   pCfg                The configuration.
    591614 * @param   hFile               Handle to the file.
    592615 */
    593 static int rtDbgSymCacheAddDebugPdb(const char *pszPath, PCRTDBGSYMCACHEADDCFG pCfg, RTFILE hFile)
    594 {
    595     RT_NOREF2(pCfg, hFile);
     616static int rtDbgSymCacheAddDebugPdb(const char *pszPath, const char *pszDstName, PCRTDBGSYMCACHEADDCFG pCfg, RTFILE hFile)
     617{
     618    RT_NOREF(pCfg, hFile, pszDstName);
    596619    return RTMsgErrorRc(VERR_NOT_IMPLEMENTED, "PDB support not implemented: '%s'", pszPath);
    597620}
     
    603626 * @returns IPRT status code
    604627 * @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.
    605630 * @param   pCfg                The configuration.
    606631 */
    607 static int rtDbgSymCacheAddDebugFile(const char *pszPath, PCRTDBGSYMCACHEADDCFG pCfg)
     632static int rtDbgSymCacheAddDebugFile(const char *pszPath, const char *pszDstName, PCRTDBGSYMCACHEADDCFG pCfg)
    608633{
    609634    /*
     
    634659         */
    635660        if (!memcmp(uBuf.ab, RT_STR_TUPLE("Microsoft C/C++ MSF 7.00")))
    636             rc = rtDbgSymCacheAddDebugPdb(pszPath, pCfg, hFile);
     661            rc = rtDbgSymCacheAddDebugPdb(pszPath, pszDstName, pCfg, hFile);
    637662        else if (   uBuf.au32[0] == IMAGE_FAT_SIGNATURE
    638663                 || uBuf.au32[0] == IMAGE_FAT_SIGNATURE_OE
     
    641666                 || uBuf.au32[0] == IMAGE_MACHO32_SIGNATURE_OE
    642667                 || uBuf.au32[0] == IMAGE_MACHO64_SIGNATURE_OE)
    643             rc = rtDbgSymCacheAddDebugMachO(pszPath, pCfg);
     668            rc = rtDbgSymCacheAddDebugMachO(pszPath, pszDstName, pCfg);
    644669        else
    645670            rc = RTMsgErrorRc(VERR_INVALID_MAGIC, "Unsupported debug file '%s' magic: %#010x", pszPath, uBuf.au32[0]);
     
    721746 *
    722747 * @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 */
     760static int rtDbgSymCacheAddImageBundle(char *pszPath, size_t cchPath, size_t cchName, const char *pszDstName,
    734761                                       PRTDIRENTRYEX pDirEntry, PCRTDBGSYMCACHEADDCFG pCfg)
    735762{
     
    741768    int rc = rtDbgSymCacheConstructBundlePath(pszPath, cchPath, cchName, "Contents/MacOS/", g_apszBundleSuffixes);
    742769    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    }
    744775
    745776    /*
     
    788819 *
    789820 * @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 */
     831static int rtDbgSymCacheAddDebugBundle(char *pszPath, size_t cchPath, size_t cchName, const char *pszDstName,
     832                                       PCRTDBGSYMCACHEADDCFG pCfg)
    799833{
    800834    /*
     
    815849    int rc = rtDbgSymCacheConstructBundlePath(pszPath, cchPath, cchName, "Contents/Resources/DWARF/", g_apszDSymBundleSuffixes);
    816850    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    }
    818856    return rc;
    819857}
     
    10181056
    10191057            case RTDBGSYMCACHEFILETYPE_DEBUG_FILE:
    1020                 rc2 = rtDbgSymCacheAddDebugFile(pszPath, pCfg);
     1058                rc2 = rtDbgSymCacheAddDebugFile(pszPath, pDirEntry->szName, pCfg);
    10211059                break;
    10221060
    10231061            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);
    10251063                break;
    10261064
    10271065            case RTDBGSYMCACHEFILETYPE_DEBUG_BUNDLE:
    1028                 rc2 = rtDbgSymCacheAddDebugBundle(pszPath, cchPath, pDirEntry->cbName, pCfg);
     1066                rc2 = rtDbgSymCacheAddDebugBundle(pszPath, cchPath, pDirEntry->cbName, NULL /*pszDstName*/, pCfg);
    10291067                break;
    10301068
    10311069            case RTDBGSYMCACHEFILETYPE_IMAGE_BUNDLE:
    1032                 rc2 = rtDbgSymCacheAddImageBundle(pszPath, cchPath, pDirEntry->cbName, pDirEntry, pCfg);
     1070                rc2 = rtDbgSymCacheAddImageBundle(pszPath, cchPath, pDirEntry->cbName, NULL /*pszDstName*/, pDirEntry, pCfg);
    10331071                break;
    10341072
     
    11171155    Cfg.pszFilter       = NULL;
    11181156
     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
    11191172    int rc;
    11201173    RTDBGSYMCACHEFILETYPE enmType = rtDbgSymCacheFigureType(pszPath);
     
    11231176        default:
    11241177        case RTDBGSYMCACHEFILETYPE_INVALID:
    1125             return RTMsgErrorExit(RTEXITCODE_FAILURE, "Invalid: '%s'", pszPath);
     1178            rc = RTMsgErrorRc(VERR_INVALID_PARAMETER, "Invalid: '%s'", pszPath);
     1179            break;
    11261180
    11271181        case RTDBGSYMCACHEFILETYPE_DIR_FILTER:
     
    11291183            RT_FALL_THRU();
    11301184        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!");
    11321189            break;
    11331190
    11341191        case RTDBGSYMCACHEFILETYPE_DEBUG_FILE:
    1135             rc = rtDbgSymCacheAddDebugFile(pszPath, &Cfg);
     1192            rc = rtDbgSymCacheAddDebugFile(pszPath, pszDstName, &Cfg);
    11361193            break;
    11371194
    11381195        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);
    11401197            break;
    11411198
     
    11501207                memcpy(szPathBuf, pszPath, cchPath + 1);
    11511208                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);
    11531211                else
    11541212                {
    11551213                    RTDIRENTRYEX DirEntry;
    1156                     rc = rtDbgSymCacheAddImageBundle(szPathBuf, cchPath - cchFilename, cchFilename, &DirEntry, &Cfg);
     1214                    rc = rtDbgSymCacheAddImageBundle(szPathBuf, cchPath - cchFilename, cchFilename,
     1215                                                     pszEqual ? pszDstName : NULL, &DirEntry, &Cfg);
    11571216                }
    11581217            }
     
    11661225            break;
    11671226    }
     1227
     1228    RTStrFree(pszFree);
    11681229    return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
    11691230}
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