1

in gdb there is a command like:

run $(python -c 'print "\x90"*90')

Where you use a pythons scripts output as your args. How do I do something like this in lldb?

1 Answer 1

2

lldb doesn't have a way to mix python execution output into the command line like this. Since lldb has always had a Python script interpreter ready to hand, it tends to rely on that for this sort of "script like" task.

The simplest example is just running a command you've made up in Python:

(lldb) script
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
>>> lldb.debugger.HandleCommand("run {0}".format("\x90"*90))

You can also do this on one line:

(lldb) script lldb.debugger.HandleCommand("run {0}".format("\x90"*90))

which is handy if you do it a lot because you can make a command alias for this line, and invoke the alias. And if you want to handle the errors or do further operations on the result, there's an equivalent SBCommandInterpreter.HandleCommand API that will return the error/result to you.

There are also more programmatic ways to do this particular job, for instance:

(lldb) script
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
>>> launch_info = lldb.target.GetLaunchInfo()
>>> launch_info.SetArguments(["\x90"*90], True)
>>> error = lldb.SBError()
>>> lldb.target.Launch(launch_info, error)

if you have ambitions to do fancier stuff.

There's more info on the Python Scripting here:

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

and on the SB API's here:

https://lldb.llvm.org/python_api.html

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

2 Comments

I am a little confused by "run {0}".format("\x90"*90). I can get the code to work without the "0" inside the "{}" what does the 0 do?
That's not an lldb thing, that's just the new-ish python string format syntax. The 0 is a positional marker, since you can do things like "{0} {1} {0}".format("outside", "inside") to get: 'outside inside outside'. If you have only one substitution apparently you can leave off the 0, but that seems like an error-prone shortcut to me. Not sure why the positional marker isn't working for you, however.

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.