错误解决
在写某个程序时,出现错误,想要使用gdb进行调试,但是在使用b
命令设置断点后出现如下错误,并且运行后不能在断点处暂停。
No symbol table is loaded. Use the "file" command.
Make breakpoint pending on future shared library load? (y or [n])
经过搜索资料发现是在编译的时候没有加上-g
选项,导致无法进行断点调试,因此在Makefile
文件中的CPPFLAGS
(如果是C语言就是CFLAGS
)中加上-g
选项后,就能够正常进行断点调试了。
gdb的简单使用方法
- 设置断点
- 根据函数名设置断点:
b func_name
- 根据代码行位置设置断点:
b src/mycode.cc:81
gdb运行到该文件的地81行处中断。 - 根据运行时的地址进行设置断点:
b *0x5859c0
- 根据函数名设置断点:
- 跳入或跳出指令
- 执行到某个函数时不进入函数体内:
n
- 执行到某个函数时进入函数体内:
s
- 跳出当前函数(执行完当前函数返回到调用它的函数):
f
- 执行到某个函数时不进入函数体内:
参考资料
- No symbol table is loaded. Use the “file” command.解决方法: https://blog.csdn.net/pinghegood/article/details/8512747
- gdb几种设置断点的方式: https://blog.csdn.net/wojiuguowei/article/details/82386567