From: http://www.codefrom.com/paper/%E4%BD%BF%E7%94%A8gdb%E8%B0%83%E8%AF%95p ...
The extension of PHP is developed using C + + and can be easily debugged with GDB. The steps are as follows:
You need to add the * *--enable-debug** parameter when compiling PHP first
./configure--enable-debugmake && make install
Test on my Ubuntu machine, the extended directory defaults to/usr/local/lib/php/extensions/debug-non-zts-20131226/
In this way PHP source debugging is also very convenient.
The next step is to create the extension, enter the PHP source's ext directory, run
./ext_skel--extname=mydebug
The mydebug directory will be automatically generated under the current directory, then enter the directory, edit the config.m4 file, remove the 10~12 line of DNL, as follows
Php_arg_with (Mydebug, for Mydebug support,make sure. The comment is aligned:[ --with-mydebug Include mydebug Support])
Add on last line
If Test-z "$PHP _debug"; Then ac_arg_enable (Debug, [--ENABLE-DEBG compile with debugging system], [php_debug= $enableval], [ Php_debug=no] ) fi
This means that the extension is capable of debugging, then compiling the extension, using the command
Phpize./configure--enable-debugmake && make install
The phpize and php-config here need to be configured with the environment variables in advance and then load the extension. The address on my machine is/usr/local/lib/php/extensions/debug-non-zts-20131226/. Enter the mydebug extension source directory, the default generated function is confirm_mydebug_compiled, defined in Mydebug.c, extended automatically generated functions.
Php_function (confirm_mydebug_compiled) { char *arg = NULL; int Arg_len, Len; char *STRG; if (Zend_parse_parameters (Zend_num_args () tsrmls_cc, "s", &arg, &arg_len) = = FAILURE) { return; } Len = spprintf (&STRG, 0, "congratulations! You have successfully modified EXT/%.78S/CONFIG.M4. Module%.78s is now compiled into PHP. "," Mydebug ", Arg); Return_stringl (STRG, Len, 0);}
The idea is to get a string argument and then spell a string back. View the generated mydebug.so exported symbols through the NM command.
Run nm mydebug.so return zif_confirm_mydebug_compiled ...
Php_function is actually adding zif_ in front of the function name and then debugging GDB
The first step runs: gdb PHP then runs: Break zif_confirm_mydebug_compiled Terminal tip: Function "zif_confirm_mydebug_compiled" not defined. Make breakpoint pending on the future shared library load? (Y or [n]) Enter: Y input: run/tmp/test.php This will echo: Breakpoint 1, zif_confirm_mydebug_compiled (Ht=1, return_value= 0XB7BF0D44, return_value_ptr=0xb7bd6104, this_ptr=0x0, return_value_used=1) at /...../php-5.6.6/ext/mydebug/ Mydebug.c:56 then enter: L Display: php_function (confirm_mydebug_compiled) on {$ char *arg = null;57 int arg_ Len, len;58 char *strg;5960 if (Zend_parse_parameters (Zend_num_args () tsrmls_cc, "s", &arg, &arg_len) = = FAILURE) {
Where the contents of the file/tmp/test.php are:
As you can see, the function source code is already out and can be debugged using the common GDB command.
More exciting original content into http://www.codefrom.com/