[lldb-dev] defining an alias that passes a parameter to a script command

Cameron McCormack cam at mcc.id.au
Thu Nov 21 17:39:30 PST 2013


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?

Thanks,

Cameron



More information about the lldb-dev mailing list