代码运行过程中,难免因各种原因引起crash,如果crash 发生时恰好capture 当时的堆栈信息,对定位错误将是大功一件,然而有时候看到满满的堆栈信息,却不知从何开始入手, 本文介绍几个著名的Linux so 查看工具,掌握它们可能会有事半功倍的效果。
比如获取下列信息:
tm::TcpHandler::Open(tm::iohandler_paraset*)+300
这里已经比较明确指出在Open 函数地址偏移 300 的地方, 那么是否可以获得更详细的信息呢?
Linux so库查看工具:
- objdump
objdump可用来反汇编so库,查看文件可能带有的附加信息。 详细使用时通过 –help 了解,常用参数有:
-d, --disassemble Display assembler contents of executable sections
-D, --disassemble-all Display assembler contents of all sections
-S, --source Intermix source code with disassembly, 这个比较重要
-s, --full-contents Display the full contents of all sections requested
- nm
nm用来列出目标文件的符号清单。详细使用时通过 –help 了解,常用参数有:
-a, --debug-syms Display debugger-only symbols
-l, --line-numbers Use debugging information to find a filename and line number for each symbol
- add2line
add2line 将指令的地址和可执行映像转换成文件名、函数名和源代码行数的工具。详细使用时通过 –help 了解。
-a --addresses Show addresses
-b --target=<bfdname> Set the binary file format
-e --exe=<executable> Set the input file name (default is a.out)
-f --functions Show function names