Tools Guide



Chapter 12   SilverStream Debugger

The SilverStream Debugger lets you find and fix runtime errors in your Java applications by controlling and monitoring the execution of Java source code. You can debug client-side and server-side objects, either on a local host machine or remotely on distributed machines.

You can also run the Debugger as a standalone tool for debugging any Java application, even if the application was developed outside the SilverStream environment.

Here is a sample Debugger window, showing many of its features:

This page describes the following:

Concepts you need to know   Top of page

You should review the following concepts before you use the Debugger.

Breakpoints   Top of page

A breakpoint is a specific line in your code where you want execution to stop temporarily. When you set a breakpoint in code, the program stops running before executing the line containing the breakpoint, then turns control over to the Debugger.

Deadlock   Top of page

Deadlock occurs when two or more threads have locks on different objects, but are waiting for one of the other locked objects to free up. Since the threads are waiting for each other to complete and release their locks, none of the threads can run.

Instance variables   Top of page

An instance variable occurs in every instance of a specific created class. It is a non-static variable.

Local variables   Top of page

A local variable is declared inside a particular method. Only code that is contained in the method can access a local variable.

Monitor   Top of page

In Java, a monitor is an exclusive lock on an object. Locks are used in thread synchronization.When methods are programmed to be synchronized, they cannot run concurrently. When a synchronized method is entered, it acquires a monitor on the current object (the object whose method was called). The monitor prevents other synchronized methods in the object from executing. When the synchronized method returns, its monitor is released, allowing other synchronized methods in the same object to run.

Threads   Top of page

A thread is a single execution stream in a program. Java is a multi-threaded language which means that you can have several execution streams operating at one time. In Java threads are represented by the Thread object.

What you can do with the Debugger   Top of page

The SilverStream Debugger provides you with the following capabilities for diagnosing and correcting problems with your Java applications:

Local and Remote Debugging   Top of page

With the SilverStream Debugger you can troubleshoot Java applications running on a local host or remotely in a distributed network. You can configure a process to be debugged either on the local machine or on the remote machine, but not for both in the same session.

There are many situations that require remote debugging. Here are examples of scenarios you might encounter:

For more information about how to debug applications locally or on remote machines, see Launching the Debugger from the Programming Editor and Launching the Debugger as a standalone tool.

Using the Debugger   Top of page

The SilverStream Debugger is a versatile tool. You can invoke the Debugger for local or remote debugging, either from the Programming Editor in the SilverStream Designer or as a separate process. When deciding how to use the Debugger to meet your specific needs, consider these questions:

Do you want to design and debug your Java application in one integrated environment?

If the answer is yes, you can develop your application using the SilverStream Designer and then start up the Debugger from the Programming Editor. Because the Debugger is tightly integrated with the Programming Editor, you do not need to explicitly load source files. The Debugger can locate your source code automatically. You can also switch easily between design mode and debug mode to modify source code and test your changes.

You can perform local or remote debugging when you run the Debugger from the Programming Editor in the Designer.

See Launching the Debugger from the Programming Editor.

Are your Java applications developed outside the SilverStream environment?

If you want to debug externally-developed Java applications, you must invoke the Debugger as a standalone process. When running standalone, the Debugger can be configured either to start up the application on the local machine, or attach to an application that is already running on a local host or on a remote machine.

See Launching the Debugger as a standalone tool.

Do you want to invoke the Debugger quickly for a short debugging session?

If expediency is important, invoke the Debugger is as a standalone process (thereby bypassing the Designer).

See Launching the Debugger as a standalone tool.

Typical work flow for debugging   Top of page

Although each debugging session poses its own unique challenges, you would typically follow this work flow when you are ready to troubleshoot your application:

Locating source code for pre-built applications   Top of page

When you are debugging pre-built applications that reside in databases you have added to your server, you need to give the Debugger local access to the source code. SilverStream provides a local compile cache directory where the SilverStream Designer stores source and class files when compiling Java code.Typically named compilecache, this directory is located in your root SilverStream installation directory.

There are two ways to load an application's source code and class files to the compilecache directory:

