Compare commits

..

5 Commits

Author SHA1 Message Date
5f56e4b63a
kernel: Disable UBSAN in debug.cmake
All checks were successful
Build and test / build (push) Successful in 1m42s
UBSAN seems to bloat the kernel too much, so let's make debug.cmake actually usable for debugging by commenting it out.
2024-12-11 19:19:36 +01:00
24b886b0d1
kernel: Log each thread's instruction pointer when dumping scheduler stats 2024-12-11 19:18:25 +01:00
d8e4489079
kernel: Make Thread::ip() and sp() const-friendly 2024-12-11 19:17:04 +01:00
2868fd8122
kernel: Add a way to lookup specific threads 2024-12-11 19:16:45 +01:00
56a2b607b5
kernel: Fix some debug-only log strings after the process rework 2024-12-11 19:16:22 +01:00
6 changed files with 21 additions and 9 deletions

View File

@ -12,4 +12,4 @@ target_compile_definitions(moon PRIVATE DEVICE_REGISTRY_DEBUG)
target_compile_definitions(moon PRIVATE FORK_DEBUG)
target_compile_definitions(moon PRIVATE MOUNT_DEBUG)
target_compile_definitions(moon PRIVATE CACHE_DEBUG)
target_compile_options(moon PRIVATE -fsanitize=undefined)
#target_compile_options(moon PRIVATE -fsanitize=undefined)

View File

@ -15,7 +15,7 @@ void Thread::set_ip(u64 ip)
regs.rip = ip;
}
u64 Thread::ip()
u64 Thread::ip() const
{
return regs.rip;
}
@ -25,7 +25,7 @@ void Thread::set_sp(u64 sp)
regs.rsp = sp;
}
u64 Thread::sp()
u64 Thread::sp() const
{
return regs.rsp;
}

View File

@ -243,7 +243,7 @@ Result<u64> sys_fork(Registers* regs, SyscallArgs)
Scheduler::add_process(process);
#ifdef FORK_DEBUG
kdbgln("fork: thread %d forked into child %d", current->id, thread->id);
kdbgln("fork: thread %d forked into child %d", current->id, process->id);
#endif
return process->id;

View File

@ -251,7 +251,7 @@ namespace Scheduler
CPU::disable_interrupts();
#ifdef REAP_DEBUG
kdbgln("reap: reaping thread with id %d", thread->id);
kdbgln("reap: reaping thread with id %d", thread->tid);
#endif
if (thread->is_kernel)
@ -409,6 +409,16 @@ namespace Scheduler
return {};
}
Option<Thread*> find_by_tid(pid_t tid)
{
for (auto* const thread : g_threads)
{
if (thread->tid == tid) return thread;
}
return {};
}
bool has_children(Process* process)
{
bool result { false };
@ -447,8 +457,9 @@ namespace Scheduler
for (const auto* thread : g_threads)
{
kdbgln("Thread %p (belongs to pid %4d) %c [%-20s] %4d, state = %d", thread, thread->process->id,
thread->is_kernel ? 'k' : 'u', thread->cmdline.chars(), thread->tid, (int)thread->state);
kdbgln("Thread %p (belongs to pid %4d) %c [%-20s] %4d, state = %d, ip = %p", thread, thread->process->id,
thread->is_kernel ? 'k' : 'u', thread->cmdline.chars(), thread->tid, (int)thread->state,
(void*)thread->ip());
}
for (const auto* process : g_processes)

View File

@ -38,6 +38,7 @@ namespace Scheduler
LinkedList<Process> check_for_dead_processes();
Option<Process*> find_by_pid(pid_t pid);
Option<Thread*> find_by_tid(pid_t tid);
template <typename Callback> void for_each_child(Process* process, Callback callback)
{

View File

@ -198,10 +198,10 @@ struct Thread : public LinkedListNode<Thread>
void set_arguments(u64 arg1, u64 arg2, u64 arg3, u64 arg4);
void set_ip(u64 ip);
u64 ip();
u64 ip() const;
void set_sp(u64 sp);
u64 sp();
u64 sp() const;
void set_return(u64 ret);
u64 return_register();