$ gdb -q ./output
(gdb) break main
Breakpoint 1 at 0x400846: file test_lambda.cpp, line 11.
(gdb) run
Starting program: /home/mantosh/practice/notesofprogramming/gcc4.9/output
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Breakpoint 1, main () at test_lambda.cpp:11
11 foo();
//whenever you just type command "p", it checks for the last command
used. As we have
not used "p" anytime in our debug session for this particular program, it shows the
message "history is empty"//
(gdb) p
The history is empty.
// This command would give the information about all registers
(gdb) info registers
rax 0x7ffff73a3548 140737341175112
rbx 0x0 0
rcx 0x60 96
rdx 0x7fffffffe1b8 140737488347576
rsi 0x7fffffffe1a8 140737488347560
rdi 0x1 1
rbp 0x7fffffffe0c0 0x7fffffffe0c0
rsp 0x7fffffffe0c0 0x7fffffffe0c0
r8 0x7ffff7dd8240 140737351877184
r9 0x7ffff7dbddb0 140737351769520
r10 0x7fffffffddf0 140737488346608
r11 0x7ffff7023880 140737337505920
r12 0x4006f0 4196080
r13 0x7fffffffe1a0 140737488347552
r14 0x0 0
r15 0x0 0
rip 0x400846 0x400846 <main()+4>
eflags 0x246 [ PF ZF IF ]
cs 0x33 51
ss 0x2b 43
ds 0x0 0
es 0x0 0
fs 0x0 0
gs 0x0 0
// Now we can print the rip(instruction pointer) using "p" command.
After this if we
continue to debug our program, we can just type "p" and it would print about "rip"
as this is this was the argument passed in command "p" last time during the debug.
(gdb) p $rip
$1 = (void (*)(void)) 0x400846 <main()+4>
(gdb) step
foo () at test_lambda.cpp:4
4 int x = 10;
(gdb) p
$2 = (void (*)(void)) 0x400846 <main()+4>
(gdb) step
5 int y= 20;
(gdb) p
$3 = (void (*)(void)) 0x400846 <main()+4>
(gdb) n
6 x = x + y;
(gdb) p
$4 = (void (*)(void)) 0x400846 <main()+4>
(gdb) n
7 std::cout<<x<<std::endl;
(gdb) p
$5 = (void (*)(void)) 0x400846 <main()+4>
(gdb) c
Continuing.
30
[Inferior 1 (process 3226) exited normally]
(gdb)