For more information about the compile cache, see the section on compiling in How you'll work in the Programmer's Guide.

When the Debugger cannot locate source code   Top of page

When the Debugger cannot locate source code for a particular operation, it prompts you to provide the path to the source file. Either provide the path, or dismiss the prompt and follow directions to either continue execution or step out of the current method.

Launching the Debugger from the Programming Editor   Top of page

If you are debugging applications developed in the SilverStream Designer, you probably want to invoke the Debugger from the Programming Editor. Here are the steps to follow:

  1. Start the SilverStream Application Server using one of these methods:

    To debug:

    Do this:

    Server objects

    Start the Server in debug mode for local debugging or remote debugging

    Client objects only

    Start the Server as you normally would.

  2. Set up the Designer to record debugging information in your compiled Java code.

  3. Start the Debugger from the Programming Editor by setting breakpoints and running your application.

This section describes each of these procedures.

To start the Server for local debugging:

To start the Server for remote debugging:

To set up the Designer to record debugging information in compiled Java code:

  1. In the Designer, select Preferences in the Edit menu.

  2. Select the Compiler tab in the Preferences dialog.

  3. Select the Include Debugging Information checkbox.

  4. Click OK.

To start the Debugger from the Programming Editor:

  1. In the SilverStream Main Designer, open the client or server object you wish to debug.

    For example, if you want to debug a Page, select Pages in the desired database in the left pane, highlight the page name in the right pane, and either double-click it or choose the Design action icon:

  2. In the Business Object Designer, open the Programming Editor.

    If you are debugging a form, you can set breakpoints only if you are programming in Java mode. Breakpoints are not available if you are using Simple Actions mode. To enter Java mode, select the Java mode icon:

  3. Set one or more breakpoints in your source code.

  4. Start the application.

    If you are debugging objects that can run standalone--such as forms and pages--you can invoke them from the Designers or Programming Editor. Follow these steps:

    To run:

    Do this:

    Forms

    With the form open the Form Designer or Programming Editor, select the Enter Test Mode icon:

    Pages

    Select either of these methods to run pages to trigger the Debugger:

    • With the page open in the Page Designer or Programming Editor, select the Enter Test Mode icon:

    • In the Main Designer, select the page in the right pane and then select the Run icon:

  5. Interact with the application to trigger the desired code.

The Debugger is launched when the application reaches the first breakpoint. You will see a Debug window that highlights where execution stops in the source code, call stack, and threads, as in this example:

This window also presents options for managing program execution and analyzing the behavior of the application. For example, this Debug window displays local variables, the call stack, and thread status.

Launching the Debugger as a standalone tool   Top of page

If you are debugging applications developed outside the SilverStream environment, you must invoke the Debugger as a standalone process. When you run the Debugger standalone, you can configure it to either start the application you wish to debug on the local machine, or attach it to an application that is already running either locally or on a remote machine. In either case, you use the SilverDebugger command.

This section describes how to call SilverDebugger to start applications and to attach to running applications.

SilverDebugger command   Top of page

Launches the SilverStream Debugger as a standalone process. You must specify different options and arguments when you want to start up an application from the Debugger than when you want to attach the Debugger to an application that is already running.

When starting up an application from the Debugger

Syntax

  SilverDebugger [options] class arguments 

options

You can specify the following options when starting up a Java application to debug on a local host or remote machine:

class

Name of the class that contains the main() entry point to the application.

arguments

Arguments to pass to the main() method of class. Typically, arguments are separated by spaces.

When attaching the Debugger to a running application

Syntax

  SilverDebugger -attach [hostname debug_address | hostname:debug_port] 

options

You must specify one of the following options to attach the Debugger to a Java application already running on a local host or remote machine.

Option

Description

-attach hostname debug_address

Attach to the JVM running on the local host hostname with address debug_address.

-attach hostname:debug_port

Attach to the JVM running on remote machine hostname using port debug_port.

Using the Debugger to start your application   Top of page

This section describes how to use the SilverDebugger command to invoke the Debugger as a standalone tool and have it start the application you wish to debug.

