Sama Azari
Sama Azari

Reputation: 489

How to record watch command output to a file in gdb

I want to record the register changes using watch command in gdb which is like this:

(gdb) watch $register-name

gdb stop whenever the register changes in the application and I have to press c to continue debugging. Is there any way to instead of hitting enter for endless time, I just ask gdb to save all the changes in the register to a file?

Upvotes: 0

Views: 451

Answers (1)

Employed Russian
Employed Russian

Reputation: 213456

I have to press c to continue debugging.

Note that pressing <Enter> will repeat previous command (e.g. previous c).

Is there any way to instead of hitting enter for endless time, I just ask gdb to save all the changes in the register to a file?

Sure:

(gdb) watch $rax
Watchpoint 2: $rax

(gdb) commands 2
Type commands for breakpoint(s) 2, one per line.
End with a line saying just "end".
>c
>end

# This is to prevent stop after every screen-full of output
(gdb) set height 0

(gdb) set logging on
Copying output to gdb.txt.

(gdb) continue

Voila: you now have all the changes in gdb.txt

Upvotes: 1

Related Questions