From b23323c03d6cfe5773c8ca76a6d5052ccb071084 Mon Sep 17 00:00:00 2001 From: Nikita Smith Date: Tue, 5 May 2026 17:38:01 -0700 Subject: [PATCH] add switch to override default logs folder --- src/base/base_log.c | 2 ++ src/base/base_log.h | 5 +++++ src/dbg_engine/dbg_engine_core.c | 17 ++++++----------- src/raddbg/raddbg_core.c | 17 +++++++---------- src/raddbg/raddbg_main.c | 13 ++++++++++++- 5 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/base/base_log.c b/src/base/base_log.c index 3916ce1c..5adf5a8a 100644 --- a/src/base/base_log.c +++ b/src/base/base_log.c @@ -9,6 +9,8 @@ C_LINKAGE thread_static Log *log_active; C_LINKAGE thread_static Log *log_active = 0; #endif +String8 g_logs_folder; + //////////////////////////////// //~ rjf: Log Creation/Selection diff --git a/src/base/base_log.h b/src/base/base_log.h index 1cc58ff0..8ef71a37 100644 --- a/src/base/base_log.h +++ b/src/base/base_log.h @@ -36,6 +36,11 @@ struct Log LogScope *top_scope; }; +//////////////////////////////// +// Globals + +extern String8 g_logs_folder; + //////////////////////////////// //~ rjf: Log Creation/Selection diff --git a/src/dbg_engine/dbg_engine_core.c b/src/dbg_engine/dbg_engine_core.c index e55ef168..3885ca13 100644 --- a/src/dbg_engine/dbg_engine_core.c +++ b/src/dbg_engine/dbg_engine_core.c @@ -53,17 +53,12 @@ d_init(void) d_ctrl_state->c2u_ring_size = KB(64); d_ctrl_state->c2u_ring_max_string_size = d_ctrl_state->c2u_ring_size/2; d_ctrl_state->c2u_ring_base = push_array_no_zero(arena, U8, d_ctrl_state->c2u_ring_size); - d_ctrl_state->c2u_ring_mutex = mutex_alloc(); - d_ctrl_state->c2u_ring_cv = cond_var_alloc(); - { - Temp scratch = scratch_begin(0, 0); - String8 user_program_data_path = get_process_info()->user_program_data_path; - String8 user_data_folder = push_str8f(scratch.arena, "%S/%Sraddbg/logs", user_program_data_path, program_data_folder_prefix_from_os(OperatingSystem_CURRENT)); - make_directory(user_data_folder); - d_ctrl_state->ctrl_thread_log_path = push_str8f(d_ctrl_state->arena, "%S/ctrl_thread.raddbg_log", user_data_folder); - write_data_to_file_path(d_ctrl_state->ctrl_thread_log_path, str8_zero()); - scratch_end(scratch); - } + d_ctrl_state->c2u_ring_mutex = mutex_alloc(); + d_ctrl_state->c2u_ring_cv = cond_var_alloc(); + { + d_ctrl_state->ctrl_thread_log_path = push_str8f(d_ctrl_state->arena, "%S/ctrl_thread.raddbg_log", g_logs_folder); + write_data_to_file_path(d_ctrl_state->ctrl_thread_log_path, str8_zero()); + } d_ctrl_state->ctrl_thread_entity_ctx_rw_mutex = rw_mutex_alloc(); d_ctrl_state->ctrl_thread_entity_store = d_entity_ctx_rw_store_alloc(); d_ctrl_state->ctrl_thread_eval_cache = e_cache_alloc(); diff --git a/src/raddbg/raddbg_core.c b/src/raddbg/raddbg_core.c index 3d8b53c1..1806e204 100644 --- a/src/raddbg/raddbg_core.c +++ b/src/raddbg/raddbg_core.c @@ -10597,16 +10597,13 @@ rd_init(CmdLine *cmdln) rd_state->frame_arenas[idx] = arena_alloc(); } rd_state->log = log_alloc(); - log_select(rd_state->log); - { - Temp scratch = scratch_begin(0, 0); - String8 user_program_data_path = get_process_info()->user_program_data_path; - String8 user_data_folder = push_str8f(scratch.arena, "%S/%Sraddbg/logs", user_program_data_path, program_data_folder_prefix_from_os(OperatingSystem_CURRENT)); - rd_state->log_path = push_str8f(rd_state->arena, "%S/ui_thread.raddbg_log", user_data_folder); - make_directory(user_data_folder); - write_data_to_file_path(rd_state->log_path, str8_zero()); - scratch_end(scratch); - } + log_select(rd_state->log); + { + Temp scratch = scratch_begin(0, 0); + rd_state->log_path = push_str8f(rd_state->arena, "%S/ui_thread.raddbg_log", g_logs_folder); + write_data_to_file_path(rd_state->log_path, str8_zero()); + scratch_end(scratch); + } rd_state->num_frames_requested = 2; rd_state->seconds_until_autosave = 0.5f; rd_state->eval_cache = e_cache_alloc(); diff --git a/src/raddbg/raddbg_main.c b/src/raddbg/raddbg_main.c index 7395e32b..efaab158 100644 --- a/src/raddbg/raddbg_main.c +++ b/src/raddbg/raddbg_main.c @@ -532,7 +532,16 @@ entry_point(CmdLine *cmd_line) try_u64_from_str8_c_rules(jit_addr_string, &jit_addr); jit_attach = (jit_addr != 0); } - + + // init log + g_logs_folder = cmd_line_string(cmd_line, str8_lit("logs")); + if(g_logs_folder.size == 0) + { + String8 user_program_data_path = get_process_info()->user_program_data_path; + g_logs_folder = push_str8f(scratch.arena, "%S/%Sraddbg/logs", program_data_folder_prefix_from_os(OperatingSystem_CURRENT), user_program_data_path); + } + make_directory(g_logs_folder); + //- rjf: dispatch to top-level codepath based on execution mode switch(exec_mode) { @@ -863,6 +872,8 @@ entry_point(CmdLine *cmd_line) "This will launch the debugger in the non-graphical IPC mode, which is used to communicate with another running instance of the debugger. The debugger instance will launch, send the specified command, then immediately terminate. This may be used by editors or other programs to control the debugger.\n\n" "--gen_crash_dump\n" "Generate mini dump on crash.\n\n" + "--logs:\n" + "Overrides default path to the folder with logs.\n" )); }break; }