3 ^l/@sdZddlZddlmZdZdadZiZiZiZ iZ ddZ dd Z Gd d d Z Gd d d ZddZGdddZGdddZGdddZGdddZGdddZddZddZddZd d!Zed"krdd#lmZed$d%d&d'dS)(aSupport for remote Python debugging. Some ASCII art to describe the structure: IN PYTHON SUBPROCESS # IN IDLE PROCESS # # oid='gui_adapter' +----------+ # +------------+ +-----+ | GUIProxy |--remote#call-->| GUIAdapter |--calls-->| GUI | +-----+--calls-->+----------+ # +------------+ +-----+ | Idb | # / +-----+<-calls--+------------+ # +----------+<--calls-/ | IdbAdapter |<--remote#call--| IdbProxy | +------------+ # +----------+ oid='idb_adapter' # The purpose of the Proxy and Adapter classes is to translate certain arguments and return values that cannot be transported through the RPC barrier, in particular frame and traceback objects. N)debugger idb_adapterZ gui_adaptercCst|}|t|<|S)N)id frametable)framefidr*/usr/lib64/python3.6/idlelib/debugger_r.py wrap_frame(sr cCsN|dkr dS|d}t|tjs$tt|}|t|<|d|d|f}|SdS)z0replace info[2], a traceback instance, by its IDNr) isinstancetypes TracebackTypeAssertionErrorrtracebacktable)info tracebackZ traceback_id modified_inforrr wrap_info-src@seZdZddZdddZdS)GUIProxycCs||_||_dS)N)connoid)selfr gui_adap_oidrrr __init__;szGUIProxy.__init__NcCs&|jj|jd|t|t|fidS)N interaction)r remotecallrr r)rmessagerrrrr r?s zGUIProxy.interaction)N)__name__ __module__ __qualname__rrrrrr r9src@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)S)* IdbAdaptercCs ||_dS)N)idb)rr#rrr rHszIdbAdapter.__init__cCs|jjdS)N)r#set_step)rrrr r$MszIdbAdapter.set_stepcCs|jjdS)N)r#set_quit)rrrr r%PszIdbAdapter.set_quitcCs|jjdS)N)r# set_continue)rrrr r&SszIdbAdapter.set_continuecCst|}|jj|dS)N)rr#set_next)rrrrrr r'VszIdbAdapter.set_nextcCst|}|jj|dS)N)rr# set_return)rrrrrr r(ZszIdbAdapter.set_returncCsFt|}|dkrd}nt|}|jj||\}}dd|D}||fS)NcSsg|]\}}t||fqSr)r ).0Zframe2krrr esz(IdbAdapter.get_stack..)rrr# get_stack)rrtbidrtbstackirrr r,^szIdbAdapter.get_stackcCsddl}|jj||jdS)Nr)__main__r#run__dict__)rcmdr1rrr r2hszIdbAdapter.runcCs|jj||}|S)N)r# set_break)rfilenamelinenomsgrrr r5lszIdbAdapter.set_breakcCs|jj||}|S)N)r# clear_break)rr6r7r8rrr r9pszIdbAdapter.clear_breakcCs|jj|}|S)N)r#clear_all_file_breaks)rr6r8rrr r:ts z IdbAdapter.clear_all_file_breakscCst|}t||S)N)rgetattr)rrnamerrrr frame_attrzszIdbAdapter.frame_attrcCs"t|}|j}t|}|t|<|S)N)r f_globalsr dicttable)rrrdictdidrrr frame_globals~s zIdbAdapter.frame_globalscCs"t|}|j}t|}|t|<|S)N)rf_localsrr?)rrrr@rArrr frame_localss zIdbAdapter.frame_localscCs"t|}|j}t|}|t|<|S)N)rf_coder codetable)rrrcodecidrrr frame_codes zIdbAdapter.frame_codecCst|}|jS)N)rFco_name)rrHrGrrr code_nameszIdbAdapter.code_namecCst|}|jS)N)rF co_filename)rrHrGrrr code_filenameszIdbAdapter.code_filenamecCs tddS)Nz"dict_keys not public or pickleable)NotImplementedError)rrArrr dict_keysszIdbAdapter.dict_keyscCst|}t|jS)N)r?listkeys)rrAr@rrr dict_keys_listszIdbAdapter.dict_keys_listcCst|}||}t|}|S)N)r?repr)rrAkeyr@valuerrr dict_itemszIdbAdapter.dict_itemN)rr r!rr$r%r&r'r(r,r2r5r9r:r=rBrDrIrKrMrOrRrVrrrr r"Fs(  r"cCs,t||}tj|}t|}|jt|tS)a|Start the debugger and its RPC link in the Python subprocess Start the subprocess side of the split debugger and set up that side of the RPC link by instantiating the GUIProxy, Idb debugger, and IdbAdapter objects and linking them together. Register the IdbAdapter with the RPCServer to handle RPC requests from the split debugger GUI via the IdbProxy. )rrZIdbr"register idb_adap_oid)Z rpchandlerrZ gui_proxyr#Zidb_adaprrr start_debuggers   rYc@s<eZdZddZddZddZddZd d Zd d Zd S) FrameProxycCs||_||_d|_i|_dS)Nr)_conn_fid_oid _dictcache)rrrrrr rszFrameProxy.__init__cCsb|dddkrt||dkr(|jS|dkr8|jS|dkrH|jS|jj|jd|j|fiS)Nr _rEr>rCr=)AttributeError _get_f_code_get_f_globals _get_f_localsr[rr]r\)rr<rrr __getattr__s zFrameProxy.__getattr__cCs(|jj|jd|jfi}t|j|j|S)NrI)r[rr]r\ CodeProxy)rrHrrr raszFrameProxy._get_f_codecCs"|jj|jd|jfi}|j|S)NrB)r[rr]r\_get_dict_proxy)rrArrr rbs  zFrameProxy._get_f_globalscCs"|jj|jd|jfi}|j|S)NrD)r[rr]r\rf)rrArrr rcs  zFrameProxy._get_f_localscCs2||jkr|j|St|j|j|}||j|<|S)N)r^ DictProxyr[r])rrAZdprrr rfs    zFrameProxy._get_dict_proxyN) rr r!rrdrarbrcrfrrrr rZs  rZc@seZdZddZddZdS)recCs||_||_||_dS)N)r[r]_cid)rrrrHrrr rszCodeProxy.__init__cCsD|dkr |jj|jd|jfiS|dkr@|jj|jd|jfiSdS)NrJrKrLrM)r[rr]rh)rr<rrr rds    zCodeProxy.__getattr__N)rr r!rrdrrrr resrec@s,eZdZddZddZddZddZd S) rgcCs||_||_||_dS)N)r[r]_did)rrrrArrr rszDictProxy.__init__cCs|jj|jd|jfiS)NrR)r[rr]ri)rrrr rQs zDictProxy.keyscCs|jj|jd|j|fiS)NrV)r[rr]ri)rrTrrr __getitem__s zDictProxy.__getitem__cCs t|dS)N)r`)rr<rrr rdszDictProxy.__getattr__N)rr r!rrQrjrdrrrr rgs rgc@seZdZddZddZdS) GUIAdaptercCs||_||_dS)N)rgui)rrrlrrr rszGUIAdapter.__init__cCs t|j|}|jj|||dS)N)rZrrlr)rrrrrrrr r!s zGUIAdapter.interactionN)rr r!rrrrrr rksrkc@sleZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZdS)IdbProxycCs||_||_||_dS)N)rrshell)rrrnrrrr r)szIdbProxy.__init__cOs|jj|j|||}|S)N)rrr)rZ methodnameargskwargsrUrrr call.sz IdbProxy.callcCs$|jj|jd|fi}||jj_dS)Nr2)rZ asyncqueuerrnZinterpZ active_seq)rr4localsseqrrr r24sz IdbProxy.runcs.jd|j|\}}fdd|D}||fS)Nr,cs g|]\}}tj||fqSr)rZr)r)rr*)rrr r+<sz&IdbProxy.get_stack..)rqr\)rrr-r/r0r)rr r,9szIdbProxy.get_stackcCs|jddS)Nr&)rq)rrrr r&?szIdbProxy.set_continuecCs|jddS)Nr$)rq)rrrr r$BszIdbProxy.set_stepcCs|jd|jdS)Nr')rqr\)rrrrr r'EszIdbProxy.set_nextcCs|jd|jdS)Nr()rqr\)rrrrr r(HszIdbProxy.set_returncCs|jddS)Nr%)rq)rrrr r%KszIdbProxy.set_quitcCs|jd||}|S)Nr5)rq)rr6r7r8rrr r5NszIdbProxy.set_breakcCs|jd||}|S)Nr9)rq)rr6r7r8rrr r9RszIdbProxy.clear_breakcCs|jd|}|S)Nr:)rq)rr6r8rrr r:Vs zIdbProxy.clear_all_file_breaksN)rr r!rrqr2r,r&r$r'r(r%r5r9r:rrrr rm'srmcCsD|jddtfiat||t}tj||}t||}|jt||S)a]Start the subprocess debugger, initialize the debugger GUI and RPC link Request the RPCServer start the Python subprocess debugger and link. Set up the Idle side of the split debugger by instantiating the IdbProxy, debugger GUI, and debugger GUIAdapter objects and linking them together. Register the GUIAdapter with the RPCClient to handle debugger GUI interaction requests coming from the subprocess debugger via the GUIProxy. The IdbAdapter will pass execution and environment requests coming from the Idle debugger GUI to the subprocess debugger via the IdbProxy. execstart_the_debugger)rrrXrmrZDebuggerrkrW)rpccltZpyshellZ idb_proxyrlZgui_adaprrr start_remote_debuggerZs     rwcCst||jtdS)a]Shut down subprocess debugger and Idle side of debugger RPC link Request that the RPCServer shut down the subprocess debugger and link. Unregister the GUIAdapter, which will cause a GC on the Idle process debugger and RPC link objects. (The second reference to the debugger GUI is deleted in pyshell.close_remote_debugger().) N)close_subprocess_debuggerZ unregisterr)rvrrr close_remote_debuggerrs rycCs|jddtfidS)NrtZstop_the_debugger)rrX)rvrrr rx~srxcCs&|jddtfi}|tks"tddS)Nrtruz Idb restarted with different oid)rrrXr)rvZidb_adap_oid_retrrr restart_subprocess_debuggers rzr1)mainzidlelib.idle_test.test_debuggerr F) verbosityexit)__doc__rZidlelibrZ debuggingrXrrr?rFrr rrr"rYrZrergrkrmrwryrxrzrZunittestr{rrrr s4   m* 3