1. gdb调试打开方式
1.直接打开
gdb main
2.先进入再打开
hsm:Templates/ $ gdb [9:37:48]
GNU gdb (GDB) 9.2
Copyright (C) 2020 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-pc-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 main
Reading symbols from main...
3.打开的同时,不显示版本等信息
gdb -q main
2. 运行
- run (r)
作用是运行程序,当遇到断点的时候,停止运行,等待下一步命令 - continue (c)
继续执行,到下一个断点处(或运行结束) - next
单步跟踪程序,当遇到函数调用的时候,不会进入函数体 - step
单步跟踪程序,当遇到函数调用的时候,会进入函数体
disas
- disas main
反汇编
Dump of assembler code for function main:
0x0000000000001139 <+0>: push %rbp
0x000000000000113a <+1>: mov %rsp,%rbp
0x000000000000113d <+4>: sub $0x10,%rsp
0x0000000000001141 <+8>: mov %edi,-0x4(%rbp)
0x0000000000001144 <+11>: mov %rsi,-0x10(%rbp)
0x0000000000001148 <+15>: lea 0xeb5(%rip),%rdi # 0x2004
0x000000000000114f <+22>: mov $0x0,%eax
0x0000000000001154 <+27>: callq 0x1030 <printf@plt>
0x0000000000001159 <+32>: mov $0x0,%eax
0x000000000000115e <+37>: leaveq
0x000000000000115f <+38>: retq
End of assembler dump.
3. 断点
- break n
在第n行设置断点 - break func
在函数gunc()的入口处设置断点 - delete n
删除第n个断点 - disable
暂停第n行的断点 - enable
开启第n个断点 - clear n
清除第n行的断点 - info b
显示当前程序的断点设置情况 - delete breakpoints
删除所有断点
4. info
可以查看比如内存,函数,栈等信息
比如
- info functions
(gdb) info functions
All defined functions:
File main.c:
2:int main(int, char **);
Non-debugging symbols:
0x0000000000001000 _init
0x0000000000001030 printf@plt
0x0000000000001040 _start
0x0000000000001070 deregister_tm_clones
0x00000000000010a0 register_tm_clones
0x00000000000010e0 __do_global_dtors_aux
0x0000000000001130 frame_dummy
0x0000000000001160 __libc_csu_init
0x00000000000011d0 __libc_csu_fini
0x00000000000011d8 _fini
(gdb)
5. 退出
(gdb) quit