Search code examples
pythonlldb

Getting AttributeError While Trying to Use GetTriple() in LLDB Python


When I try to use the script from afl-unicorn I get the error below when I try to run it:

AttributeError("'NoneType' object has no attribute 'GetTriple'")

Related line is arch, arch_vendor, arch_os = lldb.target.GetTriple().split('-') but it works when I just type lldb.target.GetTriple() on interactive console. I don't know why it does not work when importing as comments in the script states.

I tried to add the script as a command later by doing command script add dumper -f unicorn_dumper_lldb but this throws error: unable to execute script function; so that didn't work.

Any idea why?


Solution

  • The error message is because lldb.target is None. To understand why this is so, see the couple of paragraphs in this section of the lldb Python reference after the table:

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

    The lldb.target, etc variables are only defined when running in the embedded script interpreter. It doesn't make sense to use a global "selected target" in general purpose scripting, since lldb supports more than one target at a time, and you have no way of knowing that the currently selected target will be the one you want to operate on.

    To work properly, the script will have to figure out how to pass the target it intends to work on around within the script.