Is there a way to print what the condition of an if statement evaluates to in LLDB ? Or the value value of any conditionnal expression at some point in of the execution of the program ?
I know how to print a variable with var
or print
, how to print an array's values with parray 10 arr
,
how to get the return value of a function by stepping-out of it and thread info
but I
don't know how to get the value of a conditional expression.
Any debugging tips much appreciated.
Edit : I just learned from a comment below that one can just use print
with some conditionnal expression to see what it evaluates to.
Still, is there somme command that allows to see that without typing the whole condition and have lldb evalluate it again from the state of the variables but to print what a specific condition has evaluated to at some specific point in the program ?
There isn't such a command.
It would be pretty hard to write one that would be fully general since individual source lines are very often not complete statements, and we'd have to do something sensible in that case, etc...
Also, I don't think you actually want "evaluate this line as an expression", you want something more complex. I imagine you have a source line like:
if (!strncmp(token_table[i].token, input , token_table[i].len))) {
That's not an expression in C, so we couldn't evaluate the whole source line directly. You really want "find anything that looks like it's a conditional in this source line, pull it out and evaluate that." That looks tractable in simple cases like the one above, but in the general case this starts to get complicated, and it would be hard to get it right.
OTOH, it would be pretty straightforward to write a Python command that only handles simple instances of an if conditional, using the SB API's to pull out the source line, then some Python parsing to pull out the condition, then SBFrame.EvaluateExpression to evaluate it. So you could certainly use the Python API's to whip up something that's good enough for your purposes.
More details about the Python affordances in lldb are here:
https://lldb.llvm.org/use/python-reference.html
and the lldb API's are documented here: