2012-08-28 47 views
2

我通過在命令行鍵入php -a以交互方式使用PHP。我修改了/etc/php5/cli/php.ini來加載我使用SWIG構建的擴展模塊。在交互式會話中詳細運行PHP

當我終止交互式會話,我得到一個分段錯誤:

[email protected]:~$ php -a 
Interactive shell 

php > ^DSegmentation fault 
[email protected]:~$ 

我想在詳細模式下運行PHP的,這樣我可以看到,導致了賽格故障的電話。有沒有辦法在交互模式下運行php?例如,使用Python,可以運行python -v以獲取詳細的診斷信息。有沒有PHP的等價物?

[更新]

這裏是一個堆棧跟蹤使用的valgrind時:

[email protected]:~$ USE_ZEND_ALLOC=0 valgrind php -a 
==16414== Memcheck, a memory error detector 
==16414== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al. 
==16414== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info 
==16414== Command: php -a 
==16414== 

valgrind: Fatal error at startup: a function redirection 
valgrind: which is mandatory for this platform-tool combination 
valgrind: cannot be set up. Details of the redirection are: 
valgrind: 
valgrind: A must-be-redirected function 
valgrind: whose name matches the pattern:  strlen 
valgrind: in an object with soname matching: ld-linux-x86-64.so.2 
valgrind: was not found whilst processing 
valgrind: symbols from the object with soname: ld-linux-x86-64.so.2 
valgrind: 
valgrind: Possible fixes: (1, short term): install glibc's debuginfo 
valgrind: package on this machine. (2, longer term): ask the packagers 
valgrind: for your Linux distribution to please in future ship a non- 
valgrind: stripped ld.so (or whatever the dynamic linker .so is called) 
valgrind: that exports the above-named function using the standard 
valgrind: calling conventions for this platform. The package you need 
valgrind: to install for fix (1) is called 
valgrind: 
valgrind: On Debian, Ubuntu:     libc6-dbg 
valgrind: On SuSE, openSuSE, Fedora, RHEL: glibc-debuginfo 
valgrind: 
valgrind: Cannot continue -- exiting now. Sorry. 

回答

1

您可以使用通常的C調試工具獲取堆棧跟蹤。例如:

  • Valgrind的:

    $ USE_ZEND_ALLOC=0 valgrind php -a 
    
  • GDB:

    $ gdb php 
    > r -a 
    

如果你沒有得到有意義的堆棧跟蹤,你可能需要重新編譯PHP與調試符號並減少優化。您可以通過將--enable-debug傳遞給您的./configure產品線。

+0

對於有用的信息+1。我現在使用gdb,但我想使用valgrind。我已經接受了你的回答,但是當我按照建議運行valgrind時,更新了我得到的錯誤。請在有空的時候看看並回復。謝謝。 –

+0

@HomunculusReticulli你應該嘗試一下錯誤信息的建議,例如'sudo apt-get install libc6-dbg'(如果在Ubuntu上)。似乎你錯過了某種調試符號(雖然我不知道它到底需要什麼)。 – NikiC

+0

k,謝謝。我會嘗試的。 –

0

你可能會想使用valgrind或類似追查正是你的PHP安裝在那裏是Seg Faulting。

最有可能的是,錯誤將與您已加載的擴展相關,這些擴展可能不會被編譯到正確的架構,包含泄漏或其他內容。