This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Fix platform selection on Apple Silicon (again)
ClosedPublic

Authored by JDevlieghere on Mar 10 2022, 11:10 PM.

Details

Summary

This patch is another attempt to fix platform selection on Apple Silicon. It partially undoes D117340 which tried to fix the issue by always instantiating a remote-ios platform for "iPhone and iPad Apps on Apple Silicon Macs". While the previous patch worked for attaching, it broke launching and everything else that expects the remote platform to be connected. I made an attempt to work around that, but quickly found out that there were just too may places that had this assumption baked in.

This patch takes a different approach and reverts back to marking the host platform compatible with iOS triples. This brings us back to the original situation where platform selection was broken for remote iOS debugging on Apple Silicon. To fix that, I now look at the process' system architecture to differentiate between iOS binaries running remotely and iOS binaries running locally. I wish I could make this distinction in the platform, but you need a connected process to do this.

I tested the following scenarios, which now all uses the desired platform:

  • Launching an iOS binary on macOS: uses the host platform
  • Attaching to an iOS binary on macOS: uses the host platform
  • Attaching to a remote iOS binary: uses the remote-ios platform

rdar://89840215

Diff Detail

Event Timeline

JDevlieghere created this revision.Mar 10 2022, 11:10 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 10 2022, 11:10 PM
JDevlieghere requested review of this revision.Mar 10 2022, 11:10 PM
JDevlieghere updated this revision to Diff 414590.

Include TargetConditionals.h

I wish I could make this distinction in the platform, but you need a connected process to do this.

Basically, what you're saying is that the ArchSpec alone is not sufficient to select the right platform. Instead of punching right through the layers, could we just give more information (which I guess would be the system architecture) to the functions responsible for selecting the right plugin? Then they could do the regular ask-each-plugin-if-it-wants-to-handle-it dance. The host plugin would say "I don't handle processes with system-arch=*-ios" and then we would go around until we find the remote-ios plugin saying "I live for debugging ios systems"?

[I must admit that I have a bit of an ulterior motive for suggesting this -- I also have a use case where the ArchSpec is not sufficient to select the best platform, but I've struggled to formulate it in a way that makes sense upstream. The system architecture is not relevant for my case (what I'd really need is to inspect the details of the executable being debugged -- mainly its path, but possibly also some other bits), but if we open the door to more elaborate platform selection, then I might be able to squeeze this in as well.

I wish I could make this distinction in the platform, but you need a connected process to do this.

Basically, what you're saying is that the ArchSpec alone is not sufficient to select the right platform. Instead of punching right through the layers, could we just give more information (which I guess would be the system architecture) to the functions responsible for selecting the right plugin? Then they could do the regular ask-each-plugin-if-it-wants-to-handle-it dance. The host plugin would say "I don't handle processes with system-arch=*-ios" and then we would go around until we find the remote-ios plugin saying "I live for debugging ios systems"?

[I must admit that I have a bit of an ulterior motive for suggesting this -- I also have a use case where the ArchSpec is not sufficient to select the best platform, but I've struggled to formulate it in a way that makes sense upstream. The system architecture is not relevant for my case (what I'd really need is to inspect the details of the executable being debugged -- mainly its path, but possibly also some other bits), but if we open the door to more elaborate platform selection, then I might be able to squeeze this in as well.

Yup, that could totally work, it didn't seem worth like changing all that for just the one use case, but happy to do it if you can benefit from that as well. Did you have any particular design in mind? For me, passing an extra ArchSpec for the host arch would do the trick, but that doesn't get you much further. I could pass in a little context object which would hold an ArchSpec for the host arch and a FileSpec for your use case. Or maybe we should just pass in the process if we have one and get all the information from that.

I wish I could make this distinction in the platform, but you need a connected process to do this.

Basically, what you're saying is that the ArchSpec alone is not sufficient to select the right platform. Instead of punching right through the layers, could we just give more information (which I guess would be the system architecture) to the functions responsible for selecting the right plugin? Then they could do the regular ask-each-plugin-if-it-wants-to-handle-it dance. The host plugin would say "I don't handle processes with system-arch=*-ios" and then we would go around until we find the remote-ios plugin saying "I live for debugging ios systems"?

