简体   繁体   中英

LLDB Python API type casting

In GDB Macros, I can do something like this:

set $node = (node_t *) $arg0

When the node_t is actually defined in a library file. How do I go about doing casting operations of the same nature in LLDB Python macros?

There are a couple of ways to do this. The easiest is to use SBFrame.EvaluateExpression like:

options = lldb.SBExpressionOptions()
val = frame.EvaluateExpression("(node_t *) $arg1", options)

where frame is the stack frame you in the context of which you are evaluating the expression.

You can also do this without expressions, which is more efficient if you are going to do this a lot.

For instance, if you have an address and a type, then you can use SBTarget.CreateValueFromAddress to directly produce the cast value. You can find types by using SBTarget.FindFirstType .

If the value you are interested in is in a register, you can get its value from SBFrame.FindRegister , then cast it with SBValue.Cast . That Cast function doesn't always work when casting one complex type to another - you need the expression parser for that - but for simple C pointers it does work fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM