Author: Carl Friedrich Bolz <[email protected]>
Branch: 
Changeset: r78418:c2ef4714164a
Date: 2015-07-03 09:35 +0200
http://bitbucket.org/pypy/pypy/changeset/c2ef4714164a/

Log:    allow GDB to attach and make set_trace an error if --lldebug isn't
        given to translation

diff --git a/rpython/rtyper/module/ll_pdb.py b/rpython/rtyper/module/ll_pdb.py
--- a/rpython/rtyper/module/ll_pdb.py
+++ b/rpython/rtyper/module/ll_pdb.py
@@ -4,12 +4,32 @@
 
 import os
 import pdb
+import signal
 from rpython.rtyper.module.support import _WIN32
-from rpython.rtyper.extfunc import register_external
+from rpython.rtyper.extfunc import register_external, ExtFuncEntry
+from rpython.rtyper.lltypesystem import rffi, lltype
+from rpython.translator.tool.cbuild import ExternalCompilationInfo
+from rpython.annotator.model import s_None
+from rpython.config.translationconfig import get_translation_config
+
+import time
 
 
 if not _WIN32:
+    eci = ExternalCompilationInfo(includes=['string.h', 'assert.h', 
'sys/prctl.h'],
+                                  post_include_bits=["""
+static void pypy__allow_attach(void) {
+    prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY);
+    return;
+}
+    """])
+
+    allow_attach= rffi.llexternal(
+        "pypy__allow_attach", [], lltype.Void,
+        compilation_info=eci, _nowrapper=True)
+
     def pdb_set_trace():
+        allow_attach()
         pid = os.getpid()
         gdbpid = os.fork()
         if gdbpid == 0:
@@ -22,5 +42,21 @@
             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)
+                os.write(2, "Could not start GDB: %s" % (os.strerror(e.errno)))
+                raise SystemExit
+        else:
+            time.sleep(1) # give the GDB time to attach
+
+
+    class FunEntry(ExtFuncEntry):
+        _about_ = pdb.set_trace
+        signature_args = []
+        lltypeimpl = staticmethod(pdb_set_trace)
+        name = "pdb_set_trace"
+
+        def compute_result_annotation(self, *args_s):
+            config = self.bookkeeper.annotator.translator.config.translation
+            if config.lldebug or config.lldebug0:
+                return s_None
+            raise Exception("running pdb.set_trace() without also providing "
+                            "--lldebug when translating is not supported")
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to