Skip to main content

Debug Native Image

Comparing to JVM model, debugging a native image is much harder.

Debug Info

The first step is to add debug info into the native image. This is done by adding the -g or -H:GenerateDebugInfo option to native-image.

Debug information is recorded with the DWARF (debugging with attributed record formats) format. The debug info can be viewed by using objdump.

objdump --dwarf=info buggycode

Source code of the native image is cached alongside the generated native image in a subdirectory named sources. This directory contains source code from JDK, GraalVM, and the application. To use a different cache directory, the -H:DebugInfoSourceCacheRoot option can be used.

If there are other paths to search for source code, the -H:DebugInfoSourceSearchPath option can be used to specify the search paths.

Debugging

Executables created by native-image can be debugged using gdb.