Skip to content

Aim debugserver workaround more precisely. #83099

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
merged 1 commit into from
Feb 27, 2024

Conversation

adrian-prantl
Copy link
Collaborator

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Feb 27, 2024

@llvm/pr-subscribers-lldb

Author: Adrian Prantl (adrian-prantl)

Changes

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

2 Files Affected:

  • (modified) lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp (+14-1)
  • (modified) lldb/source/Target/Target.cpp (+3-1)
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index 6f8aa262289946..c38d74ca8e6c95 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -17,6 +17,7 @@
 
 #include "lldb/Core/ModuleSpec.h"
 #include "lldb/Host/HostInfo.h"
+#include "lldb/Host/SafeMachO.h"
 #include "lldb/Host/XML.h"
 #include "lldb/Symbol/Symbol.h"
 #include "lldb/Target/MemoryRegionInfo.h"
@@ -2147,8 +2148,20 @@ bool GDBRemoteCommunicationClient::GetCurrentProcessInfo(bool allow_lazy) {
           if (!value.getAsInteger(16, cpu))
             ++num_keys_decoded;
         } else if (name.equals("cpusubtype")) {
-          if (!value.getAsInteger(16, sub))
+          if (!value.getAsInteger(16, sub)) {
             ++num_keys_decoded;
+            // Workaround for for pre-2024 Apple debugserver, which always
+            // returns arm64e on arm64e-capable hardware regardless of
+            // what the process is. This can be deleted at some point in
+            // the future.
+            if (cpu == llvm::MachO::CPU_TYPE_ARM64 &&
+                sub == llvm::MachO::CPU_SUBTYPE_ARM64E) {
+              if (GetGDBServerVersion())
+                if (m_gdb_server_version >= 1000 &&
+                    m_gdb_server_version <= 1504)
+                  sub = 0;
+            }
+          }
         } else if (name.equals("triple")) {
           StringExtractor extractor(value);
           extractor.GetHexByteString(triple);
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 089915cab4915a..b592016e7a9824 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -33,7 +33,6 @@
 #include "lldb/Expression/UtilityFunction.h"
 #include "lldb/Host/Host.h"
 #include "lldb/Host/PosixApi.h"
-#include "lldb/Host/SafeMachO.h"
 #include "lldb/Host/StreamFile.h"
 #include "lldb/Interpreter/CommandInterpreter.h"
 #include "lldb/Interpreter/CommandReturnObject.h"
@@ -1572,6 +1571,7 @@ bool Target::SetArchitecture(const ArchSpec &arch_spec, bool set_platform,
 
         if (m_arch.GetSpec().GetTriple() == other.GetTriple())
           replace_local_arch = false;
+<<<<<<< HEAD
         // Workaround for for pre-2024 debugserver, which always
         // returns arm64e on arm64e-capable hardware regardless of
         // what the process is. This can be deleted at some point in
@@ -1579,6 +1579,8 @@ bool Target::SetArchitecture(const ArchSpec &arch_spec, bool set_platform,
         if (!m_arch.GetSpec().GetMachOCPUSubType() &&
             other.GetMachOCPUSubType() == llvm::MachO::CPU_SUBTYPE_ARM64E)
           replace_local_arch = true;
+=======
+>>>>>>> e491dde5dab4 (Aim debugserver workaround more precisely.)
       }
     }
   }

@jasonmolenda
Copy link
Collaborator

I'm a little split because the current packet is not super useful as it's constructed today - I'd really like to see a domain or vendor along with a version number And instead of a simple number, maybe a major/minor version number and/or a version string? I'm also fine with landing this now, detecting an "old" apple debugserver as 1000 < version number < 1504, and I can do the version packet fix separately and update the check.

@jasonmolenda
Copy link
Collaborator

I'm not fishing for Adrian to dig in to that, I'm happy to make the change. but I'm curious what @JDevlieghere and @adrian-prantl think, if it's worth changing this packet. It's not used anywhere yet, so overhauling it now before/shortly after we actually start using it, is the right way to go.

Copy link
Collaborator

@jasonmolenda jasonmolenda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, let's land this patch. I will extend the stub version packet with additional fields (Jonas points out that other stubs implement this packet already as-is) and update this once that PR is approved and merged. But we don't need to block this PR on getting that done.

Copy link
Member

@JDevlieghere JDevlieghere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy if Jason is happy!

@adrian-prantl adrian-prantl merged commit 8a87f76 into llvm:main Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants