@@ -1420,48 +1420,22 @@ bool LLScan::ScanHeapForObjects(lldb::SBTarget target,
1420
1420
// Reload process anyway
1421
1421
process_ = target.GetProcess ();
1422
1422
1423
- // Need to reload memory ranges (though this does assume the user has also
1424
- // updated
1425
- // LLNODE_RANGESFILE with data for the new dump or things won't match up).
1423
+ // Need to reload memory regions.
1426
1424
if (target_ != target) {
1427
- ClearMemoryRanges ();
1428
1425
ClearMapsToInstances ();
1429
1426
ClearReferences ();
1430
1427
target_ = target;
1431
1428
}
1432
1429
1433
- #ifndef LLDB_SBMemoryRegionInfoList_h_
1434
- /* Fall back to environment variable containing pre-parsed list of memory
1435
- * ranges. */
1436
- if (nullptr == ranges_) {
1437
- const char * segmentsfilename = getenv (" LLNODE_RANGESFILE" );
1438
-
1439
- if (segmentsfilename == nullptr ) {
1440
- result.SetError (
1441
- " No memory range information available for this process. Cannot scan "
1442
- " for objects.\n "
1443
- " Please set `LLNODE_RANGESFILE` environment variable\n " );
1444
- return false ;
1445
- }
1446
-
1447
- if (!GenerateMemoryRanges (target, segmentsfilename)) {
1448
- result.SetError (
1449
- " No memory range information available for this process. Cannot scan "
1450
- " for objects.\n " );
1451
- return false ;
1452
- }
1453
- }
1454
- #endif // LLDB_SBMemoryRegionInfoList_h_
1455
-
1456
1430
/* If we've reached here we have access to information about the valid memory
1457
- * ranges in the process and can scan for objects.
1431
+ * regions in the process and can scan for objects.
1458
1432
*/
1459
1433
1460
1434
/* Populate the map of objects. */
1461
1435
if (mapstoinstances_.empty ()) {
1462
1436
FindJSObjectsVisitor v (target, this );
1463
1437
1464
- ScanMemoryRanges (v);
1438
+ ScanMemoryRegions (v);
1465
1439
}
1466
1440
1467
1441
return true ;
@@ -1539,25 +1513,14 @@ inline static ByteOrder GetHostByteOrder() {
1539
1513
return u.b == 1 ? ByteOrder::eByteOrderBig : ByteOrder::eByteOrderLittle;
1540
1514
}
1541
1515
1542
- void LLScan::ScanMemoryRanges (FindJSObjectsVisitor& v) {
1543
- bool done = false ;
1544
-
1516
+ void LLScan::ScanMemoryRegions (FindJSObjectsVisitor& v) {
1545
1517
const uint64_t addr_size = process_.GetAddressByteSize ();
1546
1518
bool swap_bytes = process_.GetByteOrder () != GetHostByteOrder ();
1547
1519
1548
1520
// Pages are usually around 1mb, so this should more than enough
1549
1521
const uint64_t block_size = 1024 * 1024 * addr_size;
1550
1522
unsigned char * block = new unsigned char [block_size];
1551
1523
1552
- #ifndef LLDB_SBMemoryRegionInfoList_h_
1553
- MemoryRange* head = ranges_;
1554
-
1555
- while (head != nullptr && !done) {
1556
- uint64_t address = head->start_ ;
1557
- uint64_t len = head->length_ ;
1558
- head = head->next_ ;
1559
-
1560
- #else // LLDB_SBMemoryRegionInfoList_h_
1561
1524
lldb::SBMemoryRegionInfoList memory_regions = process_.GetMemoryRegions ();
1562
1525
lldb::SBMemoryRegionInfo region_info;
1563
1526
@@ -1571,7 +1534,6 @@ void LLScan::ScanMemoryRanges(FindJSObjectsVisitor& v) {
1571
1534
uint64_t address = region_info.GetRegionBase ();
1572
1535
uint64_t len = region_info.GetRegionEnd () - region_info.GetRegionBase ();
1573
1536
1574
- #endif // LLDB_SBMemoryRegionInfoList_h_
1575
1537
/* Brute force search - query every address - but allow the visitor code to
1576
1538
* say how far to move on so we don't read every byte.
1577
1539
*/
@@ -1614,7 +1576,6 @@ void LLScan::ScanMemoryRanges(FindJSObjectsVisitor& v) {
1614
1576
}
1615
1577
1616
1578
if (increment == 0 ) {
1617
- done = true ;
1618
1579
break ;
1619
1580
}
1620
1581
}
@@ -1623,73 +1584,6 @@ void LLScan::ScanMemoryRanges(FindJSObjectsVisitor& v) {
1623
1584
delete[] block;
1624
1585
}
1625
1586
1626
-
1627
- /* Read a file of memory ranges parsed from the core dump.
1628
- * This is a work around for the lack of an API to get the memory ranges
1629
- * within lldb.
1630
- * There are scripts for generating this file on Mac and Linux stored in
1631
- * the scripts directory of the llnode repository.
1632
- * Export the name or full path to the ranges file in the LLNODE_RANGESFILE
1633
- * env var before starting lldb and loading the llnode plugin.
1634
- */
1635
- bool LLScan::GenerateMemoryRanges (lldb::SBTarget target,
1636
- const char * segmentsfilename) {
1637
- std::ifstream input (segmentsfilename);
1638
-
1639
- if (!input.is_open ()) {
1640
- return false ;
1641
- }
1642
-
1643
- uint64_t address = 0 ;
1644
- uint64_t len = 0 ;
1645
-
1646
- MemoryRange** tailptr = &ranges_;
1647
-
1648
- lldb::addr_t address_byte_size = target.GetProcess ().GetAddressByteSize ();
1649
-
1650
- while (input >> std::hex >> address >> std::hex >> len) {
1651
- /* Check if the range is accessible.
1652
- * The structure of a core file means if you check the start and the end of
1653
- * a range then the middle will be there, ranges are contiguous in the file,
1654
- * but cores often get truncated due to file size limits so ranges can be
1655
- * missing or truncated. Sometimes shared memory segments are omitted so
1656
- * it's also possible an entire section could be missing from the middle.
1657
- */
1658
- lldb::SBError error;
1659
-
1660
- target.GetProcess ().ReadPointerFromMemory (address, error);
1661
- if (!error.Success ()) {
1662
- /* Could not access first word, skip. */
1663
- continue ;
1664
- }
1665
-
1666
- target.GetProcess ().ReadPointerFromMemory (
1667
- (address + len) - address_byte_size, error);
1668
- if (!error.Success ()) {
1669
- /* Could not access last word, skip. */
1670
- continue ;
1671
- }
1672
-
1673
- MemoryRange* newRange = new MemoryRange (address, len);
1674
-
1675
- *tailptr = newRange;
1676
- tailptr = &(newRange->next_ );
1677
- }
1678
- return true ;
1679
- }
1680
-
1681
-
1682
- void LLScan::ClearMemoryRanges () {
1683
- MemoryRange* head = ranges_;
1684
- while (head != nullptr ) {
1685
- MemoryRange* range = head;
1686
- head = head->next_ ;
1687
- delete range;
1688
- }
1689
- ranges_ = nullptr ;
1690
- }
1691
-
1692
-
1693
1587
void LLScan::ClearMapsToInstances () {
1694
1588
TypeRecord* t;
1695
1589
for (auto entry : mapstoinstances_) {
0 commit comments