gdb在python + pybind11 segfault上显示java吗?

问题描述

我遇到了一些python + pybind11(C ++)代码的段错误。我尝试在gdb中进行调试,但stacktrace最终以libjvm结尾,我不知道它来自何处。现在我完全无法诊断问题了。

关于如何从这里出发的任何建议?

(colin) colinf@spark-ultra-1:~$ gdb python -ex 'r test.py'
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
copyright (C) 2016 Free Software Foundation,Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY,to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions,please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help,type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from python...done.
Starting program: /home/jupyterhub/miniconda3/envs/colin/bin/python test.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff4a03700 (LWP 14958)]
[New Thread 0x7ffff4202700 (LWP 14959)]
[New Thread 0x7fffefa01700 (LWP 14960)]
[New Thread 0x7fffed200700 (LWP 14961)]
[New Thread 0x7fffea9ff700 (LWP 14962)]
[New Thread 0x7fffe81fe700 (LWP 14963)]
[New Thread 0x7fffe59fd700 (LWP 14964)]
[New Thread 0x7fffe31fc700 (LWP 14965)]
[New Thread 0x7fffe09fb700 (LWP 14966)]
[New Thread 0x7fffe01fa700 (LWP 14967)]
[New Thread 0x7fffdd9f9700 (LWP 14968)]
[New Thread 0x7fffd91f8700 (LWP 14969)]
[New Thread 0x7fffd69f7700 (LWP 14970)]
[New Thread 0x7fffd41f6700 (LWP 14971)]
[New Thread 0x7fffd19f5700 (LWP 14972)]
[New Thread 0x7fffcf1f4700 (LWP 14973)]
[New Thread 0x7fffce9f3700 (LWP 14974)]
[New Thread 0x7fffcc1f2700 (LWP 14975)]
[New Thread 0x7fffc99f1700 (LWP 14976)]
DEBUG:root:1570235349409078
INFO:root:Processing date=2019-10-05
[New Thread 0x7fffbd9ff700 (LWP 14977)]

Thread 1 "python" received signal SIGSEGV,Segmentation fault.
0x00007fffa79c92b4 in ?? ()
(gdb) bt
#0  0x00007fffa79c92b4 in ?? ()
#1  0x0000000000000246 in ?? ()
#2  0x00007fffa79c9160 in ?? ()
#3  0x00007fffb7fb3f30 in VM_Operation::_names () from /usr/lib/jvm/java-8-oracle//jre/lib/amd64/server/libjvm.so
#4  0x00007fffffff7120 in ?? ()
#5  0x00007fffb7ae178d in VM_Version::get_processor_features() () from /usr/lib/jvm/java-8-oracle//jre/lib/amd64/server/libjvm.so
Backtrace stopped: prevIoUs frame inner to this frame (corrupt stack?)

我也尝试过使用故障处理程序,但是在遇到段错误后没有任何回溯

python -q -X faulthandler
>>> import test

...
Segmentation fault

解决方法

如果您使用pybind11加载本身会加载JVM的内容,这是预期的。 JVM安装信号处理程序并拦截这些故障。为了调试还涉及JVM的程序,您需要告诉GDB将SIGSEGVSIGBUS信号传递给程序:

(gdb) handle SIGSEGV noprint nostop pass
Signal        Stop  Print   Pass to program Description
SIGSEGV       No    No  Yes     Segmentation fault
(gdb) handle SIGBUS noprint nostop pass
Signal        Stop  Print   Pass to program Description
SIGBUS        No    No  Yes     Bus error