如何在命令行中使用 Addr2Line

how to use addr2line in commandline

本文关键字:Addr2Line 命令行      更新时间:2023-10-16

如何使用addr2line?我有一个程序,可以回溯它在崩溃前访问的最后 10 个地址。但是如果我使用这些地址来添加 addr2line 像

addr2line -e test [address]

它只是给了我

??:0

有没有一种特殊的编译方法来编译使用addr2line,就像我们使用ggdb使用GDB一样?

您需要将一些调试信息编译到可执行文件中。

例如
$ gcc t.c                         # debug information not requested
$ gdb ./a.out 
...
(gdb) break main
Breakpoint 1 at 0x400588
(gdb) q
$ addr2line -e a.out 0x400588
??:0                              # no information returned
$ gcc -g t.c                      # default debug information requested with -g
$ addr2line -e a.out 0x400588    
t.c:4                             # line information returnedd
$