判断linux库文件在编译的时候与没有用 -g 选项

先写一个简单的文件1.c:

$ cat 1.c
void foo(void)
{
}

然后编译两个库,一个不加 -g, 一个加:

gcc 1.c  -c

gdb -shared -fpic -o lib1.so 1.o

cp 1.c 2.c

gcc -c -g 2.c

gcc -shared -fpic -o lib2.so 2.o

下面介绍几种判断的方法:

1. 使用 objdump

$ objdump --debugging lib2.so  | grep debug
Contents of the .debug_aranges section:
  Offset into .debug_info:  0x0
Contents of the .debug_info section:
Contents of the .debug_abbrev section:
Raw dump of debug contents of section .debug_line:
Contents of the .debug_str section:

可以看出,对于使用 -g的库, objdump --debugging会有很多 debug相关的信息输出。对于 没有加-g的库,则没有这样的输出.

也可用 readelf -w 或者 objdump -W

2.使用 gdb.

e$ gdb lib2.so 
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 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 "i686-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 lib2.so...done.

注意有输出: Reading symbols from lib2.so...done.

对于 lib1.so,输出为 Reading symbols from lib1.so...(no debugging symbols found)...done.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值