VirtualBox

Changeset 49061 in vbox


Ignore:
Timestamp:
Oct 11, 2013 8:15:59 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
89860
Message:

More Mach-O symbol hacking.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/dbg.h

    r49053 r49061  
    461461RTDECL(int) RTDbgCfgOpenDsymBundle(RTDBGCFG hDbgCfg, const char *pszFilename, PCRTUUID pUuid,
    462462                                   PFNDBGCFGOPEN pfnCallback, void *pvUser1, void *pvUser2);
     463RTDECL(int) RTDbgCfgOpenMachOImage(RTDBGCFG hDbgCfg, const char *pszFilename, PCRTUUID pUuid,
     464                                   PFNDBGCFGOPEN pfnCallback, void *pvUser1, void *pvUser2);
    463465
    464466
  • trunk/include/iprt/mangling.h

    r49044 r49061  
    380380# define RTDbgCfgOpenDbg                                RT_MANGLER(RTDbgCfgOpenDbg)
    381381# define RTDbgCfgOpenDsymBundle                         RT_MANGLER(RTDbgCfgOpenDsymBundle)
     382# define RTDbgCfgOpenMachOImage                         RT_MANGLER(RTDbgCfgOpenMachOImage)
    382383# define RTDbgCfgOpenDwo                                RT_MANGLER(RTDbgCfgOpenDwo)
    383384# define RTDbgCfgOpenPdb70                              RT_MANGLER(RTDbgCfgOpenPdb70)
  • trunk/src/VBox/Debugger/DBGPlugInDarwin.cpp

    r49044 r49061  
    272272                    return VERR_INVALID_NAME;
    273273                if (!strcmp(uLCmd.pSeg32->segname, "__LINKEDIT"))
    274                     continue; /* This usually is discarded or not loaded at all. */
     274                    break; /* This usually is discarded or not loaded at all. */
    275275                if (cSegs >= RT_ELEMENTS(aSegs))
    276276                    return VERR_BUFFER_OVERFLOW;
     
    291291                    return VERR_INVALID_NAME;
    292292                if (!strcmp(uLCmd.pSeg64->segname, "__LINKEDIT"))
    293                     continue; /* This usually is discarded or not loaded at all. */
     293                    break; /* This usually is discarded or not loaded at all. */
    294294                if (cSegs >= RT_ELEMENTS(aSegs))
    295295                    return VERR_BUFFER_OVERFLOW;
     
    388388        uint64_t uRvaNext = 0;
    389389        uint32_t cLinked  = 0;
    390         for (iSeg = 0; iSeg < cSegs; iSeg++)
     390        iSeg = cSegs;
     391        while (iSeg-- > 0) /* HACK: Map in reverse order to avoid replacing __TEXT. */
    391392            if (aSegs[iSeg].cb)
    392393            {
    393                 int rc2 = RTDbgAsModuleLinkSeg(hAs, hMod, iSeg, aSegs[iSeg].Address, RTDBGASLINK_FLAGS_REPLACE /*fFlags*/);
     394                /* Find matching segment in the debug module. */
     395                uint32_t iDbgSeg = 0;
     396                while (iDbgSeg < cSegs)
     397                {
     398                    RTDBGSEGMENT SegInfo;
     399                    int rc3 = RTDbgModSegmentByIndex(hMod, iDbgSeg, &SegInfo);
     400                    if (RT_SUCCESS(rc3) && !strcmp(SegInfo.szName, aSegs[iSeg].szName))
     401                        break;
     402                    iDbgSeg++;
     403                }
     404                AssertMsgStmt(iDbgSeg < cSegs, ("%s\n", aSegs[iSeg].szName), continue);
     405
     406                /* Map it. */
     407                int rc2 = RTDbgAsModuleLinkSeg(hAs, hMod, iDbgSeg, aSegs[iSeg].Address, RTDBGASLINK_FLAGS_REPLACE /*fFlags*/);
    394408                if (RT_SUCCESS(rc2))
    395409                    cLinked++;
  • trunk/src/VBox/Runtime/common/dbg/dbgcfg.cpp

    r49057 r49061  
    184184
    185185
     186/** Interesting bundle suffixes. */
     187static const char * const g_apszBundleSuffixes[] =
     188{
     189    ".kext",
     190    ".app",
     191    ".framework",
     192    ".component",
     193    ".action",
     194    ".caction",
     195    ".bundle",
     196    ".sourcebundle",
     197    ".menu",
     198    ".plugin",
     199    ".ppp",
     200    ".monitorpanel",
     201    ".scripting",
     202    ".prefPane",
     203    ".qlgenerator",
     204    ".brailledriver",
     205    ".saver",
     206    ".SpeechVoice",
     207    ".SpeechRecognizer",
     208    ".SpeechSynthesizer",
     209    ".mdimporter",
     210    ".spreporter",
     211    ".xpc",
     212    NULL
     213};
     214
     215/** Debug bundle suffixes. (Same as above + .dSYM) */
     216static const char * const g_apszDSymBundleSuffixes[] =
     217{
     218    ".dSYM",
     219    ".kext.dSYM",
     220    ".app.dSYM",
     221    ".framework.dSYM",
     222    ".component.dSYM",
     223    ".action.dSYM",
     224    ".caction.dSYM",
     225    ".bundle.dSYM",
     226    ".sourcebundle.dSYM",
     227    ".menu.dSYM",
     228    ".plugin.dSYM",
     229    ".ppp.dSYM",
     230    ".monitorpanel.dSYM",
     231    ".scripting.dSYM",
     232    ".prefPane.dSYM",
     233    ".qlgenerator.dSYM",
     234    ".brailledriver.dSYM",
     235    ".saver.dSYM",
     236    ".SpeechVoice.dSYM",
     237    ".SpeechRecognizer.dSYM",
     238    ".SpeechSynthesizer.dSYM",
     239    ".mdimporter.dSYM",
     240    ".spreporter.dSYM",
     241    ".xpc.dSYM",
     242    NULL
     243};
     244
     245
    186246
    187247/**
     
    374434    if (fCaseInsensitive)
    375435        return rtDbgCfgIsXxxxAndFixCaseWorker(pszPath, cchPath, RTDIRENTRYTYPE_DIRECTORY);
     436
     437    pszPath[cchPath] = '\0';
     438    return false;
     439}
     440
     441
     442/**
     443 * Appends @a pszSubDir1 and @a pszSuffix to @a pszPath and check whether it
     444 * exists and is a directory.
     445 *
     446 * If @a fCaseInsensitive is set, we will do a case insensitive search for a
     447 * matching sub directory.
     448 *
     449 * @returns true / false
     450 * @param   pszPath             The path buffer containing an existing
     451 *                              directory.  RTPATH_MAX in size.
     452 * @param   pszSubDir           The sub directory to append.
     453 * @param   fCaseInsensitive    Whether case insensitive searching is required.
     454 */
     455static bool rtDbgCfgIsDirAndFixCase2(char *pszPath, const char *pszSubDir, const char *pszSuffix, bool fCaseInsensitive)
     456{
     457    Assert(!strpbrk(pszSuffix, ":/\\"));
     458
     459    /* Save the length of the input path so we can restore it in the case
     460       insensitive branch further down. */
     461    size_t const cchPath = strlen(pszPath);
     462
     463    /*
     464     * Append the subdirectory and suffix, then check if we got a hit.
     465     */
     466    int rc = RTPathAppend(pszPath, RTPATH_MAX, pszSubDir);
     467    if (RT_SUCCESS(rc))
     468    {
     469        rc = RTStrCat(pszPath, RTPATH_MAX, pszSuffix);
     470        if (RT_SUCCESS(rc))
     471        {
     472            if (RTDirExists(pszPath))
     473                return true;
     474
     475            /*
     476             * Do case insensitive lookup if requested.
     477             */
     478            if (fCaseInsensitive)
     479                return rtDbgCfgIsXxxxAndFixCaseWorker(pszPath, cchPath, RTDIRENTRYTYPE_DIRECTORY);
     480        }
     481    }
    376482
    377483    pszPath[cchPath] = '\0';
     
    12511357 * Very similar to rtDbgCfgTryOpenDir.
    12521358 */
    1253 static int rtDbgCfgTryOpenDsymBundleInDir(PRTDBGCFGINT pThis, char *pszPath, PRTPATHSPLIT pSplitFn, const char *pszDsymName,
    1254                                           uint32_t fFlags, PFNDBGCFGOPEN pfnCallback, void *pvUser1, void *pvUser2)
     1359static int rtDbgCfgTryOpenDsymBundleInDir(PRTDBGCFGINT pThis, char *pszPath, PRTPATHSPLIT pSplitFn,
     1360                                          const char * const *papszSuffixes, uint32_t fFlags,
     1361                                          PFNDBGCFGOPEN pfnCallback, void *pvUser1, void *pvUser2)
    12551362{
    12561363    int rcRet = VWRN_NOT_FOUND;
     
    12781385    /*
    12791386     * Look for the file with less and less of the original path given.
    1280      */
     1387     * Also try out typical bundle extension variations.
     1388     */
     1389    const char *pszName = pSplitFn->apszComps[pSplitFn->cComps - 1];
    12811390    for (unsigned i = RTPATH_PROP_HAS_ROOT_SPEC(pSplitFn->fProps); i < pSplitFn->cComps; i++)
    12821391    {
     
    12871396            if (!rtDbgCfgIsDirAndFixCase(pszPath, pSplitFn->apszComps[i], fCaseInsensitive))
    12881397                rc2 = VERR_FILE_NOT_FOUND;
    1289         if (    RT_SUCCESS(rc2)
    1290             && !rtDbgCfgIsDirAndFixCase(pszPath, pszDsymName, fCaseInsensitive)
    1291             && !rtDbgCfgIsDirAndFixCase(pszPath, "Contents", fCaseInsensitive)
    1292             && !rtDbgCfgIsDirAndFixCase(pszPath, "Resources", fCaseInsensitive)
    1293             && !rtDbgCfgIsDirAndFixCase(pszPath, "DWARF", fCaseInsensitive))
    1294         {
    1295             if (rtDbgCfgIsFileAndFixCase(pszPath, pSplitFn->apszComps[pSplitFn->cComps - 1], NULL /*pszSuffix*/,
    1296                                          fCaseInsensitive, false, NULL))
     1398        if (RT_SUCCESS(rc2))
     1399        {
     1400            size_t cchCurPath = cchPath + strlen(&pszPath[cchPath]);
     1401            for (uint32_t iSuffix = 0; papszSuffixes[iSuffix]; iSuffix++)
    12971402            {
    1298                 rtDbgCfgLog1(pThis, "Trying '%s'...\n", pszPath);
    1299                 rc2 = pfnCallback(pThis, pszPath, pvUser1, pvUser2);
    1300                 if (rc2 == VINF_CALLBACK_RETURN || rc2 == VERR_CALLBACK_RETURN)
     1403                if (   !rtDbgCfgIsDirAndFixCase2(pszPath, pszName, papszSuffixes[iSuffix], fCaseInsensitive)
     1404                    && !rtDbgCfgIsDirAndFixCase(pszPath, "Contents", fCaseInsensitive)
     1405                    && !rtDbgCfgIsDirAndFixCase(pszPath, "Resources", fCaseInsensitive)
     1406                    && !rtDbgCfgIsDirAndFixCase(pszPath, "DWARF", fCaseInsensitive))
    13011407                {
    1302                     if (rc2 == VINF_CALLBACK_RETURN)
    1303                         rtDbgCfgLog1(pThis, "Found '%s'.\n", pszPath);
    1304                     else
    1305                         rtDbgCfgLog1(pThis, "Error opening '%s'.\n", pszPath);
    1306                     return rc2;
     1408                    if (rtDbgCfgIsFileAndFixCase(pszPath, pszName, NULL /*pszSuffix*/, fCaseInsensitive, false, NULL))
     1409                    {
     1410                        rtDbgCfgLog1(pThis, "Trying '%s'...\n", pszPath);
     1411                        rc2 = pfnCallback(pThis, pszPath, pvUser1, pvUser2);
     1412                        if (rc2 == VINF_CALLBACK_RETURN || rc2 == VERR_CALLBACK_RETURN)
     1413                        {
     1414                            if (rc2 == VINF_CALLBACK_RETURN)
     1415                                rtDbgCfgLog1(pThis, "Found '%s'.\n", pszPath);
     1416                            else
     1417                                rtDbgCfgLog1(pThis, "Error opening '%s'.\n", pszPath);
     1418                            return rc2;
     1419                        }
     1420                        rtDbgCfgLog1(pThis, "Error %Rrc opening '%s'.\n", rc2, pszPath);
     1421                        if (RT_FAILURE(rc2) && RT_SUCCESS_NP(rcRet))
     1422                            rcRet = rc2;
     1423                    }
    13071424                }
    1308                 rtDbgCfgLog1(pThis, "Error %Rrc opening '%s'.\n", rc2, pszPath);
    1309                 if (RT_FAILURE(rc2) && RT_SUCCESS_NP(rcRet))
    1310                     rcRet = rc2;
    13111425            }
    13121426        }
     
    13301444 * Very similar to rtDbgCfgTryOpenList.
    13311445 */
    1332 static int rtDbgCfgTryOpenDsumBundleInList(PRTDBGCFGINT pThis, PRTLISTANCHOR pList, PRTPATHSPLIT pSplitFn,
    1333                                            const char *pszDsymName, const char *pszCacheSubDir, const char *pszCacheSuffix,
    1334                                            const char *pszUuidMappingSubDir, uint32_t fFlags, char *pszPath,
    1335                                            PFNDBGCFGOPEN pfnCallback, void *pvUser1, void *pvUser2)
     1446static int rtDbgCfgTryOpenBundleInList(PRTDBGCFGINT pThis, PRTLISTANCHOR pList, PRTPATHSPLIT pSplitFn,
     1447                                       const char * const *papszSuffixes, const char *pszCacheSubDir,
     1448                                       const char *pszCacheSuffix, const char *pszUuidMappingSubDir,
     1449                                       uint32_t fFlags, char *pszPath,
     1450                                       PFNDBGCFGOPEN pfnCallback, void *pvUser1, void *pvUser2)
    13361451{
    13371452    int rcRet = VWRN_NOT_FOUND;
     
    14591574            RTPathChangeToUnixSlashes(pszPath, false);
    14601575
    1461             rc2 = rtDbgCfgTryOpenDsymBundleInDir(pThis, pszPath, pSplitFn, pszDsymName, fFlagsDir,
     1576            rc2 = rtDbgCfgTryOpenDsymBundleInDir(pThis, pszPath, pSplitFn, papszSuffixes, fFlagsDir,
    14621577                                                 pfnCallback, pvUser1, pvUser2);
    14631578            if (rc2 == VINF_CALLBACK_RETURN || rc2 == VERR_CALLBACK_RETURN)
     
    15231638
    15241639
    1525 RTDECL(int) RTDbgCfgOpenDsymBundle(RTDBGCFG hDbgCfg, const char *pszImage, PCRTUUID pUuid,
    1526                                    PFNDBGCFGOPEN pfnCallback, void *pvUser1, void *pvUser2)
     1640static int rtDbgCfgOpenBundleFile(RTDBGCFG hDbgCfg, const char *pszImage, const char * const *papszSuffixes,
     1641                                  const char *pszBundleSubDir, PCRTUUID pUuid, const char *pszUuidMapDirName,
     1642                                  const char *pszCacheSuffix, bool fOpenImage,
     1643                                  PFNDBGCFGOPEN pfnCallback, void *pvUser1, void *pvUser2)
    15271644{
    15281645    /*
    15291646     * Bundles are directories, means we can forget about sharing code much
    15301647     * with the other RTDbgCfgOpenXXX methods.  Thus we're duplicating a lot of
    1531      * code from rtDbgCfgOpenWithSubDir with .dSYM related adjustments, so, a bug
    1532      * found here or there probably means the other version needs updating.
     1648     * code from rtDbgCfgOpenWithSubDir with .dSYM/.kext/.dylib/.app/.* related
     1649     * adjustments, so, a bug found here or there probably means the other
     1650     * version needs updating.
    15331651     */
    15341652    int rcRet = VINF_SUCCESS;
     
    15611679        pszCacheSubDir = szCacheSubDir;
    15621680
    1563         rc2 = rtDbgCfgConstructUuidMappingSubDir(szUuidMappingSubDir, sizeof(szUuidMappingSubDir),
    1564                                                  RTDBG_CACHE_UUID_MAP_DIR_DSYMS, pUuid);
     1681        rc2 = rtDbgCfgConstructUuidMappingSubDir(szUuidMappingSubDir, sizeof(szUuidMappingSubDir), pszUuidMapDirName, pUuid);
    15651682        AssertRCReturn(rc2, rc2);
    15661683    }
     
    15851702    AssertReturnStmt(pSplitFn->fProps & RTPATH_PROP_FILENAME, RTPathSplitFree(pSplitFn), VERR_IS_A_DIRECTORY);
    15861703
    1587 
    1588 /** @todo Extend this to look for pszFilename*.dSYM as well as detecting a
    1589  *        bundle and looking for a .dSYM bundle outside the image bundle. */
    1590 
    15911704    /*
    15921705     * Try the image directory first.
     
    15961709    {
    15971710        rc2 = RTPathSplitReassemble(pSplitFn, RTPATH_STR_F_STYLE_HOST, szPath, sizeof(szPath));
    1598         if (RT_SUCCESS(rc2))
    1599             rc2 = RTStrCat(szPath, sizeof(szPath),
    1600                            ".dSYM" RTPATH_SLASH_STR "Contents" RTPATH_SLASH_STR "Resources" RTPATH_SLASH_STR "DWARF");
    1601         if (RT_SUCCESS(rc2))
    1602             rc2 = RTPathAppend(szPath, sizeof(szPath), pSplitFn->apszComps[pSplitFn->cComps - 1]);
    1603         if (RT_SUCCESS(rc2))
     1711        if (fOpenImage && RT_SUCCESS(rc2))
     1712        {
     1713            rc2 = RTStrCat(szPath, sizeof(szPath), papszSuffixes[0]);
     1714            if (RT_SUCCESS(rc2))
     1715                rc2 = RTStrCat(szPath, sizeof(szPath), pszBundleSubDir);
     1716            if (RT_SUCCESS(rc2))
     1717                rc2 = RTPathAppend(szPath, sizeof(szPath), pSplitFn->apszComps[pSplitFn->cComps - 1]);
     1718        }
     1719        if (RT_SUCCESS(rc2) && RTPathExists(szPath))
    16041720        {
    16051721            RTPathChangeToUnixSlashes(szPath, false);
     
    16171733        && rc2 != VERR_CALLBACK_RETURN)
    16181734    {
    1619         char *pszDsymName = (char *)alloca(strlen(pSplitFn->apszComps[pSplitFn->cComps - 1]) + sizeof(".dSYM"));
    1620         strcat(strcpy(pszDsymName, pSplitFn->apszComps[pSplitFn->cComps - 1]), ".dSYM");
    1621 
    16221735        /*
    16231736         * Try the current directory (will take cover relative paths
     
    16291742        RTPathChangeToUnixSlashes(szPath, false);
    16301743
    1631         rc2 = rtDbgCfgTryOpenDsymBundleInDir(pThis, szPath, pSplitFn, pszDsymName, fFlags, pfnCallback, pvUser1, pvUser2);
     1744        rc2 = rtDbgCfgTryOpenDsymBundleInDir(pThis, szPath, pSplitFn, g_apszDSymBundleSuffixes,
     1745                                             fFlags, pfnCallback, pvUser1, pvUser2);
    16321746        if (RT_FAILURE(rc2) && RT_SUCCESS_NP(rcRet))
    16331747            rcRet = rc2;
     
    16431757                 * Run the applicable lists.
    16441758                 */
    1645                 rc2 = rtDbgCfgTryOpenDsumBundleInList(pThis, &pThis->PathList, pSplitFn, pszDsymName,
    1646                                                       pszCacheSubDir, RTDBG_CACHE_DSYM_FILE_SUFFIX,
    1647                                                       pszUuidMappingSubDir, fFlags, szPath,
    1648                                                       pfnCallback, pvUser1, pvUser2);
     1759                rc2 = rtDbgCfgTryOpenBundleInList(pThis, &pThis->PathList, pSplitFn, g_apszDSymBundleSuffixes,
     1760                                                  pszCacheSubDir, pszCacheSuffix,
     1761                                                  pszUuidMappingSubDir, fFlags, szPath,
     1762                                                  pfnCallback, pvUser1, pvUser2);
    16491763                if (RT_FAILURE(rc2) && RT_SUCCESS_NP(rcRet))
    16501764                    rcRet = rc2;
     
    16641778        rcRet = VERR_NOT_FOUND;
    16651779    return rcRet;
     1780}
     1781
     1782
     1783RTDECL(int) RTDbgCfgOpenDsymBundle(RTDBGCFG hDbgCfg, const char *pszImage, PCRTUUID pUuid,
     1784                                   PFNDBGCFGOPEN pfnCallback, void *pvUser1, void *pvUser2)
     1785{
     1786    return rtDbgCfgOpenBundleFile(hDbgCfg, pszImage, g_apszDSymBundleSuffixes,
     1787                                  "Contents" RTPATH_SLASH_STR "Resources" RTPATH_SLASH_STR "DWARF",
     1788                                  pUuid, RTDBG_CACHE_UUID_MAP_DIR_DSYMS, RTDBG_CACHE_DSYM_FILE_SUFFIX, false /* fOpenImage */,
     1789                                  pfnCallback, pvUser1, pvUser2);
     1790}
     1791
     1792
     1793RTDECL(int) RTDbgCfgOpenMachOImage(RTDBGCFG hDbgCfg, const char *pszImage, PCRTUUID pUuid,
     1794                                   PFNDBGCFGOPEN pfnCallback, void *pvUser1, void *pvUser2)
     1795{
     1796    return rtDbgCfgOpenBundleFile(hDbgCfg, pszImage, g_apszBundleSuffixes,
     1797                                  "Contents" RTPATH_SLASH_STR "MacOS",
     1798                                  pUuid, RTDBG_CACHE_UUID_MAP_DIR_IMAGES, NULL /*pszCacheSuffix*/, true /* fOpenImage */,
     1799                                  pfnCallback, pvUser1, pvUser2);
    16661800}
    16671801
  • trunk/src/VBox/Runtime/common/dbg/dbgmod.cpp

    r49053 r49061  
    11881188 */
    11891189
     1190
     1191/**
     1192 * Argument package used when opening Mach-O images and .dSYMs files.
     1193 */
     1194typedef struct RTDBGMODMACHOARGS
     1195{
     1196    /** For use more internal use in file locator callbacks. */
     1197    RTLDRARCH           enmArch;
     1198    /** For use more internal use in file locator callbacks. */
     1199    PCRTUUID            pUuid;
     1200    /** For use more internal use in file locator callbacks. */
     1201    bool                fOpenImage;
     1202} RTDBGMODMACHOARGS;
     1203/** Pointer to a const segment package. */
     1204typedef RTDBGMODMACHOARGS const *PCRTDBGMODMACHOARGS;
     1205
     1206
     1207
    11901208/** @callback_method_impl{FNRTDBGCFGOPEN} */
    11911209static DECLCALLBACK(int)
    1192 rtDbgModFromMachOImageOpenMachOCallback(RTDBGCFG hDbgCfg, const char *pszFilename, void *pvUser1, void *pvUser2)
    1193 {
    1194     PRTDBGMODINT        pDbgMod   = (PRTDBGMODINT)pvUser1;
    1195     PCRTDBGDWARFSEGPKG  pSegPkg   = (PCRTDBGDWARFSEGPKG)pvUser2;
    1196 
    1197     /** @todo  */
    1198 
    1199     return VERR_OPEN_FAILED;
    1200 }
    1201 
    1202 
    1203 /** @callback_method_impl{FNRTDBGCFGOPEN} */
    1204 static DECLCALLBACK(int)
    1205 rtDbgModFromMachOImageOpenDsymCallback(RTDBGCFG hDbgCfg, const char *pszFilename, void *pvUser1, void *pvUser2)
    1206 {
    1207     PRTDBGMODINT        pDbgMod   = (PRTDBGMODINT)pvUser1;
    1208     PCRTDBGDWARFSEGPKG  pSegPkg   = (PCRTDBGDWARFSEGPKG)pvUser2;
     1210rtDbgModFromMachOImageOpenDsymMachOCallback(RTDBGCFG hDbgCfg, const char *pszFilename, void *pvUser1, void *pvUser2)
     1211{
     1212    PRTDBGMODINT        pDbgMod = (PRTDBGMODINT)pvUser1;
     1213    PCRTDBGMODMACHOARGS pArgs   = (PCRTDBGMODMACHOARGS)pvUser2;
    12091214
    12101215    Assert(!pDbgMod->pDbgVt);
     
    12361241            pDbgMod->pImgVt    = pImg->pVt;
    12371242            pDbgMod->pvImgPriv = NULL;
    1238             rc = pImg->pVt->pfnTryOpen(pDbgMod, pSegPkg->enmArch);
     1243            rc = pImg->pVt->pfnTryOpen(pDbgMod, pArgs->enmArch);
    12391244            if (RT_SUCCESS(rc))
    12401245                break;
     
    12481253             * Check the UUID if one was given.
    12491254             */
    1250             if (pSegPkg->pUuid)
     1255            if (pArgs->pUuid)
    12511256            {
    12521257                RTUUID UuidOpened;
     
    12541259                if (RT_SUCCESS(rc))
    12551260                {
    1256                     if (RTUuidCompare(&UuidOpened, pSegPkg->pUuid) != 0)
     1261                    if (RTUuidCompare(&UuidOpened, pArgs->pUuid) != 0)
    12571262                        rc = VERR_DBG_FILE_MISMATCH;
    12581263                }
     
    12671272                for (PRTDBGMODREGDBG pDbg = g_pDbgHead; pDbg; pDbg = pDbg->pNext)
    12681273                {
    1269                     if (pDbg->pVt->fSupports & RT_DBGTYPE_DWARF)
     1274                    if (   pArgs->fOpenImage
     1275                        || (pDbg->pVt->fSupports & RT_DBGTYPE_DWARF) )
     1276
    12701277                    {
    12711278                        pDbgMod->pDbgVt    = pDbg->pVt;
    1272                         pDbgMod->pvDbgPriv = pSegPkg->cSegs ? (void *)pSegPkg : NULL;
     1279                        pDbgMod->pvDbgPriv = NULL;
    12731280                        rc = pDbg->pVt->pfnTryOpen(pDbgMod, pDbgMod->pImgVt->pfnGetArch(pDbgMod));
    12741281                        if (RT_SUCCESS(rc))
     
    12861293                    }
    12871294                }
     1295
     1296                /*
     1297                 * Likely fallback for when opening image.
     1298                 */
     1299                if (pArgs->fOpenImage)
     1300                {
     1301                    rc = rtDbgModCreateForExports(pDbgMod);
     1302                    if (RT_SUCCESS(rc))
     1303                    {
     1304                        /*
     1305                         * Done.
     1306                         */
     1307                        RTSemRWReleaseRead(g_hDbgModRWSem);
     1308                        RTStrCacheRelease(g_hDbgModStrCache, pszImgFileOrg);
     1309                        return VINF_CALLBACK_RETURN;
     1310                    }
     1311                }
    12881312            }
    12891313
     
    13071331                                        uint32_t cSegs, PCRTDBGSEGMENT paSegs, PCRTUUID pUuid, RTDBGCFG hDbgCfg)
    13081332{
    1309     RTDBGDWARFSEGPKG SegPkg;
    1310     SegPkg.cSegs    = cSegs;
    1311     SegPkg.paSegs   = paSegs;
    1312     SegPkg.enmArch  = enmArch;
    1313     SegPkg.pUuid    = pUuid && RTUuidIsNull(pUuid) ? pUuid : NULL;
     1333    RTDBGMODMACHOARGS Args;
     1334    Args.enmArch    = enmArch;
     1335    Args.pUuid      = pUuid && RTUuidIsNull(pUuid) ? pUuid : NULL;
     1336    Args.fOpenImage = false;
    13141337
    13151338    /*
     
    13171340     */
    13181341    int rc = RTDbgCfgOpenDsymBundle(hDbgCfg, pDbgMod->pszImgFile, pUuid,
    1319                                     rtDbgModFromMachOImageOpenDsymCallback, pDbgMod, &SegPkg);
     1342                                    rtDbgModFromMachOImageOpenDsymMachOCallback, pDbgMod, &Args);
    13201343    if (RT_FAILURE(rc))
    13211344    {
     
    13231346         * If we cannot get at the .dSYM, try the executable image.
    13241347         */
    1325         //rc = RTDbgCfgOpenMachOImage(hDbgCfg, pDbgMod->pszImgFile, pUuid,
    1326         //                            rtDbgModFromMachOImageOpenMachOCallback, pDbgMod, &SegPkg);
     1348        Args.fOpenImage = true;
     1349        rc = RTDbgCfgOpenMachOImage(hDbgCfg, pDbgMod->pszImgFile, pUuid,
     1350                                    rtDbgModFromMachOImageOpenDsymMachOCallback, pDbgMod, &Args);
    13271351    }
    13281352    return rc;
     
    13981422                 */
    13991423                if (   !(fDbgCfg & RTDBGCFG_FLAGS_DEFERRED)
     1424                    || cSegs /* for the time being. */
    14001425                    || (!cbImage && !cSegs)
    14011426                    || (fFlags & RTDBGMOD_F_NOT_DEFERRED) )
     
    14061431                     * Procrastinate.  Need image size atm.
    14071432                     */
    1408                     uint32_t uRvaMax = cbImage;
    1409                     if (!uRvaMax)
    1410                         for (uint32_t iSeg = 0; iSeg < cSegs; iSeg++)
    1411                         {
    1412                             if (   paSegs[iSeg].uRva > uRvaMax
    1413                                 && paSegs[iSeg].uRva - uRvaMax < _1M)
    1414                                 uRvaMax = paSegs[iSeg].uRva;
    1415                             uRvaMax += paSegs[iSeg].cb;
    1416                         }
    1417 
    14181433                    PRTDBGMODDEFERRED pDeferred;
    1419                     rc = rtDbgModDeferredCreate(pDbgMod, rtDbgModFromMachOImageDeferredCallback, uRvaMax, hDbgCfg,
     1434                    rc = rtDbgModDeferredCreate(pDbgMod, rtDbgModFromMachOImageDeferredCallback, cbImage, hDbgCfg,
    14201435                                                RT_OFFSETOF(RTDBGMODDEFERRED, u.MachO.aSegs[cSegs]),
    14211436                                                &pDeferred);
     
    14261441                        pDeferred->u.MachO.cSegs   = cSegs;
    14271442                        if (cSegs)
    1428                         {
    14291443                            memcpy(&pDeferred->u.MachO.aSegs, paSegs, cSegs * sizeof(paSegs[0]));
    1430                             if (!cbImage)
    1431                             {
    1432                                 /* If we calculated a cbImage above, do corresponding RVA adjustments. */
    1433                                 uRvaMax = 0;
    1434                                 for (uint32_t iSeg = 0; iSeg < cSegs; iSeg++)
    1435                                 {
    1436                                     if (   paSegs[iSeg].uRva > uRvaMax
    1437                                         && paSegs[iSeg].uRva - uRvaMax < _1M)
    1438                                         uRvaMax = paSegs[iSeg].uRva;
    1439                                     else
    1440                                         pDeferred->u.MachO.aSegs[iSeg].uRva = uRvaMax;
    1441                                     uRvaMax += paSegs[iSeg].cb;
    1442                                 }
    1443                             }
    1444                         }
    14451444                    }
    14461445                }
  • trunk/src/VBox/Runtime/include/internal/dbgmod.h

    r49044 r49061  
    641641
    642642
    643 /**
    644  * Special segment package used passing segment order information for mach-o
    645  * images (mainly mach_kernel, really).
    646  *
    647  * Passes to rtDbgModDwarf_TryOpen via RTDBGMODINF::pvDbgPriv.
    648  */
    649 typedef struct RTDBGDWARFSEGPKG
    650 {
    651     /** Pointer to the segment array. */
    652     PCRTDBGSEGMENT      paSegs;
    653     /** Number of segments. */
    654     uint32_t            cSegs;
    655     /** For use more internal use in file locator callbacks. */
    656     RTLDRARCH           enmArch;
    657     /** For use more internal use in file locator callbacks. */
    658     PCRTUUID            pUuid;
    659 } RTDBGDWARFSEGPKG;
    660 /** Pointer to a const segment package. */
    661 typedef RTDBGDWARFSEGPKG const *PCRTDBGDWARFSEGPKG;
    662 
    663 
    664643extern DECLHIDDEN(RTSTRCACHE)           g_hDbgModStrCache;
    665644extern DECLHIDDEN(RTDBGMODVTDBG const)  g_rtDbgModVtDbgCodeView;
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