To invoke the standalone debugger to start your application:

  1. Call SilverDebugger on a Windows NT command line as follows:

      SilverStream_installation_directory\bin\SilverDebugger.exe [options] class class_arguments 
    

    Here is a description of each argument:

    Argument

    Description

    options

    Options passed to Debugger:

    • -sourcepath list of directories separated by semicolons--Directories in which to look for source files.

    NOTE   The directories must be source tree roots.

    • -sourcefile filename--Java source file for the Debugger to open.

    • -?--Display usage information.

    NOTE   If your source and class files reside on remote network machines, provide these paths to SilverDebugger in Universal Naming Convention (UNC) format:

      \\server-name\shared-resource-pathname 
    

    Options passed by Debugger to application:

    • -classpath list of directories separated by semicolons-- Directories in which to search for Java classes, separated by semicolons.

    • -Dname=value--System property setting.

    • -Xoption--JVM option

    class

    Name of the class to debug.

    class_arguments

    Arguments to pass to the main() method of class

    The Debugger starts up on your desktop and opens the Java source file you specified on the command line.

    Example:

    To debug a form whose source code resides in c:\dev\source\mypackage\frmQuery.java in the application myApp.class located in c:\apps\myApp.jar, enter this command:

      SilverStream_installation_directory\bin\SilverDebugger.exe -sourcepath c:\dev\source -sourcefile c:\dev\source\mypackage\frmQuery.java -classpath c:\apps\myApp.jar mypackage.myApp 
    
  2. Set one or more breakpoints in your code or in exceptions.

  3. Select Continue from the Tools menu or click the Continue icon in the toolbar of the Debugger window:

    The application opens on your desktop and execution stops at the first breakpoint encountered.

Now you are ready to manage program execution and analyze the behavior of your application.

Attaching the Debugger to a running Java application   Top of page

This section describes how to attach the Debugger to a Java application that is already running. You can attach to an externally-developed Java application or attach to a SilverStream Java application.

Attaching to an external Java application

When you attach the Debugger to an external Java application, you must pass a number of option settings to the Java Virtual Machine (JVM) when you start up the application. This section describes these options and procedures.

To attach the Debugger to an external Java application:

  1. Add the following directory to your Path environment variable:

      SilverStream_installation_directory\jre\bin 
    
  2. Launch the Java application either on the local host or on a remote machine, as described:

    To launch the application on the local host, follow these steps:

  3. Invoke the Debugger using the appropriate SilverDebugger command:

    For:

    Type this command:

    Local debugging

      SilverDebugger.exe -attach localhost debug_address 
    

    NOTE   debug_address is the address returned by the JVM when you launch your Java application for local debugging.

    Example:

      SilverDebugger.exe -attach localhost javadebug 
    

    Remote debugging

      SilverDebugger.exe -attach machine_name:debug_port 
    

    NOTE   debug_port is the port number returned by the JVM when you launch your application for remote debugging.

    Example:

      SilverDebugger.exe -attach mymachine:1084 
    

    The Debugger opens on your desktop.

  4. Open a source file for debugging by selecting Open from the File menu.

Now you are ready to manage program execution and analyze the behavior of your application.

Attaching to a SilverStream Java application

When you attach the Debugger to a SilverStream executable, such as SilverServer.exe and SilverJRunner.exe, you need only pass debugger options. The correct JVM option settings are automatically generated. This section describes these debugger options and procedures.

Debugger options

This section describes the debugger options to use when launching SilverStream applications that you want to attach to the standalone Debugger. Some of these options override default settings, described in Default debug port and debug addresses.

Option

Description

+debug

Starts a SilverStream executable for local debugging, using a default debug address.

You can specify these suboptions for local debugging:

  • +debug:suspend=y -- Suspends the JVM at start-up. You use the Continue command in the Debugger to resume execution. This option is helpful if you want to debug initialization code that would normally get executed before the Debugger is attached.

  • +debug:suspend=n -- Does not suspend the JVM at start-up. This is the default.

  • +debug:address=debug_address -- Starts the application using debug_address instead of the default debug address.

+debug:port=port_num

Starts a SilverStream executable for remote debugging using port_num instead of the default debug port 9901. Use this command if port 9901 is not available.

+debugremote

Starts a SilverStream executable for remote debugging using the default debug port 9901.

NOTE   You cannot specify +debug:address and +debug:port on the same command line because one option is for local debugging and the other is for remote debugging.

Default debug port and debug addresses

Here are the default debug ports and debug addresses for SilverStream executables:

Default option

Description

agjrn

Default debug address for SilverJRunner.exe

agsrv

Default debug address for SilverServer.exe

9901

Default debug port for SilverJRunner.exe and SilverServer.exe

These default options are used when attaching the Debugger to a SilverStream application.

To attach the Debugger to a SilverStream application:

  1. Launch the SilverStream application, as described:

    To launch the application for debugging client objects:

  2. Invoke the Debugger using the appropriate SilverDebugger command:

    For:

    Type this command:

    Local debugging

      SilverDebugger.exe -attach localhost debug_address 
    

    Example: Attaching the Debugger to a running SilverJRunner:

      SilverDebugger.exe -attach localhost agjrn 
    

    Example: Attaching the Debugger to a running SilverServer:

      SilverDebugger.exe -attach localhost agsrv 
    

    Remote debugging

      SilverDebugger.exe -attach machine_name:debug_port 
    

    Example:

      SilverDebugger.exe -attach mymachine:9901 
    

    NOTE   agjrn and agsrv are default debug addresses, and 9901 is the default debug port, as described in Default debug port and debug addresses.

    The Debugger opens on your desktop.

  3. Open a source file for debugging by selecting Open from the File menu.

Now you are ready to manage program execution and analyze the behavior of your application.

Managing program execution   Top of page

The Debugger offers several ways to manage program execution to allow you to isolate, diagnose, and fix problems in the source code:

Using breakpoints   Top of page

You use breakpoints to specify lines in your code where you want to stop execution and give control to the Debugger. When the source code stops executing and the Debugger takes control, you can execute Debugger commands, and view the call stack, thread status, and variable values.

You can set breakpoints only on individual lines in your code. If a line contains multiple statements, you can set a breakpoint only on the first statement in the line. To set breakpoints on the subsequent statements, you need to break up the line so that each statement appears on its own line.

How breakpoints are stored

Breakpoints are stored by server name and class name. As a result, objects share breakpoints in the following circumstances:

In these scenarios, breakpoints set in one object will automatically appear in the other related objects and, conversely, breakpoints removed from one object will automatically disappear from the other related objects. If you debug objects that share breakpoints in this way--but contain different versions of code--the results might be unpredictable. To avoid potential problems, it is best not to run or debug different versions of the same application on the same server.

Setting and removing breakpoints in code

There are several ways to set and remove breakpoints in code, either for local classes or classes loaded from external sources. If the Debugger cannot find the source code, it prompts you for a path, as described in When the Debugger cannot locate source code.

This section describes the procedures for setting and removing breakpoints in source code.

To set breakpoints in code using Toggle Breakpoint:

  1. Position your cursor at the line in your source code where you want to set a breakpoint.

  2. Either choose Toggle Breakpoint from the Tools menu or select the Toggle Breakpoint icon in the Debugger toolbar:

    The breakpoint indicator appears in the left margin next to the line you specified.

To set breakpoints in code using the Edit menu:

  1. Select Show Line Numbers from the Edit menu to make it easier to specify locations for breakpoints.

  2. Choose Breakpoints from the Edit menu.

    The Manage Breakpoints dialog opens.

  3. Select the Code tab and choose the Add button.

    The Add Breakpoint dialog opens, showing all breakpoints that exist in the source code for the Java class.

  4. Choose one of these options:

    To insert a breakpoint in:

    Do this:

    Your local Java class

    1. In the Specify Breakpoint field, enter the location where you want to add a breakpoint, in this form:

      <fully-qualified class name>:<line number>

      Example:

      com.sssw.gen.pages.pgShoppingBasket:99

    2. Click OK.

    Loaded classes

    1. Choose the Browse button.

    2. Navigate to the method where you want to insert a breakpoint and click OK.

      The breakpoint specification appears in the Specify Breakpoint field.

    The new breakpoint appears in the Manage Breakpoints dialog.

  5. Click Done to add the breakpoint to the source code.

