I have been away from Eclipse CDT for a while and have become spoiled by JetBrains' excellent IDEs (and the company won't let me have Clion). Admittedly these are mostly for interpreted, rather than compiled languages, so evaluation is simpler.
When I am breakpointed in Eclipse CDT, (how) can I quickly evaluate expressions involving variables known to the debugger, but in ways in which they are not used in the code?
For instance, if I have two integers, i
and j
, (how) can I quickly evaluate i + j
?
Is it possible, given char *s
, to evaluate stlen(s)
? Or the result of a local function call?
Off the top of my head I would suggest either the Expression view or the Console view, depending on what your flow is, etc.
The Expressions view allows you to add any arbitrary expressions to be evaluated by the selected frame every time the debugger hits a breakpoint or completes a single step.
The Expressions view is not open by default. You can open it from the Window -> Show View -> Expressions.
You can then press the Add new expression button and enter an expression to evaluate. (You can enter pretty much any expression:i+j
, strlen(s)
, or anything else you like)
Alternatively, you can:
The console view allows you to enter GDB commands in standard GDB syntax.
To use the Console:
print i + j
or p i - j
(p
is short for print
):Other Hints when using the Console
You can "pin" the console so that it stays the selected console top with this button on the toolbar:
You can switch console with this drop-down: