Skip to content

Commit

Permalink
Everywhere: Replace a bundle of dbg with dbgln.
Browse files Browse the repository at this point in the history
These changes are arbitrarily divided into multiple commits to make it
easier to find potentially introduced bugs with git bisect.
  • Loading branch information
asynts authored and awesomekling committed Jan 22, 2021
1 parent dd727d1 commit c6ebca5
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 106 deletions.
23 changes: 23 additions & 0 deletions AK/Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 8 additions & 15 deletions Kernel/Net/LocalSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down
14 changes: 4 additions & 10 deletions Kernel/Net/Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
Expand All @@ -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;
Expand Down
21 changes: 6 additions & 15 deletions Kernel/Net/TCPSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand All @@ -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++;
Expand Down
53 changes: 14 additions & 39 deletions Kernel/PCI/Access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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) });
Expand All @@ -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;
Expand All @@ -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);
}
Expand All @@ -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 {};
}

Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions Kernel/PCI/Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#pragma once

#include <AK/Debug.h>
#include <AK/Function.h>
#include <AK/LogStream.h>
#include <AK/String.h>
Expand Down Expand Up @@ -195,11 +196,10 @@ class PhysicalID {
, 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; }
Expand Down
Loading

0 comments on commit c6ebca5

Please sign in to comment.