From f7adb756ece6631c98023d1fd281cf344c768d15 Mon Sep 17 00:00:00 2001 From: Philippe Coval Date: Tue, 20 Nov 2018 14:55:05 +0100 Subject: [PATCH] tizenrt: Disable debugger code if not enabled (#1798) Observed build issue on TizenRT (2.0+): iotjs.c:58: undefined reference to `jerryx_debugger_tcp_create' iotjs.c:59: undefined reference to `jerryx_debugger_ws_create' iotjs.c:58: undefined reference to `jerryx_debugger_after_connect' The whole part is disabled, even if only jerry-ext functions are not linked. This should not cause any issue on earlier versions of TizenRT debugger: Disable code if not desired This part is not as critical for TizenRT, but will help to make iotjs smaller. Thanks-to: Daeyeon Jeong daeyeon.jeong@samsung.com Relate-to: https://github.com/Samsung/iotjs/pull/1795 Forwarded: https://github.com/Samsung/iotjs/pull/1798 IoT.js-DCO-1.0-Signed-off-by: Philippe Coval p.coval@samsung.com --- src/iotjs.c | 14 ++++++++++++-- src/iotjs_env.c | 12 ++++++++++++ src/iotjs_env.h | 6 ++++++ src/modules/iotjs_module_process.c | 11 ++++++++++- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/iotjs.c b/src/iotjs.c index 2df7e0fae6..b50b9396e7 100644 --- a/src/iotjs.c +++ b/src/iotjs.c @@ -53,6 +53,7 @@ static bool jerry_initialize(iotjs_environment_t* env) { // Initialize jerry. jerry_init(jerry_flags); +#ifdef JERRY_DEBUGGER if (iotjs_environment_config(env)->debugger != NULL) { uint16_t port = iotjs_environment_config(env)->debugger->port; jerryx_debugger_after_connect(jerryx_debugger_tcp_create(port) && @@ -65,6 +66,7 @@ static bool jerry_initialize(iotjs_environment_t* env) { jerry_debugger_continue(); } +#endif // Set magic strings. iotjs_register_jerry_magic_string(); @@ -123,6 +125,8 @@ bool iotjs_initialize(iotjs_environment_t* env) { return true; } + +#ifdef JERRY_DEBUGGER void iotjs_restart(iotjs_environment_t* env, jerry_value_t jmain) { jerry_value_t abort_value = jerry_get_value_from_error(jmain, false); if (jerry_value_is_string(abort_value)) { @@ -142,6 +146,8 @@ void iotjs_restart(iotjs_environment_t* env, jerry_value_t jmain) { } jerry_release_value(abort_value); } +#endif + void iotjs_run(iotjs_environment_t* env) { // Evaluating 'iotjs.js' returns a function. @@ -155,10 +161,12 @@ void iotjs_run(iotjs_environment_t* env) { JERRY_SNAPSHOT_EXEC_ALLOW_STATIC); #endif +#ifdef JERRY_DEBUGGER if (jerry_value_is_abort(jmain)) { iotjs_restart(env, jmain); - } else if (jerry_value_is_error(jmain) && - !iotjs_environment_is_exiting(env)) { + } else +#endif + if (jerry_value_is_error(jmain) && !iotjs_environment_is_exiting(env)) { jerry_value_t errval = jerry_get_value_from_error(jmain, false); iotjs_uncaught_exception(errval); jerry_release_value(errval); @@ -265,6 +273,7 @@ int iotjs_entry(int argc, char** argv) { iotjs_terminate(env); exit: +#ifdef JERRY_DEBUGGER if (iotjs_environment_config(env)->debugger && iotjs_environment_config(env)->debugger->context_reset) { iotjs_environment_release(); @@ -272,6 +281,7 @@ int iotjs_entry(int argc, char** argv) { return iotjs_entry(argc, argv); } +#endif iotjs_environment_release(); iotjs_debuglog_release(); diff --git a/src/iotjs_env.c b/src/iotjs_env.c index 45de6228da..e6df9c0a5a 100644 --- a/src/iotjs_env.c +++ b/src/iotjs_env.c @@ -24,9 +24,11 @@ typedef enum { OPT_HELP, OPT_MEM_STATS, OPT_SHOW_OP, +#ifdef JERRY_DEBUGGER OPT_DEBUG_SERVER, OPT_DEBUGGER_WAIT_SOURCE, OPT_DEBUG_PORT, +#endif NUM_OF_OPTIONS } cli_option_id_t; @@ -66,7 +68,9 @@ void iotjs_environment_release() { return; iotjs_environment_t* env = iotjs_environment_get(); +#ifdef JERRY_DEBUGGER IOTJS_RELEASE(env->config.debugger); +#endif IOTJS_RELEASE(env->argv); initialized = false; } @@ -79,7 +83,9 @@ static void initialize(iotjs_environment_t* env) { env->state = kInitializing; env->config.memstat = false; env->config.show_opcode = false; +#ifdef JERRY_DEBUGGER env->config.debugger = NULL; +#endif env->exitcode = 0; } @@ -108,6 +114,7 @@ bool iotjs_environment_parse_command_line_arguments(iotjs_environment_t* env, .longopt = "show-opcodes", .help = "dump parser byte-code", }, +#ifdef JERRY_DEBUGGER { .id = OPT_DEBUG_SERVER, .opt = "d", @@ -126,6 +133,7 @@ bool iotjs_environment_parse_command_line_arguments(iotjs_environment_t* env, .more = 1, .help = "debug server port (default: 5001)", }, +#endif }; const cli_option_t* cur_opt; @@ -168,6 +176,7 @@ bool iotjs_environment_parse_command_line_arguments(iotjs_environment_t* env, case OPT_SHOW_OP: { env->config.show_opcode = true; } break; +#ifdef JERRY_DEBUGGER case OPT_DEBUGGER_WAIT_SOURCE: case OPT_DEBUG_SERVER: { if (!env->config.debugger) { @@ -185,6 +194,7 @@ bool iotjs_environment_parse_command_line_arguments(iotjs_environment_t* env, env->config.debugger->port = (uint16_t)strtoul(argv[i + 1], &pos, 10); } } break; +#endif default: break; } @@ -193,10 +203,12 @@ bool iotjs_environment_parse_command_line_arguments(iotjs_environment_t* env, i += (1 + cur_opt->more); } +#ifdef JERRY_DEBUGGER // If IoT.js is waiting for source from the debugger client, // Further processing over command line argument is not needed. if (env->config.debugger && env->config.debugger->wait_source) return true; +#endif // There must be at least one argument after processing the IoT.js args, if (argc - i < 1) { diff --git a/src/iotjs_env.h b/src/iotjs_env.h index d354cf0362..23b4017d32 100644 --- a/src/iotjs_env.h +++ b/src/iotjs_env.h @@ -18,16 +18,20 @@ #include "uv.h" +#ifdef JERRY_DEBUGGER typedef struct { bool wait_source; bool context_reset; uint16_t port; } DebuggerConfig; +#endif typedef struct { uint32_t memstat : 1; uint32_t show_opcode : 1; +#ifdef JERRY_DEBUGGER DebuggerConfig* debugger; +#endif } Config; typedef enum { @@ -73,7 +77,9 @@ uv_loop_t* iotjs_environment_loop(const iotjs_environment_t* env); void iotjs_environment_set_loop(iotjs_environment_t* env, uv_loop_t* loop); const Config* iotjs_environment_config(const iotjs_environment_t* env); +#ifdef JERRY_DEBUGGER const DebuggerConfig* iotjs_environment_dconfig(const iotjs_environment_t* env); +#endif void iotjs_environment_set_state(iotjs_environment_t* env, State s); bool iotjs_environment_is_exiting(iotjs_environment_t* env); diff --git a/src/modules/iotjs_module_process.c b/src/modules/iotjs_module_process.c index 751a547451..0b95ca8fd5 100644 --- a/src/modules/iotjs_module_process.c +++ b/src/modules/iotjs_module_process.c @@ -41,11 +41,13 @@ JS_FUNCTION(Compile) { iotjs_string_t source = JS_GET_ARG(1, string); const char* filename = iotjs_string_data(&file); - const iotjs_environment_t* env = iotjs_environment_get(); +#ifdef JERRY_DEBUGGER + const iotjs_environment_t* env = iotjs_environment_get(); if (iotjs_environment_config(env)->debugger != NULL) { jerry_debugger_stop(); } +#endif jerry_value_t jres = WrapEval(filename, strlen(filename), iotjs_string_data(&source), @@ -58,6 +60,7 @@ JS_FUNCTION(Compile) { } +#ifdef JERRY_DEBUGGER // Callback function for DebuggerGetSource static jerry_value_t wait_for_source_callback( const jerry_char_t* resource_name_p, size_t resource_name_size, @@ -103,6 +106,7 @@ JS_FUNCTION(DebuggerGetSource) { return ret_val; } +#endif JS_FUNCTION(CompileModule) { @@ -341,6 +345,7 @@ static void SetProcessPrivate(jerry_value_t process, bool wait_source) { CompileModule); iotjs_jval_set_method(private, IOTJS_MAGIC_STRING_READSOURCE, ReadSource); +#ifdef JERRY_DEBUGGER // debugger iotjs_jval_set_method(private, IOTJS_MAGIC_STRING_DEBUGGERGETSOURCE, DebuggerGetSource); @@ -350,6 +355,8 @@ static void SetProcessPrivate(jerry_value_t process, bool wait_source) { wait_source_val); jerry_release_value(wait_source_val); +#endif + jerry_release_value(private); } @@ -384,10 +391,12 @@ jerry_value_t InitProcess() { // Set iotjs SetProcessIotjs(process); bool wait_source = false; +#ifdef JERRY_DEBUGGER if (iotjs_environment_config(iotjs_environment_get())->debugger != NULL) { wait_source = iotjs_environment_config(iotjs_environment_get()) ->debugger->wait_source; } +#endif if (!wait_source) { SetProcessArgv(process);