如何使用GDB调试PHP程序
|
(1)启动你的程序,可以按照你的自定义的要求随心所欲的运行程序。 (2)可让被调试的程序在你所指定的调置的断点处停住。(断点可以是条件表达式) (3)当程序被停住时,可以检查此时你的程序中所发生的事。 (4)动态的改变你程序的执行环境。 GDB是GNU开源组织发布的一个强大的UNIX下的程序调试工具。如果你是在 UNIX平台下做软件,你会发现GDB这个调试工具有比VC、BCB的图形化调试器更强大的功能。同时GDB也具有例如ddd这样的图形化的调试端。 直接上代码了 using namespace std; long factorial(int n); int main() { int n(0); cin>>n; long val=factorial(n); cout<编译1 g++ k.cpp -g -Wall -Werror -o main 开始调试
This is free software: you are free to change and redistribute it.
There is NO WARRANTY,to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-redhat-linux-gnu".
For bug reporting instructions,please see:
warning: Source file is more recent than executable. 设置断点 break linenumber设置观察点 watch var可以看到是while那里,导致n越界了,fix 0) //doesn't let n reach 0 { result*=n; n--; //decrements only after the evaluation }一些快捷命令l – list
p – print print {variable}
c – continue
s – step
b - break break line_number/break [file_name]:line_number/break [file_name]:func_name
r - run
set = ENTER: pressing enter key would execute the previously executed command again. c/n/s的区别•c or continue: Debugger will continue executing until the next break point. •n or next: Debugger will execute the next line as single instruction. •s or step: Same as next,but does not treats function as a single instruction,instead goes into the function and executes it line by line 3、调试PHP程序 PHP代码开始调试,加上断点... Reading symbols from /usr/bin/php...done. (gdb) b zif_sleep Breakpoint 1 at 0x8435180: file /usr/local/src/php-5.5.23/ext/standard/basic_functions.c,line 4449. (gdb) b zif_in_array Breakpoint 2 at 0x8426923: file /usr/local/src/php-5.5.23/ext/standard/array.c,line 1215. (gdb) b zif_print_r Breakpoint 3 at 0x8438273: file /usr/local/src/php-5.5.23/ext/standard/basic_functions.c,line 5553. (gdb) b zif_var_dump Breakpoint 4 at 0x847d296: file /usr/local/src/php-5.5.23/ext/standard/var.c,line 178. (gdb) b zif_printf Function "zif_printf" not defined. Make breakpoint pending on future shared library load? (y or [n]) n (gdb) b zif_sprintf Function "zif_sprintf" not defined. Make breakpoint pending on future shared library load? (y or [n]) n (gdb) b printf Breakpoint 5 at 0x806a390 (gdb) b memcpy Breakpoint 6 at 0x8069390 (gdb) b zif_print Function "zif_print" not defined. Make breakpoint pending on future shared library load? (y or [n]) n (gdb) b zif_echo Function "zif_echo" not defined. Make breakpoint pending on future shared library load? (y or [n]) n (gdb) info b Num Type Disp Enb Address What 1 breakpoint keep y 0x08435180 in zif_sleep at /usr/local/src/php-5.5.23/ext/standard/basic_functions.c:4449 2 breakpoint keep y 0x08426923 in zif_in_array at /usr/local/src/php-5.5.23/ext/standard/array.c:1215 3 breakpoint keep y 0x08438273 in zif_print_r at /usr/local/src/php-5.5.23/ext/standard/basic_functions.c:5553 4 breakpoint keep y 0x0847d296 in zif_var_dump at /usr/local/src/php-5.5.23/ext/standard/var.c:178 5 breakpoint keep y 0x0806a390加几个断点测试一下 syntax:break [file_name]:func_name,这里大致可以看一下 echo print等不是函数了 然后开始调试 |
