简体   繁体   English

如何在Java中打印出本机stacktrace?

[英]How to print out native stacktrace in Java?

I would like to print the stacktrace of native methods calls of a Java application. 我想打印Java应用程序的本机方法调用的stacktrace The Thread.dumpStack() is only printing java methods calls. Thread.dumpStack()仅打印java方法调用。

If you want the non-java stack, you need a "native" debugger, eg gdb . 如果您需要非Java堆栈,则需要一个“本机”调试器,例如gdb

You can attach to your running java with gdb , too. 您也可以使用gdb附加到正在运行的Java。

For documentation on seamless debugging of Java with gdb, see also: http://gcc.gnu.org/java/gdb.html 有关使用gdb 无缝调试Java的文档,另请参见: 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.) (gcc可以将Java代码编译为本机代码;这时本机调试器还将显示Java回溯。)

如果可以在应用程序外部执行此操作,则可以运行$JAVA_HOME/bin/jstack -m <jvm_pid>

To view the internal JVM (C-level) function calls, attach a standard C debugger to the process. 要查看内部JVM(C级)函数调用,请将标准C调试器附加到进程。

Exactly how to do this does depends on your OS and debugger of choice, for example on OSX one would use xcode. 确切的操作方式取决于您的操作系统和选择的调试器,例如在OSX上,将使用xcode。 Instructions for using gdb can be read here . 可以在此处阅读有关使用gdb的说明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM