使用gdb调试出现 No debugging symbols found in a.out

使用常规的gcc编译或者使用带调式信息-g的编译都有可能会在使用gdb工具的时候出现No debugging symbols found in a.out错误。

1. 常规编译

使用常规编译生成的可执行文件正常一定会出现No debugging symbols found in a.out错误。

imaginemiracle@ubuntu:test$ ls
test.c
imaginemiracle@ubuntu:test$ gcc test.c 

imaginemiracle@ubuntu:test$ gdb a.out 
Reading symbols from a.out...
(No debugging symbols found in a.out)
(gdb) 

2.带调试编译

即使使用带调试信息-g编译时,有时候也会出现这种情况。

imaginemiracle@ubuntu:test$ gcc -g test.c 
imaginemiracle@ubuntu:test$ ls
a.out  test.c

imaginemiracle@ubuntu:test$ gdb a.out 
Reading symbols from a.out...
(No debugging symbols found in a.out)
(gdb) 

3. 解决办法

我们先使用-c -g生成带调试信息的只进行过预处理、编译、汇编,但没有被链接的目标文件,再利用目标文件链接、重定位后生成可执行文件,使用这个可执行文件便不会出现问题。

imaginemiracle@ubuntu:test$ rm a.out 
imaginemiracle@ubuntu:test$ gcc -c -g test.c 
imaginemiracle@ubuntu:test$ ls
test.c  test.o
imaginemiracle@ubuntu:test$ gcc test.o
maginemiracle@ubuntu:test$ gdb a.out 
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 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-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 a.out...
(gdb) l
1	int main(int argc, char **argv)
2	{
3	    int a = 10;
4	    int b = 20;
5	
6	    int result = 0;
7	
8	    result = a + b / a;
9	
10	    return 0;
(gdb) 
  • 6
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Imagine Miracle

爱你哟 =^ v ^=

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值