PHP How to debug Segmentation Faults


To Segementation faults, like PHP7 currently occurring in to determine and analyze, can you proceed in the following way

1. Specifying the location for the core dumps

echo '/tmp/coredump_%e_%p' > /proc/sys/kernel/core_pattern

2. enable core dumps in PHP-FPM

in the file: PHP-fpm.conf:

rlimit_core = unlimited     ; vorher: 0

3. Restart PHP FPM

service php-fpm restart

4. Analyzing the core dumps with gdb

Refer to the C-PHP core the core dumps and are around 100mb in size. You can be analyzed with the tool of gdb.

apt-get install gdb

Start gdb:

gdb  /usr/sbin/php-fpm /tmp/coredump_php-fpm7.0_27190

Edition:

 GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 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 /usr/sbin/php-fpm7.0...(no debugging symbols found)...done.
[New LWP 31740]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `php-fpm: pool toolbox                                                        '.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x0000556562bee64f in zend_hash_destroy ()

Run the Backtracebefhel:

bt

Edition:

#0  0x0000556562bee64f in zend_hash_destroy ()
#1  0x00007f2bf0c18461 in delete_type_persistent () from /usr/lib/php/20151012/soap.so
#2  0x0000556562bee5a5 in zend_hash_destroy ()
#3  0x00007f2bf0c1f321 in ?? () from /usr/lib/php/20151012/soap.so
#4  0x00007f2bf0c1f38f in ?? () from /usr/lib/php/20151012/soap.so
#5  0x0000556562bed602 in zend_hash_del ()
#6  0x00007f2bf0c230d3 in get_sdl () from /usr/lib/php/20151012/soap.so
#7  0x00007f2bf0bf936a in zim_SoapClient_SoapClient () from /usr/lib/php/20151012/soap.so
#8  0x0000556562bcd57a in dtrace_execute_internal ()
#9  0x0000556562c62300 in ?? ()
#10 0x0000556562c1d9db in execute_ex ()
#11 0x0000556562bcd411 in dtrace_execute_ex ()
#12 0x0000556562c6243d in ?? ()
#13 0x0000556562c1d9db in execute_ex ()
#14 0x0000556562bcd411 in dtrace_execute_ex ()
#15 0x0000556562c6243d in ?? ()
#16 0x0000556562c1d9db in execute_ex ()
#17 0x0000556562bcd411 in dtrace_execute_ex ()
#18 0x0000556562c6243d in ?? ()
#19 0x0000556562c1d9db in execute_ex ()
#20 0x0000556562bcd411 in dtrace_execute_ex ()
#21 0x0000556562c6e17c in ?? ()
#22 0x0000556562c1d9db in execute_ex ()
#23 0x0000556562bcd411 in dtrace_execute_ex ()
#24 0x0000556562c71717 in zend_execute ()
#25 0x0000556562bdd613 in zend_execute_scripts ()
#26 0x0000556562b7ddd0 in php_execute_script ()
#27 0x0000556562a64686 in main ()

Result:
The backtrace and Google you come to the conclusion, that this stack trace on a still open Bug-ticket is PHP and the cause is the caching of the WSDL in the store, that must be disabled, to work around the error.

If you find a bug ticket, should you watch, If all packages up to date are, because many segmentation faults are fixed over time:

apt-get update
apt-get upgrade

If the segfault still hitting, You should create a bug ticket on php.net and a working snippet to create the reconstruction.