diff --git a/AK/LogStream.cpp b/AK/LogStream.cpp index 2144b80842..33e58c68b8 100644 --- a/AK/LogStream.cpp +++ b/AK/LogStream.cpp @@ -24,10 +24,15 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include +#include #include +#ifdef KERNEL +# include +# include +#endif + namespace AK { const LogStream& operator<<(const LogStream& stream, const String& value) @@ -62,7 +67,7 @@ const LogStream& operator<<(const LogStream& stream, const void* value) return stream << String::format("%p", value); } -#if defined (__serenity__) && !defined(KERNEL) +#if defined(__serenity__) && !defined(KERNEL) static TriState got_process_name = TriState::Unknown; static char process_name_buffer[256]; #endif @@ -70,7 +75,7 @@ static char process_name_buffer[256]; DebugLogStream dbg() { DebugLogStream stream; -#if defined (__serenity__) && !defined(KERNEL) +#if defined(__serenity__) && !defined(KERNEL) if (got_process_name == TriState::Unknown) { if (get_process_name(process_name_buffer, sizeof(process_name_buffer)) == 0) got_process_name = TriState::True; @@ -79,6 +84,12 @@ DebugLogStream dbg() } if (got_process_name == TriState::True) stream << "\033[33;1m" << process_name_buffer << '(' << getpid() << ")\033[0m: "; +#endif +#if defined(__serenity__) && defined(KERNEL) + if (current) + stream << "\033[34;1m[" << *current << "]\033[0m: "; + else + stream << "\033[36;1m[Kernel]\033[0m: "; #endif return stream; } diff --git a/Kernel/Devices/BXVGADevice.cpp b/Kernel/Devices/BXVGADevice.cpp index 0d1e30fb36..714096f586 100644 --- a/Kernel/Devices/BXVGADevice.cpp +++ b/Kernel/Devices/BXVGADevice.cpp @@ -123,9 +123,7 @@ KResultOr BXVGADevice::mmap(Process& process, FileDescription&, Virtual 0, "BXVGA Framebuffer", prot); - dbgprintf("BXVGA: %s(%u) created Region{%p} with size %u for framebuffer P%x with vaddr V%p\n", - process.name().characters(), process.pid(), - region, region->size(), m_framebuffer_address.as_ptr(), region->vaddr().get()); + dbg() << "BXVGADevice: mmap with size " << region->size() << " at " << region->vaddr(); ASSERT(region); return region; } diff --git a/Kernel/Devices/MBVGADevice.cpp b/Kernel/Devices/MBVGADevice.cpp index 24f678bf3f..c8ca9f6177 100644 --- a/Kernel/Devices/MBVGADevice.cpp +++ b/Kernel/Devices/MBVGADevice.cpp @@ -62,9 +62,7 @@ KResultOr MBVGADevice::mmap(Process& process, FileDescription&, Virtual 0, "MBVGA Framebuffer", prot); - dbgprintf("MBVGA: %s(%u) created Region{%p} with size %u for framebuffer P%x with vaddr V%p\n", - process.name().characters(), process.pid(), - region, region->size(), m_framebuffer_address.as_ptr(), region->vaddr().get()); + dbg() << "MBVGADevice: mmap with size " << region->size() << " at " << region->vaddr(); ASSERT(region); return region; } diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index 6b4ba042eb..90a3b62953 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -728,38 +728,38 @@ KResult VFS::validate_path_against_process_veil(StringView path, int options) auto* unveiled_path = find_matching_unveiled_path(path); if (!unveiled_path) { - dbg() << *current << " rejecting path '" << path << "' since it hasn't been unveiled."; + dbg() << "Rejecting path '" << path << "' since it hasn't been unveiled."; return KResult(-ENOENT); } if (options & O_CREAT) { if (!(unveiled_path->permissions & UnveiledPath::Access::CreateOrRemove)) { - dbg() << *current << " rejecting path '" << path << "' since it hasn't been unveiled with 'c' permission."; + dbg() << "Rejecting path '" << path << "' since it hasn't been unveiled with 'c' permission."; return KResult(-EACCES); } } if (options & O_UNLINK_INTERNAL) { if (!(unveiled_path->permissions & UnveiledPath::Access::CreateOrRemove)) { - dbg() << *current << " rejecting path '" << path << "' for unlink since it hasn't been unveiled with 'c' permission."; + dbg() << "Rejecting path '" << path << "' for unlink since it hasn't been unveiled with 'c' permission."; return KResult(-EACCES); } return KSuccess; } if (options & O_RDONLY) { if (!(unveiled_path->permissions & UnveiledPath::Access::Read)) { - dbg() << *current << " rejecting path '" << path << "' since it hasn't been unveiled with 'r' permission."; + dbg() << "Rejecting path '" << path << "' since it hasn't been unveiled with 'r' permission."; return KResult(-EACCES); } } if (options & O_WRONLY) { if (!(unveiled_path->permissions & UnveiledPath::Access::Write)) { - dbg() << *current << " rejecting path '" << path << "' since it hasn't been unveiled with 'w' permission."; + dbg() << "Rejecting path '" << path << "' since it hasn't been unveiled with 'w' permission."; return KResult(-EACCES); } } if (options & O_EXEC) { if (!(unveiled_path->permissions & UnveiledPath::Access::Execute)) { - dbg() << *current << " rejecting path '" << path << "' since it hasn't been unveiled with 'x' permission."; + dbg() << "Rejecting path '" << path << "' since it hasn't been unveiled with 'x' permission."; return KResult(-EACCES); } } diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 56dc3ea059..8977c00555 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -697,7 +697,7 @@ int Process::do_exec(NonnullRefPtr main_program_description, Ve { ASSERT(is_ring3()); auto path = main_program_description->absolute_path(); - dbgprintf("%s(%d) do_exec(%s): thread_count() = %d\n", m_name.characters(), m_pid, path.characters(), thread_count()); + dbg() << "do_exec(" << path << ")"; // FIXME(Thread): Kill any threads the moment we commit to the exec(). if (thread_count() != 1) { dbgprintf("Gonna die because I have many threads! These are the threads:\n"); @@ -1251,7 +1251,7 @@ Process::Process(Thread*& first_thread, const String& name, uid_t uid, gid_t gid , m_tty(tty) , m_ppid(ppid) { - dbgprintf("Process: New process PID=%u with name=%s\n", m_pid, m_name.characters()); + dbg() << "Created new process " << m_name << "(" << m_pid << ")"; m_page_directory = PageDirectory::create_for_userspace(*this, fork_parent ? &fork_parent->page_directory().range_allocator() : nullptr); #ifdef MM_DEBUG @@ -1305,7 +1305,6 @@ Process::Process(Thread*& first_thread, const String& name, uid_t uid, gid_t gid Process::~Process() { - dbgprintf("~Process{%p} name=%s pid=%d, m_fds=%d, m_thread_count=%u\n", this, m_name.characters(), pid(), m_fds.size(), m_thread_count); ASSERT(thread_count() == 0); } @@ -2269,7 +2268,7 @@ int Process::reap(Process& process) } } - dbgprintf("reap: %s(%u)\n", process.name().characters(), process.pid()); + dbg() << "Reaping process " << process; ASSERT(process.is_dead()); g_processes->remove(&process); } @@ -2280,7 +2279,7 @@ int Process::reap(Process& process) pid_t Process::sys$waitpid(pid_t waitee, int* wstatus, int options) { REQUIRE_PROMISE(stdio); - dbgprintf("sys$waitpid(%d, %p, %d)\n", waitee, wstatus, options); + dbg() << "sys$waitpid(" << waitee << ", " << wstatus << ", " << options << ")"; if (!options) { // FIXME: This can't be right.. can it? Figure out how this should actually work. @@ -2712,7 +2711,7 @@ int Process::sys$select(const Syscall::SC_select_params* params) for (int fd = 0; fd < nfds; ++fd) { if (FD_ISSET(fd, fds)) { if (!file_description(fd)) { - dbg() << *current << " sys$select: Bad fd number " << fd; + dbg() << "sys$select: Bad fd number " << fd; return -EBADF; } vector.append(fd); @@ -2931,7 +2930,7 @@ int Process::sys$chown(const Syscall::SC_chown_params* user_params) void Process::finalize() { ASSERT(current == g_finalizer); - dbgprintf("Finalizing Process %s(%u)\n", m_name.characters(), m_pid); + dbg() << "Finalizing process " << *this; m_fds.clear(); m_tty = nullptr; diff --git a/Kernel/Process.h b/Kernel/Process.h index e8c4f3b8ac..11074ec59d 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -636,21 +636,21 @@ inline u32 Thread::effective_priority() const return m_priority + m_process.priority_boost() + m_priority_boost + m_extra_priority; } -#define REQUIRE_NO_PROMISES \ - do { \ - if (current->process().has_promises()) { \ - dbg() << *current << " has made a promise"; \ - cli(); \ - current->process().crash(SIGABRT, 0); \ - ASSERT_NOT_REACHED(); \ - } \ +#define REQUIRE_NO_PROMISES \ + do { \ + if (current->process().has_promises()) { \ + dbg() << "Has made a promise"; \ + cli(); \ + current->process().crash(SIGABRT, 0); \ + ASSERT_NOT_REACHED(); \ + } \ } while (0) #define REQUIRE_PROMISE(promise) \ do { \ if (current->process().has_promises() \ && !current->process().has_promised(Pledge::promise)) { \ - dbg() << *current << " has not pledged " << #promise; \ + dbg() << "Has not pledged " << #promise; \ cli(); \ current->process().crash(SIGABRT, 0); \ ASSERT_NOT_REACHED(); \ diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index 048182812d..9ba255cb47 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -82,7 +82,7 @@ Thread::Thread(Process& process) m_tid = Process::allocate_pid(); } process.m_thread_count++; - dbgprintf("Thread{%p}: New thread TID=%u in %s(%u)\n", this, m_tid, process.name().characters(), process.pid()); + dbg() << "Created new thread " << process.name() << "(" << process.pid() << ":" << m_tid << ")"; set_default_signal_dispositions(); m_fpu_state = (FPUState*)kmalloc_aligned(sizeof(FPUState), 16); memcpy(m_fpu_state, &s_clean_fpu_state, sizeof(FPUState)); @@ -143,7 +143,6 @@ Thread::Thread(Process& process) Thread::~Thread() { - dbgprintf("~Thread{%p}\n", this); kfree_aligned(m_fpu_state); { InterruptDisabler disabler; @@ -282,7 +281,7 @@ void Thread::finalize() { ASSERT(current == g_finalizer); - dbgprintf("Finalizing Thread %u in %s(%u)\n", tid(), m_process.name().characters(), pid()); + dbg() << "Finalizing thread " << *this; set_state(Thread::State::Dead); if (m_joiner) { @@ -308,7 +307,6 @@ void Thread::finalize_dying_threads() return IterationDecision::Continue; }); } - dbgprintf("Finalizing %u dying threads\n", dying_threads.size()); for (auto* thread : dying_threads) { auto& process = thread->process(); thread->finalize(); @@ -316,7 +314,6 @@ void Thread::finalize_dying_threads() if (process.m_thread_count == 0) process.finalize(); } - dbgprintf("Done\n"); } bool Thread::tick() diff --git a/Kernel/VM/MemoryManager.cpp b/Kernel/VM/MemoryManager.cpp index 36fe7113b4..3c8827446d 100644 --- a/Kernel/VM/MemoryManager.cpp +++ b/Kernel/VM/MemoryManager.cpp @@ -570,7 +570,7 @@ bool MemoryManager::validate_range(const Process& process, VirtualAddress base_v VirtualAddress vaddr = base_vaddr.page_base(); VirtualAddress end_vaddr = base_vaddr.offset(size - 1).page_base(); if (end_vaddr < vaddr) { - dbg() << *current << " Shenanigans! Asked to validate " << base_vaddr << " size=" << size; + dbg() << "Shenanigans! Asked to validate " << base_vaddr << " size=" << size; return false; } const Region* region = nullptr; diff --git a/Kernel/VM/Region.cpp b/Kernel/VM/Region.cpp index 4ed61ac3f8..cd1de3c593 100644 --- a/Kernel/VM/Region.cpp +++ b/Kernel/VM/Region.cpp @@ -444,7 +444,7 @@ PageFaultResponse Region::handle_inode_fault(size_t page_index_in_region) cli(); #ifdef PAGE_FAULT_DEBUG - dbg() << *current << " inode fault in " << name() << " page index: " << page_index_in_region; + dbg() << "Inode fault in " << name() << " page index: " << page_index_in_region; #endif if (!vmobject_physical_page_entry.is_null()) {