[I must admit that I have a bit of an ulterior motive for suggesting this -- I also have a use case where the ArchSpec is not sufficient to select the best platform, but I've struggled to formulate it in a way that makes sense upstream. The system architecture is not relevant for my case (what I'd really need is to inspect the details of the executable being debugged -- mainly its path, but possibly also some other bits), but if we open the door to more elaborate platform selection, then I might be able to squeeze this in as well.

Yup, that could totally work, it didn't seem worth like changing all that for just the one use case, but happy to do it if you can benefit from that as well. Did you have any particular design in mind? For me, passing an extra ArchSpec for the host arch would do the trick, but that doesn't get you much further. I could pass in a little context object which would hold an ArchSpec for the host arch and a FileSpec for your use case. Or maybe we should just pass in the process if we have one and get all the information from that.

A process wouldn't help me, since I am primarily interested in the launch scenario, where the platform is selected long before the process is launched. I am contemplating passing in a ModuleSpec instead of a plain ArchSpec. That would be sufficient for my use case, but I don't know if I really like it (it seems somewhat strange because the we would really like to pass in the process architecture, but a ModuleSpec would normally describe the module architecture (which may be less precise)). So, it may be best to have a specialized context object, but at the end of the day, I don't think that's something that you need to solve. I think it would be sufficient to just add an additional ArchSpec argument for now. If that idea proves itself (and I decide to go ahead with this), I can upgrade that to a context object.

I wish I could make this distinction in the platform, but you need a connected process to do this.

Basically, what you're saying is that the ArchSpec alone is not sufficient to select the right platform. Instead of punching right through the layers, could we just give more information (which I guess would be the system architecture) to the functions responsible for selecting the right plugin? Then they could do the regular ask-each-plugin-if-it-wants-to-handle-it dance. The host plugin would say "I don't handle processes with system-arch=*-ios" and then we would go around until we find the remote-ios plugin saying "I live for debugging ios systems"?

[I must admit that I have a bit of an ulterior motive for suggesting this -- I also have a use case where the ArchSpec is not sufficient to select the best platform, but I've struggled to formulate it in a way that makes sense upstream. The system architecture is not relevant for my case (what I'd really need is to inspect the details of the executable being debugged -- mainly its path, but possibly also some other bits), but if we open the door to more elaborate platform selection, then I might be able to squeeze this in as well.

Yup, that could totally work, it didn't seem worth like changing all that for just the one use case, but happy to do it if you can benefit from that as well. Did you have any particular design in mind? For me, passing an extra ArchSpec for the host arch would do the trick, but that doesn't get you much further. I could pass in a little context object which would hold an ArchSpec for the host arch and a FileSpec for your use case. Or maybe we should just pass in the process if we have one and get all the information from that.

A process wouldn't help me, since I am primarily interested in the launch scenario, where the platform is selected long before the process is launched. I am contemplating passing in a ModuleSpec instead of a plain ArchSpec. That would be sufficient for my use case, but I don't know if I really like it (it seems somewhat strange because the we would really like to pass in the process architecture, but a ModuleSpec would normally describe the module architecture (which may be less precise)). So, it may be best to have a specialized context object, but at the end of the day, I don't think that's something that you need to solve. I think it would be sufficient to just add an additional ArchSpec argument for now. If that idea proves itself (and I decide to go ahead with this), I can upgrade that to a context object.

Cool, that works for me

Check the host architecture in PlatformMacOSX

I don't suppose we could have a (gdb-client?) test for some of this stuff?

lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
159

if (!host_arch || host_arch.GetTriple().getOS() == llvm::Triple::MacOSX)

...
JDevlieghere marked an inline comment as done.Mar 14 2022, 1:39 PM
labath accepted this revision.Mar 15 2022, 2:24 AM

Cool.

This revision is now accepted and ready to land.Mar 15 2022, 2:24 AM
This revision was landed with ongoing or failed builds.Mar 15 2022, 9:07 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 15 2022, 9:07 AM