瀏覽代碼

AK: Remove custom %w format string specifier

This was a non-standard specifier alias for %04x. This patch replaces
all uses of it with new-style formatting functions instead.
Andreas Kling 4 年之前
父節點
當前提交
ed5c26d698

+ 0 - 5
AK/PrintfImplementation.h

@@ -386,10 +386,6 @@ struct PrintfImpl {
         m_putch(m_bufptr, '%');
         return 1;
     }
-    ALWAYS_INLINE int format_w(const ModifierState& state, ArgumentListRefT ap) const
-    {
-        return print_hex(m_putch, m_bufptr, NextArgument<int>()(ap), false, state.alternate_form, false, true, 4);
-    }
     ALWAYS_INLINE int format_c(const ModifierState& state, ArgumentListRefT ap) const
     {
         char c = NextArgument<int>()(ap);
@@ -511,7 +507,6 @@ ALWAYS_INLINE int printf_internal(PutChFunc putch, char* buffer, const char*& fm
                 PRINTF_IMPL_DELEGATE_TO_IMPL(q);
                 PRINTF_IMPL_DELEGATE_TO_IMPL(s);
                 PRINTF_IMPL_DELEGATE_TO_IMPL(u);
-                PRINTF_IMPL_DELEGATE_TO_IMPL(w);
                 PRINTF_IMPL_DELEGATE_TO_IMPL(x);
             default:
                 ret += impl.format_unrecognized(*p, fmt, state, ap);

+ 37 - 7
Kernel/Net/NetworkTask.cpp

@@ -123,7 +123,7 @@ void NetworkTask_main(void*)
         }
         auto& eth = *(const EthernetFrameHeader*)buffer;
 #ifdef ETHERNET_DEBUG
-        klog() << "NetworkTask: From " << eth.source().to_string().characters() << " to " << eth.destination().to_string().characters() << ", ether_type=" << String::format("%w", eth.ether_type()) << ", packet_length=" << packet_size;
+        dbgln("NetworkTask: From {} to {}, ether_type={:#04x}, packet_size={}", eth.source().to_string(), eth.destination().to_string(), eth.ether_type(), packet_size);
 #endif
 
 #ifdef ETHERNET_VERY_DEBUG
@@ -171,16 +171,21 @@ void handle_arp(const EthernetFrameHeader& eth, size_t frame_size)
     }
     auto& packet = *static_cast<const ARPPacket*>(eth.payload());
     if (packet.hardware_type() != 1 || packet.hardware_address_length() != sizeof(MACAddress)) {
-        klog() << "handle_arp: Hardware type not ethernet (" << String::format("%w", packet.hardware_type()) << ", len=" << packet.hardware_address_length() << ")";
+        dbgln("handle_arp: Hardware type not ethernet ({:#04x}, len={})", packet.hardware_type(), packet.hardware_address_length());
         return;
     }
     if (packet.protocol_type() != EtherType::IPv4 || packet.protocol_address_length() != sizeof(IPv4Address)) {
-        klog() << "handle_arp: Protocol type not IPv4 (" << String::format("%w", packet.hardware_type()) << ", len=" << packet.protocol_address_length() << ")";
+        dbgln("handle_arp: Protocol type not IPv4 ({:#04x}, len={})", packet.protocol_type(), packet.protocol_address_length());
         return;
     }
 
 #ifdef ARP_DEBUG
