Skip to content

Commit 1ddda76

Browse files
author
Bence Gabor Kis
committed
Support Bluetooth communcation JerryScript debugger
Documentation can be found in 07.DEBUGGER.md JerryScript-DCO-1.0-Signed-off-by: Bence Gabor Kis [email protected]
1 parent 704eb45 commit 1ddda76

File tree

10 files changed

+381
-13
lines changed

10 files changed

+381
-13
lines changed

.travis.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ matrix:
1919
- name: "Checks"
2020
env:
2121
- OPTS="--check-signed-off=travis --check-cppcheck --check-doxygen --check-vera --check-license --check-magic-strings --check-pylint"
22-
install: pip install --user pylint==1.6.5
22+
install:
23+
- sudo apt-get install -q libbluetooth-dev
24+
- sudo apt-get install -q python-dev
25+
- pip install --user pylint==1.6.5
26+
- pip install --user pybluez
2327
addons:
2428
apt:
2529
packages: [doxygen, cppcheck, vera++]
@@ -68,7 +72,10 @@ matrix:
6872
- name: "Debugger Tests"
6973
env:
7074
- OPTS="--jerry-debugger"
71-
75+
install:
76+
- sudo apt-get install -q libbluetooth-dev
77+
- sudo apt-get install -q python-dev
78+
- pip install --user pybluez
7279
- name: "Conformance Tests"
7380
env:
7481
- OPTS="--test262"

docs/07.DEBUGGER.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This simple application demonstrates the communication protocol
99
between the client and server, and can be reused by integrated
1010
development environments.
1111

12-
## Setting up the debugger server
12+
## Setting up TCP/IP debugger server
1313

1414
The following arguments must be passed to `tools/build.py`:
1515

@@ -21,6 +21,24 @@ JerryScript extension, which transmits messages over TCP/IP networks.
2121
If necessary/implemented, any reliable stream or datagram based
2222
protocol can be used for transmitting debugger messages.
2323

24+
## Setting up Bluetooth debugger server
25+
26+
The following arguments must be passed to `tools/build.py`:
27+
28+
`--jerry-bl-debugger=on`
29+
30+
The transport layer of the communication protocol is pluggable.
31+
At the moment, a WebSocket-based implementation is provided as a
32+
JerryScript extension, which transmits messages over Bluetooth network.
33+
34+
The following library is needed to build JerryScript
35+
- libbluetooth-dev
36+
37+
The following python commands needed to run jerry-client.py
38+
- sudo apt-get install -q python-dev
39+
- pip install --user pylint==1.6.5
40+
- pip install --user pybluez
41+
2442
## Debugging JavaScript applications
2543

2644
The debugger client must be connected to the server before the
@@ -43,6 +61,12 @@ source code:
4361

4462
`--debugger-wait-source`
4563

64+
The following argument makes JerryScript create a server with
65+
the given type. There are two choices, tcp or bluetooth.
66+
(default: tcp)
67+
68+
`--server-type bluetooth`
69+
4670
It is also recommended to increase the log level to see
4771
the *Waiting for client connection* message:
4872

jerry-core/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ set(ENABLE_ALL_IN_ONE OFF CACHE BOOL "Enable all-in-one build?")
2222
# Optional features
2323
set(FEATURE_CPOINTER_32_BIT OFF CACHE BOOL "Enable 32 bit compressed pointers?")
2424
set(FEATURE_DEBUGGER OFF CACHE BOOL "Enable JerryScript debugger?")
25+
set(FEATURE_BL_DEBUGGER OFF CACHE BOOL "Enable JerryScript bluetooth?")
2526
set(FEATURE_ERROR_MESSAGES OFF CACHE BOOL "Enable error messages?")
2627
set(FEATURE_EXTERNAL_CONTEXT OFF CACHE BOOL "Enable external context?")
2728
set(FEATURE_JS_PARSER ON CACHE BOOL "Enable js-parser?")
@@ -73,9 +74,14 @@ if(FEATURE_MEM_STATS OR FEATURE_PARSER_DUMP OR FEATURE_REGEXP_DUMP)
7374
set(FEATURE_LOGGING_MESSAGE " (FORCED BY STATS OR DUMP)")
7475
endif()
7576

