用gdb調試php程式

來源:互聯網
上載者:User

 

有一個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&)'

 

可以讓程式運行到這個函數時停止。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.