1

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

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Also wanted to ask one small thing. The result of my function is a pointer and I am able to execute your command successfully. result.GetValue() returns an address. However, when I run result.GetChildMemberWithName("data").GetValue() (My struct contains a member array int data[2]), I get None. But I've confirmed via the console that it is not None and has a value. Is this a flaw with the code I've written or is there some issue in the result SBValue pointer?
GetChildMemberWithName is getting you an SBValue that represents the 2-element array "data". Arrays don't have values - what would the value of an array mean? Rather, they have children - the elements of the array. So if you wanted to see data[0] you would get the SBValue for "data" using GetChildMemberWithName("data") and call GetChildAtIndex(0) on that. The SBValue that gets returned from that call is a scalar, and will have a value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.