Debug PHP C Extension program with GDB+NM

Source: Internet
Author: User
Tags php script

. 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 ^_^

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.