Darshan L
Darshan L

Reputation: 945

In GDB is there an option to stop execution when the variable of our interest is set or modified?

I have a large codebase, I want to know when a particular variable of our interest is getting set. Since there are hundreds of placed in the huge codebase it is getting set and since I am new to the codebase I am not aware of the code flow as well. It has become difficult to trace when the variable is getting set.

So there is an option inn GDB to watch on a particular variable which is of our interest and the GDB stops the flow or intimates about the modification of the variable.

Upvotes: 0

Views: 25

Answers (1)

MrBens
MrBens

Reputation: 1260

You can use watch when you don't know where exactly in the code some expression will be evaluated, or break when you know the line number/symbol. gdb will stop the execution of the program when the expression evaluates to true.

The syntax for watch is watch [expression].

The syntax for break is break [line number/symbol] if [cond]

As ssbssa pointed out, you may refer to the watchpoints section of the gdb manual here.

Upvotes: 1

Related Questions