Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attaching to a remote process for debugging

Using Xcode 3.1 on OSX 10.5; is it possible to attach (the debugger) to a running remote process?

I know that it's possible to start and debug a remote process (as explained here), but it would be great if I could find a way to attach to an already running remote process...

edit to add: Thanks. I've submitted a bug report to Apple. Will update this question if/when I hear back from them.

like image 700
fuad Avatar asked Oct 08 '08 00:10

fuad


People also ask

How do you connect to remote server for debugging?

Select Configure remote debugging to configure the firewall and start the remote debugger. When configuration is complete, the Remote Debugger window appears. The remote debugger is now waiting for a connection. Use the server name and port number shown to set the remote connection configuration in Visual Studio.

How do you attach a debugger to a process in IntelliJ?

Press Ctrl+Alt+F5 or choose Run | Attach to Process from the main menu. IntelliJ IDEA will show the list of the running local processes. Select the process to attach to. The processes launched with the debug agent are shown under Java.

What does attach to process mean?

Attaching to the process means telling the CPU to send the instructions in the executable code to a debugger before they're executed by the CPU. In other words, you place the debugger between the executable code and the CPU.


1 Answers

There is no nice gui for it in XCode but you can do it this way:

  1. start a second instance of the program from XCode with remote debugging,
  2. use the GDB attach command from the console

Step by step instructions:

  1. Follow Apple's instructions to set up remote debuging:

  2. Find out the process-id of the running instance of your program on the remote box:

    ssh "remotemachine" 'ps -x -w -w' | grep "AppName"

    (you can also use ARD and ActivityMonitor)

  3. Put a breakpoint to your app main, and start a second instance from the Debugger (on the remote box)

  4. In the GDB console (Run/Console menu) enter:

    attach process-id

  5. Now you have you XCode attached to the running process. You can now use the graphical debugger.

(In early XCode, there was no GUI for attaching to local processes, so this trick/hack was the solution...)

like image 157
mfazekas Avatar answered Sep 20 '22 22:09

mfazekas