mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-06-17 09:32:22 -07:00
sketch out logging stub, to begin marking up debugger layers with logging - high level stuff still wip
This commit is contained in:
@@ -15,4 +15,5 @@
|
||||
#include "base_thread_context.c"
|
||||
#include "base_command_line.c"
|
||||
#include "base_markup.c"
|
||||
#include "base_log.c"
|
||||
#include "base_entry_point.c"
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "base_thread_context.h"
|
||||
#include "base_command_line.h"
|
||||
#include "base_markup.h"
|
||||
#include "base_log.h"
|
||||
#include "base_entry_point.h"
|
||||
|
||||
#endif // BASE_INC_H
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Globals/Thread-Locals
|
||||
|
||||
C_LINKAGE thread_static Log *log_active;
|
||||
#if !BUILD_SUPPLEMENTARY_UNIT
|
||||
C_LINKAGE thread_static Log *log_active = 0;
|
||||
#endif
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Log Creation/Selection
|
||||
|
||||
internal Log *
|
||||
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;
|
||||
}
|
||||
|
||||
internal void
|
||||
log_release(Log *log)
|
||||
{
|
||||
arena_release(log->arena);
|
||||
}
|
||||
|
||||
internal void
|
||||
log_select(Log *log)
|
||||
{
|
||||
log_active = log;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Log Building/Clearing
|
||||
|
||||
internal void
|
||||
log_msg(String8 string)
|
||||
{
|
||||
if(log_active != 0)
|
||||
{
|
||||
str8_list_push(log_active->arena, &log_active->log_buffer_strings, string);
|
||||
}
|
||||
}
|
||||
|
||||
internal void
|
||||
log_msgf(char *fmt, ...)
|
||||
{
|
||||
if(log_active != 0)
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
String8 string = push_str8fv(scratch.arena, fmt, args);
|
||||
log_msg(string);
|
||||
va_end(args);
|
||||
scratch_end(scratch);
|
||||
}
|
||||
}
|
||||
|
||||
internal void
|
||||
log_clear(void)
|
||||
{
|
||||
if(log_active != 0)
|
||||
{
|
||||
arena_pop_to(log_active->arena, log_active->log_buffer_start_pos);
|
||||
MemoryZeroStruct(&log_active->log_buffer_strings);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#ifndef BASE_LOG_H
|
||||
#define BASE_LOG_H
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Log Type
|
||||
|
||||
typedef struct Log Log;
|
||||
struct Log
|
||||
{
|
||||
Arena *arena;
|
||||
U64 log_buffer_start_pos;
|
||||
String8List log_buffer_strings;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Log Creation/Selection
|
||||
|
||||
internal Log *log_alloc(void);
|
||||
internal void log_release(Log *log);
|
||||
internal void log_select(Log *log);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Log Building/Clearing
|
||||
|
||||
internal void log_msg(String8 string);
|
||||
internal void log_msgf(char *fmt, ...);
|
||||
internal void log_clear(void);
|
||||
|
||||
#endif // BASE_LOG_H
|
||||
@@ -4,9 +4,9 @@
|
||||
#ifndef BASE_MARKUP_H
|
||||
#define BASE_MARKUP_H
|
||||
|
||||
internal void thread_namef(char *fmt, ...);
|
||||
internal void thread_name(String8 string);
|
||||
internal void thread_namef(char *fmt, ...);
|
||||
#define ThreadNameF(...) (ProfThreadName(__VA_ARGS__), thread_namef(__VA_ARGS__))
|
||||
#define ThreadName(str) (ProfThreadName("%s", str8_varg(str)), thread_name(str))
|
||||
#define ThreadName(str) (ProfThreadName("%.*s", str8_varg(str)), thread_name(str))
|
||||
|
||||
#endif // BASE_MARKUP_H
|
||||
|
||||
@@ -865,6 +865,7 @@ ctrl_init(void)
|
||||
ctrl_state->u2ms_ring_base = push_array(arena, U8, ctrl_state->u2ms_ring_size);
|
||||
ctrl_state->u2ms_ring_mutex = os_mutex_alloc();
|
||||
ctrl_state->u2ms_ring_cv = os_condition_variable_alloc();
|
||||
ctrl_state->ctrl_thread_log = log_alloc();
|
||||
ctrl_state->ctrl_thread = os_launch_thread(ctrl_thread__entry_point, 0, 0);
|
||||
ctrl_state->ms_thread_count = Clamp(1, os_logical_core_count()-1, 4);
|
||||
ctrl_state->ms_threads = push_array(arena, OS_Handle, ctrl_state->ms_thread_count);
|
||||
@@ -1737,6 +1738,7 @@ ctrl_thread__entry_point(void *p)
|
||||
ThreadNameF("[ctrl] thread");
|
||||
ProfBeginFunction();
|
||||
DMN_CtrlCtx *ctrl_ctx = dmn_ctrl_begin();
|
||||
log_select(ctrl_state->ctrl_thread_log);
|
||||
|
||||
//- rjf: loop
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
@@ -1923,6 +1925,22 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg,
|
||||
// rjf: grab first event
|
||||
DMN_EventNode *next_event_node = ctrl_state->first_dmn_event_node;
|
||||
|
||||
// rjf: log event
|
||||
if(next_event_node != 0)
|
||||
{
|
||||
DMN_Event *ev = &next_event_node->v;
|
||||
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]);
|
||||
log_msgf("process: [%I64u]\n", ev->process.u64[0]);
|
||||
log_msgf("thread: [%I64u]\n", ev->thread.u64[0]);
|
||||
log_msgf("module: [%I64u]\n", ev->module.u64[0]);
|
||||
log_msgf("arch: %S\n", string_from_architecture(ev->arch));
|
||||
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);
|
||||
}
|
||||
|
||||
// rjf: determine if we should filter
|
||||
B32 should_filter_event = 0;
|
||||
if(next_event_node != 0)
|
||||
|
||||
@@ -515,6 +515,7 @@ struct CTRL_State
|
||||
|
||||
// rjf: ctrl thread state
|
||||
OS_Handle ctrl_thread;
|
||||
Log *ctrl_thread_log;
|
||||
CTRL_EntityStore *ctrl_thread_entity_store;
|
||||
Arena *dmn_event_arena;
|
||||
DMN_EventNode *first_dmn_event_node;
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Generated Code
|
||||
|
||||
#include "generated/demon.meta.c"
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Basic Type Functions (Helpers, Implemented Once)
|
||||
|
||||
|
||||
@@ -61,6 +61,11 @@ DMN_ExceptionKindTable:
|
||||
COUNT
|
||||
}
|
||||
|
||||
@data(String8) dmn_event_kind_string_table:
|
||||
{
|
||||
@expand(DMN_EventKindTable a) `str8_lit_comp("$(a.name)")`
|
||||
}
|
||||
|
||||
@enum DMN_ErrorKind:
|
||||
{
|
||||
@expand(DMN_ErrorKindTable a) `$(a.name)`,
|
||||
@@ -78,3 +83,8 @@ DMN_ExceptionKindTable:
|
||||
@expand(DMN_ExceptionKindTable a) `$(a.name)`,
|
||||
COUNT
|
||||
}
|
||||
|
||||
@data(String8) dmn_exception_kind_string_table:
|
||||
{
|
||||
@expand(DMN_ExceptionKindTable a) `str8_lit_comp("$(a.name)")`
|
||||
}
|
||||
|
||||
@@ -4,5 +4,35 @@
|
||||
//- GENERATED CODE
|
||||
|
||||
C_LINKAGE_BEGIN
|
||||
String8 dmn_event_kind_string_table[17] =
|
||||
{
|
||||
str8_lit_comp("Null"),
|
||||
str8_lit_comp("Error"),
|
||||
str8_lit_comp("HandshakeComplete"),
|
||||
str8_lit_comp("CreateProcess"),
|
||||
str8_lit_comp("ExitProcess"),
|
||||
str8_lit_comp("CreateThread"),
|
||||
str8_lit_comp("ExitThread"),
|
||||
str8_lit_comp("LoadModule"),
|
||||
str8_lit_comp("UnloadModule"),
|
||||
str8_lit_comp("Breakpoint"),
|
||||
str8_lit_comp("Trap"),
|
||||
str8_lit_comp("SingleStep"),
|
||||
str8_lit_comp("Exception"),
|
||||
str8_lit_comp("Halt"),
|
||||
str8_lit_comp("Memory"),
|
||||
str8_lit_comp("DebugString"),
|
||||
str8_lit_comp("SetThreadName"),
|
||||
};
|
||||
|
||||
String8 dmn_exception_kind_string_table[5] =
|
||||
{
|
||||
str8_lit_comp("Null"),
|
||||
str8_lit_comp("MemoryRead"),
|
||||
str8_lit_comp("MemoryWrite"),
|
||||
str8_lit_comp("MemoryExecute"),
|
||||
str8_lit_comp("CppThrow"),
|
||||
};
|
||||
|
||||
C_LINKAGE_END
|
||||
|
||||
|
||||
@@ -58,6 +58,8 @@ DMN_ExceptionKind_COUNT,
|
||||
} DMN_ExceptionKind;
|
||||
|
||||
C_LINKAGE_BEGIN
|
||||
extern String8 dmn_event_kind_string_table[17];
|
||||
extern String8 dmn_exception_kind_string_table[5];
|
||||
C_LINKAGE_END
|
||||
|
||||
#endif // DEMON_META_H
|
||||
|
||||
+9
-1
@@ -4295,10 +4295,18 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D
|
||||
|
||||
// rjf: help menu
|
||||
UI_Key help_menu_key = ui_key_from_string(ui_key_zero(), str8_lit("_help_menu_key_"));
|
||||
UI_CtxMenu(help_menu_key) UI_PrefWidth(ui_em(40.f, 1.f))
|
||||
UI_CtxMenu(help_menu_key) UI_PrefWidth(ui_em(60.f, 1.f))
|
||||
{
|
||||
UI_Row UI_TextAlignment(UI_TextAlign_Center) UI_TextColor(df_rgba_from_theme_color(DF_ThemeColor_WeakText))
|
||||
ui_label(str8_lit(BUILD_TITLE_STRING_LITERAL));
|
||||
UI_PrefHeight(ui_children_sum(1)) UI_Row UI_Padding(ui_pct(1, 0))
|
||||
{
|
||||
R_Handle texture = df_gfx_state->icon_texture;
|
||||
Vec2S32 texture_dim = r_size_from_tex2d(texture);
|
||||
UI_PrefWidth(ui_px(ui_top_font_size()*10.f, 1.f))
|
||||
UI_PrefHeight(ui_px(ui_top_font_size()*10.f, 1.f))
|
||||
ui_image(texture, R_Tex2DSampleKind_Linear, r2f32p(0, 0, texture_dim.x, texture_dim.y), v4f32(1, 1, 1, 1), 0, str8_lit(""));
|
||||
}
|
||||
ui_spacer(ui_em(0.25f, 1.f));
|
||||
UI_Row
|
||||
UI_PrefWidth(ui_text_dim(10, 1))
|
||||
|
||||
Reference in New Issue
Block a user