Debug the phpcextension program with gdb + nm.

Source: Internet
Author: User
Recently, the phpcextension client program written to Beanstalkd cannot be separated from Debugging. The following describes the problems encountered during debugging and the solution.

Recently, I am writing Beanstalkd's php c extension client program. I cannot write programs without debugging. I will share with you the problems and solutions encountered during debugging.

. So is called for the php script. if the execution of the php script fails ,. so can only end with hate in the process. at this time, echo, print_r, and var_dump, which are often used for php script debugging, are useless. Even if I can print a bit of error logs, I can only see the appearance. I don't know the story, and I can't solve some strange bugs. Fortunately, we have gdb. next we will use four steps to Debug php c extension.

1. prepare debuggable. so

Add the configuration information above in config. m4.

 

./Configure-enable-debug // the same effect as debugging c program-g

Make // Generate. so with debugging information

Make install // install. so to the path that can be loaded by the php interpreter

2. View through nm

To debug a function, you need to set a breakpoint. to ensure that the function does not repeat the symbols in the c library, add the unified prefix zif before the function is exported, to know that the breakpoint is to be debugged. which symbols are available for so? the nm command is no longer suitable. The nm command is used to list the symbols of the target file (. a or. so), including the function or class name, such:

 

3. load the php interpreter and. so to gdb.

It is time to load the php interpreter to gdb. The file command of gdb is used: file/usr/bin/php. The php interpreter here does not need debugging symbols, however, make sure that the file to be debugged is loaded. so (you can use the php-m command for reference ).

 

4. set the breakpoint and run the php script for debugging.

All are ready. set the breakpoint and use the symbol viewed from nm. Run *. the php command is. the php script is passed as a parameter to the php interpreter and executed by the php interpreter *. php script, and stop at the breakpoint. Then find out all the bugs in list, print, and next.

 

When you set a breakpoint, you must select y, because the breakpoint is set in the extended so, and must be loaded before it can be found.

Other steps are the same as debugging c programs. I wish you all a happy time!


Related Article

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.