GDB 简单调试

ubuntu安装gdb

:~# apt-get update
......
......
:~# apt-get install gdb 
......
......
Do you want to continue? [Y/n] y
......
......
:~#

ubuntu 系统、VSCode 

命令命令缩写命令说明
listl显示多行源代码
breakb设置断点,程序运行到断点的位置会停下来
 b fun设置一个断点breakpoint在函数”fun”的最开始
 b file.c:N在当前源文件file.c的第N行设置断点
 d N删掉delete第N行的断点
infoi描述程序的状态
info break 显示所有断点信息
runr开始运行程序
displaydisp跟踪查看某个变量,每次停下来都显示它的值
steps执行下一条语句,如果该语句为函数调用,则进入函数执行其中的第一条语句
nextn执行下一条语句,如果该语句为函数调用,不会进入函数内部执行(即不会一步步地调试函数内部语句)
printp打印内部变量值
continuec继续程序的运行,直到遇到下一个断点
set var name=v设置变量的值
startst开始执行程序,在main函数的第一条语句前面停下来
file 装入需要调试的程序
killk终止正在调试的程序
watch 监视变量值的变化
backtracebt产看函数调用信息(堆栈)
framef查看栈帧
quitq退出GDB环境

$:~/Documents/TSRTC-Workspace/EffectiveCTest$ which gdb
/usr/bin/gdb
$:~/Documents/TSRTC-Workspace/EffectiveCTest$ cd build/
$:~/Documents/TSRTC-Workspace/EffectiveCTest/build$ gdb ./EffectiveCTest 
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 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 ./EffectiveCTest...done.
(gdb) list
1       #include <iostream>
2
3       int main(int, char**) {
4           std::cout << "Hello, world!\n";
5
6           int n = 10;
7           n++;
8           std::cout << "Hello, world!\n" << n;
9           n++;
10          std::cout << "Hello, world!\n" << n;
(gdb) break 6
Breakpoint 1 at 0x4009a4: file $$/EffectiveCTest/main.cpp, line 6.
(gdb) r
Starting program: /home/reykou/Documents/TSRTC-Workspace/EffectiveCTest/build/EffectiveCTest 
Hello, world!

Breakpoint 1, main () at $$/EffectiveCTest/main.cpp:6
6           int n = 10;
(gdb) s
7           n++;
(gdb) p
The history is empty.
(gdb) disp n
1: n = 10
(gdb) s
8           std::cout << "Hello, world!\n" << n;
1: n = 11
(gdb) 

 参考文献 http://www.gnu.org/software/gdb/documentation/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值