Attach debugger to existing process?

Dear Adrian,

it is possible to start an application from Xcode and attach a JDWP debugger after it launched.

For simulator:

  1. Open the Xcode project
  2. Open the Scheme editor
  3. In the “Run” section go to the “Arguments” tab and add the following arg:
-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005

(if you don’t want the application to wait for the debugger to connect, then use suspend=n)
4. Launch the application from Xcode
5. Create a “Remote” run configuration in Android Studio
6. Set it up to connect to the port specified above (5005)

Note: when using suspend=y, JDWP needs to connect quickly (less than about 30s), otherwise iOS might kill the app.

For devices:

  1. Do the same as for the simulator until (including) step 4.
  2. Open terminal and type
cd ~/.moe/moe-sdk-1.1.0/tools/
java -jar ios-device.jar --debug=5005
  1. Continue from step 5.

If you need the other way around, attaching Xcode to an already running MOE application (which was launched from MOE’s launcher), that is unsupported.

2 Likes