Commit 933953e2 authored by Julien Muchembled's avatar Julien Muchembled

debug: extend 'pdb' example to optionally break on an arbitrary list of callables

parent ec031cdf
......@@ -11,7 +11,15 @@ The prompt is accessible through network in case that the process is daemonized:
IF = 'pdb'
if IF == 'pdb':
import socket, sys, threading
# List of (module, callables) to break at.
# If empty, a thread is started with a breakpoint.
# All breakpoints are automatically removed on the first break,
# or when this module is reloaded.
BP = (#('ZODB.Connection', 'Connection.setstate'),
#('ZPublisher.Publish', 'publish_module_standard'),
import errno, socket, sys, threading, weakref
# Unfortunately, IPython does not always print to given stdout.
#from neo.lib.debug import getPdb
from pdb import Pdb as getPdb
......@@ -55,7 +63,7 @@ if IF == 'pdb':
return False
def pdb(app_set):
def pdb():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# For better security, maybe we should use a unix socket.
......@@ -87,7 +95,53 @@ if IF == 'pdb':
app_set = ()
del f
threading.Thread(target=pdb, args=(app_set,)).start()
class setupBreakPoints(list):
def __init__(self, bp_list):
self._lock = threading.Lock()
for o, name in bp_list:
o = __import__(o, fromlist=1)
x = name.split('.')
name = x.pop()
for x in x:
o = getattr(o, x)
orig = getattr(o, name)
if orig.__module__ == __name__:
orig = getattr(o, name)
assert orig.__module__ != __name__, (o, name)
orig = getattr(orig, '__func__', orig)
self.append((o, name, orig))
setattr(o, name, self._wrap(orig))
print 'BP set on', orig
self._hold = weakref.ref(pdb, self._revert)
def _revert(self, *_):
for x in self:
print 'BP removed on', x[2]
del self[:]
def _wrap(self, orig):
return lambda *args, **kw: self(orig, *args, **kw)
def __call__(self, orig, *args, **kw):
stop = False
with self._lock:
if self:
stop = True
if stop:
return orig(*args, **kw)
if BP:
elif IF == 'frames':
import sys, traceback
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment