gdb:“没有符号表被加载”
当试图在gdb中添加断点时,我不断收到这个错误信息。
我用这些命令来编译:
gcc -g main.c utmpib2.c -o main.o and: cc -g main.c utmpib2.c -o main.o and also: g++ -g main.c utmpib2.c -o main.o 我也试过“-ggdb”而不是“-g”,我仍然得到这个错误信息。
然后我执行gdb:
 $gdb 
在gdb中:
 (gdb)exec-file main.o (gdb)break 59 No symbol table is loaded. Use the "file" command. 
	
 首先,你有什么是一个完全编译的程序,而不是一个目标文件,所以放下.o扩展名。 现在,请注意错误信息是什么,它告诉你如何解决你的问题:“没有加载符号表, 使用”file“命令 。 
 (gdb) exec-file test (gdb) b 2 No symbol table is loaded. Use the "file" command. (gdb) file test Reading symbols from /home/user/test/test...done. (gdb) b 2 Breakpoint 1 at 0x80483ea: file test.c, line 2. (gdb) 
或者只是在命令行上传递程序。
 $ gdb test GNU gdb (GDB) 7.4 Copyright (C) 2012 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> [...] Reading symbols from /home/user/test/test...done. (gdb) b 2 Breakpoint 1 at 0x80483ea: file test.c, line 2. (gdb) 
您必须添加额外的参数-g,它会生成源级别的debugging信息。 它会看起来像:
 gcc -g prog.c 
之后,你可以用普通的方式使用gdb。
我有同样的问题,我跟着这个post ,它解决了我的问题。
遵循以下2个步骤:
-  确保优化级别是-O0
-  编译程序时添加-ggdb标志
祝你好运!