Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../idlelib
File: RemoteDebugger.py
"""Support for remote Python debugging.
[0] Fix | Delete
[1] Fix | Delete
Some ASCII art to describe the structure:
[2] Fix | Delete
[3] Fix | Delete
IN PYTHON SUBPROCESS # IN IDLE PROCESS
[4] Fix | Delete
#
[5] Fix | Delete
# oid='gui_adapter'
[6] Fix | Delete
+----------+ # +------------+ +-----+
[7] Fix | Delete
| GUIProxy |--remote#call-->| GUIAdapter |--calls-->| GUI |
[8] Fix | Delete
+-----+--calls-->+----------+ # +------------+ +-----+
[9] Fix | Delete
| Idb | # /
[10] Fix | Delete
+-----+<-calls--+------------+ # +----------+<--calls-/
[11] Fix | Delete
| IdbAdapter |<--remote#call--| IdbProxy |
[12] Fix | Delete
+------------+ # +----------+
[13] Fix | Delete
oid='idb_adapter' #
[14] Fix | Delete
[15] Fix | Delete
The purpose of the Proxy and Adapter classes is to translate certain
[16] Fix | Delete
arguments and return values that cannot be transported through the RPC
[17] Fix | Delete
barrier, in particular frame and traceback objects.
[18] Fix | Delete
[19] Fix | Delete
"""
[20] Fix | Delete
[21] Fix | Delete
import types
[22] Fix | Delete
from idlelib import Debugger
[23] Fix | Delete
[24] Fix | Delete
debugging = 0
[25] Fix | Delete
[26] Fix | Delete
idb_adap_oid = "idb_adapter"
[27] Fix | Delete
gui_adap_oid = "gui_adapter"
[28] Fix | Delete
[29] Fix | Delete
#=======================================
[30] Fix | Delete
#
[31] Fix | Delete
# In the PYTHON subprocess:
[32] Fix | Delete
[33] Fix | Delete
frametable = {}
[34] Fix | Delete
dicttable = {}
[35] Fix | Delete
codetable = {}
[36] Fix | Delete
tracebacktable = {}
[37] Fix | Delete
[38] Fix | Delete
def wrap_frame(frame):
[39] Fix | Delete
fid = id(frame)
[40] Fix | Delete
frametable[fid] = frame
[41] Fix | Delete
return fid
[42] Fix | Delete
[43] Fix | Delete
def wrap_info(info):
[44] Fix | Delete
"replace info[2], a traceback instance, by its ID"
[45] Fix | Delete
if info is None:
[46] Fix | Delete
return None
[47] Fix | Delete
else:
[48] Fix | Delete
traceback = info[2]
[49] Fix | Delete
assert isinstance(traceback, types.TracebackType)
[50] Fix | Delete
traceback_id = id(traceback)
[51] Fix | Delete
tracebacktable[traceback_id] = traceback
[52] Fix | Delete
modified_info = (info[0], info[1], traceback_id)
[53] Fix | Delete
return modified_info
[54] Fix | Delete
[55] Fix | Delete
class GUIProxy:
[56] Fix | Delete
[57] Fix | Delete
def __init__(self, conn, gui_adap_oid):
[58] Fix | Delete
self.conn = conn
[59] Fix | Delete
self.oid = gui_adap_oid
[60] Fix | Delete
[61] Fix | Delete
def interaction(self, message, frame, info=None):
[62] Fix | Delete
# calls rpc.SocketIO.remotecall() via run.MyHandler instance
[63] Fix | Delete
# pass frame and traceback object IDs instead of the objects themselves
[64] Fix | Delete
self.conn.remotecall(self.oid, "interaction",
[65] Fix | Delete
(message, wrap_frame(frame), wrap_info(info)),
[66] Fix | Delete
{})
[67] Fix | Delete
[68] Fix | Delete
class IdbAdapter:
[69] Fix | Delete
[70] Fix | Delete
def __init__(self, idb):
[71] Fix | Delete
self.idb = idb
[72] Fix | Delete
[73] Fix | Delete
#----------called by an IdbProxy----------
[74] Fix | Delete
[75] Fix | Delete
def set_step(self):
[76] Fix | Delete
self.idb.set_step()
[77] Fix | Delete
[78] Fix | Delete
def set_quit(self):
[79] Fix | Delete
self.idb.set_quit()
[80] Fix | Delete
[81] Fix | Delete
def set_continue(self):
[82] Fix | Delete
self.idb.set_continue()
[83] Fix | Delete
[84] Fix | Delete
def set_next(self, fid):
[85] Fix | Delete
frame = frametable[fid]
[86] Fix | Delete
self.idb.set_next(frame)
[87] Fix | Delete
[88] Fix | Delete
def set_return(self, fid):
[89] Fix | Delete
frame = frametable[fid]
[90] Fix | Delete
self.idb.set_return(frame)
[91] Fix | Delete
[92] Fix | Delete
def get_stack(self, fid, tbid):
[93] Fix | Delete
##print >>sys.__stderr__, "get_stack(%r, %r)" % (fid, tbid)
[94] Fix | Delete
frame = frametable[fid]
[95] Fix | Delete
if tbid is None:
[96] Fix | Delete
tb = None
[97] Fix | Delete
else:
[98] Fix | Delete
tb = tracebacktable[tbid]
[99] Fix | Delete
stack, i = self.idb.get_stack(frame, tb)
[100] Fix | Delete
##print >>sys.__stderr__, "get_stack() ->", stack
[101] Fix | Delete
stack = [(wrap_frame(frame2), k) for frame2, k in stack]
[102] Fix | Delete
##print >>sys.__stderr__, "get_stack() ->", stack
[103] Fix | Delete
return stack, i
[104] Fix | Delete
[105] Fix | Delete
def run(self, cmd):
[106] Fix | Delete
import __main__
[107] Fix | Delete
self.idb.run(cmd, __main__.__dict__)
[108] Fix | Delete
[109] Fix | Delete
def set_break(self, filename, lineno):
[110] Fix | Delete
msg = self.idb.set_break(filename, lineno)
[111] Fix | Delete
return msg
[112] Fix | Delete
[113] Fix | Delete
def clear_break(self, filename, lineno):
[114] Fix | Delete
msg = self.idb.clear_break(filename, lineno)
[115] Fix | Delete
return msg
[116] Fix | Delete
[117] Fix | Delete
def clear_all_file_breaks(self, filename):
[118] Fix | Delete
msg = self.idb.clear_all_file_breaks(filename)
[119] Fix | Delete
return msg
[120] Fix | Delete
[121] Fix | Delete
#----------called by a FrameProxy----------
[122] Fix | Delete
[123] Fix | Delete
def frame_attr(self, fid, name):
[124] Fix | Delete
frame = frametable[fid]
[125] Fix | Delete
return getattr(frame, name)
[126] Fix | Delete
[127] Fix | Delete
def frame_globals(self, fid):
[128] Fix | Delete
frame = frametable[fid]
[129] Fix | Delete
dict = frame.f_globals
[130] Fix | Delete
did = id(dict)
[131] Fix | Delete
dicttable[did] = dict
[132] Fix | Delete
return did
[133] Fix | Delete
[134] Fix | Delete
def frame_locals(self, fid):
[135] Fix | Delete
frame = frametable[fid]
[136] Fix | Delete
dict = frame.f_locals
[137] Fix | Delete
did = id(dict)
[138] Fix | Delete
dicttable[did] = dict
[139] Fix | Delete
return did
[140] Fix | Delete
[141] Fix | Delete
def frame_code(self, fid):
[142] Fix | Delete
frame = frametable[fid]
[143] Fix | Delete
code = frame.f_code
[144] Fix | Delete
cid = id(code)
[145] Fix | Delete
codetable[cid] = code
[146] Fix | Delete
return cid
[147] Fix | Delete
[148] Fix | Delete
#----------called by a CodeProxy----------
[149] Fix | Delete
[150] Fix | Delete
def code_name(self, cid):
[151] Fix | Delete
code = codetable[cid]
[152] Fix | Delete
return code.co_name
[153] Fix | Delete
[154] Fix | Delete
def code_filename(self, cid):
[155] Fix | Delete
code = codetable[cid]
[156] Fix | Delete
return code.co_filename
[157] Fix | Delete
[158] Fix | Delete
#----------called by a DictProxy----------
[159] Fix | Delete
[160] Fix | Delete
def dict_keys(self, did):
[161] Fix | Delete
dict = dicttable[did]
[162] Fix | Delete
return dict.keys()
[163] Fix | Delete
[164] Fix | Delete
def dict_item(self, did, key):
[165] Fix | Delete
dict = dicttable[did]
[166] Fix | Delete
value = dict[key]
[167] Fix | Delete
value = repr(value)
[168] Fix | Delete
return value
[169] Fix | Delete
[170] Fix | Delete
#----------end class IdbAdapter----------
[171] Fix | Delete
[172] Fix | Delete
[173] Fix | Delete
def start_debugger(rpchandler, gui_adap_oid):
[174] Fix | Delete
"""Start the debugger and its RPC link in the Python subprocess
[175] Fix | Delete
[176] Fix | Delete
Start the subprocess side of the split debugger and set up that side of the
[177] Fix | Delete
RPC link by instantiating the GUIProxy, Idb debugger, and IdbAdapter
[178] Fix | Delete
objects and linking them together. Register the IdbAdapter with the
[179] Fix | Delete
RPCServer to handle RPC requests from the split debugger GUI via the
[180] Fix | Delete
IdbProxy.
[181] Fix | Delete
[182] Fix | Delete
"""
[183] Fix | Delete
gui_proxy = GUIProxy(rpchandler, gui_adap_oid)
[184] Fix | Delete
idb = Debugger.Idb(gui_proxy)
[185] Fix | Delete
idb_adap = IdbAdapter(idb)
[186] Fix | Delete
rpchandler.register(idb_adap_oid, idb_adap)
[187] Fix | Delete
return idb_adap_oid
[188] Fix | Delete
[189] Fix | Delete
[190] Fix | Delete
#=======================================
[191] Fix | Delete
#
[192] Fix | Delete
# In the IDLE process:
[193] Fix | Delete
[194] Fix | Delete
[195] Fix | Delete
class FrameProxy:
[196] Fix | Delete
[197] Fix | Delete
def __init__(self, conn, fid):
[198] Fix | Delete
self._conn = conn
[199] Fix | Delete
self._fid = fid
[200] Fix | Delete
self._oid = "idb_adapter"
[201] Fix | Delete
self._dictcache = {}
[202] Fix | Delete
[203] Fix | Delete
def __getattr__(self, name):
[204] Fix | Delete
if name[:1] == "_":
[205] Fix | Delete
raise AttributeError, name
[206] Fix | Delete
if name == "f_code":
[207] Fix | Delete
return self._get_f_code()
[208] Fix | Delete
if name == "f_globals":
[209] Fix | Delete
return self._get_f_globals()
[210] Fix | Delete
if name == "f_locals":
[211] Fix | Delete
return self._get_f_locals()
[212] Fix | Delete
return self._conn.remotecall(self._oid, "frame_attr",
[213] Fix | Delete
(self._fid, name), {})
[214] Fix | Delete
[215] Fix | Delete
def _get_f_code(self):
[216] Fix | Delete
cid = self._conn.remotecall(self._oid, "frame_code", (self._fid,), {})
[217] Fix | Delete
return CodeProxy(self._conn, self._oid, cid)
[218] Fix | Delete
[219] Fix | Delete
def _get_f_globals(self):
[220] Fix | Delete
did = self._conn.remotecall(self._oid, "frame_globals",
[221] Fix | Delete
(self._fid,), {})
[222] Fix | Delete
return self._get_dict_proxy(did)
[223] Fix | Delete
[224] Fix | Delete
def _get_f_locals(self):
[225] Fix | Delete
did = self._conn.remotecall(self._oid, "frame_locals",
[226] Fix | Delete
(self._fid,), {})
[227] Fix | Delete
return self._get_dict_proxy(did)
[228] Fix | Delete
[229] Fix | Delete
def _get_dict_proxy(self, did):
[230] Fix | Delete
if did in self._dictcache:
[231] Fix | Delete
return self._dictcache[did]
[232] Fix | Delete
dp = DictProxy(self._conn, self._oid, did)
[233] Fix | Delete
self._dictcache[did] = dp
[234] Fix | Delete
return dp
[235] Fix | Delete
[236] Fix | Delete
[237] Fix | Delete
class CodeProxy:
[238] Fix | Delete
[239] Fix | Delete
def __init__(self, conn, oid, cid):
[240] Fix | Delete
self._conn = conn
[241] Fix | Delete
self._oid = oid
[242] Fix | Delete
self._cid = cid
[243] Fix | Delete
[244] Fix | Delete
def __getattr__(self, name):
[245] Fix | Delete
if name == "co_name":
[246] Fix | Delete
return self._conn.remotecall(self._oid, "code_name",
[247] Fix | Delete
(self._cid,), {})
[248] Fix | Delete
if name == "co_filename":
[249] Fix | Delete
return self._conn.remotecall(self._oid, "code_filename",
[250] Fix | Delete
(self._cid,), {})
[251] Fix | Delete
[252] Fix | Delete
[253] Fix | Delete
class DictProxy:
[254] Fix | Delete
[255] Fix | Delete
def __init__(self, conn, oid, did):
[256] Fix | Delete
self._conn = conn
[257] Fix | Delete
self._oid = oid
[258] Fix | Delete
self._did = did
[259] Fix | Delete
[260] Fix | Delete
def keys(self):
[261] Fix | Delete
return self._conn.remotecall(self._oid, "dict_keys", (self._did,), {})
[262] Fix | Delete
[263] Fix | Delete
def __getitem__(self, key):
[264] Fix | Delete
return self._conn.remotecall(self._oid, "dict_item",
[265] Fix | Delete
(self._did, key), {})
[266] Fix | Delete
[267] Fix | Delete
def __getattr__(self, name):
[268] Fix | Delete
##print >>sys.__stderr__, "failed DictProxy.__getattr__:", name
[269] Fix | Delete
raise AttributeError, name
[270] Fix | Delete
[271] Fix | Delete
[272] Fix | Delete
class GUIAdapter:
[273] Fix | Delete
[274] Fix | Delete
def __init__(self, conn, gui):
[275] Fix | Delete
self.conn = conn
[276] Fix | Delete
self.gui = gui
[277] Fix | Delete
[278] Fix | Delete
def interaction(self, message, fid, modified_info):
[279] Fix | Delete
##print "interaction: (%s, %s, %s)" % (message, fid, modified_info)
[280] Fix | Delete
frame = FrameProxy(self.conn, fid)
[281] Fix | Delete
self.gui.interaction(message, frame, modified_info)
[282] Fix | Delete
[283] Fix | Delete
[284] Fix | Delete
class IdbProxy:
[285] Fix | Delete
[286] Fix | Delete
def __init__(self, conn, shell, oid):
[287] Fix | Delete
self.oid = oid
[288] Fix | Delete
self.conn = conn
[289] Fix | Delete
self.shell = shell
[290] Fix | Delete
[291] Fix | Delete
def call(self, methodname, *args, **kwargs):
[292] Fix | Delete
##print "**IdbProxy.call %s %s %s" % (methodname, args, kwargs)
[293] Fix | Delete
value = self.conn.remotecall(self.oid, methodname, args, kwargs)
[294] Fix | Delete
##print "**IdbProxy.call %s returns %r" % (methodname, value)
[295] Fix | Delete
return value
[296] Fix | Delete
[297] Fix | Delete
def run(self, cmd, locals):
[298] Fix | Delete
# Ignores locals on purpose!
[299] Fix | Delete
seq = self.conn.asyncqueue(self.oid, "run", (cmd,), {})
[300] Fix | Delete
self.shell.interp.active_seq = seq
[301] Fix | Delete
[302] Fix | Delete
def get_stack(self, frame, tbid):
[303] Fix | Delete
# passing frame and traceback IDs, not the objects themselves
[304] Fix | Delete
stack, i = self.call("get_stack", frame._fid, tbid)
[305] Fix | Delete
stack = [(FrameProxy(self.conn, fid), k) for fid, k in stack]
[306] Fix | Delete
return stack, i
[307] Fix | Delete
[308] Fix | Delete
def set_continue(self):
[309] Fix | Delete
self.call("set_continue")
[310] Fix | Delete
[311] Fix | Delete
def set_step(self):
[312] Fix | Delete
self.call("set_step")
[313] Fix | Delete
[314] Fix | Delete
def set_next(self, frame):
[315] Fix | Delete
self.call("set_next", frame._fid)
[316] Fix | Delete
[317] Fix | Delete
def set_return(self, frame):
[318] Fix | Delete
self.call("set_return", frame._fid)
[319] Fix | Delete
[320] Fix | Delete
def set_quit(self):
[321] Fix | Delete
self.call("set_quit")
[322] Fix | Delete
[323] Fix | Delete
def set_break(self, filename, lineno):
[324] Fix | Delete
msg = self.call("set_break", filename, lineno)
[325] Fix | Delete
return msg
[326] Fix | Delete
[327] Fix | Delete
def clear_break(self, filename, lineno):
[328] Fix | Delete
msg = self.call("clear_break", filename, lineno)
[329] Fix | Delete
return msg
[330] Fix | Delete
[331] Fix | Delete
def clear_all_file_breaks(self, filename):
[332] Fix | Delete
msg = self.call("clear_all_file_breaks", filename)
[333] Fix | Delete
return msg
[334] Fix | Delete
[335] Fix | Delete
def start_remote_debugger(rpcclt, pyshell):
[336] Fix | Delete
"""Start the subprocess debugger, initialize the debugger GUI and RPC link
[337] Fix | Delete
[338] Fix | Delete
Request the RPCServer start the Python subprocess debugger and link. Set
[339] Fix | Delete
up the Idle side of the split debugger by instantiating the IdbProxy,
[340] Fix | Delete
debugger GUI, and debugger GUIAdapter objects and linking them together.
[341] Fix | Delete
[342] Fix | Delete
Register the GUIAdapter with the RPCClient to handle debugger GUI
[343] Fix | Delete
interaction requests coming from the subprocess debugger via the GUIProxy.
[344] Fix | Delete
[345] Fix | Delete
The IdbAdapter will pass execution and environment requests coming from the
[346] Fix | Delete
Idle debugger GUI to the subprocess debugger via the IdbProxy.
[347] Fix | Delete
[348] Fix | Delete
"""
[349] Fix | Delete
global idb_adap_oid
[350] Fix | Delete
[351] Fix | Delete
idb_adap_oid = rpcclt.remotecall("exec", "start_the_debugger",\
[352] Fix | Delete
(gui_adap_oid,), {})
[353] Fix | Delete
idb_proxy = IdbProxy(rpcclt, pyshell, idb_adap_oid)
[354] Fix | Delete
gui = Debugger.Debugger(pyshell, idb_proxy)
[355] Fix | Delete
gui_adap = GUIAdapter(rpcclt, gui)
[356] Fix | Delete
rpcclt.register(gui_adap_oid, gui_adap)
[357] Fix | Delete
return gui
[358] Fix | Delete
[359] Fix | Delete
def close_remote_debugger(rpcclt):
[360] Fix | Delete
"""Shut down subprocess debugger and Idle side of debugger RPC link
[361] Fix | Delete
[362] Fix | Delete
Request that the RPCServer shut down the subprocess debugger and link.
[363] Fix | Delete
Unregister the GUIAdapter, which will cause a GC on the Idle process
[364] Fix | Delete
debugger and RPC link objects. (The second reference to the debugger GUI
[365] Fix | Delete
is deleted in PyShell.close_remote_debugger().)
[366] Fix | Delete
[367] Fix | Delete
"""
[368] Fix | Delete
close_subprocess_debugger(rpcclt)
[369] Fix | Delete
rpcclt.unregister(gui_adap_oid)
[370] Fix | Delete
[371] Fix | Delete
def close_subprocess_debugger(rpcclt):
[372] Fix | Delete
rpcclt.remotecall("exec", "stop_the_debugger", (idb_adap_oid,), {})
[373] Fix | Delete
[374] Fix | Delete
def restart_subprocess_debugger(rpcclt):
[375] Fix | Delete
idb_adap_oid_ret = rpcclt.remotecall("exec", "start_the_debugger",\
[376] Fix | Delete
(gui_adap_oid,), {})
[377] Fix | Delete
assert idb_adap_oid_ret == idb_adap_oid, 'Idb restarted with different oid'
[378] Fix | Delete
[379] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function