[lldb-dev] Various questions about lldbinit and python scripts.

Enrico Granata egranata at apple.com
Mon Oct 7 17:43:35 PDT 2013

On Oct 7, 2013, at 5:19 PM, Jean-Yves Avenard <jyavenard at gmail.com> wrote:

> Hello
> Thanks for answering!... very much appreciated
> On 8 October 2013 10:40, Greg Clayton <gclayton at apple.com> wrote:
>> This works for me currently using the exact source for cmdtemplate.py:
> duh.. I feel silly.
> I had called the script lldbfunc.py
> After I changed:
>    debugger.HandleCommand('command script add -f
> cmdtemplate.the_framestats_command framestats')
> into:
>    debugger.HandleCommand('command script add -f
> lldbfunc.the_framestats_command framestats')
> then it works...
> It's a bit of a worry though when the code being run in a file is
> dependent on the name of that file !

This is unfortunately Python’s fault
There are a couple ways that we could work around it.

One is to use __file__ (without the .py extension of course) to know the module name. Now you still somehow depend on your module name, but this dependency is masked by Python itself doing the undignified work of figuring that out for you

Alternatively, you can use the @lldb.command decorator

At the top of your life, just import lldb (which you might be doing anyway), and then you can mark your commands with @lldb.command, as in:

import lldb

def MyCommandImplementor(debugger,args,retval,unused):
	print>>retval,"Hello world this is me"

Enrico Granata
📩 egranata@.com
☎️ 27683

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20131007/f547575e/attachment.html>

More information about the lldb-dev mailing list