llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/105576.diff


4 Files Affected:

- (modified) lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp (+10-5) 
- (added) lldb/test/Shell/Process/Inputs/a.out.yaml (+62) 
- (added) lldb/test/Shell/Process/Inputs/corefile.yaml (+22) 
- (added) lldb/test/Shell/Process/ProcessMachCoreArch.test (+8) 


``````````diff
diff --git a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp 
b/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
index 930c707604bb3..348b18e38560a 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 0000000000000..f63457d39824c
--- /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 0000000000000..537da8e85cba3
--- /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 0000000000000..5d3bbd4ab6950
--- /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

``````````

</details>


https://github.com/llvm/llvm-project/pull/105576
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to