问题
When I create a custom type summary using a Python script, it is possible to access ivars using value.GetChildMemberByName("<child-name>")
. However, this does not work for computed properties or functions.
With the frame variable
command, the script that generates the summary can evaluate expressions in the current frame (e.g. value.GetFrame().EvaluateExpression(value.GetName() + ".description")
)
However, this will not work when using p <some-expression>
/expression -- <some-expression>
as there is no frame, so the above statement will fail to produce any results.
Is there a way to call functions or evaluate computed properties in a type summary when using p
(expression --
)?
回答1:
The EvaluateExpression
function is available on the target as well as on frames. Try value.GetTarget().EvaluateExpression(...)
.
回答2:
You might what to use SBValue.CreateValueFromExpression instead of either the frame or the target EvaluateExpression calls for data formatters.
SBValues remember the context they were defined in, and SBValue.CreateValueFromExpression funnels that context back to the expression evaluator. Since the Variable formatters always receive the SBValue that they are acting on, CreateValueFromExpression allows a simple way to forward that context to the new expression.
来源:https://stackoverflow.com/questions/62398294/lldb-for-swift-access-computed-property-or-perform-function-call-in-type-summar