Jatinshravan
Jatinshravan

Reputation: 445

LLDB Python API call function in C code

For example, while writing GDB Macros, I can give something like:

list_iterate $arg0

If my list_iterate() function in the C code looks like

list_iterate(list_node *)

In the LLDB Python API, how do I do the same thing, i.e call and execute a function from the C code? I've scoured the documentation but can't seem to find something like this

Upvotes: 1

Views: 796

Answers (1)

Jim Ingham
Jim Ingham

Reputation: 27110

SBFrame::EvaluateExpression is the function you want. Something like:

(lldb) script
>>> options = lldb.SBExpressionOptions()
>>> result = lldb.frame.EvaluateExpression('printf("Hello there.\\n");', options)
Hello there.
>>> print result
(int) $1 = 13

Note, if you are writing scripts (or Python commands, etc.) don't use lldb.frame, you can get the selected frame from your process, or if you are writing a command use the form that gets passed an SBExecutionContext. See:

https://lldb.llvm.org/use/python-reference.html

for more details.

Upvotes: 3

Related Questions