Attach debugger to existing process?

Moved from GitHub:

Is this feature supported?

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

Is it possible to attach debugger to the app started from the Java IDE?

No, you should start the app from Xcode with custom command line args to wait for the Java debugger to attach.

The other way around is currently unsupported.

EDIT: I assumed, that you wanted to attach an Xcode debugger to the running process. To attach a Java debugger, you would have to make sure that the Java debugger is initialized (e.g. change the main.cpp accordingly), but it does not wait for a debugger to attach, only listen for connections on a specified port.

Then you could attach to that port using a remote debugger configuration.
For debugging on devices, you will have to set up a port proxy, like above.

Thank you Gergely. I am looking for the Java debugger.
Could you please enlighten me a bit more on changing main.cpp for initializing Java debugger?

As far as I understand this needs to be in the command line before JVM starts:
-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005

Right, that code is called from the IDE plugin, so I have to modify the argv passed to moevm in main.cpp below. Unfortunately that is beyond my C/C++ skills… :confused:

int main(int argc, char *argv[]) {
    return moevm(argc, argv);
}

Here is a sample

http://cpp.sh/8klf

1 Like

Actually, this should work from IDE run config program arguments, but it does not now. I created an issue to track this:

https://github.com/multi-os-engine/multi-os-engine/issues/85

This only relates to launching from Java IDE. Launching from Xcode like this works as intended.

I see there were some changes in 1.3.0 on this respect.

How’s the best way to use the debugger for an iOS app as of today?

Thanks in advance,