improve fscript debugger

This commit is contained in:
lixianjing 2022-01-22 18:38:08 +08:00
parent aff10967e4
commit d472d8734b
10 changed files with 90 additions and 60 deletions

View File

@ -2,6 +2,7 @@
2022/01/22
* line_number支持设置高亮行。
* 完善fscript debugger
2022/01/21
* 完善fscript debugger并增加fdb命令行调试工具。

View File

@ -514,11 +514,9 @@ ret_t debugger_fscript_print_func(fscript_t* fscript, fscript_args_t* args, valu
uint32_t i = 0;
debugger_log_event_t event;
debugger_t* debugger = NULL;
return_value_if_fail(fscript != NULL, RET_BAD_PARAMS);
if (fscript != NULL && fscript->code_id != NULL) {
debugger = debugger_server_find_debugger(fscript->code_id);
}
debugger = debugger_server_find_debugger(fscript->code_id);
if (debugger != NULL) {
uint32_t line = fscript->curr->row;
value_set_bool(result, TRUE);
@ -685,10 +683,7 @@ ret_t debugger_fscript_exec_func(fscript_t* fscript, const char* name, fscript_f
debugger_t* debugger = NULL;
return_value_if_fail(fscript != NULL, RET_BAD_PARAMS);
if (fscript != NULL && fscript->code_id != NULL) {
debugger = debugger_server_find_debugger(fscript->code_id);
}
debugger = debugger_server_find_debugger(fscript->code_id);
if (debugger == NULL) {
return fscript_exec_func_default(fscript, iter, result);
} else {
@ -729,10 +724,7 @@ ret_t debugger_fscript_set_var(fscript_t* fscript, const char* name, const value
debugger_t* debugger = NULL;
return_value_if_fail(fscript != NULL, RET_BAD_PARAMS);
if (fscript != NULL && fscript->code_id != NULL) {
debugger = debugger_server_find_debugger(fscript->code_id);
}
debugger = debugger_server_find_debugger(fscript->code_id);
if (debugger == NULL) {
return fscript_set_var_default(fscript, name, v);
} else {

View File

@ -27,9 +27,6 @@
static ret_t debugger_fscript_on_connect(fscript_t* fscript) {
debugger_t* debugger = NULL;
return_value_if_fail(fscript != NULL, RET_BAD_PARAMS);
if (fscript->code_id == NULL) {
return RET_OK;
}
debugger = debugger_server_find_debugger(fscript->code_id);
if (debugger != NULL) {
@ -45,9 +42,6 @@ static ret_t debugger_fscript_on_connect(fscript_t* fscript) {
static ret_t debugger_fscript_on_disconnect(fscript_t* fscript) {
debugger_t* debugger = NULL;
return_value_if_fail(fscript != NULL, RET_BAD_PARAMS);
if (fscript->code_id == NULL) {
return RET_OK;
}
debugger = debugger_server_find_debugger(fscript->code_id);
if (debugger != NULL) {
@ -63,9 +57,6 @@ static ret_t debugger_fscript_on_disconnect(fscript_t* fscript) {
static ret_t debugger_fscript_on_fscript_init(fscript_t* fscript, const char* code) {
debugger_t* debugger = NULL;
return_value_if_fail(fscript != NULL, RET_BAD_PARAMS);
if (fscript->code_id == NULL) {
return RET_OK;
}
debugger = debugger_server_find_debugger(fscript->code_id);
if (debugger != NULL) {

View File

@ -38,7 +38,7 @@ typedef struct _debugger_server_t {
bool_t quited;
/*启动完成*/
bool_t started;
bool_t single_mode;
tk_istream_t* in;
tk_ostream_t* out;
tk_iostream_t* io;
@ -53,13 +53,14 @@ static void* debugger_server_run(void* ctx);
static ret_t debugger_server_send_object(debugger_server_t* server, debugger_resp_t* resp,
tk_object_t* obj);
static debugger_server_t* debugger_server_create(tk_iostream_t* io) {
static debugger_server_t* debugger_server_create(tk_iostream_t* io, bool_t single_mode) {
debugger_server_t* server = TKMEM_ZALLOC(debugger_server_t);
return_value_if_fail(server != NULL, NULL);
assert(io != NULL);
server->io = io;
server->single_mode = single_mode;
server->in = tk_iostream_get_istream(io);
server->out = tk_iostream_get_ostream(io);
darray_init(&(server->debuggers), 5, (tk_destroy_t)tk_object_unref, NULL);
@ -219,15 +220,18 @@ static ret_t debugger_server_get_debuggers(debugger_server_t* server, str_t* deb
static debugger_t* debugger_server_find(debugger_server_t* server, const char* code_id) {
uint32_t i = 0;
debugger_t* debugger = NULL;
return_value_if_fail(code_id != NULL, NULL);
return_value_if_fail(server != NULL, NULL);
if (tk_mutex_nest_lock(server->mutex) == RET_OK) {
for (i = 0; i < server->debuggers.size; i++) {
debugger_t* iter = (debugger_t*)darray_get(&(server->debuggers), i);
if (debugger_match(iter, code_id)) {
debugger = iter;
break;
if (server->single_mode) {
debugger = server->debugger;
} else {
for (i = 0; i < server->debuggers.size; i++) {
debugger_t* iter = (debugger_t*)darray_get(&(server->debuggers), i);
if (debugger_match(iter, code_id)) {
debugger = iter;
break;
}
}
}
tk_mutex_nest_unlock(server->mutex);
@ -542,13 +546,14 @@ static void* debugger_server_run(void* ctx) {
return NULL;
}
static bool_t s_single_mode = FALSE;
static debugger_server_t* s_debugger_server = NULL;
ret_t debugger_server_start(tk_iostream_t* io) {
debugger_server_t* server = NULL;
return_value_if_fail(io != NULL && s_debugger_server == NULL, RET_BAD_PARAMS);
server = debugger_server_create(io);
server = debugger_server_create(io, s_single_mode);
return_value_if_fail(server != NULL, RET_BAD_PARAMS);
s_debugger_server = server;
@ -567,7 +572,6 @@ ret_t debugger_server_stop(void) {
debugger_t* debugger_server_find_debugger(const char* code_id) {
debugger_server_t* server = s_debugger_server;
return_value_if_fail(code_id != NULL, NULL);
return debugger_server_find(server, code_id);
}
@ -575,3 +579,14 @@ debugger_t* debugger_server_find_debugger(const char* code_id) {
bool_t debugger_server_is_running(void) {
return s_debugger_server != NULL;
}
ret_t debugger_server_set_single_mode(bool_t single_mode) {
debugger_server_t* server = s_debugger_server;
s_single_mode = single_mode;
if (server != NULL) {
server->single_mode = single_mode;
}
return RET_OK;
}

View File

@ -50,6 +50,14 @@ ret_t debugger_server_start(tk_iostream_t* io);
*/
ret_t debugger_server_stop(void);
/**
* @method debugger_server_set_single_mode
* debugger模式
* @param {bool_t} single_mode debugger模式
* @return {ret_t} RET_OK表示成功
*/
ret_t debugger_server_set_single_mode(bool_t single_mode);
/**
* @method debugger_server_is_running
*

View File

@ -19,6 +19,7 @@
*
*/
#include "tkc/thread.h"
#include "tkc/socket_helper.h"
#include "streams/inet/iostream_tcp.h"
#include "debugger/debugger_server_tcp.h"
@ -58,10 +59,34 @@ ret_t debugger_server_tcp_start(void) {
return RET_OK;
}
static tk_thread_t* s_accept_thread = NULL;
static void* accept_thread(void* arg) {
debugger_server_tcp_start();
s_accept_thread = NULL;
return NULL;
}
ret_t debugger_server_tcp_start_async(void) {
return_value_if_fail(s_accept_thread == NULL, RET_BUSY);
s_accept_thread = tk_thread_create(accept_thread, NULL);
return_value_if_fail(s_accept_thread != NULL, RET_OOM);
tk_thread_start(s_accept_thread);
return RET_OK;
}
ret_t debugger_server_tcp_deinit(void) {
return_value_if_fail(s_server_sock >= 0, RET_BAD_PARAMS);
socket_close(s_server_sock);
s_server_sock = -1;
if (s_accept_thread != NULL) {
tk_thread_destroy(s_accept_thread);
s_accept_thread = NULL;
}
debugger_server_stop();
return RET_OK;

View File

@ -24,6 +24,7 @@
#include "tkc/iostream.h"
#include "debugger/debugger.h"
#include "debugger/debugger_global.h"
#include "debugger/debugger_server.h"
BEGIN_C_DECLS
@ -51,6 +52,14 @@ ret_t debugger_server_tcp_init(uint32_t port);
*/
ret_t debugger_server_tcp_start(void);
/**
* @method debugger_server_tcp_start_async
*
* >
* @return {ret_t} RET_OK表示成功
*/
ret_t debugger_server_tcp_start_async(void);
/**
* @method debugger_server_tcp_deinit
*

View File

@ -65,7 +65,6 @@ static ret_t da_serial_destroy(void* data) {
return RET_OK;
}
int serial_handle_get_fd(serial_handle_t handle) {
return handle->dev;
}
@ -114,19 +113,17 @@ ret_t serial_oflush(serial_handle_t handle) {
}
ret_t serial_wait_for_data(serial_handle_t handle, uint32_t timeout_ms) {
int len = 0;
int fd = serial_handle_get_fd(handle);
while (timeout_ms) {
aw_ioctl(fd, AW_FIONREAD, &len);
if (len > 0) {
return RET_OK;
}
sleep_ms(10);
timeout_ms -= tk_min(timeout_ms, 10);
int len = 0;
int fd = serial_handle_get_fd(handle);
while (timeout_ms) {
aw_ioctl(fd, AW_FIONREAD, &len);
if (len > 0) {
return RET_OK;
}
return RET_TIMEOUT;
sleep_ms(10);
timeout_ms -= tk_min(timeout_ms, 10);
}
return RET_TIMEOUT;
}
int32_t serial_read(serial_handle_t handle, uint8_t* buff, uint32_t max_size) {

View File

@ -430,10 +430,10 @@ ret_t aw_flow_shell_run(debugger_t* debugger) {
tk_object_t* obj = object_default_create();
return_value_if_fail(debugger != NULL, RET_BAD_PARAMS);
app.obj = obj;
app.break_at_line = 0xffff;
app.debugger = debugger;
app.completed = FALSE;
app.obj = obj;
app.break_at_line = 0xffff;
app.debugger = debugger;
app.completed = FALSE;
aw_read_line_init();
register_functions(obj);

View File

@ -40,22 +40,14 @@ static ret_t run_fscript(const char* code, uint32_t times, bool_t debug) {
fscript_t* fscript = NULL;
if (debug) {
str_t str;
debugger_global_init();
debugger_server_tcp_init(DEBUGGER_TCP_PORT);
debugger_server_tcp_start();
debugger_server_set_single_mode(TRUE);
sleep_ms(1000);
str_init(&str, 100);
str_set(&str, code);
str_append_more(&str, "//code_id(\"", DEBUGGER_DEFAULT_CODE_ID, "\")\n", NULL);
fscript = fscript_create(obj, str.str);
log_debug("%s\n", str.str);
str_reset(&str);
} else {
fscript = fscript_create(obj, code);
}
fscript = fscript_create(obj, code);
fscript_exec(fscript, &v);
fscript_destroy(fscript);
@ -85,7 +77,7 @@ static ret_t run_fscript_file(const char* filename, uint32_t times, bool_t debug
int main(int argc, char* argv[]) {
platform_prepare();
tk_socket_init();
tk_socket_init();
tk_mem_dump();
fscript_global_init();
fscript_ext_init();
@ -123,7 +115,7 @@ int main(int argc, char* argv[]) {
data_writer_factory_set(NULL);
data_reader_factory_set(NULL);
fscript_global_deinit();
tk_socket_deinit();
tk_socket_deinit();
return 0;
}