LLDB for Swift: Access computed property or perform function call in type summary Python script

。_饼干妹妹 提交于 2021-01-28 03:45:17

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!