FeaturesPluginsDocs & SupportCommunityPartners

Overview of Selected Features

The NetBeans debugger is a multisession, multithreaded, multilanguage debugger. In addition to providing features that are standard to all debuggers--single stepping, breakpoints, and watches--the NetBeans debugger provides the following features:

Remote debugging
Expression evaluation
Advanced breakpoints
Variable and expression evaluation in the Source Editor
Multisession debugging
Multithreaded debugging
Run Into Method Action

Remote Debugging
Remote debugging enables you to connect the debugger to a Java application that is already running and to inspect the state of that application. An advantage of remote debugging is performance. For example, you can attach the debugger to a server, find bugs in the server, fix the bugs using the Fix & Continue command, and then disconnect the debugger from the server.

To attach the debugger to an application, the application must be running in debug mode. The application can run on a different version of the Java Virtual Machine (JVM) or on a different computer than the IDE. See VM Options for Running Applications in Debugging Mode for more information.

Different debugger implementations support different connectors. For example, the JPDA debugger implementation provides a socket transport on both Solaris and Win32 platforms and a shared memory transport on the Win32 platform.

Following is a snapshot of the Attach to VM dialog box, which you use to attach the debugger to a running application.

Attach Dialog


Expression Evaluation
The NetBeans debugger uses an expression evaluator to evaluate Java-syntax expressions assigned to watches and conditional breakpoints. The evaluation is performed according to the context given by the current thread. The input to the evaluator is a string (Java-syntax expression). The expression can contain local variables, fields of the current object, static fields, and method calls. You can create a new instance of an object and call its methods. All class names must be fully qualified (such as java.lang.System).

Following is a snapshot of the New Watch dialog box, which uses the expression evaluator.

Add Watch Expression


Advanced Breakpoints
In addition to the standard line and method breakpoints, the NetBeans debugger provides the following types of advanced breakpoints:

  • Class breakpoint
    You can set a breakpoint on a class and trigger the breakpoint when the class is loaded into the virtual machine, unloaded from the virtual machine, or both. This enables you to watch when the first class is loaded from a package (such as java.lang.*).

  • Thread breakpoint
    You can set a breakpoint on a thread and trigger the breakpoint when the thread starts, stops, or both. This feature enables you to detect how many threads are running and from where they started.

  • Exception breakpoint
    You can set a breakpoint on an exception and trigger the breakpoint when the exception is caught, when the exception is not caught, or on all exceptions. This breakpoint type enables you to monitor where and when an exception from a specific package (for example, com.myApp.*) is thrown or caught.

  • Variable breakpoint
    You can set a breakpoint on a variable and trigger the breakpoint when your program queries a variable in the specified class and field or when the value of the variable changes. This feature enables you to detect which part of your code accessed a specific variable or set an invalid value in a field.
Following is a snapshot of the New Breakpoint dialog box, which you can use to create a breakpoint.

New Breakpoint Dialog


Variable and Expression Evaluation in the Source Editor
In the IDE, you can evaluate a variable directly in the Source Editor by moving the pointer over the variable. If the variable is active in the current context, the value of the variable is displayed in a tool tip. In cases where a program includes different variables with the same name, the Source Editor displays the value based on the current context, and not on the instance of the variable in the source code. The debugger must be paused on a breakpoint or otherwise stopped in order to evaluate an expression.

Following is an example of a tool tip in the Source Editor.

Tooltips  


Multisession Debugging
The NetBeans debugger is able to debug several processes at the same time.  You start a session by selecting the main class in the NetBeans Explorer and choosing the desired debugging command on the toolbar. A list of the currently running debugging sessions is maintained in the Sessions view of the Debugger window. One session is the current session, unless no sessions are running.

Most views in the Debugger window depend on the current session. For example, the Threads view shows the threads in the current session, while the Call Stack view shows the call stack for the current thread. The Local Variables view shows the variables that are local to the current call, and the Classes view shows the classes that have been loaded by the current session. The Breakpoints and Watches view are shared by all sessions.

You finish a session by using the Finish command on the Debug menu or on the contextual menu in the Sessions View. Following is a snapshot of the Sessions View.

Sessions View


Multithreaded Debugging
All the threads created in the current session are displayed in the Threads view in the Debugger window. The information given for each thread includes the current state of the thread. Using the contextual menu in the Threads view, you can manage threads as follows:
  • Change the current thread
  • Suspend execution of a thread if you think it is causing problems and then later resume the thread once the problem is solved
  • View the thread's current location in the Source Editor
You can inspect the call stack and locale variables of the current thread in the Call Stack and Local Variables views. Following is a snapshot of the Threads View.

Threads View  


Run Into Method Action
It is possible to step into a selected method within a series of nested (chained) method calls. While debugging, user can select a method call with cursor and invoke RunIntoMethod action. In the following piece of code, action steps directly into init method:

Classes View


Companion
Projects:
MySQL Database Server   Open JDK: an Open SourceJDK   GlassFish Community: an Open Source Application Server    Mobile & Embedded Community    Open Solaris   java.net - The Source for Java Technology Collaboration   Virtual Box - full virtualizer  Open ESB - The Open Enterprise Service Bus Powered by