Skip to content

Commit

Permalink
[lldb] Pick the correct architecutre when target and core file disagr…
Browse files Browse the repository at this point in the history
…ee (#105576)

In f9f3316, Adrian fixed an issue where LLDB wouldn't update the
target's architecture when the process reported a different triple that
only differed in its sub-architecture.

This unintentionally regressed core file debugging when the core file
reports the base architecture (e.g. armv7) while the main binary knows
the correct CPU subtype (e.g. armv7em). After the aforementioned change,
we update the target architecture from armv7em to armv7. Fix the issue
by trusting the target architecture over the ProcessMachCore process.

rdar://133834304
  • Loading branch information
JDevlieghere authored Aug 22, 2024
1 parent 3c54aa1 commit 9f41805
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,17 +562,22 @@ Status ProcessMachCore::DoLoadCore() {

SetCanJIT(false);

// The corefile's architecture is our best starting point.
ArchSpec arch(m_core_module_sp->GetArchitecture());
if (arch.IsValid())
GetTarget().SetArchitecture(arch);

CreateMemoryRegions();

LoadBinariesAndSetDYLD();

CleanupMemoryRegionPermissions();

ModuleSP exe_module_sp = GetTarget().GetExecutableModule();
if (exe_module_sp && exe_module_sp->GetArchitecture().IsValid()) {
GetTarget().SetArchitecture(exe_module_sp->GetArchitecture());
} else {
// The corefile's architecture is our best starting point.
ArchSpec arch(m_core_module_sp->GetArchitecture());
if (arch.IsValid())
GetTarget().SetArchitecture(arch);
}

AddressableBits addressable_bits = core_objfile->GetAddressableBits();
SetAddressableBitMasks(addressable_bits);

Expand Down
62 changes: 62 additions & 0 deletions lldb/test/Shell/Process/Inputs/a.out.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
--- !mach-o
FileHeader:
magic: 0xFEEDFACE
cputype: 0xC
cpusubtype: 0x10
filetype: 0x2
ncmds: 3
sizeofcmds: 272
flags: 0x200085
LoadCommands:
- cmd: LC_SEGMENT
cmdsize: 56
segname: __PAGEZERO
vmaddr: 0
vmsize: 16384
fileoff: 0
filesize: 0
maxprot: 0
initprot: 0
nsects: 0
flags: 0
- cmd: LC_SEGMENT
cmdsize: 192
segname: __TEXT
vmaddr: 16384
vmsize: 32768
fileoff: 0
filesize: 32768
maxprot: 5
initprot: 5
nsects: 2
flags: 0
Sections:
- sectname: __text
segname: __TEXT
addr: 0xBFB4
size: 4
offset: 0x7FB4
align: 1
reloff: 0x0
nreloc: 0
flags: 0x80000400
reserved1: 0x0
reserved2: 0x0
reserved3: 0x0
content: '00207047'
- sectname: __unwind_info
segname: __TEXT
addr: 0xBFB8
size: 72
offset: 0x7FB8
align: 2
reloff: 0x0
nreloc: 0
flags: 0x0
reserved1: 0x0
reserved2: 0x0
reserved3: 0x0
content: 010000001C000000000000001C000000000000001C00000002000000B57F00003400000034000000BA7F00000000000034000000030000000C000100100001000000000000000000
- cmd: LC_UUID
cmdsize: 24
uuid: C2065535-C63D-3C6A-BF79-19CF960DEF2E
22 changes: 22 additions & 0 deletions lldb/test/Shell/Process/Inputs/corefile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--- !mach-o
FileHeader:
magic: 0xFEEDFACF
cputype: 0xC
cpusubtype: 0x9
filetype: 0x4
ncmds: 1
sizeofcmds: 84
flags: 0x0
reserved: 0x0
LoadCommands:
- cmd: LC_THREAD
cmdsize: 84
PayloadBytes: [ 0x1, 0x0, 0x0, 0x0, 0x11, 0x0, 0x0, 0x0, 0x0, 0x0,
0x1, 0x0, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x3, 0x0,
0x0, 0x0, 0x4, 0x0, 0x0, 0x0, 0x5, 0x0, 0x0, 0x0,
0x6, 0x0, 0x0, 0x0, 0x7, 0x0, 0x0, 0x0, 0x8, 0x0,
0x0, 0x0, 0x9, 0x0, 0x0, 0x0, 0xA, 0x0, 0x0, 0x0,
0xB, 0x0, 0x0, 0x0, 0xC, 0x0, 0x0, 0x0, 0xD, 0x0,
0x0, 0x0, 0xE, 0x0, 0x0, 0x0, 0xF, 0x0, 0x0, 0x0,
0x10, 0x0, 0x0, 0x0, 0x11, 0x0 ]
...
8 changes: 8 additions & 0 deletions lldb/test/Shell/Process/ProcessMachCoreArch.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# RUN: yaml2obj %S/Inputs/corefile.yaml -o %t.corefile
# RUN: yaml2obj %S/Inputs/a.out.yaml -o %t.out

# RUN: %lldb -b -c %t.corefile %t.out -o 'target list ' | FileCheck %s --check-prefix BINARY
# BINARY: target {{.*}} arch=armv7em-apple

# RUN: %lldb -b %t.corefile -o 'target list' | FileCheck %s --check-prefix CORE
# CORE: target {{.*}} arch=armv7-apple

0 comments on commit 9f41805

Please sign in to comment.