Current File : //usr/share/gdb/python/gdb/dap/__pycache__/server.cpython-39.opt-1.pyc
a

ɱZh�$�@s&ddlZddlZddlZddlZddlZddlmZmZddlm	Z	m
Z
mZmZm
Z
mZmZmZddlmZiaiadaGdd�d�Zd"dd	�Zd
d�Zdd
dd�eeeed�dd�Zd#dd�Zdd�Zeddd�dd��Zedd
d�ed�dd���Zeddd
d�ed�d
d �ed �d!d���Z dS)$�N�)�start_json_writer�	read_json)�exec_and_log�
in_dap_thread�
in_gdb_thread�send_gdb�send_gdb_with_response�start_thread�log�	log_stack)�
type_checkc@s`eZdZdZdd�Zedd��Zdd�Zdd	�Zed
d��Z	edd
d��Z
ddd�Zdd�ZdS)�ServerzThe DAP server class.cCsX||_||_||_g|_tjddkr@tjddkr@t��|_n
t�	�|_d|_
|adS)Nr�r�F)�	in_stream�
out_stream�child_stream�delayed_events�sys�version_info�queueZQueue�write_queueZSimpleQueue�done�_server)�selfrrr�r�'/usr/share/gdb/python/gdb/dap/server.py�__init__1s
zServer.__init__c
Cs�|dd|dd�}zHd|vr(|d}ni}t|dfi|��}|durR||d<d|d<Wn>ty�}z&t�d	|d<t|�|d
<WYd}~n
d}~00|S)N�seq�response�command)Zrequest_seq�typer!Z	arguments�bodyT�successF�message)�	_commands�
BaseExceptionr�str)r�params�result�argsr#�errr�_handle_commandCs"�
"zServer._handle_commandcCs"|j��}|�dd|d��qdS)N�output�stdout)�categoryr.)r�readline�
send_event)r�linerrr�_read_inferior_output]s
��zServer._read_inferior_outputcCs&tdt�|�d�|j�|�dS)Nz
WROTE: <<<�>>>)r�json�dumpsr�put)r�objrrr�
_send_jsoniszServer._send_jsoncCs�td|j�t|j|j�|js|t|j�}tdt	�
|�d�|�|�}|�|�|j
}g|_
|D]\}}|�||�qdq|j�d�dS)z The main loop of the DAP server.z
output readerz	READ: <<<r5N)r
r4rrrrrrrr6r7r-r:rr2r8)r�cmdr*�events�eventr#rrr�	main_loopms


zServer.main_loopNcCs|j�||f�dS)z^Send a DAP event back to the client, but only after the
        current request has completed.N)r�append)rr=r#rrr�send_event_later�szServer.send_event_latercCs(d|d�}|dur||d<|�|�dS)z�Send an event to the DAP client.
        EVENT is the name of the event, a string.
        BODY is the body of the event, an arbitrary object.r=)r"r=Nr#)r:)rr=r#r9rrrr2�s�zServer.send_eventcCs
d|_dS)z"Request that the server shut down.TN)r)rrrr�shutdown�szServer.shutdown)N)N)
�__name__�
__module__�__qualname__�__doc__rrr-r4r:r>r@r2rArrrrr.s


rcCst�||�dS)z�Send an event to the DAP client.
    EVENT is the name of the event, a string.
    BODY is the body of the event, an arbitrary object.N)rr2)r=r#rrrr2�sr2cst����fdd��}|S)Ncs&ddlm}|rtd���|i|��S)Nr)�inferior_runningZ
notStopped)r<rF�	Exception)r+�kwargsrF��funcrr�check�sz!_check_not_running.<locals>.check)�	functools�wraps)rJrKrrIr�_check_not_running�s	rNTF)r �
on_dap_thread�expect_stopped)�namer rOrPcs����fdd�}|S)a)A decorator for DAP requests.

    This registers the function as the implementation of the DAP
    request NAME.  By default, the function is invoked in the gdb
    thread, and its result is returned as the 'body' of the DAP
    response.

    Some keyword arguments are provided as well:

    If RESPONSE is False, the result of the function will not be
    waited for and no 'body' will be in the response.

    If ON_DAP_THREAD is True, the function will be invoked in the DAP
    thread.  When ON_DAP_THREAD is True, RESPONSE may not be False.

    If EXPECT_STOPPED is True (the default), then the request will
    fail with the 'notStopped' reason if it is processed while the
    inferior is running.  When EXPECT_STOPPED is False, the request
    will proceed regardless of the inferior's state.
    csz�j}zWntyYn0t����r4t��}n.t����rR�fdd�}|}n�fdd�}|}�rnt|�}|t�<|S)Ncst��fdd��S)Ncs�fi���S�Nrr�r+rJrr�<lambda>��z:request.<locals>.wrap.<locals>.sync_call.<locals>.<lambda>)r	�r+rIrVr�	sync_call�sz(request.<locals>.wrap.<locals>.sync_callcst��fdd��S)Ncs�fi���SrRrrrSrrrT�rUz>request.<locals>.wrap.<locals>.non_sync_call.<locals>.<lambda>)rrVrIrVr�
non_sync_call�sz,request.<locals>.wrap.<locals>.non_sync_call)�__code__�AttributeErrorr
rrrNr&)rJ�coder;rWrX�rPrQrOr rIr�wrap�s$
zrequest.<locals>.wrapr)rQr rOrPr]rr\r�request�s,r^cs��fdd�}|S)z\A decorator that indicates that the wrapper function implements
    the DAP capability NAME.cs�t�<|SrR)�
_capabilitiesrI�rQ�valuerrr]szcapability.<locals>.wrapr)rQrar]rr`r�
capabilitysrbcCs(|tjvr$ttj|t�r$tj|SdS)z�Return the value of a boolean client capability.

    If the capability was not specified, or did not have boolean type,
    False is returned.F)r�config�
isinstance�bool)rQrrr�client_bool_capabilitys
rf�
initialize)rOcKs|t_t�d�t��S)NZinitialized)rrcr@r_�copyrVrrrrgs
�	terminate)rPZsupportsTerminateRequestcKstd�dS�N�kill)rrVrrrri#s�
disconnect)rOrPZsupportTerminateDebuggee)�terminateDebuggeecKs|rtd�t��dSrj)r	rrA)rmr+rrrrl)s)N)T)!rL�inspectr6rr�iorrZstartuprrrrr	r
rrZ	typecheckr
r_r&rrr2rNr(rer^rbrfrgrirlrrrr�<module>s@(
q
	��N