Remote debugging on Mac OS X with XCode 6



I’m currently trying to remote debug one of my Mac application: build on Yosemite 10.10 and try to debug on my old MacBook under Lion 10.7.5 (which has not Xcode installed)

As far as I know, the remote debug option has unfortunately disappeared since Xcode 4. Digging on forums didn’t give me a solution but it seems that one tool called debugserver is used when remote debugging on iPhone.

This tool is included in the Xcode package (DeveloperDiskImage.dmg), for iPhone only. But it is possible to build it from the lldb sources:

* Step 1: building debugserver for OS X

on, get the source with:
– git clone
– open the lldb.codeproj with Xcode
– set the build target to the debugserver scheme and the OS X 10.7 deployment target.
– CMD-B to build, there is a failed codesign error but we don’t need it yet (we don’t build the full lldb tools which need to be code signed)
– on the left pane, navigate to Tools->debugserver->debugserver.xcodeproj->Products and right click on debugserver -> reveal in finder.

You should have a working binary. Send it to your remote 10.7 machine, it should work. If it’s not running correctly, you might need to install the developer tools – not 100% sure with that, I made several unsuccessfull tests before.


* Step 2: creating a common build folder

For my tests purposes, I simply made a folder called sharedBuild on my desktop, and shared it on my network. My remote computer is able to see it, and I created a symlink in order to have the same paths on the local and the remote machine (ln -s /Users/myuserlocal /Users/myremoteuser). It’s a bit dirty but easily changeable depending on your configuration.

You should now to able to build on the local machine, and directly run the app from the remote computer. I removed all code signs option to be sure that the app will run correctly on the remote machine.

* Step 3: attach to the remote process from the local debugger lldb

– open the terminal on the remote machine and run the debugserver:
sudo /path/to/debugserver 192.168.0.X:1234 /path/to/sharedBuild/appname-cdcscdsdsds/Build/Products/Debug/
192.168.0.X is the IP of your local machine
you should see: Listening on port 1234 for a connection from 192.168.0.X

– on your local machine, open a terminal and run lldb as follow:
platform select remote-macosx

// Platform: remote-macosx
// Connected: no

process connect connect://192.168.0.Y (IP of your remote machine)
//Process 75292 stopped
//* thread #1: tid = 0x4503d, 0x00007fff6ea3e028 dyld`_dyld_start, stop reason = signal SIGSTOP
// frame #0: 0x00007fff6ea3e028 dyld`_dyld_start
//-> 0x7fff6ea3e028: pushq $0x0
// 0x7fff6ea3e02a: movq %rsp, %rbp
// 0x7fff6ea3e02d: andq $-0x10, %rsp
// 0x7fff6ea3e031: movq 0x8(%rbp), %rdi

//Process 75292 resuming

the process is now running, this step seems stuck and is very long, but after a while the app is running on the remote machine, and I can interrupt it from the local machine.

* Step 4 : stuck and looking for help …

– trying to set breakpoints and see the source code is not working for me – still don’t know why
– I wish I could attach directly the process from Xcode but I am unable to do so. I check under the schemes option and the preferences behaviors. Also, running a first instance on the local machine, trying to detach the process is also killing the lldb debugger.
– If you have more improvements, or a better way to remote debug on OS X with Xcode, feel free to answer!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>