ADC Home > Reference Library > Technical Q&As > Tools > Compiling & Debugging >

Remote or Two-Machine Debugging Applications with GDB


Q: I cannot use GDB to debug my application because it interferes with the code that I'm trying to debug, what can I do?

A: You may experience this situation if you try to debug, for example, a drag and drop operation between two applications, a complex activate / deactivate / update case, or an application which grabs the entire screen (this is not an exhaustive list). In those situations, the window displaying GDB (whether in Project Builder or in Terminal) will interfere with the code that you want to debug. A very good solution to that problem is to do two-machine debugging, aka remote debugging: you just need another Macintosh and have both machines connected to the same network.

You will debug the target Macintosh through GDB that you will use within the Terminal application on the Macintosh in control. It may be easier, in the future, to use GDB within Xcode on the Macintosh in control, but it is currently impractical.

1) On the target Macintosh, which contains the application or applications to debug, you enable "Remote Login" by using the "Sharing" pane of the System Preferences. When you turn that service on, a message will appear giving you the command line information you need in order to connect (ie. type "ssh yourname@yournetwork.com")



Note:
You could also just use "ssh xx.xx.xx.xx" if you know the IP address of the target Macintosh.



2) On the Macintosh in control, you launch the Terminal application and open as many windows as there are applications to debug (two in the drag and drop scenario, one in the others).

3) In each window, you first ssh to the target Macintosh by typing the command line information you got in the Sharing pane (you will be asked the password associated with that user), and then, you launch GDB (the GDB tool launched is the one on the target machine) and either run the application or attach to its pid (please, read the GDB manual for more details). You can also use the symbols files of the application[s] you need to debug (again read the GDB manual for more details).



Note:
If you have two windows, each running GDB, it's advisable to tile them so that you can see both of them at the same time in order to easily notice breakpoints interrupts or messages from either application.



4) After you're done debugging, don't forget to quit GDB, quit Terminal, and, if you no longer have a need for it, disable the Remote Login service on the target Macintosh.


[Sep 09, 2003]


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.