|
|
How To Debug
How to debug various Java applications using the
JDebugTool® graphical Java™ debugger.
The following instructions augment the JDebugTool
Starting Out:
How to debug a Google Android™ app?
How to debug a Java ME app?
How to launch JDebugTool as an external tool in Eclipse?
How to debug a NetBeans project in JDebugTool?
How to remotely debug a Java application?
How to debug an Apache Tomcat™ Servlet?
How to debug an Apache Tomcat 5.0 JSP?
How to debug a JSP (Java Server Pages)?
How to debug an Applet?
-
How to debug a Google Android app?
The JDebugTool Java debugger can debug Android apps.
The following instructions reference the
Developing In Other IDEs Android documentation for information on
using the Android command line tools.
Use the android create project Android command to create a new
Android project. Then build your Android project in debug mode using the
ant debug command.
Or create an Android Project using the Eclipse ADT (Android Development
Tools) plug-in. Do not use the Eclipse Run or Debug actions, or DDMS
perspective. Instead you will use the instructions below to debug using
JDebugTool.
- You would then Mount your application's src directory, as your
Source Path in JDebugTool.
Create an AVD (Android Virtual Device) using the
android create avd Android command, if you have not already.
Launch the Android emulator using the
emulator -avd your_avd_name
Android command.
Install your Android application's .apk file into the emulator
using the
adb install /path/to/your/app.apk
Android command, if you have not already.
Launch the DDMS (Dalvik Debug Monitor Server) using the
ddms
Android command.
If you want to suspend your application on startup, waiting for the
debugger to attach, launch the Dev Tools Android application on the emulator.
Click on Development Settings. Under Debug App, select your application, and
also check Wait for Debugger. Your application will continue execution, after
the debugger attaches, so you will need to set breakpoints ahead of time.
You can also use the android.os.Debug.waitForDebugger() method call
in your application's code, to suspend the calling thread, waiting for the
debugger to attach. The waitForDebugger() call returns immediately
after the debugger attaches, so you will need to set a breakpoint after the
call.
Launch your application on the Android emulator.
Back in the DDMS, click to expand (if necessary) the tree node for your
emulator, and then click to select your application in the subtree of processes.
(If the names of the processes are not being displayed, your application is
probably the last process in the subtree.)
In JDebugTool, select Attach... from the Target menu in the menu bar.
In the resulting Attach to Target dialog, enter localhost as the
Host Name, and 8700 as the Port Number, and finally click on the
OK Button.
Note if debugging on a real device, instead of the emulator,
enable USB debugging, by checking the USB debugging checkbox
under Settings | Applications | Development, on the real device.
Also make sure that you set
<application android:debuggable="true" in your
AndroidManifest.xml
If you are developing on MS Windows®, you will need to install the
USB driver for Windows.
See
Developing on a Device for more details on Android device debugging.
-
How to debug a Java ME app?
The JDebugTool Java debugger can debug Java ME apps.
The following instructions utilize the
Java ME Platform SDK 3.0
In the Java ME Platform SDK GUI, create a new project or open an existing
project, if needed.
- You would then Mount your application's src directory, as your
Source Path in JDebugTool.
In the Java ME Platform SDK GUI, in the Projects tab, right-click on
the project you want to debug, and select the Set as Main Project menu item,
if needed. Make sure that Generate Debugging Info is checked, and that
Obfuscation Level is Off, in the Project Properties.
In the Java ME Platform SDK GUI, click on the Run Main Project in
Debug Mode toolbar button. In the resulting pop up dialog, take note of the
debugging port number. The Java ME emulator is also automatically launched
in debug mode.
In the Java ME emulator, launch your Java ME application, which
will then be suspended, waiting for the debugger to attach.
In JDebugTool, select Attach... from the Target menu in the menu bar.
In the resulting Attach to Target dialog, enter the Port Number you took note
of in Step 4. above, and finally click on the OK Button.
Your Java ME application, will now be suspended in JDebugTool, on a
JVM start event.
-
How to launch JDebugTool as an external tool in Eclipse?
In the Eclipse toolbar, click on the External Tools drop-down menu button,
and select the External Tools Configurations... menu item.
In the resulting External Tools Configurations dialog, click on Program
in the tree on the left-hand side. Then click on the New launch configuration
button in the dialog's toolbar.
In the resulting form page, type JDebugTool in the Name field.
In the Main tab, in the Location field, click on the
Browse File System... button. In the resulting File Selection dialog,
select the location of the JDK Java executable you will use to launch JDebugTool.
For example:
c:/Program Files/Java/jdk1.6.0_21/bin/java.exe
In the Main tab, in the Arguments field, type the arguments
required to launch JDebugTool. For example:
-cp "c:/Users/Mike/jdebugtool/jdebugtool.jar;
c:/Program Files/Java/jdk1.6.0_21/lib/tools.jar"
com.debugtools.jdebugtool.Main
Note well that there is no space after the semicolon. On UNIX®
use a colon instead of the semicolon as the classpath separator.
An optional JDebugTool project name may be specified as the last
argument, in order for the debugger to open a specific project.
If you name your
JDebugTool project the same name as your Eclipse project, then you can click on the
Variables... button under the Arguments field.
In the resulting Select Variable dialog, select
project_name from the list and then click on the OK button to insert the argument
${project_name} as the last argument in the Arguments field.
Then eclipse will substitute the currently selected Eclipse project name
(in the Package Explorer) as the last argument, when launching JDebugTool.
Finally click on the Apply button in the External Tools Configurations
dialog to save your settings. Then click on the Run button to test launch JDebugTool.
Now you will be able to quickly launch JDebugTool from Eclipse by clicking
on the External Tools drop-down menu button in the Eclipse toolbar
and selecting the JDebugTool menu item.
Assuming the default Eclipse project layout, you would Mount the following
Source Path in JDebugTool. For example:
c:/Users/Mike/workspace/MyProject/src
Assuming the default Eclipse project layout, you would add the following
CLASSPATH entry in the Run In Debugger dialog in JDebugTool. For example:
c:/Users/Mike/workspace/MyProject/bin
- In Eclipse, make sure that Generate Debugging Info is turned on
(which it is by default), by right-clicking on your Eclipse project and selecting
Properties from the resulting pop-up context menu. In the resulting
Properties dialog, click on Java Compiler in the left-hand side list.
In the resulting form, under
Classfile Generation, make sure that the following check boxes are checked:
- Add variable attributes to generated class files (used by the
debugger)
- Add line number attributes to generated class files
(used by the debugger)
- Add source file name to generated
class file (used by the debugger)
-
How to debug a NetBeans project in JDebugTool?
Assuming the default NetBeans project layout, you would Mount the following
Source Path in JDebugTool. For example:
c:/Users/Mike/projects/MyProject/src
Assuming the default NetBeans project layout, you would add the following
CLASSPATH entry in the Run In Debugger dialog in JDebugTool. For example:
c:/Users/Mike/projects/MyProject/build/classes
In NetBeans, make sure that Generate Debugging Info is turned on
(which it is by default), by right-clicking on your NetBeans project and selecting
Properties from the resulting pop-up context menu. In the resulting
Project Properties dialog, click on Compiling under Build,
in the Categories tree. In the resulting form, make sure that the
Generate Debugging Info checkbox is checked.
-
How to remotely debug a Java application?
You will need to invoke your Java application with special JVM debugging flags,
for example (all on one line):
jdk1.6.x/bin/java -agentlib:jdwp=transport=dt_socket,server=y,address=8000
test.Test args
This will suspend your application on a JVM start event, waiting for a Java
debugger to attach using a network socket connection, on port 8000.
For JDebugTool to attach to your application, use the Target | Attach... menu item
from the menubar, and the resulting Attach Dialog. Click on the Socket tab, and
fill in the Host Name that your application is running on, and Port Number
8000 in this example. Finally click on the OK button.
See JDebugTool's Context sensitive Help Viewer for other examples, on how to invoke
your application. For the official documentation from
Sun, see the JPDA Connection and Invocation Details for
JDK 1.6,
JDK 1.5,
JDK 1.4 or
JDK 1.3.
It is also possible for JDebugTool to listen for a connection from your
application, use the Target | Listen menu item from the menubar,
and the resulting Listen Dialog.
-
How to debug an Apache Tomcat Servlet?
JDebugTool can debug Tomcat Servlets. How to configure Tomcat to support
remote debugging, depends on how you start Tomcat:
-
You can start Tomcat using catalina jpda start as follows:
First make sure you have defined the environment variable JAVA_HOME to point to
the root directory where you have the JDK installed. Then simply invoke on Windows
$CATALINA_HOME/bin/catalina.bat jpda start
or on Unix®
$CATALINA_HOME/bin/catalina.sh jpda start
The default transport of dt_shmem on Windows, and dt_socket
on Unix can be changed by defining the JPDA_TRANSPORT environment variable.
Also the default address of jdbconn on Windows, and 8000
on Unix can be changed by defining the JPDA_ADDRESS environment variable.
-
If you run Tomcat using a service wrapper, add for example, the following
remote debugging JVM options before any other JVM options
(check the documentation for the service):
-agentlib:jdwp=transport=dt_socket,server=y,address=8000
Then in JDebugTool, select Attach... from the Target menu in the menubar, to display the
Attach to Target dialog. If using the shared memory transport,
select the Shared Memory tab, and enter
jdbconn in the Shared Memory Name field. If using the socket transport, select the
Socket tab, and enter 8000 in the Port Number field. If you are debugging
Tomcat remotely (on a different computer) also enter the Host Name field with
the hostname or IP address of the computer where Tomcat is running.
Finally click on the OK button in the Attach to Target dialog in JDebugTool.
You should now be attached to Tomcat, and ready to debug.
-
How to debug an Apache Tomcat 5.0 JSP?
You can indirectly debug a Tomcat 5.0 JSP, by generating the corresponding
Java source file, and then Mounting the corresponding Source Path in
JDebugTool.
First you will need to attach JDebugTool to Tomcat as described in
How To #6 above. Then you will need to
invoke your JSP to determine where the generated Java source file is created.
For example, you would then Mount the following Source Path (see
FAQ #1):
$CATALINA_HOME/webapps/mywebapp/WEB-INF/classes
where mywebapp would be the corresponding name of your web app.
You are now ready to debug the generated Java source file as usual.
-
How to debug a JSP (Java Server Pages)?
You can indirectly debug a JSP by saving the generated Java source code of the JSP
and mounting the generated Java source code in JDebugTool (see
FAQ #1).
See also How To #7
How do I debug an Apache Tomcat 5.0 JSP?
-
How to debug an Applet?
Basically you need to attach (see the Target | Attach... menu
item from the menubar, and the resulting Attach Dialog) to the Java Plugin.
See Applet Debugging Support from Sun, for
JDK 1.6,
JDK 1.5 or
JDK 1.4,
on how to configure the Java Plugin to support debugging (and being attached to by JDebugTool).
|