[lldb-dev] writing an extension command in Python

Cameron McCormack cam at mcc.id.au
Tue Jan 4 18:08:08 PST 2011


OK, I am making some progress.  In my .lldbinit file I have

  script import ImageData

and in ImageData.py it tries to register an alias for itself when it is
loaded

  __GetDebugger().HandleCommand("commands alias showimage script ImageData.ShowImageARGB(%1, %2, \"%3\")")

so that I can type commands like this:

  (lldb) showimage 300 200 myStruct->mImageData

This doesn’t work; when I try to use the showimage alias the Python
interpreter complains about a literal "%1" that it’s trying to parse.
Is there a way I can escape or unescape appropriately so that the alias
arguments get passed to my Python function call?

This way of registering an alias for my function seems unideal, though,
because it won’t work if the expression that I use contains spaces
(since it will get split up into %3, %4, etc.) or if it includes double
quotes, since that will mess with the quoting I’m using to pass the
expression in as a string.  Are there better ways to handle this?  Is
there a way to register my command with the SBCommandIntepreter so that
it can feel more like a built-in command?

Thanks!

Cameron

-- 
Cameron McCormack ≝ http://mcc.id.au/



More information about the lldb-dev mailing list