diff --git a/src/artifact_cache/artifact_cache.c b/src/artifact_cache/artifact_cache.c index b9b0db58..7a1e1e30 100644 --- a/src/artifact_cache/artifact_cache.c +++ b/src/artifact_cache/artifact_cache.c @@ -681,6 +681,7 @@ ac_async_tick(void) internal void ac_cancel_thread_entry_point(void *p) { + ThreadNameF("ac_cancel_thread"); for(;;) { sleep_ms(50); diff --git a/src/linux/base/linux_base.c b/src/linux/base/linux_base.c index e95e2be8..28069770 100644 --- a/src/linux/base/linux_base.c +++ b/src/linux/base/linux_base.c @@ -367,8 +367,7 @@ set_platform_thread_name(String8 name) { Temp scratch = scratch_begin(0, 0); String8 name_copy = str8_copy(scratch.arena, name); - pthread_t current_thread = pthread_self(); - pthread_setname_np(current_thread, (char *)name_copy.str); + prctl(PR_SET_NAME, (char *)name_copy.str); scratch_end(scratch); } diff --git a/src/linux/base/linux_base.h b/src/linux/base/linux_base.h index 230f7f18..27cad030 100644 --- a/src/linux/base/linux_base.h +++ b/src/linux/base/linux_base.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include diff --git a/src/linux/demon/linux_demon.c b/src/linux/demon/linux_demon.c index 46cce896..2d5429db 100644 --- a/src/linux/demon/linux_demon.c +++ b/src/linux/demon/linux_demon.c @@ -3272,6 +3272,48 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) e->error_kind = DMN_ErrorKind_NotAttached; } + ////////////////////////////// + //- rjf: gather thread names + // + for(LNX_DMN_Process *process = lnx_dmn_state->first_process; process != 0; process = process->next) + { + U64 main_thread_name_hash = 0; + for(LNX_DMN_Thread *thread = process->first_thread; thread != 0; thread = thread->next) + { + if(thread->tid == process->pid) + { + main_thread_name_hash = thread->last_name_hash; + break; + } + } + for(LNX_DMN_Thread *thread = process->first_thread; thread != 0; thread = thread->next) + { + if(thread->last_name_hash == 0 || thread->name_gather_time_us+1000000 <= now_time_us()) + { + Temp temp = temp_begin(scratch.arena); + char *thread_name_path = (char *)str8f(temp.arena, "/proc/%d/task/%d/comm", process->pid, thread->tid).str; + int thread_name_file = LNX_RETRY_ON_EINTR(open(thread_name_path, O_RDONLY)); + if(thread_name_file >= 0) + { + String8 thread_name = lnx_dmn_read_string_capped(temp.arena, thread_name_file, 0, 1024); + U64 hash = u64_hash_from_str8(thread_name); + if(thread_name.size != 0 && hash != thread->last_name_hash && (hash != main_thread_name_hash || thread->tid == process->pid)) + { + DMN_Event *e = dmn_event_list_push(arena, &events); + e->kind = DMN_EventKind_SetThreadName; + e->process = lnx_dmn_handle_from_process(process); + e->thread = lnx_dmn_handle_from_thread(thread); + e->string = str8_copy(arena, thread_name); + } + thread->last_name_hash = hash; + } + thread->name_gather_time_us = now_time_us(); + LNX_RETRY_ON_EINTR(close(thread_name_file)); + temp_end(temp); + } + } + } + ////////////////////////////// //- rjf: re-allow halts // @@ -3297,7 +3339,7 @@ dmn_halt(U64 code, U64 user_data) for EachNode(process, LNX_DMN_Process, lnx_dmn_state->first_process) { int kill_result = LNX_RETRY_ON_EINTR(kill(process->pid, SIGSTOP)); - int x = 0; + (void)kill_result; } } } diff --git a/src/linux/demon/linux_demon.h b/src/linux/demon/linux_demon.h index ae81b419..22ff00fb 100644 --- a/src/linux/demon/linux_demon.h +++ b/src/linux/demon/linux_demon.h @@ -179,6 +179,8 @@ struct LNX_DMN_Thread B32 is_reg_block_dirty; B32 pass_through_signal; B32 ghost_trap; + U64 last_name_hash; + U64 name_gather_time_us; U64 pass_through_signo; U64 orig_rax; U64 dtv_base_vaddr; diff --git a/src/raddbg/raddbg_main.c b/src/raddbg/raddbg_main.c index c17b9203..2225d739 100644 --- a/src/raddbg/raddbg_main.c +++ b/src/raddbg/raddbg_main.c @@ -5,19 +5,15 @@ //~ rjf: linux TODO notes // // initial alpha: -// [x] .so loading/debugging - missing debug info -// [x] missing disasm // [ ] recycling semaphore files - or alt strat? -// [ ] control -// [ ] stale memory - things evaluating to stale values that are definitely not zero // [ ] rendering // [ ] bitmaps / geometry // // post initial alpha: // [ ] windowing -// [ ] wayland +// [ ] wayland // [ ] support -// [ ] .eh_frame unwinding without .eh_frame_hdr +// [ ] .eh_frame unwinding without .eh_frame_hdr // // [x] clipboard // [x] jai exes - busted call stacks / unwind info / paths? @@ -25,6 +21,11 @@ // [x] statically linked EXEs, not parsing maps file correctly // [x] asan // [x] multithreaded stepping - trap hits reported on other threads. +// [x] .so loading/debugging - missing debug info +// [x] missing disasm +// [x] control +// [x] stale memory - things evaluating to stale values that are definitely not zero +// [x] thread names //////////////////////////////// //~ rjf: evaluation system pass TODO notes