Skip to content

Commit

Permalink
Everywhere: Turn #if *_DEBUG into dbgln_if/if constexpr
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnarbeutner authored and awesomekling committed May 1, 2021
1 parent 4e6f03a commit 6cf59b6
Show file tree
Hide file tree
Showing 58 changed files with 316 additions and 470 deletions.
12 changes: 3 additions & 9 deletions Kernel/ACPI/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,26 +215,20 @@ void Parser::try_acpi_shutdown()
size_t Parser::get_table_size(PhysicalAddress table_header)
{
InterruptDisabler disabler;
#if ACPI_DEBUG
dbgln("ACPI: Checking SDT Length");
#endif
dbgln_if(ACPI_DEBUG, "ACPI: Checking SDT Length");
return map_typed<Structures::SDTHeader>(table_header)->length;
}

u8 Parser::get_table_revision(PhysicalAddress table_header)
{
InterruptDisabler disabler;
#if ACPI_DEBUG
dbgln("ACPI: Checking SDT Revision");
#endif
dbgln_if(ACPI_DEBUG, "ACPI: Checking SDT Revision");
return map_typed<Structures::SDTHeader>(table_header)->revision;
}

UNMAP_AFTER_INIT void Parser::initialize_main_system_description_table()
{
#if ACPI_DEBUG
dbgln("ACPI: Checking Main SDT Length to choose the correct mapping size");
#endif
dbgln_if(ACPI_DEBUG, "ACPI: Checking Main SDT Length to choose the correct mapping size");
VERIFY(!m_main_system_description_table.is_null());
auto length = get_table_size(m_main_system_description_table);
auto revision = get_table_revision(m_main_system_description_table);
Expand Down
4 changes: 1 addition & 3 deletions Kernel/Arch/i386/CPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,7 @@ void page_fault_handler(TrapFrame* trap)

handle_crash(regs, "Page Fault", SIGSEGV, response == PageFaultResponse::OutOfMemory);
} else if (response == PageFaultResponse::Continue) {
#if PAGE_FAULT_DEBUG
dbgln("Continuing after resolved page fault");
#endif
dbgln_if(PAGE_FAULT_DEBUG, "Continuing after resolved page fault");
} else {
VERIFY_NOT_REACHED();
}
Expand Down
6 changes: 2 additions & 4 deletions Kernel/Devices/HID/PS2MouseDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,8 @@ MousePacket PS2MouseDevice::parse_data_packet(const RawPacket& raw_packet)
}

packet.is_relative = true;
#if PS2MOUSE_DEBUG
dbgln("PS2 Relative Mouse: Buttons {:x}", packet.buttons);
dbgln("Mouse: X {}, Y {}, Z {}", packet.x, packet.y, packet.z);
#endif
dbgln_if(PS2MOUSE_DEBUG, "PS2 Relative Mouse: Buttons {:x}", packet.buttons);
dbgln_if(PS2MOUSE_DEBUG, "Mouse: X {}, Y {}, Z {}", packet.x, packet.y, packet.z);
return packet;
}

Expand Down
13 changes: 6 additions & 7 deletions Kernel/Devices/USB/UHCIController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,8 @@ UNMAP_AFTER_INIT void UHCIController::create_structures()
transfer_descriptor->set_isochronous();
transfer_descriptor->link_queue_head(m_interrupt_transfer_queue->paddr());

#if UHCI_VERBOSE_DEBUG
transfer_descriptor->print();
#endif
if constexpr (UHCI_VERBOSE_DEBUG)
transfer_descriptor->print();
}

m_free_td_pool.resize(MAXIMUM_NUMBER_OF_TDS);
Expand All @@ -192,10 +191,10 @@ UNMAP_AFTER_INIT void UHCIController::create_structures()
// access the raw descriptor (that we later send to the controller)
m_free_td_pool.at(i) = new (placement_addr) Kernel::USB::TransferDescriptor(paddr);

#if UHCI_VERBOSE_DEBUG
auto transfer_descriptor = m_free_td_pool.at(i);
transfer_descriptor->print();
#endif
if constexpr (UHCI_VERBOSE_DEBUG) {
auto transfer_descriptor = m_free_td_pool.at(i);
transfer_descriptor->print();
}
}

