Skip to content

Commit

Permalink
tizenrt: Disable debugger code if not enabled (#1798)
Browse files Browse the repository at this point in the history
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: #1795
Forwarded: #1798
IoT.js-DCO-1.0-Signed-off-by: Philippe Coval p.coval@samsung.com
  • Loading branch information
rzr authored and zherczeg committed Nov 20, 2018
1 parent be57848 commit f7adb75
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/iotjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand All @@ -65,6 +66,7 @@ static bool jerry_initialize(iotjs_environment_t* env) {

jerry_debugger_continue();
}
#endif

// Set magic strings.
iotjs_register_jerry_magic_string();
Expand Down Expand Up @@ -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)) {
Expand All @@ -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.
Expand All @@ -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);
Expand Down Expand Up @@ -265,13 +273,15 @@ 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();
iotjs_debuglog_release();

return iotjs_entry(argc, argv);
}
#endif

iotjs_environment_release();
iotjs_debuglog_release();
Expand Down
12 changes: 12 additions & 0 deletions src/iotjs_env.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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",
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand All @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions src/iotjs_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 10 additions & 1 deletion src/modules/iotjs_module_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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,
Expand Down Expand Up @@ -103,6 +106,7 @@ JS_FUNCTION(DebuggerGetSource) {

return ret_val;
}
#endif


JS_FUNCTION(CompileModule) {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f7adb75

Please sign in to comment.