From 62d1c6b13057b7dbb5cf806563498a8a698d1422 Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Thu, 18 Apr 2024 14:48:03 -0700 Subject: [PATCH] scoped log gathering; communicate ctrl logs -> user via events --- src/base/base_log.c | 37 +++++++++++++++++++++++++++++++------ src/base/base_log.h | 22 +++++++++++++++++----- src/ctrl/ctrl_core.c | 10 ++++++++++ src/ctrl/ctrl_core.h | 3 +++ src/raddbg/raddbg.h | 26 +++++++++++++------------- 5 files changed, 74 insertions(+), 24 deletions(-) diff --git a/src/base/base_log.c b/src/base/base_log.c index 0d9bee81..af7b25ec 100644 --- a/src/base/base_log.c +++ b/src/base/base_log.c @@ -18,7 +18,6 @@ log_alloc(void) Arena *arena = arena_alloc(); Log *log = push_array(arena, Log, 1); log->arena = arena; - log->log_buffer_start_pos = arena_pos(arena); return log; } @@ -40,9 +39,10 @@ log_select(Log *log) internal void log_msg(String8 string) { - if(log_active != 0) + if(log_active != 0 && log_active->top_scope != 0) { - str8_list_push(log_active->arena, &log_active->log_buffer_strings, string); + String8 string_copy = push_str8_copy(log_active->arena, string); + str8_list_push(log_active->arena, &log_active->top_scope->strings, string_copy); } } @@ -61,12 +61,37 @@ log_msgf(char *fmt, ...) } } +//////////////////////////////// +//~ rjf: Log Scopes + internal void -log_clear(void) +log_scope_begin(void) { if(log_active != 0) { - arena_pop_to(log_active->arena, log_active->log_buffer_start_pos); - MemoryZeroStruct(&log_active->log_buffer_strings); + U64 pos = arena_pos(log_active->arena); + LogScope *scope = push_array(log_active->arena, LogScope, 1); + scope->pos = pos; + SLLStackPush(log_active->top_scope, scope); } } + +internal String8 +log_scope_end(Arena *arena) +{ + String8 result = {0}; + if(log_active != 0) + { + LogScope *scope = log_active->top_scope; + if(scope != 0) + { + SLLStackPop(log_active->top_scope); + if(arena != 0) + { + result = str8_list_join(arena, &scope->strings, 0); + } + arena_pop_to(log_active->arena, scope->pos); + } + } + return result; +} diff --git a/src/base/base_log.h b/src/base/base_log.h index da433a5c..ff4ac6e4 100644 --- a/src/base/base_log.h +++ b/src/base/base_log.h @@ -5,14 +5,21 @@ #define BASE_LOG_H //////////////////////////////// -//~ rjf: Log Type +//~ rjf: Log Types + +typedef struct LogScope LogScope; +struct LogScope +{ + LogScope *next; + U64 pos; + String8List strings; +}; typedef struct Log Log; struct Log { Arena *arena; - U64 log_buffer_start_pos; - String8List log_buffer_strings; + LogScope *top_scope; }; //////////////////////////////// @@ -23,10 +30,15 @@ internal void log_release(Log *log); internal void log_select(Log *log); //////////////////////////////// -//~ rjf: Log Building/Clearing +//~ rjf: Log Building internal void log_msg(String8 string); internal void log_msgf(char *fmt, ...); -internal void log_clear(void); + +//////////////////////////////// +//~ rjf: Log Scopes + +internal void log_scope_begin(void); +internal String8 log_scope_end(Arena *arena); #endif // BASE_LOG_H diff --git a/src/ctrl/ctrl_core.c b/src/ctrl/ctrl_core.c index 5bfec6f4..747ad430 100644 --- a/src/ctrl/ctrl_core.c +++ b/src/ctrl/ctrl_core.c @@ -1929,6 +1929,7 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg, if(next_event_node != 0) { DMN_Event *ev = &next_event_node->v; + log_scope_begin(); log_msgf("--- event ---\n"); log_msgf("kind: %S\n", dmn_event_kind_string_table[ev->kind]); log_msgf("exception_kind: %S\n", dmn_exception_kind_string_table[ev->exception_kind]); @@ -1939,6 +1940,15 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg, log_msgf("address: 0x%I64x\n", ev->address); log_msgf("string: \"%S\"\n", ev->string); log_msgf("ip_vaddr: 0x%I64x\n", ev->instruction_pointer); + String8 log = log_scope_end(scratch.arena); + if(log.size != 0) + { + CTRL_EventList evts = {0}; + CTRL_Event *evt = ctrl_event_list_push(scratch.arena, &evts); + evt->kind = CTRL_EventKind_Log; + evt->string = log; + ctrl_c2u_push_events(&evts); + } } // rjf: determine if we should filter diff --git a/src/ctrl/ctrl_core.h b/src/ctrl/ctrl_core.h index a321401f..96e55f09 100644 --- a/src/ctrl/ctrl_core.h +++ b/src/ctrl/ctrl_core.h @@ -302,6 +302,9 @@ typedef enum CTRL_EventKind CTRL_EventKind_MemDecommit, CTRL_EventKind_MemRelease, + //- rjf: log + CTRL_EventKind_Log, + CTRL_EventKind_COUNT } CTRL_EventKind; diff --git a/src/raddbg/raddbg.h b/src/raddbg/raddbg.h index 72b217cd..513f9990 100644 --- a/src/raddbg/raddbg.h +++ b/src/raddbg/raddbg.h @@ -1,14 +1,6 @@ // Copyright (c) 2024 Epic Games Tools // Licensed under the MIT license (https://opensource.org/license/mit/) -//////////////////////////////// -//~ rjf: Demon/Cleanup Pass Tasks -// -// [ ] TLS eval -> in-process-memory EXE info -// [ ] unwinding -> in-process-memory EXE info -// [ ] "root" concept in hash store, which buckets keys & allows usage code to -// jettison a collection of keys in retained mode fashion - //////////////////////////////// //~ rjf: Frontend/UI Pass Tasks // @@ -57,6 +49,9 @@ //////////////////////////////// //~ rjf: Hot, High Priority Tasks (Complete Unusability, Crashes, Fire-Worthy) // +// [ ] robustify dbgi layer to renames (cache should not be based only on +// path - must invalidate naturally when new filetime occurs) +// // [ ] raddbg jai.exe my_file.jai -- foobar -> raddbg consumes `--` incorrectly // [ ] PDB files distributed with the build are not found by DbgHelp!!! // [ ] Jai compiler debugging crash @@ -82,6 +77,14 @@ // // [ ] ** Converter performance & heuristics for asynchronously doing it early +//////////////////////////////// +//~ rjf: Demon/Cleanup Pass Tasks +// +// [ ] TLS eval -> in-process-memory EXE info +// [ ] unwinding -> in-process-memory EXE info +// [ ] "root" concept in hash store, which buckets keys & allows usage code to +// jettison a collection of keys in retained mode fashion + //////////////////////////////// //~ rjf: Hot, Medium Priority Tasks (Low-Hanging-Fruit Features, UI Jank, Cleanup) // @@ -198,7 +201,6 @@ // the files myself in the shell, but it seemed weird that there was no // "save" option in the menus. // -// [ ] @cleanup @feature double & triple click select in source views // [ ] @feature debug info overrides (both path-based AND module-based) // [ ] configure tab size // [ ] auto-scroll output window @@ -315,8 +317,6 @@ // [ ] @bug view-snapping in scroll-lists, accounting for mapping between // visual positions & logical positions (variably sized rows in watch, // table headers, etc.) -// [ ] @bug selected frame should be keyed by run_idx or something so that it -// can gracefully reset to the top frame when running // [ ] @cleanup collapse DF_CfgNodes into just being MD trees, find another way // to encode config source - don't need it at every node // [ ] @cleanup straighten out index/number space & types & terminology for @@ -335,8 +335,6 @@ // when editing) // [ ] @feature eval system -> somehow evaluate breakpoint hit counts? "meta" // variables? -// [ ] @feature watch window labels -// [ ] @feature scheduler -> thread grid view? // // [ ] @feature disasm view improvement features // [ ] interleaved src/dasm view @@ -411,6 +409,8 @@ // bit more user-friendly? // // [x] The cursor feels a bit too huge vertically. +// [x] @feature watch window labels +// [x] @cleanup @feature double & triple click select in source views #ifndef RADDBG_H #define RADDBG_H