[lldb-dev] writing an extension command in Python

Caroline Tice ctice at apple.com
Wed Jan 5 11:26:20 PST 2011


On Jan 4, 2011, at 6:08 PM, Cameron McCormack wrote:

> 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\")")
> 

That particular alias command (as you discovered) will not work because the 'script' command takes raw input, so the % arguments do not get interpreted as place-holders but as part of the raw input text.

You could try something like:

_GetDebugger().HandleCommand("commands alias showimage script ImageData.ShowImageARGB")

(lldb) showimage (300, 200, "myStruct->mImageData")

I believe this will work.  (It worked in my test case).

> 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?
> 

There are definitely plans to eventually add the ability to register your own commands more like built-in commands (it's been on my to-do list for a while), but I'm not sure when we will get around to implementing that.

> Thanks!
> 
> Cameron
> 

If you need/want any more help with any of this stuff, please let me know; I will be more than happy to help you.

-- Caroline
ctice at apple.com






More information about the lldb-dev mailing list