-    klog() << "handle_arp: operation=" << String::format("%w", packet.operation()) << ", sender=" << packet.sender_hardware_address().to_string().characters() << "/" << packet.sender_protocol_address().to_string().characters() << ", target=" << packet.target_hardware_address().to_string().characters() << "/" << packet.target_protocol_address().to_string().characters();
+    dbgln("handle_arp: operation={:#04x}, sender={}/{}, target={}/{}",
+        packet.operation(),
+        packet.sender_hardware_address().to_string(),
+        packet.sender_protocol_address().to_string(),
+        packet.target_hardware_address().to_string(),
+        packet.target_protocol_address().to_string());
 #endif
 
     if (!packet.sender_hardware_address().is_zero() && !packet.sender_protocol_address().is_zero()) {
@@ -341,7 +346,20 @@ void handle_tcp(const IPv4Packet& ipv4_packet, const timeval& packet_timestamp)
     size_t payload_size = ipv4_packet.payload_size() - tcp_packet.header_size();
 
 #ifdef TCP_DEBUG
-    klog() << "handle_tcp: source=" << ipv4_packet.source().to_string().characters() << ":" << tcp_packet.source_port() << ", destination=" << ipv4_packet.destination().to_string().characters() << ":" << tcp_packet.destination_port() << " seq_no=" << tcp_packet.sequence_number() << ", ack_no=" << tcp_packet.ack_number() << ", flags=" << String::format("%w", tcp_packet.flags()) << " (" << (tcp_packet.has_syn() ? "SYN " : "") << (tcp_packet.has_ack() ? "ACK " : "") << (tcp_packet.has_fin() ? "FIN " : "") << (tcp_packet.has_rst() ? "RST " : "") << "), window_size=" << tcp_packet.window_size() << ", payload_size=" << payload_size;
+    dbgln("handle_tcp: source={}:{}, destination={}:{}, seq_no={}, ack_no={}, flags={:#04x} ({}{}{}{}), window_size={}, payload_size={}",
+        ipv4_packet.source().to_string(),
+        tcp_packet.source_port(),
+        ipv4_packet.destination().to_string(),
+        tcp_packet.destination_port(),
+        tcp_packet.sequence_number(),
+        tcp_packet.ack_number(),
+        tcp_packet.flags(),
+        tcp_packet.has_syn() ? "SYN " : "",
+        tcp_packet.has_ack() ? "ACK " : "",
+        tcp_packet.has_fin() ? "FIN " : "",
+        tcp_packet.has_rst() ? "RST " : "",
+        tcp_packet.window_size(),
+        payload_size);
 #endif
 
     auto adapter = NetworkAdapter::from_ipv4_address(ipv4_packet.destination());
@@ -358,8 +376,20 @@ void handle_tcp(const IPv4Packet& ipv4_packet, const timeval& packet_timestamp)
 
     auto socket = TCPSocket::from_tuple(tuple);
     if (!socket) {
-        klog() << "handle_tcp: No TCP socket for tuple " << tuple.to_string().characters();
-        klog() << "handle_tcp: source=" << ipv4_packet.source().to_string().characters() << ":" << tcp_packet.source_port() << ", destination=" << ipv4_packet.destination().to_string().characters() << ":" << tcp_packet.destination_port() << " seq_no=" << tcp_packet.sequence_number() << ", ack_no=" << tcp_packet.ack_number() << ", flags=" << String::format("%w", tcp_packet.flags()) << " (" << (tcp_packet.has_syn() ? "SYN " : "") << (tcp_packet.has_ack() ? "ACK " : "") << (tcp_packet.has_fin() ? "FIN " : "") << (tcp_packet.has_rst() ? "RST " : "") << "), window_size=" << tcp_packet.window_size() << ", payload_size=" << payload_size;
+        dbgln("handle_tcp: No TCP socket for tuple {}", tuple.to_string());
+        dbgln("handle_tcp: source={}:{}, destination={}:{}, seq_no={}, ack_no={}, flags={:#04x} ({}{}{}{}), window_size={}, payload_size={}",
+            ipv4_packet.source().to_string(), tcp_packet.source_port(),
+            ipv4_packet.destination().to_string(),
+            tcp_packet.destination_port(),
+            tcp_packet.sequence_number(),
+            tcp_packet.ack_number(),
+            tcp_packet.flags(),
+            tcp_packet.has_syn() ? "SYN " : "",
+            tcp_packet.has_ack() ? "ACK " : "",
+            tcp_packet.has_fin() ? "FIN " : "",
+            tcp_packet.has_rst() ? "RST " : "",
+            tcp_packet.window_size(),
+            payload_size);
         return;
     }
 

+ 1 - 1
Kernel/PCI/Definitions.h

@@ -87,7 +87,7 @@ struct ID {
 };
 inline const LogStream& operator<<(const LogStream& stream, const ID value)
 {
-    return stream << "(" << String::format("%w", value.vendor_id) << ":" << String::format("%w", value.device_id) << ")";
+    return stream << String::formatted("({:04x}:{:04x})", value.vendor_id, value.device_id);
 }
 struct Address {
 public:

+ 4 - 4
Kernel/Scheduler.cpp

@@ -141,15 +141,15 @@ bool Scheduler::pick_next()
     dbg() << "Scheduler[" << Processor::current().id() << "]: Non-runnables:";
     Scheduler::for_each_nonrunnable([&](Thread& thread) -> IterationDecision {
         if (thread.state() == Thread::Dying)
-            dbg() << "  " << String::format("%-12s", thread.state_string()) << " " << thread << " @ " << String::format("%w", thread.tss().cs) << ":" << String::format("%x", thread.tss().eip) << " Finalizable: " << thread.is_finalizable();
+            dbg() << "  " << String::format("%-12s", thread.state_string()) << " " << thread << " @ " << String::formatted("{:04x}:{:08x}", thread.tss().cs, thread.tss().eip) << " Finalizable: " << thread.is_finalizable();
         else
-            dbg() << "  " << String::format("%-12s", thread.state_string()) << " " << thread << " @ " << String::format("%w", thread.tss().cs) << ":" << String::format("%x", thread.tss().eip);
+            dbg() << "  " << String::format("%-12s", thread.state_string()) << " " << thread << " @ " << String::formatted("{:04x}:{:08x}", thread.tss().cs, thread.tss().eip);
         return IterationDecision::Continue;
     });
 
     dbg() << "Scheduler[" << Processor::current().id() << "]: Runnables:";
     Scheduler::for_each_runnable([](Thread& thread) -> IterationDecision {
-        dbg() << "  " << String::format("%3u", thread.effective_priority()) << "/" << String::format("%2u", thread.priority()) << " " << String::format("%-12s", thread.state_string()) << " " << thread << " @ " << String::format("%w", thread.tss().cs) << ":" << String::format("%x", thread.tss().eip);
+        dbg() << "  " << String::format("%3u", thread.effective_priority()) << "/" << String::format("%2u", thread.priority()) << " " << String::format("%-12s", thread.state_string()) << " " << thread << " @ " << String::formatted("{:04x}:{:08x}", thread.tss().cs, thread.tss().eip);
         return IterationDecision::Continue;
     });
 #endif
@@ -331,7 +331,7 @@ bool Scheduler::context_switch(Thread* thread)
             from_thread->set_state(Thread::Runnable);
 
 #ifdef LOG_EVERY_CONTEXT_SWITCH
-        dbg() << "Scheduler[" << Processor::current().id() << "]: " << *from_thread << " -> " << *thread << " [" << thread->priority() << "] " << String::format("%w", thread->tss().cs) << ":" << String::format("%x", thread->tss().eip);
+        dbgln("Scheduler[{}]: {} -> {} [prio={}] {:04x}:{:08x}", Processor::current().id(), from_thread->tid().value(), thread->tid().value(), thread->priority(), thread->tss().cs, thread->tss().eip);
 #endif
     }
 

+ 1 - 1
Kernel/Syscalls/fork.cpp

@@ -77,7 +77,7 @@ pid_t Process::sys$fork(RegisterState& regs)
     child_tss.ss = regs.userspace_ss;
 
 #ifdef FORK_DEBUG
-    dbg() << "fork: child will begin executing at " << String::format("%w", child_tss.cs) << ":" << String::format("%x", child_tss.eip) << " with stack " << String::format("%w", child_tss.ss) << ":" << String::format("%x", child_tss.esp) << ", kstack " << String::format("%w", child_tss.ss0) << ":" << String::format("%x", child_tss.esp0);
+    dbgln("fork: child will begin executing at {:04x}:{:08x} with stack {:04x}:{:08x}, kstack {:04x}:{:08x}", child_tss.cs, child_tss.eip, child_tss.ss, child_tss.esp, child_tss.ss0, child_tss.esp0);
 #endif
 
     SharedBuffer::share_all_shared_buffers(*this, *child);

+ 1 - 1
Kernel/Thread.cpp

@@ -830,7 +830,7 @@ DispatchSignalResult Thread::dispatch_signal(u8 signal)
     regs.eip = g_return_to_ring3_from_signal_trampoline.get();
 
 #ifdef SIGNAL_DEBUG
-    klog() << "signal: Okay, " << *this << " {" << state_string() << "} has been primed with signal handler " << String::format("%w", m_tss.cs) << ":" << String::format("%x", m_tss.eip) << " to deliver " << signal;
+    dbgln("signal: Thread in state '{}' has been primed with signal handler {:04x}:{:08x} to deliver {}", state_string(), m_tss.cs, m_tss.eip, signal);
 #endif
     return DispatchSignalResult::Continue;
 }

+ 1 - 1
Kernel/VM/MemoryManager.cpp

@@ -374,7 +374,7 @@ PageFaultResponse MemoryManager::handle_page_fault(const PageFault& fault)
         return PageFaultResponse::ShouldCrash;
     }
 #ifdef PAGE_FAULT_DEBUG
-    dbg() << "MM: CPU[" << Processor::current().id() << "] handle_page_fault(" << String::format("%w", fault.code()) << ") at " << fault.vaddr();
+    dbgln("MM: CPU[{}] handle_page_fault({:#04x}) at {}", Processor::current().id(), fault.code(), fault.vaddr());
 #endif
     auto* region = find_region_from_vaddr(fault.vaddr());
     if (!region) {