mirror of
https://github.com/kichikuou/xsystem35-sdl2.git
synced 2026-09-22 22:48:08 +03:00
debugger_dap: Emit Output event on sys_message
This commit is contained in:
@@ -325,3 +325,12 @@ void dbg_onsleep(void) {
|
||||
if (dbg_impl)
|
||||
dbg_impl->onsleep();
|
||||
}
|
||||
|
||||
boolean dbg_console_vprintf(const char *format, va_list ap) {
|
||||
if (!dbg_impl || !dbg_impl->console_output)
|
||||
return false;
|
||||
char buf[1024];
|
||||
vsnprintf(buf, sizeof(buf), format, ap);
|
||||
dbg_impl->console_output(buf);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#ifndef __DEBUGGER_H__
|
||||
#define __DEBUGGER_H__
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "portab.h"
|
||||
|
||||
typedef enum {
|
||||
@@ -44,6 +45,7 @@ void dbg_quit();
|
||||
void dbg_main(void);
|
||||
void dbg_onsleep(void);
|
||||
BYTE dbg_handle_breakpoint(int page, int addr);
|
||||
boolean dbg_console_vprintf(const char *format, va_list ap);
|
||||
|
||||
#else // ENABLE_DEBUGGER
|
||||
|
||||
@@ -53,6 +55,7 @@ BYTE dbg_handle_breakpoint(int page, int addr);
|
||||
#define dbg_main()
|
||||
#define dbg_onsleep()
|
||||
#define dbg_handle_breakpoint(page, addr) BREAKPOINT
|
||||
#define dbg_console_vprintf(format, ap) false
|
||||
|
||||
#endif // ENABLE_DEBUGGER
|
||||
|
||||
|
||||
+13
-3
@@ -68,21 +68,21 @@ static void send_json(cJSON *json) {
|
||||
cJSON_free(json);
|
||||
}
|
||||
|
||||
static void emit_initialized_event() {
|
||||
static void emit_initialized_event(void) {
|
||||
cJSON *event = cJSON_CreateObject();
|
||||
cJSON_AddStringToObject(event, "type", "event");
|
||||
cJSON_AddStringToObject(event, "event", "initialized");
|
||||
send_json(event);
|
||||
}
|
||||
|
||||
static void emit_terminated_event() {
|
||||
static void emit_terminated_event(void) {
|
||||
cJSON *event = cJSON_CreateObject();
|
||||
cJSON_AddStringToObject(event, "type", "event");
|
||||
cJSON_AddStringToObject(event, "event", "terminated");
|
||||
send_json(event);
|
||||
}
|
||||
|
||||
static void emit_stop_event() {
|
||||
static void emit_stop_event(void) {
|
||||
const char *reason;
|
||||
switch (dbg_state) {
|
||||
case DBG_STOPPED_ENTRY: reason = "entry"; break;
|
||||
@@ -102,6 +102,15 @@ static void emit_stop_event() {
|
||||
send_json(event);
|
||||
}
|
||||
|
||||
static void emit_output_event(const char *output) {
|
||||
cJSON *event = cJSON_CreateObject(), *body;
|
||||
cJSON_AddStringToObject(event, "type", "event");
|
||||
cJSON_AddStringToObject(event, "event", "output");
|
||||
cJSON_AddItemToObjectCS(event, "body", body = cJSON_CreateObject());
|
||||
cJSON_AddStringToObject(body, "output", output);
|
||||
send_json(event);
|
||||
}
|
||||
|
||||
static void cmd_initialize(cJSON *args, cJSON *resp) {
|
||||
cJSON *body;
|
||||
cJSON_AddBoolToObject(resp, "success", true);
|
||||
@@ -598,4 +607,5 @@ DebuggerImpl dbg_dap_impl = {
|
||||
.quit = dbg_dap_quit,
|
||||
.repl = dbg_dap_repl,
|
||||
.onsleep = dbg_dap_onsleep,
|
||||
.console_output = emit_output_event,
|
||||
};
|
||||
|
||||
@@ -52,6 +52,7 @@ typedef struct {
|
||||
void (*quit)(void);
|
||||
void (*repl)(void);
|
||||
void (*onsleep)(void);
|
||||
void (*console_output)(const char *output);
|
||||
} DebuggerImpl;
|
||||
|
||||
extern DebuggerImpl dbg_cui_impl;
|
||||
|
||||
+2
-1
@@ -176,7 +176,8 @@ void sys_message(int lv, char *format, ...) {
|
||||
int prio = prio_table[min(lv, 5)];
|
||||
__android_log_vprint(prio, "xsystem35", format, args);
|
||||
#else
|
||||
vfprintf(stderr, format, args);
|
||||
if (!dbg_console_vprintf(format, args))
|
||||
vfprintf(stderr, format, args);
|
||||
#endif
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user