[Python-checkins] r47124 - in sandbox/trunk/pdb: README.txt mpdb.py test/test_mpdb.py
matt.fleming
python-checkins at python.org
Tue Jun 27 12:52:50 CEST 2006
Author: matt.fleming
Date: Tue Jun 27 12:52:49 2006
New Revision: 47124
Modified:
sandbox/trunk/pdb/README.txt
sandbox/trunk/pdb/mpdb.py
sandbox/trunk/pdb/test/test_mpdb.py
Log:
Fix top-level pdbserver and target routines.
Modified: sandbox/trunk/pdb/README.txt
==============================================================================
--- sandbox/trunk/pdb/README.txt (original)
+++ sandbox/trunk/pdb/README.txt Tue Jun 27 12:52:49 2006
@@ -42,5 +42,9 @@
- Debugging outside a process
- Debugging remotely
- Debugging threads
+* Provide a command to distinguish between 'server' and 'client', because
+ at the moment 'info target' only tells the user whether they are local
+ or remote, and not whether they are the local/remote server or
+ local/remote client.
Modified: sandbox/trunk/pdb/mpdb.py
==============================================================================
--- sandbox/trunk/pdb/mpdb.py (original)
+++ sandbox/trunk/pdb/mpdb.py Tue Jun 27 12:52:49 2006
@@ -46,6 +46,8 @@
sys.stdin and sys.stdout are used.
"""
pydb.Pdb.__init__(self, completekey, stdin, stdout)
+ self.orig_stdout = self.stdout
+ self.orig_stdin = self.stdin
self.prompt = '(MPdb)'
self.target = 'local' # local connections by default
self.connection = None
@@ -81,6 +83,18 @@
""" All commands in 'line' are sent across this object's connection
instance variable.
"""
+ # This is the simplest way I could think of to do this without
+ # breaking any of the inherited code from pydb/pdb. If we're a
+ # remote client, always call 'rquit' (remote quit) when connected to
+ # a pdbserver. This executes extra code to allow the client and server
+ # to quit cleanly.
+ if 'quit'.startswith(line):
+ line = 'rquit'
+ self.connection.write(line)
+ # Reset the onecmd method
+ self.onecmd = lambda x: pydb.Pdb.onecmd(self, x)
+ self.do_rquit(None)
+ return
self.connection.write(line)
ret = self.connection.readline()
# The output from the command that we've just sent to the server
@@ -245,6 +259,8 @@
self.local_prompt = self.prompt
self.prompt = ""
line = self.connection.readline()
+ while '(MPdb)' not in line:
+ line = self.connection.readline()
self.msg_nocr(line)
self.onecmd = self.remote_onecmd
self.target = 'remote'
@@ -315,6 +331,7 @@
return
self.connection = eval(target+'()')
try:
+ self.msg('Listening on: %s' % comm)
self.connection.connect(comm)
except ConnectionFailed, err:
self.errmsg("Failed to connect to %s: (%s)" % (comm, err))
@@ -323,6 +340,24 @@
self._rebind_input(self.connection)
self._rebind_output(self.connection)
+ def do_rquit(self, arg):
+ """ Quit a remote debugging session. The program being executed
+is aborted.
+"""
+ if self.target == 'local':
+ self.errmsg('Connected locally, cannot remotely quit')
+ return
+ self._rebind_output(self.orig_stdout)
+ self._rebind_input(self.orig_stdin)
+ if self.connection != None:
+ self.connection.disconnect()
+ if hasattr(self, 'local_prompt'):
+ self.prompt = self.local_prompt
+ self.msg('Exiting remote debugging...')
+ self.target = 'local'
+ self.do_quit(None)
+
+
def do_thread(self, arg):
"""Use this command to switch between threads.
The new thread ID must be currently known.
@@ -354,19 +389,25 @@
t_tracer = self.tracers[int(args[1])-1]
func = args[2]
cmd = eval('t.' + func)
- result = cmd(args[3:])
+ try:
+ result = cmd(args[3:])
+ except AttributeError:
+ self.errmsg('No such thread subcommand')
+ return
-def pdbserver(addr):
+def pdbserver(addr, args):
""" This method sets up a pdbserver debugger that allows debuggers
to connect to 'address' using 'protocol'. The argument 'filename'
is the name of the file that is being debugged.
"""
m = MPdb()
- position = addr.rfind(' ')
- mainpyfile = addr[position+1:]
+ mainpyfile = args[0]
m.mainpyfile = mainpyfile
m.do_pdbserver(addr)
- m._runscript(mainpyfile)
+ while True:
+ m._runscript(mainpyfile)
+ if m._user_requested_quit:
+ break
sys.exit()
def target(addr):
@@ -375,6 +416,7 @@
tcp = 'tcp mydomainname.com:9876'
serial = '/dev/ttyC0'
"""
+ print addr
m = MPdb()
# Look Ma, no script!
m.do_target(addr)
@@ -390,7 +432,7 @@
if opts.target:
target(opts.target)
elif opts.pdbserver:
- pdbserver(opts.pdbserver)
+ pdbserver(opts.pdbserver, args)
else:
if not opts.scriptname:
if not args:
Modified: sandbox/trunk/pdb/test/test_mpdb.py
==============================================================================
--- sandbox/trunk/pdb/test/test_mpdb.py (original)
+++ sandbox/trunk/pdb/test/test_mpdb.py Tue Jun 27 12:52:49 2006
@@ -61,7 +61,7 @@
client = MPdbTest()
thread.start_new_thread(connect_to_target, (client,))
- self.server1 = MPdb()
+ self.server1 = MPdbTest()
self.server1.do_pdbserver('tcp '+__addr__)
self.server1.connection.disconnect()
More information about the Python-checkins
mailing list