gpt4 book ai didi

c++ - gdb - 列出当前函数的源而不输入其名称

转载 作者:IT老高 更新时间:2023-10-28 22:13:11 27 4
gpt4 key购买 nike

在 GDB 中,命令:

list function

将列出该函数的所有源代码。

是否有一个命令可以列出您当前所在函数的所有源代码,而无需您手动输入函数名称?

最佳答案

(gdb) help list
List specified function or line.
With no argument, lists ten more lines after or around previous listing.
"list -" lists the ten lines before a previous ten-line listing.
One argument specifies a line, and ten lines are listed around that line.
Two arguments with comma between specify starting and ending lines to list.
Lines can be specified in these ways:
LINENUM, to list around that line in current file,
FILE:LINENUM, to list around that line in that file,
FUNCTION, to list around beginning of that function,
FILE:FUNCTION, to distinguish among like-named static functions.
*ADDRESS, to list around the line containing that address.
With two args if one is empty it stands for ten lines away from the other arg.

*ADDRESS 很有趣。

在 x86/x64 上,当前指针位于 rip 寄存器中,因此:

(gdb) list *$pc
0x7ffff7b018a0 is at ../sysdeps/unix/syscall-template.S:82.
77 in ../sysdeps/unix/syscall-template.S

示例来自 cat 命令,因为我手头没有任何调试信息。

关于c++ - gdb - 列出当前函数的源而不输入其名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12824251/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com