LLDB expressions: 'unknown error' is returned upon successful evaluation

Hello,

I wondering, whether this is a bug or a feature. I have a valid top-level Clang expression, but LLDB returns an ‘unknown error’ upon successful evaluation.

Reproduction steps:
We need to have a runnable target in order to evaluate top-level expression.

  1. Create a running target.
  2. Invoke script command
  3. Prepare Options for expression evaluator:
>>> opt = lldb.SBExpressionOptions()
>>> opt.SetTopLevel()
  1. Evalute the expression: lldb.frame.EvaluateExpression("struct Foo { int bar; };", opt)
  2. Error: 'unknown error' is returned, but the expression has been evaluated.
  3. lldb.frame.EvaluateExpression("struct Foo aaa = {1}; aaa") returns (struct Foo) $0 = (bar = 1)

Is this an expected outcome? If so, is it OK to just “ignore” errors with description equal to “unknown error”?

When you run an expression that doesn’t return a result (like a type definition) there has to be a way to tell the programmer that “the SBValue we returned you doesn’t contain anything useful”. It currently does that by setting the error state in the SBValue with “unknown error”.

That is indeed an awkward way to convey that information. It would be better to have a tristate “Has value; has no value but that’s expected; has error”, but someone would have to invent that and plumb it through.

Maybe the best thing to do in this case is to make a better “error” string in this case.