Prev | Next |
Break When a Variable Changes Value
Data breakpoints can be set on a pre-determined memory variable to cause the debugger to halt execution at the line of code that has just caused the value of the variable to change. This can be useful when trying to track down the point at which a variable is modified during program execution, especially if it is not clear how program execution is affecting a particular object state.
Access
Ribbon |
Execute > Windows > Local Variables : Right-click on variable > Break When Variable is Modified or Execute > Windows > Watches : Right-click on variable > Break When Variable is Modified |
Other |
In a code editor window: Right-click on the variable of interest | Break when item modified |
Capture changes to a variable using data breakpoints
Steps |
Detail |
See also |
---|---|---|
1 |
Set a normal breakpoint in the code so you can choose a variable. Then run the debugger ( ). |
Setting Code Breakpoints |
2 |
When the program has hit the breakpoint, select the variable of interest and from its context menu, select the 'Break When Variable is Modified' option. |
View the Local Variables |
3 |
There are no breakpoint indicators in the code, but data breakpoints are easily recognizable in the Breakpoints & Events window, being a blue icon with a white diamond. Enterprise Architect displays the name of the variable and its address instead of a line number. |
View Variables in Other Scopes |
4 |
With the data breakpoint set, you can disable any other breakpoints you might have. The program will stop at any line of code that changes this variable's value. Now run your program. |
|
5 |
When this variable is modified, the debugger halts and displays the current line of code in the editor. This is not the line that caused the break, but the line of code following the event. The event is logged to the Debug window. Now we know how and where this value (its State) has changed. For example, the statement at line 58 has just updated the number of Passengers. |
|
6 |
Having discovered this and other places where this value is being changed, be sure to get rid of the notification before moving on. You can delete the data breakpoint quickly by selecting it in the Breakpoints window and pressing the . You can also use the right-click context menu to do this. |
Notes
- This feature is not presently supported by the Microsoft .NET platform