[英]How can I tell if a library was compiled with -g?
I have some compiled libraries on x86 Linux and I want to quickly determine whether they were compiled with debugging symbols.我在 x86 Linux 上有一些编译的库,我想快速确定它们是否使用调试符号编译。
The suggested command 建议的命令
objdump --debugging libinspected.a
objdump --debugging libinspected.so
gives me always the same result at least on Ubuntu/Linaro 4.5.2: 至少在Ubuntu / Linaro 4.5.2上给我总是相同的结果:
libinspected.a: file format elf64-x86-64
libinspected.so: file format elf64-x86-64
no matter whether the archive/shared library was built with or without -g
option 无论归档/共享库是使用或不使用-g
选项构建的
What really helped me to determine whether -g
was used is readelf tool: 真正帮助我确定是否使用-g
是readelf工具:
readelf --debug-dump=decodedline libinspected.so
or 要么
readelf --debug-dump=line libinspected.so
This will print out set of lines consisting of source filename, line number and address if such debug info is included into library , otherwise it'll print nothing . 这将打印出包含源文件名,行号和地址的行集, 如果这样的调试信息包含在库中 ,否则它将不打印任何内容 。
You may pass whatever value you'll find necessary for --debug-dump
option instead of decodedline
. 你可以传递你需要的任何值--debug-dump
选项而不是decodedline
。
If you're running on Linux, use objdump --debugging
. 如果您在Linux上运行,请使用objdump --debugging
。 There should be an entry for each object file in the library. 库中的每个目标文件都应该有一个条目。 For object files without debugging symbols, you'll see something like: 对于没有调试符号的目标文件,您将看到如下内容:
objdump --debugging libvoidincr.a
In archive libvoidincr.a:
voidincr.o: file format elf64-x86-64
If there are debugging symbols, the output will be much more verbose. 如果有调试符号,输出将更加冗长。
nm -a <lib>
will print all symbols from library, including debug ones. nm -a <lib>
将打印库中的所有符号,包括调试符号。
So you can compare the outputs of nm <lib>
and nm -a <lib>
- if they differ, your lib contains some debug symbols. 因此,您可以比较nm <lib>
和nm -a <lib>
- 如果它们不同,则lib包含一些调试符号。
What helped is: 有用的是:
gdb mylib.so
It prints when debug symbols are not found: 它在未找到调试符号时打印:
Reading symbols from mylib.so...(no debugging symbols found)...done.
Or when found: 或者在找到时:
Reading symbols from mylib.so...done.
None of earlier answers were giving meaningful results for me: libs without debug symbols were giving lots of output, etc. 以前的答案都没有为我提供有意义的结果:没有调试符号的libs提供了大量输出等。
On OSX you can use dsymutil -s
and dwarfdump
. 在OSX上,您可以使用dsymutil -s
和dwarfdump
。
Using dsymutil -s <lib_file> | more
使用dsymutil -s <lib_file> | more
dsymutil -s <lib_file> | more
you will see source file paths in files that have debug symbols, but only the function names otherwise. 您将在具有调试符号的文件中看到dsymutil -s <lib_file> | more
源文件路径,否则只会看到函数名称。
Answers suggesting the use of objdump --debugging
or readelf --debug-dump=...
don't work in the case that debug information is stored in a file separate from the binary, ie the binary contains a debug link section. 答案建议使用objdump --debugging
或readelf --debug-dump=...
在调试信息存储在与二进制文件分开的文件中的情况下不起作用,即二进制文件包含调试链接部分。 Perhaps one could call that a bug in readelf
. 也许有人可以称之为readelf
中的一个错误。
The following code should handle this correctly: 以下代码应正确处理:
# Test whether debug information is available for a given binary
has_debug_info() {
readelf -S "$1" | grep -q " \(.debug_info\)\|\(.gnu_debuglink\) "
}
See Separate Debug Files in the GDB manual for more information. 有关详细信息,请参阅GDB手册中的单独调试文件 。
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/developer_guide/debugging https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/developer_guide/debugging
The command readelf -wi file is a good verification of debuginfo, compiled within your program.命令 readelf -wi 文件是对调试信息的良好验证,在您的程序中编译。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.