I'm trying to use the EvaluateExpression functionality from LLDB in Python.
It looks like it works but the return type is always Error.
Run the included sample below and it will call the function foo, but the result is 'unknown error'
```
from pathlib import Path
import lldb
import os
from lldb import SBError, SBThread
def main():
c_code = \
"""
#include <stdio.h>
void foo(int i){
printf(\"Hello from foo %i\\n\", i);
}
int main(void){
return 0;
}
"""
#Compile the main code
main_file = Path("main.c")
main_file.write_text(c_code)
os.system('clang -g -O0 main.c -o main')
debugger = lldb.SBDebugger.Create()
debugger.SetAsync(False)
target = debugger.CreateTarget("main")
break_point_main = target.BreakpointCreateByName("main")
launch_info = lldb.SBLaunchInfo(["./main"])
launch_info.SetWorkingDirectory(os.getcwd())
error = SBError()
process = target.Launch(launch_info, error)
assert target.IsValid()
assert process.IsValid()
assert break_point_main.IsValid()
state = process.GetState()
assert state == lldb.eStateStopped
thread: SBThread = process.GetSelectedThread()
frame = thread.GetSelectedFrame()
assert frame.IsValid()
assert thread.IsValid()
expr1: str = "int $x=4"
result_t = target.EvaluateExpression(expr1)
error_t: SBError = result_t.GetError()
print(f"result_t: {result_t}, {error_t}")
expr2: str = "(void)foo($x)"
result_f = frame.EvaluateExpression(expr2)
error_f: SBError = result_t.GetError()
print(f"result_t: {result_f}, {error_f}")
#Result should be something other than error
# foo prints out the message, as seen in the stdout, so why is there an error?
text = process.GetSTDOUT(1024)
print(text)
if __name__ == "__main__":
main()```
I'm running this on
lldb version 17.0.6
Python 3.11.0
Tried on mac M2 and a x86_64 Ubuntu machine.
I'm trying to use the EvaluateExpression functionality from LLDB in Python. It looks like it works but the return type is always Error.
Run the included sample below and it will call the function foo, but the result is 'unknown error'