【Linux系统 03】gdb调试器

在Linux中,gdb是GNU调试器(GNU debugger)的缩写。它是一个强大的命令行调试工具,用于调试C、C++和其他编程语言的程序。

一、生成可调式程序

gcc 加上 -g 选项可生成C语言可调式程序。

(base) [root@localhost 01_test]# vim test1.c 
(base) [root@localhost 01_test]# cat test1.c 
#include <stdio.h>

int main() 
{
        int a = 0;
        int b = 0;
        return 0;
}
(base) [root@localhost 01_test]# vim makefile 
(base) [root@localhost 01_test]# cat makefile 
all: test1 test1_g

test1: test1.c
        gcc -o $@ $^ 

test1_g: test1.c
        gcc -o $@ $^ -g


.PHONY: clean
clean:
        rm -rf test1 test1_g
(base) [root@localhost 01_test]# make
gcc -o test1 test1.c 
gcc -o test1_g test1.c -g
(base) [root@localhost 01_test]# ls
makefile  test1  test1.c  test1_g
(base) [root@localhost 01_test]# 

二、调试程序指令

  • gdb [exe_filename]        开始调试
  • quit                                退出调试
  • r                                     开始调试,若无断点,则直接运行结束(run)
  • b + 行号                         给这一行打断点(break point)
  • info b                             查看断点
  • d + 断点编号                  删掉某断点(delete)
  • n                                    逐过程调试(next)
  • s                                    逐语句调试(step)
  • c                                    进入下一个断点(continue)
  • bt                                  查看调用堆栈
  • finish                            将函数调试结束
  • print + 变量                  显示变量的值
  • display  + 变量             设置常显示
  • undisplay + 常显示编号             取消常显示
  • enable/disable + 断点编号         打开/关闭断点

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AllinTome

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值