diff --git a/README.rst b/README.rst index a1ef7ab..35373f2 100644 --- a/README.rst +++ b/README.rst @@ -30,7 +30,11 @@ Requirements * `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 `_ (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 diff --git a/pyrasite/injector.py b/pyrasite/injector.py index 067fad1..15173cc 100644 --- a/pyrasite/injector.py +++ b/pyrasite/injector.py @@ -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 @@ -55,5 +79,4 @@ def inject_win(pid, filename, verbose=False, gdb_prefix=''): if verbose: print(out) print(err) - - inject = inject_win \ No newline at end of file + inject = inject_win