显示程序第linenum行的周围的源程序。
list显示函数名为function的函数的源程序。
list显示当前行后面的源程序。
list -显示当前行前面的源程序。
set listsize设置一次显示源代码的行数。
show listsize查看当前listsize的设置。
list ,显示从first行到last行之间的源代码。
list ,显示从当前行到last行之间的源代码。
list +往后显示源代码。
搜索源代码 forward-search/search从当前行向后查找匹配某个字符串的程序行
reverse-search从当前行向后查找匹配某个字符串的程序行
指定源文件的路径某些时候,用-g编译过后的执行程序中只是包括了源文件的名字,没有路径名。GDB提供了可以让你指定源文件的路径的命令,以便GDB进行搜索。
directory加一个源文件路径到当前路径的前面。如果你要指定多个路径,UNIX下你可以使用“:”,Windows下你可以使用“;”。
directory清除所有的自定义的源文件搜索路径信息。
show directories显示定义了的源文件搜索路径。
源代码的内存 info line可以查看源代码在内存中的地址
disassemble该指令可以查看源程序的当前执行时的机器码
实验- 设置断点
(gdb) break func Breakpoint 1 at 0x1149: file tst.c, line 4.
- 查看有func函数的行的代码内存地址
(gdb) info line tst.c:func Line 4 of "tst.c" starts at address 0x1149and ends at 0x1154 .
- 使程序运行
(gdb) r
Starting program: /home/ubuntu/learn_gdb/tst
Breakpoint 1, func (n=0) at tst.c:4
4 {
- 继续运行程序
(gdb) c
Continuing.
result[1-100] = 5050
Breakpoint 1, func (n=10) at tst.c:4
4 {
- 继续运行程序
(gdb) c Continuing. result[1-250] = 31125 [Inferior 1 (process 3016500) exited normally]
- 查看此时有func函数的行的代码内存地址
(gdb) info line tst.c:func Line 4 of "tst.c" starts at address 0x555555555149and ends at 0x555555555154 .
- 显示func函数的汇编代码
(gdb) disassemble func Dump of assembler code for function func: 0x0000555555555149 <+0>: endbr64 0x000055555555514d <+4>: push %rbp 0x000055555555514e <+5>: mov %rsp,%rbp 0x0000555555555151 <+8>: mov %edi,-0x14(%rbp) 0x0000555555555154 <+11>: movl $0x0,-0x8(%rbp) 0x000055555555515b <+18>: movl $0x0,-0x4(%rbp) 0x0000555555555162 <+25>: jmp 0x55555555516e参考0x0000555555555164 <+27>: mov -0x4(%rbp),%eax 0x0000555555555167 <+30>: add %eax,-0x8(%rbp) 0x000055555555516a <+33>: addl $0x1,-0x4(%rbp) 0x000055555555516e <+37>: mov -0x4(%rbp),%eax --Type for more, q to quit, c to continue without paging--c 0x0000555555555171 <+40>: cmp -0x14(%rbp),%eax 0x0000555555555174 <+43>: jl 0x555555555164 0x0000555555555176 <+45>: mov -0x8(%rbp),%eax 0x0000555555555179 <+48>: pop %rbp 0x000055555555517a <+49>: retq End of assembler dump.
用GDB调试程序(四)



