info locals command
Displays information about the local variables corresponding to the current stack frame.
Syntax
Remarks
The info locals command displays the local variable values in the current frame. You can select frames using the frame, up and down commands.
Note that the info locals command does not display the information about the function arguments. Use the info args command to list function arguments.
Examples
To demonstrate the info locals command we will debug a sample program listed below:
void func(int arg)
{
printf("func(%d)\n", arg);
}
int main(int argc, char *argv[])
{
int localVar1 = 1, localVar2 = 2;
func(localVar1 + localVar2);
return 0;
}
We will run the program, set a breakpoint in func() and use the info locals command to display the local variables in main():
Breakpoint 1 at 0x80483ea: file test.cpp, line 5.
(gdb) r
Starting program: /home/testuser/test
Breakpoint 1, func (arg=3) at test.cpp:5
5 printf("func(%d)arg);
(gdb) backtrace
#0 func (arg=3) at test.cpp:5
#1 0x0804842a in main (argc=1, argv=0xbffff784) at test.cpp:11
(gdb) info locals
No locals.
(gdb) up
#1 0x0804842a in main (argc=1, argv=0xbffff784) at test.cpp:11
11 func(localVar1 + localVar2);
(gdb) info locals
localVar1 = 1
localVar2 = 2
(gdb) down
#0 func (arg=3) at test.cpp:5
5 printf("func(%d)arg);
(gdb) info args
arg = 3
(gdb)
Compatibility with VisualGDB
You can execute the info locals command manually using the GDB Session window in Visual Studio. However it is recommended to use the Locals window to see the values of the local variables in the currently selected stack frame.