C – How do I restart naming GDB’s internal variables from $1?

How do I restart naming GDB’s internal variables from $1?… here is a solution to the problem.

How do I restart naming GDB’s internal variables from $1?

By default, GDB’s internal variables will be $1, $2, $3, …. How do I restart naming from $1?

(gdb) p v1
$1 = 7
(gdb) p v2
$2 = 8
(gdb) p v3
$3 = 9
(gdb) ???  what should be put here?
$1 = 0

Solution

See the documentation, There is no explicit command to clear the value history.

It does mention the file and symbol-file commands, which can alter the symbol table and clear the history.

In addition, you can use output instead of print to avoid putting printed values into the value history.

Related Problems and Solutions