Kernel: Tidy up debug logging a little bit

When using dbg() in the kernel, the output is automatically prefixed
with [Process(PID:TID)]. This makes it a lot easier to understand which
thread is generating the output.

This patch also cleans up some common logging messages and removes the
now-unnecessary "dbg() << *current << ..." pattern.
This commit is contained in:
Andreas Kling 2020-01-21 16:14:39 +01:00
parent 5dd5d5ca4e
commit f38cfb3562
9 changed files with 41 additions and 38 deletions

View file

@ -24,10 +24,15 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/String.h>
#include <AK/LogStream.h>
#include <AK/String.h>
#include <AK/StringView.h>
#ifdef KERNEL
# include <Kernel/Process.h>
# include <Kernel/Thread.h>
#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;
}

View file

@ -123,9 +123,7 @@ KResultOr<Region*> 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;
}

View file

@ -62,9 +62,7 @@ KResultOr<Region*> 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;
}

View file

@ -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);
}
}

View file

@ -697,7 +697,7 @@ int Process::do_exec(NonnullRefPtr<FileDescription> 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;

View file

@ -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(); \

View file

@ -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()

View file

@ -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;

View file

@ -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()) {