|Oracle® Java Micro Edition Embedded Client Developer's Guide
This chapter describes how to debug an application with the NetBeans integrated development environment (IDE).
This chapter includes these topics:
You can remotely debug a CDC application with most debuggers that support the Java Virtual Machine Tool Interface (JVMTI) described in
http://download.oracle.com/javase/6/docs/platform/jvmti/jvmti.html. The most likely choices are the NetBeans, Oracle JDeveloper, and Eclipse integrated development environments, but you can also use the Java SE
jdb command line debugger or another compatible debugger. You run the debugger on a development host, and the application plus CDC on the target device. CDC and the debugger communicate over a network.
CDC debugging has the following limitations:
Only interpreted code can be debugged.
CDC-debugger connections must use sockets. Shared memory connections are not supported.
cvmin Debug Mode
Regardless of the debugger you choose, you launch
cvm running the application in the same way.
With the Oracle Java ME Embedded Client, cvm is installed on your system in the following location:
cvmDebug Mode Syntax
Example 3-1 and Example 3-2 show how to launch
cvm in debug mode on a target device. These examples assume that the target device runs a Unix-style operating system and that socket networking is operational. Make adjustments as necessary for your target device. Use nfs networking if available to mount the workstation directory containing the compiled classfiles on the target device. Or, copy the classfiles from the workstation to the device using ftp or scp.
Be sure to set up the environment variables correctly before running cvm. For example,
Chose the appropriate command syntax and sub-options to launch
cvm in debug mode.
For the appropriate command syntax and a list of debug sub-options, run
cvm Listens for Connection from Debugger
% cvm -agentlib:jdwp=transport=dt_socket,server=y,address=port -Xdebug \ -classpath $CLASSPATH $CLASSNAME
cvm Connects to Debugger
% cvm -agentlib:jdwp=transport=dt_socket,server=n,address=host:port -Xdebug \ -classpath $CLASSPATH $CLASSNAME
cvm in debug mode, observe the following requirements:
-agentlib:jdwp and the
address sub-options must be specified.
transport value must be
y to direct
cvm to listen for a connection from the debugger (the most likely case). Set
n to direct
cvm to attach to a listening debugger.
server=y, set port to the socket port on the target host at which
cvm listens for a connection. If
server=n, set host:port to the host and socket port at which the debugger waits for a connection from
-Xdebug disables the compiler so the virtual machine interprets the application's bytecodes.
cvmDebug Mode Example
Example 3-3 shows a simple example of launching
cvm as a server to debug a
Although this section describes the NetBeans debugger, other IDE debuggers that are compatible with the Java Virtual Machine Tool Interface (JVMTI) can be used similarly. This section first describes the most common arrangement in which
cvm acts as a server for the debugger, then the converse case.
Load the NetBeans project you want to debug and create a debugger operation, such as a breakpoint. Figure 3-1 shows an example.
Ensure that the project's compiled class files are accessible to the target host and that the class files correspond to the source files loaded in the IDE.
Figure 3-1 Breakpoint in
On the target host, launch
server=y and, for this example,
address=8000, similar to the example in Section 3.2.2, "
cvm Debug Mode Example".
In NetBeans, choose Debug > Attach Debugger.
Set up the Attach Debugger dialog as shown in Figure 3-2.
Substitute the target host name for (Target Host).
Figure 3-2 Attach Debugger Dialog (Debugger as Client)
The debugger connects and indicates that execution has stopped at the breakpoint as similar to Figure 3-3.
Figure 3-3 Debugger Connected and Stopped at Breakpoint
If you want the debugger to be the server, complete the Attach Debugger dialog similar to Figure 3-4. After clicking OK, launch
cvm on the target host with
address= the debuggers' host and port.
Figure 3-4 Debugger as Server Attach Debugger Setup
cvm as a debug server (see Section 3.2.2, "
cvm Debug Mode Example") on the target host, you can connect to it with the
jdb command line debugger using syntax similar to Example 3-4. The
jdb command is in JavaSEinstall