From 7f5656445a8dfe5b3d268435f2a9829ce4788ec4 Mon Sep 17 00:00:00 2001 From: eupn Date: Tue, 14 Mar 2023 18:47:57 +0400 Subject: [PATCH] kernel: change some println!s to klog!s Even when the print-debug feature isn't turned on, println! macro is still able to output some critical non-debug info to the console such as panics, process crashes and violations, etc. Debugging messages are printed with klog! macro that's disabled when debug-print feature is not set. --- kernel/src/irq.rs | 3 ++- kernel/src/main.rs | 4 ++-- kernel/src/services.rs | 4 ++-- kernel/src/syscall.rs | 27 +++++++++++++-------------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/kernel/src/irq.rs b/kernel/src/irq.rs index 953579e6e..81fc8a103 100644 --- a/kernel/src/irq.rs +++ b/kernel/src/irq.rs @@ -22,7 +22,7 @@ pub fn handle(irqs_pending: usize) -> Result Result { #[cfg(feature = "debug-print")] - println!("NO RUNNABLE TASKS FOUND, entering idle state"); + klog!("NO RUNNABLE TASKS FOUND, entering idle state"); #[cfg(feature = "debug-print")] SystemServices::with(|system_services| { for (test_idx, process) in system_services.processes.iter().enumerate() { if !process.free() { - println!("PID {}: {:?}", test_idx + 1, process); + klog!("PID {}: {:?}", test_idx + 1, process); } } }); diff --git a/kernel/src/services.rs b/kernel/src/services.rs index c0c5a5395..df6f3a4c8 100644 --- a/kernel/src/services.rs +++ b/kernel/src/services.rs @@ -491,7 +491,7 @@ impl SystemServices { // PID0 doesn't exist -- process IDs are offset by 1. let pid_idx = pid.get() as usize - 1; if cfg!(baremetal) && self.processes[pid_idx].mapping.get_pid() != pid { - println!( + klog!( "Process doesn't match ({} vs {})", self.processes[pid_idx].mapping.get_pid(), pid @@ -1049,7 +1049,7 @@ impl SystemServices { // Ensure the new process can be run. match new.state { ProcessState::Free => { - println!("PID {} was free", new_pid); + klog!("PID {} was free", new_pid); return Err(xous_kernel::Error::ProcessNotFound); } ProcessState::Setup(_) | ProcessState::Allocated => new_tid = INITIAL_TID, diff --git a/kernel/src/syscall.rs b/kernel/src/syscall.rs index f9ceb73d2..541b5ba00 100644 --- a/kernel/src/syscall.rs +++ b/kernel/src/syscall.rs @@ -367,11 +367,11 @@ fn return_memory( }) } WaitingMessage::ScalarMessage(_pid, _tid) => { - println!("WARNING: Tried to wait on a message that was a scalar"); + klog!("WARNING: Tried to wait on a message that was a scalar"); return Err(xous_kernel::Error::DoubleFree); } WaitingMessage::None => { - println!("WARNING: Tried to wait on a message that didn't exist -- return memory"); + klog!("WARNING: Tried to wait on a message that didn't exist -- return memory"); return Err(xous_kernel::Error::DoubleFree); } }; @@ -463,25 +463,25 @@ fn return_result( let (client_pid, client_tid) = match result { WaitingMessage::ScalarMessage(pid, tid) => (pid, tid), WaitingMessage::ForgetMemory(_) => { - println!( + klog!( "WARNING: Tried to wait on a scalar message that was actually forgettingmemory" ); return Err(xous_kernel::Error::DoubleFree); } WaitingMessage::BorrowedMemory(_, _, _, _, _) => { - println!( + klog!( "WARNING: Tried to wait on a scalar message that was actually borrowed memory" ); return Err(xous_kernel::Error::DoubleFree); } WaitingMessage::MovedMemory => { - println!( + klog!( "WARNING: Tried to wait on a scalar message that was actually moved memory" ); return Err(xous_kernel::Error::DoubleFree); } WaitingMessage::None => { - println!("WARNING ({}:{}): Tried to wait on a message that didn't exist (irq? {}) -- return {:?}", server_pid.get(), server_tid, if in_irq { "yes"} else {"no"}, result); + klog!("WARNING ({}:{}): Tried to wait on a message that didn't exist (irq? {}) -- return {:?}", server_pid.get(), server_tid, if in_irq { "yes"} else {"no"}, result); return Err(xous_kernel::Error::DoubleFree); } }; @@ -581,7 +581,7 @@ fn reply_and_receive_next( MessageResponse { pid, tid, result } } WaitingMessage::ForgetMemory(_) => { - println!( + klog!( "WARNING: Tried to wait on a scalar message that was actually forgetting memory" ); return Err(xous_kernel::Error::DoubleFree); @@ -605,13 +605,13 @@ fn reply_and_receive_next( } } WaitingMessage::MovedMemory => { - println!( + klog!( "WARNING: Tried to wait on a scalar message that was actually moved memory" ); return Err(xous_kernel::Error::DoubleFree); } WaitingMessage::None => { - println!("WARNING: Tried to wait on a message that didn't exist -- receive and return scalar"); + klog!("WARNING: Tried to wait on a message that didn't exist -- receive and return scalar"); return Err(xous_kernel::Error::DoubleFree); } }; @@ -745,12 +745,12 @@ fn receive_message(pid: PID, tid: TID, sid: SID, blocking: ExecutionType) -> Sys } pub fn handle(pid: PID, tid: TID, in_irq: bool, call: SysCall) -> SysCallResult { - #[cfg(feature = "debug-print")] - print!("KERNEL({}:{}): Syscall {:x?}", pid, tid, call); + klog!("KERNEL({}:{}): Syscall {:x?}, in_irq={}", pid, tid, call, in_irq); // let call_string = format!("{:x?}", call); // let start_time = std::time::Instant::now(); #[allow(clippy::let_and_return)] let result = if in_irq && !call.can_call_from_interrupt() { + klog!("[!] Called {:?} that's cannot be called from the interrupt handler!", call); Err(xous_kernel::Error::InvalidSyscall) } else { handle_inner(pid, tid, in_irq, call) @@ -758,8 +758,7 @@ pub fn handle(pid: PID, tid: TID, in_irq: bool, call: SysCall) -> SysCallResult // println!("KERNEL [{:2}:{:2}] Syscall took {:7} usec: {}", pid, tid, start_time.elapsed().as_micros(), call_string); - #[cfg(feature = "debug-print")] - println!( + klog!( " -> ({}:{}) {:x?}", crate::arch::current_pid(), crate::arch::process::Process::current().current_tid(), @@ -785,7 +784,7 @@ pub fn handle_inner(pid: PID, tid: TID, in_irq: bool, call: SysCall) -> SysCallR .map(|x| x.get() >= arch::mem::USER_AREA_END) .unwrap_or(false) { - println!("Exceeded user area"); + klog!("Exceeded user area"); return Err(xous_kernel::Error::BadAddress); // Don't allow mapping non-page values