Conditional Breakpoints

Adding a simple breakpoint at a line will stop the running programming whenever that line of code is hit. But this might not be the requirement every time. Suppose we want to add a kind of breakpoint on a line that will get hit only when a condition is met, not always.

Let’s understand by example. Check the code below,

Now suppose we want to set the breakpoint at line 8 and we want to get it hit when val is 50. To do that we need to add breakpoint with following command,

br <FILENAME>:<LINE NUM> if <CONDITION>

For Example,

After this breakpoint when application runs, line number 8 will be hit many times before value of va is 50. But breakpoint will be hit on this line only when value of val is 50.

 

If you check the current list of breakpoints, it will explain the stuff too i.e.

Watchpoints

Watchpoints is a kind of breakpoint but it is set on a variable instead of any line. Suppose you set the watchpoint on a variable val i.e.

Then whenever value of val will change watchpoint will be hit and it will display the old and new values. For example,

Disable and Enabling Breakpoints or watchpoints

A watchpoint can be enbaled and disabled by using enable and disable command i.e.

Click Here to Subscribe for more Articles / Tutorials like this.