Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0e3a577

Browse files
committed
Polish RemoteDebugger code.
Use a repr() on the subprocess side when fetching dict values for stack. The various dict entities are not needed by the debugger GUI, only their representation.
1 parent 0444302 commit 0e3a577

6 files changed

Lines changed: 69 additions & 46 deletions

File tree

Lib/idlelib/Debugger.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,18 @@ def __frame2message(self, frame):
5252

5353
class Debugger:
5454

55-
interacting = 0
55+
# interacting = 0 # XXX KBK 14Jun02 move to __init__
5656
vstack = vsource = vlocals = vglobals = None
5757

5858
def __init__(self, pyshell, idb=None):
5959
if idb is None:
6060
idb = Idb(self)
6161
self.pyshell = pyshell
6262
self.idb = idb
63+
self.frame = None
6364
self.make_gui()
64-
65+
self.interacting = 0
66+
6567
def run(self, *args):
6668
try:
6769
self.interacting = 1
@@ -155,7 +157,7 @@ def make_gui(self):
155157
if self.vglobals.get():
156158
self.show_globals()
157159

158-
frame = None
160+
# frame = None # XXX KBK 14Jun02 Move to __init__
159161

160162
def interaction(self, message, frame, info=None):
161163
self.frame = frame
@@ -300,10 +302,11 @@ def show_variables(self, force=0):
300302
gdict = frame.f_globals
301303
if lv and gv and ldict is gdict:
302304
ldict = None
305+
# Calls OldStackviewer.NamespaceViewer.load_dict():
303306
if lv:
304-
lv.load_dict(ldict, force)
307+
lv.load_dict(ldict, force, self.pyshell.interp.rpcclt)
305308
if gv:
306-
gv.load_dict(gdict, force)
309+
gv.load_dict(gdict, force, self.pyshell.interp.rpcclt)
307310

308311
def set_breakpoint_here(self, edit):
309312
text = edit.text
@@ -312,7 +315,7 @@ def set_breakpoint_here(self, edit):
312315
text.bell()
313316
return
314317
lineno = int(float(text.index("insert")))
315-
msg = self.set_break(filename, lineno)
318+
msg = self.idb.set_break(filename, lineno)
316319
if msg:
317320
text.bell()
318321
return

Lib/idlelib/OldStackViewer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def __init__(self, master, title, dict=None):
232232

233233
dict = -1
234234

235-
def load_dict(self, dict, force=0):
235+
def load_dict(self, dict, force=0, rpc_client=None):
236236
if dict is self.dict and not force:
237237
return
238238
subframe = self.subframe
@@ -250,6 +250,10 @@ def load_dict(self, dict, force=0):
250250
for name in names:
251251
value = dict[name]
252252
svalue = self.repr.repr(value) # repr(value)
253+
# Strip extra quotes caused by calling repr on the (already)
254+
# repr'd value sent across the RPC interface:
255+
if rpc_client:
256+
svalue = svalue[1:-1]
253257
l = Label(subframe, text=name)
254258
l.grid(row=row, column=0, sticky="nw")
255259
## l = Label(subframe, text=svalue, justify="l", wraplength=300)

Lib/idlelib/PyShell.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,9 @@ def close_debugger(self):
529529
self.set_debugger_indicator()
530530

531531
def open_debugger(self):
532+
# XXX KBK 13Jun02 An RPC client always exists now? Open remote
533+
# debugger and return...dike the rest of this fcn and combine
534+
# with open_remote_debugger?
532535
if self.interp.rpcclt:
533536
return self.open_remote_debugger()
534537
import Debugger

Lib/idlelib/RemoteDebugger.py

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import rpc
2525
import Debugger
2626

27+
debugging = 0
28+
2729
# In the PYTHON subprocess
2830

2931
frametable = {}
@@ -43,9 +45,9 @@ def wrap_info(info):
4345

4446
class GUIProxy:
4547

46-
def __init__(self, conn, oid):
48+
def __init__(self, conn, gui_adap_oid):
4749
self.conn = conn
48-
self.oid = oid
50+
self.oid = gui_adap_oid
4951

