From 5576f14a0f0006af09c65f27f04f12a3298fc74b Mon Sep 17 00:00:00 2001 From: kichikuou Date: Sun, 17 Nov 2024 09:42:25 +0900 Subject: [PATCH] debugger_dap: minor fixes * Add `allThreadsStopped` to Stopped event to indicate that stacktrace can be accessed * StackTraceResponse should return most recent call first * Fix instruction pointers of calling frames The first two will improve compatibility with DAP clients other than xsys4dbg. --- src/debugger_dap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/debugger_dap.c b/src/debugger_dap.c index 9957f96..200c3a4 100644 --- a/src/debugger_dap.c +++ b/src/debugger_dap.c @@ -127,6 +127,7 @@ static void emit_stopped_event(struct dbg_stop *stop) } if (stop->message) cJSON_AddStringToObject(body, "text", stop->message); + cJSON_AddBoolToObject(body, "allThreadsStopped", true); emit_event("stopped", body); } @@ -182,7 +183,7 @@ static void cmd_stackTrace(cJSON *args, cJSON *resp) cJSON_AddItemToObjectCS(resp, "body", body = cJSON_CreateObject()); cJSON_AddNumberToObject(body, "totalFrames", call_stack_ptr); cJSON_AddItemToObjectCS(body, "stackFrames", stack_frames = cJSON_CreateArray()); - for (int i = 0; i < call_stack_ptr; i++) { + for (int i = call_stack_ptr - 1; i >= 0; i--) { cJSON_AddItemToArray(stack_frames, frame = cJSON_CreateObject()); cJSON_AddNumberToObject(frame, "id", i); // this *shouldn't* happen, but since we're in the debugger... @@ -196,7 +197,7 @@ static void cmd_stackTrace(cJSON *args, cJSON *resp) if (i == call_stack_ptr - 1) { snprintf(ip, 9, "%x", (unsigned)instr_ptr); } else { - snprintf(ip, 9, "%x", call_stack[i].call_address); + snprintf(ip, 9, "%x", call_stack[i+1].call_address); } cJSON_AddStringToObject(frame, "instructionPointerReference", ip); cJSON_AddNumberToObject(frame, "line", 0);