Author: Ronan Lamy <[email protected]>
Branch:
Changeset: r82092:e415ef72b422
Date: 2016-02-05 17:26 +0000
http://bitbucket.org/pypy/pypy/changeset/e415ef72b422/
Log: Use regular register_external() call for attach_gdb()
diff --git a/rpython/rlib/debug.py b/rpython/rlib/debug.py
--- a/rpython/rlib/debug.py
+++ b/rpython/rlib/debug.py
@@ -4,7 +4,7 @@
from rpython.rtyper.extregistry import ExtRegistryEntry
from rpython.rlib.objectmodel import we_are_translated
from rpython.rlib.rarithmetic import is_valid_int
-from rpython.rtyper.extfunc import ExtFuncEntry
+from rpython.rtyper.extfunc import register_external
from rpython.rtyper.lltypesystem import lltype
from rpython.rtyper.lltypesystem import rffi
from rpython.translator.tool.cbuild import ExternalCompilationInfo
@@ -397,12 +397,11 @@
import pdb; pdb.set_trace()
if not sys.platform.startswith('win'):
- def _make_impl_attach_gdb():
- if sys.platform.startswith('linux'):
- # Only necessary on Linux
- eci = ExternalCompilationInfo(includes=['string.h', 'assert.h',
- 'sys/prctl.h'],
- post_include_bits=["""
+ if sys.platform.startswith('linux'):
+ # Only necessary on Linux
+ eci = ExternalCompilationInfo(includes=['string.h', 'assert.h',
+ 'sys/prctl.h'],
+ post_include_bits=["""
/* If we have an old Linux kernel (or compile with old system headers),
the following two macros are not defined. But we would still like
a pypy translated on such a system to run on a more modern system. */
@@ -416,55 +415,38 @@
prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY);
}
"""])
- allow_attach = rffi.llexternal(
- "pypy__allow_attach", [], lltype.Void,
- compilation_info=eci, _nowrapper=True)
+ allow_attach = rffi.llexternal(
+ "pypy__allow_attach", [], lltype.Void,
+ compilation_info=eci, _nowrapper=True)
+ else:
+ # Do nothing, there's no prctl
+ def allow_attach():
+ pass
+
+ def impl_attach_gdb():
+ import os
+ allow_attach()
+ 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:
+ os.write(2, "Could not start GDB: %s" % (
+ os.strerror(e.errno)))
+ raise SystemExit
else:
- # Do nothing, there's no prctl
- def allow_attach():
- pass
+ time.sleep(1) # give the GDB time to attach
- def impl_attach_gdb():
- import os
- allow_attach()
- 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:
- os.write(2, "Could not start GDB: %s" % (
- os.strerror(e.errno)))
- raise SystemExit
- else:
- time.sleep(1) # give the GDB time to attach
+else:
+ def impl_attach_gdb():
+ print "Don't know how to attach GDB on Windows"
- return impl_attach_gdb
-else:
- def _make_impl_attach_gdb():
- def impl_attach_gdb():
- print "Don't know how to attach GDB on Windows"
- return impl_attach_gdb
-
-
-class FunEntry(ExtFuncEntry):
- _about_ = attach_gdb
- signature_args = []
- #lltypeimpl = staticmethod(impl_attach_gdb) --- done lazily below
- name = "impl_attach_gdb"
-
- @property
- def lltypeimpl(self):
- if not hasattr(self.__class__, '_lltypeimpl'):
- self.__class__._lltypeimpl = staticmethod(_make_impl_attach_gdb())
- return self._lltypeimpl
-
- def compute_result_annotation(self, *args_s):
- from rpython.annotator.model import s_None
- return s_None
+register_external(attach_gdb, [], result=None,
+ export_name="impl_attach_gdb", llimpl=impl_attach_gdb)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit