avatar2.protocols package¶
Submodules¶
avatar2.protocols.gdb module¶
-
class
avatar2.protocols.gdb.
GDBProtocol
(gdb_executable='gdb', arch=<class 'avatar2.archs.arm.ARM'>, additional_args=[], async_message_handler=None, avatar_queue=None, origin=None)¶ Bases:
object
Main class for the gdb communication protocol :ivar gdb_executable: the path to the gdb which should be executed :ivar arch: the architecture :ivar additional_args: additional arguments for gdb :ivar avatar_queue : The queue serving as message sink for async messages
-
cont
()¶ Continues the execution of the target :returns: True on success
-
get_register_names
()¶ fetch all register names :returns: a list with all registers names, in order as known to gdb
-
read_memory
(address, wordsize=4, num_words=1, raw=False)¶ reads memory
Parameters: - address – Address to write to
- wordsize – the size of a read word (1, 2, 4 or 8)
- num_words – the amount of read words
- raw – Whether the read memory should be returned unprocessed
Returns: The read memory
-
read_register
(reg)¶
-
read_register_from_nr
(reg_num)¶ Gets the value of a single register
Parameters: reg_num – number of the register Returns: the value as integer on success, else None Todo: Implement function for multiple registers
-
remote_connect
(ip='127.0.0.1', port=3333)¶ connect to a remote gdb server
Parameters: - ip – ip of the remote gdb-server (default: localhost)
- port – port of the remote gdb-server (default: port)
Returns: True on successful connection
-
remote_connect_serial
(device='/dev/ttyACM0', baud_rate=38400, parity='none')¶ connect to a remote gdb server through a serial device
Parameters: - device – file representing the device (default: /dev/ttyACM0)
- baud_rate – baud_rate of the serial device (default: 38400)
- parity – parity of the serial link (default no parity)
Returns: True on successful connection
-
remote_disconnect
()¶ disconnects from remote target
-
remove_breakpoint
(bkpt)¶ Deletes a breakpoint
-
set_breakpoint
(line, hardware=False, temporary=False, regex=False, condition=None, ignore_count=0, thread=0)¶ Inserts a breakpoint
Parameters: - hardware (bool) – Hardware breakpoint
- tempory (bool) – Tempory breakpoint
- regex (str) – If set, inserts breakpoints matching the regex
- condition (str) – If set, inserts a breakpoint with specified condition
- ignore_count (int) – Amount of times the bp should be ignored
- thread (int) – Threadno in which this breakpoints should be added
Returns: The number of the breakpoint
-
set_endianness
(endianness='little')¶
-
set_watchpoint
(variable, write=True, read=False)¶
-
shutdown
()¶
-
step
()¶ Step one instruction on the target :returns: True on success
-
stop
()¶ Stops execution of the target :returns: True on success
-
write_memory
(address, wordsize, val, num_words=1, raw=False)¶ Writes memory
Parameters: - address – Address to write to
- wordsize – the size of the write (1, 2, 4 or 8)
- val (int if num_words == 1 and raw == False list if num_words > 1 and raw == False str or byte if raw == True) – the written value
- num_words – The amount of words to read
- raw – Specifies whether to write in raw or word mode
Returns: True on success else False
-
write_register
(reg, value)¶ Set one register on the target :returns: True on success
-
-
class
avatar2.protocols.gdb.
GDBResponseListener
(gdb_protocol, gdb_controller, avatar_queue, origin=None)¶ Bases:
threading.Thread
This class creates objects waiting for responses from the gdb-process Depending whether a synchronous or asynchronous message is received, it is either put in a synchronous dictionary or parsed/lifted to an AvatarMessage and added to the Queue of the according target
-
get_async_response
(timeout=0)¶
-
get_sync_response
(token, timeout=5)¶
-
get_token
()¶ Gets a token for a synchronous request :returns: An (integer) token
-
parse_async_notify
(response)¶ This functions converts gdb notify messages to an avatar message
Parameters: response – A pygdbmi response dictonary Returns: An avatar message
-
parse_async_response
(response)¶ This functions converts a async gdb/mi message to an avatar message
Parameters: response – A pygdbmi response dictonary
-
run
()¶
-
stop
()¶ Stops the listening thread. Useful for teardown of the target
-
avatar2.protocols.openocd module¶
-
class
avatar2.protocols.openocd.
OpenOCDProtocol
(openocd_script, openocd_executable='openocd', additional_args=[], telnet_port=4444, gdb_port=3333, origin=None, output_directory='/tmp')¶ Bases:
object
This class implements the openocd protocol. Although OpenOCD itself is very powerful, it is only used as monitor protocol, since all other functionalities are also exposed via the gdb-interface, which is easier to parse in an automatic manner.
Parameters: - openocd_script (str or list) – The openocd scripts to be executed.
- openocd_executable – The executable
- additional_args (list) – Additional arguments delivered to openocd.
- telnet_port – the port used for the telnet connection
- gdb_port – the port used for openocds gdb-server
-
connect
()¶ Connects to OpenOCDs telnet-server for all subsequent communication returns: True on success, else False
-
reset
()¶ Resets the target returns: True on success, else False
-
shutdown
()¶ Shuts down OpenOCD returns: True on success, else False
avatar2.protocols.qmp module¶
-
class
avatar2.protocols.qmp.
QMPProtocol
(port, origin=None)¶ Bases:
object
-
connect
()¶
-
execute_command
(cmd, args=None)¶
-
get_registers
()¶ Gets the current register state based on the hmp info registers command. In comparison to register-access with the register protocol, this function can also be called while the target is executing. returns: A dictionary with the registers
-
reset
()¶ Resets the target returns: True on success, else False
-
shutdown
()¶ returns: True on success, else False
-
avatar2.protocols.remote_memory module¶
-
class
avatar2.protocols.remote_memory.
RemoteMemoryProtocol
(rx_queue_name, tx_queue_name, avatar_queue, origin=None)¶ Bases:
object
This class listens to memoryforward requests and lifts them to avatar messages. Likewise it can be directed to emit memoryforward-response messages
Parameters: - rx_queue_name – Name of the queue for receiving
- tx_queue_name – Name of the queue for sending
- avatar_queue – Queue to dispatch received requests to
- origin – Reference to the Target utilizing this protocol
-
connect
()¶ Connect to the message queues for remote memory
:return True on success, else False
-
sendResponse
(id, value, success)¶
-
shutdown
()¶
-
class
avatar2.protocols.remote_memory.
RemoteMemoryReq
¶ Bases:
_ctypes.Structure
-
address
¶ Structure/Union member
-
id
¶ Structure/Union member
-
operation
¶ Structure/Union member
-
size
¶ Structure/Union member
-
value
¶ Structure/Union member
-
-
class
avatar2.protocols.remote_memory.
RemoteMemoryRequestListener
(rx_queue, avatar_queue, origin)¶ Bases:
threading.Thread
-
run
()¶
-
stop
()¶
-