【Linux应用】 GDB调试工具常见用法

本文详细介绍了GDB的使用流程,从启动GDB、查看源码到设置断点、单步执行、查看变量,再到退出GDB,涵盖了GDB的基本使用命令,包括运行、设置断点、查看源码、打印表达式和查看运行信息。此外,还讨论了GDB在多进程调试中的应用。
摘要由CSDN通过智能技术生成

一、gdb简介

GDB是一个由GNU开源组织发布的、UNIX/LINUX操作系统下的、基于命令行的、功能强大的程序调试工具。 对于一名Linux下工作的c/c++程序员,gdb是必不可少的工具;

二、gdb使用流程

1、启动gdb

编译一个测试程序,-g表示可以调试,命令如下:

gcc -g test.c -o test

启动gdb,命令如下:

gdb test 
gdb -q test //表示不打印gdb版本信息,界面较为干净;

测试如下:

root@ubuntu:/home/eit/c_test# gdb test
GNU gdb (Ubuntu 7.7-0ubuntu3) 7.7
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <GNU General Public License>
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:
<Bugs in GDB>.
Find the GDB manual and other documentation resources online at:
<GDB Documentation>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from test...done.
(gdb) q
root@ubuntu:/home/eit/c_test# gdb -q test
Reading symbols from test...done.
(gdb) 

到此gdb启动完成!

2、查看源码

list(简写 l): 查看源程序代码,默认显示10行,按回车键继续看余下的。

测试如下:

 (gdb) list 
9	#define MAX_SIZE
10	
11	int main()
12	{
   
13	    int i,fd,size1 ,size2 ,len;
14	    char *buf = "helo!I'm li hanrui ";
15	    char buf_r[15];
16	    len = strlen(buf);
17	    fd = open("/home/hello.txt",O_CREAT | O_TRUNC | O_RDWR,
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值