Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to attach Xcode view debugger to the simulator launched from Visual Studio?

Xcode has a view debugger tool that allows to inspect view hierarchy.

I am working on iOS Xamarin app and would like to debug its view. The app runs on a simulator launched from Visual Studio.

Xcode's attach to process tool does not see PID of the running simulator.

How can I attach Xcode view debugger to this process? Or perhaps there is another way of debugging view hierarchy of a Xamarin app?

like image 448
0rt Avatar asked May 28 '18 14:05

0rt


People also ask

How do I use the Xcode debugger?

You can either launch the App and then attach the debugger or attach and then launch. Either way use the Xcode Debug menu to attach the debugger to a process: If the App is not yet running you will need to attach to it by name.

How do I debug an app in Visual Studio Code?

To debug a simple app in VS Code, press F5 and VS Code will try to debug your currently active file. However, for most debugging scenarios, creating a launch configuration file is beneficial because it allows you to configure and save debugging setup details.

What debuggers are available for Visual Studio for Mac?

Visual Studio for Mac has debuggers with support for.NET Core,.NET Framework, Unity, and Xamarin applications. Visual Studio for Mac uses the Mono Soft Debugger, which is implemented into the Mono runtime, allowing Visual Studio for Mac to debug managed code across all platforms.

Does Visual Studio Code support remote debugging?

Remote debugging. VS Code does not itself support remote debugging: this is a feature of the debug extension you are using, and you should consult the extension's page in the Marketplace for support and details. There is, however, one exception: the Node.js debugger included in VS Code supports remote debugging.


1 Answers

Since you do not have an Enterprise license and thus Xamarin Inspector which is integrated in the Visual Studio debug workflow, you can use Xcode but of course you have to manually apply changes back to your C#/F# code.

  1. Via VS4M start your app on the simulator in order to install it
  2. Stop debugging your app in VS4M
    • Xcode needs to use lldb to access the app and Mono prevents that via a ptrace call (there are ways around this via breaking on mono_assembly_init_with_opt and doing an early return on it, but that is another story)
  3. Manually launch your app in the simulator
  4. Open Xcode
    1. You will need to create an iOS project
      • Anything project will do, it is so Xcode will enable the Debug/Attach to process by PID or Name menu option
  5. If you do not know the process name, obtain the process id of the Xamarin.iOS application that is running on the simulator

    • You can use ps

    ps ax | grep -i Weather | cut -d " " -f 2

    7864

  6. In Xcode attach to that process

    • Debug/Attach to process by PID or Name

enter image description here

  1. Wait a couple of seconds

    • or longer, sometimes Xcode can take a while and other times it is instant (?)
  2. Now you can select View UI Hierarchy from the process info icon (far right icon from the Process name/id) via View process in other ways

enter image description here

Note: View the process name and you can use that in the future instead of the pid, in this case it is WeatherApp.iOS (see screen shot, top left corner)

Note: The above screenshot is using the demo Xamarin.Forms WeatherApp (xamarin-forms-samples/Weather)

like image 85
SushiHangover Avatar answered Sep 28 '22 16:09

SushiHangover