Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Fix sys.argv import when running inside LLDB Python interpreter. #101

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mblsha
Copy link

@mblsha mblsha commented Feb 2, 2014

I'm using clint.colored inside LLDB scripts, and this fix is required for that to work.

@jpiper
Copy link
Collaborator

jpiper commented Feb 6, 2014

What do you think about finding a way to detect LLDB running and only do this in that scenario? I'm slightly worried that this could mask problems with argv imports in other scenarios (although I can't think why this would ever happen, so maybe this isn't an issue)

@mblsha
Copy link
Author

mblsha commented Feb 7, 2014

I've checked os.environ, and there's nothing special to check. sys.platform is darwin. sys.argv is available without import for me:

> xcrun lldb
(lldb) script
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
>>> import sys
>>> sys.argv
[]

Can't think of anything else to check. Any ideas?

@jpiper
Copy link
Collaborator

jpiper commented Feb 7, 2014

It actually appears that lldb loads python with an lldb module which isn't usually around, so I think the following might be a good solution

try:
    from sys import argv
# Can happen when executing inside LLDB context   
except ImportError:
    if lldb:
        import sys
        sys.argv = []
    else:
        raise ImportError

@mblsha
Copy link
Author

mblsha commented Feb 15, 2014

lldb module seems to be automatically present only when running inside embedded interpreter, not when inserting externals scripts:

mblsha@siruba ~> cat 1.py 
print lldb

mblsha@siruba ~> xcrun lldb
(lldb) command script import 1.py
error: module importing failed: Python error raised while importing module: reload() argument must be module - traceback:   File "temp.py", line 1, in <module>
(lldb) script
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
>>> print lldb
<module 'lldb' from '/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/Python/lldb/__init__.py'>
>>> ^D

@jpiper jpiper force-pushed the master branch 2 times, most recently from c239c0a to e3f283e Compare October 19, 2014 19:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants