From e8ecad598a28c58e7bb9300f3d5e19c4d4e656ac Mon Sep 17 00:00:00 2001 From: kichikuou Date: Sun, 10 Nov 2024 08:40:50 +0900 Subject: [PATCH] debugger_dap: Support SteppingGranularity Debuggers that operate at the instruction level can execute instruction- level step even when xsystem4 has loaded debug information, by adding `granularity: "instruction"` to the step request. --- src/debugger_dap.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/debugger_dap.c b/src/debugger_dap.c index 57393e3..d7f242a 100644 --- a/src/debugger_dap.c +++ b/src/debugger_dap.c @@ -162,6 +162,7 @@ static void cmd_initialize(cJSON *args, cJSON *resp) //cJSON_AddBoolToObject(body, "supportsSetExpression", true); //cJSON_AddBoolToObject(body, "supportsTerminateRequest", true); cJSON_AddBoolToObject(body, "supportsInstructionBreakpoints", true); + cJSON_AddBoolToObject(body, "supportsSteppingGranularity", true); send_response(resp, true); emit_initialized_event(); @@ -665,10 +666,28 @@ static void cmd_pause(cJSON *args, cJSON *resp) } } +enum stepping_granularity { + STEPPING_GRANULARITY_STATEMENT, + STEPPING_GRANULARITY_LINE, + STEPPING_GRANULARITY_INSTRUCTION, +}; + +static enum stepping_granularity get_granularity(cJSON *args) +{ + cJSON *g = cJSON_GetObjectItemCaseSensitive(args, "granularity"); + if (cJSON_IsString(g)) { + if (!strcmp(g->valuestring, "line")) + return STEPPING_GRANULARITY_LINE; + if (!strcmp(g->valuestring, "instruction")) + return STEPPING_GRANULARITY_INSTRUCTION; + } + return STEPPING_GRANULARITY_STATEMENT; +} + static void cmd_stepIn(cJSON *args, cJSON *resp) { stepping_file = stepping_line = 0; - if (dbg_info) + if (dbg_info && get_granularity(args) != STEPPING_GRANULARITY_INSTRUCTION) dbg_info_addr2line(dbg_info, instr_ptr, &stepping_file, &stepping_line); dbg_set_step_into_breakpoint(); @@ -692,7 +711,7 @@ static void cmd_stepOut(cJSON *args, cJSON *resp) static void cmd_next(cJSON *args, cJSON *resp) { stepping_file = stepping_line = 0; - if (dbg_info) + if (dbg_info && get_granularity(args) != STEPPING_GRANULARITY_INSTRUCTION) dbg_info_addr2line(dbg_info, instr_ptr, &stepping_file, &stepping_line); dbg_set_step_over_breakpoint();