diff --git a/docs/changes.md b/docs/changes.md index 37b3773fd..b3b665199 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -3,6 +3,7 @@ 2023/11/24 * 完善remote ui service * 支持 combox 不需要手动写偏移文字也可以居中(感谢智明提供补丁) + * 修改 debugger 的 dispatch_messages 函数和调试下一步等按钮会修改 debugger 状态(感谢智明提供补丁) 2023/11/23 * object\_default支持设置属性时保持属性类型不变。 diff --git a/src/debugger/debugger.c b/src/debugger/debugger.c index bd1b4efe3..341dd20d1 100644 --- a/src/debugger/debugger.c +++ b/src/debugger/debugger.c @@ -104,38 +104,63 @@ bool_t debugger_match(debugger_t* debugger, const char* code_id) { } ret_t debugger_step_in(debugger_t* debugger) { + ret_t ret = RET_OK; return_value_if_fail(debugger != NULL && debugger->vt != NULL, RET_BAD_PARAMS); return_value_if_fail(debugger->vt->step_in != NULL, RET_BAD_PARAMS); - return debugger->vt->step_in(debugger); + ret = debugger->vt->step_in(debugger); + if (ret == RET_OK) { + debugger_set_state(debugger, DEBUGGER_PROGRAM_STATE_RUNNING); + } + return ret; } ret_t debugger_step_out(debugger_t* debugger) { + ret_t ret = RET_OK; return_value_if_fail(debugger != NULL && debugger->vt != NULL, RET_BAD_PARAMS); return_value_if_fail(debugger->vt->step_out != NULL, RET_BAD_PARAMS); - return debugger->vt->step_out(debugger); + ret = debugger->vt->step_out(debugger); + if (ret == RET_OK) { + debugger_set_state(debugger, DEBUGGER_PROGRAM_STATE_RUNNING); + } + return ret; } ret_t debugger_step_over(debugger_t* debugger) { + ret_t ret = RET_OK; return_value_if_fail(debugger != NULL && debugger->vt != NULL, RET_BAD_PARAMS); return_value_if_fail(debugger->vt->step_over != NULL, RET_BAD_PARAMS); - return debugger->vt->step_over(debugger); + ret = debugger->vt->step_over(debugger); + if (ret == RET_OK) { + debugger_set_state(debugger, DEBUGGER_PROGRAM_STATE_RUNNING); + } + return ret; } ret_t debugger_step_loop_over(debugger_t* debugger) { + ret_t ret = RET_OK; return_value_if_fail(debugger != NULL && debugger->vt != NULL, RET_BAD_PARAMS); return_value_if_fail(debugger->vt->step_loop_over != NULL, RET_BAD_PARAMS); - return debugger->vt->step_loop_over(debugger); + ret = debugger->vt->step_loop_over(debugger); + if (ret == RET_OK) { + debugger_set_state(debugger, DEBUGGER_PROGRAM_STATE_RUNNING); + } + return ret; } ret_t debugger_continue(debugger_t* debugger) { + ret_t ret = RET_OK; return_value_if_fail(debugger != NULL && debugger->vt != NULL, RET_BAD_PARAMS); return_value_if_fail(debugger->vt->continve != NULL, RET_BAD_PARAMS); - return debugger->vt->continve(debugger); + ret = debugger->vt->continve(debugger); + if (ret == RET_OK) { + debugger_set_state(debugger, DEBUGGER_PROGRAM_STATE_RUNNING); + } + return ret; } tk_object_t* debugger_get_local(debugger_t* debugger, uint32_t frame_index) { @@ -344,9 +369,9 @@ ret_t debugger_set_current_thread_id(debugger_t* debugger, uint64_t thread_id) { } } -ret_t debugger_dispatch_messages(debugger_t* debugger) { +ret_t debugger_dispatch_messages(debugger_t* debugger, uint32_t timeout, uint32_t* ret_num) { return_value_if_fail(debugger != NULL && debugger->vt != NULL, RET_BAD_PARAMS); - return_value_if_fail(debugger->vt->dispatch_messages != NULL, RET_BAD_PARAMS); + return_value_if_fail(debugger->vt->dispatch_messages != NULL && ret_num != NULL, RET_BAD_PARAMS); - return debugger->vt->dispatch_messages(debugger); + return debugger->vt->dispatch_messages(debugger, timeout, ret_num); } diff --git a/src/debugger/debugger.h b/src/debugger/debugger.h index bb83e1a45..303fd3364 100644 --- a/src/debugger/debugger.h +++ b/src/debugger/debugger.h @@ -103,7 +103,7 @@ typedef tk_object_t* (*debugger_get_var_t)(debugger_t* debugger, const char* pat typedef ret_t (*debugger_set_break_point_ex_t)(debugger_t* debugger, const char* position); typedef ret_t (*debugger_remove_break_point_ex_t)(debugger_t* debugger, const char* position); typedef ret_t (*debugger_set_current_frame_t)(debugger_t* debugger, uint32_t frame_index); -typedef ret_t (*debugger_dispatch_messages_t)(debugger_t* debugger); +typedef ret_t (*debugger_dispatch_messages_t)(debugger_t* debugger, uint32_t timeout, uint32_t* ret_num); /*}扩展接口以支持lldb的DAP协议{*/ typedef debugger_t* (*debugger_fscript_create_t)(void); @@ -558,10 +558,12 @@ ret_t debugger_set_current_thread_id(debugger_t* debugger, uint64_t thread_id); * @method debugger_dispatch_messages * dispatch_messages(仅适用于客户端) * @param {debugger_t*} debugger debugger对象。 + * @param {uint32_t} timeout 超时时间。 + * @param {uint32_t*} ret_num 返回处理命令个数。 * * @return {ret_t} 返回RET_OK表示成功,否则表示失败。 */ -ret_t debugger_dispatch_messages(debugger_t* debugger); +ret_t debugger_dispatch_messages(debugger_t* debugger, uint32_t timeout, uint32_t* ret_num); /** * @method debugger_set_state diff --git a/src/debugger/debugger_client.c b/src/debugger/debugger_client.c index 6cffa6187..1824a3d64 100644 --- a/src/debugger/debugger_client.c +++ b/src/debugger/debugger_client.c @@ -131,7 +131,8 @@ static ret_t debugger_client_dispatch_one(debugger_t* debugger, debugger_resp_t* return debugger_client_dispatch_message(debugger, resp); } -static ret_t debugger_client_dispatch_messages(debugger_t* debugger) { +static ret_t debugger_client_dispatch_messages(debugger_t* debugger, uint32_t timeout, uint32_t* ret_num) { + ret_t ret = RET_OK; debugger_resp_t resp; tk_istream_t* in = NULL; debugger_client_t* client = DEBUGGER_CLIENT(debugger); @@ -140,7 +141,8 @@ static ret_t debugger_client_dispatch_messages(debugger_t* debugger) { memset(&resp, 0x00, sizeof(resp)); in = tk_iostream_get_istream(client->io); - while (tk_istream_wait_for_data(in, 10) == RET_OK) { + while ((ret = tk_istream_wait_for_data(in, timeout)) == RET_OK) { + *ret_num += 1; if (debugger_client_dispatch_one(debugger, &resp) != RET_OK) { break; } @@ -150,7 +152,8 @@ static ret_t debugger_client_dispatch_messages(debugger_t* debugger) { } ret_t debugger_client_dispatch(debugger_t* debugger) { - return debugger_client_dispatch_messages(debugger); + uint32_t num = 0; + return debugger_client_dispatch_messages(debugger, 10, &num); } ret_t debugger_client_wait_for_completed(debugger_t* debugger) { diff --git a/src/debugger/debugger_lldb.c b/src/debugger/debugger_lldb.c index 188abc1d1..625cf8ab7 100644 --- a/src/debugger/debugger_lldb.c +++ b/src/debugger/debugger_lldb.c @@ -924,14 +924,16 @@ static ret_t debugger_lldb_simple_command(debugger_t* debugger, const char* cmd) return ret; } -ret_t debugger_lldb_dispatch_messages(debugger_t* debugger) { - while (debugger_lldb_dispatch_one(debugger, 10) == RET_OK) { +ret_t debugger_lldb_dispatch_messages(debugger_t* debugger, uint32_t timeout, uint32_t* ret_num) { + ret_t ret = RET_OK; + while ((ret = debugger_lldb_dispatch_one(debugger, timeout)) == RET_OK) { + *ret_num += 1; if (debugger_get_state(debugger) == DEBUGGER_PROGRAM_STATE_RUNNING) { break; } } - return RET_OK; + return ret; } ret_t debugger_lldb_wait_for_completed(debugger_t* debugger) { @@ -1105,13 +1107,14 @@ static tk_object_t* debugger_lldb_get_global(debugger_t* debugger) { static tk_object_t* debugger_lldb_get_callstack(debugger_t* debugger) { int32_t i = 0; int32_t n = 0; + uint32_t num = 0; char path[MAX_PATH + 1] = {0}; tk_object_t* ret_obj = NULL; tk_object_t* callstack = NULL; debugger_lldb_t* lldb = DEBUGGER_LLDB(debugger); return_value_if_fail(lldb != NULL, NULL); - debugger_lldb_dispatch_messages(debugger); + debugger_lldb_dispatch_messages(debugger, 10, &num); callstack = debugger_lldb_get_callstack_obj(debugger); return_value_if_fail(callstack != NULL, NULL); @@ -1244,10 +1247,11 @@ static ret_t debugger_lldb_launch(debugger_t* debugger, const char* lang, } static ret_t debugger_lldb_get_code(debugger_t* debugger, binary_data_t* code) { + uint32_t num = 0; debugger_lldb_t* lldb = DEBUGGER_LLDB(debugger); return_value_if_fail(lldb != NULL && code != NULL, RET_BAD_PARAMS); - debugger_lldb_dispatch_messages(debugger); + debugger_lldb_dispatch_messages(debugger, 10, &num); if (code != NULL && lldb->current_frame_source != NULL) { code->data = (void*)(lldb->current_frame_source); diff --git a/tests/debugger_test.cc b/tests/debugger_test.cc index f588a6120..f521fbc8c 100644 --- a/tests/debugger_test.cc +++ b/tests/debugger_test.cc @@ -667,7 +667,8 @@ TEST(Debugger, event1) { debugger_t* debugger = debugger_server_find_debugger(fscript->code_id); ASSERT_EQ(debugger_is_paused(debugger), TRUE); - debugger_dispatch_messages(client); + uint32_t num; + debugger_dispatch_messages(client, 1, &num); ASSERT_EQ(debugger_is_paused(client), TRUE); ASSERT_EQ(debugger_continue(client), RET_OK); diff --git a/tools/fdb/fdb.cpp b/tools/fdb/fdb.cpp index b638c0477..95b9e324c 100644 --- a/tools/fdb/fdb.cpp +++ b/tools/fdb/fdb.cpp @@ -551,43 +551,43 @@ static ret_t func_remove_break(app_info_t* app, tokenizer_t* tokenizer) { } static ret_t func_step_in(app_info_t* app, tokenizer_t* tokenizer) { + uint32_t num = 0; debugger_step_in(app->debugger); - sleep_ms(300); - debugger_dispatch_messages(app->debugger); + debugger_dispatch_messages(app->debugger, 300, &num); return fdb_show_code(app, FALSE); } static ret_t func_next(app_info_t* app, tokenizer_t* tokenizer) { + uint32_t num = 0; debugger_step_over(app->debugger); - sleep_ms(300); - debugger_dispatch_messages(app->debugger); + debugger_dispatch_messages(app->debugger, 300, &num); return fdb_show_code(app, FALSE); } static ret_t func_continue(app_info_t* app, tokenizer_t* tokenizer) { + uint32_t num = 0; debugger_continue(app->debugger); - sleep_ms(300); - debugger_dispatch_messages(app->debugger); + debugger_dispatch_messages(app->debugger, 300, &num); return fdb_show_code(app, FALSE); } static ret_t func_flush(app_info_t* app, tokenizer_t* tokenizer) { - debugger_dispatch_messages(app->debugger); - sleep_ms(300); + uint32_t num = 0; + debugger_dispatch_messages(app->debugger, 300, &num); return RET_OK; } static ret_t func_step_out(app_info_t* app, tokenizer_t* tokenizer) { + uint32_t num = 0; debugger_step_out(app->debugger); - sleep_ms(300); - debugger_dispatch_messages(app->debugger); + debugger_dispatch_messages(app->debugger, 300, &num); return fdb_show_code(app, FALSE); } static ret_t func_step_loop_over(app_info_t* app, tokenizer_t* tokenizer) { + uint32_t num = 0; debugger_step_loop_over(app->debugger); - sleep_ms(300); - debugger_dispatch_messages(app->debugger); + debugger_dispatch_messages(app->debugger, 300, &num); return fdb_show_code(app, FALSE); } @@ -750,20 +750,21 @@ ret_t fdb_shell_run(void) { register_functions(obj); while (TRUE) { + uint32_t num = 0; char* line = aw_read_line(KMAG "[fdb] # " KNRM); if (line == NULL) { break; } if (app.debugger != NULL) { - debugger_dispatch_messages(app.debugger); + debugger_dispatch_messages(app.debugger, 16, &num); } if (fdb_shell_exec(&app, line) == RET_STOP) { aw_read_line_free(line); break; } if (app.debugger != NULL) { - debugger_dispatch_messages(app.debugger); + debugger_dispatch_messages(app.debugger, 16, &num); } aw_read_line_add_history(line);