Kategorien
PHP PHP 7

PHP How to debug Segmentation Faults

Um Segementation Faults, die gerne in PHP7 zur Zeit auftreten zu bestimmen und zu analysieren, kann man folgender Weise vorgehen

1. Angabe des Speicherortes für die Coredumps

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

2. aktivieren der Coredumps in PHP-FPM

in der Datei: php-fpm.conf:

rlimit_core = unlimited     ; vorher: 0

3. PHP FPM restarten

service php-fpm restart

4. Analysieren der Coredumps mit gdb

Die Coredumps beziehen sich auf den C-PHP Core und sind um die 100mb groß. Sie lassen sich mit dem Tool gdb analysieren.

apt-get install gdb

Starten von gdb:

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

Ausgabe:

 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 ()

Den Backtracebefhel ausführen:

bt

Ausgabe:

#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 ()

Ergebnis:
Über den Backtrace und mit Google kommt man zu dem Ergebnis, dass dieser Stacktrace sich auf ein noch offenes Bug-Ticket von PHP bezieht und die Ursache ist das Cachen der WSDL im Arbeitspeicher, die deaktiviert werden muss, um den Fehler zu umgehen.

Wenn man kein Bug-Ticket findet, sollte man schauen, ob alle Packete auf dem neusten Stand sind, weil viele Segmentation Faults gefixt werden mit der Zeit:

apt-get update
apt-get upgrade

Falls der Segfault immer noch aufschlägt, sollte man ein Bug-Ticket erstellen auf php.net und ein lauffähiges Snippet erstellen zur Rekonstruktion.