1

I am developing a macOS app that runs on 10.11+. My dev machine runs 10.12 and quite possibly sometime later today 10.13.

To test the app on 10.11 I copy it into a Parallels virtual machine that runs the older version(s) of macOS. Now if I wanted to actually debug the app under the old system, what would I have to do (Is this even possible)? I had a crash that only happened under 10.11 and it was really hard to debug without having breakpoints available.

The following problems arise:

I use Xcode 9 which requires 10.12 afaik, so I can't just run Xcode inside the VM (Aside from the fact that I am specifically building the app with the latest 10.12 SDK, which wouldn't be available on 10.11?).

So is it possible to actually either

  • start the app inside the VM by "running" it from Xcode on the host?
  • attach after the app is manually run from outside Xcode?
  • not use Xcode but at least debug from the command line?

How is that problem usually solved?

Thomas Krajacic
  • 2,488
  • 1
  • 21
  • 25
  • In this situation, I'd ignore Xcode and run the `lldb` debugger from the command line, in the 10.11 VM. That way you can start the app from the debugger, or just attach to it while running. – TheDarkKnight Sep 25 '17 at 12:47
  • Mhm, but do I have the source code available in lldb inside the VM? Sorry if that's a stupid questions but I never used lldb on the command line. I mean how can I step through my source code then? – Thomas Krajacic Sep 25 '17 at 13:25
  • If it's a debug build, then yes. You can also generate the [dysm file](https://stackoverflow.com/questions/29209582/make-sure-your-project-build-settings-are-generating-a-dsym-file-debug-informat) for release builds. Copy it to the machine on which you're debugging, in a location that Finder can index it and it should automatically get picked up. – TheDarkKnight Sep 25 '17 at 13:58
  • Mhm, when I install lldb in the vm I only get Swift 3. I guess I need to install the latest Swift 4 toolchain then. Trying now ;) – Thomas Krajacic Sep 25 '17 at 15:11
  • Ok, so I can use the old lldb and can run the target, but I can't set a breakpoint using a filename and line number yet because those locations are not found. I guess I need to learn some lldb stuff first :( – Thomas Krajacic Sep 25 '17 at 15:42
  • Also, I am trying to debug the release executable but I have put the dsym file next to it on the Desktop. – Thomas Krajacic Sep 25 '17 at 15:44
  • I guess I need to copy the source files to some accessible location inside the vm as well? – Thomas Krajacic Sep 25 '17 at 15:50
  • If you're missing source code, [this SO question](https://stackoverflow.com/questions/36968721/lldb-not-showing-source-code) should help. Whilst it may be a learning curve to get this working, familiarising yourself with lldb will be worth it in the long term. – TheDarkKnight Sep 26 '17 at 07:52

1 Answers1

0

To run lldb from the host and attach to the VM guest this worked for me with Parallels 14 Pro for Mac, El-Capitan VM, Mojave Host

On the VM:

Download the Xcode command line tools and find lldb-server, the path for mine was as below, start the server:

/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/lldb-server platform --listen "*:1234" --server

Start your application on the VM - I just used a shared folder

On the Host

$ lldb
lldb> platform select remote-macosx
lldb> platform connect connect://<Your VM - e.g. el-capitan>:1234   
lldb> file "<YourPath>/<YourApp>.app/Contents/MacOS/<AppName>"
lldb> platform process list
lldb> attach 750 # The PID from the list command
lldb> process continue
lldb> break set --filename <AnyFileInYourApp>.swift --line <nnn>
lldb> po <variable>
lldb> ... and so on

Note in the file command its not the .app but the binary

Now to find an IDE that supports this

Visual Studio Code seems to work well, and here's my launch.json entry

{
            "name": "Remote attach",
            "type": "lldb",
            "request": "attach",
            "program": "<YourPath>/<YourApp>.app/Contents/MacOS/<AppName>",
            "initCommands": [
                "platform select remote-macosx",
                "platform connect connect://<Your VM - e.g. el-capitan>:1234"
            ],
}
daven11
  • 2,905
  • 3
  • 26
  • 43