Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MacOSX support] pyrasite uses lldb on macosx #64

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ Requirements

* `gdb <https://www.gnu.org/s/gdb>`_ (version 7.3+ (or RHEL5+))

On OS X you will need to have a codesigned gdb - see https://sourceware.org/gdb/wiki/BuildingOnDarwin
On OS X:

* `xcode command line tools - lldb <https://developer.apple.com/download/more/>`_ (version 7+)

Or you will need to have a codesigned gdb - see https://sourceware.org/gdb/wiki/BuildingOnDarwin
if you get errors while running with --verbose which mention codesigning.

Compatiblity
Expand Down
29 changes: 26 additions & 3 deletions pyrasite/injector.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,31 @@ def inject(pid, filename, verbose=False, gdb_prefix=''):
print(out)
print(err)

if platform.system() == 'Windows':
_platform = platform.system()
if _platform == 'Darwin':
def inject_mac(pid, filename, verbose=False, gdb_prefix=''):
filename = os.path.abspath(filename)
gdb_cmds = [
'(int) PyGILState_Ensure()',
'(int) PyRun_SimpleString("'
'import sys; sys.path.insert(0, \\"%s\\"); '
'sys.path.insert(0, \\"%s\\"); '
'exec(open(\\"%s\\").read())")' %
(os.path.dirname(filename),
os.path.abspath(os.path.join(os.path.dirname(__file__), '..')),
filename),
'(int) PyGILState_Release($1)',
]
p = subprocess.Popen('%slldb -p %d -b %s -k quit' % (gdb_prefix, pid,
' '.join(["-k 'call %s'" % cmd for cmd in gdb_cmds])),
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
if verbose:
print(out)
print(err)
inject = inject_mac

elif _platform == 'Windows':
def inject_win(pid, filename, verbose=False, gdb_prefix=''):
if gdb_prefix == '':
gdb_prefix = os.path.join(os.path.dirname(__file__), 'win') + os.sep
Expand All @@ -55,5 +79,4 @@ def inject_win(pid, filename, verbose=False, gdb_prefix=''):
if verbose:
print(out)
print(err)

inject = inject_win
inject = inject_win