linux_demon: thread names

This commit is contained in:
Ryan Fleury committed 2026-09-29 13:09:41 -06:00
1 parent 0b91cab00a
commit 7082c7b67d
6 files changed
+55 -9

No files matched your search

+1
View File
@@ -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);
+1 -2
View File
@@ -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);
}
+1
View File
@@ -30,6 +30,7 @@
#include <sys/sysinfo.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/prctl.h>
#include <time.h>
#include <unistd.h>
#include <ucontext.h>
+43 -1
View File
@@ -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;
}
}
}
+2
View File
@@ -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;
+7 -6
View File
@@ -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