1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-25 18:15:09 +00:00

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.
This commit is contained in:
asynts 2021-01-14 00:21:21 +01:00 committed by Andreas Kling
parent 67583bc424
commit dd727d1fec
4 changed files with 63 additions and 55 deletions

View file

@ -159,3 +159,22 @@ constexpr bool debug_irq = true;
#else #else
constexpr bool debug_irq = false; constexpr bool debug_irq = false;
#endif #endif
#ifdef INTERRUPT_DEBUG
constexpr bool debug_interrupt = true;
#else
constexpr bool debug_interrupt = false;
#endif
#ifdef E1000_DEBUG
constexpr bool debug_e1000 = true;
#else
constexpr bool debug_e1000 = false;
#endif
#ifdef IPV4_SOCKET_DEBUG
constexpr bool debug_ipv4_socket = true;
#else
constexpr bool debug_ipv4_socket = false;
#endif

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <AK/Debug.h>
#include <Kernel/Arch/i386/CPU.h> #include <Kernel/Arch/i386/CPU.h>
#include <Kernel/Assertions.h> #include <Kernel/Assertions.h>
#include <Kernel/Interrupts/IRQHandler.h> #include <Kernel/Interrupts/IRQHandler.h>
@ -59,9 +60,7 @@ void SharedIRQHandler::unregister_handler(GenericInterruptHandler& handler)
bool SharedIRQHandler::eoi() bool SharedIRQHandler::eoi()
{ {
#ifdef INTERRUPT_DEBUG dbgln<debug_interrupt>("EOI IRQ {}", interrupt_number());
dbg() << "EOI IRQ " << interrupt_number();
#endif
m_responsible_irq_controller->eoi(*this); m_responsible_irq_controller->eoi(*this);
return true; return true;
} }
@ -87,21 +86,19 @@ SharedIRQHandler::~SharedIRQHandler()
void SharedIRQHandler::handle_interrupt(const RegisterState& regs) void SharedIRQHandler::handle_interrupt(const RegisterState& regs)
{ {
ASSERT_INTERRUPTS_DISABLED(); ASSERT_INTERRUPTS_DISABLED();
#ifdef INTERRUPT_DEBUG
dbg() << "Interrupt @ " << interrupt_number(); if constexpr (debug_interrupt) {
dbg() << "Interrupt Handlers registered - " << m_handlers.size(); dbgln("Interrupt @ {}", interrupt_number());
#endif dbgln("Interrupt Handlers registered - {}", m_handlers.size());
}
int i = 0; int i = 0;
for (auto* handler : m_handlers) { for (auto* handler : m_handlers) {
#ifdef INTERRUPT_DEBUG dbgln<debug_interrupt>("Going for Interrupt Handling @ {}, Shared Interrupt {}", i, interrupt_number());
dbg() << "Going for Interrupt Handling @ " << i << ", Shared Interrupt " << interrupt_number();
#endif
ASSERT(handler != nullptr); ASSERT(handler != nullptr);
handler->increment_invoking_counter(); handler->increment_invoking_counter();
handler->handle_interrupt(regs); handler->handle_interrupt(regs);
#ifdef INTERRUPT_DEBUG dbgln<debug_interrupt>("Going for Interrupt Handling @ {}, Shared Interrupt {} - End", i, interrupt_number());
dbg() << "Going for Interrupt Handling @ " << i << ", Shared Interrupt " << interrupt_number() << " - End";
#endif
i++; i++;
} }
} }

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <AK/Debug.h>
#include <AK/MACAddress.h> #include <AK/MACAddress.h>
#include <Kernel/IO.h> #include <Kernel/IO.h>
#include <Kernel/Net/E1000NetworkAdapter.h> #include <Kernel/Net/E1000NetworkAdapter.h>
@ -363,9 +364,7 @@ void E1000NetworkAdapter::initialize_tx_descriptors()
void E1000NetworkAdapter::out8(u16 address, u8 data) void E1000NetworkAdapter::out8(u16 address, u8 data)
{ {
#ifdef E1000_DEBUG dbgln<debug_e1000>("E1000: OUT8 {:#02x} @ {:#04x}", data, address);
dbg() << "E1000: OUT8 0x" << String::format("%02x", data) << " @ 0x" << String::format("%04x", address);
#endif
if (m_use_mmio) { if (m_use_mmio) {
auto* ptr = (volatile u8*)(m_mmio_base.get() + address); auto* ptr = (volatile u8*)(m_mmio_base.get() + address);
*ptr = data; *ptr = data;
@ -376,9 +375,7 @@ void E1000NetworkAdapter::out8(u16 address, u8 data)
void E1000NetworkAdapter::out16(u16 address, u16 data) void E1000NetworkAdapter::out16(u16 address, u16 data)
{ {
#ifdef E1000_DEBUG dbgln<debug_e1000>("E1000: OUT16 {:#04x} @ {:#04x}", data, address);
dbg() << "E1000: OUT16 0x" << String::format("%04x", data) << " @ 0x" << String::format("%04x", address);
#endif
if (m_use_mmio) { if (m_use_mmio) {
auto* ptr = (volatile u16*)(m_mmio_base.get() + address); auto* ptr = (volatile u16*)(m_mmio_base.get() + address);
*ptr = data; *ptr = data;
@ -389,9 +386,7 @@ void E1000NetworkAdapter::out16(u16 address, u16 data)
void E1000NetworkAdapter::out32(u16 address, u32 data) void E1000NetworkAdapter::out32(u16 address, u32 data)
{ {
#ifdef E1000_DEBUG dbgln<debug_e1000>("E1000: OUT32 {:#08x} @ {:#04x}", data, address);
dbg() << "E1000: OUT32 0x" << String::format("%08x", data) << " @ 0x" << String::format("%04x", address);
#endif
if (m_use_mmio) { if (m_use_mmio) {
auto* ptr = (volatile u32*)(m_mmio_base.get() + address); auto* ptr = (volatile u32*)(m_mmio_base.get() + address);
*ptr = data; *ptr = data;
@ -402,9 +397,7 @@ void E1000NetworkAdapter::out32(u16 address, u32 data)
u8 E1000NetworkAdapter::in8(u16 address) u8 E1000NetworkAdapter::in8(u16 address)
{ {
#ifdef E1000_DEBUG dbgln<debug_e1000>("E1000: IN8 @ {:#04x}", address);
dbg() << "E1000: IN8 @ 0x" << String::format("%04x", address);
#endif
if (m_use_mmio) if (m_use_mmio)
return *(volatile u8*)(m_mmio_base.get() + address); return *(volatile u8*)(m_mmio_base.get() + address);
return m_io_base.offset(address).in<u8>(); return m_io_base.offset(address).in<u8>();
@ -412,9 +405,7 @@ u8 E1000NetworkAdapter::in8(u16 address)
u16 E1000NetworkAdapter::in16(u16 address) u16 E1000NetworkAdapter::in16(u16 address)
{ {
#ifdef E1000_DEBUG dbgln<debug_e1000>("E1000: IN16 @ {:#04x}", address);
dbg() << "E1000: IN16 @ 0x" << String::format("%04x", address);
#endif
if (m_use_mmio) if (m_use_mmio)
return *(volatile u16*)(m_mmio_base.get() + address); return *(volatile u16*)(m_mmio_base.get() + address);
return m_io_base.offset(address).in<u16>(); return m_io_base.offset(address).in<u16>();
@ -422,9 +413,7 @@ u16 E1000NetworkAdapter::in16(u16 address)
u32 E1000NetworkAdapter::in32(u16 address) u32 E1000NetworkAdapter::in32(u16 address)
{ {
#ifdef E1000_DEBUG dbgln<debug_e1000>("E1000: IN32 @ {:#04x}", address);
dbg() << "E1000: IN32 @ 0x" << String::format("%04x", address);
#endif
if (m_use_mmio) if (m_use_mmio)
return *(volatile u32*)(m_mmio_base.get() + address); return *(volatile u32*)(m_mmio_base.get() + address);
return m_io_base.offset(address).in<u32>(); return m_io_base.offset(address).in<u32>();

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <AK/Debug.h>
#include <AK/Singleton.h> #include <AK/Singleton.h>
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <Kernel/FileSystem/FileDescription.h> #include <Kernel/FileSystem/FileDescription.h>
@ -67,9 +68,7 @@ KResultOr<NonnullRefPtr<Socket>> IPv4Socket::create(int type, int protocol)
IPv4Socket::IPv4Socket(int type, int protocol) IPv4Socket::IPv4Socket(int type, int protocol)
: Socket(AF_INET, type, protocol) : Socket(AF_INET, type, protocol)
{ {
#ifdef IPV4_SOCKET_DEBUG dbgln<debug_ipv4_socket>("IPv4Socket({}) created with type={}, protocol={}", this, type, protocol);
dbg() << "IPv4Socket{" << this << "} created with type=" << type << ", protocol=" << protocol;
#endif
m_buffer_mode = type == SOCK_STREAM ? BufferMode::Bytes : BufferMode::Packets; m_buffer_mode = type == SOCK_STREAM ? BufferMode::Bytes : BufferMode::Packets;
if (m_buffer_mode == BufferMode::Bytes) { if (m_buffer_mode == BufferMode::Bytes) {
m_scratch_buffer = KBuffer::create_with_size(65536); m_scratch_buffer = KBuffer::create_with_size(65536);
@ -122,9 +121,7 @@ KResult IPv4Socket::bind(Userspace<const sockaddr*> user_address, socklen_t addr
m_local_address = IPv4Address((const u8*)&address.sin_addr.s_addr); m_local_address = IPv4Address((const u8*)&address.sin_addr.s_addr);
m_local_port = requested_local_port; m_local_port = requested_local_port;
#ifdef IPV4_SOCKET_DEBUG dbgln<debug_ipv4_socket>("IPv4Socket::bind {}({}) to {}:{}", class_name(), this, m_local_address, m_local_port);
dbg() << "IPv4Socket::bind " << class_name() << "{" << this << "} to " << m_local_address << ":" << m_local_port;
#endif
return protocol_bind(); return protocol_bind();
} }
@ -140,9 +137,7 @@ KResult IPv4Socket::listen(size_t backlog)
m_role = Role::Listener; m_role = Role::Listener;
evaluate_block_conditions(); evaluate_block_conditions();
#ifdef IPV4_SOCKET_DEBUG dbgln<debug_ipv4_socket>("IPv4Socket({}) listening with backlog={}", this, backlog);
dbg() << "IPv4Socket{" << this << "} listening with backlog=" << backlog;
#endif
return protocol_listen(); return protocol_listen();
} }
@ -293,9 +288,11 @@ KResultOr<size_t> IPv4Socket::receive_packet_buffered(FileDescription& descripti
if (!m_receive_queue.is_empty()) { if (!m_receive_queue.is_empty()) {
packet = m_receive_queue.take_first(); packet = m_receive_queue.take_first();
set_can_read(!m_receive_queue.is_empty()); set_can_read(!m_receive_queue.is_empty());
#ifdef IPV4_SOCKET_DEBUG
dbg() << "IPv4Socket(" << this << "): recvfrom without blocking " << packet.data.value().size() << " bytes, packets in queue: " << m_receive_queue.size(); dbgln<debug_ipv4_socket>("IPv4Socket({}): recvfrom without blocking {} bytes, packets in queue: {}",
#endif this,
packet.data.value().size(),
m_receive_queue.size());
} }
} }
if (!packet.data.has_value()) { if (!packet.data.has_value()) {
@ -320,18 +317,18 @@ KResultOr<size_t> IPv4Socket::receive_packet_buffered(FileDescription& descripti
ASSERT(!m_receive_queue.is_empty()); ASSERT(!m_receive_queue.is_empty());
packet = m_receive_queue.take_first(); packet = m_receive_queue.take_first();
set_can_read(!m_receive_queue.is_empty()); set_can_read(!m_receive_queue.is_empty());
#ifdef IPV4_SOCKET_DEBUG
dbg() << "IPv4Socket(" << this << "): recvfrom with blocking " << packet.data.value().size() << " bytes, packets in queue: " << m_receive_queue.size(); dbgln<debug_ipv4_socket>("IPv4Socket({}): recvfrom with blocking {} bytes, packets in queue: {}",
#endif this,
packet.data.value().size(),
m_receive_queue.size());
} }
ASSERT(packet.data.has_value()); ASSERT(packet.data.has_value());
packet_timestamp = packet.timestamp; packet_timestamp = packet.timestamp;
if (addr) { if (addr) {
#ifdef IPV4_SOCKET_DEBUG dbgln<debug_ipv4_socket>("Incoming packet is from: {}:{}", packet.peer_address, packet.peer_port);
dbg() << "Incoming packet is from: " << packet.peer_address << ":" << packet.peer_port;
#endif
sockaddr_in out_addr {}; sockaddr_in out_addr {};
memcpy(&out_addr.sin_addr, &packet.peer_address, sizeof(IPv4Address)); memcpy(&out_addr.sin_addr, &packet.peer_address, sizeof(IPv4Address));
@ -415,12 +412,18 @@ bool IPv4Socket::did_receive(const IPv4Address& source_address, u16 source_port,
set_can_read(true); set_can_read(true);
} }
m_bytes_received += packet_size; m_bytes_received += packet_size;
#ifdef IPV4_SOCKET_DEBUG
if constexpr (debug_ipv4_socket) {
if (buffer_mode() == BufferMode::Bytes) if (buffer_mode() == BufferMode::Bytes)
dbg() << "IPv4Socket(" << this << "): did_receive " << packet_size << " bytes, total_received=" << m_bytes_received; dbgln("IPv4Socket({}): did_receive {} bytes, total_received={}", this, packet_size, m_bytes_received);
else else
dbg() << "IPv4Socket(" << this << "): did_receive " << packet_size << " bytes, total_received=" << m_bytes_received << ", packets in queue: " << m_receive_queue.size(); dbgln("IPv4Socket({}): did_receive {} bytes, total_received={}, packets in queue: {}",
#endif this,
packet_size,
m_bytes_received,
m_receive_queue.size());
}
return true; return true;
} }