[lldb-dev] defining an alias that passes a parameter to a script command
jingham at apple.com
jingham at apple.com
Fri Nov 22 08:11:52 PST 2013
On Nov 21, 2013, at 5:39 PM, Cameron McCormack <cam at mcc.id.au> wrote:
> Hi,
>
> (First please let me know if there is a better mailing list for user questions like this.)
>
> I want to write some commands in Python and to give them handy aliases. My first thought was to do this:
>
> command alias foo script MyPythonFunction(%1)
>
> but that doesn't work, as script takes "raw input" and won't expand the %1. Is there a way I can make that work?
>
> My next thought was to define a command handler from Python for "foo". I tried this:
>
> class Handler:
> def DoExecute(self, debugger, command, retobj):
> # ... implementation of the foo command ...
> ci = lldb.debugger.GetCommandIntepreter()
> ci.AddCommand("foo", Handler(), "help text")
>
> but it looks like AddCommand is not exposed in the Python bindings. Any reason why? I guess then I would have had to parse out the arguments from |command|, and it wasn't clear to me whether there's an easy way to do that. Ideally I could declare that my command takes a single value argument, and I would be given an SBValue object.
>
>
> Is there an idiomatic way of defining a command using Python and exposing it to the command interpreter that I'm missing?
There isn't a way to ADD the Python command to the interpreter using Python API's, but you can just use HandleCommand to invoke the command line equivalent. Other than that it is pretty straightforward. See the section titled "CREATE A NEW LLDB COMMAND USING A PYTHON FUNCTION" in the lldb Python reference http://lldb.llvm.org/python-reference.html for details.
Jim
>
> Thanks,
>
> Cameron
> _______________________________________________
> lldb-dev mailing list
> lldb-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev
More information about the lldb-dev
mailing list