Changeset 49044 in vbox for trunk/src/VBox/Runtime/common/dbg
- Timestamp:
- Oct 11, 2013 1:06:28 AM (11 years ago)
- Location:
- trunk/src/VBox/Runtime/common/dbg
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/dbg/dbgcfg.cpp
r46161 r49044 1425 1425 int rc2; 1426 1426 1427 //RTStrPrintf(szFile, sizeof(szFile), "%s.dSYM/Contents/Resources/DWARF/%s", pszFilename, pszFilename);1428 1429 1427 /* 1430 1428 * Do a little validating first. … … 1543 1541 rcRet = VERR_NOT_FOUND; 1544 1542 return rcRet; 1545 1546 1547 1543 } 1548 1544 -
trunk/src/VBox/Runtime/common/dbg/dbgmod.cpp
r49040 r49044 47 47 #include <iprt/strcache.h> 48 48 #include <iprt/string.h> 49 #include <iprt/uuid.h> 49 50 #include "internal/dbgmod.h" 50 51 #include "internal/magics.h" … … 326 327 AssertPtrReturn(pszName, VERR_INVALID_POINTER); 327 328 AssertReturn(*pszName, VERR_INVALID_PARAMETER); 328 AssertReturn(fFlags == 0 , VERR_INVALID_PARAMETER);329 AssertReturn(fFlags == 0 || fFlags == RTDBGMOD_F_NOT_DEFERRED, VERR_INVALID_PARAMETER); 329 330 330 331 int rc = rtDbgModLazyInit(); … … 1135 1136 { 1136 1137 PRTDBGMODDEFERRED pDeferred; 1137 rc = rtDbgModDeferredCreate(pDbgMod, rtDbgModFromPeImageDeferredCallback, cbImage, hDbgCfg, &pDeferred); 1138 rc = rtDbgModDeferredCreate(pDbgMod, rtDbgModFromPeImageDeferredCallback, cbImage, hDbgCfg, 0, 1139 &pDeferred); 1138 1140 if (RT_SUCCESS(rc)) 1139 1141 pDeferred->u.PeImage.uTimestamp = uTimestamp; … … 1170 1172 1171 1173 1174 1175 1176 /* 1177 * 1178 * M a c h - O I M A G E 1179 * M a c h - O I M A G E 1180 * M a c h - O I M A G E 1181 * 1182 */ 1183 1184 /** @callback_method_impl{FNRTDBGCFGOPEN} */ 1185 static DECLCALLBACK(int) 1186 rtDbgModFromMachOImageOpenMachOCallback(RTDBGCFG hDbgCfg, const char *pszFilename, void *pvUser1, void *pvUser2) 1187 { 1188 PRTDBGMODINT pDbgMod = (PRTDBGMODINT)pvUser1; 1189 PCRTDBGDWARFSEGPKG pSegPkg = (PCRTDBGDWARFSEGPKG)pvUser2; 1190 1191 /** @todo */ 1192 1193 return VERR_OPEN_FAILED; 1194 } 1195 1196 1197 /** @callback_method_impl{FNRTDBGCFGOPEN} */ 1198 static DECLCALLBACK(int) 1199 rtDbgModFromMachOImageOpenDsymCallback(RTDBGCFG hDbgCfg, const char *pszFilename, void *pvUser1, void *pvUser2) 1200 { 1201 PRTDBGMODINT pDbgMod = (PRTDBGMODINT)pvUser1; 1202 PCRTDBGDWARFSEGPKG pSegPkg = (PCRTDBGDWARFSEGPKG)pvUser2; 1203 1204 Assert(!pDbgMod->pDbgVt); 1205 Assert(!pDbgMod->pvDbgPriv); 1206 Assert(!pDbgMod->pszDbgFile); 1207 Assert(!pDbgMod->pImgVt); 1208 Assert(!pDbgMod->pvDbgPriv); 1209 Assert(pDbgMod->pszImgFile); 1210 Assert(pDbgMod->pszImgFileSpecified); 1211 1212 const char *pszImgFileOrg = pDbgMod->pszImgFile; 1213 pDbgMod->pszImgFile = RTStrCacheEnter(g_hDbgModStrCache, pszFilename); 1214 if (!pDbgMod->pszImgFile) 1215 return VERR_NO_STR_MEMORY; 1216 RTStrCacheRetain(pDbgMod->pszImgFile); 1217 pDbgMod->pszDbgFile = pDbgMod->pszImgFile; 1218 1219 /* 1220 * Try image interpreters as the dwarf file inside the dSYM bundle is a 1221 * Mach-O file with dwarf debug sections insides it and no code or data. 1222 */ 1223 int rc = RTSemRWRequestRead(g_hDbgModRWSem, RT_INDEFINITE_WAIT); 1224 if (RT_SUCCESS(rc)) 1225 { 1226 rc = VERR_DBG_NO_MATCHING_INTERPRETER; 1227 PRTDBGMODREGIMG pImg; 1228 for (pImg = g_pImgHead; pImg; pImg = pImg->pNext) 1229 { 1230 pDbgMod->pImgVt = pImg->pVt; 1231 pDbgMod->pvImgPriv = NULL; 1232 rc = pImg->pVt->pfnTryOpen(pDbgMod, pSegPkg->enmArch); 1233 if (RT_SUCCESS(rc)) 1234 break; 1235 pDbgMod->pImgVt = NULL; 1236 Assert(pDbgMod->pvImgPriv == NULL); 1237 } 1238 1239 if (RT_SUCCESS(rc)) 1240 { 1241 /* 1242 * Check the UUID if one was given. 1243 */ 1244 if (pSegPkg->pUuid) 1245 { 1246 RTUUID UuidOpened; 1247 rc = pDbgMod->pImgVt->pfnQueryProp(pDbgMod, RTLDRPROP_UUID, &UuidOpened, sizeof(UuidOpened)); 1248 if (RT_SUCCESS(rc)) 1249 { 1250 if (RTUuidCompare(&UuidOpened, pSegPkg->pUuid) != 0) 1251 rc = VERR_DBG_FILE_MISMATCH; 1252 } 1253 else if (rc == VERR_NOT_FOUND || rc == VERR_NOT_IMPLEMENTED) 1254 rc = VERR_DBG_FILE_MISMATCH; 1255 } 1256 if (RT_SUCCESS(rc)) 1257 { 1258 /* 1259 * Pass it to the DWARF reader(s). 1260 */ 1261 for (PRTDBGMODREGDBG pDbg = g_pDbgHead; pDbg; pDbg = pDbg->pNext) 1262 { 1263 if (pDbg->pVt->fSupports & RT_DBGTYPE_DWARF) 1264 { 1265 pDbgMod->pDbgVt = pDbg->pVt; 1266 pDbgMod->pvDbgPriv = pSegPkg->cSegs ? (void *)pSegPkg : NULL; 1267 rc = pDbg->pVt->pfnTryOpen(pDbgMod, pDbgMod->pImgVt->pfnGetArch(pDbgMod)); 1268 if (RT_SUCCESS(rc)) 1269 { 1270 /* 1271 * Got it! 1272 */ 1273 ASMAtomicIncU32(&pDbg->cUsers); 1274 RTSemRWReleaseRead(g_hDbgModRWSem); 1275 RTStrCacheRelease(g_hDbgModStrCache, pszImgFileOrg); 1276 return VINF_CALLBACK_RETURN; 1277 } 1278 pDbgMod->pDbgVt = NULL; 1279 Assert(pDbgMod->pvDbgPriv == NULL); 1280 } 1281 } 1282 } 1283 1284 pDbgMod->pImgVt->pfnClose(pDbgMod); 1285 pDbgMod->pImgVt = NULL; 1286 pDbgMod->pvImgPriv = NULL; 1287 } 1288 } 1289 1290 /* No joy. */ 1291 RTSemRWReleaseRead(g_hDbgModRWSem); 1292 RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszImgFile); 1293 pDbgMod->pszImgFile = pszImgFileOrg; 1294 RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszDbgFile); 1295 pDbgMod->pszDbgFile = NULL; 1296 return rc; 1297 } 1298 1299 1300 static int rtDbgModFromMachOImageWorker(PRTDBGMODINT pDbgMod, RTLDRARCH enmArch, uint32_t cbImage, 1301 uint32_t cSegs, PCRTDBGSEGMENT paSegs, PCRTUUID pUuid, RTDBGCFG hDbgCfg) 1302 { 1303 RTDBGDWARFSEGPKG SegPkg; 1304 SegPkg.cSegs = cSegs; 1305 SegPkg.paSegs = paSegs; 1306 SegPkg.enmArch = enmArch; 1307 SegPkg.pUuid = pUuid && RTUuidIsNull(pUuid) ? pUuid : NULL; 1308 1309 /* 1310 * Search for the .dSYM bundle first, since that's generally all we need. 1311 */ 1312 int rc = RTDbgCfgOpenDsymBundle(hDbgCfg, pDbgMod->pszImgFile, pUuid, 1313 rtDbgModFromMachOImageOpenDsymCallback, pDbgMod, &SegPkg); 1314 if (RT_FAILURE(rc)) 1315 { 1316 /* 1317 * If we cannot get at the .dSYM, try the executable image. 1318 */ 1319 //rc = RTDbgCfgOpenMachOImage(hDbgCfg, pDbgMod->pszImgFile, pUuid, 1320 // rtDbgModFromMachOImageOpenMachOCallback, pDbgMod, &SegPkg); 1321 } 1322 return rc; 1323 } 1324 1325 1326 /** @callback_method_impl{FNRTDBGMODDEFERRED} */ 1327 static DECLCALLBACK(int) rtDbgModFromMachOImageDeferredCallback(PRTDBGMODINT pDbgMod, PRTDBGMODDEFERRED pDeferred) 1328 { 1329 return rtDbgModFromMachOImageWorker(pDbgMod, pDeferred->u.MachO.enmArch, pDeferred->cbImage, 1330 pDeferred->u.MachO.cSegs, pDeferred->u.MachO.aSegs, 1331 &pDeferred->u.MachO.Uuid, pDeferred->hDbgCfg); 1332 } 1333 1334 1335 RTDECL(int) RTDbgModCreateFromMachOImage(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, 1336 RTLDRARCH enmArch, uint32_t cbImage, uint32_t cSegs, PCRTDBGSEGMENT paSegs, 1337 PCRTUUID pUuid, RTDBGCFG hDbgCfg, uint32_t fFlags) 1338 { 1339 /* 1340 * Input validation and lazy initialization. 1341 */ 1342 AssertPtrReturn(phDbgMod, VERR_INVALID_POINTER); 1343 *phDbgMod = NIL_RTDBGMOD; 1344 AssertPtrReturn(pszFilename, VERR_INVALID_POINTER); 1345 AssertReturn(*pszFilename, VERR_INVALID_PARAMETER); 1346 if (!pszName) 1347 pszName = RTPathFilenameEx(pszFilename, RTPATH_STR_F_STYLE_HOST); 1348 AssertPtrReturn(pszName, VERR_INVALID_POINTER); 1349 if (cSegs) 1350 { 1351 AssertReturn(cSegs < 1024, VERR_INVALID_PARAMETER); 1352 AssertPtrReturn(paSegs, VERR_INVALID_POINTER); 1353 AssertReturn(!cbImage, VERR_INVALID_PARAMETER); 1354 } 1355 AssertReturn(cbImage || cSegs, VERR_INVALID_PARAMETER); 1356 AssertPtrNullReturn(pUuid, VERR_INVALID_POINTER); 1357 AssertReturn(!(fFlags & ~(RTDBGMOD_F_NOT_DEFERRED)), VERR_INVALID_PARAMETER); 1358 1359 int rc = rtDbgModLazyInit(); 1360 if (RT_FAILURE(rc)) 1361 return rc; 1362 1363 uint64_t fDbgCfg = 0; 1364 if (hDbgCfg) 1365 { 1366 rc = RTDbgCfgQueryUInt(hDbgCfg, RTDBGCFGPROP_FLAGS, &fDbgCfg); 1367 AssertRCReturn(rc, rc); 1368 } 1369 1370 /* 1371 * Allocate a new module instance. 1372 */ 1373 PRTDBGMODINT pDbgMod = (PRTDBGMODINT)RTMemAllocZ(sizeof(*pDbgMod)); 1374 if (!pDbgMod) 1375 return VERR_NO_MEMORY; 1376 pDbgMod->u32Magic = RTDBGMOD_MAGIC; 1377 pDbgMod->cRefs = 1; 1378 rc = RTCritSectInit(&pDbgMod->CritSect); 1379 if (RT_SUCCESS(rc)) 1380 { 1381 pDbgMod->pszName = RTStrCacheEnterLower(g_hDbgModStrCache, pszName); 1382 if (pDbgMod->pszName) 1383 { 1384 pDbgMod->pszImgFile = RTStrCacheEnter(g_hDbgModStrCache, pszFilename); 1385 if (pDbgMod->pszImgFile) 1386 { 1387 RTStrCacheRetain(pDbgMod->pszImgFile); 1388 pDbgMod->pszImgFileSpecified = pDbgMod->pszImgFile; 1389 1390 /* 1391 * Load it immediately? 1392 */ 1393 if ( !(fDbgCfg & RTDBGCFG_FLAGS_DEFERRED) 1394 || (!cbImage && !cSegs) 1395 || (fFlags & RTDBGMOD_F_NOT_DEFERRED) ) 1396 rc = rtDbgModFromMachOImageWorker(pDbgMod, enmArch, cbImage, cSegs, paSegs, pUuid, hDbgCfg); 1397 else 1398 { 1399 /* 1400 * Procrastinate. Need image size atm. 1401 */ 1402 uint32_t uRvaMax = cbImage; 1403 if (!uRvaMax) 1404 for (uint32_t iSeg = 0; iSeg < cSegs; iSeg++) 1405 { 1406 if ( paSegs[iSeg].uRva > uRvaMax 1407 && paSegs[iSeg].uRva - uRvaMax < _1M) 1408 uRvaMax = paSegs[iSeg].uRva; 1409 uRvaMax += paSegs[iSeg].cb; 1410 } 1411 1412 PRTDBGMODDEFERRED pDeferred; 1413 rc = rtDbgModDeferredCreate(pDbgMod, rtDbgModFromMachOImageDeferredCallback, uRvaMax, hDbgCfg, 1414 RT_OFFSETOF(RTDBGMODDEFERRED, u.MachO.aSegs[cSegs]), 1415 &pDeferred); 1416 if (RT_SUCCESS(rc)) 1417 { 1418 pDeferred->u.MachO.Uuid = *pUuid; 1419 pDeferred->u.MachO.enmArch = enmArch; 1420 pDeferred->u.MachO.cSegs = cSegs; 1421 if (cSegs) 1422 { 1423 memcpy(&pDeferred->u.MachO.aSegs, paSegs, cSegs * sizeof(paSegs[0])); 1424 if (!cbImage) 1425 { 1426 /* If we calculated a cbImage above, do corresponding RVA adjustments. */ 1427 uRvaMax = 0; 1428 for (uint32_t iSeg = 0; iSeg < cSegs; iSeg++) 1429 { 1430 if ( paSegs[iSeg].uRva > uRvaMax 1431 && paSegs[iSeg].uRva - uRvaMax < _1M) 1432 uRvaMax = paSegs[iSeg].uRva; 1433 else 1434 pDeferred->u.MachO.aSegs[iSeg].uRva = uRvaMax; 1435 uRvaMax += paSegs[iSeg].cb; 1436 } 1437 } 1438 } 1439 } 1440 } 1441 if (RT_SUCCESS(rc)) 1442 { 1443 *phDbgMod = pDbgMod; 1444 return VINF_SUCCESS; 1445 } 1446 1447 /* Failed, bail out. */ 1448 RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszName); 1449 } 1450 else 1451 rc = VERR_NO_STR_MEMORY; 1452 RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszImgFileSpecified); 1453 RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszImgFile); 1454 } 1455 else 1456 rc = VERR_NO_STR_MEMORY; 1457 RTCritSectDelete(&pDbgMod->CritSect); 1458 } 1459 1460 RTMemFree(pDbgMod); 1461 return rc; 1462 } 1463 1464 1465 1466 RT_EXPORT_SYMBOL(RTDbgModCreateFromMachOImage); 1467 1468 1469 1172 1470 /** 1173 1471 * Destroys an module after the reference count has reached zero. -
trunk/src/VBox/Runtime/common/dbg/dbgmoddeferred.cpp
r46281 r49044 439 439 * 440 440 */ 441 442 /** @interface_method_impl{RTDBGMODVTIMG,pfnQueryProp} */ 443 static DECLCALLBACK(int ) rtDbgModDeferredImg_QueryProp(PRTDBGMODINT pMod, RTLDRPROP enmProp, void *pvBuf, size_t cbBuf) 444 { 445 int rc = rtDbgModDeferredDoIt(pMod, false /*fForceRetry*/); 446 if (RT_SUCCESS(rc)) 447 rc = pMod->pImgVt->pfnQueryProp(pMod, enmProp, pvBuf, cbBuf); 448 return rc; 449 } 441 450 442 451 … … 593 602 /*.pfnGetFormat = */ rtDbgModDeferredImg_GetFormat, 594 603 /*.pfnGetArch = */ rtDbgModDeferredImg_GetArch, 604 /*.pfnQueryProp = */ rtDbgModDeferredImg_QueryProp, 595 605 596 606 /*.u32EndMagic = */ RTDBGMODVTIMG_MAGIC … … 608 618 * @param hDbgCfg The debug config handle. Can be NIL. A 609 619 * reference will be retained. 620 * @param cbDeferred The size of the deferred instance data, 0 if the 621 * default structure is good enough. 610 622 * @param ppDeferred Where to return the instance data. Can be NULL. 611 623 */ 612 624 DECLHIDDEN(int) rtDbgModDeferredCreate(PRTDBGMODINT pDbgMod, PFNRTDBGMODDEFERRED pfnDeferred, RTUINTPTR cbImage, 613 RTDBGCFG hDbgCfg, PRTDBGMODDEFERRED *ppDeferred)625 RTDBGCFG hDbgCfg, size_t cbDeferred, PRTDBGMODDEFERRED *ppDeferred) 614 626 { 615 627 AssertReturn(!pDbgMod->pDbgVt, VERR_DBG_MOD_IPE); 616 628 617 PRTDBGMODDEFERRED pDeferred = (PRTDBGMODDEFERRED)RTMemAllocZ(sizeof(*pDeferred)); 629 if (cbDeferred < sizeof(RTDBGMODDEFERRED)) 630 cbDeferred = sizeof(RTDBGMODDEFERRED); 631 PRTDBGMODDEFERRED pDeferred = (PRTDBGMODDEFERRED)RTMemAllocZ(cbDeferred); 618 632 if (!pDeferred) 619 633 return VERR_NO_MEMORY; -
trunk/src/VBox/Runtime/common/dbg/dbgmodldr.cpp
r46266 r49044 5 5 6 6 /* 7 * Copyright (C) 2011 Oracle Corporation7 * Copyright (C) 2011-2013 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 59 59 typedef RTDBGMODLDR *PRTDBGMODLDR; 60 60 61 62 63 /** @interface_method_impl{RTDBGMODVTIMG,pfnQueryProp} */ 64 static DECLCALLBACK(int) rtDbgModLdr_QueryProp(PRTDBGMODINT pMod, RTLDRPROP enmProp, void *pvBuf, size_t cbBuf) 65 { 66 PRTDBGMODLDR pThis = (PRTDBGMODLDR)pMod->pvImgPriv; 67 return RTLdrQueryProp(pThis->hLdrMod, enmProp, pvBuf, cbBuf); 68 } 61 69 62 70 … … 216 224 /*.pfnGetFormat = */ rtDbgModLdr_GetFormat, 217 225 /*.pfnGetArch = */ rtDbgModLdr_GetArch, 226 /*.pfnQueryProp = */ rtDbgModLdr_QueryProp, 218 227 219 228 /*.u32EndMagic = */ RTDBGMODVTIMG_MAGIC
Note:
See TracChangeset
for help on using the changeset viewer.