用gdb调试php程序

 

有一个php程序,命令行执行时如下:

[root@h10-vm08 demo]#  php ParseFile.php xxxx.ykml  
*** glibc detected *** free(): invalid pointer: 0xb7869b7c ***
Aborted
[root@h10-vm08 demo]#

 

这个php程序调用的php extension的so文件中有非法访问指针错误,但错误发生在什么地方?用gdb来定位这类问题是最方便的。

 

[root@h10-vm08 demo]# gdb php

(gdb) run ParseFile.php xxxx.ykml

Starting program: /home/y/bin/php ParseFile.php xxxx.ykml
[Thread debugging using libthread_db enabled]
[New Thread -1208723776 (LWP 3225)]
*** glibc detected *** free(): invalid pointer: 0xb783cbc4 ***

Program received signal SIGABRT, Aborted.
[Switching to Thread -1208723776 (LWP 3225)]
0x005847a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
(gdb)

(gdb) bt
#0  0x005847a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
#1  0x004477a5 in raise () from /lib/tls/libc.so.6
#2  0x00449209 in abort () from /lib/tls/libc.so.6
#3  0x0047b71a in __libc_message () from /lib/tls/libc.so.6
#4  0x00481fbf in _int_free () from /lib/tls/libc.so.6
#5  0x0048233a in free () from /lib/tls/libc.so.6
#6  0x02f37b56 in FBMLStyleSheet::TranslateURL () from /home/y/lib/php/20060613/fbml.so
#7  0x02f453a5 in CSSParserImpl::ParseURL () from /home/y/lib/php/20060613/fbml.so
#8  0x02f44585 in CSSParserImpl::ParseVariant () from /home/y/lib/php/20060613/fbml.so
#9  0x02f461c0 in CSSParserImpl::ParseSingleValueProperty () from /home/y/lib/php/20060613/fbml.so

......

 

 

这样就得到了栈的轨迹,定位到了发生错误的函数。

 

 

下断点:

(gdb) b 'CSSParserImpl::ParseURL(unsigned int&, nsCSSValue&)'

 

可以让程序运行到这个函数时停止。

你可能感兴趣的:(thread,c,PHP,extension,Signal,debugging)