[pypy-commit] pypy default: Merged in timfel/pypy (pull request #327)

cfbolz noreply at buildbot.pypy.org
Thu Jul 2 12:50:43 CEST 2015


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: 
Changeset: r78411:ead7b35f3abb
Date: 2015-07-02 12:50 +0200
http://bitbucket.org/pypy/pypy/changeset/ead7b35f3abb/

Log:	Merged in timfel/pypy (pull request #327)

	Drop to gdb on unix when pdb.set_trace is encountered

diff --git a/rpython/rtyper/extfuncregistry.py b/rpython/rtyper/extfuncregistry.py
--- a/rpython/rtyper/extfuncregistry.py
+++ b/rpython/rtyper/extfuncregistry.py
@@ -9,6 +9,7 @@
 from rpython.rtyper.lltypesystem.module import ll_math
 from rpython.rtyper.module import ll_os
 from rpython.rtyper.module import ll_time
+from rpython.rtyper.module import ll_pdb
 from rpython.rlib import rfloat
 
 # the following functions all take one float, return one float
@@ -54,4 +55,3 @@
                           export_name='ll_math.%s' % method_name,
                           sandboxsafe=True,
                           llimpl=getattr(ll_math, method_name))
-
diff --git a/rpython/rtyper/module/ll_pdb.py b/rpython/rtyper/module/ll_pdb.py
new file mode 100644
--- /dev/null
+++ b/rpython/rtyper/module/ll_pdb.py
@@ -0,0 +1,26 @@
+"""
+Low-level implementation for pdb.set_trace()
+"""
+
+import os
+import pdb
+from rpython.rtyper.module.support import _WIN32
+from rpython.rtyper.extfunc import register_external
+
+
+if not _WIN32:
+    def pdb_set_trace():
+        pid = os.getpid()
+        gdbpid = os.fork()
+        if gdbpid == 0:
+            shell = os.environ.get("SHELL") or "/bin/sh"
+            sepidx = shell.rfind(os.sep) + 1
+            if sepidx > 0:
+                argv0 = shell[sepidx:]
+            else:
+                argv0 = shell
+            try:
+                os.execv(shell, [argv0, "-c", "gdb -p %d" % pid])
+            except OSError as e:
+                raise SystemExit('Could not start GDB: %s.' % e)
+    register_external(pdb.set_trace, [], llimpl=pdb_set_trace)


More information about the pypy-commit mailing list