Linux下gdb调试命令介绍

GNU Debugger(GDB)是GNU项目的一部分,是功能强大且灵活的调试工具,广泛应用于调试C、C++、Fortran和其他编程语言的程序,能帮助开发者检查和修改程序的运行状态,从而识别和修复错误。以下是一些Linux系统下常用的gdb调试命令: 1. **进入gdb并加载程序**:在终端输入 `gdb` 进入gdb环境,之后输入 `file test` 加载名为 `test` 的可执行文件。示例如下: ```plaintext ➜ example gdb GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1 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". (gdb) file test ``` 2. **指定行号查看代码**:使用 `l 行号` 命令指定行号查看代码,例如 `(gdb) l 10` 会以第10行为中心显示代码。示例如下: ```plaintext (gdb) l 10 5 #include<stdlib.h> 6 #include<unistd.h> 7 using namespace std; 8 int main() 9 { 10 char arr[102] = { 0 }; 11 const char* Lop = "|/-\\"; 12 memset(arr, 0, sizeof(arr)); 13 int i = 0; 14 for(i = 0; i <= 100; i++) ``` 3. **开始调试**:使用 `r` 命令开始调试程序。 需要注意的是,Linux gcc/g++ 编译出来的二进制程序默认是release模式,要使用gdb调试,必须在源代码生成二进制程序的时候加上 `-g` 选项 [^1]。
评论 7
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

dvlinker

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

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

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

打赏作者

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

抵扣说明:

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

余额充值