我有一个大应用程序,以多线程模式运行 - 45 个线程。在某些时候,应用程序崩溃了Segmentation fault
。我通过以下方式使用 gdb:
ulimit -c unlimited
sudo sysctl -w kernel.core_pattern=/tmp/core-%e.%p.%h.%t
sleep 10 & killall -SIGSEGV sleep
gdb /etc/php7/bin/php /tmp/core-sleep.4970.mike-Inspiron-N5040.1557648122
run script.php
完整的回溯是:
Thread 1 "php" received signal SIGSEGV, Segmentation fault.
pthreads_store_tohash (object=object@entry=0x7fffe9211b80,
hash=0x7fffea78f188)
at /var/www/interceptor.cmd.source/pthreads/src/store.c:564
564 ZEND_HASH_FOREACH_KEY_PTR(threaded->store.props, idx, name, storage) {
(gdb) bt
#0 pthreads_store_tohash (object=object@entry=0x7fffe9211b80,
hash=0x7fffea78f188)
at /var/www/interceptor.cmd.source/pthreads/src/store.c:564
#1 0x00007fffeac558d0 in pthreads_read_properties (object=0x7fffe9211b80)
at /var/www/interceptor.cmd.source/pthreads/src/handlers.c:80
#2 0x000055555590769b in php_json_encode_array (
buf=buf@entry=0x7fffffffb730, val=val@entry=0x7fffe9211b80,
options=options@entry=0, encoder=encoder@entry=0x7fffffffb724)
at /var/www/interceptor/php-src-php-7.2.2/ext/json/json_encoder.c:139
#3 0x0000555555907020 in php_json_encode_zval (
buf=buf@entry=0x7fffffffb730, val=val@entry=0x7fffe9211b80,
options=options@entry=0, encoder=encoder@entry=0x7fffffffb724)
at /var/www/interceptor/php-src-php-7.2.2/ext/json/json_encoder.c:546
#4 0x00005555559078b5 in php_json_encode_array (
buf=buf@entry=0x7fffffffb730, val=val@entry=0x7fffe9dada40,
options=options@entry=0, encoder=encoder@entry=0x7fffffffb724)
at /var/www/interceptor/php-src-php-7.2.2/ext/json/json_encoder.c:218
#5 0x0000555555907020 in php_json_encode_zval (
buf=buf@entry=0x7fffffffb730, val=val@entry=0x7fffe9dada40,
options=options@entry=0, encoder=encoder@entry=0x7fffffffb724)
at /var/www/interceptor/php-src-php-7.2.2/ext/json/json_encoder.c:546
#6 0x00005555559078b5 in php_json_encode_array (
buf=buf@entry=0x7fffffffb730, val=val@entry=0x7fffec21eb90,
options=options@entry=0, encoder=encoder@entry=0x7fffffffb724)
at /var/www/interceptor/php-src-php-7.2.2/ext/json/json_encoder.c:218
#7 0x0000555555907020 in php_json_encode_zval (
buf=buf@entry=0x7fffffffb730, val=val@entry=0x7fffec21eb90, options=0,
encoder=encoder@entry=0x7fffffffb724)
at /var/www/interceptor/php-src-php-7.2.2/ext/json/json_encoder.c:546
#8 0x0000555555905570 in zif_json_encode (execute_data=0x7fffec21eb40,
return_value=0x7fffec21eb20)
at /var/www/interceptor/php-src-php-7.2.2/ext/json/json.c:245
#9 0x0000555555c41b13 in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER ()
at /var/www/interceptor/php-src-php-7.2.2/Zend/zend_vm_execute.h:1032
#10 execute_ex (ex=0x7fffeab4e560)
at /var/www/interceptor/php-src-php-7.2.2/Zend/zend_vm_execute.h:59752
#11 0x00007fffeac4ba15 in pthreads_execute_ex (data=<optimized out>)
---Type <return> to continue, or q <return> to quit---
at /var/www/interceptor.cmd.source/pthreads/php_pthreads.c:135
#12 0x0000555555c3fb5c in ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER ()
at /var/www/interceptor/php-src-php-7.2.2/Zend/zend_vm_execute.h:888
#13 execute_ex (ex=0x7fffeab4e560)
at /var/www/interceptor/php-src-php-7.2.2/Zend/zend_vm_execute.h:59749
#14 0x00007fffeac4ba15 in pthreads_execute_ex (data=<optimized out>)
at /var/www/interceptor.cmd.source/pthreads/php_pthreads.c:135
#15 0x0000555555c3fb5c in ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER ()
at /var/www/interceptor/php-src-php-7.2.2/Zend/zend_vm_execute.h:888
#16 execute_ex (ex=0x7fffeab4e560)
at /var/www/interceptor/php-src-php-7.2.2/Zend/zend_vm_execute.h:59749
#17 0x00007fffeac4ba15 in pthreads_execute_ex (data=<optimized out>)
at /var/www/interceptor.cmd.source/pthreads/php_pthreads.c:135
#18 0x0000555555c3fb5c in ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER ()
at /var/www/interceptor/php-src-php-7.2.2/Zend/zend_vm_execute.h:888
#19 execute_ex (ex=0x7fffeab4e560)
at /var/www/interceptor/php-src-php-7.2.2/Zend/zend_vm_execute.h:59749
#20 0x00007fffeac4ba15 in pthreads_execute_ex (data=<optimized out>)
at /var/www/interceptor.cmd.source/pthreads/php_pthreads.c:135
#21 0x0000555555c4265f in zend_execute (op_array=<optimized out>,
return_value=0x0)
at /var/www/interceptor/php-src-php-7.2.2/Zend/zend_vm_execute.h:63760
#22 0x0000555555b852d2 in zend_execute_scripts (type=type@entry=8,
retval=retval@entry=0x0, file_count=-333321568, file_count@entry=3)
at /var/www/interceptor/php-src-php-7.2.2/Zend/zend.c:1496
#23 0x0000555555b1276e in php_execute_script (primary_file=0x7fffffffd020)
at /var/www/interceptor/php-src-php-7.2.2/main/main.c:2590
#24 0x0000555555c44d73 in do_cli (argc=2, argv=0x55555674b7b0)
at /var/www/interceptor/php-src-php-7.2.2/sapi/cli/php_cli.c:1011
#25 0x00005555556e3f31 in main (argc=2, argv=0x55555674b7b0)
at /var/www/interceptor/php-src-php-7.2.2/sapi/cli/php_cli.c:1404
所以可能错误出现在我的 PHP 代码中。但我不知道它可能在哪里。我可以知道发生分段错误的确切 PHP 文件和行吗?
Xdebug 我无法使用,因为它与某些扩展名冲突。多线程模式也可能是 xdebug 的一个问题。
我的环境是:
Ubuntu 服务器 18.04 64bit PHP 7.2.2 ZTS 无调试