Apache2分段故障由自定义php模块引起

时间:2017-01-06 13:35:11

标签: segmentation-fault gdb php-extension

我的头撞在了墙上。

对于我的一个php项目,我正在使用一个php模块,可以使用瑞士星历进行一些天文计算。未来的开发过程确实依赖于它。所以我需要让它在php7中工作。这个php模块使用瑞士星历(一个有行星位置的库)提供c函数,以便使用模块包含在php中。

可以在here

上找到此php模块的源代码

当为php5和ubuntu 14.04编译这个模块时,它运行正常,但是当我为php7和ubuntu 16.04编译这个模块时。

我在编译时遇到错误,如下所示:

/home/hermes/Bureaublad/php-sweph-master/sweph.c:1098:2: error: 
‘RETURN_STRING’ undeclared (first use in this function)
 RETURN_STRING(name, 1);

经过一些试验和错误,我确实发现这个函数中有许多参数,因为在php7中已经改变了一些东西。在很多功能中删除“,1”参数后。我终于编译了模块并且运行正常,但并非所有功能都正常工作。

有很多函数导致apache2分段错误错误(11)。同时其他功能也完美无缺。

所以经过一些阅读后我开始调试apache2以找出导致分段错误的原因,但从这一点开始,事情没有任何意义......

我遵循了这个指南:"[notice] child pid XXXX exit signal Segmentation fault (11)" in apache error.log

GDB返回此信息,但我不知道这与我的php模块有什么关系导致错误。

 gdb attach 19966
 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"...
 attach: Bestand of map bestaat niet.
 Attaching to process 19966
 Reading symbols from /bin/bash...(no debugging symbols found)...done.
 Reading symbols from /lib/x86_64-linux-gnu/libtinfo.so.5...(no       
 debugging symbols found)...done.
 Reading symbols from /lib/x86_64-linux-gnu/libdl.so.2...Reading   
 symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libdl-2.23.so...done.
 done.
 Reading symbols from /lib/x86_64-linux-gnu/libc.so.6...Reading 
 symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libc-
 2.23.so...done.
 done.
 Reading symbols from /lib64/ld-linux-x86-64.so.2...Reading symbols  
 from /usr/lib/debug//lib/x86_64-linux-gnu/ld-2.23.so...done.
 done.
 Reading symbols from /lib/x86_64-linux-
 gnu/libnss_compat.so.2...Reading symbols from 
 /usr/lib/debug//lib/x86_64-linux-gnu/libnss_compat-2.23.so...done.
 done.
 Reading symbols from /lib/x86_64-linux-gnu/libnsl.so.1...Reading 
 symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libnsl-
 2.23.so...done.
 done.
 Reading symbols from /lib/x86_64-linux-gnu/libnss_nis.so.2...Reading   
 symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libnss_nis-  
 2.23.so...done.
 done.
 Reading symbols from /lib/x86_64-linux-
 gnu/libnss_files.so.2...Reading symbols from 
 /usr/lib/debug//lib/x86_64-linux-gnu/libnss_files-2.23.so...done.
 done.
 0x00007fdc29a1f4ca in __GI___waitpid (pid=-1, 
 stat_loc=0x7ffe86bd85f0, options=10)
 at ../sysdeps/unix/sysv/linux/waitpid.c:29
 29 ../sysdeps/unix/sysv/linux/waitpid.c: Bestand of map bestaat niet.
 (gdb) back
 #0  0x00007fdc29a1f4ca in __GI___waitpid (pid=-1,     
 stat_loc=0x7ffe86bd85f0, options=10)
 at ../sysdeps/unix/sysv/linux/waitpid.c:29
 #1  0x0000000000446f5d in ?? ()
 #2  0x000000000044843b in wait_for ()
 #3  0x000000000043842f in execute_command_internal ()
 #4  0x000000000043848e in execute_command ()
 #5  0x000000000042139e in reader_loop ()
 #6  0x000000000041fdb1 in main ()
 (gdb) back full
 #0  0x00007fdc29a1f4ca in __GI___waitpid (pid=-1,     
 stat_loc=0x7ffe86bd85f0, options=10)
 at ../sysdeps/unix/sysv/linux/waitpid.c:29
    resultvar = 18446744073709551104
 #1  0x0000000000446f5d in ?? ()
 No symbol table info available.
 #2  0x000000000044843b in wait_for ()
 No symbol table info available.
 #3  0x000000000043842f in execute_command_internal ()
 No symbol table info available.
 #4  0x000000000043848e in execute_command ()
 No symbol table info available.
 #5  0x000000000042139e in reader_loop ()
 No symbol table info available.
 #6  0x000000000041fdb1 in main ()
 No symbol table info available.
 (gdb) 

1 个答案:

答案 0 :(得分:1)

 Attaching to process 19966
 Reading symbols from /bin/bash...(no debugging symbols found)...done.

您似乎已经附加了错误的pid号码。即你附加到/bin/bash,你的一个shell实例。您想要附加到Apache2进程。再次查看ps输出,并按照"[notice] child pid XXXX exit signal Segmentation fault (11)" in apache error.log中的建议找到您的Apache2实例。