Skip to content

Commit beb9720

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 kisbg@inf.u-szeged.hu
1 parent f02de7a commit beb9720

File tree

10 files changed

+363
-17
lines changed

10 files changed

+363
-17
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ matrix:
1717
install: pip install --user pylint==1.6.5
1818
addons:
1919
apt:
20-
packages: [doxygen, cppcheck, vera++]
20+
packages: [doxygen, cppcheck, vera++, pybluez]
2121

2222
- name: "Linux/x86-64 Build & Correctness Tests"
2323
env:
@@ -65,7 +65,9 @@ matrix:
6565
- name: "Debugger Tests"
6666
env:
6767
- OPTS="--jerry-debugger"
68-
68+
addons:
69+
apt:
70+
packages: [pybluez]
6971
- name: "Conformance Tests"
7072
env:
7173
- OPTS="--test262"

docs/07.DEBUGGER.md

Lines changed: 26 additions & 2 deletions
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,7 +21,25 @@ 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-
## Debugging JavaScript applications
24+
## Setting up Bluetooth debugger server
25+
26+
The following arguments must be passed to `tools/build.py`:
27+
28+
`--jerry-bt-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+
42+
2543

2644
The debugger client must be connected to the server before the
2745
JavaScript application runs. On-the-fly attachment is supported
@@ -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_BT_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})
@@ -194,6 +200,11 @@ if(FEATURE_MEM_STATS)
194200
set(DEFINES_JERRY ${DEFINES_JERRY} JMEM_STATS)
195201
endif()
196202

203+
# Enable bluetooth_debugger
204+
if(FEATURE_BL_DEBUGGER)
205+
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_BL_DEBUGGER)
206+
endif()
207+
197208
# Enable debugger
198209
if(FEATURE_DEBUGGER)
199210
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_DEBUGGER)

jerry-debugger/jerry_client.py

Lines changed: 2 additions & 1 deletion
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,7 +292,7 @@ def main():
291292
if __name__ == "__main__":
292293
try:
293294
main()
294-
except socket.error as error_msg:
295+
except IOError as error_msg:
295296
ERRNO = error_msg.errno
296297
MSG = str(error_msg)
297298
if ERRNO == 111:

jerry-debugger/jerry_client_ws.py

Lines changed: 18 additions & 7 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,17 +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):
271-
272+
temp = address.split(":")
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+
elif len(temp) == 2:
278+
self.host = temp[0]
279+
self.port = int(temp[1])
280+
self.client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
281+
elif len(temp) == 6:
282+
self.host = address
283+
self.port = 1 # use default port
284+
self.client_socket = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
275285
else:
276-
self.host, self.port = address.split(":")
277-
self.port = int(self.port)
286+
raise Exception("Wrong address type")
278287

279-
print("Connecting to: %s:%s" % (self.host, self.port))
280288

281289
self.message_data = b""
282290
self.prompt = False
@@ -303,7 +311,6 @@ def __init__(self, address):
303311
self.nocolor = ''
304312
self.src_offset = 0
305313
self.src_offset_diff = 0
306-
self.client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
307314
self.client_socket.connect((self.host, self.port))
308315
self.non_interactive = False
309316
self.current_out = b""
@@ -385,7 +392,11 @@ def __init__(self, address):
385392
self.message_data = result[len_expected:]
386393

387394
def __del__(self):
388-
self.client_socket.close()
395+
try:
396+
self.client_socket.close()
397+
except AttributeError:
398+
pass
399+
389400

390401
def _exec_command(self, command_id):
391402
self.send_command(command_id)

jerry-ext/CMakeLists.txt

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

50+
if(FEATURE_BT_DEBUGGER)
51+
target_link_libraries(${JERRY_EXT_NAME} -lbluetooth)
52+
endif()
53+
5054
install(TARGETS ${JERRY_EXT_NAME} DESTINATION lib)
5155
install(DIRECTORY ${INCLUDE_EXT_PUBLIC}/ DESTINATION include)

0 commit comments

Comments
 (0)