Skip to content

[lldb][Mach-O] Handle shared cache binaries correctly #117832

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2235,11 +2235,11 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
LLDB_LOG(log, "Parsing symbol table for {0}", file_name);
Progress progress("Parsing symbol table", file_name);

llvm::MachO::symtab_command symtab_load_command = {0, 0, 0, 0, 0, 0};
llvm::MachO::linkedit_data_command function_starts_load_command = {0, 0, 0, 0};
llvm::MachO::linkedit_data_command exports_trie_load_command = {0, 0, 0, 0};
llvm::MachO::dyld_info_command dyld_info = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
llvm::MachO::dysymtab_command dysymtab = m_dysymtab;
SymtabCommandLargeOffsets symtab_load_command;
// The data element of type bool indicates that this entry is thumb
// code.
typedef AddressDataArray<lldb::addr_t, bool, 100> FunctionStarts;
Expand Down Expand Up @@ -2276,12 +2276,20 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
// Watch for the symbol table load command
switch (lc.cmd) {
case LC_SYMTAB:
// struct symtab_command {
// uint32_t cmd; /* LC_SYMTAB */
// uint32_t cmdsize; /* sizeof(struct symtab_command) */
// uint32_t symoff; /* symbol table offset */
// uint32_t nsyms; /* number of symbol table entries */
// uint32_t stroff; /* string table offset */
// uint32_t strsize; /* string table size in bytes */
// };
symtab_load_command.cmd = lc.cmd;
symtab_load_command.cmdsize = lc.cmdsize;
// Read in the rest of the symtab load command
if (m_data.GetU32(&offset, &symtab_load_command.symoff, 4) ==
nullptr) // fill in symoff, nsyms, stroff, strsize fields
return;
symtab_load_command.symoff = m_data.GetU32(&offset);
symtab_load_command.nsyms = m_data.GetU32(&offset);
symtab_load_command.stroff = m_data.GetU32(&offset);
symtab_load_command.strsize = m_data.GetU32(&offset);
break;

case LC_DYLD_INFO:
Expand Down
13 changes: 13 additions & 0 deletions lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,19 @@ class ObjectFileMachO : public lldb_private::ObjectFile {
bool IsValid() { return all_image_infos.size() > 0; }
};

// The LC_SYMTAB's symtab_command structure uses 32-bit file offsets
// for two fields, but ObjectFileMachO needs to calculate the offsets
// in virtual address layout from the start of the TEXT segment, and
// that span may be larger than 4GB.
struct SymtabCommandLargeOffsets {
uint32_t cmd = 0; /* LC_SYMTAB */
uint32_t cmdsize = 0; /* sizeof(struct symtab_command) */
lldb::offset_t symoff = 0; /* symbol table offset */
uint32_t nsyms = 0; /* number of symbol table entries */
lldb::offset_t stroff = 0; /* string table offset */
uint32_t strsize = 0; /* string table size in bytes */
};

/// Get the list of binary images that were present in the process
/// when the corefile was produced.
/// \return
Expand Down