if constexpr (UHCI_DEBUG) {
Expand Down
8 changes: 2 additions & 6 deletions Kernel/Net/TCPSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,7 @@ bool TCPSocket::protocol_is_disconnected() const
void TCPSocket::shut_down_for_writing()
{
if (state() == State::Established) {
#if TCP_SOCKET_DEBUG
dbgln(" Sending FIN/ACK from Established and moving into FinWait1");
#endif
dbgln_if(TCP_SOCKET_DEBUG, " Sending FIN/ACK from Established and moving into FinWait1");
[[maybe_unused]] auto rc = send_tcp_packet(TCPFlags::FIN | TCPFlags::ACK);
set_state(State::FinWait1);
} else {
Expand All @@ -468,9 +466,7 @@ KResult TCPSocket::close()
Locker socket_locker(lock());
auto result = IPv4Socket::close();
if (state() == State::CloseWait) {
#if TCP_SOCKET_DEBUG
dbgln(" Sending FIN from CloseWait and moving into LastAck");
#endif
dbgln_if(TCP_SOCKET_DEBUG, " Sending FIN from CloseWait and moving into LastAck");
[[maybe_unused]] auto rc = send_tcp_packet(TCPFlags::FIN | TCPFlags::ACK);
set_state(State::LastAck);
}
Expand Down
4 changes: 1 addition & 3 deletions Kernel/PCI/IOAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ void IOAccess::write32_field(Address address, u32 field, u32 value)

void IOAccess::enumerate_hardware(Function<void(Address, ID)> callback)
{
#if PCI_DEBUG
dbgln("PCI: IO enumerating hardware");
#endif
dbgln_if(PCI_DEBUG, "PCI: IO enumerating hardware");
// Single PCI host controller.
if ((read8_field(Address(), PCI_HEADER_TYPE) & 0x80) == 0) {
enumerate_bus(-1, 0, callback, true);
Expand Down
12 changes: 3 additions & 9 deletions Kernel/VM/AnonymousVMObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,7 @@ PageFaultResponse AnonymousVMObject::handle_cow_fault(size_t page_index, Virtual
auto& page_slot = physical_pages()[page_index];
bool have_committed = m_shared_committed_cow_pages && is_nonvolatile(page_index);
if (page_slot->ref_count() == 1) {
#if PAGE_FAULT_DEBUG
dbgln(" >> It's a COW page but nobody is sharing it anymore. Remap r/w");
#endif
dbgln_if(PAGE_FAULT_DEBUG, " >> It's a COW page but nobody is sharing it anymore. Remap r/w");
set_should_cow(page_index, false);
if (have_committed) {
if (m_shared_committed_cow_pages->return_one())
Expand All @@ -456,14 +454,10 @@ PageFaultResponse AnonymousVMObject::handle_cow_fault(size_t page_index, Virtual

RefPtr<PhysicalPage> page;
if (have_committed) {
#if PAGE_FAULT_DEBUG
dbgln(" >> It's a committed COW page and it's time to COW!");
#endif
dbgln_if(PAGE_FAULT_DEBUG, " >> It's a committed COW page and it's time to COW!");
page = m_shared_committed_cow_pages->allocate_one();
} else {
#if PAGE_FAULT_DEBUG
dbgln(" >> It's a COW page and it's time to COW!");
#endif
dbgln_if(PAGE_FAULT_DEBUG, " >> It's a COW page and it's time to COW!");
page = MM.allocate_user_physical_page(MemoryManager::ShouldZeroFill::No);
if (page.is_null()) {
dmesgln("MM: handle_cow_fault was unable to allocate a physical page");
Expand Down
4 changes: 1 addition & 3 deletions Kernel/VM/Region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,7 @@ PageFaultResponse Region::handle_zero_fault(size_t page_index_in_region)
auto page_index_in_vmobject = translate_to_vmobject_page(page_index_in_region);

if (!page_slot.is_null() && !page_slot->is_shared_zero_page() && !page_slot->is_lazy_committed_page()) {
#if PAGE_FAULT_DEBUG
dbgln("MM: zero_page() but page already present. Fine with me!");
#endif
dbgln_if(PAGE_FAULT_DEBUG, "MM: zero_page() but page already present. Fine with me!");
if (!remap_vmobject_page(page_index_in_vmobject))
return PageFaultResponse::OutOfMemory;
return PageFaultResponse::Continue;
Expand Down
24 changes: 11 additions & 13 deletions Userland/Applications/IRCClient/IRCClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,16 +233,16 @@ void IRCClient::send_whois(const String& nick)

void IRCClient::handle(const Message& msg)
{
#if IRC_DEBUG
outln("IRCClient::execute: prefix='{}', command='{}', arguments={}",
msg.prefix,
msg.command,
msg.arguments.size());

size_t index = 0;
for (auto& arg : msg.arguments)
outln(" [{}]: {}", index++, arg);
#endif
if constexpr (IRC_DEBUG) {
outln("IRCClient::execute: prefix='{}', command='{}', arguments={}",
msg.prefix,
msg.command,
msg.arguments.size());

size_t index = 0;
for (auto& arg : msg.arguments)
outln(" [{}]: {}", index++, arg);
}

auto numeric = msg.command.to_uint();

Expand Down Expand Up @@ -464,13 +464,11 @@ void IRCClient::handle_privmsg_or_notice(const Message& msg, PrivmsgOrNotice typ

bool is_ctcp = has_ctcp_payload(msg.arguments[1]);

#if IRC_DEBUG
outln("handle_privmsg_or_notice: type='{}'{}, sender_nick='{}', target='{}'",
outln_if(IRC_DEBUG, "handle_privmsg_or_notice: type='{}'{}, sender_nick='{}', target='{}'",
type == PrivmsgOrNotice::Privmsg ? "privmsg" : "notice",
is_ctcp ? " (ctcp)" : "",
sender_nick,
target);
#endif

if (sender_nick.is_empty())
return;
Expand Down
16 changes: 4 additions & 12 deletions Userland/DevTools/HackStudio/CursorTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ namespace HackStudio {

void CursorTool::on_mousedown(GUI::MouseEvent& event)
{
#if CURSOR_TOOL_DEBUG
dbgln("CursorTool::on_mousedown");
#endif
dbgln_if(CURSOR_TOOL_DEBUG, "CursorTool::on_mousedown");
auto& form_widget = m_editor.form_widget();
auto result = form_widget.hit_test(event.position(), GUI::Widget::ShouldRespectGreediness::No);

Expand Down Expand Up @@ -52,9 +50,7 @@ void CursorTool::on_mousedown(GUI::MouseEvent& event)

void CursorTool::on_mouseup(GUI::MouseEvent& event)
{
#if CURSOR_TOOL_DEBUG
dbgln("CursorTool::on_mouseup");
#endif
dbgln_if(CURSOR_TOOL_DEBUG, "CursorTool::on_mouseup");
if (event.button() == GUI::MouseButton::Left) {
auto& form_widget = m_editor.form_widget();
auto result = form_widget.hit_test(event.position(), GUI::Widget::ShouldRespectGreediness::No);
Expand All @@ -73,9 +69,7 @@ void CursorTool::on_mouseup(GUI::MouseEvent& event)

void CursorTool::on_mousemove(GUI::MouseEvent& event)
{
#if CURSOR_TOOL_DEBUG
dbgln("CursorTool::on_mousemove");
#endif
dbgln_if(CURSOR_TOOL_DEBUG, "CursorTool::on_mousemove");
auto& form_widget = m_editor.form_widget();

if (m_rubber_banding) {
Expand Down Expand Up @@ -112,9 +106,7 @@ void CursorTool::on_mousemove(GUI::MouseEvent& event)

void CursorTool::on_keydown(GUI::KeyEvent& event)
{
#if CURSOR_TOOL_DEBUG
dbgln("CursorTool::on_keydown");
#endif
dbgln_if(CURSOR_TOOL_DEBUG, "CursorTool::on_keydown");

auto move_selected_widgets_by = [this](int x, int y) {
m_editor.selection().for_each([&](auto& widget) {
Expand Down
8 changes: 4 additions & 4 deletions Userland/DevTools/HackStudio/Git/DiffViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ void DiffViewer::set_content(const String& original, const String& diff)
m_original_lines = split_to_lines(original);
m_hunks = Diff::parse_hunks(diff);

#if DIFF_DEBUG
for (size_t i = 0; i < m_original_lines.size(); ++i)
dbgln("{}:{}", i, m_original_lines[i]);
#endif
if constexpr (DIFF_DEBUG) {
for (size_t i = 0; i < m_original_lines.size(); ++i)
dbgln("{}:{}", i, m_original_lines[i]);
}
}

DiffViewer::DiffViewer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ Vector<GUI::AutocompleteProvider::Entry> LexerAutoComplete::get_suggestions(cons

auto suggestions = identifier_prefixes(lines, tokens, index_of_target_token.value());

#if AUTOCOMPLETE_DEBUG
for (auto& suggestion : suggestions) {
dbgln("suggestion: {}", suggestion.completion);
if constexpr (AUTOCOMPLETE_DEBUG) {
for (auto& suggestion : suggestions) {
dbgln("suggestion: {}", suggestion.completion);
}
}
#endif

return suggestions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ OwnPtr<ParserAutoComplete::DocumentData> ParserAutoComplete::create_document_dat
for (auto& path : document_data->preprocessor().included_paths()) {
get_or_create_document_data(document_path_from_include_path(path));
}
#ifdef CPP_LANGUAGE_SERVER_DEBUG
root->dump(0);
#endif
if constexpr (CPP_LANGUAGE_SERVER_DEBUG)
root->dump(0);

update_declared_symbols(*document_data);

Expand Down
44 changes: 24 additions & 20 deletions Userland/DevTools/IPCCompiler/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#include <ctype.h>
#include <stdio.h>

#ifndef GENERATE_DEBUG_CODE
# define GENERATE_DEBUG_CODE 0
#endif

struct Parameter {
Vector<String> attributes;
String type;
Expand Down Expand Up @@ -444,22 +448,22 @@ class @endpoint.name@Endpoint : public IPC::Endpoint {
stream >> message_endpoint_magic;
if (stream.handle_any_error()) {
)~~~");
#if GENERATE_DEBUG_CODE
endpoint_generator.append(R"~~~(
dbgln("Failed to read message endpoint magic");
if constexpr (GENERATE_DEBUG_CODE) {
endpoint_generator.append(R"~~~(
dbgln("Failed to read message endpoint magic");
)~~~");
#endif
}
endpoint_generator.append(R"~~~(
return {};
}
if (message_endpoint_magic != @endpoint.magic@) {
)~~~");
#if GENERATE_DEBUG_CODE
endpoint_generator.append(R"~~~(
dbgln("@endpoint.name@: Endpoint magic number message_endpoint_magic != @endpoint.magic@, not my message! (the other endpoint may have handled it)");
if constexpr (GENERATE_DEBUG_CODE) {
endpoint_generator.append(R"~~~(
dbgln("@endpoint.name@: Endpoint magic number message_endpoint_magic != @endpoint.magic@, not my message! (the other endpoint may have handled it)");
)~~~");
#endif
}
endpoint_generator.append(R"~~~(
return {};
}
Expand All @@ -468,11 +472,11 @@ class @endpoint.name@Endpoint : public IPC::Endpoint {
stream >> message_id;
if (stream.handle_any_error()) {
)~~~");
#if GENERATE_DEBUG_CODE
endpoint_generator.append(R"~~~(
dbgln("Failed to read message ID");
if constexpr (GENERATE_DEBUG_CODE) {
endpoint_generator.append(R"~~~(
dbgln("Failed to read message ID");
)~~~");
#endif
}
endpoint_generator.append(R"~~~(
return {};
}
Expand Down Expand Up @@ -502,22 +506,22 @@ class @endpoint.name@Endpoint : public IPC::Endpoint {
endpoint_generator.append(R"~~~(
default:
)~~~");
#if GENERATE_DEBUG_CODE
endpoint_generator.append(R"~~~(
dbgln("Failed to decode @endpoint.name@.({})", message_id);
if constexpr (GENERATE_DEBUG_CODE) {
endpoint_generator.append(R"~~~(
dbgln("Failed to decode @endpoint.name@.({})", message_id);
)~~~");
#endif
}
endpoint_generator.append(R"~~~(
return {};
}
if (stream.handle_any_error()) {
)~~~");
#if GENERATE_DEBUG_CODE
endpoint_generator.append(R"~~~(
dbgln("Failed to read the message");
if constexpr (GENERATE_DEBUG_CODE) {
endpoint_generator.append(R"~~~(
dbgln("Failed to read the message");
)~~~");
#endif
}
endpoint_generator.append(R"~~~(
return {};
}
Expand Down
5 changes: 2 additions & 3 deletions Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ namespace UserspaceEmulator {

u32 Emulator::virt_syscall(u32 function, u32 arg1, u32 arg2, u32 arg3)
{
#if SPAM_DEBUG
reportln("Syscall: {} ({:x})", Syscall::to_string((Syscall::Function)function), function);
#endif
if constexpr (SPAM_DEBUG)
reportln("Syscall: {} ({:x})", Syscall::to_string((Syscall::Function)function), function);
switch (function) {
case SC_chdir:
return virt$chdir(arg1, arg2);
Expand Down
Loading

0 comments on commit 6cf59b6

Please sign in to comment.