9#include "llvm/ADT/ScopeExit.h"
10#include "llvm/ADT/StringRef.h"
51#include "llvm/ADT/DenseSet.h"
52#include "llvm/Support/Compression.h"
53#include "llvm/Support/Endian.h"
54#include "llvm/Support/FormatVariadic.h"
55#include "llvm/Support/MemoryBuffer.h"
61#include <TargetConditionals.h>
64#include <mach/mach_init.h>
65#include <mach/vm_map.h>
86#ifdef CPU_TYPE_ARM64_32
87#undef CPU_TYPE_ARM64_32
98#ifdef LC_VERSION_MIN_MACOSX
99#undef LC_VERSION_MIN_MACOSX
101#ifdef LC_VERSION_MIN_IPHONEOS
102#undef LC_VERSION_MIN_IPHONEOS
104#ifdef LC_VERSION_MIN_TVOS
105#undef LC_VERSION_MIN_TVOS
107#ifdef LC_VERSION_MIN_WATCHOS
108#undef LC_VERSION_MIN_WATCHOS
110#ifdef LC_BUILD_VERSION
111#undef LC_BUILD_VERSION
116#ifdef PLATFORM_MACCATALYST
117#undef PLATFORM_MACCATALYST
122#ifdef PLATFORM_IOSSIMULATOR
123#undef PLATFORM_IOSSIMULATOR
128#ifdef PLATFORM_TVOSSIMULATOR
129#undef PLATFORM_TVOSSIMULATOR
131#ifdef PLATFORM_WATCHOS
132#undef PLATFORM_WATCHOS
134#ifdef PLATFORM_WATCHOSSIMULATOR
135#undef PLATFORM_WATCHOSSIMULATOR
140using namespace llvm::MachO;
158 static_assert(offsetof(T, cmd) == 0,
"T::cmd must be the first field");
159 static_assert(offsetof(T, cmdsize) ==
sizeof(uint32_t),
160 "T::cmdsize must immediately follow T::cmd");
161 static_assert(std::is_same<
decltype(T::cmd), uint32_t>::value,
162 "T::cmd must be uint32_t");
163 static_assert(std::is_same<
decltype(T::cmdsize), uint32_t>::value,
164 "T::cmdsize must be uint32_t");
165 if (data.
GetU32(&offset, &cmd, 2) ==
nullptr)
167 if (cmd.cmdsize <
sizeof(load_command))
173 const char *alt_name,
size_t reg_byte_size,
176 if (reg_info ==
nullptr)
181 if (reg_info->
byte_size >= reg_byte_size)
185 for (
size_t i = 0, n = reg_byte_size - reg_info->
byte_size; i < n; ++i)
192 for (
size_t i = 0; i < reg_byte_size; ++i)
215 int flavor = data.
GetU32(&offset);
218 uint32_t count = data.
GetU32(&offset);
221 uint32_t *gpr_data =
reinterpret_cast<uint32_t *
>(&
gpr.rax);
222 for (uint32_t i = 0; i < count && offset < data.
GetByteSize(); ++i)
223 gpr_data[i] = data.
GetU32(&offset);
406 int flavor = data.
GetU32(&offset);
407 uint32_t count = data.
GetU32(&offset);
408 offset_t next_thread_state = offset + (count * 4);
413 uint32_t gpr_buf_count = (
sizeof(
gpr.r) /
sizeof(
gpr.r[0])) + 1;
414 if (count == gpr_buf_count) {
415 for (uint32_t i = 0; i < (count - 1); ++i) {
425 uint8_t *fpu_reg_buf = (uint8_t *)&
fpu.floats;
426 const int fpu_reg_buf_size =
sizeof(
fpu.floats);
428 fpu_reg_buf) == fpu_reg_buf_size) {
429 offset += fpu_reg_buf_size;
444 offset = next_thread_state;
528 int flavor = data.
GetU32(&offset);
529 uint32_t count = data.
GetU32(&offset);
530 offset_t next_thread_state = offset + (count * 4);
535 if (count >= (33 * 2) + 1) {
536 for (uint32_t i = 0; i < 29; ++i)
547 uint8_t *fpu_reg_buf = (uint8_t *)&
fpu.v[0];
548 const int fpu_reg_buf_size =
sizeof(
fpu);
549 if (fpu_reg_buf_size == count *
sizeof(uint32_t) &&
551 fpu_reg_buf) == fpu_reg_buf_size) {
564 offset = next_thread_state;
668 int flavor = data.
GetU32(&offset);
669 uint32_t count = data.
GetU32(&offset);
670 offset_t next_thread_state = offset + (count * 4);
675 for (uint32_t i = 0; i < 32; ++i)
676 ((uint32_t *)&
gpr.x0)[i] = data.
GetU32(&offset);
684 for (uint32_t i = 0; i < 32; ++i)
685 ((uint32_t *)&
fpr.f0)[i] = data.
GetU32(&offset);
699 offset = next_thread_state;
786 return sizeof(
struct llvm::MachO::mach_header);
790 return sizeof(
struct llvm::MachO::mach_header_64);
799#define MACHO_NLIST_ARM_SYMBOL_IS_THUMB 0x0008
819 if (!extractor_sp || !extractor_sp->HasData()) {
824 extractor_sp = std::make_shared<DataExtractor>(data_sp);
831 if (extractor_sp->GetByteSize() < length) {
836 extractor_sp = std::make_shared<DataExtractor>(data_sp);
838 auto objfile_up = std::make_unique<ObjectFileMachO>(
839 module_sp, extractor_sp, data_offset, file, file_offset, length);
840 if (!objfile_up || !objfile_up->ParseHeader())
843 return objfile_up.release();
849 DataExtractorSP extractor_sp = std::make_shared<DataExtractor>(data_sp);
851 extractor_sp->GetByteSize())) {
852 std::unique_ptr<ObjectFile> objfile_up(
854 if (objfile_up.get() && objfile_up->ParseHeader())
855 return objfile_up.release();
863 if (!extractor_sp || !extractor_sp->HasData())
868 extractor_sp->GetByteSize())) {
869 llvm::MachO::mach_header header;
871 if (
ParseHeader(extractor_sp, &data_offset, header)) {
872 size_t header_and_load_cmds =
874 if (header_and_load_cmds >= extractor_sp->GetByteSize()) {
876 MapFileData(file, header_and_load_cmds, file_offset);
878 extractor_sp->SetData(file_data_sp);
881 if (extractor_sp && extractor_sp->HasData()) {
894 static constexpr llvm::StringLiteral g_segment_name_TEXT(
"__TEXT");
895 return g_segment_name_TEXT;
899 static constexpr llvm::StringLiteral g_segment_name_DATA(
"__DATA");
900 return g_segment_name_DATA;
904 static constexpr llvm::StringLiteral g_segment_name(
"__DATA_DIRTY");
905 return g_segment_name;
909 static constexpr llvm::StringLiteral g_segment_name(
"__DATA_CONST");
910 return g_segment_name;
914 static constexpr llvm::StringLiteral g_segment_name_OBJC(
"__OBJC");
915 return g_segment_name_OBJC;
919 static constexpr llvm::StringLiteral g_section_name_LINKEDIT(
"__LINKEDIT");
920 return g_section_name_LINKEDIT;
924 static constexpr llvm::StringLiteral g_section_name(
"__DWARF");
925 return g_section_name;
929 static constexpr llvm::StringLiteral g_section_name(
"__LLVM_COV");
930 return g_section_name;
934 static constexpr llvm::StringLiteral g_section_name_eh_frame(
"__eh_frame");
935 return g_section_name_eh_frame;
939 static constexpr llvm::StringLiteral g_section_name_lldb_no_nlist(
941 return g_section_name_lldb_no_nlist;
948 uint32_t magic = extractor_sp->GetU32(&offset);
952 uint32_t filetype = extractor_sp->GetU32(&offset);
957 if (filetype == llvm::MachO::MH_FILESET)
969 :
ObjectFile(module_sp, file, file_offset, length, extractor_sp,
982 :
ObjectFile(module_sp, process_sp, header_addr,
993 llvm::MachO::mach_header &header) {
996 header.magic = extractor_sp->GetU32(data_offset_ptr);
997 bool can_parse =
false;
998 bool is_64_bit =
false;
999 switch (header.magic) {
1002 extractor_sp->SetAddressByteSize(4);
1008 extractor_sp->SetAddressByteSize(8);
1017 extractor_sp->SetAddressByteSize(4);
1025 extractor_sp->SetAddressByteSize(8);
1035 extractor_sp->GetU32(data_offset_ptr, &header.cputype, 6);
1037 *data_offset_ptr += 4;
1040 memset(&header, 0,
sizeof(header));
1050 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
1051 bool can_parse =
false;
1098 for (
unsigned i = 0, e = all_specs.
GetSize(); i != e; ++i) {
1103 const ArchSpec &module_arch = module_sp->GetArchitecture();
1108 const size_t header_and_lc_size =
1110 if (
m_data_nsp->GetByteSize() < header_and_lc_size) {
1118 if (data_sp->GetByteSize() != header_and_lc_size)
1130 memset(&
m_header, 0,
sizeof(
struct llvm::MachO::mach_header));
1140 return m_header.filetype == MH_EXECUTE;
1144 return m_header.filetype == MH_DYLINKER;
1148 return m_header.flags & MH_DYLIB_IN_CACHE;
1152 return m_header.filetype == MH_KEXT_BUNDLE;
1170 switch (section_type) {
1175 if (
m_header.cputype == llvm::MachO::CPU_TYPE_ARM) {
1261 switch (symbol_type) {
1270 if (
m_header.cputype == llvm::MachO::CPU_TYPE_ARM) {
1338 for (uint32_t i = 0; i <
m_header.ncmds; ++i) {
1341 llvm::MachO::load_command lc = {};
1344 if (lc.cmd == LC_DYSYMTAB) {
1348 (
sizeof(
m_dysymtab) /
sizeof(uint32_t)) - 2) ==
1355 offset = load_cmd_offset + lc.cmdsize;
1368 llvm::MachO::encryption_info_command encryption_cmd;
1369 for (uint32_t i = 0; i <
m_header.ncmds; ++i) {
1376 if (encryption_cmd.cmd == LC_ENCRYPTION_INFO ||
1377 encryption_cmd.cmd == LC_ENCRYPTION_INFO_64) {
1378 if (
m_data_nsp->GetU32(&offset, &encryption_cmd.cryptoff, 3)) {
1379 if (encryption_cmd.cryptid != 0) {
1387 offset = load_cmd_offset + encryption_cmd.cmdsize;
1394 llvm::MachO::segment_command_64 &seg_cmd, uint32_t cmd_idx) {
1395 if (
m_length == 0 || seg_cmd.filesize == 0)
1403 llvm::StringRef segname(seg_cmd.segname,
1404 strnlen(seg_cmd.segname,
sizeof(seg_cmd.segname)));
1420 const char *lc_segment_name =
1421 seg_cmd.cmd == LC_SEGMENT_64 ?
"LC_SEGMENT_64" :
"LC_SEGMENT";
1423 "load command {0} {1} has a fileoff ({2:x16}) that extends beyond "
1424 "the end of the file ({3:x16}), ignoring this section",
1425 cmd_idx, lc_segment_name, seg_cmd.fileoff,
m_length);
1427 seg_cmd.fileoff = 0;
1428 seg_cmd.filesize = 0;
1431 if (seg_cmd.fileoff + seg_cmd.filesize >
m_length) {
1438 const char *lc_segment_name =
1439 seg_cmd.cmd == LC_SEGMENT_64 ?
"LC_SEGMENT_64" :
"LC_SEGMENT";
1441 "load command {0} {1} has a fileoff + filesize ({2:x16}) that "
1442 "extends beyond the end of the file ({3:x16}), the segment will be "
1443 "truncated to match",
1444 cmd_idx, lc_segment_name, seg_cmd.fileoff + seg_cmd.filesize,
m_length);
1447 seg_cmd.filesize =
m_length - seg_cmd.fileoff;
1453 uint32_t result = 0;
1454 if (seg_cmd.initprot & VM_PROT_READ)
1455 result |= ePermissionsReadable;
1456 if (seg_cmd.initprot & VM_PROT_WRITE)
1457 result |= ePermissionsWritable;
1458 if (seg_cmd.initprot & VM_PROT_EXECUTE)
1459 result |= ePermissionsExecutable;
1464 llvm::StringRef section_name) {
1466 if (flags & (S_ATTR_PURE_INSTRUCTIONS | S_ATTR_SOME_INSTRUCTIONS))
1469 uint32_t mach_sect_type = flags & SECTION_TYPE;
1470 static constexpr llvm::StringLiteral g_sect_name_objc_data(
"__objc_data");
1471 static constexpr llvm::StringLiteral g_sect_name_objc_msgrefs(
1473 static constexpr llvm::StringLiteral g_sect_name_objc_selrefs(
1475 static constexpr llvm::StringLiteral g_sect_name_objc_classrefs(
1476 "__objc_classrefs");
1477 static constexpr llvm::StringLiteral g_sect_name_objc_superrefs(
1478 "__objc_superrefs");
1479 static constexpr llvm::StringLiteral g_sect_name_objc_const(
"__objc_const");
1480 static constexpr llvm::StringLiteral g_sect_name_objc_classlist(
1481 "__objc_classlist");
1482 static constexpr llvm::StringLiteral g_sect_name_cfstring(
"__cfstring");
1484 static constexpr llvm::StringLiteral g_sect_name_dwarf_debug_str_offs(
1485 "__debug_str_offs");
1486 static constexpr llvm::StringLiteral g_sect_name_dwarf_debug_str_offs_dwo(
1487 "__debug_str_offs.dwo");
1488 static constexpr llvm::StringLiteral g_sect_name_dwarf_apple_names(
1490 static constexpr llvm::StringLiteral g_sect_name_dwarf_apple_types(
1492 static constexpr llvm::StringLiteral g_sect_name_dwarf_apple_namespaces(
1493 "__apple_namespac");
1494 static constexpr llvm::StringLiteral g_sect_name_dwarf_apple_objc(
1496 static constexpr llvm::StringLiteral g_sect_name_eh_frame(
"__eh_frame");
1497 static constexpr llvm::StringLiteral g_sect_name_compact_unwind(
1499 static constexpr llvm::StringLiteral g_sect_name_text(
"__text");
1500 static constexpr llvm::StringLiteral g_sect_name_data(
"__data");
1501 static constexpr llvm::StringLiteral g_sect_name_go_symtab(
"__gosymtab");
1502 static constexpr llvm::StringLiteral g_sect_name_ctf(
"__ctf");
1503 static constexpr llvm::StringLiteral g_sect_name_lldb_summaries(
1505 static constexpr llvm::StringLiteral g_sect_name_lldb_formatters(
1506 "__lldbformatters");
1507 static constexpr llvm::StringLiteral g_sect_name_swift_ast(
"__swift_ast");
1509 if (section_name == g_sect_name_dwarf_debug_str_offs)
1511 if (section_name == g_sect_name_dwarf_debug_str_offs_dwo)
1514 llvm::StringRef stripped_name = section_name;
1515 if (stripped_name.consume_front(
"__debug_"))
1518 if (section_name == g_sect_name_dwarf_apple_names)
1520 if (section_name == g_sect_name_dwarf_apple_types)
1522 if (section_name == g_sect_name_dwarf_apple_namespaces)
1524 if (section_name == g_sect_name_dwarf_apple_objc)
1526 if (section_name == g_sect_name_objc_selrefs)
1528 if (section_name == g_sect_name_objc_msgrefs)
1530 if (section_name == g_sect_name_eh_frame)
1532 if (section_name == g_sect_name_compact_unwind)
1534 if (section_name == g_sect_name_cfstring)
1536 if (section_name == g_sect_name_go_symtab)
1538 if (section_name == g_sect_name_ctf)
1540 if (section_name == g_sect_name_lldb_summaries)
1542 if (section_name == g_sect_name_lldb_formatters)
1544 if (section_name == g_sect_name_swift_ast)
1546 if (section_name == g_sect_name_objc_data ||
1547 section_name == g_sect_name_objc_classrefs ||
1548 section_name == g_sect_name_objc_superrefs ||
1549 section_name == g_sect_name_objc_const ||
1550 section_name == g_sect_name_objc_classlist) {
1554 switch (mach_sect_type) {
1557 if (section_name == g_sect_name_text)
1559 if (section_name == g_sect_name_data)
1564 case S_CSTRING_LITERALS:
1566 case S_4BYTE_LITERALS:
1568 case S_8BYTE_LITERALS:
1570 case S_LITERAL_POINTERS:
1572 case S_NON_LAZY_SYMBOL_POINTERS:
1574 case S_LAZY_SYMBOL_POINTERS:
1576 case S_SYMBOL_STUBS:
1579 case S_MOD_INIT_FUNC_POINTERS:
1582 case S_MOD_TERM_FUNC_POINTERS:
1592 case S_16BYTE_LITERALS:
1596 case S_LAZY_DYLIB_SYMBOL_POINTERS:
1616 const llvm::MachO::load_command &load_cmd_,
lldb::offset_t offset,
1618 llvm::MachO::segment_command_64 load_cmd;
1619 memcpy(&load_cmd, &load_cmd_,
sizeof(load_cmd_));
1621 if (!
m_data_nsp->GetU8(&offset, (uint8_t *)load_cmd.segname, 16))
1626 const bool is_dsym = (
m_header.filetype == MH_DSYM);
1627 bool add_section =
true;
1628 bool add_to_unified =
true;
1629 llvm::StringRef segname(load_cmd.segname,
1630 strnlen(load_cmd.segname,
sizeof(load_cmd.segname)));
1633 if (is_dsym && unified_section_sp) {
1637 add_to_unified =
false;
1641 add_section =
false;
1644 load_cmd.vmaddr =
m_data_nsp->GetAddress(&offset);
1645 load_cmd.vmsize =
m_data_nsp->GetAddress(&offset);
1646 load_cmd.fileoff =
m_data_nsp->GetAddress(&offset);
1647 load_cmd.filesize =
m_data_nsp->GetAddress(&offset);
1648 if (!
m_data_nsp->GetU32(&offset, &load_cmd.maxprot, 4))
1654 const bool segment_is_encrypted =
1655 (load_cmd.flags & SG_PROTECTED_VERSION_1) != 0;
1660 if (add_section && (!segname.empty() || is_core)) {
1661 segment_sp = std::make_shared<Section>(
1681 segment_sp->SetIsEncrypted(segment_is_encrypted);
1683 segment_sp->SetPermissions(segment_permissions);
1686 }
else if (unified_section_sp) {
1696 if (is_dsym && unified_section_sp->GetFileAddress() != load_cmd.vmaddr) {
1698 "Installing dSYM's {0} segment file address over ObjectFile's "
1699 "so symbol table/debug info resolves correctly for {1}",
1700 segname, module_sp->GetFileSpec().GetFilename());
1704 module_sp->GetObjectFile()->GetSymtab();
1710 unified_section_sp->SetFileAddress(load_cmd.vmaddr);
1719 llvm::MachO::section_64 sect64;
1720 ::memset(§64, 0,
sizeof(sect64));
1725 uint32_t segment_sect_idx;
1731 uint64_t section_offset_adjust = 0;
1732 const uint32_t num_u32s = load_cmd.cmd == LC_SEGMENT ? 7 : 8;
1733 for (segment_sect_idx = 0; segment_sect_idx < load_cmd.nsects;
1734 ++segment_sect_idx) {
1735 if (
m_data_nsp->GetU8(&offset, (uint8_t *)sect64.sectname,
1736 sizeof(sect64.sectname)) ==
nullptr)
1738 if (
m_data_nsp->GetU8(&offset, (uint8_t *)sect64.segname,
1739 sizeof(sect64.segname)) ==
nullptr)
1741 sect64.addr =
m_data_nsp->GetAddress(&offset);
1742 sect64.size =
m_data_nsp->GetAddress(&offset);
1744 if (
m_data_nsp->GetU32(&offset, §64.offset, num_u32s) ==
nullptr)
1759 const uint64_t section_file_offset =
1760 (uint64_t)sect64.offset + section_offset_adjust;
1761 const uint64_t end_section_offset = (uint64_t)sect64.offset + sect64.size;
1763 section_offset_adjust += end_section_offset & 0xFFFFFFFF00000000ull;
1766 llvm::StringRef section_name(
1767 sect64.sectname, strnlen(sect64.sectname,
sizeof(sect64.sectname)));
1768 if (segname.empty()) {
1775 segname = llvm::StringRef(
1776 sect64.segname, strnlen(sect64.segname,
sizeof(sect64.segname)));
1778 if (segment_sp.get()) {
1779 Section *segment = segment_sp.get();
1782 const lldb::addr_t sect64_max_addr = sect64_min_addr + sect64.size;
1783 const lldb::addr_t curr_seg_byte_size = segment->GetByteSize();
1784 const lldb::addr_t curr_seg_min_addr = segment->GetFileAddress();
1786 curr_seg_min_addr + curr_seg_byte_size;
1787 if (sect64_min_addr >= curr_seg_min_addr) {
1789 sect64_max_addr - curr_seg_min_addr;
1791 if (new_seg_byte_size > curr_seg_byte_size)
1792 segment->SetByteSize(new_seg_byte_size);
1797 sect64_min_addr - curr_seg_min_addr;
1798 segment->Slide(slide_amount,
false);
1799 segment->GetChildren().Slide(-slide_amount,
false);
1800 segment->SetByteSize(curr_seg_max_addr - sect64_min_addr);
1804 if (section_file_offset) {
1806 segment->GetFileOffset();
1808 segment_min_file_offset + segment->GetFileSize();
1810 const lldb::addr_t section_min_file_offset = section_file_offset;
1812 section_min_file_offset + sect64.size;
1814 std::min(section_min_file_offset, segment_min_file_offset);
1816 std::max(section_max_file_offset, segment_max_file_offset) -
1818 segment->SetFileOffset(new_file_offset);
1819 segment->SetFileSize(new_file_size);
1823 segment_sp = std::make_shared<Section>(
1838 section_file_offset,
1840 section_file_offset ? sect64.size : 0,
1845 segment_sp->SetIsFake(
true);
1846 segment_sp->SetPermissions(segment_permissions);
1850 segment_sp->SetIsEncrypted(segment_is_encrypted);
1853 assert(segment_sp.get());
1857 SectionSP section_sp = std::make_shared<Section>(
1859 section_name.str(), sect_type,
1860 sect64.addr - segment_sp->GetFileAddress(), sect64.size,
1861 section_file_offset, section_file_offset == 0 ? 0 : sect64.size,
1862 sect64.align, sect64.flags);
1865 bool section_is_encrypted =
false;
1866 if (!segment_is_encrypted && load_cmd.filesize != 0)
1868 section_file_offset) !=
nullptr;
1870 section_sp->SetIsEncrypted(segment_is_encrypted || section_is_encrypted);
1871 section_sp->SetPermissions(segment_permissions);
1872 segment_sp->GetChildren().AddSection(section_sp);
1874 if (segment_sp->IsFake()) {
1880 if (segment_sp && is_dsym) {
1883 for (sect_uid = first_segment_sectID; sect_uid <= context.
NextSectionIdx;
1886 segment_sp->GetChildren().FindSectionByID(sect_uid));
1890 segment_sp->GetChildren().FindSectionByID(sect_uid + 1);
1892 if (curr_section_sp.get()) {
1893 if (curr_section_sp->GetByteSize() == 0) {
1894 if (next_section_sp.get() !=
nullptr)
1895 curr_section_sp->SetByteSize(next_section_sp->GetFileAddress() -
1896 curr_section_sp->GetFileAddress());
1898 curr_section_sp->SetByteSize(load_cmd.vmsize);
1907 const llvm::MachO::load_command &load_cmd,
lldb::offset_t offset) {
1911 (
sizeof(
m_dysymtab) /
sizeof(uint32_t)) - 2);
1927 llvm::MachO::load_command load_cmd;
1928 for (uint32_t i = 0; i <
m_header.ncmds; ++i) {
1933 if (load_cmd.cmd == LC_SEGMENT || load_cmd.cmd == LC_SEGMENT_64)
1935 else if (load_cmd.cmd == LC_DYSYMTAB)
1938 offset = load_cmd_offset + load_cmd.cmdsize;
1942 module_sp->SectionFileAddressesChanged();
1964 section_sp->GetFileAddress());
1966 section_sp->GetByteSize());
1968 std::string filename =
"<unknown>";
1970 if (first_section_sp)
1971 filename = first_section_sp->GetObjectFile()->GetFileSpec().GetPath();
1974 llvm::formatv(
"unable to find section {0} for a symbol in "
1975 "{1}, corrupt file?",
1990 return m_section_list->FindSectionContainingFileAddress(file_addr);
2006 const char *&symbol_name_non_abi_mangled,
2008 static constexpr llvm::StringLiteral g_objc_v2_prefix_class(
"_OBJC_CLASS_$_");
2009 static constexpr llvm::StringLiteral g_objc_v2_prefix_metaclass(
2010 "_OBJC_METACLASS_$_");
2011 static constexpr llvm::StringLiteral g_objc_v2_prefix_ivar(
"_OBJC_IVAR_$_");
2013 llvm::StringRef symbol_name_ref(symbol_name);
2014 if (symbol_name_ref.empty())
2017 if (symbol_name_ref.starts_with(g_objc_v2_prefix_class)) {
2018 symbol_name_non_abi_mangled = symbol_name + 1;
2019 symbol_name = symbol_name + g_objc_v2_prefix_class.size();
2024 if (symbol_name_ref.starts_with(g_objc_v2_prefix_metaclass)) {
2025 symbol_name_non_abi_mangled = symbol_name + 1;
2026 symbol_name = symbol_name + g_objc_v2_prefix_metaclass.size();
2031 if (symbol_name_ref.starts_with(g_objc_v2_prefix_ivar)) {
2032 symbol_name_non_abi_mangled = symbol_name + 1;
2033 symbol_name = symbol_name + g_objc_v2_prefix_ivar.size();
2042 bool &demangled_is_synthesized,
2050 llvm::StringRef symbol_sect_name = symbol_section->GetName();
2051 if (symbol_section->IsDescendant(text_section_sp.get())) {
2052 if (symbol_section->IsClear(S_ATTR_PURE_INSTRUCTIONS |
2053 S_ATTR_SELF_MODIFYING_CODE |
2054 S_ATTR_SOME_INSTRUCTIONS))
2058 }
else if (symbol_section->IsDescendant(data_section_sp.get()) ||
2059 symbol_section->IsDescendant(data_dirty_section_sp.get()) ||
2060 symbol_section->IsDescendant(data_const_section_sp.get())) {
2061 if (symbol_sect_name.starts_with(
"__objc")) {
2065 llvm::StringRef symbol_name_ref(symbol_name);
2066 if (symbol_name_ref.starts_with(
"OBJC_")) {
2067 static const llvm::StringRef g_objc_v2_prefix_class(
"OBJC_CLASS_$_");
2068 static const llvm::StringRef g_objc_v2_prefix_metaclass(
2069 "OBJC_METACLASS_$_");
2070 static const llvm::StringRef g_objc_v2_prefix_ivar(
"OBJC_IVAR_$_");
2071 if (symbol_name_ref.starts_with(g_objc_v2_prefix_class)) {
2072 symbol_name = symbol_name + g_objc_v2_prefix_class.size();
2074 demangled_is_synthesized =
true;
2075 }
else if (symbol_name_ref.starts_with(g_objc_v2_prefix_metaclass)) {
2076 symbol_name = symbol_name + g_objc_v2_prefix_metaclass.size();
2078 demangled_is_synthesized =
true;
2079 }
else if (symbol_name_ref.starts_with(g_objc_v2_prefix_ivar)) {
2080 symbol_name = symbol_name + g_objc_v2_prefix_ivar.size();
2082 demangled_is_synthesized =
true;
2086 }
else if (symbol_sect_name.starts_with(
"__gcc_except_tab")) {
2091 }
else if (symbol_sect_name.starts_with(
"__IMPORT")) {
2097static std::optional<struct nlist_64>
2099 size_t nlist_byte_size) {
2100 struct nlist_64 nlist;
2112 const struct nlist_64 &nlist,
2113 bool &has_source_files,
2114 bool &has_debug_map) {
2116 has_source_files =
true;
2119 has_debug_map =
true;
2132 llvm::StringRef file_name = file.
GetFilename().nonEmptyOr(
"<Unknown>");
2134 file_name.str().c_str());
2135 LLDB_LOG(log,
"Parsing symbol table for {0}", file_name);
2136 Progress progress(
"Parsing symbol table", file_name.str());
2151 llvm::DenseSet<addr_t> symbols_added;
2155 auto add_symbol_addr = [&symbols_added](
lldb::addr_t file_addr) {
2159 symbols_added.insert(file_addr);
2161 FunctionStarts function_starts;
2167 for (i = 0; i <
m_header.ncmds; ++i) {
2170 llvm::MachO::load_command lc;
2176 llvm::MachO::symtab_command lc_obj;
2177 if (
m_data_nsp->GetU32(&offset, &lc_obj.symoff, 4)) {
2178 lc_obj.cmd = lc.cmd;
2179 lc_obj.cmdsize = lc.cmdsize;
2180 symtab_load_command = lc_obj;
2185 case LC_DYLD_INFO_ONLY: {
2186 llvm::MachO::dyld_info_command lc_obj;
2187 if (
m_data_nsp->GetU32(&offset, &lc_obj.rebase_off, 10)) {
2188 lc_obj.cmd = lc.cmd;
2189 lc_obj.cmdsize = lc.cmdsize;
2195 case LC_LOAD_WEAK_DYLIB:
2196 case LC_REEXPORT_DYLIB:
2198 case LC_LOAD_UPWARD_DYLIB: {
2199 uint32_t name_offset = cmd_offset +
m_data_nsp->GetU32(&offset);
2200 if (std::optional<llvm::StringRef> path =
2205 if (path->starts_with(
"@"))
2208 if (lc.cmd == LC_REEXPORT_DYLIB) {
2212 dylib_files.
Append(file_spec);
2216 case LC_DYLD_EXPORTS_TRIE: {
2217 llvm::MachO::linkedit_data_command lc_obj;
2218 lc_obj.cmd = lc.cmd;
2219 lc_obj.cmdsize = lc.cmdsize;
2220 if (
m_data_nsp->GetU32(&offset, &lc_obj.dataoff, 2))
2221 exports_trie_load_command = lc_obj;
2223 case LC_FUNCTION_STARTS: {
2224 llvm::MachO::linkedit_data_command lc_obj;
2225 lc_obj.cmd = lc.cmd;
2226 lc_obj.cmdsize = lc.cmdsize;
2227 if (
m_data_nsp->GetU32(&offset, &lc_obj.dataoff, 2))
2228 function_starts_load_command = lc_obj;
2232 const uint8_t *uuid_bytes =
m_data_nsp->PeekData(offset, 16);
2235 image_uuid =
UUID(uuid_bytes, 16);
2242 offset = cmd_offset + lc.cmdsize;
2245 if (!symtab_load_command.
cmd)
2249 if (section_list ==
nullptr)
2252 bool has_source_files =
false;
2253 bool has_debug_map =
false;
2255 const uint32_t addr_byte_size =
m_data_nsp->GetAddressByteSize();
2257 bool bit_width_32 = addr_byte_size == 4;
2258 const size_t nlist_byte_size =
2259 bit_width_32 ?
sizeof(
struct nlist) : sizeof(struct nlist_64);
2261 DataExtractor nlist_data(nullptr, 0, byte_order, addr_byte_size);
2262 DataExtractor strtab_data(nullptr, 0, byte_order, addr_byte_size);
2263 DataExtractor function_starts_data(nullptr, 0, byte_order, addr_byte_size);
2264 DataExtractor indirect_symbol_index_data(nullptr, 0, byte_order,
2266 DataExtractor dyld_trie_data(nullptr, 0, byte_order, addr_byte_size);
2268 const
addr_t nlist_data_byte_size =
2269 symtab_load_command.nsyms * nlist_byte_size;
2270 const
addr_t strtab_data_byte_size = symtab_load_command.strsize;
2273 ProcessSP process_sp(m_process_wp.lock());
2274 Process *process = process_sp.get();
2278 bool is_local_shared_cache_image = is_shared_cache_image && !
IsInMemory();
2281 section_list->FindSectionByName(GetSegmentNameTEXT()));
2283 section_list->FindSectionByName(GetSegmentNameDATA()));
2285 section_list->FindSectionByName(GetSegmentNameLINKEDIT()));
2287 section_list->FindSectionByName(GetSegmentNameDATA_DIRTY()));
2289 section_list->FindSectionByName(GetSegmentNameDATA_CONST()));
2291 section_list->FindSectionByName(GetSegmentNameOBJC()));
2296 if (text_section_sp.get()) {
2297 eh_frame_section_sp = text_section_sp->GetChildren().FindSectionByName(
2298 g_section_name_eh_frame);
2299 lldb_no_nlist_section_sp = text_section_sp->GetChildren().FindSectionByName(
2300 g_section_name_lldb_no_nlist);
2302 eh_frame_section_sp =
2304 lldb_no_nlist_section_sp =
2308 if (process &&
m_header.filetype != llvm::MachO::MH_OBJECT &&
2309 !is_local_shared_cache_image) {
2310 Target &target = process->GetTarget();
2319 if (lldb_no_nlist_section_sp)
2324 if (linkedit_section_sp) {
2325 addr_t linkedit_load_addr =
2326 linkedit_section_sp->GetLoadBaseAddress(&target);
2336 const addr_t linkedit_file_offset = linkedit_section_sp->GetFileOffset();
2337 const addr_t symoff_addr = linkedit_load_addr +
2338 symtab_load_command.
symoff -
2339 linkedit_file_offset;
2340 strtab_addr = linkedit_load_addr + symtab_load_command.
stroff -
2341 linkedit_file_offset;
2349 m_header.filetype == llvm::MachO::MH_DYLINKER) {
2351 ReadMemory(process_sp, symoff_addr, nlist_data_byte_size));
2353 nlist_data.SetData(nlist_data_sp, 0, nlist_data_sp->GetByteSize());
2355 const addr_t indirect_syms_addr = linkedit_load_addr +
2357 linkedit_file_offset;
2359 process_sp, indirect_syms_addr, dysymtab.
nindirectsyms * 4));
2360 if (indirect_syms_data_sp)
2361 indirect_symbol_index_data.SetData(
2362 indirect_syms_data_sp, 0, indirect_syms_data_sp->GetByteSize());
2372 if (!is_shared_cache_image) {
2374 ReadMemory(process_sp, strtab_addr, strtab_data_byte_size));
2375 if (strtab_data_sp) {
2376 strtab_data.SetData(strtab_data_sp, 0,
2377 strtab_data_sp->GetByteSize());
2382 if (function_starts_load_command.
cmd) {
2383 const addr_t func_start_addr =
2384 linkedit_load_addr + function_starts_load_command.
dataoff -
2385 linkedit_file_offset;
2388 function_starts_load_command.
datasize));
2389 if (func_start_data_sp)
2390 function_starts_data.SetData(func_start_data_sp, 0,
2391 func_start_data_sp->GetByteSize());
2397 if (is_local_shared_cache_image && linkedit_section_sp) {
2405 lldb::addr_t linkedit_offset = linkedit_section_sp->GetFileOffset();
2408 symtab_load_command.
symoff += linkedit_slide;
2409 symtab_load_command.
stroff += linkedit_slide;
2412 function_starts_load_command.
dataoff += linkedit_slide;
2413 exports_trie_load_command.
dataoff += linkedit_slide;
2417 nlist_data_byte_size);
2418 strtab_data = *
m_data_nsp->GetSubsetExtractorSP(symtab_load_command.
stroff,
2419 strtab_data_byte_size);
2424 && (exports_trie_load_command.
datasize > 0)));
2428 }
else if (exports_trie_load_command.
datasize > 0) {
2431 exports_trie_load_command.
datasize);
2435 indirect_symbol_index_data = *
m_data_nsp->GetSubsetExtractorSP(
2438 if (function_starts_load_command.
cmd) {
2439 function_starts_data = *
m_data_nsp->GetSubsetExtractorSP(
2440 function_starts_load_command.
dataoff,
2441 function_starts_load_command.
datasize);
2445 const bool is_arm = (
m_header.cputype == llvm::MachO::CPU_TYPE_ARM);
2462 if (text_section_sp && function_starts_data.GetByteSize()) {
2463 FunctionStarts::Entry function_start_entry;
2464 function_start_entry.data =
false;
2466 function_start_entry.addr = text_section_sp->GetFileAddress();
2468 while ((delta = function_starts_data.GetULEB128(&function_start_offset)) >
2471 function_start_entry.addr += delta;
2473 if (function_start_entry.addr & 1) {
2475 function_start_entry.data =
true;
2476 }
else if (always_thumb) {
2477 function_start_entry.data =
true;
2480 function_starts.Append(function_start_entry);
2488 if (text_section_sp.get() && eh_frame_section_sp.get() &&
2494 addr_t text_base_addr = text_section_sp->GetFileAddress();
2495 size_t count = functions.
GetSize();
2496 for (
size_t i = 0; i < count; ++i) {
2500 FunctionStarts::Entry function_start_entry;
2501 function_start_entry.addr = func->
base - text_base_addr;
2503 if (function_start_entry.addr & 1) {
2505 function_start_entry.data =
true;
2506 }
else if (always_thumb) {
2507 function_start_entry.data =
true;
2510 function_starts.Append(function_start_entry);
2516 const size_t function_starts_count = function_starts.GetSize();
2531 if (unwind_or_symbol_log)
2532 module_sp->LogMessage(
2533 unwind_or_symbol_log,
2534 "no LC_FUNCTION_STARTS, will not allow assembly profiled unwinds");
2537 const user_id_t TEXT_eh_frame_sectID = eh_frame_section_sp.get()
2538 ? eh_frame_section_sp->GetID()
2544 std::vector<uint32_t> N_FUN_indexes;
2545 std::vector<uint32_t> N_NSYM_indexes;
2546 std::vector<uint32_t> N_INCL_indexes;
2547 std::vector<uint32_t> N_BRAC_indexes;
2548 std::vector<uint32_t> N_COMM_indexes;
2549 typedef std::multimap<uint64_t, uint32_t> ValueToSymbolIndexMap;
2550 typedef llvm::DenseMap<uint32_t, uint32_t> NListIndexToSymbolIndexMap;
2551 typedef llvm::DenseMap<const char *, uint32_t> ConstNameToSymbolIndexMap;
2552 ValueToSymbolIndexMap N_FUN_addr_to_sym_idx;
2553 ValueToSymbolIndexMap N_STSYM_addr_to_sym_idx;
2554 ConstNameToSymbolIndexMap N_GSYM_name_to_sym_idx;
2557 NListIndexToSymbolIndexMap m_nlist_idx_to_sym_idx;
2558 Symbol *symbol_ptr =
nullptr;
2560 uint32_t sym_idx = 0;
2562 size_t num_syms = 0;
2563 std::string memory_symbol_name;
2564 uint32_t unmapped_local_symbols_found = 0;
2566 std::vector<TrieEntryWithOffset> reexport_trie_entries;
2567 std::vector<TrieEntryWithOffset> external_sym_trie_entries;
2568 std::set<lldb::addr_t> resolver_addresses;
2570 const size_t dyld_trie_data_size = dyld_trie_data.
GetByteSize();
2571 if (dyld_trie_data_size > 0) {
2572 LLDB_LOG(log,
"Parsing {0} bytes of dyld trie data", dyld_trie_data_size);
2576 if (text_segment_sp)
2577 text_segment_file_addr = text_segment_sp->GetFileAddress();
2579 resolver_addresses, reexport_trie_entries,
2580 external_sym_trie_entries);
2583 typedef std::set<ConstString> IndirectSymbols;
2584 IndirectSymbols indirect_symbol_names;
2586 typedef llvm::DenseMap<ConstString, uint16_t> UndefinedNameToDescMap;
2587 typedef llvm::DenseMap<uint32_t, ConstString> SymbolIndexToName;
2588 UndefinedNameToDescMap undefined_name_to_desc;
2589 SymbolIndexToName reexport_shlib_needs_fixup;
2593 auto ParseSymbolLambda = [&](
struct nlist_64 &nlist, uint32_t nlist_idx,
2595 const bool is_debug = ((nlist.n_type & N_STAB) != 0);
2596 if (is_debug != debug_only)
2599 const char *symbol_name_non_abi_mangled =
nullptr;
2600 const char *symbol_name =
nullptr;
2602 if (strtab.GetByteSize() > 0) {
2603 std::optional<llvm::StringRef> name = strtab.PeekCStr(nlist.n_strx);
2609 const bool is_dsc_local = nlist_idx >= symtab_load_command.
nsyms;
2611 "{0}symbol[{1}] has invalid or unterminated string table offset "
2612 "{2:x} in {3}, ignoring symbol",
2613 is_dsc_local ?
"DSC unmapped local " :
"",
2614 is_dsc_local ? nlist_idx - symtab_load_command.
nsyms : nlist_idx,
2615 nlist.n_strx, module_sp->GetFileSpec().GetPath()));
2620 symbol_name = name->data();
2622 const addr_t str_addr = strtab_addr + nlist.n_strx;
2624 if (process->ReadCStringFromMemory(str_addr, memory_symbol_name,
2626 symbol_name = memory_symbol_name.c_str();
2631 bool add_nlist =
true;
2632 bool is_gsym =
false;
2633 bool demangled_is_synthesized =
false;
2634 bool set_value =
true;
2636 assert(sym_idx < num_syms);
2640 switch (nlist.n_type) {
2658 symbol_name_non_abi_mangled, type)) {
2659 demangled_is_synthesized =
true;
2661 if (nlist.n_value != 0)
2663 section_info.
GetSection(nlist.n_sect, nlist.n_value);
2678 symbol_section = section_info.
GetSection(nlist.n_sect, nlist.n_value);
2680 N_FUN_addr_to_sym_idx.insert(std::make_pair(nlist.n_value, sym_idx));
2684 N_FUN_indexes.push_back(sym_idx);
2688 if (!N_FUN_indexes.empty()) {
2693 N_FUN_indexes.pop_back();
2704 N_STSYM_addr_to_sym_idx.insert(std::make_pair(nlist.n_value, sym_idx));
2705 symbol_section = section_info.
GetSection(nlist.n_sect, nlist.n_value);
2706 if (symbol_name && symbol_name[0]) {
2714 symbol_section = section_info.
GetSection(nlist.n_sect, nlist.n_value);
2745 symbol_section = section_info.
GetSection(nlist.n_sect, nlist.n_value);
2757 if (symbol_name ==
nullptr) {
2768 N_NSYM_indexes.clear();
2769 N_INCL_indexes.clear();
2770 N_BRAC_indexes.clear();
2771 N_COMM_indexes.clear();
2772 N_FUN_indexes.clear();
2778 const bool N_SO_has_full_path = symbol_name[0] ==
'/';
2779 if (N_SO_has_full_path) {
2780 if ((N_SO_index == sym_idx - 1) && ((sym_idx - 1) < num_syms)) {
2784 m_nlist_idx_to_sym_idx[nlist_idx] = sym_idx - 1;
2789 N_SO_index = sym_idx;
2791 }
else if ((N_SO_index == sym_idx - 1) &&
2792 ((sym_idx - 1) < num_syms)) {
2796 llvm::StringRef so_path =
2798 if (!so_path.empty()) {
2799 std::string full_so_path(so_path);
2800 const size_t double_slash_pos = full_so_path.find(
"//");
2801 if (double_slash_pos != std::string::npos) {
2809 so_dir.
SetFile(&full_so_path[double_slash_pos + 1],
2810 FileSpec::Style::native);
2813 full_so_path.erase(0, double_slash_pos + 1);
2817 if (*full_so_path.rbegin() !=
'/')
2818 full_so_path +=
'/';
2819 full_so_path += symbol_name;
2823 m_nlist_idx_to_sym_idx[nlist_idx] = sym_idx - 1;
2827 N_SO_index = sym_idx;
2847 N_INCL_indexes.push_back(sym_idx);
2856 if (!N_INCL_indexes.empty()) {
2860 N_INCL_indexes.pop_back();
2895 symbol_section = section_info.
GetSection(nlist.n_sect, nlist.n_value);
2904 symbol_section = section_info.
GetSection(nlist.n_sect, nlist.n_value);
2905 N_BRAC_indexes.push_back(sym_idx);
2914 symbol_section = section_info.
GetSection(nlist.n_sect, nlist.n_value);
2915 if (!N_BRAC_indexes.empty()) {
2919 N_BRAC_indexes.pop_back();
2935 N_COMM_indexes.push_back(sym_idx);
2940 symbol_section = section_info.
GetSection(nlist.n_sect, nlist.n_value);
2949 if (!N_COMM_indexes.empty()) {
2953 N_COMM_indexes.pop_back();
2972 uint8_t n_type = N_TYPE & nlist.n_type;
2973 sym[sym_idx].
SetExternal((N_EXT & nlist.n_type) != 0);
2977 std::optional<llvm::StringRef> reexport_name_str =
2978 strtab.PeekCStr(nlist.n_value);
2979 if (reexport_name_str && !reexport_name_str->empty() && symbol_name) {
2981 ConstString reexport_name(reexport_name_str->drop_front(
2982 reexport_name_str->front() ==
'_' ? 1 : 0));
2985 reexport_shlib_needs_fixup[sym_idx] = reexport_name;
2986 indirect_symbol_names.insert(
2987 ConstString(symbol_name + ((symbol_name[0] ==
'_') ? 1 : 0)));
2993 if (symbol_name && symbol_name[0]) {
2995 ((symbol_name[0] ==
'_') ? 1 : 0));
2996 undefined_name_to_desc[undefined_name] = nlist.n_desc;
3009 symbol_section = section_info.
GetSection(nlist.n_sect, nlist.n_value);
3011 if (!symbol_section) {
3017 if (TEXT_eh_frame_sectID == nlist.n_sect) {
3020 uint32_t section_type = symbol_section->Get() & SECTION_TYPE;
3022 switch (section_type) {
3023 case S_CSTRING_LITERALS:
3026 case S_4BYTE_LITERALS:
3029 case S_8BYTE_LITERALS:
3032 case S_LITERAL_POINTERS:
3035 case S_NON_LAZY_SYMBOL_POINTERS:
3038 case S_LAZY_SYMBOL_POINTERS:
3041 case S_SYMBOL_STUBS:
3045 case S_MOD_INIT_FUNC_POINTERS:
3048 case S_MOD_TERM_FUNC_POINTERS:
3055 case S_16BYTE_LITERALS:
3061 case S_LAZY_DYLIB_SYMBOL_POINTERS:
3065 switch (symbol_section->GetType()) {
3087 llvm::StringRef symbol_sect_name = symbol_section->GetName();
3088 if (symbol_section->IsDescendant(text_section_sp.get())) {
3089 if (symbol_section->IsClear(S_ATTR_PURE_INSTRUCTIONS |
3090 S_ATTR_SELF_MODIFYING_CODE |
3091 S_ATTR_SOME_INSTRUCTIONS))
3095 }
else if (symbol_section->IsDescendant(data_section_sp.get()) ||
3096 symbol_section->IsDescendant(
3097 data_dirty_section_sp.get()) ||
3098 symbol_section->IsDescendant(
3099 data_const_section_sp.get())) {
3100 if (symbol_sect_name.starts_with(
"__objc")) {
3104 symbol_name, symbol_name_non_abi_mangled, type))
3105 demangled_is_synthesized =
true;
3106 }
else if (symbol_sect_name.starts_with(
"__gcc_except_tab")) {
3111 }
else if (symbol_sect_name.starts_with(
"__IMPORT")) {
3113 }
else if (symbol_section->IsDescendant(objc_section_sp.get())) {
3115 if (symbol_name && symbol_name[0] ==
'.') {
3116 llvm::StringRef symbol_name_ref(symbol_name);
3117 llvm::StringRef g_objc_v1_prefix_class(
".objc_class_name_");
3118 if (symbol_name_ref.starts_with(g_objc_v1_prefix_class)) {
3119 symbol_name_non_abi_mangled = symbol_name;
3120 symbol_name = symbol_name + g_objc_v1_prefix_class.size();
3122 demangled_is_synthesized =
true;
3133 sym[sym_idx].
Clear();
3137 uint64_t symbol_value = nlist.n_value;
3139 if (symbol_name_non_abi_mangled) {
3145 if (symbol_name && symbol_name[0] ==
'_') {
3156 const char *gsym_name = sym[sym_idx]
3161 N_GSYM_name_to_sym_idx[gsym_name] = sym_idx;
3164 if (symbol_section) {
3165 const addr_t section_file_addr = symbol_section->GetFileAddress();
3166 symbol_value -= section_file_addr;
3175 std::pair<ValueToSymbolIndexMap::const_iterator,
3176 ValueToSymbolIndexMap::const_iterator>
3178 range = N_FUN_addr_to_sym_idx.equal_range(nlist.n_value);
3179 if (range.first != range.second) {
3180 for (ValueToSymbolIndexMap::const_iterator pos = range.first;
3181 pos != range.second; ++pos) {
3185 m_nlist_idx_to_sym_idx[nlist_idx] = pos->second;
3189 sym[pos->second].
SetExternal(sym[sym_idx].IsExternal());
3190 sym[pos->second].
SetFlags(nlist.n_type << 16 | nlist.n_desc);
3191 if (resolver_addresses.find(nlist.n_value) !=
3192 resolver_addresses.end())
3194 sym[sym_idx].
Clear();
3199 if (resolver_addresses.find(nlist.n_value) !=
3200 resolver_addresses.end())
3210 std::pair<ValueToSymbolIndexMap::const_iterator,
3211 ValueToSymbolIndexMap::const_iterator>
3213 range = N_STSYM_addr_to_sym_idx.equal_range(nlist.n_value);
3214 if (range.first != range.second) {
3215 for (ValueToSymbolIndexMap::const_iterator pos = range.first;
3216 pos != range.second; ++pos) {
3220 m_nlist_idx_to_sym_idx[nlist_idx] = pos->second;
3224 sym[pos->second].
SetExternal(sym[sym_idx].IsExternal());
3225 sym[pos->second].
SetFlags(nlist.n_type << 16 | nlist.n_desc);
3226 sym[sym_idx].
Clear();
3232 const char *gsym_name = sym[sym_idx]
3237 ConstNameToSymbolIndexMap::const_iterator pos =
3238 N_GSYM_name_to_sym_idx.find(gsym_name);
3239 if (pos != N_GSYM_name_to_sym_idx.end()) {
3240 const uint32_t GSYM_sym_idx = pos->second;
3241 m_nlist_idx_to_sym_idx[nlist_idx] = GSYM_sym_idx;
3245 Address(symbol_section, symbol_value);
3246 add_symbol_addr(sym[GSYM_sym_idx].GetAddress().GetFileAddress());
3250 sym[GSYM_sym_idx].
SetFlags(nlist.n_type << 16 | nlist.n_desc);
3251 sym[sym_idx].
Clear();
3259 sym[sym_idx].
SetID(nlist_idx);
3264 add_symbol_addr(sym[sym_idx].GetAddress().GetFileAddress());
3266 sym[sym_idx].
SetFlags(nlist.n_type << 16 | nlist.n_desc);
3269 if (nlist.n_desc & N_WEAK_REF)
3272 if (demangled_is_synthesized)
3280 auto ParseNListsLambda = [&](
DataExtractor &nlist_extractor,
3282 uint32_t end_nlist_idx,
3286 std::vector<struct nlist_64> nlists;
3288 std::min<uint64_t>(end_nlist_idx - first_nlist_idx,
3289 nlist_extractor.
GetByteSize() / nlist_byte_size));
3290 for (uint32_t i = first_nlist_idx; i < end_nlist_idx; ++i) {
3291 if (
auto nlist =
ParseNList(nlist_extractor, offset, nlist_byte_size))
3292 nlists.push_back(*nlist);
3301 uint32_t nlist_idx = first_nlist_idx;
3302 for (
auto &nlist : nlists)
3303 ParseSymbolLambda(nlist, nlist_idx++,
DebugSymbols, strtab);
3306 nlist_idx = first_nlist_idx;
3307 for (
auto &nlist : nlists)
3323 __block
void *nlist_buffer =
nullptr;
3324 __block
unsigned nlist_count = 0;
3325 __block
char *string_table =
nullptr;
3326 __block vm_offset_t vm_nlist_memory = 0;
3327 __block mach_msg_type_number_t vm_nlist_bytes_read = 0;
3328 __block vm_offset_t vm_string_memory = 0;
3329 __block mach_msg_type_number_t vm_string_bytes_read = 0;
3331 llvm::scope_exit _(^{
3332 if (vm_nlist_memory)
3333 vm_deallocate(
mach_task_self(), vm_nlist_memory, vm_nlist_bytes_read);
3334 if (vm_string_memory)
3335 vm_deallocate(
mach_task_self(), vm_string_memory, vm_string_bytes_read);
3347 UUID process_shared_cache_uuid;
3348 addr_t process_shared_cache_base_addr;
3352 process_shared_cache_uuid);
3355 __block
bool found_image =
false;
3359 auto nlist_extraction_block = ^(
const void *nlistStart, uint64_t nlistCount,
3360 const char *stringTable) {
3361 if (!nlistStart || !nlistCount)
3367 kern_return_t ret = vm_read(
mach_task_self(), (vm_address_t)nlistStart,
3368 nlist_byte_size * nlistCount,
3369 &vm_nlist_memory, &vm_nlist_bytes_read);
3372 assert(vm_nlist_bytes_read == nlist_byte_size * nlistCount);
3377 vm_address_t string_address = (vm_address_t)stringTable;
3378 vm_size_t region_size;
3379 mach_msg_type_number_t info_count = VM_REGION_BASIC_INFO_COUNT_64;
3380 vm_region_basic_info_data_t info;
3381 memory_object_name_t object;
3382 ret = vm_region_64(
mach_task_self(), &string_address, ®ion_size,
3383 VM_REGION_BASIC_INFO_64, (vm_region_info_t)&info,
3384 &info_count, &
object);
3389 region_size - ((vm_address_t)stringTable - string_address),
3390 &vm_string_memory, &vm_string_bytes_read);
3394 nlist_buffer = (
void *)vm_nlist_memory;
3395 string_table = (
char *)vm_string_memory;
3396 nlist_count = nlistCount;
3402 image_uuid, process_shared_cache_uuid,
3406 dyld_image_local_nlist_content_4Symbolication((
dyld_image_t)image,
3407 nlist_extraction_block);
3418 if (process_shared_cache_uuid.
IsValid() &&
3419 process_shared_cache_uuid !=
UUID(&cache_uuid, 16))
3428 if (image_uuid !=
UUID(dsc_image_uuid, 16))
3432 dyld_image_local_nlist_content_4Symbolication(image,
3433 nlist_extraction_block);
3438 unmapped_local_symbols_found = nlist_count;
3443 unmapped_local_symbols_found -
m_dysymtab.nlocalsym);
3450 if (nlist_data.GetByteSize() > 0) {
3452 const uint64_t max_nsyms = nlist_data.GetByteSize() / nlist_byte_size;
3453 const uint64_t max_nindirectsyms =
3454 indirect_symbol_index_data.GetByteSize() /
sizeof(uint32_t);
3458 if (sym ==
nullptr) {
3460 std::min<uint64_t>(symtab_load_command.
nsyms, max_nsyms) +
3461 std::min<uint64_t>(
m_dysymtab.nindirectsyms, max_nindirectsyms));
3465 uint32_t first_nlist_idx = 0;
3466 if (unmapped_local_symbols_found) {
3468 nlist_data_offset += (
m_dysymtab.nlocalsym * nlist_byte_size);
3472 ParseNListsLambda(nlist_data, nlist_data_offset, first_nlist_idx,
3473 symtab_load_command.
nsyms, strtab_data);
3479 nlist_count * nlist_byte_size,
3480 byte_order, addr_byte_size);
3481 DataExtractor dsc_string_table_data(string_table, vm_string_bytes_read,
3482 byte_order, addr_byte_size);
3485 ParseNListsLambda(dsc_local_symbols_data, 0, symtab_load_command.
nsyms,
3486 symtab_load_command.
nsyms + nlist_count,
3487 dsc_string_table_data);
3491 for (
const auto &pos : reexport_shlib_needs_fixup) {
3492 const auto undef_pos = undefined_name_to_desc.find(pos.second);
3493 if (undef_pos != undefined_name_to_desc.end()) {
3494 const uint8_t dylib_ordinal =
3495 llvm::MachO::GET_LIBRARY_ORDINAL(undef_pos->second);
3496 if (dylib_ordinal > 0 && dylib_ordinal < dylib_files.
GetSize())
3503 int trie_symbol_table_augment_count = 0;
3504 for (
auto &e : external_sym_trie_entries) {
3505 if (!symbols_added.contains(e.entry.address))
3506 trie_symbol_table_augment_count++;
3509 if (num_syms < sym_idx + trie_symbol_table_augment_count) {
3510 num_syms = sym_idx + trie_symbol_table_augment_count;
3511 sym = symtab.
Resize(num_syms);
3513 uint32_t synthetic_sym_id =
3514 symtab_load_command.
nsyms + unmapped_local_symbols_found;
3517 for (
auto &e : external_sym_trie_entries) {
3518 if (symbols_added.contains(e.entry.address))
3524 if (module_sp->ResolveFileAddress(e.entry.address, symbol_addr)) {
3526 const char *symbol_name = e.entry.name.GetCString();
3527 bool demangled_is_synthesized =
false;
3529 GetSymbolType(symbol_name, demangled_is_synthesized, text_section_sp,
3530 data_section_sp, data_dirty_section_sp,
3531 data_const_section_sp, symbol_section);
3534 if (symbol_section) {
3535 sym[sym_idx].
SetID(synthetic_sym_id++);
3537 if (demangled_is_synthesized)
3550 if (function_starts_count > 0) {
3551 uint32_t num_synthetic_function_symbols = 0;
3552 for (i = 0; i < function_starts_count; ++i) {
3553 if (!symbols_added.contains(function_starts.GetEntryRef(i).addr))
3554 ++num_synthetic_function_symbols;
3557 if (num_synthetic_function_symbols > 0) {
3558 if (num_syms < sym_idx + num_synthetic_function_symbols) {
3559 num_syms = sym_idx + num_synthetic_function_symbols;
3560 sym = symtab.
Resize(num_syms);
3562 for (i = 0; i < function_starts_count; ++i) {
3563 const FunctionStarts::Entry *func_start_entry =
3564 function_starts.GetEntryAtIndex(i);
3565 if (!symbols_added.contains(func_start_entry->addr)) {
3566 addr_t symbol_file_addr = func_start_entry->addr;
3567 uint32_t symbol_flags = 0;
3568 if (func_start_entry->data)
3571 if (module_sp->ResolveFileAddress(symbol_file_addr, symbol_addr)) {
3573 if (symbol_section) {
3574 sym[sym_idx].
SetID(synthetic_sym_id++);
3584 sym[sym_idx].
SetFlags(symbol_flags);
3595 if (sym_idx < num_syms) {
3597 sym = symtab.
Resize(num_syms);
3602 if (indirect_symbol_index_data.GetByteSize()) {
3603 NListIndexToSymbolIndexMap::const_iterator end_index_pos =
3604 m_nlist_idx_to_sym_idx.end();
3611 if (symbol_stub_byte_size == 0)
3614 const uint32_t num_symbol_stubs =
3617 if (num_symbol_stubs == 0)
3620 const uint32_t symbol_stub_index_offset =
3622 for (uint32_t stub_idx = 0; stub_idx < num_symbol_stubs; ++stub_idx) {
3623 const uint32_t symbol_stub_index =
3624 symbol_stub_index_offset + stub_idx;
3627 (stub_idx * symbol_stub_byte_size);
3629 if (indirect_symbol_index_data.ValidOffsetForDataOfSize(
3630 symbol_stub_offset, 4)) {
3631 const uint32_t stub_sym_id =
3632 indirect_symbol_index_data.GetU32(&symbol_stub_offset);
3633 if (stub_sym_id & (INDIRECT_SYMBOL_ABS | INDIRECT_SYMBOL_LOCAL))
3636 NListIndexToSymbolIndexMap::const_iterator index_pos =
3637 m_nlist_idx_to_sym_idx.find(stub_sym_id);
3638 Symbol *stub_symbol =
nullptr;
3639 if (index_pos != end_index_pos) {
3650 Address so_addr(symbol_stub_addr, section_list);
3657 if (resolver_addresses.find(symbol_stub_addr) ==
3658 resolver_addresses.end())
3668 if (sym_idx >= num_syms) {
3669 sym = symtab.
Resize(++num_syms);
3670 stub_symbol =
nullptr;
3672 sym[sym_idx].
SetID(synthetic_sym_id++);
3673 sym[sym_idx].
GetMangled() = stub_symbol_mangled_name;
3674 if (resolver_addresses.find(symbol_stub_addr) ==
3675 resolver_addresses.end())
3687 "warning: symbol stub referencing symbol table "
3688 "symbol %u that isn't in our minimal symbol table, "
3699 if (!reexport_trie_entries.empty()) {
3700 for (
const auto &e : reexport_trie_entries) {
3701 if (e.entry.import_name) {
3704 if (indirect_symbol_names.find(e.entry.name) ==
3705 indirect_symbol_names.end()) {
3707 if (sym_idx >= num_syms)
3708 sym = symtab.
Resize(++num_syms);
3709 sym[sym_idx].
SetID(synthetic_sym_id++);
3714 if (e.entry.other > 0 && e.entry.other <= dylib_files.
GetSize()) {
3733 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
3734 s->
Printf(
"%p: ",
static_cast<void *
>(
this));
3741 *s <<
", file = '" <<
m_file;
3747 for (
unsigned i = 0, e = all_specs.
GetSize(); i != e; ++i) {
3772 llvm::MachO::uuid_command load_cmd;
3775 for (i = 0; i < header.ncmds; ++i) {
3780 if (load_cmd.cmd == LC_UUID) {
3781 const uint8_t *uuid_bytes = data.
PeekData(offset, 16);
3787 const uint8_t opencl_uuid[] = {0x8c, 0x8e, 0xb3, 0x9b, 0x3b, 0xa8,
3788 0x4b, 0x16, 0xb6, 0xa4, 0x27, 0x63,
3789 0xbb, 0x14, 0xf0, 0x0d};
3791 if (!memcmp(uuid_bytes, opencl_uuid, 16))
3794 return UUID(uuid_bytes, 16);
3798 offset = cmd_offset + load_cmd.cmdsize;
3805 case llvm::MachO::LC_VERSION_MIN_IPHONEOS:
3806 return llvm::Triple::getOSTypeName(llvm::Triple::IOS);
3807 case llvm::MachO::LC_VERSION_MIN_MACOSX:
3808 return llvm::Triple::getOSTypeName(llvm::Triple::MacOSX);
3809 case llvm::MachO::LC_VERSION_MIN_TVOS:
3810 return llvm::Triple::getOSTypeName(llvm::Triple::TvOS);
3811 case llvm::MachO::LC_VERSION_MIN_WATCHOS:
3812 return llvm::Triple::getOSTypeName(llvm::Triple::WatchOS);
3814 llvm_unreachable(
"unexpected LC_VERSION load command");
3820 llvm::StringRef os_type;
3821 llvm::StringRef environment;
3822 OSEnv(uint32_t cmd) {
3824 case llvm::MachO::PLATFORM_MACOS:
3825 os_type = llvm::Triple::getOSTypeName(llvm::Triple::MacOSX);
3827 case llvm::MachO::PLATFORM_IOS:
3828 os_type = llvm::Triple::getOSTypeName(llvm::Triple::IOS);
3830 case llvm::MachO::PLATFORM_TVOS:
3831 os_type = llvm::Triple::getOSTypeName(llvm::Triple::TvOS);
3833 case llvm::MachO::PLATFORM_WATCHOS:
3834 os_type = llvm::Triple::getOSTypeName(llvm::Triple::WatchOS);
3836 case llvm::MachO::PLATFORM_BRIDGEOS:
3837 os_type = llvm::Triple::getOSTypeName(llvm::Triple::BridgeOS);
3839 case llvm::MachO::PLATFORM_DRIVERKIT:
3840 os_type = llvm::Triple::getOSTypeName(llvm::Triple::DriverKit);
3842 case llvm::MachO::PLATFORM_MACCATALYST:
3843 os_type = llvm::Triple::getOSTypeName(llvm::Triple::IOS);
3844 environment = llvm::Triple::getEnvironmentTypeName(llvm::Triple::MacABI);
3846 case llvm::MachO::PLATFORM_IOSSIMULATOR:
3847 os_type = llvm::Triple::getOSTypeName(llvm::Triple::IOS);
3849 llvm::Triple::getEnvironmentTypeName(llvm::Triple::Simulator);
3851 case llvm::MachO::PLATFORM_TVOSSIMULATOR:
3852 os_type = llvm::Triple::getOSTypeName(llvm::Triple::TvOS);
3854 llvm::Triple::getEnvironmentTypeName(llvm::Triple::Simulator);
3856 case llvm::MachO::PLATFORM_WATCHOSSIMULATOR:
3857 os_type = llvm::Triple::getOSTypeName(llvm::Triple::WatchOS);
3859 llvm::Triple::getEnvironmentTypeName(llvm::Triple::Simulator);
3861 case llvm::MachO::PLATFORM_XROS:
3862 os_type = llvm::Triple::getOSTypeName(llvm::Triple::XROS);
3864 case llvm::MachO::PLATFORM_XROS_SIMULATOR:
3865 os_type = llvm::Triple::getOSTypeName(llvm::Triple::XROS);
3867 llvm::Triple::getEnvironmentTypeName(llvm::Triple::Simulator);
3870 Log *log(
GetLog(LLDBLog::Symbols | LLDBLog::Process));
3871 LLDB_LOGF(log,
"unsupported platform in LC_BUILD_VERSION");
3878 uint32_t major_version, minor_version, patch_version;
3879 MinOS(uint32_t version)
3880 : major_version(version >> 16), minor_version((version >> 8) & 0xffu),
3881 patch_version(version & 0xffu) {}
3892 if (!base_arch.IsValid())
3895 bool found_any =
false;
3896 auto add_triple = [&](
const llvm::Triple &triple) {
3897 auto spec = base_spec;
3899 if (spec.GetArchitecture().IsValid()) {
3907 llvm::Triple base_triple = base_arch.GetTriple();
3908 base_triple.setOS(llvm::Triple::UnknownOS);
3909 base_triple.setOSName(llvm::StringRef());
3911 if (header.filetype == MH_PRELOAD) {
3912 if (header.cputype == CPU_TYPE_ARM) {
3918 base_triple.setVendor(llvm::Triple::Apple);
3923 base_triple.setVendor(llvm::Triple::UnknownVendor);
3924 base_triple.setVendorName(llvm::StringRef());
3926 return add_triple(base_triple);
3929 llvm::MachO::load_command load_cmd;
3934 for (uint32_t i = 0; i < header.ncmds; ++i) {
3939 llvm::MachO::version_min_command version_min;
3940 switch (load_cmd.cmd) {
3941 case llvm::MachO::LC_VERSION_MIN_MACOSX:
3942 case llvm::MachO::LC_VERSION_MIN_IPHONEOS:
3943 case llvm::MachO::LC_VERSION_MIN_TVOS:
3944 case llvm::MachO::LC_VERSION_MIN_WATCHOS: {
3945 if (load_cmd.cmdsize !=
sizeof(version_min))
3950 MinOS min_os(version_min.version);
3951 llvm::SmallString<32> os_name;
3952 llvm::raw_svector_ostream os(os_name);
3953 os <<
GetOSName(load_cmd.cmd) << min_os.major_version <<
'.'
3954 << min_os.minor_version <<
'.' << min_os.patch_version;
3956 auto triple = base_triple;
3957 triple.setOSName(os.str());
3960 if (load_cmd.cmd != llvm::MachO::LC_VERSION_MIN_MACOSX &&
3961 (base_triple.getArch() == llvm::Triple::x86_64 ||
3962 base_triple.getArch() == llvm::Triple::x86)) {
3969 triple.setEnvironment(llvm::Triple::Simulator);
3978 offset = cmd_offset + load_cmd.cmdsize;
3984 for (uint32_t i = 0; i < header.ncmds; ++i) {
3990 if (load_cmd.cmd == llvm::MachO::LC_BUILD_VERSION) {
3991 llvm::MachO::build_version_command build_version;
3992 if (load_cmd.cmdsize <
sizeof(build_version)) {
3996 if (data.
ExtractBytes(cmd_offset,
sizeof(build_version),
3999 MinOS min_os(build_version.minos);
4000 OSEnv os_env(build_version.platform);
4001 llvm::SmallString<16> os_name;
4002 llvm::raw_svector_ostream os(os_name);
4003 os << os_env.os_type << min_os.major_version <<
'.'
4004 << min_os.minor_version <<
'.' << min_os.patch_version;
4005 auto triple = base_triple;
4006 triple.setOSName(os.str());
4008 if (!os_env.environment.empty())
4009 triple.setEnvironmentName(os_env.environment);
4013 offset = cmd_offset + load_cmd.cmdsize;
4017 add_triple(base_triple);
4022 ModuleSP module_sp,
const llvm::MachO::mach_header &header,
4027 base_spec, all_specs);
4032 const ArchSpec &module_arch = module_sp->GetArchitecture();
4033 for (
unsigned i = 0, e = all_specs.
GetSize(); i != e; ++i) {
4050 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
4063 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
4064 llvm::MachO::load_command load_cmd;
4066 std::vector<std::string> rpath_paths;
4067 std::vector<std::string> rpath_relative_paths;
4068 std::vector<std::string> at_exec_relative_paths;
4070 for (i = 0; i <
m_header.ncmds; ++i) {
4071 const uint32_t cmd_offset = offset;
4075 switch (load_cmd.cmd) {
4078 case LC_LOAD_WEAK_DYLIB:
4079 case LC_REEXPORT_DYLIB:
4080 case LC_LOAD_DYLINKER:
4082 case LC_LOAD_UPWARD_DYLIB: {
4083 uint32_t name_offset = cmd_offset +
m_data_nsp->GetU32(&offset);
4088 bool is_delayed_init =
false;
4089 uint32_t use_command_marker =
m_data_nsp->GetU32(&offset);
4090 if (use_command_marker == 0x1a741800 ) {
4093 uint32_t flags =
m_data_nsp->GetU32(&offset);
4099 is_delayed_init =
true;
4101 std::optional<llvm::StringRef> maybe_path =
4103 if (maybe_path && !is_delayed_init) {
4104 llvm::StringRef path = *maybe_path;
4105 if (load_cmd.cmd == LC_RPATH)
4106 rpath_paths.push_back(path.str());
4107 else if (path.consume_front(
"@rpath"))
4108 rpath_relative_paths.push_back(path.str());
4109 else if (path.consume_front(
"@executable_path"))
4110 at_exec_relative_paths.push_back(path.str());
4111 else if (!path.starts_with(
"@")) {
4122 offset = cmd_offset + load_cmd.cmdsize;
4128 if (!rpath_paths.empty()) {
4130 const std::string this_directory = this_file_spec.
GetDirectory().str();
4131 for (
auto &rpath : rpath_paths) {
4133 rpath = this_directory + rpath.substr(
g_loader_path.size());
4138 for (
const auto &rpath_relative_path : rpath_relative_paths) {
4139 for (
const auto &rpath : rpath_paths) {
4140 std::string path = rpath;
4141 path += rpath_relative_path;
4161 for (
const auto &at_exec_relative_path : at_exec_relative_paths) {
4208 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
4209 llvm::MachO::load_command load_cmd;
4215 for (i = 0; i <
m_header.ncmds; ++i) {
4220 switch (load_cmd.cmd) {
4223 while (offset < cmd_offset + load_cmd.cmdsize) {
4224 uint32_t flavor =
m_data_nsp->GetU32(&offset);
4225 uint32_t count =
m_data_nsp->GetU32(&offset);
4232 case llvm::MachO::CPU_TYPE_ARM:
4243 case llvm::MachO::CPU_TYPE_ARM64:
4244 case llvm::MachO::CPU_TYPE_ARM64_32:
4253 case llvm::MachO::CPU_TYPE_X86_64:
4270 offset += count * 4;
4274 uint64_t entryoffset =
m_data_nsp->GetU64(&offset);
4277 if (text_segment_sp) {
4279 start_address = text_segment_sp->GetFileAddress() + entryoffset;
4290 offset = cmd_offset + load_cmd.cmdsize;
4295 const Symbol *dyld_start_sym =
4321 module_sp->FindSymbolsWithNameAndType(
ConstString(
"start"),
4340 if (text_segment_sp)
4341 header_addr =
Address(text_segment_sp, 0);
4349 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
4354 llvm::MachO::thread_command thread_cmd;
4355 for (uint32_t i = 0; i <
m_header.ncmds; ++i) {
4356 const uint32_t cmd_offset = offset;
4360 if (thread_cmd.cmd == LC_THREAD) {
4365 offset = cmd_offset + thread_cmd.cmdsize;
4372std::vector<std::tuple<offset_t, offset_t>>
4374 std::vector<std::tuple<offset_t, offset_t>> results;
4377 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
4380 for (uint32_t i = 0; i <
m_header.ncmds; ++i) {
4381 const uint32_t cmd_offset = offset;
4382 llvm::MachO::load_command lc = {};
4385 if (lc.cmd == LC_NOTE) {
4386 char data_owner[17];
4387 m_data_nsp->CopyData(offset, 16, data_owner);
4388 data_owner[16] =
'\0';
4391 if (name == data_owner) {
4394 results.push_back({payload_offset, payload_size});
4397 offset = cmd_offset + lc.cmdsize;
4408 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
4411 for (
auto lc_note : lc_notes) {
4412 offset_t payload_offset = std::get<0>(lc_note);
4413 offset_t payload_size = std::get<1>(lc_note);
4415 if (
m_data_nsp->GetU32(&payload_offset, &version, 1) !=
nullptr) {
4417 uint32_t strsize = payload_size -
sizeof(uint32_t);
4418 std::string result(strsize,
'\0');
4419 m_data_nsp->CopyData(payload_offset, strsize, result.data());
4420 LLDB_LOGF(log,
"LC_NOTE 'kern ver str' found with text '%s'",
4430 for (uint32_t i = 0; i <
m_header.ncmds; ++i) {
4431 const uint32_t cmd_offset = offset;
4432 llvm::MachO::ident_command ident_command;
4435 if (ident_command.cmd == LC_IDENT && ident_command.cmdsize != 0) {
4436 std::string result(ident_command.cmdsize,
'\0');
4437 if (
m_data_nsp->CopyData(offset, ident_command.cmdsize,
4438 result.data()) == ident_command.cmdsize) {
4439 LLDB_LOGF(log,
"LC_IDENT found with text '%s'", result.c_str());
4443 offset = cmd_offset + ident_command.cmdsize;
4455 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
4457 for (
auto lc_note : lc_notes) {
4458 offset_t payload_offset = std::get<0>(lc_note);
4460 if (
m_data_nsp->GetU32(&payload_offset, &version, 1) !=
nullptr) {
4462 uint32_t num_addr_bits =
4463 m_data_nsp->GetU32_unchecked(&payload_offset);
4466 "LC_NOTE 'addrable bits' v3 found, value %d "
4471 uint32_t lo_addr_bits =
m_data_nsp->GetU32_unchecked(&payload_offset);
4472 uint32_t hi_addr_bits =
m_data_nsp->GetU32_unchecked(&payload_offset);
4474 if (lo_addr_bits == hi_addr_bits)
4478 LLDB_LOGF(log,
"LC_NOTE 'addrable bits' v4 found, value %d & %d bits",
4479 lo_addr_bits, hi_addr_bits);
4484 return addressable_bits;
4488 bool &value_is_offset,
4494 value_is_offset =
false;
4496 uint32_t log2_pagesize = 0;
4497 uint32_t platform = 0;
4500 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
4503 for (
auto lc_note : lc_notes) {
4504 offset_t payload_offset = std::get<0>(lc_note);
4543 if (
m_data_nsp->GetU32(&payload_offset, &version, 1) !=
nullptr &&
4545 uint32_t binspec_type = 0;
4547 memset(raw_uuid, 0,
sizeof(
uuid_t));
4549 if (!
m_data_nsp->GetU32(&payload_offset, &binspec_type, 1))
4551 if (!
m_data_nsp->GetU64(&payload_offset, &value, 1))
4554 if (version > 1 && !
m_data_nsp->GetU64(&payload_offset, &slide, 1))
4558 value_is_offset =
true;
4566 const char *typestr =
"unrecognized type";
4568 switch (binspec_type) {
4575 typestr =
"xnu kernel";
4579 typestr =
"userland dyld";
4583 typestr =
"standalone";
4587 typestr =
"userland dyld_all_image_infos";
4591 "LC_NOTE 'main bin spec' found, version %d type %d "
4592 "(%s), value 0x%" PRIx64
" value-is-slide==%s uuid %s",
4593 version, type, typestr, value,
4594 value_is_offset ?
"true" :
"false",
4596 if (!
m_data_nsp->GetU32(&payload_offset, &log2_pagesize, 1))
4598 if (version > 1 && !
m_data_nsp->GetU32(&payload_offset, &platform, 1))
4609 std::vector<lldb::tid_t> &tids) {
4613 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
4621 "'process metadata' LC_NOTE does not have a 'threads' key");
4625 LLDB_LOGF(log,
"Unable to read 'process metadata' LC_NOTE, number of "
4626 "threads does not match number of LC_THREADS.");
4629 const size_t num_threads = threads->
GetSize();
4630 for (
size_t i = 0; i < num_threads; i++) {
4631 std::optional<StructuredData::Dictionary *> maybe_thread =
4633 if (!maybe_thread) {
4635 "Unable to read 'process metadata' LC_NOTE, threads "
4636 "array does not have a dictionary at index %zu.",
4642 if (thread->GetValueForKeyAsInteger<
lldb::tid_t>(
"thread_id", tid))
4645 tids.push_back(tid);
4650 logmsg.
Printf(
"LC_NOTE 'process metadata' found: ");
4651 dict->
Dump(logmsg,
false);
4675 const uint8_t *bytes = data.
PeekData(offset, size);
4677 return llvm::createStringError(
4678 "payload of %" PRIu64
" bytes is out of bounds", size);
4679 llvm::ArrayRef<uint8_t> payload(bytes, size);
4681 constexpr llvm::StringLiteral magic =
"ZLIB";
4682 constexpr size_t header_size = magic.size() +
sizeof(uint64_t);
4683 if (!llvm::toStringRef(payload).starts_with(magic))
4684 return llvm::toStringRef(payload).str();
4685 if (payload.size() < header_size)
4686 return llvm::createStringError(
"compressed payload header is truncated");
4688 uint64_t uncompressed_size =
4689 llvm::support::endian::read64be(payload.data() + magic.size());
4690 llvm::ArrayRef<uint8_t> compressed = payload.drop_front(header_size);
4693 if (uncompressed_size / 1032 > compressed.size())
4694 return llvm::createStringError(
"uncompressed size %" PRIu64
4695 " is impossible for %zu compressed bytes",
4696 uncompressed_size, compressed.size());
4697 if (!llvm::compression::zlib::isAvailable())
4698 return llvm::createStringError(
4699 "payload is zlib-compressed but LLDB was built without zlib");
4701 llvm::SmallVector<uint8_t, 0> uncompressed;
4702 if (llvm::Error err = llvm::compression::zlib::decompress(
4703 compressed, uncompressed, uncompressed_size))
4705 return llvm::toStringRef(uncompressed).str();
4714 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
4716 if (lc_notes.size() == 0)
4719 if (lc_notes.size() > 1)
4722 "Multiple 'process metadata' LC_NOTEs found, only using the first.");
4724 auto [payload_offset, payload_size] = lc_notes[0];
4725 llvm::Expected<std::string> json =
4729 "Unable to read 'process metadata' LC_NOTE: {0}");
4735 LLDB_LOGF(log,
"Unable to read 'process metadata' LC_NOTE, did not "
4736 "parse as valid JSON.");
4741 LLDB_LOGF(log,
"Unable to read 'process metadata' LC_NOTE, did not "
4742 "get a dictionary.");
4756 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
4762 if (thread_context_file_range) {
4768 case llvm::MachO::CPU_TYPE_ARM64:
4769 case llvm::MachO::CPU_TYPE_ARM64_32:
4771 std::make_shared<RegisterContextDarwin_arm64_Mach>(thread, data);
4774 case llvm::MachO::CPU_TYPE_ARM:
4776 std::make_shared<RegisterContextDarwin_arm_Mach>(thread, data);
4779 case llvm::MachO::CPU_TYPE_X86_64:
4781 std::make_shared<RegisterContextDarwin_x86_64_Mach>(thread, data);
4784 case llvm::MachO::CPU_TYPE_RISCV:
4786 std::make_shared<RegisterContextDarwin_riscv32_Mach>(thread, data);
4829 case MH_KEXT_BUNDLE:
4857 if (
m_header.flags & MH_DYLDLINK) {
4884 case MH_KEXT_BUNDLE:
4895 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
4896 llvm::MachO::dylib_command load_cmd;
4898 uint32_t version_cmd = 0;
4899 uint64_t version = 0;
4901 for (i = 0; i <
m_header.ncmds; ++i) {
4906 if (load_cmd.cmd == LC_ID_DYLIB) {
4907 if (version_cmd == 0) {
4908 version_cmd = load_cmd.cmd;
4909 if (
m_data_nsp->GetU32(&offset, &load_cmd.dylib, 4) ==
nullptr)
4911 version = load_cmd.dylib.current_version;
4916 offset = cmd_offset + load_cmd.cmdsize;
4919 if (version_cmd == LC_ID_DYLIB) {
4920 unsigned major = (version & 0xFFFF0000ull) >> 16;
4921 unsigned minor = (version & 0x0000FF00ull) >> 8;
4922 unsigned subminor = (version & 0x000000FFull);
4923 return llvm::VersionTuple(major, minor, subminor);
4926 return llvm::VersionTuple();
4933 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
4950 std::optional<uint64_t> size;
4952 private_shared_cache, sc_filepath, size);
4957 "inferior process shared cache has a UUID of %s, base address 0x%" PRIx64,
4980#if defined(__APPLE__)
4981 uint8_t *(*dyld_get_all_image_infos)(void);
4982 dyld_get_all_image_infos =
4983 (uint8_t * (*)()) dlsym(RTLD_DEFAULT,
"_dyld_get_all_image_infos");
4984 if (dyld_get_all_image_infos) {
4985 uint8_t *dyld_all_image_infos_address = dyld_get_all_image_infos();
4986 if (dyld_all_image_infos_address) {
4987 uint32_t *version = (uint32_t *)
4988 dyld_all_image_infos_address;
4989 if (*version >= 13) {
4990 uuid_t *sharedCacheUUID_address = 0;
4991 int wordsize =
sizeof(uint8_t *);
4992 if (wordsize == 8) {
4993 sharedCacheUUID_address =
4994 (
uuid_t *)((uint8_t *)dyld_all_image_infos_address +
4999 *)((uint8_t *)dyld_all_image_infos_address +
5002 sharedCacheUUID_address =
5003 (
uuid_t *)((uint8_t *)dyld_all_image_infos_address +
5005 if (*version >= 15) {
5009 *)((uint8_t *)dyld_all_image_infos_address +
5013 uuid =
UUID(sharedCacheUUID_address,
sizeof(
uuid_t));
5019 unsigned int task, uint64_t timestamp,
5020 unsigned int *kernelError);
5021 void (*dyld_process_info_get_cache)(
void *info,
void *cacheInfo);
5024 dyld_process_info_create = (
void *(*)(
unsigned int , uint64_t,
5026 dlsym(RTLD_DEFAULT,
"_dyld_process_info_create");
5027 dyld_process_info_get_cache = (void (*)(
void *,
void *))dlsym(
5028 RTLD_DEFAULT,
"_dyld_process_info_get_cache");
5029 dyld_process_info_release =
5030 (void (*)(
void *))dlsym(RTLD_DEFAULT,
"_dyld_process_info_release");
5032 if (dyld_process_info_create && dyld_process_info_get_cache) {
5033 unsigned int kern_ret;
5039 dyld_process_info_get_cache(process_info, &sc_info);
5044 dyld_process_info_release(process_info);
5051 "lldb's in-memory shared cache has a UUID of %s base address of "
5060 for (
size_t i = 0; i < ncmds; i++) {
5062 llvm::MachO::load_command lc = {};
5066 uint32_t version = 0;
5067 if (lc.cmd == llvm::MachO::LC_VERSION_MIN_MACOSX ||
5068 lc.cmd == llvm::MachO::LC_VERSION_MIN_IPHONEOS ||
5069 lc.cmd == llvm::MachO::LC_VERSION_MIN_TVOS ||
5070 lc.cmd == llvm::MachO::LC_VERSION_MIN_WATCHOS) {
5078 version = data.
GetU32(&offset);
5079 }
else if (lc.cmd == llvm::MachO::LC_BUILD_VERSION) {
5089 offset +=
sizeof(uint32_t);
5090 version = data.
GetU32(&offset);
5094 const uint32_t xxxx = version >> 16;
5095 const uint32_t yy = (version >> 8) & 0xffu;
5096 const uint32_t zz = version & 0xffu;
5098 return llvm::VersionTuple(xxxx, yy, zz);
5100 offset = load_cmd_offset + lc.cmdsize;
5102 return llvm::VersionTuple();
5120 return m_header.filetype == llvm::MachO::MH_DYLINKER;
5126 return m_header.filetype == llvm::MachO::MH_DSYM;
5152 return text_segment_sp.get();
5154 const size_t num_sections = section_list->
GetSize();
5155 for (
size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
5165 assert(section.
GetObjectFile() ==
this &&
"Wrong object file!");
5170 const bool is_data_const_got =
5171 segment->GetName() ==
"__DATA_CONST" && section.
GetName() ==
"__got";
5172 const bool is_auth_const_ptr =
5173 segment->GetName() ==
"__AUTH_CONST" &&
5174 (section.
GetName() ==
"__auth_got" || section.
GetName() ==
"__auth_ptr");
5175 return is_data_const_got || is_auth_const_ptr;
5209 if (module_sp && header_section && section &&
5213 return section->
GetFileAddress() - file_addr + header_load_address;
5219 bool value_is_offset) {
5229 size_t num_loaded_sections = 0;
5230 const size_t num_sections = section_list->
GetSize();
5234 const bool warn_multiple =
true;
5238 logmsg <<
"ObjectFileMachO::SetLoadAddress ";
5246 if (value_is_offset) {
5248 for (
size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
5255 "ObjectFileMachO::SetLoadAddress segment '{0}' load addr is {1:x}",
5256 section_sp->GetName(), section_sp->GetFileAddress() + value);
5258 section_sp->GetFileAddress() + value,
5260 ++num_loaded_sections;
5268 if (mach_header_section) {
5269 for (
size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
5274 value, mach_header_section, section_sp.get());
5277 "ObjectFileMachO::SetLoadAddress segment '{0}' load addr is "
5279 section_sp->GetName(), section_load_addr);
5282 ++num_loaded_sections;
5287 return num_loaded_sections > 0;
5372 Target &target = process_sp->GetTarget();
5381 std::set<std::string> executing_uuids;
5382 std::vector<ThreadSP> thread_list =
5383 process_sp->CalculateCoreFileThreadList(options);
5384 for (
const ThreadSP &thread_sp : thread_list) {
5385 uint32_t stack_frame_count = thread_sp->GetStackFrameCount();
5386 for (uint32_t j = 0; j < stack_frame_count; j++) {
5387 StackFrameSP stack_frame_sp = thread_sp->GetStackFrameAtIndex(j);
5388 Address pc = stack_frame_sp->GetFrameCodeAddress();
5391 UUID uuid = module_sp->GetUUID();
5399 size_t modules_count = modules.
GetSize();
5417 std::vector<std::vector<segment_vmaddr>> modules_segment_vmaddrs;
5418 for (
size_t i = 0; i < modules_count; i++) {
5422 size_t sections_count = sections->
GetSize();
5423 std::vector<segment_vmaddr> segment_vmaddrs;
5424 for (
size_t j = 0; j < sections_count; j++) {
5426 if (!section->GetParent().get()) {
5427 addr_t vmaddr = section->GetLoadBaseAddress(&target);
5430 llvm::StringRef name = section->GetName();
5438 strncpy(seg_vmaddr.
segname, name.data(),
5439 std::min(name.size(),
sizeof(seg_vmaddr.
segname)));
5440 seg_vmaddr.
vmaddr = vmaddr;
5442 segment_vmaddrs.push_back(seg_vmaddr);
5445 modules_segment_vmaddrs.push_back(segment_vmaddrs);
5448 offset_t size_of_vmaddr_structs = 0;
5449 for (
size_t i = 0; i < modules_segment_vmaddrs.size(); i++) {
5450 size_of_vmaddr_structs +=
5454 offset_t size_of_filepath_cstrings = 0;
5455 for (
size_t i = 0; i < modules_count; i++) {
5457 size_of_filepath_cstrings += module_sp->GetFileSpec().GetPath().size() + 1;
5466 start_of_entries +
sizeof(
image_entry) * modules_count;
5467 offset_t start_of_filenames = start_of_seg_vmaddrs + size_of_vmaddr_structs;
5469 offset_t final_file_offset = start_of_filenames + size_of_filepath_cstrings;
5475 offset_t current_string_offset = start_of_filenames;
5476 offset_t current_segaddrs_offset = start_of_seg_vmaddrs;
5477 for (
size_t i = 0; i < modules_count; i++) {
5481 memcpy(&ent.
uuid, module_sp->GetUUID().GetBytes().data(),
sizeof(ent.
uuid));
5482 if (modules_segment_vmaddrs[i].size() > 0) {
5487 ObjectFile *objfile = module_sp->GetObjectFile();
5501 if (executing_uuids.find(module_sp->GetUUID().GetAsString()) !=
5502 executing_uuids.end())
5503 all_image_infos_payload.
PutHex32(1);
5505 all_image_infos_payload.
PutHex32(0);
5508 current_string_offset += module_sp->GetFileSpec().GetPath().size() + 1;
5513 for (
size_t i = 0; i < modules_segment_vmaddrs.size(); i++) {
5514 if (modules_segment_vmaddrs[i].size() == 0)
5517 all_image_infos_payload.
PutRawBytes(segvm.segname,
sizeof(segvm.segname));
5518 all_image_infos_payload.
PutHex64(segvm.vmaddr);
5519 all_image_infos_payload.
PutHex64(segvm.unused);
5523 for (
size_t i = 0; i < modules_count; i++) {
5525 std::string filepath = module_sp->GetFileSpec().GetPath();
5526 all_image_infos_payload.
PutRawBytes(filepath.data(), filepath.size() + 1);
5529 return final_file_offset;
5552 Target &target = process_sp->GetTarget();
5554 const llvm::Triple &target_triple = target_arch.
GetTriple();
5555 if (target_triple.getVendor() == llvm::Triple::Apple &&
5556 (target_triple.getOS() == llvm::Triple::MacOSX ||
5557 target_triple.getOS() == llvm::Triple::IOS ||
5558 target_triple.getOS() == llvm::Triple::WatchOS ||
5559 target_triple.getOS() == llvm::Triple::TvOS ||
5560 target_triple.getOS() == llvm::Triple::BridgeOS ||
5561 target_triple.getOS() == llvm::Triple::XROS)) {
5562 bool make_core =
false;
5564 case llvm::Triple::aarch64:
5565 case llvm::Triple::aarch64_32:
5566 case llvm::Triple::arm:
5567 case llvm::Triple::thumb:
5568 case llvm::Triple::x86:
5569 case llvm::Triple::x86_64:
5574 "unsupported core architecture: %s", target_triple.str().c_str());
5580 error = process_sp->CalculateCoreFileSaveRanges(options, core_ranges);
5581 if (
error.Success()) {
5584 std::vector<llvm::MachO::segment_command_64> segment_load_commands;
5585 for (
const auto &core_range_info : core_ranges) {
5587 const auto &core_range = core_range_info.data;
5588 uint32_t cmd_type = LC_SEGMENT_64;
5589 uint32_t segment_size =
sizeof(llvm::MachO::segment_command_64);
5590 if (addr_byte_size == 4) {
5591 cmd_type = LC_SEGMENT;
5592 segment_size =
sizeof(llvm::MachO::segment_command);
5596 if (core_range.lldb_permissions == 0 || core_range.range.size() == 0)
5598 uint32_t vm_prot = 0;
5599 if (core_range.lldb_permissions & ePermissionsReadable)
5600 vm_prot |= VM_PROT_READ;
5601 if (core_range.lldb_permissions & ePermissionsWritable)
5602 vm_prot |= VM_PROT_WRITE;
5603 if (core_range.lldb_permissions & ePermissionsExecutable)
5604 vm_prot |= VM_PROT_EXECUTE;
5605 const addr_t vm_addr = core_range.range.start();
5606 const addr_t vm_size = core_range.range.size();
5607 llvm::MachO::segment_command_64 segment = {
5619 segment_load_commands.push_back(segment);
5624 llvm::MachO::mach_header_64 mach_header;
5625 mach_header.magic = addr_byte_size == 8 ? MH_MAGIC_64 : MH_MAGIC;
5628 mach_header.filetype = MH_CORE;
5629 mach_header.ncmds = segment_load_commands.size();
5630 mach_header.flags = 0;
5631 mach_header.reserved = 0;
5632 ThreadList &thread_list = process_sp->GetThreadList();
5633 const uint32_t num_threads = thread_list.
GetSize();
5639 std::vector<StreamString> LC_THREAD_datas(num_threads);
5640 for (
auto &LC_THREAD_data : LC_THREAD_datas) {
5642 LC_THREAD_data.SetByteOrder(byte_order);
5644 for (uint32_t thread_idx = 0; thread_idx < num_threads; ++thread_idx) {
5647 switch (mach_header.cputype) {
5648 case llvm::MachO::CPU_TYPE_ARM64:
5649 case llvm::MachO::CPU_TYPE_ARM64_32:
5651 thread_sp.get(), LC_THREAD_datas[thread_idx]);
5654 case llvm::MachO::CPU_TYPE_ARM:
5656 thread_sp.get(), LC_THREAD_datas[thread_idx]);
5659 case llvm::MachO::CPU_TYPE_X86_64:
5661 thread_sp.get(), LC_THREAD_datas[thread_idx]);
5664 case llvm::MachO::CPU_TYPE_RISCV:
5666 thread_sp.get(), LC_THREAD_datas[thread_idx]);
5673 if (addr_byte_size == 8) {
5674 mach_header.sizeofcmds = segment_load_commands.size() *
5675 sizeof(llvm::MachO::segment_command_64);
5677 mach_header.sizeofcmds = segment_load_commands.size() *
5678 sizeof(llvm::MachO::segment_command);
5682 for (
const auto &LC_THREAD_data : LC_THREAD_datas) {
5683 ++mach_header.ncmds;
5684 mach_header.sizeofcmds += 8 + LC_THREAD_data.GetSize();
5689 uint64_t address_mask = process_sp->GetCodeAddressMask();
5692 mach_header.ncmds++;
5693 mach_header.sizeofcmds +=
sizeof(llvm::MachO::note_command);
5697 mach_header.ncmds++;
5698 mach_header.sizeofcmds +=
sizeof(llvm::MachO::note_command);
5701 mach_header.ncmds++;
5702 mach_header.sizeofcmds +=
sizeof(llvm::MachO::note_command);
5705 buffer.
PutHex32(mach_header.magic);
5706 buffer.
PutHex32(mach_header.cputype);
5707 buffer.
PutHex32(mach_header.cpusubtype);
5708 buffer.
PutHex32(mach_header.filetype);
5709 buffer.
PutHex32(mach_header.ncmds);
5710 buffer.
PutHex32(mach_header.sizeofcmds);
5711 buffer.
PutHex32(mach_header.flags);
5712 if (addr_byte_size == 8) {
5713 buffer.
PutHex32(mach_header.reserved);
5718 addr_t file_offset = buffer.
GetSize() + mach_header.sizeofcmds;
5720 file_offset = llvm::alignTo(file_offset, 16);
5721 std::vector<std::unique_ptr<LCNoteEntry>> lc_notes;
5725 std::unique_ptr<LCNoteEntry> addrable_bits_lcnote_up(
5727 addrable_bits_lcnote_up->name =
"addrable bits";
5728 addrable_bits_lcnote_up->payload_file_offset = file_offset;
5729 int bits = std::bitset<64>(~address_mask).count();
5730 addrable_bits_lcnote_up->payload.PutHex32(4);
5731 addrable_bits_lcnote_up->payload.PutHex32(
5733 addrable_bits_lcnote_up->payload.PutHex32(
5735 addrable_bits_lcnote_up->payload.PutHex32(0);
5737 file_offset += addrable_bits_lcnote_up->payload.GetSize();
5739 lc_notes.push_back(std::move(addrable_bits_lcnote_up));
5743 std::unique_ptr<LCNoteEntry> thread_extrainfo_lcnote_up(
5745 thread_extrainfo_lcnote_up->name =
"process metadata";
5746 thread_extrainfo_lcnote_up->payload_file_offset = file_offset;
5749 std::make_shared<StructuredData::Dictionary>());
5751 std::make_shared<StructuredData::Array>());
5753 process_sp->CalculateCoreFileThreadList(options)) {
5755 std::make_shared<StructuredData::Dictionary>());
5756 thread->AddIntegerItem(
"thread_id", thread_sp->GetID());
5757 threads->AddItem(thread);
5759 dict->AddItem(
"threads", threads);
5761 dict->Dump(strm,
false);
5762 thread_extrainfo_lcnote_up->payload.PutRawBytes(strm.
GetData(),
5765 file_offset += thread_extrainfo_lcnote_up->payload.GetSize();
5766 file_offset = llvm::alignTo(file_offset, 16);
5767 lc_notes.push_back(std::move(thread_extrainfo_lcnote_up));
5770 std::unique_ptr<LCNoteEntry> all_image_infos_lcnote_up(
5772 all_image_infos_lcnote_up->name =
"all image infos";
5773 all_image_infos_lcnote_up->payload_file_offset = file_offset;
5775 process_sp, file_offset, all_image_infos_lcnote_up->payload,
5777 lc_notes.push_back(std::move(all_image_infos_lcnote_up));
5780 for (
auto &lcnote : lc_notes) {
5783 buffer.
PutHex32(
sizeof(llvm::MachO::note_command));
5785 memset(namebuf, 0,
sizeof(namebuf));
5791 strncpy(namebuf, lcnote->name.c_str(),
sizeof(namebuf));
5793 buffer.
PutHex64(lcnote->payload_file_offset);
5794 buffer.
PutHex64(lcnote->payload.GetSize());
5798 file_offset = llvm::alignTo(file_offset, 4096);
5800 for (
auto &segment : segment_load_commands) {
5801 segment.fileoff = file_offset;
5802 file_offset += segment.filesize;
5806 for (
const auto &LC_THREAD_data : LC_THREAD_datas) {
5807 const size_t LC_THREAD_data_size = LC_THREAD_data.GetSize();
5809 buffer.
PutHex32(8 + LC_THREAD_data_size);
5810 buffer.
Write(LC_THREAD_data.GetString().data(), LC_THREAD_data_size);
5814 for (
const auto &segment : segment_load_commands) {
5817 buffer.
PutRawBytes(segment.segname,
sizeof(segment.segname));
5818 if (addr_byte_size == 8) {
5824 buffer.
PutHex32(
static_cast<uint32_t
>(segment.vmaddr));
5825 buffer.
PutHex32(
static_cast<uint32_t
>(segment.vmsize));
5826 buffer.
PutHex32(
static_cast<uint32_t
>(segment.fileoff));
5827 buffer.
PutHex32(
static_cast<uint32_t
>(segment.filesize));
5835 std::string core_file_path(outfile.
GetPath());
5843 uint8_t bytes[0x1000];
5845 size_t bytes_written = buffer.
GetString().size();
5847 core_file.get()->Write(buffer.
GetString().data(), bytes_written);
5848 if (
error.Success()) {
5850 for (
auto &lcnote : lc_notes) {
5851 if (core_file.get()->SeekFromStart(lcnote->payload_file_offset) ==
5854 "Unable to seek to corefile pos "
5855 "to write '%s' LC_NOTE payload",
5856 lcnote->name.c_str());
5859 bytes_written = lcnote->payload.GetSize();
5860 error = core_file.get()->Write(lcnote->payload.GetData(),
5862 if (!
error.Success())
5867 for (
const auto &segment : segment_load_commands) {
5868 if (core_file.get()->SeekFromStart(segment.fileoff) == -1) {
5870 "unable to seek to offset 0x%" PRIx64
" in '%s'",
5871 segment.fileoff, core_file_path.c_str());
5877 " bytes of data for memory region at 0x%" PRIx64
"\n",
5878 segment.vmsize, segment.vmaddr);
5879 addr_t bytes_left = segment.vmsize;
5880 addr_t addr = segment.vmaddr;
5882 while (bytes_left > 0 &&
error.Success()) {
5883 const size_t bytes_to_read =
5884 bytes_left >
sizeof(bytes) ?
sizeof(bytes) : bytes_left;
5889 const size_t bytes_read = process_sp->ReadMemoryFromInferior(
5892 if (bytes_read == bytes_to_read) {
5893 size_t bytes_written = bytes_read;
5894 error = core_file.get()->Write(bytes, bytes_written);
5895 bytes_left -= bytes_read;
5900 memset(bytes, 0, bytes_to_read);
5901 size_t bytes_written = bytes_to_read;
5902 error = core_file.get()->Write(bytes, bytes_written);
5903 bytes_left -= bytes_to_read;
5904 addr += bytes_to_read;
5925 for (
auto lc_note : lc_notes) {
5926 offset_t payload_offset = std::get<0>(lc_note);
5928 uint32_t version =
m_data_nsp->GetU32(&payload_offset);
5932 uint32_t imgcount =
m_data_nsp->GetU32(&payload_offset);
5933 uint64_t entries_fileoff =
m_data_nsp->GetU64(&payload_offset);
5938 LLDB_LOGF(log,
"LC_NOTE 'all image infos' found version %d with %d images",
5940 payload_offset = entries_fileoff;
5941 for (uint32_t i = 0; i < imgcount; i++) {
5947 uint64_t load_address =
m_data_nsp->GetU64(&payload_offset);
5949 uint32_t segment_count =
m_data_nsp->GetU32(&payload_offset);
5950 uint32_t currently_executing =
m_data_nsp->GetU32(&payload_offset);
5954 (
const char *)
m_data_nsp->GetCStr(&filepath_offset);
5957 image_entry.currently_executing = currently_executing;
5959 offset_t seg_vmaddrs_offset = seg_addrs_offset;
5960 for (uint32_t j = 0; j < segment_count; j++) {
5962 m_data_nsp->CopyData(seg_vmaddrs_offset, 16, segname);
5964 seg_vmaddrs_offset += 16;
5965 uint64_t vmaddr =
m_data_nsp->GetU64(&seg_vmaddrs_offset);
5966 seg_vmaddrs_offset += 8;
5968 std::tuple<ConstString, addr_t> new_seg{
ConstString(segname), vmaddr};
5969 image_entry.segment_load_addresses.push_back(new_seg);
5971 LLDB_LOGF(log,
" image entry: %s %s 0x%" PRIx64
" %s",
5975 image_entry.currently_executing ?
"currently executing"
5976 :
"not currently executing");
5982 for (
auto lc_note : lc_notes) {
5983 offset_t payload_offset = std::get<0>(lc_note);
5984 uint32_t version =
m_data_nsp->GetU32(&payload_offset);
5989 uint64_t load_address =
m_data_nsp->GetU64(&payload_offset);
5990 uint64_t slide =
m_data_nsp->GetU64(&payload_offset);
5991 std::string filename =
m_data_nsp->GetCStr(&payload_offset);
6001 "LC_NOTE 'load binary' found, filename %s uuid %s load "
6002 "address 0x%" PRIx64
" slide 0x%" PRIx64,
6006 :
"00000000-0000-0000-0000-000000000000",
6007 load_address, slide);
6018 bool found_platform_binary =
false;
6021 llvm::SmallVector<const MachOCorefileImageEntry *> pending_images;
6022 std::vector<DynamicLoader::BinarySpec> pending_specs;
6039 "ObjectFileMachO::%s binary at 0x%" PRIx64
6040 " is a platform binary, has been handled by a Platform plugin.",
6042 found_platform_binary =
true;
6063 bin_spec.
value = value;
6073 pending_images.push_back(&image);
6074 pending_specs.push_back(std::move(bin_spec));
6079 for (
auto [image, bin_spec] :
6080 llvm::zip_equal(pending_images, pending_specs)) {
6082 if (llvm::Expected<ModuleSP> loaded =
6084 module_sp = *loaded;
6085 }
else if (bin_spec.force_symbol_search) {
6087 << llvm::toString(loaded.takeError()) <<
"\n";
6091 llvm::consumeError(loaded.takeError());
6097 added_modules.
Append(module_sp,
false );
6103 log->
Printf(
"ObjectFileMachO::LoadCoreFileImages adding binary '%s' "
6104 "UUID %s with section load addresses",
6105 module_sp->GetFileSpec().GetPath().c_str(),
6108 ObjectFile *objfile = module_sp->GetObjectFile();
6116 sect_sp, std::get<1>(name_vmaddr_tuple));
6123 log->
Printf(
"ObjectFileMachO::LoadCoreFileImages adding binary '%s' "
6124 "UUID %s with %s 0x%" PRIx64,
6125 module_sp->GetFileSpec().GetPath().c_str(), uuidstr.c_str(),
6126 bin_spec.value_is_offset ?
"slide" :
"load address",
6130 module_sp->SetLoadAddress(process.
GetTarget(), bin_spec.value,
6131 bin_spec.value_is_offset, changed);
6135 if (added_modules.
GetSize() > 0) {
6142 if (found_platform_binary)
static llvm::raw_ostream & error(Stream &strm)
void dyld_shared_cache_copy_uuid(dyld_shared_cache_t cache, uuid_t *uuid)
struct dyld_image_s * dyld_image_t
struct dyld_shared_cache_s * dyld_shared_cache_t
bool dyld_image_copy_uuid(dyld_image_t cache, uuid_t *uuid)
void dyld_shared_cache_for_each_image(dyld_shared_cache_t cache, void(^block)(dyld_image_t image))
static const char * memory_read_error
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOGF(log,...)
#define LLDB_LOG_ERROR(log, error,...)
static bool ReadMachOCommand(DataExtractor &data, lldb::offset_t &offset, T &cmd)
Read a Mach-O load-command header (cmd + cmdsize) from data at offset into cmd, advancing offset by 8...
static uint32_t MachHeaderSizeFromMagic(uint32_t magic)
static uint32_t GetSegmentPermissions(const llvm::MachO::segment_command_64 &seg_cmd)
static constexpr llvm::StringLiteral g_loader_path
static std::optional< struct nlist_64 > ParseNList(DataExtractor &nlist_data, lldb::offset_t &nlist_data_offset, size_t nlist_byte_size)
static bool ReadMachOCommand(const DataExtractor &data, lldb::offset_t &offset, T &cmd)
Read a Mach-O load-command header (cmd + cmdsize) from data at offset into cmd, advancing offset by 8...
static constexpr llvm::StringLiteral g_executable_path
static void PrintRegisterValue(RegisterContext *reg_ctx, const char *name, const char *alt_name, size_t reg_byte_size, Stream &data)
static llvm::Expected< std::string > ReadLCNotePayload(const DataExtractor &data, lldb::offset_t offset, uint64_t size)
Return the payload of an LC_NOTE, decompressing it if needed.
static lldb::SectionType GetSectionType(uint32_t flags, llvm::StringRef section_name)
static llvm::StringRef GetOSName(uint32_t cmd)
static llvm::VersionTuple FindMinimumVersionInfo(DataExtractor &data, lldb::offset_t offset, size_t ncmds)
unsigned int mach_task_self()
static void UpdateHasSourceFilesAndDebugMap(SymbolType type, const struct nlist_64 &nlist, bool &has_source_files, bool &has_debug_map)
#define MACHO_NLIST_ARM_SYMBOL_IS_THUMB
static uint32_t MachHeaderSizeFromMagic(uint32_t magic)
static offset_t CreateAllImageInfosPayload(const lldb::ProcessSP &process_sp, offset_t initial_file_offset, StreamString &all_image_infos_payload, lldb_private::SaveCoreOptions &options)
static bool TryParseV2ObjCMetadataSymbol(const char *&symbol_name, const char *&symbol_name_non_abi_mangled, SymbolType &type)
static SymbolType GetSymbolType(const char *&symbol_name, bool &demangled_is_synthesized, const SectionSP &text_section_sp, const SectionSP &data_section_sp, const SectionSP &data_dirty_section_sp, const SectionSP &data_const_section_sp, const SectionSP &symbol_section)
#define LLDB_PLUGIN_DEFINE(PluginName)
#define KERN_SUCCESS
Constants returned by various RegisterContextDarwin_*** functions.
#define LLDB_SCOPED_TIMERF(...)
static llvm::StringRef GetName(XcodeSDK::Type type)
SectionList * m_section_list
std::vector< SectionInfo > m_section_infos
SectionSP GetSection(uint8_t n_sect, addr_t file_addr)
MachSymtabSectionInfo(SectionList *section_list)
bool SectionIsLoadable(const lldb_private::Section *section)
llvm::MachO::mach_header m_header
bool m_allow_assembly_emulation_unwind_plans
std::optional< llvm::VersionTuple > m_min_os_version
lldb_private::AddressableBits GetAddressableBits() override
Some object files may have the number of bits used for addressing embedded in them,...
uint32_t GetDependentModules(lldb_private::FileSpecList &files) override
Extract the dependent modules from an object file.
static lldb_private::ObjectFile * CreateMemoryInstance(const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp, const lldb::ProcessSP &process_sp, lldb::addr_t header_addr)
FileRangeArray m_thread_context_offsets
ObjectFile::Type CalculateType() override
The object file should be able to calculate its type by looking at its file header and possibly the s...
lldb_private::RangeVector< uint32_t, uint32_t, 8 > EncryptedFileRanges
static bool MagicBytesMatch(lldb::DataExtractorSP extractor_sp, lldb::addr_t offset, lldb::addr_t length)
std::vector< std::tuple< lldb::offset_t, lldb::offset_t > > FindLC_NOTEByName(std::string name)
void Dump(lldb_private::Stream *s) override
Dump a description of this object to a Stream.
bool AllowAssemblyEmulationUnwindPlans() override
Returns if the function bounds for symbols in this symbol file are likely accurate.
std::string GetIdentifierString() override
Some object files may have an identifier string embedded in them, e.g.
void ProcessSegmentCommand(const llvm::MachO::load_command &load_cmd, lldb::offset_t offset, uint32_t cmd_idx, SegmentParsingContext &context)
std::vector< llvm::MachO::section_64 > m_mach_sections
static llvm::StringRef GetSegmentNameLINKEDIT()
bool SetLoadAddress(lldb_private::Target &target, lldb::addr_t value, bool value_is_offset) override
Sets the load address for an entire module, assuming a rigid slide of sections, if possible in the im...
void GetProcessSharedCacheUUID(lldb_private::Process *, lldb::addr_t &base_addr, lldb_private::UUID &uuid)
Intended for same-host arm device debugging where lldb needs to detect libraries in the shared cache ...
bool IsGOTSection(const lldb_private::Section §ion) const override
Returns true if the section is a global offset table section.
bool GetIsDynamicLinkEditor() override
Return true if this file is a dynamic link editor (dyld)
lldb::ByteOrder GetByteOrder() const override
Gets whether endian swapping should occur when extracting data from this object file.
bool ParseHeader() override
Attempts to parse the object header.
bool IsStripped() override
Detect if this object file has been stripped of local symbols.
lldb_private::UUID GetUUID() override
Gets the UUID for this object file.
llvm::VersionTuple GetMinimumOSVersion() override
Get the minimum OS version this object file can run on.
static llvm::StringRef GetPluginDescriptionStatic()
static llvm::StringRef GetPluginNameStatic()
lldb::RegisterContextSP GetThreadContextAtIndex(uint32_t idx, lldb_private::Thread &thread) override
lldb_private::FileSpecList m_reexported_dylibs
static void GetAllArchSpecs(const llvm::MachO::mach_header &header, const lldb_private::DataExtractor &data, lldb::offset_t lc_offset, lldb_private::ModuleSpec &base_spec, lldb_private::ModuleSpecList &all_specs)
Enumerate all ArchSpecs supported by this Mach-O file.
bool GetCorefileThreadExtraInfos(std::vector< lldb::tid_t > &tids) override
Get metadata about thread ids from the corefile.
static llvm::StringRef GetSectionNameEHFrame()
bool IsDynamicLoader() const
bool IsExecutable() const override
Tells whether this object file is capable of being the main executable for a process.
lldb_private::Address GetEntryPointAddress() override
Returns the address of the Entry Point in this object file - if the object file doesn't have an entry...
lldb_private::Address m_entry_point_address
bool LoadCoreFileImages(lldb_private::Process &process) override
Load binaries listed in a corefile.
bool CanTrustAddressRanges() override
Can we trust the address ranges accelerator associated with this object file to be complete.
void SanitizeSegmentCommand(llvm::MachO::segment_command_64 &seg_cmd, uint32_t cmd_idx)
static lldb_private::ObjectFile * CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataExtractorSP extractor_sp, lldb::offset_t data_offset, const lldb_private::FileSpec *file, lldb::offset_t file_offset, lldb::offset_t length)
llvm::VersionTuple GetSDKVersion() override
Get the SDK OS version this object file was built with.
lldb_private::ArchSpec GetArchitecture() override
Get the ArchSpec for this object file.
lldb_private::Address GetBaseAddress() override
Returns base address of this object file.
bool IsSharedCacheBinary() const override
Tells whether this object file is part of a shared cache.
static llvm::StringRef GetSectionNameLLDBNoNlist()
lldb::addr_t m_text_address
uint32_t GetAddressByteSize() const override
Gets the address size in bytes for the current object file.
static lldb_private::ModuleSpecList GetModuleSpecifications(const lldb_private::FileSpec &file, lldb::DataExtractorSP &extractor_sp, lldb::offset_t file_offset, lldb::offset_t length)
static llvm::StringRef GetSegmentNameDATA()
llvm::MachO::dysymtab_command m_dysymtab
bool GetCorefileMainBinaryInfo(lldb::addr_t &value, bool &value_is_offset, lldb_private::UUID &uuid, ObjectFile::BinaryType &type) override
static llvm::StringRef GetSegmentNameDATA_DIRTY()
static bool SaveCore(const lldb::ProcessSP &process_sp, lldb_private::SaveCoreOptions &options, lldb_private::Status &error)
void ProcessDysymtabCommand(const llvm::MachO::load_command &load_cmd, lldb::offset_t offset)
static llvm::StringRef GetSegmentNameLLVM_COV()
MachOCorefileAllImageInfos GetCorefileAllImageInfos()
Get the list of binary images that were present in the process when the corefile was produced.
lldb::addr_t CalculateSectionLoadAddressForMemoryImage(lldb::addr_t mach_header_load_address, const lldb_private::Section *mach_header_section, const lldb_private::Section *section)
bool m_thread_context_offsets_valid
ObjectFile::Strata CalculateStrata() override
The object file should be able to calculate the strata of the object file.
void CreateSections(lldb_private::SectionList &unified_section_list) override
static llvm::StringRef GetSegmentNameDATA_CONST()
lldb_private::AddressClass GetAddressClass(lldb::addr_t file_addr) override
Get the address type given a file address in an object file.
lldb_private::StructuredData::ObjectSP GetCorefileProcessMetadata() override
Get process metadata from the corefile in a StructuredData dictionary.
static llvm::StringRef GetSegmentNameOBJC()
std::optional< llvm::VersionTuple > m_sdk_versions
ObjectFileMachO(const lldb::ModuleSP &module_sp, lldb::DataExtractorSP extractor_sp, lldb::offset_t data_offset, const lldb_private::FileSpec *file, lldb::offset_t offset, lldb::offset_t length)
void GetLLDBSharedCacheUUID(lldb::addr_t &base_addir, lldb_private::UUID &uuid)
Intended for same-host arm device debugging where lldb will read shared cache libraries out of its ow...
llvm::VersionTuple GetVersion() override
Get the object file version numbers.
EncryptedFileRanges GetEncryptedFileRanges()
uint32_t GetNumThreadContexts() override
static llvm::StringRef GetSegmentNameDWARF()
static llvm::StringRef GetSegmentNameTEXT()
lldb::offset_t m_linkedit_original_offset
lldb_private::Section * GetMachHeaderSection()
int DoWriteDBG(lldb::tid_t tid, int flavor, const DBG &dbg) override
int DoWriteGPR(lldb::tid_t tid, int flavor, const GPR &gpr) override
int DoWriteFPU(lldb::tid_t tid, int flavor, const FPU &fpu) override
int DoReadGPR(lldb::tid_t tid, int flavor, GPR &gpr) override
int DoWriteEXC(lldb::tid_t tid, int flavor, const EXC &exc) override
RegisterContextDarwin_arm64_Mach(lldb_private::Thread &thread, const DataExtractor &data)
int DoReadEXC(lldb::tid_t tid, int flavor, EXC &exc) override
void SetRegisterDataFrom_LC_THREAD(const DataExtractor &data)
int DoReadDBG(lldb::tid_t tid, int flavor, DBG &dbg) override
void InvalidateAllRegisters() override
int DoReadFPU(lldb::tid_t tid, int flavor, FPU &fpu) override
static bool Create_LC_THREAD(Thread *thread, Stream &data)
bool SetError(int flavor, uint32_t err_idx, int err)
RegisterContextDarwin_arm64(lldb_private::Thread &thread, uint32_t concrete_frame_idx)
RegisterContextDarwin_arm_Mach(lldb_private::Thread &thread, const DataExtractor &data)
int DoWriteDBG(lldb::tid_t tid, int flavor, const DBG &dbg) override
int DoReadFPU(lldb::tid_t tid, int flavor, FPU &fpu) override
int DoWriteFPU(lldb::tid_t tid, int flavor, const FPU &fpu) override
int DoReadDBG(lldb::tid_t tid, int flavor, DBG &dbg) override
int DoWriteEXC(lldb::tid_t tid, int flavor, const EXC &exc) override
int DoReadGPR(lldb::tid_t tid, int flavor, GPR &gpr) override
void SetRegisterDataFrom_LC_THREAD(const DataExtractor &data)
int DoWriteGPR(lldb::tid_t tid, int flavor, const GPR &gpr) override
void InvalidateAllRegisters() override
int DoReadEXC(lldb::tid_t tid, int flavor, EXC &exc) override
static bool Create_LC_THREAD(Thread *thread, Stream &data)
RegisterContextDarwin_arm(lldb_private::Thread &thread, uint32_t concrete_frame_idx)
bool SetError(int flavor, uint32_t err_idx, int err)
int DoWriteEXC(lldb::tid_t tid, int flavor, const EXC &exc) override
int DoReadFPU(lldb::tid_t tid, int flavor, FPU &fpu) override
int DoWriteCSR(lldb::tid_t tid, int flavor, const CSR &csr) override
RegisterContextDarwin_riscv32_Mach(lldb_private::Thread &thread, const DataExtractor &data)
void InvalidateAllRegisters() override
int DoReadGPR(lldb::tid_t tid, int flavor, GPR &gpr) override
int DoWriteFPU(lldb::tid_t tid, int flavor, const FPU &fpu) override
int DoWriteGPR(lldb::tid_t tid, int flavor, const GPR &gpr) override
int DoReadCSR(lldb::tid_t tid, int flavor, CSR &csr) override
static bool Create_LC_THREAD(Thread *thread, Stream &data)
void SetRegisterDataFrom_LC_THREAD(const DataExtractor &data)
int DoReadEXC(lldb::tid_t tid, int flavor, EXC &exc) override
RegisterContextDarwin_riscv32(lldb_private::Thread &thread, uint32_t concrete_frame_idx)
bool SetError(int flavor, uint32_t err_idx, int err)
RegisterContextDarwin_x86_64_Mach(lldb_private::Thread &thread, const DataExtractor &data)
int DoWriteFPU(lldb::tid_t tid, int flavor, const FPU &fpu) override
static bool Create_LC_THREAD(Thread *thread, Stream &data)
void SetRegisterDataFrom_LC_THREAD(const DataExtractor &data)
int DoWriteEXC(lldb::tid_t tid, int flavor, const EXC &exc) override
int DoReadFPU(lldb::tid_t tid, int flavor, FPU &fpu) override
int DoReadGPR(lldb::tid_t tid, int flavor, GPR &gpr) override
void InvalidateAllRegisters() override
int DoWriteGPR(lldb::tid_t tid, int flavor, const GPR &gpr) override
int DoReadEXC(lldb::tid_t tid, int flavor, EXC &exc) override
RegisterContextDarwin_x86_64(lldb_private::Thread &thread, uint32_t concrete_frame_idx)
bool SetError(int flavor, uint32_t err_idx, int err)
A section + offset based address class.
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
lldb::SectionSP GetSection() const
Get const accessor for the section.
lldb::addr_t GetFileAddress() const
Get the file address.
bool IsValid() const
Check if the object state is valid.
A class which holds the metadata from a remote stub/corefile note about how many bits are used for ad...
void SetAddressableBits(uint32_t addressing_bits)
When a single value is available for the number of bits.
An architecture specification class.
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
bool IsValid() const
Tests if this ArchSpec is valid.
llvm::Triple & GetTriple()
Architecture triple accessor.
bool IsAlwaysThumbInstructions() const
Detect whether this architecture uses thumb code exclusively.
bool SetArchitecture(ArchitectureType arch_type, uint32_t cpu, uint32_t sub, uint32_t os=0)
Change the architecture object type, CPU type and OS type.
uint32_t GetMachOCPUSubType() const
bool IsCompatibleMatch(const ArchSpec &rhs) const
Shorthand for IsMatch(rhs, CompatibleMatch).
uint32_t GetMachOCPUType() const
lldb::ByteOrder GetByteOrder() const
Returns the byte order for the architecture specification.
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
A uniqued constant string class.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
const char * GetCString() const
Get the string value as a C string.
void GetFunctionAddressAndSizeVector(FunctionAddressAndSizeVector &function_info)
RangeVector< lldb::addr_t, uint32_t > FunctionAddressAndSizeVector
lldb::StreamUP GetAsyncErrorStream()
static void ReportError(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report error events.
PlatformList & GetPlatformList()
lldb::StreamUP GetAsyncOutputStream()
A plug-in interface definition class for dynamic loaders.
static void LocateBinaries(Process *process, llvm::MutableArrayRef< BinarySpec > bin_specs)
Search for a batch of binaries, without mutating the Target.
virtual bool GetSharedCacheInformation(lldb::addr_t &base_address, UUID &uuid, LazyBool &using_shared_cache, LazyBool &private_shared_cache, lldb_private::FileSpec &shared_cache_path, std::optional< uint64_t > &size)
Get information about the shared cache for a process, if possible.
static llvm::Expected< lldb::ModuleSP > LoadBinaryInTarget(Process *process, BinarySpec &bin_spec)
Add a binary that LocateBinaries searched for to the Target, and set its load address.
const FileSpec & GetFileSpecAtIndex(size_t idx) const
Get file at index.
void Append(const FileSpec &file)
Append a FileSpec object to the list.
size_t GetSize() const
Get the number of files in the file list.
bool AppendIfUnique(const FileSpec &file)
Append a FileSpec object if unique.
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
FileSpec CopyByAppendingPathComponent(llvm::StringRef component) const
void ClearDirectory()
Clear the directory in this object.
llvm::StringRef GetFilename() const
Filename string const get accessor.
llvm::StringRef GetDirectory() const
Directory string const get accessor.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
FileSpec CopyByRemovingLastPathComponent() const
int Open(const char *path, int flags, int mode=0600)
Wraps open in a platform-independent way.
static FileSystem & Instance()
void Resolve(llvm::SmallVectorImpl< char > &path, bool force_make_absolute=false)
Resolve path to make it canonical.
void void Printf(const char *format,...) __attribute__((format(printf
Prefer using LLDB_LOGF whenever possible.
A class that handles mangled names.
void SetDemangledName(ConstString name)
ConstString GetDemangledName() const
Demangled name get accessor.
void SetMangledName(ConstString name)
void SetValue(ConstString name)
Set the string value in this object.
ConstString GetName(NamePreference preference=ePreferDemangled) const
Best name get accessor.
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
A collection class for Module objects.
void Clear()
Clear the object's state.
bool AppendIfNeeded(const lldb::ModuleSP &new_module, bool notify=true)
Append a module to the module list, if it is not already there.
lldb::ModuleSP GetModuleAtIndex(size_t idx) const
Get the module shared pointer for the module at index idx.
void Append(const lldb::ModuleSP &module_sp, bool notify=true)
Append a module to the module list.
size_t GetSize() const
Gets the size of the module list.
void Append(const ModuleSpec &spec)
ModuleSpec & GetModuleSpecRefAtIndex(size_t i)
void SetObjectSize(uint64_t object_size)
ArchSpec & GetArchitecture()
void SetObjectOffset(uint64_t object_offset)
A plug-in interface definition class for object file parsers.
std::atomic< lldb_private::Symtab * > m_symtab
Owned.
std::unique_ptr< lldb_private::SectionList > m_sections_up
static lldb::DataBufferSP MapFileData(const FileSpec &file, uint64_t Size, uint64_t Offset)
const lldb::addr_t m_memory_addr
Set if the object file only exists in memory.
static lldb::SectionType GetDWARFSectionTypeFromName(llvm::StringRef name)
Parses the section type from a section name for DWARF sections.
Symtab * GetSymtab(bool can_create=true)
Gets the symbol table for the currently selected architecture (and object for archives).
DataExtractorNSP m_data_nsp
The data for this object file so things can be parsed lazily.
static lldb::WritableDataBufferSP ReadMemory(const lldb::ProcessSP &process_sp, lldb::addr_t addr, size_t byte_size)
@ eTypeExecutable
A normal executable.
@ eTypeDebugInfo
An object file that contains only debug information.
@ eTypeStubLibrary
A library that can be linked against but not used for execution.
@ eTypeObjectFile
An intermediate object file.
@ eTypeDynamicLinker
The platform's dynamic linker executable.
@ eTypeCoreFile
A core file that has a checkpoint of a program's execution state.
@ eTypeSharedLibrary
A shared library that can be used during execution.
lldb::addr_t m_file_offset
The offset in bytes into the file, or the address in memory.
static lldb::SymbolType GetSymbolTypeFromName(llvm::StringRef name, lldb::SymbolType symbol_type_hint=lldb::eSymbolTypeUndefined)
bool SetModulesArchitecture(const ArchSpec &new_arch)
Sets the architecture for a module.
virtual FileSpec & GetFileSpec()
Get accessor to the object file specification.
virtual SectionList * GetSectionList(bool update_module_section_list=true)
Gets the section list for the currently selected architecture (and object for archives).
ObjectFile(const lldb::ModuleSP &module_sp, const FileSpec *file_spec_ptr, lldb::offset_t file_offset, lldb::offset_t length, lldb::DataExtractorSP extractor_sp, lldb::offset_t data_offset)
Construct with a parent module, offset, and header data.
bool IsInMemory() const
Returns true if the object file exists only in memory.
lldb::ProcessWP m_process_wp
lldb::addr_t m_length
The length of this object file if it is known (can be zero if length is unknown or can't be determine...
BinaryType
If we have a corefile binary hint, this enum specifies the binary type which we can use to select the...
@ eBinaryTypeKernel
kernel binary
@ eBinaryTypeUser
user process binary, dyld addr
@ eBinaryTypeUserAllImageInfos
user process binary, dyld_all_image_infos addr
@ eBinaryTypeStandalone
standalone binary / firmware
virtual lldb_private::Address GetBaseAddress()
Returns base address of this object file.
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
A plug-in interface definition class for debugging a process.
void Flush()
Flush all data in the process.
virtual DynamicLoader * GetDynamicLoader()
Get the dynamic loader plug-in for this process.
Target & GetTarget()
Get the target object pointer for this module.
A Progress indicator helper class.
const Entry * FindEntryThatContains(B addr) const
const Entry * GetEntryAtIndex(size_t i) const
void Append(const Entry &entry)
Range< uint32_t, uint32_t > Entry
const RegisterInfo * GetRegisterInfoByName(llvm::StringRef reg_name, uint32_t start_idx=0)
virtual bool ReadRegister(const RegisterInfo *reg_info, RegisterValue ®_value)=0
const void * GetBytes() const
const std::optional< lldb_private::FileSpec > GetOutputFile() const
lldb::SaveCoreStyle GetStyle() const
void SetStyle(lldb::SaveCoreStyle style)
size_t GetNumSections(uint32_t depth) const
lldb::SectionSP FindSectionByName(llvm::StringRef section_name) const
size_t AddSection(const lldb::SectionSP §ion_sp)
void Dump(llvm::raw_ostream &s, unsigned indent, Target *target, bool show_header, uint32_t depth) const
lldb::SectionSP GetSectionAtIndex(size_t idx) const
bool IsThreadSpecific() const
lldb::SectionSP GetParent() const
lldb::offset_t GetFileOffset() const
llvm::StringRef GetName() const
lldb::addr_t GetFileAddress() const
ObjectFile * GetObjectFile()
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
const char * GetData() const
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
size_t Write(const void *src, size_t src_len)
Output character bytes to the stream.
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
size_t PutHex64(uint64_t uvalue, lldb::ByteOrder byte_order=lldb::eByteOrderInvalid)
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
@ eBinary
Get and put data as binary instead of as the default string mode.
size_t PutHex32(uint32_t uvalue, lldb::ByteOrder byte_order=lldb::eByteOrderInvalid)
size_t PutRawBytes(const void *s, size_t src_len, lldb::ByteOrder src_byte_order=lldb::eByteOrderInvalid, lldb::ByteOrder dst_byte_order=lldb::eByteOrderInvalid)
unsigned GetIndentLevel() const
Get the current indentation level.
std::optional< Dictionary * > GetItemAtIndexAsDictionary(size_t idx) const
Retrieves the element at index idx from a StructuredData::Array if it is a Dictionary.
bool GetValueForKeyAsArray(llvm::StringRef key, Array *&result) const
Dictionary * GetAsDictionary()
void Dump(lldb_private::Stream &s, bool pretty_print=true) const
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Object > ObjectSP
static ObjectSP ParseJSON(llvm::StringRef json_text)
std::shared_ptr< Array > ArraySP
Defines a list of symbol context objects.
bool GetContextAtIndex(size_t idx, SymbolContext &sc) const
Get accessor for a symbol context at index idx.
uint32_t GetSize() const
Get accessor for a symbol context list size.
Defines a symbol context baton that can be handed other debug core functions.
Symbol * symbol
The Symbol for a given query.
bool ValueIsAddress() const
void SetReExportedSymbolName(ConstString name)
void SetType(lldb::SymbolType type)
void SetSizeIsSibling(bool b)
Address & GetAddressRef()
uint32_t GetFlags() const
bool SetReExportedSymbolSharedLibrary(const FileSpec &fspec)
lldb::addr_t GetByteSize() const
lldb::SymbolType GetType() const
void SetFlags(uint32_t flags)
Address GetAddress() const
void SetIsSynthetic(bool b)
void SetByteSize(lldb::addr_t size)
void SetDemangledNameIsSynthesized(bool b)
Symbol * FindSymbolByID(lldb::user_id_t uid) const
Symbol * SymbolAtIndex(size_t idx)
Symbol * FindFirstSymbolWithNameAndType(ConstString name, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility)
Symbol * Resize(size_t count)
Symbol * FindSymbolContainingFileAddress(lldb::addr_t file_addr)
void SetHasDebugMap(bool has_debug_map)
Set whether this symbol table has a debug map.
size_t GetNumSymbols() const
void SetHasSourceFiles(bool has_source_files)
Set whether this symbol table contains any source file symbols.
MemoryModuleLoadLevel GetMemoryModuleLoadLevel() const
void ModulesDidLoad(ModuleList &module_list)
This call may preload module symbols, and may do so in parallel depending on the following target set...
Debugger & GetDebugger() const
const ModuleList & GetImages() const
Get accessor for the images for this process.
const ArchSpec & GetArchitecture() const
bool SetSectionLoadAddress(const lldb::SectionSP §ion, lldb::addr_t load_addr, bool warn_multiple=false)
uint32_t GetSize(bool can_update=true)
lldb::ThreadSP GetThreadAtIndex(uint32_t idx, bool can_update=true)
Represents UUID's of various sizes.
std::string GetAsString(llvm::StringRef separator="-") const
#define LLDB_INVALID_ADDRESS_MASK
Address Mask Bits not used for addressing are set to 1 in the mask; all mask bits set is an invalid v...
#define LLDB_INVALID_THREAD_ID
#define LLDB_INVALID_ADDRESS
lldb::ByteOrder InlHostByteOrder()
A class that represents a running process on the host machine.
constexpr uint64_t THUMB_ADDRESS_BIT_MASK
Mask that clears the low Thumb bit from an ARM function address.
bool ParseTrieEntries(DataExtractor &data, const bool is_arm, lldb::addr_t text_seg_base_addr, std::set< lldb::addr_t > &resolver_addresses, std::vector< TrieEntryWithOffset > &reexports, std::vector< TrieEntryWithOffset > &ext_symbols)
Parse the Mach-O export trie (the dyld symbol trie from LC_DYLD_INFO or LC_DYLD_EXPORTS_TRIE) startin...
@ eMemoryModuleLoadLevelPartial
@ eMemoryModuleLoadLevelComplete
@ eMemoryModuleLoadLevelMinimal
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
constexpr uint64_t TRIE_SYMBOL_IS_THUMB
Set on TrieEntry::flags for an ARM symbol whose address has the low Thumb bit set; the bit is strippe...
static uint32_t bits(const uint32_t val, const uint32_t msbit, const uint32_t lsbit)
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::Thread > ThreadSP
@ eSymbolSharedCacheUseHostAndInferiorSharedCache
std::shared_ptr< lldb_private::Process > ProcessSP
@ eSymbolTypeVariableType
@ eSymbolTypeObjCMetaClass
@ eSymbolTypeASTFile
The symbol's name is the path to a compiler AST file.
@ eSymbolTypeAdditional
When symbols take more than one entry, the extra entries get this type.
@ eSymbolTypeInstrumentation
ByteOrder
Byte ordering definitions.
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::Section > SectionSP
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
@ eSectionTypeDWARFDebugStrOffsets
@ eSectionTypeELFDynamicSymbols
Elf SHT_DYNSYM section.
@ eSectionTypeDWARFDebugPubNames
@ eSectionTypeDataObjCCFStrings
Objective-C const CFString/NSString objects.
@ eSectionTypeDWARFDebugLocDwo
@ eSectionTypeDWARFDebugFrame
@ eSectionTypeContainer
The section contains child sections.
@ eSectionTypeDWARFDebugLocLists
DWARF v5 .debug_loclists.
@ eSectionTypeDWARFDebugTypes
DWARF .debug_types section.
@ eSectionTypeDataSymbolAddress
Address of a symbol in the symbol table.
@ eSectionTypeELFDynamicLinkInfo
Elf SHT_DYNAMIC section.
@ eSectionTypeDWARFDebugMacInfo
@ eSectionTypeAbsoluteAddress
Dummy section for symbols with absolute address.
@ eSectionTypeCompactUnwind
compact unwind section in Mach-O, __TEXT,__unwind_info
@ eSectionTypeELFRelocationEntries
Elf SHT_REL or SHT_REL section.
@ eSectionTypeDWARFAppleNamespaces
@ eSectionTypeLLDBFormatters
@ eSectionTypeDWARFDebugNames
DWARF v5 .debug_names.
@ eSectionTypeDWARFDebugRngLists
DWARF v5 .debug_rnglists.
@ eSectionTypeDWARFDebugStrOffsetsDwo
@ eSectionTypeDWARFDebugMacro
@ eSectionTypeDWARFAppleTypes
@ eSectionTypeDWARFDebugInfo
@ eSectionTypeDWARFDebugTypesDwo
@ eSectionTypeDWARFDebugRanges
@ eSectionTypeDWARFDebugRngListsDwo
@ eSectionTypeLLDBTypeSummaries
@ eSectionTypeDWARFDebugLine
@ eSectionTypeDWARFDebugPubTypes
@ eSectionTypeDataObjCMessageRefs
Pointer to function pointer + selector.
@ eSectionTypeDWARFDebugTuIndex
@ eSectionTypeDWARFDebugStr
@ eSectionTypeDWARFDebugLineStr
DWARF v5 .debug_line_str.
@ eSectionTypeDWARFDebugLoc
@ eSectionTypeDWARFAppleNames
@ eSectionTypeDataCStringPointers
Pointers to C string data.
@ eSectionTypeDWARFAppleObjC
@ eSectionTypeSwiftModules
@ eSectionTypeDWARFDebugCuIndex
@ eSectionTypeDWARFDebugAranges
@ eSectionTypeDWARFDebugAbbrevDwo
@ eSectionTypeDWARFGNUDebugAltLink
@ eSectionTypeDWARFDebugStrDwo
@ eSectionTypeDWARFDebugAbbrev
@ eSectionTypeDataPointers
@ eSectionTypeDWARFDebugLocListsDwo
@ eSectionTypeDWARFDebugInfoDwo
@ eSectionTypeDWARFDebugAddr
@ eSectionTypeDataCString
Inlined C string data.
@ eSectionTypeELFSymbolTable
Elf SHT_SYMTAB section.
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP
std::shared_ptr< lldb_private::DataExtractor > DataExtractorSP
std::shared_ptr< lldb_private::Module > ModuleSP
Range< addr_t, addr_t > vm_range
lldb::offset_t export_off
The LC_DYSYMTAB's dysymtab_command has 32-bit file offsets that we will use as virtual address offset...
lldb::offset_t indirectsymoff
std::vector< MachOCorefileImageEntry > all_image_infos
A corefile may include metadata about all of the binaries that were present in the process when the c...
lldb::addr_t load_address
std::vector< std::tuple< lldb_private::ConstString, lldb::addr_t > > segment_load_addresses
lldb_private::SectionList & UnifiedList
SegmentParsingContext(EncryptedFileRanges EncryptedRanges, lldb_private::SectionList &UnifiedList)
const EncryptedFileRanges EncryptedRanges
bool FileAddressesChanged
image_entry(const image_entry &rhs)
uint64_t seg_addrs_offset
uint64_t cacheBaseAddress
A binary to find and load into a Target.
lldb::addr_t value
Address where the binary should be loaded, or read out of memory.
bool allow_memory_image_last_resort
If no better binary image can be found, allow reading the binary out of memory, if possible,...
UUID uuid
UUID of the binary to be loaded.
std::string name
Name of the binary, if available.
bool force_symbol_search
Allow the search to do a possibly expensive external search for the ObjectFile and/or SymbolFile.
bool set_address_in_target
Whether the address of the binary should be set in the Target if it is added.
bool notify
Whether ModulesDidLoad should be called once the binary has been added to the Target.
bool value_is_offset
A flag indicating that value is an address, or an offset to be applied to the file addresses.
BaseType GetRangeBase() const
SizeType GetByteSize() const
void SetRangeBase(BaseType b)
Set the start value for the range, and keep the same size.
void SetByteSize(SizeType s)
Every register is described in detail including its name, alternate name (optional),...
uint32_t byte_size
Size in bytes of the register.
void * GetImageBaton() const
segment_vmaddr(const segment_vmaddr &rhs)