gdb

46 篇文章 1 订阅

0.绪

GDB(GNU Debugger)是类 Unix(如 Linux)操作系统下的一款开源的 C/C++ 程序调试器。

要使用gdb进行调试,需要在gcc/g++命令选项加“-g”,去掉调试信息使用“strip”命令。

例如:下面fork.c文件:

#include<stdio.h>
#include<unistd.h>
int main(){
        if(  ( fork()&& fork()  )  ||    (  fork()&&fork() )  );
        printf("fork\n");
        //return 0;
}

 编译:

gcc -g -o fork fork.c

调试:

gdb fork
bo@bo:/home/share/test$ gdb fork
GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git
Copyright (C) 2018 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 "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from fork...done.
(gdb)

去掉调试信息:

strip fork

2.gdb命令

命令缩写说明
runr运行程序
continuec继续执行,到下一个断点处
nextn单步跟踪程序
steps则进入函数
untilu运行程序直到退出循环体
until+行号 运行至某行
finishfi运行程序,直到当前函数完成返回
call 调用程序中可见的函数,并传递“参数”
return 结束当前调用函数并返回指定值
jumpj前程序执行流跳转到指定行
printp打印变量或寄存器值
backtracebt当前运行的堆栈列表
breakb设置断点
deletedel删除断点
enable 启用断点
disable 禁用断点
watch 监视变量
listl查看源代码
disassembledis查看汇编代码
info 查看当前断点设置情况
set args 设置程序启动命令行参数
show args 查看设置的命令行参数
layout 分割窗口
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值