bg>=dZddlmZddlmZddlmZmZddlTddl m Z ddl m Z ddl Z ddlZddlZddlZddlZddlZddlZddlZddlZddlZGd d eZGd d ZGd dejZGddZGddZGddejZdZ dZ!da"da#e j$e!dS)z4 Support remote access to a Python interpreter. )cmdhpy)heapycTarget)*)Console) mutbitsetNceZdZdS) SocketClosedN)__name__ __module__ __qualname__e/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib64/python3.11/site-packages/guppy/heapy/Remote.pyr r sDrr ceZdZdZdZdS)IsolatedCallerc||_dSNfunc)selfrs r__init__zIsolatedCaller.__init__"s  rc|j|i|Srr)rargskwdss r__call__zIsolatedCaller.__call__%sty$'$'''rN)r rrrrrrrrrs2 (((((rrceZdZddZdS)QueueWithReadlinec\ |dS#tj$rY)wxYw)N?)timeout)getqueueEmptyrsizes rreadlinezQueueWithReadline.readline*sB  xxx,,,;    s ++Nr!)r rrr+rrrr r )s(rr c2eZdZdZedZddZdS)InterruptableSocketc||_|jj|_|jj|_|jj|_|jj|_|jj|_dSr)_backingfilenoclosereadablewritableseekable)rbackings rrzInterruptableSocket.__init__6sI m* ](  .  .  . rc|jjSr)r0closedrs rr8zInterruptableSocket.closed>s }##rr!ctj|gggdds tj|gggdd|j|S)Nr$r)selectr0readr)s rr<zInterruptableSocket.readBs]-B44Q7  -B44Q7 }!!$'''rNr,)r rrrpropertyr8r<rrrr.r.5sR///$$X$((((((rr.c$eZdZdZddZddZdS) NotiInputc"||_||_dSrinputoutput)rrBrCs rrzNotiInput.__init__Js  rr!c,||Sr)r+r)s rr<zNotiInput.readNs}}T"""rct|jt|j|Sr)rCwriteREADLINErBr+r)s rr+zNotiInput.readlineRs. (###z""4(((rNr,)r rrrr<r+rrrr?r?IsK####))))))rr?ceZdZejZejZdZdZ ddZ dZ dZ dZ dZd Zd ZejjZd ZeZd Zd ZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dS)Annexrz Ncbtj||t}t|f|_||_|jjd |j |_ d|_ d|_ tj|_i|_|ddS)Nzguppy.heapy.Remoter)rCmdr HEAPYPORT LOCALHOSTserver_addresstargetsysmodulesr asynch_closer2socketisclosed_thread allocate_lock closelock intlocalsdo_reset)rrPports rrzAnnex.__init__]s  <D($/ z)*>?NN      .00  brc|j |jsd|_||jn#|jwxYwt |drX|jrCtj dt |dr|j=dSdSdSdS)Nr#thr$) rXacquirerU disconnectreleasehasattrr]is_alivetimesleepr9s rrSzAnnex.asynch_closens     %= " ! !!! N " " $ $ $ $DN " " $ $ $ $dD!! dg&6&6&8&8  JsOOOdD!! dg&6&6&8&8         s "AA2c tj|j|j|_|jsc |j|jnD#t $rtj$r|jrtj dYnwxYw|jcdStj |j dddd|_ ttj t|j dddd|j |_t"j|_|t(j||j|j dS) Nwbr) bufferingzutf-8T)encoding write_throughrb)stdinstdout)rTaddress_family socket_typerUconnectrO SystemExiterrorrcrdio TextIOWrappermakefilermr?r.rlrQstderrstart_ki_threadrrLrr9s rrpz Annex.connectsmD$7$($466 -   ##D$7888   <   = 1   -  F& K  3 3D222 r/  4 4TQ 4 G G H HD 2 2 237;@@ j   TZ DDDDDsA 5BBc,tjtj_jfd}t j|d_jdj j_ j dS)NrAc jurnj}|snR|tkr.jur$t jjjtnj |junjur&t jjjtdSdS#jur%t jjjtwwxYwr) rTrBr+KEYBOARDINTERRUPTr set_async_excrP annex_threadKeyboardInterruptputr )lineostdinr'rrTs rrunz"Annex.start_ki_thread..runs 7 ++!<0022D000!T[00"01I1BDDD" $ ++T[((()A)577777)(6T[((()A)57777)s A7B++0Cr)rPrhp) r rlr?rCrT threadingThreadr]rY _hiding_tag_start)rrrr'rTs` @@@rrwzAnnex.start_ki_threads"##U&,m555  7 7 7 7 7 7 7 7""#(*,,,#~d3@  rcH|j}|dSd|_ |tn#t$rYnwxYw |tjn#t$rYnwxYw |n#t$rYnwxYwdt_dSr) rTsendDONE Exceptionshutdown SHUT_RDWRr2rQlast_traceback)rsocks rr_zAnnex.disconnects{ < F   IIdOOOO    D   MM&* + + + +    D   JJLLLL    D !s0/ <<A A-,A-1B BBc.|dS)Nr#)rSrargs rdo_closezAnnex.do_closes qrc2td|jdS)Naclose ----- Close and disable this remote connection completely. It can then not be reopened other than by some command from within the target process. Normally you shouldn't need to use this command, because you can return to the Monitor via other commands ( or .) keeping the connection open. But it might be useful when you want to get rid of the remote control interpreter and thread, if it uses too much memory or disturbs the target process in some other way.fileprintrmr9s r help_closezAnnex.help_closes/ %,0; 8 8 8 8 8 8rc2td|jdS)Nzh(elp) ----- Without argument, print the list of available commands. With a command name as argument, print help about that command.rrr9s rhelp_hz Annex.help_hs8 CJN V V V V V Vrctj}tj}tj} |jt_|jt_|jt_t tjtj|j}|d|jz|t_|t_|t_dS#|t_|t_|t_wxYw)N)rlrmlocalsz8Remote interactive console. To return to Annex, type %r.)rQrlrmrvr rYinteractEOF_key_sequence)rrrostdoutostderrcons rdo_intz Annex.do_ints** ! CICJCJ #*!%111C LLJ$% & & & CI CJ CJJJCI CJ CJ s A;C&C-c2td|jdS)Na{int ----- Interactive console. Bring up a Python console in the Remote Control interpreter. This console will initially have access to a heapy constructor, named hpy, and a ready-made instance, named hp, and the target (see also the reset command). Other things may be imported as needed. After returning to the Annex (by q) or to the Monitor (by . or ), the data in the interactive console will remain there - and will be available till the next time the console is entered. But the data may be cleared and reset to the initial state - a new heapy instance will be created - by the 'reset' command of Annex. It should be noted that the interpreter thread under investigation is executing in parallell with the remote control interpreter. So there may be some problems to do with that if both are executing at the same time. This has to be dealt with for each case specifically.rrr9s rhelp_intzAnnex.help_int s7 ?$FJ[% R R R R R Rr a1e55f5dc4c9f708311e9f97b8098cd3cN|jd}g}||_g}||j|j<td|j|||jd|j|g}|}|j||zrt d|jt|D]d\}}|||zrGt d|z|jt ||j |jent d|j|`|j|j=dS)Nr0 __builtins__zIsolation test failed.rz)-- Shortest Path(s) to testobjects[%d] --zIsolation test succeeded.) rY_a_bnameevalheapisorrm enumerateshpaths) rrrab testobjectshivs r do_isolatestzAnnex.do_isolatest#sI ^D !  &'t{# S$.!!!~n5~  GGII 26; ! # A * = = = =!+.. ? ?166!99q=?CaGdk[[[["&&))+$+>>>>  ? -DK @ @ @ @ G N4; ' ' 'rc2td|jdS)Nadisolatest ---------- Isolation test. Test that the target interpreter heap view is isolated from the data in the remote control interpreter. Data introduced here, eg in the interactive console, should not be seen in the heap as reported by hp.heap() etc. This is achieved by setting hp to not follow the calling interpreter root. However, this isolation may become broken. This test is intended to diagnose this problem. The test checks that none of a number of test objects is visible in the target heap view. If the test failed, it will show the shortest path(s) to each of the test objects that was visible.rrr9s rhelp_isolatestzAnnex.help_isolatestAs/ &-1K 9 9 9 9 9 9rc^td|jtd|jdS)Nz(To return to Monitor, type or .rz4To close this connection ('permanently'), type closerrs rdo_qz Annex.do_qPs4 8t{KKKK D4;WWWWWWrc2td|jdS)Nzq ----- Quit. This doesn't currently do anything except printing a message. (I thought it would be too confusing to have a q (quit) command from the Annex, when there was a similarly named command in the Monitor.)rrr9s rhelp_qz Annex.help_qTs8 D KO+  W W W W W Wrc|j|j|j||jd|jd|jd<dS)N)rrrPrr)rYclearupdaterrPrs rrZzAnnex.do_reset]sj  H88::{     #nT2src2td|jdS)Nareset ----- Reset things to an initial state. This resets the state of the interactive console data only, for now. It is reinitialized to contain the following: hpy --- from guppy import hpy hp --- hp = hpy() target --- a reference to some data in the target interpreter h --- h = hp; h is a shorthand for hp (The hpy function is modified here from the normal one so it sets some options to make it be concerned with the target interpreter heap under investigation rather than the current one.) rrr9s r help_resetzAnnex.help_reseths/  +      rctd|jtd|jtd|jjjz|jtd|jjjz|jtd|jjz|jtd|jjz|jtd|jdS)NzTarget overviewrz$------------------------------------ztarget.sys.executable = %sztarget.sys.argv = %sztarget.wd = %sztarget.pid = %d)rrmrPrQ executableargvwdpidrs rdo_statz Annex.do_statzs dk2222 44;GGGG ,ko()/3{ < < < < ,ko"#)- 6 6 6 6 ,kn#'; 0 0 0 0 ,ko$(K 1 1 1 1 44;GGGGGGrc2td|jdS)Nastat ----- Print an overview status table, with data from the target interpreter. In the table, sys.executable and sys.argv means the current values of those attributes in the sys module of the target interpreter. The row labeled target.wd is the working directory of the target interpreter, at the time the Remote Control interpreter was started (the actual working directory may have changed since that time). The row labeled target.pid is the process id of the target interpreter. rrr9s r help_statzAnnex.help_stats/  +      rcddlm}||i|}d|j_|j|j_|j|j_|j|jj_d|_|S)Nrrr#zhp.)guppyrViewis_hiding_calling_interpreterrPrr2reprefix)rrrrrs rrz Annex.hpysd S$ $  01-#%?  )+ &  rc |js||js|d |ng#t$rYn\t $rO t j|jn0#t $r#t jtjYYn wxYwYzwxYw~| |j| dS#| wxYw)NrKr#r) rUrprcmdloopr r traceback print_excrmrQr_rSr9s rrz Annex.runs7 m " } %LL$$$ % % LLNNNN+"""!E(%%%& ) 3 E E E E E#,&&& ) 3 D D D D %&%H % %!!!!m "*        D      sd8C)AC) B4C) B4&BB4)B.*B4+C)-B..B41C)3B44C))C?r)$r rrrTAF_INETrn SOCK_STREAMro use_rawinputpromptrrSrprwr_rrrrLdo_helpdo_hr help_helprrrrrrrrZrrrrrrrrrIrIWs^N$KL F"(EEE:!!!F"""& 8 8 8 7?DVVV I!!!6RRR*0F(((< 9 9 9XXXWWW 3 3 3$ H H H        rrIctdSttddrdSd}tjat j|dtiatt_dS)N#_is_guppy_heapy_remote_interpreter_rz# Set a flag to stop recursion when importing site # in case sitecustomize tries to do Remote.on() import sys sys._is_guppy_heapy_remote_interpreter_ = 1 import site from guppy.heapy import Remote Remote.Annex(target).run() rP)r|getattrrQrrPr interpreter) start_annexs ronrsbs91==K]__F%kHf3EFFL&FrcntdStdD]>} tj}|n%#t$rt jdY;wxYwtjtt ttj dtzsnt jd8dxaadS)N g?Tz t%d_async_exc) r|rangerPr2AttributeErrorrcrdrr{rqra RootState)rr2s roffrs 2YY   LE EGGG E     Jt        z222v'<)GHH   Jt     ! L666s 4AA)%__doc__ guppy.etcrrr guppy.heapyrrguppy.heapy.RemoteConstantsguppy.heapy.Consoler guppy.setsr atexitrsr'r;rTrQrcrVrrrr rQueuer r.r?rLrIrrr|rPregisterrrrrs"&&&&&&&&))))''''''      9    ( ( ( ( ( ( ( (        ((((((((( ) ) ) ) ) ) ) )_ _ _ _ _ CG_ _ _ D ''',!!!8 r