Browse Source

Everywhere: Replace a bundle of dbg with dbgln.

These changes are arbitrarily divided into multiple commits to make it
easier to find potentially introduced bugs with git bisect.
asynts 4 years ago
parent
commit
c6ebca5b45

+ 23 - 0
AK/Debug.h

@@ -178,3 +178,26 @@ constexpr bool debug_ipv4_socket = true;
 constexpr bool debug_ipv4_socket = false;
 #endif
 
+#ifdef DEBUG_LOCAL_SOCKET
+constexpr bool debug_local_socket = true;
+#else
+constexpr bool debug_local_socket = false;
+#endif
+
+#ifdef DEBUG_SOCKET
+constexpr bool debug_socket = true;
+#else
+constexpr bool debug_socket = false;
+#endif
+
+#ifdef TCP_SOCKET_DEBUG
+constexpr bool debug_tcp_socket = true;
+#else
+constexpr bool debug_tcp_socket = false;
+#endif
+
+#ifdef PCI_DEBUG
+constexpr bool debug_pci = true;
+#else
+constexpr bool debug_pci = false;
+#endif

+ 8 - 15
Kernel/Net/LocalSocket.cpp

@@ -24,6 +24,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <AK/Debug.h>
 #include <AK/Singleton.h>
 #include <AK/StringBuilder.h>
 #include <Kernel/FileSystem/FileDescription.h>
@@ -75,9 +76,7 @@ LocalSocket::LocalSocket(int type)
         evaluate_block_conditions();
     });
 
-#ifdef DEBUG_LOCAL_SOCKET
-    dbg() << "LocalSocket{" << this << "} created with type=" << type;
-#endif
+    dbgln<debug_local_socket>("LocalSocket({}) created with type={}", this, type);
 }
 
 LocalSocket::~LocalSocket()
