Skip to content

Commit 8a5d29c

Browse files
committed
[MachO] Set display name of memory regions to match the segment names they correspond to
1 parent ade5807 commit 8a5d29c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

view/macho/machoview.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,30 @@ bool MachoView::InitializeHeader(MachOHeader& header, bool isMainHeader, uint64_
16301630
}
16311631
EndBulkAddSegments();
16321632

1633+
if (auto memoryMap = GetMemoryMap())
1634+
{
1635+
for (auto& segment : header.segments)
1636+
{
1637+
if (segment.initprot == MACHO_VM_PROT_NONE || !segment.vmsize)
1638+
continue;
1639+
1640+
auto region = memoryMap->GetActiveMemoryRegionAt(segment.vmaddr);
1641+
if (region.empty())
1642+
continue;
1643+
1644+
std::string segmentName(segment.segname, std::find(segment.segname, std::end(segment.segname), '\0'));
1645+
memoryMap->SetMemoryRegionDisplayName(region, segmentName);
1646+
1647+
if (segment.vmsize == segment.filesize)
1648+
continue;
1649+
1650+
uint64_t zeroFillStart = segment.vmaddr + segment.filesize;
1651+
auto zeroFillRegion = memoryMap->GetActiveMemoryRegionAt(zeroFillStart);
1652+
if (!zeroFillRegion.empty())
1653+
memoryMap->SetMemoryRegionDisplayName(zeroFillRegion, segmentName + " (zero fill)");
1654+
}
1655+
}
1656+
16331657
for (auto& section : header.sections)
16341658
{
16351659
char sectionName[17];

0 commit comments

Comments
 (0)