Skip to content

Commit b995909

Browse files
committed
sketch out logging stub, to begin marking up debugger layers with logging - high level stuff still wip
1 parent a954317 commit b995909

File tree

12 files changed

+183
-3
lines changed

12 files changed

+183
-3
lines changed

src/base/base_inc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@
1515
#include "base_thread_context.c"
1616
#include "base_command_line.c"
1717
#include "base_markup.c"
18+
#include "base_log.c"
1819
#include "base_entry_point.c"

src/base/base_inc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "base_thread_context.h"
1818
#include "base_command_line.h"
1919
#include "base_markup.h"
20+
#include "base_log.h"
2021
#include "base_entry_point.h"
2122

2223
#endif // BASE_INC_H

src/base/base_log.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright (c) 2024 Epic Games Tools
2+
// Licensed under the MIT license (https://opensource.org/license/mit/)
3+
4+
////////////////////////////////
5+
//~ rjf: Globals/Thread-Locals
6+
7+
C_LINKAGE thread_static Log *log_active;
8+
#if !BUILD_SUPPLEMENTARY_UNIT
9+
C_LINKAGE thread_static Log *log_active = 0;
10+
#endif
11+
12+
////////////////////////////////
13+
//~ rjf: Log Creation/Selection
14+
15+
internal Log *
16+
log_alloc(void)
17+
{
18+
Arena *arena = arena_alloc();
19+
Log *log = push_array(arena, Log, 1);
20+
log->arena = arena;
21+
log->log_buffer_start_pos = arena_pos(arena);
22+
return log;
23+
}
24+
25+
internal void
26+
log_release(Log *log)
27+
{
28+
arena_release(log->arena);
29+
}
30+
31+
internal void
32+
log_select(Log *log)
33+
{
34+
log_active = log;
35+
}
36+
37+
////////////////////////////////
38+
//~ rjf: Log Building/Clearing
39+
40+
internal void
41+
log_msg(String8 string)
42+
{
43+
if(log_active != 0)
44+
{
45+
str8_list_push(log_active->arena, &log_active->log_buffer_strings, string);
46+
}
47+
}
48+
49+
internal void
50+
log_msgf(char *fmt, ...)
51+
{
52+
if(log_active != 0)
53+
{
54+
Temp scratch = scratch_begin(0, 0);
55+
va_list args;
56+
va_start(args, fmt);
57+
String8 string = push_str8fv(scratch.arena, fmt, args);
58+
log_msg(string);
59+
va_end(args);
60+
scratch_end(scratch);
61+
}
62+
}
63+
64+
internal void
65+
log_clear(void)
66+
{
67+
if(log_active != 0)
68+
{
69+
arena_pop_to(log_active->arena, log_active->log_buffer_start_pos);
70+
MemoryZeroStruct(&log_active->log_buffer_strings);
71+
}
72+
}

src/base/base_log.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) 2024 Epic Games Tools
2+
// Licensed under the MIT license (https://opensource.org/license/mit/)
3+
4+
#ifndef BASE_LOG_H
5+
#define BASE_LOG_H
6+
7+
////////////////////////////////
8+
//~ rjf: Log Type
9+
10+
typedef struct Log Log;
11+
struct Log
12+
{
13+
Arena *arena;
14+
U64 log_buffer_start_pos;
15+
String8List log_buffer_strings;
16+
};
17+
18+
////////////////////////////////
19+
//~ rjf: Log Creation/Selection
20+
21+
internal Log *log_alloc(void);
22+
internal void log_release(Log *log);
23+
internal void log_select(Log *log);
24+
25+
////////////////////////////////
26+
//~ rjf: Log Building/Clearing
27+
28+
internal void log_msg(String8 string);
29+
internal void log_msgf(char *fmt, ...);
30+
internal void log_clear(void);
31+
32+
#endif // BASE_LOG_H

src/base/base_markup.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#ifndef BASE_MARKUP_H
55
#define BASE_MARKUP_H
66

