GDB 是什么php
GDB 是 linux 环境下的通常功能强大的调试器,用来调试 C 或 C++ 写的程序。它能够作这些事情linux
- Start your program, specifying anything that might affect its behavior.
- Make your program stop on specified conditions.
- Examine what has happened, when your program has stopped.
- Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another.
安装centos
以 centos 7 为例,安装 GDB-8.2.1 版本数组
安装依赖app
C++ 11 编译器和 GUN make 是 GDB 必要的工具包,需先安装他们。函数
yum install gcc* -- 或者为了省事,直接把开发经常使用的工具包都安装了 yum group install "Development Tools" -- 查看是否安装成功 gcc -v # 需 4.8 以上版本
gun make 官网地址工具
安装 GDB学习
在官网上找到官方的 FTP 仓库,下载最新的版本,解压后开始安装spa
./configure --prefix=/usr/local/gdb821 make && make install 安装完成将 /usr/local/gdb821/bin 添加到 PATH 环境变量 -- 也能够直接用 yum 安装 yum install -y gdb
安装须要花比较久时间,能够洗个澡干点爱干的事。调试
gdb -v
使用示例
一个简单的示例,运行一个 PHP 脚本 gdb_test.php
<?php for($i = 0; $i < 10; $i++){ if(in_array($i,[1,9,20])){ echo $i*$i,PHP_EOL; } }
开始调试
gdb php > run /usr/local/src/gdb_test.php
这样脚本就执行成功了,实验了第一个命令。
后续再详细学习断点,单步调试等真正的实验。
附:GDB 经常使用命令