I would like to print the stacktrace
of native methods calls of a Java application. The Thread.dumpStack()
is only printing java methods calls.
Asked
Active
Viewed 1,849 times
2

Bionix1441
- 2,135
- 1
- 30
- 65
-
1Just to clarify, by native do you mean the native keyword or the C level function calls within the JVM? – Chris K Jun 03 '15 at 08:04
-
C level function calls within the jvm – Bionix1441 Jun 03 '15 at 08:05
3 Answers
4
If you want the non-java stack, you need a "native" debugger, e.g. gdb
.
You can attach to your running java with gdb
, too.
For documentation on seamless debugging of Java with gdb, see also: http://gcc.gnu.org/java/gdb.html
(gcc can compile java code to native code; at which point the native debugger will also show Java backtraces.)

Has QUIT--Anony-Mousse
- 76,138
- 12
- 138
- 194
-
1
-
1You should of course do a *debug build* of your native library, and if you want to see details on hotspot, install the debug symbols of your JRE, too. (e.g. Ubuntu package `openjdk-8-dbg`) – Has QUIT--Anony-Mousse Jun 03 '15 at 08:36
-
`javac TestT.java gcj -g --main=TestT -o TestT TestT.class gdb TestT` I Should I install gcj : the Gnu Compiler for Java as well ? – Bionix1441 Jun 03 '15 at 08:49
-
1If you want to do the seamless debugging approach, then yes. If you want to use OpenJDK/HotSpot, no. – Has QUIT--Anony-Mousse Jun 03 '15 at 08:51
-
-
Or `gdb java PID` to attach to a running java process with process id `PID`. – Has QUIT--Anony-Mousse Jun 03 '15 at 17:43
2
If it is OK to do it outside of your application you can run $JAVA_HOME/bin/jstack -m <jvm_pid>

K Erlandsson
- 13,408
- 6
- 51
- 67
-
But what if I want the native method calls for a class `HelloWorld.java` ? – Bionix1441 Jun 03 '15 at 07:59
-