Does an automatic "print locals" command exist in gdb?
Is there a gdb command that does what info locals
does but automatically (i.e after every step or breakpoint)? 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.