To remove individual breakpoints using Toggle Breakpoints:

  1. Click your cursor in a line that already has a breakpoint

  2. Select the Toggle Breakpoint icon in the Debugger toolbar

To remove breakpoints using the Edit menu:

  1. Choose Breakpoints from the Edit menu.

    The Manage Breakpoints dialog opens.

  2. Select the Code tab and click to select the breakpoints you wish to remove.

  3. Choose the Delete button.

    The breakpoints disappear from the list in the Manage Breakpoints dialog.

  4. Click Done.

    The breakpoints disappear from the source code.

To remove all breakpoints:

Setting and removing breakpoints in exceptions

In addition to setting breakpoints in the main body of source code in your Java applications, you can also set breakpoints in standard Java exceptions or in exceptions that you write to handle specific behaviors.

This capability can help you pinpoint the source of exceptions that are thrown unexpectedly when you run your application. When you set a breakpoint in an exception and then run your application, the Debugger will stop where the exception gets thrown and display the offending source code if it is available for the class you are debugging. If the Debugger cannot find the source code, it prompts you for a path, as described in When the Debugger cannot locate source code.

To set breakpoints in exceptions:

  1. Choose Breakpoints from the Edit menu.

    The Manage Breakpoints dialog opens.

  2. Select the Exception tab and choose the Add button.

    The Add Exception Breakpoint dialog opens.

  3. Type the fully-qualified name of the exception class on which you want to break.

  4. Click OK to return to the Manage Breakpoints dialog.

    The new breakpoint appears in the Manage Breakpoints field.

  5. Click Done.

    NOTE   Exception breakpoints do not appear in the source code.

To remove breakpoints from exceptions:

  1. Choose Breakpoints from the Edit menu.

    The Manage Breakpoints dialog opens.

  2. Select the Exception tab and click to select the breakpoints you wish to remove.

  3. Choose the Delete button.

    The breakpoints disappear from the list in the Manage Breakpoints dialog.

  4. Click Done.

Enabling and disabling breakpoints

The Debugger allows you to enable and disable breakpoints in code and exceptions. Disabled breakpoints appear with a grayed icon:

To enable breakpoints:

  1. Select Breakpoints from the Edit menu.

    The Manage Breakpoints dialog opens.

  2. Select the Code or Exception tab to locate the breakpoints you wish to enable.

  3. Click to highlight the breakpoints you wish to activate and select the Enable button.

    You can select multiple breakpoints by holding down the Control key or Shift key when you click each choice.

  4. Click Done.

    The breakpoints you select will be enabled when you continue program execution.

To disable breakpoints:

  1. Select Breakpoints from the Edit menu.

    The Manage Breakpoints dialog opens.

  2. Select the Code or Exception tab to locate the breakpoints you wish to disable.

  3. Click to highlight the breakpoints you wish to activate and select the Disable button.

    You can select multiple breakpoints by holding down the Control key or Shift key when you click.

  4. Click Done.

    The breakpoints you select will be disabled when you continue program execution.

Continuing execution   Top of page

The Debugger offers several ways to continue execution after the program stops at a breakpoint:

When a breakpoint is reached, the Debugger window is activated and an arrow appears in the margin to the left of the code indicating which line is about to be executed. This arrow is known as the execution pointer.

Along with the execution pointer, the Debugger displays a list of local and instance variables and enables the commands for stepping through your code.

To start or continue execution:

