docs/reference-manual/native-image/JDWP.md
This document describes the Java Debug Wire Protocol (JDWP) debugging support for Native Image, a feature that enables debugging of native images using standard Java tooling.
The JDWP feature relies on a shared library, which is loaded only when the debugger is actively used. This library must be built once before building native images with JDWP enabled.
native-image --macro:svmjdwp-library
Note: This is a one-time setup step. The same library will be used for all native images built with JDWP enabled.
Note: This library is stored in the GraalVM installation by default. If that directory is not writable, provide an alternative destination path with
-o <path/to/writable/directory>/libsvmjdwp, or on Windows, use-o <path\\to\\writable\\directory>\\svmjdwp.
Note: JDWP debugging for Native Image is experimental.
To include JDWP support in a native image, add the -H:+JDWP option to your native-image command:
native-image -H:+UnlockExperimentalVMOptions -H:+JDWP ... -cp <class/path> YourApplication ...
This command produces:
<image-name>.metadata filelib:svmjdwp (libsvmjdwp.so, libsvmjdwp.dylib or svmjdwp.dll) shared library that will be necessary when debugging is also copied next to those files.To launch the native image in debug mode, use the -XX:JDWPOptions= option, similar to HotSpot's -agentlib:jdwp=:
./your-application -XX:JDWPOptions=transport=dt_socket,server=y,address=8000
Note: Debugging requires the image-name.metadata file generated at build time and the
svmjdwpshared library in the same directory as the native executable.
For a complete list of supported JDWP options on Native Image, run:
./your-application -XX:JDWPOptions=help
Native Image supports additional non-standard JDWP options:
mode=native:<path>: Specifies the path to the svmjdwp library. This can be:
lib:svmjdwplib:svmjdwplib:svmjdwp in the lib or bin directoryIf no path is specified, lib:svmjdwp is searched for beside the native executable.
Examples:
-XX:JDWPOptions=...,mode=native:<path/to/lib:svmjdwp>
-XX:JDWPOptions=...,mode=native:<path/to/directory/containing/lib:svmjdwp>
-XX:JDWPOptions=...,mode=native:<path/to/java/home>: Search lib:svmjdwp inside JAVA_HOME, for example lib|bin/lib:svmjdwp.
-XX:JDWPOptions=...,mode=native: Search lib:svmjdwp besides the native executable directory.
-XX:JDWPOptions=...,vm.options=...: VM options, separated by whitespaces, passed to the JDWP server isolate/JVM, should not include a , character.
-XX:JDWPOptions=...,vm.options=@argfile: Also supports Java Command-Line Argument Files.
Note: If lib:svmjdwp cannot be found, the application will terminate with error code 1.
The JDWP debugging support for Native Image aims to:
The JDWP debugging support is implemented using a Java bytecode interpreter, adapted from Espresso to work with Native Image. Key components include:
Interpreter: Derived from Espresso and adapted for SubstrateVM. It does not enable any dynamic features beyond what Native Image already supports.
PLT/GOT Feature: Used to divert execution to the interpreter. This implementation detail may change for some platforms.
Metadata File: An external .metadata file produced at build time, containing information required for runtime method interpretation.
JDWP Server: Implemented as a native library (lib:svmjdwp), handling network connections and implementing JDWP commands.
JDWP Resident: A component within the application providing access to locals, fields, stack traces, and other runtime information.
The JDWP debugger for Native Image is designed to align with Native Image's architecture and principles. While many limitations are a natural consequence of Native Image's design, others may be due to the current implementation of the debugger itself. Here are the key limitations to be aware of:
System.getProperty("java.class.path") == nullMethodHandle object, for example, lambdas.These limitations reflect the current state of JDWP debugging support in Native Image. Some may be addressed in future iterations of the debugger, while others are fundamental to Native Image's design.