0

I am using vsCode and I would like to know if it is possible to stop the debugger when the value of a variable changes.

I am analyzing code that I have not written and would like see where a certain boolean variable gets changed from false to true.

Is this possible?

Trailer
  • 155
  • 9
  • 1
    I went to www.google.com, typed "gdb stop when variable changes", and got the right answer as the first link. What happens when you try that, yourself? Do you get the same results? – Sam Varshavchik Dec 11 '21 at 19:02
  • Hello,unfortunately no. Would you mind sharing your google search? – Trailer Dec 11 '21 at 19:13
  • Are you referring to this post: https://stackoverflow.com/questions/12566076/set-breakpoint-on-variable-value-change? How is this introduced into vsCode? There is no answer for that... – Trailer Dec 11 '21 at 19:29
  • There is this extension for vsCode https://stackoverflow.com/questions/63691261/how-to-set-data-breakpoints-i-e-watchpoints-on-vscode but not for GDB... – Trailer Dec 11 '21 at 19:40

2 Answers2

0

This will work by doing into the debug console and typing gdb commands. In this case:

-exec awatch myVariable

or by getting the location in memory &myVariable in the watch window.

Copy the location in memory (e.g., 0x555...) and in the debug console type:

-exec awatch *memoryLocationOfVariable
Trailer
  • 155
  • 9
-3

Click to the left of the line of code you want then press debug to manually move through each line of code you have selected.

NewbCoder
  • 13
  • 4
  • Hello, thank you for the reply. My intent is not just debugging the code. I would like to check a variable of interest which was already created and initialized and make the program stop whenever the value of the variable is changed. This should be made inside vsCode which is using GDB. – Trailer Dec 11 '21 at 19:19