7-
internal void thread_namef(char *fmt, ...);
87
internal void thread_name(String8 string);
8+
internal void thread_namef(char *fmt, ...);
99
#define ThreadNameF(...) (ProfThreadName(__VA_ARGS__), thread_namef(__VA_ARGS__))
10-
#define ThreadName(str) (ProfThreadName("%s", str8_varg(str)), thread_name(str))
10+
#define ThreadName(str) (ProfThreadName("%.*s", str8_varg(str)), thread_name(str))
1111

1212
#endif // BASE_MARKUP_H

src/ctrl/ctrl_core.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,7 @@ ctrl_init(void)
865865
ctrl_state->u2ms_ring_base = push_array(arena, U8, ctrl_state->u2ms_ring_size);
866866
ctrl_state->u2ms_ring_mutex = os_mutex_alloc();
867867
ctrl_state->u2ms_ring_cv = os_condition_variable_alloc();
868+
ctrl_state->ctrl_thread_log = log_alloc();
868869
ctrl_state->ctrl_thread = os_launch_thread(ctrl_thread__entry_point, 0, 0);
869870
ctrl_state->ms_thread_count = Clamp(1, os_logical_core_count()-1, 4);
870871
ctrl_state->ms_threads = push_array(arena, OS_Handle, ctrl_state->ms_thread_count);
@@ -1737,6 +1738,7 @@ ctrl_thread__entry_point(void *p)
17371738
ThreadNameF("[ctrl] thread");
17381739
ProfBeginFunction();
17391740
DMN_CtrlCtx *ctrl_ctx = dmn_ctrl_begin();
1741+
log_select(ctrl_state->ctrl_thread_log);
17401742

17411743
//- rjf: loop
17421744
Temp scratch = scratch_begin(0, 0);
@@ -1923,6 +1925,22 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg,
19231925
// rjf: grab first event
19241926
DMN_EventNode *next_event_node = ctrl_state->first_dmn_event_node;
19251927

1928+
// rjf: log event
1929+
if(next_event_node != 0)
1930+
{
1931+
DMN_Event *ev = &next_event_node->v;
1932+
log_msgf("--- event ---\n");
1933+
log_msgf("kind: %S\n", dmn_event_kind_string_table[ev->kind]);
1934+
log_msgf("exception_kind: %S\n", dmn_exception_kind_string_table[ev->exception_kind]);
1935+
log_msgf("process: [%I64u]\n", ev->process.u64[0]);
1936+
log_msgf("thread: [%I64u]\n", ev->thread.u64[0]);
1937+
log_msgf("module: [%I64u]\n", ev->module.u64[0]);
1938+
log_msgf("arch: %S\n", string_from_architecture(ev->arch));
1939+
log_msgf("address: 0x%I64x\n", ev->address);
1940+
log_msgf("string: \"%S\"\n", ev->string);
1941+
log_msgf("ip_vaddr: 0x%I64x\n", ev->instruction_pointer);
1942+
}
1943+
19261944
// rjf: determine if we should filter
19271945
B32 should_filter_event = 0;
19281946
if(next_event_node != 0)

src/ctrl/ctrl_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ struct CTRL_State
515515

516516
// rjf: ctrl thread state
517517
OS_Handle ctrl_thread;
518+
Log *ctrl_thread_log;
518519
CTRL_EntityStore *ctrl_thread_entity_store;
519520
Arena *dmn_event_arena;
520521
DMN_EventNode *first_dmn_event_node;

src/demon/demon_core.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// Copyright (c) 2024 Epic Games Tools
22
// Licensed under the MIT license (https://opensource.org/license/mit/)
33

4+
////////////////////////////////
5+
//~ rjf: Generated Code
6+
7+
#include "generated/demon.meta.c"
8+
49
////////////////////////////////
510
//~ rjf: Basic Type Functions (Helpers, Implemented Once)
611

src/demon/demon_core.mdesk

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ DMN_ExceptionKindTable:
6161
COUNT
6262
}
6363

