I want to use LLDB as a python library as described here https://lldb.llvm.org/use/python-reference.html#using-the-lldb-py-module-in-python.
After creating a target with
debugger = lldb.SBDebugger.Create()
target = debugger.CreateTargetWithFileAndArch(path_to_executable, lldb.LLDB_ARCH_DEFAULT)
and getting the command interpreter with
interpreter = debugger.GetCommandInterpreter()
I try to start the target with
ret = llldb.SBCommandReturnObject()
interpreter.HandleCommand('/r', ret)
I get error: invalid target, create a target using the 'target create' command
. I also tried to set the selected target with debugger.SetSelectedTarget(target)
, but it didn't work either. Running file <path_to_target>
in the command handler works as expected.
Is there a way to create a target in python and run commands in the interpreter against it?