简体   繁体   English

gdb 中是否存在自动“打印本地”命令?

[英]Does an automatic "print locals" command exist in gdb?

Is there a gdb command that does what info locals does but automatically (ie after every step or breakpoint)?是否有一个 gdb 命令可以自动执行info locals的操作(即在每个步骤或断点之后)? I find info locals to be very essential, but I would much rather not have to type it everytime.我发现本地信息非常重要,但我宁愿不必每次都输入它。 It would be a bummer if something like that is not implemented.如果没有实施类似的事情,那将是一个遗憾。

Also I'm not looking to "watch" or "display" a specific variable or two.此外,我不希望“观察”或“显示”一个或两个特定变量。 Display all, everytime, that's what I'm looking for.显示所有,每次,这就是我正在寻找的。

Display all, everytime, that's what I'm looking for.显示所有,每次,这就是我正在寻找的。

(gdb) define hook-stop
info locals
end

Example:例子:

// foo.c
int foo()
{
  int z = 1;
  int zz = 2;
  int zzz = 3;
  return z + zz + zzz;
}

int main()
{
  int x = 42;
  int y = 24;
  foo();
  return x;
}

gcc -g foo.c && gdb -q ./a.out

(gdb) define hook-stop
Type commands for definition of "hook-stop".
End with a line saying just "end".
>info locals
>end
(gdb) start

Temporary breakpoint 1 at 0x1159: file foo.c, line 11.
Starting program: /tmp/a.out
x = 0
y = 0

Temporary breakpoint 1, main () at foo.c:11
11        int x = 42;
(gdb) n
x = 42
y = 0
12        int y = 24;
(gdb) n
x = 42
y = 24
13        foo();
(gdb) s
z = 21845
zz = 1431654784
zzz = 0
foo () at foo.c:3
3         int z = 1;
(gdb) n
z = 1
zz = 1431654784
zzz = 0
4         int zz = 2;
(gdb) n
z = 1
zz = 2
zzz = 0
5         int zzz = 3;
(gdb) n
z = 1
zz = 2
zzz = 3
6         return z + zz + zzz;
(gdb) n
z = 1
zz = 2
zzz = 3
7       }
(gdb)
x = 42
y = 24
main () at foo.c:14
14        return x;
(gdb) q

Documentation here .文档在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM