【问题标题】:Is there any way to extract variables that are being passed to a particular function as parameters in a given c code?有没有办法提取作为给定 c 代码中的参数传递给特定函数的变量?
【发布时间】:2020-12-12 13:52:35
【问题描述】:
有什么方法可以提取在给定 c 代码中作为参数传递给特定函数的变量?
举个例子,
main()
{
int a = 10;
float b = 2.0f;
funcA(a,b);
}
需要提取变量a和变量b在给定C代码中传递给funcA的信息。
有没有办法使用 gdb 及其函数断点提取这些信息?
【问题讨论】:
标签:
c
variables
gdb
code-analysis
information-retrieval
【解决方案1】:
当您在任何函数中键入frame 时,将为您提供函数的参数信息。
以下是一些其他命令,您可以使用这些命令来了解有关局部变量和参数的更多信息。
info locals
frame
info args
更多gdb 命令
样本:
(gdb) b main
Note: breakpoint 1 also set at pc 0x40053e.
Breakpoint 2 at 0x40053e: file main.c, line 6.
(gdb) r
Starting program: /home/a.out
Breakpoint 1, main () at main.c:6
6 int a = 10;
(gdb) n
7 float b = 2.0f;
(gdb) info locals
a = 10
b = 0
x = 0
(gdb) frame
#0 main () at main.c:7
7 float b = 2.0f;
(gdb) next
9 int x = funcA(a,b);
(gdb) step
funcA (a=10, b=2) at main.c:16
16 int sum = 0;
(gdb) frame
#0 funcA (a=10, b=2) at main.c:16
16 int sum = 0;
(gdb) info args
a = 10
b = 2
(gdb) info locals
sum = 0
(gdb) p a
$1 = 10
(gdb) print b
$2 = 2
(gdb)