From e829ae90324f8b3bd2aa6df985b24eaea38f64a9 Mon Sep 17 00:00:00 2001 From: lixianjing Date: Tue, 13 Aug 2024 09:42:17 +0800 Subject: [PATCH] improve debugger --- docs/changes.md | 2 ++ src/debugger/debugger.c | 7 +++++++ src/debugger/debugger.h | 13 +++++++++++++ src/debugger/debugger_lldb.c | 20 ++++++++++++++++---- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/docs/changes.md b/docs/changes.md index 84e81d552..ac10de191 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -1,4 +1,6 @@ # 最新动态 +2024/08/13 + * debugger增加一个获取指定层数堆栈的api(感谢智明提供补丁) 2024/08/12 * 增加文档[1.8 Release notes](docs/release_notes/awtk-1.8.md) diff --git a/src/debugger/debugger.c b/src/debugger/debugger.c index e44532c44..05cc8a493 100644 --- a/src/debugger/debugger.c +++ b/src/debugger/debugger.c @@ -198,6 +198,13 @@ tk_object_t* debugger_get_callstack(debugger_t* debugger) { return debugger->vt->get_callstack(debugger); } +tk_object_t* debugger_get_callstack_ex(debugger_t* debugger, uint32_t start, uint32_t levels) { + return_value_if_fail(debugger != NULL && debugger->vt != NULL, NULL); + return_value_if_fail(debugger->vt->get_callstack_ex != NULL, NULL); + + return debugger->vt->get_callstack_ex(debugger, start, levels); +} + ret_t debugger_clear_break_points(debugger_t* debugger) { return_value_if_fail(debugger != NULL && debugger->vt != NULL, RET_BAD_PARAMS); return_value_if_fail(debugger->vt->clear_break_points != NULL, RET_BAD_PARAMS); diff --git a/src/debugger/debugger.h b/src/debugger/debugger.h index 1aad78a3c..4a76cd5b4 100644 --- a/src/debugger/debugger.h +++ b/src/debugger/debugger.h @@ -77,6 +77,7 @@ typedef tk_object_t* (*debugger_get_local_t)(debugger_t* debugger, uint32_t fram typedef tk_object_t* (*debugger_get_self_t)(debugger_t* debugger); typedef tk_object_t* (*debugger_get_global_t)(debugger_t* debugger); typedef tk_object_t* (*debugger_get_callstack_t)(debugger_t* debugger); +typedef tk_object_t* (*debugger_get_callstack_ex_t)(debugger_t* debugger, uint32_t start, uint32_t levels); typedef ret_t (*debugger_clear_break_points_t)(debugger_t* debugger); typedef ret_t (*debugger_set_break_point_t)(debugger_t* debugger, uint32_t line); typedef ret_t (*debugger_remove_break_point_t)(debugger_t* debugger, uint32_t line); @@ -131,6 +132,7 @@ typedef struct _debugger_vtable_t { debugger_get_self_t get_self; debugger_get_global_t get_global; debugger_get_callstack_t get_callstack; + debugger_get_callstack_ex_t get_callstack_ex; debugger_get_code_t get_code; debugger_get_debuggers_t get_debuggers; debugger_get_break_points_t get_break_points; @@ -363,6 +365,17 @@ tk_object_t* debugger_get_global(debugger_t* debugger); */ tk_object_t* debugger_get_callstack(debugger_t* debugger); +/** + * @method debugger_get_callstack_ex + * 获取当前线程的callstack。 + * @param {debugger_t*} debugger debugger对象。 + * @param {uint32_t} start 堆栈 startFrame。 + * @param {uint32_t} levels 堆栈层数。 + * + * @return {tk_object_t*} 返回堆栈信息。 + */ +tk_object_t* debugger_get_callstack_ex(debugger_t* debugger, uint32_t start, uint32_t levels); + /** * @method debugger_clear_break_points * 清除全部断点。 diff --git a/src/debugger/debugger_lldb.c b/src/debugger/debugger_lldb.c index cb9caaefa..12040e668 100644 --- a/src/debugger/debugger_lldb.c +++ b/src/debugger/debugger_lldb.c @@ -93,6 +93,9 @@ #define LLDB_KEY_ST_FIRST_CODE_BREAKPOINTS "stFirstCodeBreakPoints" #define LLDB_KEY_STOPFORDESTROYORDETACH "StopForDestroyOrDetach" +#define LLDB_CALLSTCK_DEFAULT_STARTFRAME 0 +#define LLDB_CALLSTCK_DEFAULT_LEVELS 100 + #define VARREF_LOCALS (int64_t)1 #define VARREF_GLOBALS (int64_t)2 #define VARREF_REGS (int64_t)3 @@ -258,16 +261,20 @@ static ret_t debugger_lldb_set_current_thread_id(debugger_t* debugger, uint64_t return debugger_lldb_set_current_thread_id_ex(debugger, thread_id, FALSE); } -static tk_object_t* debugger_lldb_get_callstack_obj(debugger_t* debugger) { +static tk_object_t* debugger_lldb_get_callstack_ex_obj(debugger_t* debugger, uint32_t start, uint32_t levels) { debugger_lldb_t* lldb = DEBUGGER_LLDB(debugger); if (lldb->callstack == NULL) { - lldb->callstack = debugger_lldb_get_callstack_impl(debugger, 0, 100); + lldb->callstack = debugger_lldb_get_callstack_impl(debugger, start, levels); } return lldb->callstack; } +static tk_object_t* debugger_lldb_get_callstack_obj(debugger_t* debugger) { + return debugger_lldb_get_callstack_ex_obj(debugger, LLDB_CALLSTCK_DEFAULT_STARTFRAME, LLDB_CALLSTCK_DEFAULT_LEVELS); +} + static const char* debugger_lldb_get_source_path(debugger_t* debugger, uint32_t frame_index) { char path[MAX_PATH + 1] = {0}; tk_object_t* callstack = debugger_lldb_get_callstack_obj(debugger); @@ -1327,7 +1334,7 @@ static tk_object_t* debugger_lldb_get_global(debugger_t* debugger) { return debugger_lldb_get_variables_impl(debugger, VARREF_GLOBALS, 0, 0); } -static tk_object_t* debugger_lldb_get_callstack(debugger_t* debugger) { +static tk_object_t* debugger_lldb_get_callstack_ex(debugger_t* debugger, uint32_t start, uint32_t levels) { int32_t i = 0; int32_t n = 0; uint32_t num = 0; @@ -1338,7 +1345,7 @@ static tk_object_t* debugger_lldb_get_callstack(debugger_t* debugger) { return_value_if_fail(lldb != NULL, NULL); debugger_lldb_dispatch_messages(debugger, 10, &num); - callstack = debugger_lldb_get_callstack_obj(debugger); + callstack = debugger_lldb_get_callstack_ex_obj(debugger, start, levels); return_value_if_fail(callstack != NULL, NULL); ret_obj = conf_ubjson_create(); @@ -1371,6 +1378,10 @@ static tk_object_t* debugger_lldb_get_callstack(debugger_t* debugger) { return ret_obj; } +static tk_object_t* debugger_lldb_get_callstack(debugger_t* debugger) { + return debugger_lldb_get_callstack_ex(debugger, LLDB_CALLSTCK_DEFAULT_STARTFRAME, LLDB_CALLSTCK_DEFAULT_LEVELS); +} + static ret_t debugger_lldb_update_break_points(debugger_t* debugger) { if (debugger_is_paused_or_running(debugger)) { debugger_lldb_update_func_break_points(debugger); @@ -1557,6 +1568,7 @@ static const debugger_vtable_t s_debugger_lldb_vtable = { .get_debuggers = debugger_lldb_get_debuggers, .get_break_points = debugger_lldb_get_break_points, .get_callstack = debugger_lldb_get_callstack, + .get_callstack_ex = debugger_lldb_get_callstack_ex, .dispatch_messages = debugger_lldb_dispatch_messages, .update_code = debugger_lldb_update_code, .set_break_point_ex = debugger_lldb_set_break_point_ex,