Skip to content

Commit 547f7e9

Browse files
committed
[lldb] Pick the correct architecutre when target and core file disagree (llvm#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 (cherry picked from commit 9f41805)
1 parent 3c00f6f commit 547f7e9

File tree

4 files changed

+102
-5
lines changed

4 files changed

+102
-5
lines changed

lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -562,17 +562,22 @@ Status ProcessMachCore::DoLoadCore() {
562562

563563
SetCanJIT(false);
564564

565-
// The corefile's architecture is our best starting point.
566-
ArchSpec arch(m_core_module_sp->GetArchitecture());
567-
if (arch.IsValid())
568-
GetTarget().SetArchitecture(arch);
569-
570565
CreateMemoryRegions();
571566

572567
LoadBinariesAndSetDYLD();
573568

574569
CleanupMemoryRegionPermissions();
575570

571+
ModuleSP exe_module_sp = GetTarget().GetExecutableModule();
572+
if (exe_module_sp && exe_module_sp->GetArchitecture().IsValid()) {
573+
GetTarget().SetArchitecture(exe_module_sp->GetArchitecture());
574+
} else {
575+
// The corefile's architecture is our best starting point.
576+
ArchSpec arch(m_core_module_sp->GetArchitecture());
577+
if (arch.IsValid())
578+
GetTarget().SetArchitecture(arch);
579+
}
580+
576581
AddressableBits addressable_bits = core_objfile->GetAddressableBits();
577582
SetAddressableBitMasks(addressable_bits);
578583

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
--- !mach-o
2+
FileHeader:
3+
magic: 0xFEEDFACE
4+
cputype: 0xC
5+
cpusubtype: 0x10
6+
filetype: 0x2
7+
ncmds: 3
8+
sizeofcmds: 272
9+
flags: 0x200085
10+
LoadCommands:
11+
- cmd: LC_SEGMENT
12+
cmdsize: 56
13+
segname: __PAGEZERO
14+
vmaddr: 0
15+
vmsize: 16384
16+
fileoff: 0
17+
filesize: 0
18+
maxprot: 0
19+
initprot: 0
20+
nsects: 0
21+
flags: 0
22+
- cmd: LC_SEGMENT
23+
cmdsize: 192
24+
segname: __TEXT
25+
vmaddr: 16384
26+
vmsize: 32768
27+
fileoff: 0
28+
filesize: 32768
29+
maxprot: 5
30+
initprot: 5
31+
nsects: 2
32+
flags: 0
33+
Sections:
34+
- sectname: __text
35+
segname: __TEXT
36+
addr: 0xBFB4
37+
size: 4
38+
offset: 0x7FB4
39+
align: 1
40+
reloff: 0x0
41+
nreloc: 0
42+
flags: 0x80000400
43+
reserved1: 0x0
44+
reserved2: 0x0
45+
reserved3: 0x0
46+
content: '00207047'
47+
- sectname: __unwind_info
48+
segname: __TEXT
49+
addr: 0xBFB8
50+
size: 72
51+
offset: 0x7FB8
52+
align: 2
53+
reloff: 0x0
54+
nreloc: 0
55+
flags: 0x0
56+
reserved1: 0x0
57+
reserved2: 0x0
58+
reserved3: 0x0
59+
content: 010000001C000000000000001C000000000000001C00000002000000B57F00003400000034000000BA7F00000000000034000000030000000C000100100001000000000000000000
60+
- cmd: LC_UUID
61+
cmdsize: 24
62+
uuid: C2065535-C63D-3C6A-BF79-19CF960DEF2E
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--- !mach-o
2+
FileHeader:
3+
magic: 0xFEEDFACF
4+
cputype: 0xC
5+
cpusubtype: 0x9
6+
filetype: 0x4
7+
ncmds: 1
8+
sizeofcmds: 84
9+
flags: 0x0
10+
reserved: 0x0
11+
LoadCommands:
12+
- cmd: LC_THREAD
13+
cmdsize: 84
14+
PayloadBytes: [ 0x1, 0x0, 0x0, 0x0, 0x11, 0x0, 0x0, 0x0, 0x0, 0x0,
15+
0x1, 0x0, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x3, 0x0,
16+
0x0, 0x0, 0x4, 0x0, 0x0, 0x0, 0x5, 0x0, 0x0, 0x0,
17+
0x6, 0x0, 0x0, 0x0, 0x7, 0x0, 0x0, 0x0, 0x8, 0x0,
18+
0x0, 0x0, 0x9, 0x0, 0x0, 0x0, 0xA, 0x0, 0x0, 0x0,
19+
0xB, 0x0, 0x0, 0x0, 0xC, 0x0, 0x0, 0x0, 0xD, 0x0,
20+
0x0, 0x0, 0xE, 0x0, 0x0, 0x0, 0xF, 0x0, 0x0, 0x0,
21+
0x10, 0x0, 0x0, 0x0, 0x11, 0x0 ]
22+
...
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# RUN: yaml2obj %S/Inputs/corefile.yaml -o %t.corefile
2+
# RUN: yaml2obj %S/Inputs/a.out.yaml -o %t.out
3+
4+
# RUN: %lldb -b -c %t.corefile %t.out -o 'target list ' | FileCheck %s --check-prefix BINARY
5+
# BINARY: target {{.*}} arch=armv7em-apple
6+
7+
# RUN: %lldb -b %t.corefile -o 'target list' | FileCheck %s --check-prefix CORE
8+
# CORE: target {{.*}} arch=armv7-apple

0 commit comments

Comments
 (0)