Do you debug programs with lots of variables? So many that it's hard to find those that you're interested in? Yeah, us too. To help debug EGL programs, we introduced hover variable support in RBD version 18.104.22.168 -- if you hadn't noticed this yet, just hover over a variable in the EGL source editor while the debugger is suspended, and you'll see its value if the field is in scope. In RBD version 8.0.1, we added support for watch expressions.
There are two main uses of watch expressions:
- Evaluate an arbitrary expression in the current debug context (i.e. the line where you're suspended)
- Quickly view select variables
If you open the Expressions view, you can manually write expressions that will be evaluated when suspended. You can write an expression like age > 20
to get a Boolean result, or simply age
to see the value of the field, or anything else that's valid in the location where you're suspended. If an error occurs, you will see the error message as a child of the expression. The error message could be that the expression didn't compile, or it could be an error thrown when executing the code (e.g. a NullValueException
For simple variable expressions, you don't need to manually write these. If you head on over to the Variables view, you can right-click on a variable and select Watch
. This will automatically build a watch expression, which is especially useful for deeply-nested fields (Tip:
you can select multiple variables at once to "Watch").
Here's a bunch of expressions to show how they look, including some errors:5 additional things you should know about watch expressions:
- The Eclipse framework will run these evaluations a lot. Every time you suspend, step, or click on a stack frame, they're run. This can hurt performance if you have too many expressions enabled.
- Watch expressions are only run when the Expressions view is visible. Don't want them to run right now? Either close or hide the view. You can also disable the expressions and leave the view open (right-click an expression and select Disable).
- Eclipse will sometimes invoke an expression twice - for example, when you first create an expression, I've seen it get run twice. Due to this, be very careful when using expressions that have side effects (like running a commit on a database). I don't recommend such expressions from this view, at least not until Eclipse stops executing them twice in certain conditions.
- If your expression resolves to a variable, you can change its value by right-clicking on it and selecting Change Value. This can also be done for child variables (e.g. if your expression resolved to a record, you can expand it to see the record's fields and can change their values).
- If your expression contains two statements then only the first will be run. For example, i += 10; writestdout(i); will only run the first part that adds 10 to a variable i - the print statement is not run. If you want both parts run, one trick is to put the statements inside an if statement: if (true) i += 10; writestdout(i); end. Why does this work? Because the if statement is technically a single statement. In most cases, you can just have two separate expressions.
Question: Do you think it's important to remove the "1 statement" restriction, or is the "if statement" workaround sufficient?
So what do you think? Are watch expressions something you use frequently? Add a comment and let us know!
In case you missed my previous blogs on debugging, see Viewing variables during a TUI converse
and Conditional breakpoints