Clark Updike / Remote Jython Debugging¶

Legacy Wiki Page

This page was migrated from the old MoinMoin-based wiki. Information may be outdated or no longer applicable. For current documentation, see python.org.

The following describes how to set up a remote debugging session with a running jython application (or any java application for that matter).

Basically, you just:

  • Modify the java command line that starts jython

  • Set up your ide to attach to the debugging session

Java Command Line To Startup The App¶

Here’s what mine looks like to run from the jar:

C:\apps\j2sdk1.4.2\jre\bin\java.exe -Xnoagent -Djava.compiler=NONE -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000 -Dpython.home=C:\\workspace\\JythonTip\\jython\\dist -jar c:\workspace\JythonTip\jython\dist\jython.jar

or to run from the class directories:

C:\apps\j2sdk1.4.2\jre\bin\java.exe -Xnoagent -Djava.compiler=NONE -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000 -classpath <very long classpath> org.python.util.jython

Eclipse hint: external java command ā€œsnarfingā€ tip

And here’s what the options mean:

Command Line Option

Meaning

-Xnoagent

Disables the old sun.tools.debug agent

-Djava.compiler=NONE

Turn off JIT compilation (required in order to use the ā€œclassicā€ debugger)

-XDebug

Enable debugging

-Xrunjdwp:<options>

Enable the Java Debug Wire Protocol

And here’s the <options>:

JDWP Option

Meaning

server=y

Tell the app to listen for debugging connections

transport=dt_socket

We’re going to use a socket (see below for other options)

address=8000

The socket to listen on

Note: Once you hit enter, the app may not respond like it normally does. For the jython interpreter, it seems to ā€œhangā€. But once you attach your debugger to it (below), it will respond with the familiar propmt–kind of like ā€œlazy initializationā€.

See below for further references…

IDE Settings¶

For Eclipse:

  • Navigate into your source and set your break points.

  • Select Run|Debug.

  • Look for the RemoteĀ JavaĀ Application run configuration type on the Debug dialog.

  • Select your jython project.

  • The ConnectionĀ Type: should be Standard(SocketĀ Attach). I imagine in the future there may be other options, like shared memory (if your running locally on windows).

  • Enter 8000 for the port number (or whatever port number you configure your app to listen on).

  • Click Debug

This will take you into the app at the first breakpoint.

For NetBeans:
[^http://debuggercore.netbeans.org/docs/VM-options.html netbeans vm options for debugging]

I have used this technique also for debugging a development Tomcat server remotely (see article below). Keep in mind that in a multithreaded environment, all threads will get stopped at your breakpoint, so be warned if this is not a private workspace.

References¶


Eclipse External Command ā€œSnarfingā€ Tip¶

If you have an app that you run inside eclipse and you want to run it standalone (in a shell), you can get at the launch command that Eclipse uses:

  • Go into the Eclipse debug perspective.

  • If you don’t already have a debug session showing for the app (live or terminated), start it up.

  • Click on the + to expand the debug session (if needed).

  • You should see a line like this:

    • <path to javaw.exe>\javaw.exe (<timestamp>)

    • Mine is: C:\apps\j2sdk1.4.2\jre\bin\javaw.exeĀ (MarĀ 1,Ā 2005Ā 4:24:02Ā PM)

  • Right-click on this line and select properties.

  • You can then swipe/copy the CommandĀ Line info.

  • You can then paste this into your shell. You’ll typically want to convert the javaw.exe to a java.exe to receive output to the shell.