一般来说,GDB主要完成下面四个方面的功能:
(1)启动你的程序,可以按照你的自定义的要求随心所欲的运行程序。
(2)可让被调试的程序在你所指定的调置的断点处停住。(断点可以是条件表达式)
(3)当程序被停住时,可以检查此时你的程序中所发生的事。
(4)动态的改变你程序的执行环境。
1、简介
GDB是GNU开源组织发布的一个强大的UNIX下的程序调试工具。如果你是在 UNIX平台下做软件,你会发现GDB这个调试工具有比VC、BCB的图形化调试器更强大的功能。同时GDB也具有例如ddd这样的图形化的调试端。
2、调试C/C++程序
直接上代码了
#include<iostream>using namespace std;long factorial(int n); int main(){int n(0);cin>>n;long val=factorial(n);cout<<val<<endl;cin.get();return 0;}long factorial(int n){long result(1);while(n--){ result*=n;} return result;}编译
1
g++ k.cpp -g -Wall -Werror -o main
开始调试
[root@localhost code]# gdb ./mainGNU gdb (GDB) Red Hat Enterprise Linux (7.2-83.el6)Copyright (C) 2010 Free Software Foundation, Inc.License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>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:<http://mon->function_name $26 = 0x8af1841 "in_array"(gdb) p execute_data_ptr->op_array->filename $27 = 0xb7fbc8e8 "/code/kk.php"还可以加一下监控watch、设置一些调试变量set 等等
其他的调试工具还有 strace 查看系统调用、ltrace 查看类库的调用、vld查看opcode。
以上内容是小编给大家分享的关于如何使用GDB调试PHP程序的全部内容,希望大家喜欢。