. So is written for the PHP script call, if the PHP script execution is broken,. So can only be in the process of grief and finally, PHP script debugging often used Echo, Print_r, var_dump are not useful. Even if you can print a little error log out, but also saw the appearance, do not know the inside, can not solve some strange bugs. Fortunately we have GDB, the following 4 steps to fix PHP C extension debugging.
If Test-z "$PHP _debug"; Then
Ac_arg_enable (Debug,
[
--enable-debug compile with debugging symbols
],[
php_debug= $enableval
],[
Php_debug=no
])
Fi
./configure–enable-debug--enable-yourmodule //and debug C program of-G is the same effect
make//Generate a. So with debug information
make install//install the. So to the PHP interpreter can load the path
To debug to set breakpoints, to set breakpoints to know the symbol, PHP extension in order to ensure that the function does not and C library symbols are duplicated, before the export function is prefixed with the unified zif, in order to know what to debug. So all the symbols, NM command is more appropriate. The NM command lists the list of symbols for the target file (. A or. so), including the function or class name, such as:
3. Loading the PHP interpreter and. So to GDB
It's time to load the PHP interpreter into GDB, which uses the gdb file command:file/usr/bin/php the PHP interpreter here does not need to have debug symbols, but make sure that it loads the. So to be debugged (can be referenced by the php–m command).
(gdb) file ~/php/bin/php
4.break set breakpoints, run PHP script for debugging
are ready, set breakpoints, use the symbols seen from NM. Set it to run: run *.php This command is to pass the. php script as a parameter to the PHP interpreter, have the PHP interpreter execute the *.php script, and stop at the breakpoint. Then just list, print, next to find out the bug.
The others are the same steps as debugging the C program. I wish you all a happy ^_^