加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

如何使用GDB调试PHP程序

发布时间:2020-05-23 18:27:31 所属栏目:PHP 来源:互联网
导读:GDB是GNU开源组织发布的一个强大的UNIX下的程序调试工具。如果你是在 UNIX平台下做软件,你会发现GDB这个调试工具有比VC、BCB的图形化调试器更强大的功能。同时GDB也具有例如ddd这样的图形化的调试端

(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: ... Reading symbols from /code/main...done. (gdb) l

warning: Source file is more recent than executable.
1 #include
2 using namespace std;
3 long factorial(int n);
4
5 int main()
6 {
7 int n(0);
8 cin>>n;
9 long val=factorial(n);
10 cout<<val<<endl;
(gdb)

设置断点 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 = watch

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 6 breakpoint keep y 0x08069390 (gdb)

加几个断点测试一下 syntax:break [file_name]:func_name,这里大致可以看一下 echo print等不是函数了

然后开始调试

value $2 = {lval = 1515870810,handlers = 0x5a5a5a5a}} (gdb) p return_value->value->lval $3 = 1515870810

我们还可以使用内置的gdbinit来调试

查看当前堆栈,PHP内核的执行过程

查看代码段

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读