Java / GraalVM Interview questions
How do you debug a native image application when standard Java debuggers don't attach?
A native executable is compiled machine code, not JVM bytecode, so a standard jdb/JDWP-based debugger that expects a live JVM to attach to has nothing to connect to.
- Build with debug info:
native-image -g -O0 -jar app.jarembeds source-level debug symbols and disables optimizations that would otherwise make stepping through code confusing. - Attach a native debugger: on Linux, GDB can attach directly to the running native-image process and, with the embedded debug info, step through Java source lines, inspect local variables, and set breakpoints much like a native C/C++ program.
- Use IDE integration: recent versions of IntelliJ IDEA and VS Code support debugging native-image binaries directly using this same GDB-based mechanism, presenting it similarly to a normal Java debugging session.
- Fall back to JVM-mode debugging for logic-level bugs: since most application logic is identical on JVM and native image, reproducing a bug on the regular JVM with
jdbfirst is often faster, reserving native-only debugging for issues specific to native-image behavior (like a missing reflection entry).
More Related questions...