[Debugger] Create a simplified transmission layer (#2781)

It supports the raw packet sending over a TCP/IP protocol

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
This commit is contained in:
Robert Sipka
2019-03-18 11:00:15 +01:00
committed by GitHub
parent fbd734ed28
commit 3d3e6fdf58
10 changed files with 328 additions and 35 deletions
+1 -1
View File
@@ -250,7 +250,7 @@ def src_check_args(args):
def main():
args = jerry_client_main.arguments_parse()
debugger = jerry_client_main.JerryDebugger(args.address)
debugger = jerry_client_main.JerryDebugger(args.address, args.channel)
debugger.non_interactive = args.non_interactive
logging.debug("Connected to JerryScript on %d port", debugger.port)
+16 -5
View File
@@ -22,6 +22,8 @@ import select
import struct
import sys
from jerry_client_websocket import WebSocket
from jerry_client_rawpacket import RawPacket
from jerry_client_tcp import Socket
# Expected debugger protocol version.
JERRY_DEBUGGER_VERSION = 8
@@ -134,7 +136,8 @@ def arguments_parse():
help="set exception config, usage 1: [Enable] or 0: [Disable]")
parser.add_argument("--client-source", action="store", default=[], type=str, nargs="+",
help="specify a javascript source file to execute")
parser.add_argument("--channel", choices=["websocket", "rawpacket"], default="websocket",
help="specify the communication channel (default: %(default)s)")
args = parser.parse_args()
if args.verbose:
@@ -262,8 +265,8 @@ class DebuggerAction(object):
class JerryDebugger(object):
# pylint: disable=too-many-instance-attributes,too-many-statements,too-many-public-methods,no-self-use
def __init__(self, address):
# pylint: disable=too-many-instance-attributes,too-many-statements,too-many-public-methods,no-self-use,redefined-variable-type
def __init__(self, address, channel):
if ":" not in address:
self.host = address
@@ -301,8 +304,15 @@ class JerryDebugger(object):
self.non_interactive = False
self.current_out = b""
self.current_log = b""
self.channel = None
self.channel = WebSocket(address=(self.host, self.port))
protocol = Socket()
if channel == "websocket":
self.channel = WebSocket(address=(self.host, self.port), protocol=protocol)
elif channel == "rawpacket":
self.channel = RawPacket(address=(self.host, self.port), protocol=protocol)
else:
raise Exception("Unsupported communication channel")
config_size = 8
# The server will send the configuration message after connection established
@@ -342,7 +352,8 @@ class JerryDebugger(object):
logging.debug("Compressed pointer size: %d", self.cp_size)
def __del__(self):
self.channel.close()
if self.channel is not None:
self.channel.close()
def _exec_command(self, command_id):
self.send_command(command_id)
+91
View File
@@ -0,0 +1,91 @@
#!/usr/bin/env python
# Copyright JS Foundation and other contributors, http://js.foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import struct
MAX_BUFFER_SIZE = 256
class RawPacket(object):
""" Simplified transmission layer. """
def __init__(self, address, protocol):
self.protocol = protocol
self.data_buffer = b""
self.address = address
def connect(self, config_size):
""" Create connection. """
self.protocol.connect(self.address)
self.data_buffer = b""
# It will return with the Network configurations, which has the following struct:
# header [1] - size[1]
# configuration [config_size]
len_expected = config_size + 1
while len(self.data_buffer) < len_expected:
self.data_buffer += self.protocol.receive_data()
expected = struct.pack("B", config_size)
if self.data_buffer[0:1] != expected:
raise Exception("Unexpected configuration")
result = self.data_buffer[1:len_expected]
self.data_buffer = self.data_buffer[len_expected:]
return result
def close(self):
""" Close connection. """
self.protocol.close()
def send_message(self, _, data):
""" Send message. """
msg_size = len(data)
while msg_size > 0:
bytes_send = self.protocol.send_data(data)
if bytes_send < msg_size:
data = data[bytes_send:]
msg_size -= bytes_send
def get_message(self, blocking):
""" Receive message. """
# Connection was closed
if self.data_buffer is None:
return None
while True:
if len(self.data_buffer) >= 1:
size = ord(self.data_buffer[0])
if size == 0:
raise Exception("Unexpected data frame")
if len(self.data_buffer) >= size + 1:
result = self.data_buffer[1:size + 1]
self.data_buffer = self.data_buffer[size + 1:]
return result
if not blocking and not self.protocol.ready():
return b''
received_data = self.protocol.receive_data(MAX_BUFFER_SIZE)
if not received_data:
return None
self.data_buffer += received_data
+1 -2
View File
@@ -15,14 +15,13 @@
# limitations under the License.
import struct
from jerry_client_tcp import Socket
MAX_BUFFER_SIZE = 128
WEBSOCKET_BINARY_FRAME = 2
WEBSOCKET_FIN_BIT = 0x80
class WebSocket(object):
def __init__(self, address, protocol=Socket()):
def __init__(self, address, protocol):
self.data_buffer = b""
self.protocol = protocol