@@ -113,9 +112,7 @@ KResult LocalSocket::bind(Userspace<const sockaddr*> user_address, socklen_t add
 
     auto path = String(address.sun_path, strnlen(address.sun_path, sizeof(address.sun_path)));
 
-#ifdef DEBUG_LOCAL_SOCKET
-    dbg() << "LocalSocket{" << this << "} bind(" << path << ")";
-#endif
+    dbgln<debug_local_socket>("LocalSocket({}) bind({})", this, path);
 
     mode_t mode = S_IFSOCK | (m_prebind_mode & 04777);
     UidAndGid owner { m_prebind_uid, m_prebind_gid };
@@ -159,9 +156,7 @@ KResult LocalSocket::connect(FileDescription& description, Userspace<const socka
         return EFAULT;
     safe_address[sizeof(safe_address) - 1] = '\0';
 
-#ifdef DEBUG_LOCAL_SOCKET
-    dbg() << "LocalSocket{" << this << "} connect(" << safe_address << ")";
-#endif
+    dbgln<debug_local_socket>("LocalSocket({}) connect({})", this, safe_address);
 
     auto description_or_error = VFS::the().open(safe_address, O_RDWR, 0, Process::current()->current_directory());
     if (description_or_error.is_error())
@@ -197,9 +192,7 @@ KResult LocalSocket::connect(FileDescription& description, Userspace<const socka
         return EINTR;
     }
 
-#ifdef DEBUG_LOCAL_SOCKET
-    dbg() << "LocalSocket{" << this << "} connect(" << safe_address << ") status is " << to_string(setup_state());
-#endif
+    dbgln<debug_local_socket>("LocalSocket({}) connect({}) status is {}", this, safe_address, to_string(setup_state()));
 
     if (!((u32)unblock_flags & (u32)Thread::FileDescriptionBlocker::BlockFlags::Connect)) {
         set_connect_side_role(Role::None);
@@ -218,9 +211,9 @@ KResult LocalSocket::listen(size_t backlog)
     auto previous_role = m_role;
     m_role = Role::Listener;
     set_connect_side_role(Role::Listener, previous_role != m_role);
-#ifdef DEBUG_LOCAL_SOCKET
-    dbg() << "LocalSocket{" << this << "} listening with backlog=" << backlog;
-#endif
+
+    dbgln<debug_local_socket>("LocalSocket({}) listening with backlog={}", this, backlog);
+
     return KSuccess;
 }
 

+ 4 - 10
Kernel/Net/Socket.cpp

@@ -24,6 +24,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <AK/Debug.h>
 #include <AK/StringBuilder.h>
 #include <AK/StringView.h>
 #include <Kernel/FileSystem/FileDescription.h>
@@ -65,10 +66,7 @@ Socket::~Socket()
 
 void Socket::set_setup_state(SetupState new_setup_state)
 {
-#ifdef SOCKET_DEBUG
-    dbg() << "Socket{" << this << "} setup state moving from " << to_string(m_setup_state) << " to " << to_string(new_setup_state);
-#endif
-
+    dbgln<debug_socket>("Socket({}) setup state moving from {} to {}", this, to_string(m_setup_state), to_string(new_setup_state));
     m_setup_state = new_setup_state;
     evaluate_block_conditions();
 }
@@ -78,9 +76,7 @@ RefPtr<Socket> Socket::accept()
     LOCKER(m_lock);
     if (m_pending.is_empty())
         return nullptr;
-#ifdef SOCKET_DEBUG
-    dbg() << "Socket{" << this << "} de-queueing connection";
-#endif
+    dbgln<debug_socket>("Socket({}) de-queueing connection", this);
     auto client = m_pending.take_first();
     ASSERT(!client->is_connected());
     auto& process = *Process::current();
@@ -94,9 +90,7 @@ RefPtr<Socket> Socket::accept()
 
 KResult Socket::queue_connection_from(NonnullRefPtr<Socket> peer)
 {
-#ifdef SOCKET_DEBUG
-    dbg() << "Socket{" << this << "} queueing connection";
-#endif
+    dbgln<debug_socket>("Socket({}) queueing connection", this);
     LOCKER(m_lock);
     if (m_pending.size() >= m_backlog)
         return ECONNREFUSED;

+ 6 - 15
Kernel/Net/TCPSocket.cpp

@@ -24,6 +24,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <AK/Debug.h>
 #include <AK/Singleton.h>
 #include <AK/Time.h>
 #include <Kernel/Devices/RandomDevice.h>
@@ -48,9 +49,7 @@ void TCPSocket::for_each(Function<void(const TCPSocket&)> callback)
 
 void TCPSocket::set_state(State new_state)
 {
-#ifdef TCP_SOCKET_DEBUG
-    dbg() << "TCPSocket{" << this << "} state moving from " << to_string(m_state) << " to " << to_string(new_state);
-#endif
+    dbgln<debug_tcp_socket>("TCPSocket({}) state moving from {} to {}", this, to_string(m_state), to_string(new_state));
 
     auto was_disconnected = protocol_is_disconnected();
     auto previous_role = m_role;
@@ -157,9 +156,7 @@ TCPSocket::~TCPSocket()
     LOCKER(sockets_by_tuple().lock());
     sockets_by_tuple().resource().remove(tuple());
 
-#ifdef TCP_SOCKET_DEBUG
-    dbg() << "~TCPSocket in state " << to_string(state());
-#endif
+    dbgln<debug_tcp_socket>("~TCPSocket in state {}", to_string(state()));
 }
 
 NonnullRefPtr<TCPSocket> TCPSocket::create(int protocol)
@@ -278,18 +275,14 @@ void TCPSocket::receive_tcp_packet(const TCPPacket& packet, u16 size)
     if (packet.has_ack()) {
         u32 ack_number = packet.ack_number();
 
-#ifdef TCP_SOCKET_DEBUG
-        dbg() << "TCPSocket: receive_tcp_packet: " << ack_number;
-#endif
+        dbgln<debug_tcp_socket>("TCPSocket: receive_tcp_packet: {}", ack_number);
 
         int removed = 0;
         LOCKER(m_not_acked_lock);
         while (!m_not_acked.is_empty()) {
             auto& packet = m_not_acked.first();
 
-#ifdef TCP_SOCKET_DEBUG
-            dbg() << "TCPSocket: iterate: " << packet.ack_number;
-#endif
+            dbgln<debug_tcp_socket>("TCPSocket: iterate: {}", packet.ack_number);
 
             if (packet.ack_number <= ack_number) {
                 m_not_acked.take_first();
@@ -299,9 +292,7 @@ void TCPSocket::receive_tcp_packet(const TCPPacket& packet, u16 size)
             }
         }
 
-#ifdef TCP_SOCKET_DEBUG
-        dbg() << "TCPSocket: receive_tcp_packet acknowledged " << removed << " packets";
-#endif
+        dbgln<debug_tcp_socket>("TCPSocket: receive_tcp_packet acknowledged {} packets", removed);
     }
 
     m_packets_in++;

+ 14 - 39
Kernel/PCI/Access.cpp

@@ -24,6 +24,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <AK/Debug.h>
 #include <Kernel/IO.h>
 #include <Kernel/PCI/Access.h>
 #include <Kernel/PCI/IOAccess.h>
@@ -75,44 +76,34 @@ PhysicalID Access::get_physical_id(Address address) const
 
 u8 Access::early_read8_field(Address address, u32 field)
 {
-#ifdef PCI_DEBUG
-    dbg() << "PCI: Early reading 8-bit field 0x" << String::formatted("{:08x}", field) << " for " << address;
-#endif
+    dbgln<debug_pci>("PCI: Early reading 8-bit field {:#08x} for {}", field, address);
     IO::out32(PCI_ADDRESS_PORT, address.io_address_for_field(field));
     return IO::in8(PCI_VALUE_PORT + (field & 3));
 }
 
 u16 Access::early_read16_field(Address address, u32 field)
 {
-#ifdef PCI_DEBUG
-    dbg() << "PCI: Early reading 16-bit field 0x" << String::formatted("{:08x}", field) << " for " << address;
-#endif
+    dbgln<debug_pci>("PCI: Early reading 16-bit field {:#08x} for {}", field, address);
     IO::out32(PCI_ADDRESS_PORT, address.io_address_for_field(field));
     return IO::in16(PCI_VALUE_PORT + (field & 2));
 }
 
 u32 Access::early_read32_field(Address address, u32 field)
 {
-#ifdef PCI_DEBUG
-    dbg() << "PCI: Early reading 32-bit field 0x" << String::formatted("{:08x}", field) << " for " << address;
-#endif
+    dbgln<debug_pci>("PCI: Early reading 32-bit field {:#08x} for {}", field, address);
     IO::out32(PCI_ADDRESS_PORT, address.io_address_for_field(field));
     return IO::in32(PCI_VALUE_PORT);
 }
 
 u16 Access::early_read_type(Address address)
 {
-#ifdef PCI_DEBUG
-    dbg() << "PCI: Early reading type for " << address;
-#endif
+    dbgln<debug_pci>("PCI: Early reading type for {}", address);
     return (early_read8_field(address, PCI_CLASS) << 8u) | early_read8_field(address, PCI_SUBCLASS);
 }
 
 void Access::enumerate_functions(int type, u8 bus, u8 slot, u8 function, Function<void(Address, ID)>& callback)
 {
-#ifdef PCI_DEBUG
-    dbg() << "PCI: Enumerating function type=" << type << ", bus=" << bus << ", slot=" << slot << ", function=" << function;
-#endif
+    dbgln<debug_pci>("PCI: Enumerating function type={}, bus={}, slot={}, function={}", type, bus, slot, function);
     Address address(0, bus, slot, function);
     if (type == -1 || type == early_read_type(address))
         callback(address, { early_read16_field(address, PCI_VENDOR_ID), early_read16_field(address, PCI_DEVICE_ID) });
@@ -128,9 +119,7 @@ void Access::enumerate_functions(int type, u8 bus, u8 slot, u8 function, Functio
 
 void Access::enumerate_slot(int type, u8 bus, u8 slot, Function<void(Address, ID)>& callback)
 {
-#ifdef PCI_DEBUG
-    dbg() << "PCI: Enumerating slot type=" << type << ", bus=" << bus << ", slot=" << slot;
-#endif
+    dbgln<debug_pci>("PCI: Enumerating slot type={}, bus={}, slot={}", type, bus, slot);
     Address address(0, bus, slot, 0);
     if (early_read16_field(address, PCI_VENDOR_ID) == PCI_NONE)
         return;
@@ -146,9 +135,7 @@ void Access::enumerate_slot(int type, u8 bus, u8 slot, Function<void(Address, ID
 
 void Access::enumerate_bus(int type, u8 bus, Function<void(Address, ID)>& callback)
 {
-#ifdef PCI_DEBUG
-    dbg() << "PCI: Enumerating bus type=" << type << ", bus=" << bus;
-#endif
+    dbgln<debug_pci>("PCI: Enumerating bus type={}, bus={}", type, bus);
     for (u8 slot = 0; slot < 32; ++slot)
         enumerate_slot(type, bus, slot, callback);
 }
@@ -167,18 +154,12 @@ void enumerate(Function<void(Address, ID)> callback)
 
 Optional<u8> get_capabilities_pointer(Address address)
 {
-#ifdef PCI_DEBUG
-    dbg() << "PCI: Getting capabilities pointer for " << address;
-#endif
+    dbgln<debug_pci>("PCI: Getting capabilities pointer for {}", address);
     if (PCI::read16(address, PCI_STATUS) & (1 << 4)) {
-#ifdef PCI_DEBUG
-        dbg() << "PCI: Found capabilities pointer for " << address;
-#endif
+        dbgln<debug_pci>("PCI: Found capabilities pointer for {}", address);
         return PCI::read8(address, PCI_CAPABILITIES_POINTER);
     }
-#ifdef PCI_DEBUG
-    dbg() << "PCI: No capabilities pointer for " << address;
-#endif
+    dbgln<debug_pci>("PCI: No capabilities pointer for {}", address);
     return {};
 }
 
@@ -189,22 +170,16 @@ PhysicalID get_physical_id(Address address)
 
 Vector<Capability> get_capabilities(Address address)
 {
-#ifdef PCI_DEBUG
-    dbg() << "PCI: Getting capabilities for " << address;
-#endif
+    dbgln<debug_pci>("PCI: Getting capabilities for {}", address);
     auto capabilities_pointer = PCI::get_capabilities_pointer(address);
     if (!capabilities_pointer.has_value()) {
-#ifdef PCI_DEBUG
-        dbg() << "PCI: No capabilities for " << address;
-#endif
+        dbgln<debug_pci>("PCI: No capabilities for {}", address);
         return {};
     }
     Vector<Capability> capabilities;
     auto capability_pointer = capabilities_pointer.value();
     while (capability_pointer != 0) {
-#ifdef PCI_DEBUG
-        dbg() << "PCI: Reading in capability at 0x" << String::formatted("{:02x}", capability_pointer) << " for " << address;
-#endif
+        dbgln<debug_pci>("PCI: Reading in capability at {:#02x} for {}", capability_pointer, address);
         u16 capability_header = PCI::read16(address, capability_pointer);
         u8 capability_id = capability_header & 0xff;
         capability_pointer = capability_header >> 8;

+ 4 - 4
Kernel/PCI/Definitions.h

@@ -26,6 +26,7 @@
 
 #pragma once
 
+#include <AK/Debug.h>
 #include <AK/Function.h>
 #include <AK/LogStream.h>
 #include <AK/String.h>
@@ -195,11 +196,10 @@ public:
         , m_id(id)
         , m_capabilities(capabilities)
     {
-#ifdef PCI_DEBUG
-        for (auto capability : capabilities) {
-            dbg() << address << " has capbility " << capability.m_id;
+        if constexpr (debug_pci) {
+            for (auto capability : capabilities)
+                dbgln("{} has capability {}", address, capability.m_id);
         }
-#endif
     }
 
     Vector<Capability> capabilities() const { return m_capabilities; }

+ 8 - 23
Kernel/PCI/IOAccess.cpp

@@ -24,11 +24,10 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <AK/Debug.h>
 #include <Kernel/IO.h>
 #include <Kernel/PCI/IOAccess.h>
 
-//#define PCI_DEBUG
-
 namespace Kernel {
 namespace PCI {
 
@@ -36,9 +35,7 @@ void IOAccess::initialize()
 {
     if (!Access::is_initialized()) {
         new IOAccess();
-#ifdef PCI_DEBUG
-        dbgln("PCI: IO access initialised.");
-#endif
+        dbgln<debug_pci>("PCI: IO access initialised.");
     }
 }
 
@@ -52,49 +49,37 @@ IOAccess::IOAccess()
 
 u8 IOAccess::read8_field(Address address, u32 field)
 {
-#ifdef PCI_DEBUG
-    dbg() << "PCI: IO Reading 8-bit field 0x" << String::formatted("{:08x}", field) << " for " << address;
-#endif
+    dbgln<debug_pci>("PCI: IO Reading 8-bit field {:#08x} for {}", field, address);
     return Access::early_read8_field(address, field);
 }
 
 u16 IOAccess::read16_field(Address address, u32 field)
 {
-#ifdef PCI_DEBUG
-    dbg() << "PCI: IO Reading 16-bit field 0x" << String::formatted("{:08x}", field) << " for " << address;
-#endif
+    dbgln<debug_pci>("PCI: IO Reading 16-bit field {:#08x} for {}", field, address);
     return Access::early_read16_field(address, field);
 }
 
 u32 IOAccess::read32_field(Address address, u32 field)
 {
-#ifdef PCI_DEBUG
-    dbg() << "PCI: IO Reading 32-bit field 0x" << String::formatted("{:08x}", field) << " for " << address;
-#endif
+    dbgln<debug_pci>("PCI: IO Reading 32-bit field {:#08x} for {}", field, address);
     return Access::early_read32_field(address, field);
 }
 
 void IOAccess::write8_field(Address address, u32 field, u8 value)
 {
-#ifdef PCI_DEBUG
-    dbg() << "PCI: IO Writing to 8-bit field 0x" << String::formatted("{:08x}", field) << ", value=0x" << String::formatted("{:02x}", value) << " for " << address;
-#endif
+    dbgln<debug_pci>("PCI: IO Writing to 8-bit field {:#08x}, value={:#02x} for {}", field, value, address);
     IO::out32(PCI_ADDRESS_PORT, address.io_address_for_field(field));
     IO::out8(PCI_VALUE_PORT + (field & 3), value);
 }
 void IOAccess::write16_field(Address address, u32 field, u16 value)
 {
-#ifdef PCI_DEBUG
-    dbg() << "PCI: IO Writing to 16-bit field 0x" << String::formatted("{:08x}", field) << ", value=0x" << String::formatted("{:04x}", value) << " for " << address;
-#endif
+    dbgln<debug_pci>("PCI: IO Writing to 16-bit field {:#08x}, value={:#02x} for {}", field, value, address);
     IO::out32(PCI_ADDRESS_PORT, address.io_address_for_field(field));
     IO::out16(PCI_VALUE_PORT + (field & 2), value);
 }
 void IOAccess::write32_field(Address address, u32 field, u32 value)
 {
-#ifdef PCI_DEBUG
-    dbg() << "PCI: IO Writing to 32-bit field 0x" << String::formatted("{:08x}", field) << ", value=0x" << String::formatted("{:08x}", value) << " for " << address;
-#endif
+    dbgln<debug_pci>("PCI: IO Writing to 32-bit field {:#08x}, value={:#02x} for {}", field, value, address);
     IO::out32(PCI_ADDRESS_PORT, address.io_address_for_field(field));
     IO::out32(PCI_VALUE_PORT, value);
 }

+ 1 - 0
Meta/CMake/all_the_debug_macros.cmake

@@ -167,6 +167,7 @@ add_compile_definitions("WAITQUEUE_DEBUG")
 add_compile_definitions("WEAKABLE_DEBUG")
 add_compile_definitions("WINDOWMANAGER_DEBUG")
 add_compile_definitions("WSMESSAGELOOP_DEBUG")
+add_compile_definitions("DEBUG_SOCKET")
 add_compile_definitions("WSSCREEN_DEBUG")
 # False positive: IF_BMP_DEBUG is not actually a flag.
 # add_compile_definitions("IF_BMP_DEBUG")