Skip to content

Support Bluetooth communcation JerryScript debugger #2633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

kisbg
Copy link

@kisbg kisbg commented Dec 5, 2018

Documentation can be found in 07.DEBUGGER.md

JerryScript-DCO-1.0-Signed-off-by: Bence Gabor Kis [email protected]

@kisbg kisbg force-pushed the bluetooth-szakdoga branch 8 times, most recently from 29e9714 to 1ec6114 Compare December 7, 2018 13:59
@akosthekiss akosthekiss added the debugger Related to the debugger label Dec 13, 2018
@kisbg kisbg force-pushed the bluetooth-szakdoga branch from 1ec6114 to 698d9e8 Compare December 20, 2018 13:20
@kisbg kisbg changed the title [WIP] Support bluetooth communcation Jerry debugger Support Bluetooth communcation JerryScript debugger Dec 20, 2018
@kisbg kisbg force-pushed the bluetooth-szakdoga branch 2 times, most recently from b64d000 to 1ddda76 Compare December 21, 2018 08:47
@@ -73,9 +74,14 @@ if(FEATURE_MEM_STATS OR FEATURE_PARSER_DUMP OR FEATURE_REGEXP_DUMP)
set(FEATURE_LOGGING_MESSAGE " (FORCED BY STATS OR DUMP)")
endif()

if(FEATURE_BL_DEBUGGER)
set(FEATURE_DEBUGGER ON)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong indentation: two spaces are needed

Copy link
Author

@kisbg kisbg Jan 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed the suggested changes

@kisbg kisbg force-pushed the bluetooth-szakdoga branch from 1ddda76 to d7e045c Compare January 10, 2019 07:26
- sudo apt-get install -q libbluetooth-dev
- sudo apt-get install -q python-dev
- pip install --user pylint==1.6.5
- pip install --user pybluez
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do code smell and style checks need the installation of additional system and python packages?

But if they are needed, the system dependencies should be added to addons.apt.packages.

.travis.yml Outdated
install:
- sudo apt-get install -q libbluetooth-dev
- sudo apt-get install -q python-dev
- pip install --user pybluez
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System dependencies should be listed under addons.apt.packages.

Plus, I think the separating empty line should not be removed from between the jobs.


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

`--jerry-bl-debugger=on`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be wrong but I cannot recall having seen BL as an abbreviation for Bluetooth. I've only seen BT for Bluetooth and BLE for Bluetooth Low Energy, but not BL.

@@ -291,6 +292,15 @@ def main():
if __name__ == "__main__":
try:
main()
except bluetooth.BluetoothError as error_msg:
ERRNO = int(str(error_msg).split(",")[0].split("(")[1])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This string interpretation looks dangerous as well as superfluous.

So, a single except handler catching IOError as ... should be enough.

MSG = str(error_msg)
if ERRNO == 111:
sys.exit("Failed to connect to the JerryScript debugger.")
elif ERRNO == 32 or ERRNO == 104:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that these numeric values are copy-pasted from existing code but are there no symbolic names for these error numbers in the errno module? https://docs.python.org/2/library/errno.html

