Oracle® Solaris Studio 12.4: Debugging a Program With dbx

Exit Print View

Updated: January 2015
 
 

Specifying a Custom Wrapper for Your Java Application

A Java application can use a custom wrapper for startup. If your application uses a custom wrapper, you can use the jvm_invocation environment variable to specify the wrapper to be used, as shown in the following example.

jvm_invocation="/export/siva-a/forte4j/bin/forte4j.sh -J-Xdebug"

This example causes dbx to start the JVM software as follows:

/export/siva-a/forte4j/bin/forte4j.sh - –agentlib:dbx_agent=sync=process-ID

Using a Custom Wrapper That Accepts Command-Line Options

The following wrapper script (xyz) sets a few environment variables and accepts command line options.

#!/bin/sh
CPATH=/mydir/myclass:/mydir/myjar.jar; export CPATH
JARGS="-verbose:gc -verbose:jni -DXYZ=/mydir/xyz"
ARGS=
while [ $# -gt 0 ] ; do
    case "$1" in
        -userdir) shift; if [ $# -gt 0 ]
; then userdir=$1; fi;;
        -J*) jopt=`expr $1 : ’-J<.*>’`
; JARGS="$JARGS ’$jopt’";;
        *) ARGS="$ARGS ’$1’" ;;
    esac
    shift
done
java $JARGS -cp $CPATH $ARGS

This script accepts some command-line options for the JVM software and the user application. For wrapper scripts of this form, you would set the jvm_invocation environment variable and start dbx as follows:

% jvm_invocation="xyz -J-Xdebug -J other-java-options"
% dbx myclass.class -Dide=visual

Using a Custom Wrapper That Does Not Accept Command-Line Options

The following wrapper script (xyz) sets a few environment variables and starts the JVM software, but does not accept any command-line options or a class name.

#!/bin/sh
CLASSPATH=/mydir/myclass:/mydir/myjar.jar; export CLASSPATH
ABC=/mydir/abc; export ABC
java <options> myclass

    You could use such a script to debug a wrapper using dbx in one of two ways:

  • Modify the script to start dbx from inside the wrapper script itself by adding the definition of the jvm_invocation variable to the script and starting dbx.

    #!/bin/sh
    CLASSPATH=/mydir/myclass:/mydir/myjar.jar; export CLASSPATH
    ABC=/mydir/abc; export ABC
    jvm_invocation="java -Xdebug <options>"; export jvm_invocation
    dbx myclass.class

    Once you have made this modification, you could start the debugging session by running the script.

  • Modify the script slightly to accept some command-line options as follows:

    #!/bin/sh
    CLASSPATH=/mydir/myclass:/mydir/myjar.jar; export CLASSPATH
    ABC=/mydir/abc; export ABC
    JAVA_OPTIONS="$1 <options>"
    java $JAVA_OPTIONS $2

    Once you make this modification, you would set the jvm_invocation environment variable and start dbx as follows:

    % jvm_invocation="xyz -Xdebug"; export jvm_invocation
    % dbx myclass.class