ubuntu安装gdb
:~# apt-get update
......
......
:~# apt-get install gdb
......
......
Do you want to continue? [Y/n] y
......
......
:~#
ubuntu 系统、VSCode
命令 | 命令缩写 | 命令说明 |
list | l | 显示多行源代码 |
break | b | 设置断点,程序运行到断点的位置会停下来 |
b fun | 设置一个断点breakpoint在函数”fun”的最开始 | |
b file.c:N | 在当前源文件file.c的第N行设置断点 | |
d N | 删掉delete第N行的断点 | |
info | i | 描述程序的状态 |
info break | 显示所有断点信息 | |
run | r | 开始运行程序 |
display | disp | 跟踪查看某个变量,每次停下来都显示它的值 |
step | s | 执行下一条语句,如果该语句为函数调用,则进入函数执行其中的第一条语句 |
next | n | 执行下一条语句,如果该语句为函数调用,不会进入函数内部执行(即不会一步步地调试函数内部语句) |
p | 打印内部变量值 | |
continue | c | 继续程序的运行,直到遇到下一个断点 |
set var name=v | 设置变量的值 | |
start | st | 开始执行程序,在main函数的第一条语句前面停下来 |
file | 装入需要调试的程序 | |
kill | k | 终止正在调试的程序 |
watch | 监视变量值的变化 | |
backtrace | bt | 产看函数调用信息(堆栈) |
frame | f | 查看栈帧 |
quit | q | 退出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)