64+
@data(String8) dmn_event_kind_string_table:
65+
{
66+
@expand(DMN_EventKindTable a) `str8_lit_comp("$(a.name)")`
67+
}
68+
6469
@enum DMN_ErrorKind:
6570
{
6671
@expand(DMN_ErrorKindTable a) `$(a.name)`,
@@ -78,3 +83,8 @@ DMN_ExceptionKindTable:
7883
@expand(DMN_ExceptionKindTable a) `$(a.name)`,
7984
COUNT
8085
}
86+
87+
@data(String8) dmn_exception_kind_string_table:
88+
{
89+
@expand(DMN_ExceptionKindTable a) `str8_lit_comp("$(a.name)")`
90+
}

src/demon/generated/demon.meta.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,35 @@
44
//- GENERATED CODE
55

66
C_LINKAGE_BEGIN
7+
String8 dmn_event_kind_string_table[17] =
8+
{
9+
str8_lit_comp("Null"),
10+
str8_lit_comp("Error"),
11+
str8_lit_comp("HandshakeComplete"),
12+
str8_lit_comp("CreateProcess"),
13+
str8_lit_comp("ExitProcess"),
14+
str8_lit_comp("CreateThread"),
15+
str8_lit_comp("ExitThread"),
16+
str8_lit_comp("LoadModule"),
17+
str8_lit_comp("UnloadModule"),
18+
str8_lit_comp("Breakpoint"),
19+
str8_lit_comp("Trap"),
20+
str8_lit_comp("SingleStep"),
21+
str8_lit_comp("Exception"),
22+
str8_lit_comp("Halt"),
23+
str8_lit_comp("Memory"),
24+
str8_lit_comp("DebugString"),
25+
str8_lit_comp("SetThreadName"),
26+
};
27+
28+
String8 dmn_exception_kind_string_table[5] =
29+
{
30+
str8_lit_comp("Null"),
31+
str8_lit_comp("MemoryRead"),
32+
str8_lit_comp("MemoryWrite"),
33+
str8_lit_comp("MemoryExecute"),
34+
str8_lit_comp("CppThrow"),
35+
};
36+
737
C_LINKAGE_END
838

src/demon/generated/demon.meta.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ DMN_ExceptionKind_COUNT,
5858
} DMN_ExceptionKind;
5959

6060
C_LINKAGE_BEGIN
61+
extern String8 dmn_event_kind_string_table[17];
62+
extern String8 dmn_exception_kind_string_table[5];
6163
C_LINKAGE_END
6264

6365
#endif // DEMON_META_H

src/df/gfx/df_gfx.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4295,10 +4295,18 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D
42954295

42964296
// rjf: help menu
42974297
UI_Key help_menu_key = ui_key_from_string(ui_key_zero(), str8_lit("_help_menu_key_"));
4298-
UI_CtxMenu(help_menu_key) UI_PrefWidth(ui_em(40.f, 1.f))
4298+
UI_CtxMenu(help_menu_key) UI_PrefWidth(ui_em(60.f, 1.f))
42994299
{
43004300
UI_Row UI_TextAlignment(UI_TextAlign_Center) UI_TextColor(df_rgba_from_theme_color(DF_ThemeColor_WeakText))
43014301
ui_label(str8_lit(BUILD_TITLE_STRING_LITERAL));
4302+
UI_PrefHeight(ui_children_sum(1)) UI_Row UI_Padding(ui_pct(1, 0))
4303+
{
4304+
R_Handle texture = df_gfx_state->icon_texture;
4305+
Vec2S32 texture_dim = r_size_from_tex2d(texture);
4306+
UI_PrefWidth(ui_px(ui_top_font_size()*10.f, 1.f))
4307+
UI_PrefHeight(ui_px(ui_top_font_size()*10.f, 1.f))
4308+
ui_image(texture, R_Tex2DSampleKind_Linear, r2f32p(0, 0, texture_dim.x, texture_dim.y), v4f32(1, 1, 1, 1), 0, str8_lit(""));
4309+
}
43024310
ui_spacer(ui_em(0.25f, 1.f));
43034311
UI_Row
43044312
UI_PrefWidth(ui_text_dim(10, 1))

0 commit comments

Comments
 (0)