- Timestamp:
- Jan 2, 2015 12:43:39 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ExtPacks/VBoxDTrace/VBoxDTraceR0/VBoxDTraceR0.cpp
r53700 r53704 1352 1352 * @param offStrTab The string table offset. 1353 1353 */ 1354 static const char *vboxDtVtgGetString(PVTGOBJHDR pVtgHdr, 1354 static const char *vboxDtVtgGetString(PVTGOBJHDR pVtgHdr, uint32_t offStrTab) 1355 1355 { 1356 1356 Assert(offStrTab < pVtgHdr->cbStrTab); 1357 return &pVtgHdr->pachStrTab[offStrTab];1357 return (const char *)pVtgHdr + pVtgHdr->offStrTab + offStrTab; 1358 1358 } 1359 1359 … … 1381 1381 if (pProv->TracerData.DTrace.fZombie) 1382 1382 return; 1383 1383 1384 1384 dtrace_provider_id_t const idProvider = pProv->TracerData.DTrace.idProvider; 1385 1385 AssertPtrReturnVoid(idProvider); 1386 1386 1387 1387 AssertPtrReturnVoid(pProv->pHdr); 1388 PVTGPROBELOC pProbeLoc = pProv->pHdr->paProbLocs;1389 PVTGPROBELOC pProbeLocEnd = pProv->pHdr->paProbLocsEnd;1390 if (pProv->TracerData.DTrace.cProvidedProbes >= (uintptr_t)(pProbeLocEnd - pProbeLoc))1391 return; 1388 AssertReturnVoid(pProv->pHdr->offProbeLocs != 0); 1389 uint32_t const cProbeLocs = pProv->pHdr->cbProbeLocs / sizeof(VTGPROBELOC); 1390 uint32_t const cbProbeLocRW = pProv->pHdr->cBits == 32 ? sizeof(VTGPROBELOC32) : sizeof(VTGPROBELOC64); 1391 1392 1392 1393 1393 /* Need a buffer for extracting the function names and mangling them in 1394 1394 case of collision. */ 1395 size_t const cbFnNmBuf= _4K + _1K;1395 size_t const cbFnNmBuf = _4K + _1K; 1396 1396 char *pszFnNmBuf = (char *)RTMemAlloc(cbFnNmBuf); 1397 1397 if (!pszFnNmBuf) … … 1402 1402 * this provider. 1403 1403 */ 1404 uint16_t idxProv = (uint16_t)(&pProv->pHdr->paProviders[0] - pProv->pDesc); 1405 while ((uintptr_t)pProbeLoc < (uintptr_t)pProbeLocEnd) 1406 { 1407 PVTGDESCPROBE pProbeDesc = (PVTGDESCPROBE)pProbeLoc->pbProbe; 1408 if ( pProbeDesc->idxProvider == idxProv 1409 && pProbeLoc->idProbe == UINT32_MAX) 1404 uint16_t const idxProv = (uint16_t)((PVTGDESCPROVIDER)((uintptr_t)pProv->pHdr + pProv->pHdr->offProviders) - pProv->pDesc); 1405 for (uint32_t idxProbeLoc = 0; idxProbeLoc < cProbeLocs; idxProbeLoc++) 1406 { 1407 /* Skip probe location belonging to other providers or once that 1408 we've already reported. */ 1409 PCVTGPROBELOC pProbeLocRO = &pProv->paProbeLocsRO[idxProbeLoc]; 1410 PVTGDESCPROBE pProbeDesc = (PVTGDESCPROBE)pProbeLocRO->pbProbe; 1411 if (pProbeDesc->idxProvider == idxProv) 1412 continue; 1413 1414 uint32_t *pidProbe; 1415 if (!pProv->fUmod) 1416 pidProbe = (uint32_t *)&pProbeLocRO->idProbe; 1417 else 1418 pidProbe = &pProv->paR0ProbeLocs[idxProbeLoc].idProbe; 1419 if (*pidProbe == UINT32_MAX) 1420 continue; 1421 1422 /* The function name may need to be stripped since we're using C++ 1423 compilers for most of the code. ASSUMES nobody are brave/stupid 1424 enough to use function pointer returns without typedef'ing 1425 properly them (e.g. signal). */ 1426 const char *pszPrbName = vboxDtVtgGetString(pProv->pHdr, pProbeDesc->offName); 1427 const char *pszFunc = pProbeLocRO->pszFunction; 1428 const char *psz = strchr(pProbeLocRO->pszFunction, '('); 1429 size_t cch; 1430 if (psz) 1410 1431 { 1411 /* The function name normally needs to be stripped since we're 1412 using C++ compilers for most of the code. ASSUMES nobody are 1413 brave/stupid enough to use function pointer returns without 1414 typedef'ing properly them. */ 1415 const char *pszPrbName = vboxDtVtgGetString(pProv->pHdr, pProbeDesc->offName); 1416 const char *pszFunc = pProbeLoc->pszFunction; 1417 const char *psz = strchr(pProbeLoc->pszFunction, '('); 1418 size_t cch; 1419 if (psz) 1432 /* skip blanks preceeding the parameter parenthesis. */ 1433 while ( (uintptr_t)psz > (uintptr_t)pProbeLocRO->pszFunction 1434 && RT_C_IS_BLANK(psz[-1])) 1435 psz--; 1436 1437 /* Find the start of the function name. */ 1438 pszFunc = psz - 1; 1439 while ((uintptr_t)pszFunc > (uintptr_t)pProbeLocRO->pszFunction) 1420 1440 { 1421 /* skip blanks preceeding the parameter parenthesis. */ 1422 while ( (uintptr_t)psz > (uintptr_t)pProbeLoc->pszFunction 1423 && RT_C_IS_BLANK(psz[-1])) 1424 psz--; 1425 1426 /* Find the start of the function name. */ 1427 pszFunc = psz - 1; 1428 while ((uintptr_t)pszFunc > (uintptr_t)pProbeLoc->pszFunction) 1429 { 1430 char ch = pszFunc[-1]; 1431 if (!RT_C_IS_ALNUM(ch) && ch != '_' && ch != ':') 1432 break; 1433 pszFunc--; 1434 } 1435 cch = psz - pszFunc; 1441 char ch = pszFunc[-1]; 1442 if (!RT_C_IS_ALNUM(ch) && ch != '_' && ch != ':') 1443 break; 1444 pszFunc--; 1436 1445 } 1437 else 1438 cch = strlen(pszFunc); 1439 RTStrCopyEx(pszFnNmBuf, cbFnNmBuf, pszFunc, cch); 1440 1441 /* Look up the probe, if we have one in the same function, mangle 1442 the function name a little to avoid having to deal with having 1443 multiple location entries with the same probe ID. (lazy bird) */ 1444 Assert(pProbeLoc->idProbe == UINT32_MAX); 1446 cch = psz - pszFunc; 1447 } 1448 else 1449 cch = strlen(pszFunc); 1450 RTStrCopyEx(pszFnNmBuf, cbFnNmBuf, pszFunc, cch); 1451 1452 /* Look up the probe, if we have one in the same function, mangle 1453 the function name a little to avoid having to deal with having 1454 multiple location entries with the same probe ID. (lazy bird) */ 1455 Assert(*pidProbe == UINT32_MAX); 1456 if (dtrace_probe_lookup(idProvider, pProv->pszModName, pszFnNmBuf, pszPrbName) != DTRACE_IDNONE) 1457 { 1458 RTStrPrintf(pszFnNmBuf+cch, cbFnNmBuf - cch, "-%u", pProbeLocRO->uLine); 1445 1459 if (dtrace_probe_lookup(idProvider, pProv->pszModName, pszFnNmBuf, pszPrbName) != DTRACE_IDNONE) 1446 1460 { 1447 RTStrPrintf(pszFnNmBuf+cch, cbFnNmBuf - cch, "-%u", pProbeLoc->uLine);1448 if (dtrace_probe_lookup(idProvider, pProv->pszModName, pszFnNmBuf, pszPrbName) != DTRACE_IDNONE)1461 unsigned iOrd = 2; 1462 while (iOrd < 128) 1449 1463 { 1450 unsigned iOrd = 2; 1451 while (iOrd < 128) 1452 { 1453 RTStrPrintf(pszFnNmBuf+cch, cbFnNmBuf - cch, "-%u-%u", pProbeLoc->uLine, iOrd); 1454 if (dtrace_probe_lookup(idProvider, pProv->pszModName, pszFnNmBuf, pszPrbName) == DTRACE_IDNONE) 1455 break; 1456 iOrd++; 1457 } 1458 if (iOrd >= 128) 1459 { 1460 LogRel(("VBoxDrv: More than 128 duplicate probe location instances %s at line %u in function %s [%s], probe %s\n", 1461 pProbeLoc->uLine, pProbeLoc->pszFunction, pszFnNmBuf, pszPrbName)); 1462 continue; 1463 } 1464 RTStrPrintf(pszFnNmBuf+cch, cbFnNmBuf - cch, "-%u-%u", pProbeLocRO->uLine, iOrd); 1465 if (dtrace_probe_lookup(idProvider, pProv->pszModName, pszFnNmBuf, pszPrbName) == DTRACE_IDNONE) 1466 break; 1467 iOrd++; 1468 } 1469 if (iOrd >= 128) 1470 { 1471 LogRel(("VBoxDrv: More than 128 duplicate probe location instances %s at line %u in function %s [%s], probe %s\n", 1472 pProbeLocRO->uLine, pProbeLocRO->pszFunction, pszFnNmBuf, pszPrbName)); 1473 continue; 1464 1474 } 1465 1475 } 1466 1467 /* Create the probe. */1468 AssertCompile(sizeof(pProbeLoc->idProbe) == sizeof(dtrace_id_t));1469 pProbeLoc->idProbe = dtrace_probe_create(idProvider, pProv->pszModName, pszFnNmBuf, pszPrbName,1470 1 /*aframes*/, pProbeLoc);1471 pProv->TracerData.DTrace.cProvidedProbes++;1472 1476 } 1473 1477 1474 pProbeLoc++; 1478 /* Create the probe. */ 1479 AssertCompile(sizeof(*pidProbe) == sizeof(dtrace_id_t)); 1480 *pidProbe = dtrace_probe_create(idProvider, pProv->pszModName, pszFnNmBuf, pszPrbName, 1481 1 /*aframes*/, (void *)(uintptr_t)idxProbeLoc); 1482 pProv->TracerData.DTrace.cProvidedProbes++; 1475 1483 } 1476 1484 … … 1483 1491 */ 1484 1492 static int vboxDtPOps_Enable(void *pvProv, dtrace_id_t idProbe, void *pvProbe) 1493 { 1494 PSUPDRVVDTPROVIDERCORE pProv = (PSUPDRVVDTPROVIDERCORE)pvProv; 1495 if (!pProv->TracerData.DTrace.fZombie) 1496 { 1497 uint32_t idxProbeLoc = (uint32_t)(uintptr_t)pvProbe; 1498 PVTGPROBELOC32 pProbeLocEn = (PVTGPROBELOC32)( (uintptr_t)pProv->pvProbeLocsEn + idxProbeLoc * pProv->cbProbeLocsEn); 1499 PCVTGPROBELOC pProbeLocRO = (PVTGPROBELOC)&pProv->paProbeLocsRO[idxProbeLoc]; 1500 PCVTGDESCPROBE pProbeDesc = (PVTGDESCPROBE)pProbeLocRO->pbProbe; 1501 uint32_t const idxProbe = pProbeDesc->idxEnabled; 1502 1503 if (!pProv->fUmod) 1504 { 1505 if (!pProbeLocEn->fEnabled) 1506 { 1507 pProbeLocEn->fEnabled = 1; 1508 ASMAtomicIncU32(&pProv->pacProbeEnabled[idxProbe]); 1509 } 1510 } 1511 else 1512 { 1513 /* Update kernel mode structure */ 1514 if (!pProv->paR0ProbeLocs[idxProbeLoc].fEnabled) 1515 { 1516 pProv->paR0ProbeLocs[idxProbeLoc].fEnabled = 1; 1517 ASMAtomicIncU32(&pProv->paR0Probes[idxProbe].cEnabled); 1518 } 1519 1520 /* Update user mode structure. */ 1521 pProbeLocEn->fEnabled = 1; 1522 pProv->pacProbeEnabled[idxProbe] = pProv->paR0Probes[idxProbe].cEnabled; 1523 } 1524 } 1525 1526 return 0; 1527 } 1528 1529 1530 /** 1531 * @callback_method_impl{dtrace_pops_t,dtps_disable} 1532 */ 1533 static void vboxDtPOps_Disable(void *pvProv, dtrace_id_t idProbe, void *pvProbe) 1485 1534 { 1486 1535 PSUPDRVVDTPROVIDERCORE pProv = (PSUPDRVVDTPROVIDERCORE)pvProv; 1487 1536 if (!pProv->TracerData.DTrace.fZombie) 1488 1537 { 1489 PVTGPROBELOC pProbeLoc = (PVTGPROBELOC)pvProbe; 1490 PVTGDESCPROBE pProbeDesc = (PVTGDESCPROBE)pProbeLoc->pbProbe; 1491 1492 if (!pProbeLoc->fEnabled) 1538 uint32_t idxProbeLoc = (uint32_t)(uintptr_t)pvProbe; 1539 PVTGPROBELOC32 pProbeLocEn = (PVTGPROBELOC32)( (uintptr_t)pProv->pvProbeLocsEn + idxProbeLoc * pProv->cbProbeLocsEn); 1540 PCVTGPROBELOC pProbeLocRO = (PVTGPROBELOC)&pProv->paProbeLocsRO[idxProbeLoc]; 1541 PCVTGDESCPROBE pProbeDesc = (PVTGDESCPROBE)pProbeLocRO->pbProbe; 1542 uint32_t const idxProbe = pProbeDesc->idxEnabled; 1543 1544 if (!pProv->fUmod) 1493 1545 { 1494 pProbeLoc->fEnabled = 1; 1495 if (ASMAtomicIncU32(&pProbeDesc->u32User) == 1) 1496 pProv->pHdr->pafProbeEnabled[pProbeDesc->idxEnabled] = 1; 1546 if (pProbeLocEn->fEnabled) 1547 { 1548 pProbeLocEn->fEnabled = 0; 1549 ASMAtomicDecU32(&pProv->pacProbeEnabled[idxProbe]); 1550 } 1497 1551 } 1498 } 1499 1500 return 0; 1501 } 1502 1503 1504 /** 1505 * @callback_method_impl{dtrace_pops_t,dtps_disable} 1506 */ 1507 static void vboxDtPOps_Disable(void *pvProv, dtrace_id_t idProbe, void *pvProbe) 1508 { 1509 PSUPDRVVDTPROVIDERCORE pProv = (PSUPDRVVDTPROVIDERCORE)pvProv; 1510 if (!pProv->TracerData.DTrace.fZombie) 1511 { 1512 PVTGPROBELOC pProbeLoc = (PVTGPROBELOC)pvProbe; 1513 PVTGDESCPROBE pProbeDesc = (PVTGDESCPROBE)pProbeLoc->pbProbe; 1514 1515 if (pProbeLoc->fEnabled) 1552 else 1516 1553 { 1517 pProbeLoc->fEnabled = 0; 1518 if (ASMAtomicDecU32(&pProbeDesc->u32User) == 0) 1519 pProv->pHdr->pafProbeEnabled[pProbeDesc->idxEnabled] = 0; 1554 /* Update kernel mode structure */ 1555 if (pProv->paR0ProbeLocs[idxProbeLoc].fEnabled) 1556 { 1557 pProv->paR0ProbeLocs[idxProbeLoc].fEnabled = 0; 1558 ASMAtomicDecU32(&pProv->paR0Probes[idxProbe].cEnabled); 1559 } 1560 1561 /* Update user mode structure. */ 1562 pProbeLocEn->fEnabled = 0; 1563 pProv->pacProbeEnabled[idxProbe] = pProv->paR0Probes[idxProbe].cEnabled; 1520 1564 } 1521 1565 } … … 1535 1579 if (!pProv->TracerData.DTrace.fZombie) 1536 1580 { 1537 PVTGPROBELOC pProbeLoc = (PVTGPROBELOC)pvProbe; 1538 PVTGDESCPROBE pProbeDesc = (PVTGDESCPROBE)pProbeLoc->pbProbe; 1539 PVTGDESCARGLIST pArgList = (PVTGDESCARGLIST)((uintptr_t)pProv->pHdr->paArgLists + pProbeDesc->offArgList); 1540 1581 uint32_t idxProbeLoc = (uint32_t)(uintptr_t)pvProbe; 1582 PCVTGPROBELOC pProbeLocRO = (PVTGPROBELOC)&pProv->paProbeLocsRO[idxProbeLoc]; 1583 PCVTGDESCPROBE pProbeDesc = (PVTGDESCPROBE)pProbeLocRO->pbProbe; 1584 PCVTGDESCARGLIST pArgList = (PCVTGDESCARGLIST)( (uintptr_t)pProv->pHdr 1585 + pProv->pHdr->offArgLists 1586 + pProbeDesc->offArgList); 1541 1587 AssertReturnVoid(pProbeDesc->offArgList < pProv->pHdr->cbArgLists); 1588 1542 1589 if (uArg < pArgList->cArgs) 1543 1590 { … … 1586 1633 } 1587 1634 1635 NOREF(pvProbe); 1588 1636 return UINT64_MAX; 1589 1637 } … … 1598 1646 if (!pProv->TracerData.DTrace.fZombie) 1599 1647 { 1600 PVTGPROBELOC pProbeLoc = (PVTGPROBELOC)pvProbe; 1601 Assert(!pProbeLoc->fEnabled); 1602 Assert(pProbeLoc->idProbe == idProbe); NOREF(idProbe); 1603 pProbeLoc->idProbe = UINT32_MAX; 1648 uint32_t idxProbeLoc = (uint32_t)(uintptr_t)pvProbe; 1649 PCVTGPROBELOC pProbeLocRO = (PVTGPROBELOC)&pProv->paProbeLocsRO[idxProbeLoc]; 1650 uint32_t *pidProbe; 1651 if (!pProv->fUmod) 1652 { 1653 pidProbe = (uint32_t *)&pProbeLocRO->idProbe; 1654 Assert(!pProbeLocRO->fEnabled); 1655 Assert(*pidProbe == idProbe); 1656 } 1657 else 1658 { 1659 pidProbe = &pProv->paR0ProbeLocs[idxProbeLoc].idProbe; 1660 Assert(!pProv->paR0ProbeLocs[idxProbeLoc].fEnabled); 1661 Assert(*pidProbe == idProbe); NOREF(idProbe); 1662 } 1663 *pidProbe = UINT32_MAX; 1604 1664 } 1605 1665 pProv->TracerData.DTrace.cProvidedProbes--;
Note:
See TracChangeset
for help on using the changeset viewer.