5052
def interaction(self, message, frame, info=None):
5153
self.conn.remotecall(self.oid, "interaction",
@@ -128,24 +130,25 @@ def dict_keys(self, did):
128130
def dict_item(self, did, key):
129131
dict = dicttable[did]
130132
value = dict[key]
131-
try:
132-
# Test for picklability
133-
import cPickle
134-
cPickle.dumps(value)
135-
except:
136-
value = None
133+
value = repr(value)
134+
# try:
135+
# # Test for picklability
136+
# import cPickle
137+
# pklstr = cPickle.dumps(value)
138+
# except:
139+
# print >>sys.__stderr__, "** dict_item pickle failed: ", value
140+
# raise
141+
# #value = None
137142
return value
138143

139-
def start_debugger(conn, gui_oid):
140-
#
141-
# launched in the python subprocess
142-
#
143-
gui = GUIProxy(conn, gui_oid)
144-
idb = Debugger.Idb(gui)
145-
ada = IdbAdapter(idb)
146-
ada_oid = "idb_adapter"
147-
conn.register(ada_oid, ada)
148-
return ada_oid
144+
def start_debugger(conn, gui_adap_oid):
145+
"Launch debugger in the remote python subprocess"
146+
gui_proxy = GUIProxy(conn, gui_adap_oid)
147+
idb = Debugger.Idb(gui_proxy)
148+
idb_adap = IdbAdapter(idb)
149+
idb_adap_oid = "idb_adapter"
150+
conn.register(idb_adap_oid, idb_adap)
151+
return idb_adap_oid
149152

150153
# In the IDLE process
151154

@@ -223,14 +226,14 @@ def __getattr__(self, name):
223226
##print >>sys.__stderr__, "failed DictProxy.__getattr__:", name
224227
raise AttributeError, name
225228

226-
class GUIAdaper:
229+
class GUIAdapter:
227230

228231
def __init__(self, conn, gui):
229232
self.conn = conn
230233
self.gui = gui
231234

232235
def interaction(self, message, fid, iid):
233-
print "interaction(%s, %s, %s)" % (`message`, `fid`, `iid`)
236+
##print "interaction: (%s, %s, %s)" % (`message`,`fid`, `iid`)
234237
frame = FrameProxy(self.conn, fid)
235238
info = None # XXX for now
236239
self.gui.interaction(message, frame, info)
@@ -272,16 +275,23 @@ def set_quit(self):
272275
self.call("set_quit")
273276

274277
def start_remote_debugger(conn, pyshell):
275-
#
276-
# instruct the (remote) subprocess to create
277-
# a debugger instance, and lets it know that
278-
# the local GUIAdapter called "gui_adapter"
279-
# is waiting notification of debugging events
280-
#
281-
ada_oid = "gui_adapter"
282-
idb_oid = conn.remotecall("exec", "start_debugger", (ada_oid,), {})
283-
idb = IdbProxy(conn, idb_oid)
284-
gui = Debugger.Debugger(pyshell, idb)
285-
ada = GUIAdaper(conn, gui)
286-
conn.register(ada_oid, ada)
278+
"""Start the subprocess debugger, initialize the debugger GUI and RPC link
279+
280+
Start the debugger in the remote Python process. Instantiate IdbProxy,
281+
Debugger GUI, and Debugger GUIAdapter objects, and link them together.
282+
283+
The GUIAdapter will handle debugger GUI interaction requests coming from
284+
the subprocess debugger via the GUIProxy.
285+
286+
The IdbAdapter will pass execution and environment requests coming from the
287+
Idle debugger GUI to the subprocess debugger via the IdbProxy.
288+
289+
"""
290+
gui_adap_oid = "gui_adapter"
291+
idb_adap_oid = conn.remotecall("exec", "start_the_debugger",\
292+
(gui_adap_oid,), {})
293+
idb_proxy = IdbProxy(conn, idb_adap_oid)
294+
gui = Debugger.Debugger(pyshell, idb_proxy)
295+
gui_adap = GUIAdapter(conn, gui)
296+
conn.register(gui_adap_oid, gui_adap)
287297
return gui

Lib/idlelib/rpc.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def unregister(self, oid):
119119
pass
120120

121121
def localcall(self, request):
122-
##self.debug("localcall:", request)
122+
self.debug("localcall:", request)
123123
try:
124124
how, (oid, methodname, args, kwargs) = request
125125
except TypeError:
@@ -165,6 +165,7 @@ def localcall(self, request):
165165
return ("EXCEPTION", (mod, name, args, tb))
166166

167167
def remotecall(self, oid, methodname, args, kwargs):
168+
self.debug("remotecall:", oid, methodname, args, kwargs)
168169
seq = self.asynccall(oid, methodname, args, kwargs)
169170
return self.asyncreturn(seq)
170171

@@ -197,10 +198,12 @@ def decoderesponse(self, response):
197198
pass
198199
else:
199200
raise getattr(__import__(mod), name)(*args)
200-
else:
201-
if mod:
202-
name = mod + "." + name
203-
raise name, args
201+
# XXX KBK 15Jun02 mod is False here, also want to raise remaining exceptions
202+
# else:
203+
# if mod:
204+
# name = mod + "." + name
205+
# raise name, args
206+
raise name, args
204207
if how == "ERROR":
205208
raise RuntimeError, what
206209
raise SystemError, (how, what)

Lib/idlelib/run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def __init__(self, rpchandler):
3030
def runcode(self, code):
3131
exec code in self.locals
3232

33-
def start_debugger(self, gui_oid):
33+
def start_the_debugger(self, gui_adap_oid):
3434
import RemoteDebugger
35-
return RemoteDebugger.start_debugger(self.conn, gui_oid)
35+
return RemoteDebugger.start_debugger(self.conn, gui_adap_oid)
3636

3737
def stackviewer(self, flist_oid=None):
3838
if not hasattr(sys, "last_traceback"):

0 commit comments

Comments
 (0)