To run to a specified location in the source code:

  1. Click the cursor in the line of code where you want execution to stop.

  2. Select Run to Cursor from the Tools menu or click the Run to Cursor icon in the toolbar of the Debugger window:

    Run to Cursor executes your code from the current execution location until it reaches the place where your cursor is located. The cursor must be located on a line that contains executable statements. If you have breakpoints set and a line containing a breakpoint is executed before the line that has the cursor, Run to Cursor stops execution at that breakpoint line.

    NOTE   If you place your cursor on a line that doesn't get executed -- for example, if your cursor is on the first line of code inside an if statement when the if condition evaluates to false -- the effect of executing Run to Cursor will be the same as if you select the Continue command.

Stepping through the code   Top of page

There are several Step commands included in the SilverStream Debugger:

Analyzing the behavior of the application   Top of page

The Debugger allows you to examine the current execution state when the Debugger stops at a breakpoint, following a Step command, and when you suspend and resume threads. You can view the following information:

Viewing the call stack   Top of page

The Debugger provides a viewer that lets you examine the call stack during program execution. The call stack viewer shows the name of each method in the stack, along with its source file and line number.

When you double-click on a method in the call stack viewer, the source file opens in the Debugger, highlighting the line where the method is called. If the Debugger cannot find the source file, it prompts you for a path, as described in When the Debugger cannot locate source code.

The call stack viewer updates the call stack when:

To open the call stack viewer:

Viewing threads   Top of page

The Debugger provides a viewer that lets you examine the status of threads during program execution. The thread viewer displays threads organized by groups, showing the name of each thread, along with its identifier and state.

You can suspend and resume threads to isolate problems that occur in thread synchronization, such as deadlocks and infinite loops.

The thread viewer updates thread status when:

To open the thread viewer:

Thread states

Threads can exhibit a variety of states during program execution:

Thread state

Description

At breakpoint

Thread was running when execution stopped at the breakpoint.

Running

Thread is running.

Sleeping

Thread is sleeping for a specified period of time.

Suspended

Thread is suspended.

Waiting

Thread is waiting for notification to resume running.

Waiting on monitor

Thread is waiting for a monitor to be released by another thread.

NOTE   In a deadlock situation, you will see two or more threads in this state. However, threads that appear in this state do not necessarily indicate a deadlock.

Suspending and resuming threads

If you encounter an infinite loop or deadlock in a thread, you can isolate the problem by suspending the thread and viewing its call stack. You cannot view the call stack of a thread unless it is suspended.

To suspend a thread and view its call stack:

  1. Open the thread and call stack viewers.

  2. Choose one of these options:

    To suspend:

    Do this:

    All threads

    Follow these steps:

    1. Stop execution of your code at a breakpoint.

    2. Click to select the suspended thread.

    An individual thread

    Double-click a running or waiting thread in the thread viewer.

    The call stack for the selected thread appears in the call stack viewer.

  3. Double-click on methods in the call stack to view their code in the Debugger.

    If the Debugger cannot locate the source code for a method you selected, it will prompt you to supply a path, as described in When the Debugger cannot locate source code.

NOTE   If you double-click on a waiting thread, the method that put the thread in a wait state appears in the call stack viewer.

To resume a thread:

Viewing variables   Top of page

The Debugger provides a viewer that lets you examine local and instance variables when program execution stops at a breakpoint. The variable viewer displays the variable name, type, and value.

The variable viewer updates variable values when:

To open the variable viewer:

  1. In the Debugger, choose Variables from the View menu.

    A pane for viewing variables appears in the Debugger window.

  2. Select the locals button to view local variables and the this button to view instance variables for the current object.

Modifying your Java source code   Top of page

If you run the Debugger from the Programming Editor in the SilverStream Designer, you can easily switch between a debugging session and code editing session. Once you finish inspecting your code using the Debugger, you can return to the Programming Editor to modify the code for the class you are debugging.

Debugger keyboard shortcuts   Top of page

Use these keyboard shortcuts.

Keystroke

Description

Ctrl+C

Copy to Clipboard

Ctrl+G

Go to line number

Ctrl+F

Find/Replace

F5

Continue

F10

Step over

F11

Step in

Shift+F11

Step out

Ctrl+F10

Run to cursor






Copyright © 2000, SilverStream Software, Inc. All rights reserved.