Author: Jonas Devlieghere Date: 2024-08-22T08:29:48-07:00 New Revision: 9f418057dc73e4e5cb94a7cd671097275ffc29fc
URL: https://github.com/llvm/llvm-project/commit/9f418057dc73e4e5cb94a7cd671097275ffc29fc DIFF: https://github.com/llvm/llvm-project/commit/9f418057dc73e4e5cb94a7cd671097275ffc29fc.diff LOG: [lldb] Pick the correct architecutre when target and core file disagree (#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 Added: lldb/test/Shell/Process/Inputs/a.out.yaml lldb/test/Shell/Process/Inputs/corefile.yaml lldb/test/Shell/Process/ProcessMachCoreArch.test Modified: lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp Removed: ################################################################################ diff --git a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp b/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp index 930c707604bb38..348b18e38560a6 100644 --- a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp +++ b/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp @@ -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); diff --git a/lldb/test/Shell/Process/Inputs/a.out.yaml b/lldb/test/Shell/Process/Inputs/a.out.yaml new file mode 100644 index 00000000000000..f63457d39824c6 --- /dev/null +++ b/lldb/test/Shell/Process/Inputs/a.out.yaml @@ -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 diff --git a/lldb/test/Shell/Process/Inputs/corefile.yaml b/lldb/test/Shell/Process/Inputs/corefile.yaml new file mode 100644 index 00000000000000..537da8e85cba35 --- /dev/null +++ b/lldb/test/Shell/Process/Inputs/corefile.yaml @@ -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 ] +... diff --git a/lldb/test/Shell/Process/ProcessMachCoreArch.test b/lldb/test/Shell/Process/ProcessMachCoreArch.test new file mode 100644 index 00000000000000..5d3bbd4ab6950e --- /dev/null +++ b/lldb/test/Shell/Process/ProcessMachCoreArch.test @@ -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 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits