
    h]                    R   S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SKJr  S SK	J
r
JrJrJr  S SKJrJr  S SKrS SKrSr Sq \R*                  " 5       r/ r \R0                  " 5       r " S S\5      r " S S	\R8                  5      rSS
 jrS rS r S r!SS jr"S r#S r$S r%g)    )annotationsN)adapter)jsonlog	messagingsockets)
componentssessionsc                      \ rS rSr% SrS\S'   S\S'    S\S'    S\S	'   S\S
'   S\S'   S rS rS rS r	S r
S rS rS rSrg)
Connection#   a_  A debug server that is connected to the adapter.

Servers that are not participating in a debug session are managed directly by the
corresponding Connection instance.

Servers that are participating in a debug session are managed by that sessions's
Server component instance, but Connection object remains, and takes over again
once the session ends.
booldisconnectedprocess_replacedzServer | Noneserverz
int | Nonepidppidzmessaging.JsonMessageChannelchannelc                
  ^  SSK Jn  ST l        ST l        S T l        S T l        [        R                  R                  U[        T 5      5      n[        R                  " UT 5      T l        T R                  R                  5          T R                  5         T R                  R                  S5      nU" S[        R                   " 5       5      nU" S["        5      T l        U" S["        SS	9T l        T R$                  S
:X  a  S T l        [        T 5      =T R                  l        Ul        [(           T R                  (       a
   S S S 5        g [+        U 4S j[,         5       5      (       a  [/        T  S35      e[1        [,        5      S:H  n[,        R3                  T 5        [4        R7                  5         S S S 5        URB                  " T R$                  5      nUc  URB                  " T R
                  5      nUc  [:        RD                  " ST 5        OT R
                  UR
                  :X  a`  UR                  nU(       a  URF                  R                  (       d2  [:        RH                  " SU5        T R                  R?                  5         g  URJ                  RM                  T 5        g W(       a  g [:        RD                  " ST 5         T R                  R                  SSS05        T R                  R                  SST R
                  05        T R                  R                  S5        T R                  R                  S5        g ! , (       d  f       GN= f! [8         a=    [:        R<                  " S5        T R                  R?                  5         [A        5          g f = f! [8         a    [:        R<                  " ST 5         GNf = f! [8         a3    [:        R<                  " S5        T R                  R?                  5          g f = f)Nr   )r
   FpydevdSystemInfoprocessr   r   Toptional c              3     >#    U  H6  nUR                   TR                   :H  =(       a    UR                  (       + v   M8     g 7fN)r   r   .0connselfs     jC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\debugpy/adapter/servers.py	<genexpr>&Connection.__init__.<locals>.<genexpr>c   s6       , HH(F1F1F-FF ,s   >Az% is already connected to this adapterz,Failed to accept incoming server connection:z2No active debug session for parent process of {0}.z!{0} is not expecting replacement.z*Failed to notify parent session about {0}:z(No clients to wait for - unblocking {0}.
initialize	adapterIDdebugpyattachsubProcessIdconfigurationDone
disconnectz&Failed to unblock orphaned subprocess:)'debugpy.adapterr
   r   r   r   r   r   JsonIOStreamfrom_socketstrJsonMessageChannelr   startauthenticaterequestr   objectintr   name_lockany_connectionsKeyErrorlenappend_connections_changedset	Exceptionr   swallow_exceptionclosedont_wait_for_first_connectiongetinfo
connectionerrorclientnotify_of_subprocess)	r    sockr
   streamrC   process_infois_first_serverparent_sessionparent_servers	   `        r!   __init__Connection.__init__?   s   ,! %''33D#d)D 33FDA*	<<''(:;D	4;;=9L#E3/DH$VS4@DIyyB 	.1$i7DLL
 $$    ,   #dV+P#QRR"%l"3q"8##D)$((*' D "dii0!%\\$((3N!HHI4Pxx>--- . 5 5%-*B*B*S*SIIA>RLL&&(
%%::4@" ;TB	!LL  Y/GHLL  NDHH+EFLL  !45LL  .Q *  	!!"PQLL  +,
 	8  
 %%@$0  	!!!"JKLL 	!sd   B(M ,M?M A'M/M N A<O 
MM M ANN!OO:PPc                J    SU R                   c  S-   $ SU R                    S3-   $ )NServerz[?]z[pid=]r   r    s    r!   __str__Connection.__str__   s+    DHH$45NNE$((1:MNN    c                    [         c  [        R                   c  g U R                  R                  SS[         05      nUS   [        R                   :w  a%  U R                  R	                  5         [        S5      eg )NpydevdAuthorizedebugServerAccessTokenclientAccessTokenz6Mismatched "clientAccessToken"; server not authorized.)access_tokenr   r   r2   r@   RuntimeError)r    auths     r!   r1   Connection.authenticate   sl    G$8$8$@||## 8,G
 #$(<(<<LL WXX =rW   c                $    UR                  S5      eNz=Requests from the debug server to the client are not allowed.
isnt_validr    r2   s     r!   r2   Connection.request   s      K
 	
rW   c                    g r   r   r    events     r!   rh   Connection.event   s    rW   c                8    U R                   R                  5         g r   r   r@   rg   s     r!   terminated_eventConnection.terminated_event   s    rW   c                   [            SU l        U R                  b  U R                  R                  5         O3U [        ;   a)  [        R                  U 5        [        R                  5         S S S 5        g ! , (       d  f       g = fNT)r6   r   r   r*   r8   remover<   r=   rT   s    r!   r*   Connection.disconnect   sU     $D{{& &&(%##D)$((* UUs   A#A33
Bc                    [            U R                  b  [        e[        R                  " SX5        [        X5      U l        SSS5        g! , (       d  f       g= f)zAttaches this server to the specified Session as a Server component.

Raises ValueError if the server already belongs to some session.
NzAttaching {0} to {1})r6   r   
ValueErrorr   rC   rQ   r    sessions     r!   attach_to_sessionConnection.attach_to_session   s<     {{&  HH+T; /DK	 UUs   ;A
A)r   r   r   r   r   r   N)__name__
__module____qualname____firstlineno____doc____annotations__rN   rU   r1   r2   rh   rl   r*   rv   __static_attributes__r   rW   r!   r   r   #   sf       
O
))d!LOY


+
0rW   r   c                  :  ^  \ rS rSr% Sr\R                  R                  rS\S'    " S S\R                  5      r	U 4S jr
\S 5       r\S	 5       rS
 r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\SS j5       r\S 5       rS rU 4S jrSrU =r$ )rQ      z1Handles the debug server side of a debug session.r   rD   c                      \ rS rSr0 SS_SS_SS_SS_SS_SS_S	S_S
S_SS_SS_SS_SS_SS_SS_SS_SS_SS_SSSSSSSS/ / / S.ErSrg)Server.Capabilities   supportsCompletionsRequestFsupportsConditionalBreakpoints supportsConfigurationDoneRequestsupportsDataBreakpoints supportsDelayedStackTraceLoadingsupportsDisassembleRequestsupportsEvaluateForHoverssupportsExceptionInfoRequestsupportsExceptionOptionssupportsFunctionBreakpointssupportsGotoTargetsRequest!supportsHitConditionalBreakpointssupportsLoadedSourcesRequestsupportsLogPointssupportsModulesRequestsupportsReadMemoryRequestsupportsRestartFrameT)supportsRestartRequestsupportsSetExpressionsupportsSetVariablesupportsStepBacksupportsStepInTargetsRequestsupportsTerminateRequestsupportsTerminateThreadsRequestsupportsValueFormattingOptionsexceptionBreakpointFiltersadditionalModuleColumnssupportedChecksumAlgorithmsr   N)rx   ry   rz   r{   
PROPERTIESr~   r   rW   r!   Capabilitiesr      s    
(%
,e
 /
 &u	

 /
 )%
 (
 +E
 '
 *5
 )%
 0
 +E
  
 %e
  (!
" #E#
$ ',%*#( %,1(,/4.3*,')+-9

rW   r   c                B  > UR                   b   eU   UR                   (       a   e[        TU ]	  XR                  S9  X l        U R
                  R                  b   eU R
                  R                  (       an  U R
                  R                  R                  U R                  :w  a@  [        R                  " SU R
                  R                  R                  U R                  5        U R                  U R
                  l        Xl         S S S 5        g ! , (       d  f       g = f)N)r   z6Launcher reported PID={0}, but server reported PID={1})
r   superrN   r   rD   ru   r   launcherr   rC   )r    ru   rD   	__class__s      r!   rN   Server.__init__   s      (((~~%%GW.@.@A(O<<##+++||$$)>)>)B)Bdhh)NLLL))--HH
  $xxDLL!N WWs   C4D
Dc                .    U R                   R                  $ )z>Process ID of the debuggee process, as reported by the server.)rD   r   rT   s    r!   r   
Server.pid  s     """rW   c                .    U R                   R                  $ )zEParent process ID of the debuggee process, as reported by the server.)rD   r   rT   s    r!   r   Server.ppid  s     ###rW   c                    UR                  S5      (       d   eU R                  R                  5         U R                  R	                  U5      nUR                  5         U R                  XR                  5      U l        g )Nr$   )	
is_requestrD   r1   r   	propagatewait_for_responser   responsecapabilitiesrd   s     r!   r$   Server.initialize  sb    !!,////$$&,,((1!!# --d4D4DErW   c                $    UR                  S5      era   rb   rd   s     r!   r2   Server.request"  s       K
 	
rW   c                :    U R                   R                  U5        g r   )rF   propagate_after_startrg   s     r!   rh   Server.event.  s    ))%0rW   c                    g r   r   rg   s     r!   initialized_eventServer.initialized_event2  s     	rW   c                ^    U R                   (       d  U R                  R                  U5        g g r   )r   rF   r   rg   s     r!   process_eventServer.process_event7  s"     }}KK--e4 rW   c                p    U R                   R                  S;  a  U R                   R                  U5        g g )N)visualstudiovsformac)rF   	client_idr   rg   s     r!   continued_eventServer.continued_event=  s/    * ;;  (DDKK--e4 ErW   c                    U" S[         SS9S:X  a  SU R                  l        g U R                  (       d  U R                  R                  U5        g g )NpydevdReasonTr   processReplaced)r.   rD   r   r   rF   r   rg   s     r!   exited_eventServer.exited_eventU  sB    t48II
 04DOO, ==11%8 !rW   c                8    U R                   R                  5         g r   rk   rg   s     r!   rl   Server.terminated_eventb  s     	rW   c                (   [            SU l        U R                  U R                  l        [        U R                  5      =U R                  l        U R                  R                  l        S U R                  l        S S S 5        g ! , (       d  f       g = f)NF)	r6   is_connectedrD   r   handlersr.   r5   rI   r   rT   s    r!   detach_from_sessionServer.detach_from_sessiong  sZ     %D$(OODLL!;>t;OODLL 3 3 8%)DOO"	 UUs   A3B
Bc                  >^ ^ T R                   R                  (       at  [        R                  " ST 5        T R                  mTR
                  (       a  TR
                  R                  (       d  [        TU 4S jSS9  OT R                  U U4S jSS9  [           [        R                  T R                   5        [        R                  5         S S S 5        [        TT ]=  5         g ! , (       d  f       N= f)Nz*{0} is waiting for replacement subprocess.c                6   > U R                   TR                   :H  $ r   rS   )r   r    s    r!   <lambda>#Server.disconnect.<locals>.<lambda>v  s    $((dhh*>rW   <   )timeoutc                    > TR                   (       + =(       dK    TR                   R                  (       + =(       d)    [        U 4S jTR                   R                   5       5      $ )Nc              3  V   >#    U  H  nUR                   TR                   :H  v   M      g 7fr   rS   r   s     r!   r"   6Server.disconnect.<locals>.<lambda>.<locals>.<genexpr>}  s%      (I !HH0(Is   &))rF   r   r7   known_subprocessesrt   s   r!   r   r   z  sK    #NN* &~~::: (/(I(I rW   )rD   r   r   rC   ru   rF   r   wait_for_connectionwait_forr6   r8   rp   r<   r=   r   r*   )r    ru   r   s   `@r!   r*   Server.disconnectn  s    ??++ HHA4HllG>>)D)D#>    
 0 $$&  	 Us   4C$$
C2)r   rD   r   )rh   zmessaging.Event)rx   ry   rz   r{   r|   r	   	Componentmessage_handlerr}   r   rN   propertyr   r   r$   r2   rh   r   r   r   r   rl   r   r*   r~   __classcell__)r   s   @r!   rQ   rQ      s    ; **::O
z.. 
@"& # # $ $F 
 
 1 1   5 5
 5 5. 
9 
9  * rW   rQ   c                    [         R                  " S[        X5      q[        R
                  " 5         [         R                  " [        5      $ )NrQ   )r   server   listenerr
   report_socketsget_address)hostports     r!   r   r     s1    }}Xz4>Hx((rW   c                     [         S L$ r   )r   r   rW   r!   
is_servingr     s    4rW   c                      [         b  [         R                  5         S q [
        R                  " 5         g ! [         a    [        R                  " SS9   N6f = f)Nwarning)level)r   r@   r>   r   r?   r
   r   r   rW   r!   stop_servingr     sI    /NNH   /I./s   5 AAc                 b    [            [        [        5      sS S S 5        $ ! , (       d  f       g = fr   )r6   listr8   r   rW   r!   connectionsr     s    	L! 
s    
.c                  ^^^ UU4S jmTS:H  Tl         T(       a,  [        R                  " TSS9nSUl        UR	                  5         TS:w  a  [
        R                  " SU 5         [           [        R                  5         U4S j[         5       n[        US5      nUc  TR                   (       a  UsSSS5        $  SSS5        [        R                  5         Mu  ! , (       d  f       N$= f)	zWaits until there is a server matching the specified predicate connected to
this adapter, and returns the corresponding Connection.

If there is more than one server connection already available, returns the oldest
one.
c                    > [         R                  " T 5        STl        [           [        R                  5         S S S 5        g ! , (       d  f       g = fro   )timesleep	timed_outr6   r<   r=   )r   wait_for_timeouts   r!   r   -wait_for_connection.<locals>.wait_for_timeout  s1    

7%)" $$& UUs   A
Ar   z%servers.wait_for_connection() timeout)targetr5   Tz/{0} waiting for connection from debug server...c              3  F   >#    U  H  nT" U5      (       d  M  Uv   M     g 7fr   r   )r   r   	predicates     r!   r"   &wait_for_connection.<locals>.<genexpr>  s     FldioTTls   !	!N)r   	threadingThreaddaemonr0   r   rC   r6   r<   clearr8   nextwait)ru   r   r   threadconnsr   r   s    ``   @r!   r   r     s    ' ")A!!#*Q
 !|BGL
 &&(FlFEt$D#3#=#= U $>	  	!!# Us   ,AC
C)c                      [         R                  5         [           [         R                  5         [	        [
        5      (       d
   SSS5        g SSS5        MX  ! , (       d  f       N= f)zBlocks until all debug servers disconnect from the adapter.

If there are no server connections, waits until at least one is established first,
before waiting for it to disconnect.
N)r<   r   r6   r   r:   r8   r   rW   r!   wait_until_disconnectedr    sJ     !!# &&(|$$ U$  Us   *A
A(c                 l    [            [        R                  5         SSS5        g! , (       d  f       g= f)zdUnblocks any pending wait_until_disconnected() call that is waiting on the
first server to connect.
N)r6   r<   r=   r   rW   r!   rA   rA     s     
  " 
s   %
3c                  ^ ^^	^
 [         R                  " [        5      u  p4[        R                  [
        R                  R                  [        R                  5      SUS-   [        U5      -   /n[        R                  b  US[        R                  /-  nXQ-  nUS[        T 5      /-  n[        R                  " SU5         [        R                   " US[        R"                  [        R"                  [        R$                  S9m	/ m
T
R1                  S
R/                  T 5      5        UU
U 4S jn[2        R4                  " UST  S3T	R6                  4SS9R9                  5         U	UU
U 4S jn[2        R4                  " UST  S3SS9R9                  5         g ! [&         aB  n[        R(                  " ST 5        [*        R,                  " S	R/                  T U5      5      eS nAff = f)Nz	--connect:z--adapter-access-tokenz--pidz/Spawning attach-to-PID debugger injector: {0!r}r   )bufsizestdinstdoutstderrz7Failed to inject debug server into process with PID={0}z<Failed to inject debug server into process with PID={0}: {1}z$--- Starting attach to pid: {0} ---
c                  >   U R                  5       nU(       d  OKUR                  SS5      nTR                  U5        [        R                  " STUR                  5       5        Mc  [        R                  " ST5        g ! [         aC    [        R                  " 5       n[        R                  " US9  T" SUR                  5       5         g f = f)Nzutf-8replacezInjector[PID={0}] output: {1}zInjector[PID={0}] exited.)filer  )readlinedecoder;   r   rC   rstripr>   ioStringIO	traceback	print_excgetvalue)rI   lines	on_outputoutput_collectedr   s      r!   captureinject.<locals>.capture  s    	.({{7I6 ''-8#t{{}M  HH0#6 	.AQ'h

-	.s   A;A? ?A
CCzInjector[PID=z] stdoutT)r   r5   argsr   c                   > Sn [         R                   " 5       n [         R                  " S5        TR                  5       nUb=  US:w  a6  T" SS5        Tn/ mSR                  U5      nT" SSR                  U5      5        g [         R                   " 5       U-
  nT" SS	T	U4-  5        U (       dv  US
:  ap  Sn [        R
                  S;   aZ  T" SS5        T" SS5        T" SS5        T" SS5        T" SS5        T" SS5        T" SS5        T" SS5        T" SS5        T" SS5        U (       a%  Tn/ mSR                  U5      nU(       a	  T" SU5        GM8  )NFT   r   r  zAttach to PID failed.

 r
  z'Attaching to PID: %s (elapsed: %.2fs).

   )linuxlinux2z3
The attach to PID is taking longer than expected.
z1On Linux it's possible to customize the value of
z<`PYDEVD_GDB_SCAN_SHARED_LIBRARIES` so that fewer libraries.
z4are scanned when searching for the needed symbols.

zHi.e.: set in your environment variables (and restart your editor/client
z>so that it picks up the updated environment variable value):

zCPYDEVD_GDB_SCAN_SHARED_LIBRARIES=libdl, libltdl, libc, libfreebl3

zA-- the actual library may be different (the gdb output typically
zE-- writes the libraries that will be used, so, it should be possible
z8-- to test other libraries if the above doesn't work).

)r   r   polljoinsysplatform)
taking_longer_than_expectedinitial_time
returncodeoldcontentselapsedinjectorr  r  r   s
         r!   info_on_timeoutinject.<locals>.info_on_timeout  s   &+#yy{JJqM!J%? 3
 +C')$!wws|Hh(9:iikL0GDW~U /R<26/||'::!$S "$P "$[ "$T "$g "$^ "$c "$` "$d "$X +&#% 773<h1Q rW   z] info on timeout)r   r5   r   )r   r   r   r&  
executableospathdirnamer&   __file__r.   r   r\   r   rC   
subprocessPopenPIPESTDOUTr>   r?   r   MessageHandlingErrorformatr;   r   r   r
  r0   )r   debugpy_argsr  r   r   cmdlineexcr  r/  r.  r  s   ` `      @@r!   injectr?    s   $$X.JD 	
(()s
SY	G ',g.B.BCCGS""GHH>H
##//??$$
* CJJ3OP.  SE*oo	
 egL2 L2\ }SE9J%KTXegq  
Es	
 ,,JQQS
 	
	
s   AF 
G=GG)z	127.0.0.1r   r   )&
__future__r   r2  r6  r&  r   r   r&   r   debugpy.commonr   r   r   r   r+   r	   r
   r  r  r\   r   RLockr6   r8   Eventr<   r3   r   r   rQ   r   r   r   r   r   r  rA   r?  r   rW   r!   <module>rD     s   
 # 	  
     8 8 0  	 9 6 !( p0 p0fqZ!! qh) "
$D#OrW   