77+
if(FEATURE_BL_DEBUGGER)
78+
set(FEATURE_DEBUGGER ON)
79+
endif()
80+
7681
# Status messages
7782
message(STATUS "ENABLE_ALL_IN_ONE " ${ENABLE_ALL_IN_ONE} ${ENABLE_ALL_IN_ONE_MESSAGE})
7883
message(STATUS "FEATURE_CPOINTER_32_BIT " ${FEATURE_CPOINTER_32_BIT} ${FEATURE_CPOINTER_32_BIT_MESSAGE})
84+
message(STATUS "FEATURE_BL_DEBUGGER " ${FEATURE_BL_DEBUGGER})
7985
message(STATUS "FEATURE_DEBUGGER " ${FEATURE_DEBUGGER})
8086
message(STATUS "FEATURE_ERROR_MESSAGES " ${FEATURE_ERROR_MESSAGES})
8187
message(STATUS "FEATURE_EXTERNAL_CONTEXT " ${FEATURE_EXTERNAL_CONTEXT})
@@ -208,6 +214,11 @@ if(FEATURE_MEM_STATS)
208214
set(DEFINES_JERRY ${DEFINES_JERRY} JMEM_STATS)
209215
endif()
210216

217+
# Enable bluetooth_debugger
218+
if(FEATURE_BL_DEBUGGER)
219+
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_BL_DEBUGGER)
220+
endif()
221+
211222
# Enable debugger
212223
if(FEATURE_DEBUGGER)
213224
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_DEBUGGER)

jerry-debugger/jerry_client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import sys
2323
import logging
2424
import time
25+
import bluetooth
2526
import jerry_client_ws
2627

2728
def write(string):
@@ -291,6 +292,15 @@ def main():
291292
if __name__ == "__main__":
292293
try:
293294
main()
295+
except bluetooth.BluetoothError as error_msg:
296+
ERRNO = int(str(error_msg).split(",")[0].split("(")[1])
297+
MSG = str(error_msg)
298+
if ERRNO == 111:
299+
sys.exit("Failed to connect to the JerryScript debugger.")
300+
elif ERRNO == 32 or ERRNO == 104:
301+
sys.exit("Connection closed.")
302+
else:
303+
sys.exit("Failed to connect to the JerryScript debugger.\nError: %s" % (MSG))
294304
except socket.error as error_msg:
295305
ERRNO = error_msg.errno
296306
MSG = str(error_msg)

jerry-debugger/jerry_client_ws.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import socket
2323
import struct
2424
import sys
25+
import bluetooth
2526

2627
# Expected debugger protocol version.
2728
JERRY_DEBUGGER_VERSION = 8
@@ -266,15 +267,24 @@ def get_text(self):
266267

267268

268269
class JerryDebugger(object):
269-
# pylint: disable=too-many-instance-attributes,too-many-statements,too-many-public-methods,no-self-use
270+
# pylint: disable=too-many-instance-attributes,too-many-statements,too-many-public-methods,no-self-use,too-many-branches
270271
def __init__(self, address):
271272

272273
if ":" not in address:
273274
self.host = address
274275
self.port = 5001 # use default port
276+
self.client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
277+
278+
elif len(address.split(":")) == 2:
279+
self.host = address.split(":")[0]
280+
self.port = int(address.split(":")[1])
281+
self.client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
282+
elif len(address.split(":")) == 6:
283+
self.host = address
284+
self.port = 1
285+
self.client_socket = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
275286
else:
276-
self.host, self.port = address.split(":")
277-
self.port = int(self.port)
287+
sys.exit()
278288

279289
print("Connecting to: %s:%s" % (self.host, self.port))
280290

@@ -303,7 +313,6 @@ def __init__(self, address):
303313
self.nocolor = ''
304314
self.src_offset = 0
305315
self.src_offset_diff = 0
306-
self.client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
307316
self.client_socket.connect((self.host, self.port))
308317
self.non_interactive = False
309318
self.current_out = b""
@@ -385,7 +394,10 @@ def __init__(self, address):
385394
self.message_data = result[len_expected:]
386395

387396
def __del__(self):
388-
self.client_socket.close()
397+
try:
398+
self.client_socket.close()
399+
except AttributeError:
400+
print ('Wrong address type')
389401

390402
def _exec_command(self, command_id):
391403
self.send_command(command_id)

jerry-ext/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,9 @@ target_include_directories(${JERRY_EXT_NAME} PRIVATE ${INCLUDE_EXT_PRIVATE})
5353
target_compile_definitions(${JERRY_EXT_NAME} PUBLIC ${DEFINES_EXT})
5454
target_link_libraries(${JERRY_EXT_NAME} jerry-core)
5555

56+
if(FEATURE_BL_DEBUGGER)
57+
target_link_libraries(${JERRY_EXT_NAME} -lbluetooth)
58+
endif()
59+
5660
install(TARGETS ${JERRY_EXT_NAME} DESTINATION lib)
5761
install(DIRECTORY ${INCLUDE_EXT_PUBLIC}/ DESTINATION include)

0 commit comments

Comments
 (0)