如何从 gdb 的 "info symbol" 命令中获取确切位置

How to get the exact location from gdb's "info symbol" command

我正在使用 GDB 进行调试。当我输入 "info symbol 0xABCD" 时,我得到以下结果,

sample_function + 123 in section init

我知道确切位置在 sample_function() 附近,偏移量为 123,但如何在 C 代码中找到它?我还没有从互联网上找到任何关于这个的资源。感谢您的帮助。

how do I locate it in the C code?

你可以这样做:

(gdb) disas/m 0xABCD

来自"help disas":

With a /m modifier, source lines are included (if available).

或者,此命令:addr2line -fe /path/to/binary 0xABCD(运行 在 GDB 之外)应该打印源位置(如果二进制文件有调试行信息)。