[lldb-dev] command script import

Enrico Granata granata.enrico at gmail.com
Sat Oct 15 03:46:22 PDT 2011


Hi all,

> Sorry, a few more quibbles.  
> 
> Why not add FileSpec::GetFilenameStrippingExtension or something like that as well, since that's what you really use?  That seems like another useful function.  Don't take out the extension one, that also seems good.

I added that in the attached patch file.

> 
> What a pain that you can't import a Python module w/o adding its containing directory to the Python Path!  There must be some reason why, but sigh...
> 

I guess Python is trying to be smart in handling dependencies (that way, if you import foo, and foo needs to import bar, as long as bar is in the path you need not worry about its location on disk). Unfortunately, it looks like there is no trivial way to override that.

> Why do you have to do this bit:
> 
> +    FILE *tmp_fh = (python_interpreter->m_dbg_stdout ? python_interpreter->m_dbg_stdout : stdout);
> +    
> +    {
> +        Locker py_lock(python_interpreter, tmp_fh);
> 
> That seems non-obvious and at least merits a comment.
> 

This is part of the original implementation of the interaction between LLDB and Python. Basically, Python is single-threaded and LLDB tries to acquire the lock before sending commands. I am not sure about the reason why a file handle to which to write some text is required (informative for the user? trying to enforce a wait that the optimizer will not strip?), but this behavior is consistently replicated throughout ScriptInterpreterPython, so I guess the original coder of that class had her motives.
A good point would be to move the code that calculates tmp_fh into the Locker class itself. IMHO that would be best served by writing a separate patch because there are so many methods doing exactly that code snippet (I can deal with that once we're done working on this patch if you want).

> Finally since there seem to be several reasons why LoadScriptingModule could fail in this function, it would be better if it took an Error & parameter and filled that out appropriately.
> 

There it is.
I have also taken the time to check against double import. If we try to double import a same module, Python will report no error, and yet the second import silently does nothing. Now I do check for that condition, and the new command *does* report an error on double import (this would not be harmful in itself, but because we would end up calling __lldb_module_init twice, there might be unwelcome side effects in doing that).

> Jim
> 
> 

Thanks,
- Enrico Granata

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20111015/db93d0a4/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: importcmd.diff
Type: application/octet-stream
Size: 35209 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20111015/db93d0a4/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20111015/db93d0a4/attachment-0001.html>


More information about the lldb-dev mailing list