@@ -344,6 +345,9 @@ static const cli_opt_t main_opts[] =
.help = "dump regexp byte-code"),
CLI_OPT_DEF (.id = OPT_DEBUG_SERVER, .longopt = "start-debug-server",
.help = "start debug server and wait for a connecting client"),
CLI_OPT_DEF (.id = OPT_DEBUG_SERVER_TYPE, .longopt = "server-type", .meta = "TYPE",
.help = "choose a server type (choices : tcp or bluetooth) \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest prefixing the cli option with debug- as well as the help message (i.e., "debug server type").

@@ -612,7 +639,7 @@ main (int argc,

#endif /* JERRY_ENABLE_EXTERNAL_CONTEXT */

init_engine (flags, start_debug_server, debug_port);
init_engine (flags, start_debug_server, debug_server_type,debug_port);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: missing space after comma

}
else
{
printf ("bad argument (tcp or bluetooth)\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Command line argument validity check should not happen here at init_engine phase anymore. That should already be checked when arguments are processed around case OPT_DEBUG_SERVER_TYPE:.

@@ -419,13 +423,27 @@ context_alloc (size_t size,
static void
init_engine (jerry_init_flag_t flags, /**< initialized flags for the engine */
bool debug_server, /**< enable the debugger init or not */
const char *debug_server_type, /**< choose which type or server create */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This argument shouldn't be a string. As all "message transmission interfaces" have the same prototype, I think this function should have a function pointer argument, something like: bool (*jerryx_debugger_transport_create) (uint16_t port). And the call site should pass either jerryx_debugger_tcp_create or jerryx_debugger_bluetooth_create.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also prefer the function pointer argument.

@@ -31,6 +31,11 @@ void jerryx_debugger_after_connect (bool success);
*/
bool jerryx_debugger_tcp_create (uint16_t port);

/*
* Message transmission interfaces.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't repeat this comment. Just add the new declaration. The comment marks the beginning of a list. Only this list was one element long, until now.

@kisbg kisbg force-pushed the bluetooth-szakdoga branch from d7e045c to beb9720 Compare January 18, 2019 13:35
@@ -194,6 +200,11 @@ if(FEATURE_MEM_STATS)
set(DEFINES_JERRY ${DEFINES_JERRY} JMEM_STATS)
endif()

# Enable bluetooth_debugger
if(FEATURE_BL_DEBUGGER)
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_BL_DEBUGGER)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot this define can be added the same if(FEATURE_BL_DEBUGGER) check above?

#include "jerryscript-ext/debugger.h"
#include "jext-common.h"

#if defined (JERRY_DEBUGGER) && defined (JERRY_BL_DEBUGGER)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the jerry-core/CMakeLists.txt if the JERRY_BL_DEBUGGER is defined JERRY_DEBUGGER must be defined as well, so this check can be simplified.

*/
static bool
jerryx_debugger_bluetooth_send (jerry_debugger_transport_header_t *header_p, /**< bluetooth implementation */
uint8_t *message_p, /**< message to be sent */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong indentation.

{
int err_val = errno;
jerry_debugger_transport_close ();
jerryx_debugger_bluetooth_log_error (err_val);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each jerry_debugger_transport_close is followed by jerryx_debugger_bluetooth_log_error (err_val). How about adding the logging function to the end of the transport close function? Therefore it would be less function calls.

if (listen (server_socket, port) == -1)
{
close (server_socket);
jerryx_debugger_bluetooth_log_error(strerror (errno));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing spaces after each jerryx_debugger_bluetooth_log_error(strerror (errno)) function name.

bool
jerryx_debugger_bluetooth_create (uint16_t port)
{
JERRYX_ERROR_MSG ("suppoert for Bluetooth debugging is disabled.\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo suppoert

#else /* !JERRY_DEBUGGER || !JERRY_BL_DEBUGGER */

/**
* Dummy function when debugger is disabluetoothd.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of interesting word disabluetoothd, but probably a typo.

0,
JERRY_DEBUGGER_TRANSPORT_MAX_BUFFER_SIZE,
0,
JERRY_DEBUGGER_TRANSPORT_MAX_BUFFER_SIZE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 4 arguments are misaligned by 1 space.

@@ -419,13 +423,27 @@ context_alloc (size_t size,
static void
init_engine (jerry_init_flag_t flags, /**< initialized flags for the engine */
bool debug_server, /**< enable the debugger init or not */
const char *debug_server_type, /**< choose which type or server create */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also prefer the function pointer argument.

@kisbg kisbg force-pushed the bluetooth-szakdoga branch 9 times, most recently from 5c44d06 to 8e3a2ec Compare January 28, 2019 08:24
@kisbg
Copy link
Author

kisbg commented Feb 5, 2019

@akosthekiss @rerobika Thank you for the review!

@@ -73,6 +73,7 @@ if(FEATURE_MEM_STATS OR FEATURE_PARSER_DUMP OR FEATURE_REGEXP_DUMP)
set(FEATURE_LOGGING_MESSAGE " (FORCED BY STATS OR DUMP)")
endif()


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary new line.

- pip install --user pylint==1.6.5
- pip install --user pybluez


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the second new line is necessary?

set(DEFINES_EXT ${DEFINES_EXT} JERRY_BT_DEBUGGER)
endif()


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

bool
jerryx_debugger_bt_create (uint16_t port) /**< listening port */
{

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.


if (port > 30)
{
JERRYX_DEBUG_MSG ("bluetooth port range is 1-30\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the error message is correct, this check accepts the 0 port which is misleading.

} /* jerryx_debugger_bt_create */

#else /* !JERRY_BT_DEBUGGER */

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary new line.

{
if (check_feature (JERRY_FEATURE_DEBUGGER, cli_state.arg))
{
const char * temp = cli_consume_string (&cli_state);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const char * temp -> const char *temp

const char * temp = cli_consume_string (&cli_state);
if (strcmp (temp, "bluetooth") == 0)
{
debug_port = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the port is hard coded the check above for it could be an assert instead.

Documentation can be found in 07.DEBUGGER.md

JerryScript-DCO-1.0-Signed-off-by: Bence Gabor Kis [email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
debugger Related to the debugger
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants