diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-05-01 21:10:08 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-01 21:25:06 +0200 |
commit | 6cf59b6ae96aeeb8c0da957a07f913c4fa38467f (patch) | |
tree | b3f1691b59c3280993d4a8c2866f821ae15c1875 | |
parent | 4e6f03a860595f9eb2628e12ddbd333e26b0622f (diff) | |
download | serenity-6cf59b6ae96aeeb8c0da957a07f913c4fa38467f.zip |
Everywhere: Turn #if *_DEBUG into dbgln_if/if constexpr
58 files changed, 316 insertions, 470 deletions
diff --git a/Kernel/ACPI/Parser.cpp b/Kernel/ACPI/Parser.cpp index 31493b2143..6053971383 100644 --- a/Kernel/ACPI/Parser.cpp +++ b/Kernel/ACPI/Parser.cpp @@ -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); diff --git a/Kernel/Arch/i386/CPU.cpp b/Kernel/Arch/i386/CPU.cpp index 6b54076dab..0a302b750e 100644 --- a/Kernel/Arch/i386/CPU.cpp +++ b/Kernel/Arch/i386/CPU.cpp @@ -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(); } diff --git a/Kernel/Devices/HID/PS2MouseDevice.cpp b/Kernel/Devices/HID/PS2MouseDevice.cpp index f4947ea209..48bfcdcfd4 100644 --- a/Kernel/Devices/HID/PS2MouseDevice.cpp +++ b/Kernel/Devices/HID/PS2MouseDevice.cpp @@ -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; } diff --git a/Kernel/Devices/USB/UHCIController.cpp b/Kernel/Devices/USB/UHCIController.cpp index ccaeb14cdf..bcbed565b7 100644 --- a/Kernel/Devices/USB/UHCIController.cpp +++ b/Kernel/Devices/USB/UHCIController.cpp @@ -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); @@ -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) { diff --git a/Kernel/Net/TCPSocket.cpp b/Kernel/Net/TCPSocket.cpp index 1964da40d3..251bbb1f5d 100644 --- a/Kernel/Net/TCPSocket.cpp +++ b/Kernel/Net/TCPSocket.cpp @@ -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 { @@ -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); } diff --git a/Kernel/PCI/IOAccess.cpp b/Kernel/PCI/IOAccess.cpp index d4794c52ce..d2fc93defb 100644 --- a/Kernel/PCI/IOAccess.cpp +++ b/Kernel/PCI/IOAccess.cpp @@ -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); diff --git a/Kernel/VM/AnonymousVMObject.cpp b/Kernel/VM/AnonymousVMObject.cpp index fec628414f..ffb494caa8 100644 --- a/Kernel/VM/AnonymousVMObject.cpp +++ b/Kernel/VM/AnonymousVMObject.cpp @@ -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()) @@ -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"); diff --git a/Kernel/VM/Region.cpp b/Kernel/VM/Region.cpp index 84be9f285d..53e3c6b2bd 100644 --- a/Kernel/VM/Region.cpp +++ b/Kernel/VM/Region.cpp @@ -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; diff --git a/Userland/Applications/IRCClient/IRCClient.cpp b/Userland/Applications/IRCClient/IRCClient.cpp index c71b508521..1413fb071b 100644 --- a/Userland/Applications/IRCClient/IRCClient.cpp +++ b/Userland/Applications/IRCClient/IRCClient.cpp @@ -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(); @@ -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; diff --git a/Userland/DevTools/HackStudio/CursorTool.cpp b/Userland/DevTools/HackStudio/CursorTool.cpp index e441660897..bf3b793617 100644 --- a/Userland/DevTools/HackStudio/CursorTool.cpp +++ b/Userland/DevTools/HackStudio/CursorTool.cpp @@ -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); @@ -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); @@ -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) { @@ -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) { diff --git a/Userland/DevTools/HackStudio/Git/DiffViewer.cpp b/Userland/DevTools/HackStudio/Git/DiffViewer.cpp index ef8af25587..139478c77b 100644 --- a/Userland/DevTools/HackStudio/Git/DiffViewer.cpp +++ b/Userland/DevTools/HackStudio/Git/DiffViewer.cpp @@ -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() diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/LexerAutoComplete.cpp b/Userland/DevTools/HackStudio/LanguageServers/Cpp/LexerAutoComplete.cpp index 2c0052e7d4..3980f91002 100644 --- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/LexerAutoComplete.cpp +++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/LexerAutoComplete.cpp @@ -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; } diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.cpp b/Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.cpp index cb5957e121..2aedb992a1 100644 --- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.cpp +++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.cpp @@ -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); diff --git a/Userland/DevTools/IPCCompiler/main.cpp b/Userland/DevTools/IPCCompiler/main.cpp index 869f1f48d0..2ce941c425 100644 --- a/Userland/DevTools/IPCCompiler/main.cpp +++ b/Userland/DevTools/IPCCompiler/main.cpp @@ -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; @@ -444,22 +448,22 @@ public: 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 {}; } @@ -468,11 +472,11 @@ public: 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 {}; } @@ -502,22 +506,22 @@ public: 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 {}; } diff --git a/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp b/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp index 6413941d72..090533b937 100644 --- a/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp +++ b/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp @@ -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); diff --git a/Userland/DevTools/UserspaceEmulator/MallocTracer.cpp b/Userland/DevTools/UserspaceEmulator/MallocTracer.cpp index 483dc282a9..4f00c21c52 100644 --- a/Userland/DevTools/UserspaceEmulator/MallocTracer.cpp +++ b/Userland/DevTools/UserspaceEmulator/MallocTracer.cpp @@ -310,9 +310,8 @@ void MallocTracer::populate_memory_graph() auto value = m_emulator.mmu().read32({ 0x23, mallocation.address + i * sizeof(u32) }); auto other_address = value.value(); if (!value.is_uninitialized() && m_memory_graph.contains(value.value())) { -#if REACHABLE_DEBUG - reportln("region/mallocation {:p} is reachable from other mallocation {:p}", other_address, mallocation.address); -#endif + if constexpr (REACHABLE_DEBUG) + reportln("region/mallocation {:p} is reachable from other mallocation {:p}", other_address, mallocation.address); edges_from_mallocation.edges_from_node.append(other_address); } } @@ -339,9 +338,8 @@ void MallocTracer::populate_memory_graph() auto value = region.read32(i * sizeof(u32)); auto other_address = value.value(); if (!value.is_uninitialized() && m_memory_graph.contains(value.value())) { -#if REACHABLE_DEBUG - reportln("region/mallocation {:p} is reachable from region {:p}-{:p}", other_address, region.base(), region.end() - 1); -#endif + if constexpr (REACHABLE_DEBUG) + reportln("region/mallocation {:p} is reachable from region {:p}-{:p}", other_address, region.base(), region.end() - 1); m_memory_graph.find(other_address)->value.is_reachable = true; reachable_mallocations.append(other_address); } @@ -388,9 +386,8 @@ void MallocTracer::dump_leak_report() populate_memory_graph(); -#if REACHABLE_DEBUG - dump_memory_graph(); -#endif + if constexpr (REACHABLE_DEBUG) + dump_memory_graph(); for_each_mallocation([&](auto& mallocation) { if (mallocation.freed) diff --git a/Userland/DevTools/UserspaceEmulator/SoftCPU.cpp b/Userland/DevTools/UserspaceEmulator/SoftCPU.cpp index f6fcdab9e2..69208e9e20 100644 --- a/Userland/DevTools/UserspaceEmulator/SoftCPU.cpp +++ b/Userland/DevTools/UserspaceEmulator/SoftCPU.cpp @@ -138,18 +138,14 @@ ValueWithShadow<u128> SoftCPU::read_memory128(X86::LogicalAddress address) { VERIFY(address.selector() == 0x1b || address.selector() == 0x23 || address.selector() == 0x2b); auto value = m_emulator.mmu().read128(address); -#if MEMORY_DEBUG - outln("\033[36;1mread_memory128: @{:04x}:{:08x} -> {:032x} ({:032x})\033[0m", address.selector(), address.offset(), value, value.shadow()); -#endif + outln_if(MEMORY_DEBUG, "\033[36;1mread_memory128: @{:04x}:{:08x} -> {:032x} ({:032x})\033[0m", address.selector(), address.offset(), value, value.shadow()); return value; } ValueWithShadow<u256> SoftCPU::read_memory256(X86::LogicalAddress address) { VERIFY(address.selector() == 0x1b || address.selector() == 0x23 || address.selector() == 0x2b); auto value = m_emulator.mmu().read256(address); -#if MEMORY_DEBUG - outln("\033[36;1mread_memory256: @{:04x}:{:08x} -> {:064x} ({:064x})\033[0m", address.selector(), address.offset(), value, value.shadow()); -#endif + outln_if(MEMORY_DEBUG, "\033[36;1mread_memory256: @{:04x}:{:08x} -> {:064x} ({:064x})\033[0m", address.selector(), address.offset(), value, value.shadow()); return value; } @@ -184,18 +180,14 @@ void SoftCPU::write_memory64(X86::LogicalAddress address, ValueWithShadow<u64> v void SoftCPU::write_memory128(X86::LogicalAddress address, ValueWithShadow<u128> value) { VERIFY(address.selector() == 0x23 || address.selector() == 0x2b); -#if MEMORY_DEBUG - outln("\033[36;1mwrite_memory128: @{:04x}:{:08x} <- {:032x} ({:032x})\033[0m", address.selector(), address.offset(), value, value.shadow()); -#endif + outln_if(MEMORY_DEBUG, "\033[36;1mwrite_memory128: @{:04x}:{:08x} <- {:032x} ({:032x})\033[0m", address.selector(), address.offset(), value, value.shadow()); m_emulator.mmu().write128(address, value); } void SoftCPU::write_memory256(X86::LogicalAddress address, ValueWithShadow<u256> value) { VERIFY(address.selector() == 0x23 || address.selector() == 0x2b); -#if MEMORY_DEBUG - outln("\033[36;1mwrite_memory256: @{:04x}:{:08x} <- {:064x} ({:064x})\033[0m", address.selector(), address.offset(), value, value.shadow()); -#endif + outln_if(MEMORY_DEBUG, "\033[36;1mwrite_memory256: @{:04x}:{:08x} <- {:064x} ({:064x})\033[0m", address.selector(), address.offset(), value, value.shadow()); m_emulator.mmu().write256(address, value); } diff --git a/Userland/Libraries/LibAudio/WavLoader.cpp b/Userland/Libraries/LibAudio/WavLoader.cpp index b300256e42..e4ad0d6a41 100644 --- a/Userland/Libraries/LibAudio/WavLoader.cpp +++ b/Userland/Libraries/LibAudio/WavLoader.cpp @@ -54,9 +54,10 @@ bool WavLoaderPlugin::sniff() RefPtr<Buffer> WavLoaderPlugin::get_more_samples(size_t max_bytes_to_read_from_input) { -#if AWAVLOADER_DEBUG - dbgln("Read {} bytes WAV with num_channels {} sample rate {}, bits per sample {}, sample format {}", max_bytes_to_read_from_input, m_num_channels, m_sample_rate, pcm_bits_per_sample(m_sample_format), sample_format_name(m_sample_format)); -#endif + dbgln_if(AWAVLOADER_DEBUG, "Read {} bytes WAV with num_channels {} sample rate {}, " + "bits per sample {}, sample format {}", + max_bytes_to_read_from_input, m_num_channels, + m_sample_rate, pcm_bits_per_sample(m_sample_format), sample_format_name(m_sample_format)); size_t samples_to_read = static_cast<int>(max_bytes_to_read_from_input) / (m_num_channels * (pcm_bits_per_sample(m_sample_format) / 8)); RefPtr<Buffer> buffer; if (m_file) { @@ -215,9 +216,8 @@ bool WavLoaderPlugin::parse_header() } } -#if AWAVLOADER_DEBUG - dbgln("WAV format {} at {}bit, {} channels, rate {}Hz ", sample_format_name(m_sample_format), pcm_bits_per_sample(m_sample_format), m_num_channels, m_sample_rate); -#endif + dbgln_if(AWAVLOADER_DEBUG, "WAV format {} at {} bit, {} channels, rate {}Hz ", + sample_format_name(m_sample_format), pcm_bits_per_sample(m_sample_format), m_num_channels, m_sample_rate); // Read chunks until we find DATA bool found_data = false; diff --git a/Userland/Libraries/LibC/termcap.cpp b/Userland/Libraries/LibC/termcap.cpp index 75789ae62b..30216da2a7 100644 --- a/Userland/Libraries/LibC/termcap.cpp +++ b/Userland/Libraries/LibC/termcap.cpp @@ -21,9 +21,8 @@ char* BC; int tgetent([[maybe_unused]] char* bp, [[maybe_unused]] const char* name) { -#if TERMCAP_DEBUG - fprintf(stderr, "tgetent: bp=%p, name='%s'\n", bp, name); -#endif + if constexpr (TERMCAP_DEBUG) + fprintf(stderr, "tgetent: bp=%p, name='%s'\n", bp, name); PC = '\0'; BC = const_cast<char*>("\033[D"); UP = const_cast<char*>("\033[A"); @@ -81,9 +80,8 @@ static void ensure_caps() char* tgetstr(const char* id, char** area) { ensure_caps(); -#if TERMCAP_DEBUG - fprintf(stderr, "tgetstr: id='%s'\n", id); -#endif + if constexpr (TERMCAP_DEBUG) + fprintf(stderr, "tgetstr: id='%s'\n", id); auto it = caps->find(id); if (it != caps->end()) { char* ret = *area; @@ -100,9 +98,8 @@ char* tgetstr(const char* id, char** area) int tgetflag([[maybe_unused]] const char* id) { -#if TERMCAP_DEBUG - fprintf(stderr, "tgetflag: '%s'\n", id); -#endif + if constexpr (TERMCAP_DEBUG) + fprintf(stderr, "tgetflag: '%s'\n", id); auto it = caps->find(id); if (it != caps->end()) return 1; @@ -111,9 +108,8 @@ int tgetflag([[maybe_unused]] const char* id) int tgetnum(const char* id) { -#if TERMCAP_DEBUG - fprintf(stderr, "tgetnum: '%s'\n", id); -#endif + if constexpr (TERMCAP_DEBUG) + fprintf(stderr, "tgetnum: '%s'\n", id); auto it = caps->find(id); if (it != caps->end()) return atoi((*it).value); diff --git a/Userland/Libraries/LibChess/UCIEndpoint.cpp b/Userland/Libraries/LibChess/UCIEndpoint.cpp index 7b2ee65cfe..e1ab9d234b 100644 --- a/Userland/Libraries/LibChess/UCIEndpoint.cpp +++ b/Userland/Libraries/LibChess/UCIEndpoint.cpp @@ -23,9 +23,7 @@ Endpoint::Endpoint(NonnullRefPtr<Core::IODevice> in, NonnullRefPtr<Core::IODevic void Endpoint::send_command(const Command& command) { -#if UCI_DEBUG - dbgln("{} Sent UCI Command: {}", class_name(), String(command.to_string().characters(), Chomp)); -#endif + dbgln_if(UCI_DEBUG, "{} Sent UCI Command: {}", class_name(), String(command.to_string().characters(), Chomp)); m_out->write(command.to_string()); } @@ -74,9 +72,7 @@ NonnullOwnPtr<Command> Endpoint::read_command() { String line(ReadonlyBytes(m_in->read_line(4096).bytes()), Chomp); -#if UCI_DEBUG - dbgln("{} Received UCI Command: {}", class_name(), line); -#endif + dbgln_if(UCI_DEBUG, "{} Received UCI Command: {}", class_name(), line); if (line == "uci") { return make<UCICommand>(UCICommand::from_string(line)); diff --git a/Userland/Libraries/LibCore/EventLoop.cpp b/Userland/Libraries/LibCore/EventLoop.cpp index 3fee668783..670a8d0932 100644 --- a/Userland/Libraries/LibCore/EventLoop.cpp +++ b/Userland/Libraries/LibCore/EventLoop.cpp @@ -393,9 +393,7 @@ void EventLoop::pump(WaitMode mode) break; } } else if (event.type() == Event::Type::DeferredInvoke) { -#if DEFERRED_INVOKE_DEBUG - dbgln("DeferredInvoke: receiver = {}", *receiver); -#endif + dbgln_if(DEFERRED_INVOKE_DEBUG, "DeferredInvoke: receiver = {}", *receiver); static_cast<DeferredInvocationEvent&>(event).m_invokee(*receiver); } else { NonnullRefPtr<Object> protector(*receiver); diff --git a/Userland/Libraries/LibCpp/Parser.cpp b/Userland/Libraries/LibCpp/Parser.cpp index 34341a61f0..5f055a2e32 100644 --- a/Userland/Libraries/LibCpp/Parser.cpp +++ b/Userland/Libraries/LibCpp/Parser.cpp @@ -22,17 +22,17 @@ Parser::Parser(const StringView& program, const String& filename, Preprocessor:: , m_filename(filename) { initialize_program_tokens(program); -#if CPP_DEBUG - dbgln("Tokens:"); - for (auto& token : m_tokens) { - StringView text; - if (token.start().line != token.end().line || token.start().column > token.end().column) - text = {}; - else - text = text_of_token(token); - dbgln("{} {}:{}-{}:{} ({})", token.to_string(), token.start().line, token.start().column, token.end().line, token.end().column, text); + if constexpr (CPP_DEBUG) { + dbgln("Tokens:"); + for (auto& token : m_tokens) { + StringView text; + if (token.start().line != token.end().line || token.start().column > token.end().column) + text = {}; + else + text = text_of_token(token); + dbgln("{} {}:{}-{}:{} ({})", token.to_string(), token.start().line, token.start().column, token.end().line, token.end().column, text); + } } -#endif } void Parser::initialize_program_tokens(const StringView& program) diff --git a/Userland/Libraries/LibCrypto/NumberTheory/ModularFunctions.cpp b/Userland/Libraries/LibCrypto/NumberTheory/ModularFunctions.cpp index 77db745566..71b372fbb0 100644 --- a/Userland/Libraries/LibCrypto/NumberTheory/ModularFunctions.cpp +++ b/Userland/Libraries/LibCrypto/NumberTheory/ModularFunctions.cpp @@ -208,9 +208,7 @@ UnsignedBigInteger LCM(const UnsignedBigInteger& a, const UnsignedBigInteger& b) GCD_without_allocation(a, b, temp_a, temp_b, temp_1, temp_2, temp_3, temp_4, temp_quotient, temp_remainder, gcd_output); if (gcd_output == 0) { -#if NT_DEBUG - dbgln("GCD is zero"); -#endif + dbgln_if(NT_DEBUG, "GCD is zero"); return output; } diff --git a/Userland/Libraries/LibDebug/DebugInfo.cpp b/Userland/Libraries/LibDebug/DebugInfo.cpp index 1199999059..2a9568c69d 100644 --- a/Userland/Libraries/LibDebug/DebugInfo.cpp +++ b/Userland/Libraries/LibDebug/DebugInfo.cpp @@ -42,15 +42,11 @@ void DebugInfo::parse_scopes_impl(const Dwarf::DIE& die) return; if (child.get_attribute(Dwarf::Attribute::Inline).has_value()) { -#if SPAM_DEBUG - dbgln("DWARF inlined functions are not supported"); -#endif + dbgln_if(SPAM_DEBUG, "DWARF inlined functions are not supported"); return; } if (child.get_attribute(Dwarf::Attribute::Ranges).has_value()) { -#if SPAM_DEBUG - dbgln("DWARF ranges are not supported"); -#endif + dbgln_if(SPAM_DEBUG, "DWARF ranges are not supported"); return; } auto name = child.get_attribute(Dwarf::Attribute::Name); @@ -61,9 +57,7 @@ void DebugInfo::parse_scopes_impl(const Dwarf::DIE& die) scope.name = name.value().data.as_string; if (!child.get_attribute(Dwarf::Attribute::LowPc).has_value()) { -#if SPAM_DEBUG - dbgln("DWARF: Couldn't find attribute LowPc for scope"); -#endif + dbgln_if(SPAM_DEBUG, "DWARF: Couldn't find attribute LowPc for scope"); return; } scope.address_low = child.get_attribute(Dwarf::Attribute::LowPc).value().data.as_u32; diff --git a/Userland/Libraries/LibELF/Image.cpp b/Userland/Libraries/LibELF/Image.cpp index 2f745f927c..2f43a2a788 100644 --- a/Userland/Libraries/LibELF/Image.cpp +++ b/Userland/Libraries/LibELF/Image.cpp @@ -263,9 +263,7 @@ Image::RelocationSection Image::Section::relocations() const if (relocation_section.type() != SHT_REL) return static_cast<const RelocationSection>(m_image.section(0)); -#if ELF_IMAGE_DEBUG - dbgln("Found relocations for {} in {}", name(), relocation_section.name()); -#endif + dbgln_if(ELF_IMAGE_DEBUG, "Found relocations for {} in {}", name(), relocation_section.name()); return static_cast<const RelocationSection>(relocation_section); } diff --git a/Userland/Libraries/LibGUI/Menu.cpp b/Userland/Libraries/LibGUI/Menu.cpp index 2e0b905c7e..3d774ad385 100644 --- a/Userland/Libraries/LibGUI/Menu.cpp +++ b/Userland/Libraries/LibGUI/Menu.cpp @@ -87,9 +87,7 @@ int Menu::realize_menu(RefPtr<Action> default_action) unrealize_menu(); m_menu_id = WindowServerConnection::the().send_sync<Messages::WindowServer::CreateMenu>(m_name)->menu_id(); -#if MENU_DEBUG - dbgln("GUI::Menu::realize_menu(): New menu ID: {}", m_menu_id); -#endif + dbgln_if(MENU_DEBUG, "GUI::Menu::realize_menu(): New menu ID: {}", m_menu_id); VERIFY(m_menu_id > 0); for (size_t i = 0; i < m_items.size(); ++i) { auto& item = m_items[i]; diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp index 94661e0661..b6ab495466 100644 --- a/Userland/Libraries/LibGUI/TextEditor.cpp +++ b/Userland/Libraries/LibGUI/TextEditor.cpp @@ -474,9 +474,8 @@ void TextEditor::paint_event(PaintEvent& event) for_each_visual_line(line_index, [&](const Gfx::IntRect& visual_line_rect, auto& visual_line_text, size_t start_of_visual_line, [[maybe_unused]] bool is_last_visual_line) { if (is_multi_line() && line_index == m_cursor.line()) painter.fill_rect(visual_line_rect, widget_background_color.darkened(0.9f)); -#if TEXTEDITOR_DEBUG - painter.draw_rect(visual_line_rect, Color::Cyan); -#endif + if constexpr (TEXTEDITOR_DEBUG) + painter.draw_rect(visual_line_rect, Color::Cyan); if (!placeholder().is_empty() && document().is_empty() && !is_focused() && line_index == 0) { auto line_rect = visual_line_rect; diff --git a/Userland/Libraries/LibGUI/TreeView.cpp b/Userland/Libraries/LibGUI/TreeView.cpp index 53019815e2..01e50f089f 100644 --- a/Userland/Libraries/LibGUI/TreeView.cpp +++ b/Userland/Libraries/LibGUI/TreeView.cpp @@ -238,9 +238,8 @@ void TreeView::paint_event(PaintEvent& event) auto rect = a_rect.translated(0, y_offset); auto toggle_rect = a_toggle_rect.translated(0, y_offset); -#if ITEM_RECTS_DEBUG - painter.fill_rect(rect, Color::WarmGray); -#endif + if constexpr (ITEM_RECTS_DEBUG) + painter.fill_rect(rect, Color::WarmGray); bool is_selected_row = selection().contains(index); diff --git a/Userland/Libraries/LibGUI/Window.cpp b/Userland/Libraries/LibGUI/Window.cpp index 87cfcedb3f..442c8ef557 100644 --- a/Userland/Libraries/LibGUI/Window.cpp +++ b/Userland/Libraries/LibGUI/Window.cpp @@ -609,9 +609,7 @@ void Window::update(const Gfx::IntRect& a_rect) for (auto& pending_rect : m_pending_paint_event_rects) { if (pending_rect.contains(a_rect)) { -#if UPDATE_COALESCING_DEBUG - dbgln("Ignoring {} since it's contained by pending rect {}", a_rect, pending_rect); -#endif + dbgln_if(UPDATE_COALESCING_DEBUG, "Ignoring {} since it's contained by pending rect {}", a_rect, pending_rect); return; } } diff --git a/Userland/Libraries/LibGemini/GeminiJob.cpp b/Userland/Libraries/LibGemini/GeminiJob.cpp index 306594b003..003fb9310b 100644 --- a/Userland/Libraries/LibGemini/GeminiJob.cpp +++ b/Userland/Libraries/LibGemini/GeminiJob.cpp @@ -20,9 +20,7 @@ void GeminiJob::start() m_socket = TLS::TLSv12::construct(this); m_socket->set_root_certificates(m_override_ca_certificates ? *m_override_ca_certificates : DefaultRootCACertificates::the().certificates()); m_socket->on_tls_connected = [this] { -#if GEMINIJOB_DEBUG - dbgln("GeminiJob: on_connected callback"); -#endif + dbgln_if(GEMINIJOB_DEBUG, "GeminiJob: on_connected callback"); on_socket_connected(); }; m_socket->on_tls_error = [this](TLS::AlertDescription error) { diff --git a/Userland/Libraries/LibGemini/Job.cpp b/Userland/Libraries/LibGemini/Job.cpp index 518883dd25..e7c2f20eca 100644 --- a/Userland/Libraries/LibGemini/Job.cpp +++ b/Userland/Libraries/LibGemini/Job.cpp @@ -132,9 +132,7 @@ void Job::on_socket_connected() }); if (!is_established()) { -#if JOB_DEBUG - dbgln("Connection appears to have closed, finishing up"); -#endif + dbgln_if(JOB_DEBUG, "Connection appears to have closed, finishing up"); finish_up(); } }); diff --git a/Userland/Libraries/LibGfx/GIFLoader.cpp b/Userland/Libraries/LibGfx/GIFLoader.cpp index 2948ea736b..d8b60c0dbb 100644 --- a/Userland/Libraries/LibGfx/GIFLoader.cpp +++ b/Userland/Libraries/LibGfx/GIFLoader.cpp @@ -350,9 +350,7 @@ static bool decode_frame(GIFLoadingContext& context, size_t frame_index) while (true) { Optional<u16> code = decoder.next_code(); if (!code.has_value()) { -#if GIF_DEBUG - dbgln("Unexpectedly reached end of gif frame data"); -#endif + dbgln_if(GIF_DEBUG, "Unexpectedly reached end of gif frame data"); return false; } @@ -499,9 +497,7 @@ static bool load_gif_frame_descriptors(GIFLoadingContext& context) if (extension_type == 0xF9) { if (sub_block.size() != 4) { -#if GIF_DEBUG - dbgln("Unexpected graphic control size"); -#endif + dbgln_if(GIF_DEBUG, "Unexpected graphic control size"); continue; } diff --git a/Userland/Libraries/LibGfx/ICOLoader.cpp b/Userland/Libraries/LibGfx/ICOLoader.cpp index c6e5c99557..2c8755aeb0 100644 --- a/Userland/Libraries/LibGfx/ICOLoader.cpp +++ b/Userland/Libraries/LibGfx/ICOLoader.cpp @@ -169,25 +169,22 @@ static bool load_ico_directory(ICOLoadingContext& context) for (size_t i = 0; i < image_count.value(); ++i) { auto maybe_desc = decode_ico_direntry(stream); if (!maybe_desc.has_value()) { -#if ICO_DEBUG - printf("load_ico_directory: error loading entry: %lu\n", i); -#endif + if constexpr (ICO_DEBUG) + printf("load_ico_directory: error loading entry: %lu\n", i); return false; } auto& desc = maybe_desc.value(); if (desc.offset + desc.size < desc.offset // detect integer overflow || (desc.offset + desc.size) > context.data_size) { -#if ICO_DEBUG - printf("load_ico_directory: offset: %lu size: %lu doesn't fit in ICO size: %lu\n", - desc.offset, desc.size, context.data_size); -#endif + if constexpr (ICO_DEBUG) + printf("load_ico_directory: offset: %lu size: %lu doesn't fit in ICO size: %lu\n", + desc.offset, desc.size, context.data_size); return false; } -#if ICO_DEBUG - printf("load_ico_directory: index %zu width: %u height: %u offset: %lu size: %lu\n", - i, desc.width, desc.height, desc.offset, desc.size); -#endif + if constexpr (ICO_DEBUG) + printf("load_ico_directory: index %zu width: %u height: %u offset: %lu size: %lu\n", + i, desc.width, desc.height, desc.offset, desc.size); context.images.append(desc); } context.largest_index = find_largest_image(context); @@ -203,16 +200,14 @@ static bool load_ico_bmp(ICOLoadingContext& context, ImageDescriptor& desc) memcpy(&info, context.data + desc.offset, sizeof(info)); if (info.size != sizeof(info)) { -#if ICO_DEBUG - printf("load_ico_bmp: info size: %u, expected: %lu\n", info.size, sizeof(info)); -#endif + if constexpr (ICO_DEBUG) + printf("load_ico_bmp: info size: %u, expected: %lu\n", info.size, sizeof(info)); return false; } if (info.width < 0) { -#if ICO_DEBUG - printf("load_ico_bmp: width %d < 0\n", info.width); -#endif + if constexpr (ICO_DEBUG) + printf("load_ico_bmp: width %d < 0\n", info.width); return false; } bool topdown = false; @@ -222,37 +217,32 @@ static bool load_ico_bmp(ICOLoadingContext& context, ImageDescriptor& desc) } if (info.planes != 1) { -#if ICO_DEBUG - printf("load_ico_bmp: planes: %d != 1", info.planes); -#endif + if constexpr (ICO_DEBUG) + printf("load_ico_bmp: planes: %d != 1", info.planes); return false; } if (info.bpp != 32) { -#if ICO_DEBUG - printf("load_ico_bmp: unsupported bpp: %u\n", info.bpp); -#endif + if constexpr (ICO_DEBUG) + printf("load_ico_bmp: unsupported bpp: %u\n", info.bpp); return false; } -#if ICO_DEBUG - printf("load_ico_bmp: width: %d height: %d direction: %s bpp: %d size_image: %u\n", - info.width, info.height, topdown ? "TopDown" : "BottomUp", info.bpp, info.size_image); -#endif + if constexpr (ICO_DEBUG) + printf("load_ico_bmp: width: %d height: %d direction: %s bpp: %d size_image: %u\n", + info.width, info.height, topdown ? "TopDown" : "BottomUp", info.bpp, info.size_image); if (info.compression != 0 || info.palette_size != 0 || info.important_colors != 0) { -#if ICO_DEBUG - printf("load_ico_bmp: following fields must be 0: compression: %u palette_size: %u important_colors: %u\n", - info.compression, info.palette_size, info.important_colors); -#endif + if constexpr (ICO_DEBUG) + printf("load_ico_bmp: following fields must be 0: compression: %u palette_size: %u important_colors: %u\n", + info.compression, info.palette_size, info.important_colors); return false; } if (info.width != desc.width || info.height != 2 * desc.height) { -#if ICO_DEBUG - printf("load_ico_bmp: size mismatch: ico %dx%d, bmp %dx%d\n", - desc.width, desc.height, info.width, info.height); -#endif + if constexpr (ICO_DEBUG) + printf("load_ico_bmp: size mismatch: ico %dx%d, bmp %dx%d\n", + desc.width, desc.height, info.width, info.height); return false; } @@ -261,10 +251,9 @@ static bool load_ico_bmp(ICOLoadingContext& context, ImageDescriptor& desc) size_t required_len = desc.height * (desc.width * sizeof(BMP_ARGB) + mask_row_len); size_t available_len = desc.size - sizeof(info); if (required_len > available_len) { -#if ICO_DEBUG - printf("load_ico_bmp: required_len: %lu > available_len: %lu\n", - required_len, available_len); -#endif + if constexpr (ICO_DEBUG) + printf("load_ico_bmp: required_len: %lu > available_len: %lu\n", + required_len, available_len); return false; } @@ -310,17 +299,15 @@ static bool load_ico_bitmap(ICOLoadingContext& context, Optional<size_t> index) if (png_decoder.sniff()) { desc.bitmap = png_decoder.bitmap(); if (!desc.bitmap) { -#if ICO_DEBUG - printf("load_ico_bitmap: failed to load PNG encoded image index: %lu\n", real_index); -#endif + if constexpr (ICO_DEBUG) + printf("load_ico_bitmap: failed to load PNG encoded image index: %lu\n", real_index); return false; } return true; } else { if (!load_ico_bmp(context, desc)) { -#if ICO_DEBUG - printf("load_ico_bitmap: failed to load BMP encoded image index: %lu\n", real_index); -#endif + if constexpr (ICO_DEBUG) + printf("load_ico_bitmap: failed to load BMP encoded image index: %lu\n", real_index); return false; } return true; diff --git a/Userland/Libraries/LibGfx/JPGLoader.cpp b/Userland/Libraries/LibGfx/JPGLoader.cpp index b6115379b0..1c2aefc209 100644 --- a/Userland/Libraries/LibGfx/JPGLoader.cpp +++ b/Userland/Libraries/LibGfx/JPGLoader.cpp @@ -247,9 +247,7 @@ static Optional<u8> get_next_symbol(HuffmanStreamState& hstream, const HuffmanTa } } -#if JPG_DEBUG - dbgln("If you're seeing this...the jpeg decoder needs to support more kinds of JPEGs!"); -#endif + dbgln_if(JPG_DEBUG, "If you're seeing this...the jpeg decoder needs to support more kinds of JPEGs!"); return {}; } diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp index 80a5456cdb..d98e8a45f1 100644 --- a/Userland/Libraries/LibGfx/Painter.cpp +++ b/Userland/Libraries/LibGfx/Painter.cpp @@ -1880,11 +1880,11 @@ void Painter::fill_path(Path& path, Color color, WindingRule winding_rule) quick_sort(active_list, [](const auto& line0, const auto& line1) { return line1.x < line0.x; }); -#if FILL_PATH_DEBUG - if ((int)scanline % 10 == 0) { - draw_text(IntRect(active_list.last().x - 20, scanline, 20, 10), String::number((int)scanline)); + if constexpr (FILL_PATH_DEBUG) { + if ((int)scanline % 10 == 0) { + draw_text(IntRect(active_list.last().x - 20, scanline, 20, 10), String::number((int)scanline)); + } } -#endif if (active_list.size() > 1) { auto winding_number { winding_rule == WindingRule::Nonzero ? 1 : 0 }; @@ -1952,12 +1952,12 @@ void Painter::fill_path(Path& path, Color color, WindingRule winding_rule) } } -#if FILL_PATH_DEBUG - size_t i { 0 }; - for (auto& segment : segments) { - draw_line(Point<int>(segment.from), Point<int>(segment.to), Color::from_hsv(i++ * 360.0 / segments.size(), 1.0, 1.0), 1); + if constexpr (FILL_PATH_DEBUG) { + size_t i { 0 }; + for (auto& segment : segments) { + draw_line(Point<int>(segment.from), Point<int>(segment.to), Color::from_hsv(i++ * 360.0 / segments.size(), 1.0, 1.0), 1); + } } -#endif } void Painter::blit_disabled(const IntPoint& location, const Gfx::Bitmap& bitmap, const IntRect& rect, const Palette& palette) diff --git a/Userland/Libraries/LibHTTP/HttpJob.cpp b/Userland/Libraries/LibHTTP/HttpJob.cpp index 96001bb0bc..d8c480c09a 100644 --- a/Userland/Libraries/LibHTTP/HttpJob.cpp +++ b/Userland/Libraries/LibHTTP/HttpJob.cpp @@ -17,9 +17,7 @@ void HttpJob::start() VERIFY(!m_socket); m_socket = Core::TCPSocket::construct(this); m_socket->on_connected = [this] { -#if CHTTPJOB_DEBUG - dbgln("HttpJob: on_connected callback"); -#endif + dbgln_if(CHTTPJOB_DEBUG, "HttpJob: on_connected callback"); on_socket_connected(); }; bool success = m_socket->connect(m_request.url().host(), m_request.url().port()); diff --git a/Userland/Libraries/LibHTTP/HttpsJob.cpp b/Userland/Libraries/LibHTTP/HttpsJob.cpp index 4763b9cc89..18b6cb9974 100644 --- a/Userland/Libraries/LibHTTP/HttpsJob.cpp +++ b/Userland/Libraries/LibHTTP/HttpsJob.cpp @@ -20,9 +20,7 @@ void HttpsJob::start() m_socket = TLS::TLSv12::construct(this); m_socket->set_root_certificates(m_override_ca_certificates ? *m_override_ca_certificates : DefaultRootCACertificates::the().certificates()); m_socket->on_tls_connected = [this] { -#if HTTPSJOB_DEBUG - dbgln("HttpsJob: on_connected callback"); -#endif + dbgln_if(HTTPSJOB_DEBUG, "HttpsJob: on_connected callback"); on_socket_connected(); }; m_socket->on_tls_error = [&](TLS::AlertDescription error) { diff --git a/Userland/Libraries/LibHTTP/Job.cpp b/Userland/Libraries/LibHTTP/Job.cpp index 92a8cc8449..8b67de60a1 100644 --- a/Userland/Libraries/LibHTTP/Job.cpp +++ b/Userland/Libraries/LibHTTP/Job.cpp @@ -346,9 +346,7 @@ void Job::on_socket_connected() }); if (!is_established()) { -#if JOB_DEBUG - dbgln("Connection appears to have closed, finishing up"); -#endif + dbgln_if(JOB_DEBUG, "Connection appears to have closed, finishing up"); finish_up(); } }); diff --git a/Userland/Libraries/LibLine/KeyCallbackMachine.cpp b/Userland/Libraries/LibLine/KeyCallbackMachine.cpp index faab56207d..9e6020a015 100644 --- a/Userland/Libraries/LibLine/KeyCallbackMachine.cpp +++ b/Userland/Libraries/LibLine/KeyCallbackMachine.cpp @@ -20,9 +20,7 @@ void KeyCallbackMachine::register_key_input_callback(Vector<Key> keys, Function< void KeyCallbackMachine::key_pressed(Editor& editor, Key key) { -#if CALLBACK_MACHINE_DEBUG - dbgln("Key<{}, {}> pressed, seq_length={}, {} things in the matching vector", key.key, key.modifiers, m_sequence_length, m_current_matching_keys.size()); -#endif + dbgln_if(CALLBACK_MACHINE_DEBUG, "Key<{}, {}> pressed, seq_length={}, {} things in the matching vector", key.key, key.modifiers, m_sequence_length, m_current_matching_keys.size()); if (m_sequence_length == 0) { VERIFY(m_current_matching_keys.is_empty()); @@ -61,14 +59,14 @@ void KeyCallbackMachine::key_pressed(Editor& editor, Key key) return; } -#if CALLBACK_MACHINE_DEBUG - dbgln("seq_length={}, matching vector:", m_sequence_length); - for (auto& key : m_current_matching_keys) { - for (auto& k : key) - dbgln(" {}, {}", k.key, k.modifiers); - dbgln(""); + if constexpr (CALLBACK_MACHINE_DEBUG) { + dbgln("seq_length={}, matching vector:", m_sequence_length); + for (auto& key : m_current_matching_keys) { + for (auto& k : key) + dbgln(" {}, {}", k.key, k.modifiers); + dbgln(""); + } } -#endif m_should_process_this_key = false; for (auto& key : m_current_matching_keys) { diff --git a/Userland/Libraries/LibMarkdown/Text.cpp b/Userland/Libraries/LibMarkdown/Text.cpp index c93f501be3..7d363e8ab7 100644 --- a/Userland/Libraries/LibMarkdown/Text.cpp +++ b/Userland/Libraries/LibMarkdown/Text.cpp @@ -222,17 +222,15 @@ Optional<Text> Text::parse(const StringView& str) current_link_is_actually_img = true; break; case '[': -#if MARKDOWN_DEBUG - if (first_span_in_the_current_link != -1) - dbgln("Dropping the outer link"); -#endif + if constexpr (MARKDOWN_DEBUG) { + if (first_span_in_the_current_link != -1) + dbgln("Dropping the outer link"); + } first_span_in_the_current_link = spans.size(); break; case ']': { if (first_span_in_the_current_link == -1) { -#if MARKDOWN_DEBUG - dbgln("Unmatched ]"); -#endif + dbgln_if(MARKDOWN_DEBUG, "Unmatched ]"); continue; } ScopeGuard guard = [&] { diff --git a/Userland/Libraries/LibRegex/RegexDebug.h b/Userland/Libraries/LibRegex/RegexDebug.h index 690e81391f..eb45ba55bf 100644 --- a/Userland/Libraries/LibRegex/RegexDebug.h +++ b/Userland/Libraries/LibRegex/RegexDebug.h @@ -10,8 +10,6 @@ #include "LibRegex/RegexMatcher.h" #include <AK/Debug.h> -#if REGEX_DEBUG - namespace regex { class RegexDebug { @@ -131,5 +129,3 @@ private: } using regex::RegexDebug; - -#endif diff --git a/Userland/Libraries/LibRegex/RegexLexer.cpp b/Userland/Libraries/LibRegex/RegexLexer.cpp index 8065178fa1..bd7ac684f6 100644 --- a/Userland/Libraries/LibRegex/RegexLexer.cpp +++ b/Userland/Libraries/LibRegex/RegexLexer.cpp @@ -130,9 +130,8 @@ Token Lexer::next() case '\\': return 2; default: -#if REGEX_DEBUG - fprintf(stderr, "[LEXER] Found invalid escape sequence: \\%c (the parser will have to deal with this!)\n", peek(1)); -#endif + if constexpr (REGEX_DEBUG) + fprintf(stderr, "[LEXER] Found invalid escape sequence: \\%c (the parser will have to deal with this!)\n", peek(1)); return 0; } }; diff --git a/Userland/Libraries/LibRegex/RegexParser.cpp b/Userland/Libraries/LibRegex/RegexParser.cpp index 7a0a172d52..decbb8bbb1 100644 --- a/Userland/Libraries/LibRegex/RegexParser.cpp +++ b/Userland/Libraries/LibRegex/RegexParser.cpp @@ -148,9 +148,8 @@ Parser::Result Parser::parse(Optional<AllOptions> regex_options) else set_error(Error::InvalidPattern); -#if REGEX_DEBUG - fprintf(stderr, "[PARSER] Produced bytecode with %lu entries (opcodes + arguments)\n", m_parser_state.bytecode.size()); -#endif + if constexpr (REGEX_DEBUG) + fprintf(stderr, "[PARSER] Produced bytecode with %lu entries (opcodes + arguments)\n", m_parser_state.bytecode.size()); return { move(m_parser_state.bytecode), move(m_parser_state.capture_groups_count), @@ -461,9 +460,8 @@ ALWAYS_INLINE bool PosixExtendedParser::parse_sub_expression(ByteCode& stack, si if (match(TokenType::EscapeSequence)) { length = 1; Token t = consume(); -#if REGEX_DEBUG - printf("[PARSER] EscapeSequence with substring %s\n", String(t.value()).characters()); -#endif + if constexpr (REGEX_DEBUG) + printf("[PARSER] EscapeSequence with substring %s\n", String(t.value()).characters()); bytecode.insert_bytecode_compare_values({ { CharacterCompareType::Char, (u32)t.value().characters_without_null_termination()[1] } }); should_parse_repetition_symbol = true; diff --git a/Userland/Libraries/LibRegex/Tests/Regex.cpp b/Userland/Libraries/LibRegex/Tests/Regex.cpp index 054c54485b..b1d8ab9943 100644 --- a/Userland/Libraries/LibRegex/Tests/Regex.cpp +++ b/Userland/Libraries/LibRegex/Tests/Regex.cpp @@ -356,21 +356,21 @@ TEST_CASE(ini_file_entries) Regex<PosixExtended> re("[[:alpha:]]*=([[:digit:]]*)|\\[(.*)\\]"); RegexResult result; -#if REGEX_DEBUG - RegexDebug regex_dbg(stderr); - regex_dbg.print_raw_bytecode(re); - regex_dbg.print_header(); - regex_dbg.print_bytecode(re); -#endif + if constexpr (REGEX_DEBUG) { + RegexDebug regex_dbg(stderr); + regex_dbg.print_raw_bytecode(re); + regex_dbg.print_header(); + regex_dbg.print_bytecode(re); + } String haystack = "[Window]\nOpacity=255\nAudibleBeep=0\n"; EXPECT_EQ(re.search(haystack.view(), result, PosixFlags::Multiline), true); EXPECT_EQ(result.count, 3u); -#if REGEX_DEBUG - for (auto& v : result.matches) - fprintf(stderr, "%s\n", v.view.to_string().characters()); -#endif + if constexpr (REGEX_DEBUG) { + for (auto& v : result.matches) + fprintf(stderr, "%s\n", v.view.to_string().characters()); + } EXPECT_EQ(result.matches.at(0).view, "[Window]"); EXPECT_EQ(result.capture_group_matches.at(0).at(0).view, "Window"); @@ -405,12 +405,12 @@ TEST_CASE(named_capture_group) Regex<PosixExtended> re("[[:alpha:]]*=(?<Test>[[:digit:]]*)"); RegexResult result; -#if REGEX_DEBUG - RegexDebug regex_dbg(stderr); - regex_dbg.print_raw_bytecode(re); - regex_dbg.print_header(); - regex_dbg.print_bytecode(re); -#endif + if constexpr (REGEX_DEBUG) { + RegexDebug regex_dbg(stderr); + regex_dbg.print_raw_bytecode(re); + regex_dbg.print_header(); + regex_dbg.print_bytecode(re); + } String haystack = "[Window]\nOpacity=255\nAudibleBeep=0\n"; EXPECT_EQ(re.search(haystack, result, PosixFlags::Multiline), true); @@ -426,12 +426,12 @@ TEST_CASE(a_star) Regex<PosixExtended> re("a*"); RegexResult result; -#if REGEX_DEBUG - RegexDebug regex_dbg(stderr); - regex_dbg.print_raw_bytecode(re); - regex_dbg.print_header(); - regex_dbg.print_bytecode(re); -#endif + if constexpr (REGEX_DEBUG) { + RegexDebug regex_dbg(stderr); + regex_dbg.print_raw_bytecode(re); + regex_dbg.print_header(); + regex_dbg.print_bytecode(re); + } String haystack = "[Window]\nOpacity=255\nAudibleBeep=0\n"; EXPECT_EQ(re.search(haystack.view(), result, PosixFlags::Multiline), true); @@ -488,14 +488,14 @@ TEST_CASE(ECMA262_parse) for (auto& test : tests) { Regex<ECMA262> re(test.pattern); EXPECT_EQ(re.parser_result.error, test.expected_error); -#if REGEX_DEBUG - dbgln("\n"); - RegexDebug regex_dbg(stderr); - regex_dbg.print_raw_bytecode(re); - regex_dbg.print_header(); - regex_dbg.print_bytecode(re); - dbgln("\n"); -#endif + if constexpr (REGEX_DEBUG) { + dbgln("\n"); + RegexDebug regex_dbg(stderr); + regex_dbg.print_raw_bytecode(re); + regex_dbg.print_header(); + regex_dbg.print_bytecode(re); + dbgln("\n"); + } } } @@ -550,14 +550,14 @@ TEST_CASE(ECMA262_match) for (auto& test : tests) { Regex<ECMA262> re(test.pattern, test.options); -#if REGEX_DEBUG - dbgln("\n"); - RegexDebug regex_dbg(stderr); - regex_dbg.print_raw_bytecode(re); - regex_dbg.print_header(); - regex_dbg.print_bytecode(re); - dbgln("\n"); -#endif + if constexpr (REGEX_DEBUG) { + dbgln("\n"); + RegexDebug regex_dbg(stderr); + regex_dbg.print_raw_bytecode(re); + regex_dbg.print_header(); + regex_dbg.print_bytecode(re); + dbgln("\n"); + } EXPECT_EQ(re.parser_result.error, Error::NoError); EXPECT_EQ(re.match(test.subject).success, test.matches); } @@ -583,14 +583,14 @@ TEST_CASE(replace) for (auto& test : tests) { Regex<ECMA262> re(test.pattern, test.options); -#if REGEX_DEBUG - dbgln("\n"); - RegexDebug regex_dbg(stderr); - regex_dbg.print_raw_bytecode(re); - regex_dbg.print_header(); - regex_dbg.print_bytecode(re); - dbgln("\n"); -#endif + if constexpr (REGEX_DEBUG) { + dbgln("\n"); + RegexDebug regex_dbg(stderr); + regex_dbg.print_raw_bytecode(re); + regex_dbg.print_header(); + regex_dbg.print_bytecode(re); + dbgln("\n"); + } EXPECT_EQ(re.parser_result.error, Error::NoError); EXPECT_EQ(re.replace(test.subject, test.replacement), test.expected); } diff --git a/Userland/Libraries/LibTLS/ClientHandshake.cpp b/Userland/Libraries/LibTLS/ClientHandshake.cpp index e1c54093b3..8fd60ef2cc 100644 --- a/Userland/Libraries/LibTLS/ClientHandshake.cpp +++ b/Userland/Libraries/LibTLS/ClientHandshake.cpp @@ -71,10 +71,10 @@ ssize_t TLSv12::handle_hello(ReadonlyBytes buffer, WritePacketStage& write_packe if (session_length && session_length <= 32) { memcpy(m_context.session_id, buffer.offset_pointer(res), session_length); m_context.session_id_size = session_length; -#if TLS_DEBUG - dbgln("Remote session ID:"); - print_buffer(ReadonlyBytes { m_context.session_id, session_length }); -#endif + if constexpr (TLS_DEBUG) { + dbgln("Remote session ID:"); + print_buffer(ReadonlyBytes { m_context.session_id, session_length }); + } } else { m_context.session_id_size = 0; } @@ -268,10 +268,10 @@ void TLSv12::build_random(PacketBuilder& builder) } auto& certificate = m_context.certificates[certificate_option.value()]; -#if TLS_DEBUG - dbgln("PreMaster secret"); - print_buffer(m_context.premaster_key); -#endif + if constexpr (TLS_DEBUG) { + dbgln("PreMaster secret"); + print_buffer(m_context.premaster_key); + } Crypto::PK::RSA_PKCS1_EME rsa(certificate.public_key.modulus(), 0, certificate.public_key.public_exponent()); @@ -279,10 +279,10 @@ void TLSv12::build_random(PacketBuilder& builder) auto outbuf = Bytes { out, rsa.output_size() }; rsa.encrypt(m_context.premaster_key, outbuf); -#if TLS_DEBUG - dbgln("Encrypted: "); - print_buffer(outbuf); -#endif + if constexpr (TLS_DEBUG) { + dbgln("Encrypted: "); + print_buffer(outbuf); + } if (!compute_master_secret(bytes)) { dbgln("oh noes we could not derive a master key :("); diff --git a/Userland/Libraries/LibTLS/Exchange.cpp b/Userland/Libraries/LibTLS/Exchange.cpp index c291fbdcaf..45e52e2bc2 100644 --- a/Userland/Libraries/LibTLS/Exchange.cpp +++ b/Userland/Libraries/LibTLS/Exchange.cpp @@ -53,22 +53,22 @@ bool TLSv12::expand_key() auto server_iv = key + offset; offset += iv_size; -#if TLS_DEBUG - dbgln("client key"); - print_buffer(client_key, key_size); - dbgln("server key"); - print_buffer(server_key, key_size); - dbgln("client iv"); - print_buffer(client_iv, iv_size); - dbgln("server iv"); - print_buffer(server_iv, iv_size); - if (!is_aead) { - dbgln("client mac key"); - print_buffer(m_context.crypto.local_mac, mac_size); - dbgln("server mac key"); - print_buffer(m_context.crypto.remote_mac, mac_size); + if constexpr (TLS_DEBUG) { + dbgln("client key"); + print_buffer(client_key, key_size); + dbgln("server key"); + print_buffer(server_key, key_size); + dbgln("client iv"); + print_buffer(client_iv, iv_size); + dbgln("server iv"); + print_buffer(server_iv, iv_size); + if (!is_aead) { + dbgln("client mac key"); + print_buffer(m_context.crypto.local_mac, mac_size); + dbgln("server mac key"); + print_buffer(m_context.crypto.remote_mac, mac_size); + } } -#endif if (is_aead) { memcpy(m_context.crypto.local_aead_iv, client_iv, iv_size); @@ -153,10 +153,10 @@ bool TLSv12::compute_master_secret(size_t length) ReadonlyBytes { m_context.remote_random, sizeof(m_context.remote_random) }); m_context.premaster_key.clear(); -#if TLS_DEBUG - dbgln("master key:"); - print_buffer(m_context.master_key); -#endif + if constexpr (TLS_DEBUG) { + dbgln("master key:"); + print_buffer(m_context.master_key); + } expand_key(); return true; } @@ -195,9 +195,7 @@ ByteBuffer TLSv12::build_certificate() builder.append((u8)HandshakeType::CertificateMessage); if (!total_certificate_size) { -#if TLS_DEBUG - dbgln("No certificates, sending empty certificate message"); -#endif + dbgln_if(TLS_DEBUG, "No certificates, sending empty certificate message"); builder.append_u24(certificate_vector_header_size); builder.append_u24(total_certificate_size); } else { diff --git a/Userland/Libraries/LibTLS/Socket.cpp b/Userland/Libraries/LibTLS/Socket.cpp index fc4ccf9208..92c7afe1e4 100644 --- a/Userland/Libraries/LibTLS/Socket.cpp +++ b/Userland/Libraries/LibTLS/Socket.cpp @@ -57,9 +57,7 @@ String TLSv12::read_line(size_t max_size) bool TLSv12::write(ReadonlyBytes buffer) { if (m_context.connection_status != ConnectionStatus::Established) { -#if TLS_DEBUG - dbgln("write request while not connected"); -#endif + dbgln_if(TLS_DEBUG, "write request while not connected"); return false; } @@ -186,9 +184,7 @@ bool TLSv12::check_connection_state(bool read) { if (!Core::Socket::is_open() || !Core::Socket::is_connected() || Core::Socket::eof()) { // an abrupt closure (the server is a jerk) -#if TLS_DEBUG - dbgln("Socket not open, assuming abrupt closure"); -#endif + dbgln_if(TLS_DEBUG, "Socket not open, assuming abrupt closure"); m_context.connection_finished = true; } if (m_context.critical_error) { @@ -209,9 +205,7 @@ bool TLSv12::check_connection_state(bool read) m_context.application_buffer.size()); } else { m_context.connection_finished = false; -#if TLS_DEBUG - dbgln("FINISHED"); -#endif + dbgln_if(TLS_DEBUG, "FINISHED"); } if (!m_context.application_buffer.size()) { m_context.connection_status = ConnectionStatus::Disconnected; @@ -230,10 +224,10 @@ bool TLSv12::flush() if (out_buffer_length == 0) return true; -#if TLS_DEBUG - dbgln("SENDING..."); - print_buffer(out_buffer, out_buffer_length); -#endif + if constexpr (TLS_DEBUG) { + dbgln("SENDING..."); + print_buffer(out_buffer, out_buffer_length); + } if (Core::Socket::write(&out_buffer[out_buffer_index], out_buffer_length)) { write_buffer().clear(); return true; diff --git a/Userland/Libraries/LibTLS/TLSv12.cpp b/Userland/Libraries/LibTLS/TLSv12.cpp index 4d259dd1c0..671b172a4e 100644 --- a/Userland/Libraries/LibTLS/TLSv12.cpp +++ b/Userland/Libraries/LibTLS/TLSv12.cpp @@ -493,9 +493,7 @@ ssize_t TLSv12::handle_certificate(ReadonlyBytes buffer) ssize_t res = 0; if (buffer.size() < 3) { -#if TLS_DEBUG - dbgln("not enough certificate header data"); -#endif + dbgln_if(TLS_DEBUG, "not enough certificate header data"); return (i8)Error::NeedMoreData; } @@ -509,9 +507,7 @@ ssize_t TLSv12::handle_certificate(ReadonlyBytes buffer) res += 3; if (certificate_total_length > buffer.size() - res) { -#if TLS_DEBUG - dbgln("not enough data for claimed total cert length"); -#endif + dbgln_if(TLS_DEBUG, "not enough data for claimed total cert length"); return (i8)Error::NeedMoreData; } size_t size = certificate_total_length; @@ -522,18 +518,14 @@ ssize_t TLSv12::handle_certificate(ReadonlyBytes buffer) while (size > 0) { ++index; if (buffer.size() - res < 3) { -#if TLS_DEBUG - dbgln("not enough data for certificate length"); -#endif + dbgln_if(TLS_DEBUG, "not enough data for certificate length"); return (i8)Error::NeedMoreData; } size_t certificate_size = buffer[res] * 0x10000 + buffer[res + 1] * 0x100 + buffer[res + 2]; res += 3; if (buffer.size() - res < certificate_size) { -#if TLS_DEBUG - dbgln("not enough data for certificate body"); -#endif + dbgln_if(TLS_DEBUG, "not enough data for certificate body"); return (i8)Error::NeedMoreData; } diff --git a/Userland/Libraries/LibVT/Terminal.cpp b/Userland/Libraries/LibVT/Terminal.cpp index 06e44d1bf7..49c71a7edf 100644 --- a/Userland/Libraries/LibVT/Terminal.cpp +++ b/Userland/Libraries/LibVT/Terminal.cpp @@ -797,9 +797,7 @@ void Terminal::ICH(const ParamVector& params) void Terminal::on_input(u8 ch) { -#if TERMINAL_DEBUG - dbgln("Terminal::on_input: {:#02x} ({:c}), fg={}, bg={}\n", ch, ch, m_current_attribute.foreground_color, m_current_attribute.background_color); -#endif + dbgln_if(TERMINAL_DEBUG, "Terminal::on_input: {:#02x} ({:c}), fg={}, bg={}\n", ch, ch, m_current_attribute.foreground_color, m_current_attribute.background_color); auto fail_utf8_parse = [this] { m_parser_state = Normal; diff --git a/Userland/Libraries/LibWeb/Layout/FrameBox.cpp b/Userland/Libraries/LibWeb/Layout/FrameBox.cpp index 4cc5fd3560..bf1439b91d 100644 --- a/Userland/Libraries/LibWeb/Layout/FrameBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/FrameBox.cpp @@ -58,11 +58,11 @@ void FrameBox::paint(PaintContext& context, PaintPhase phase) context.set_viewport_rect(old_viewport_rect); context.painter().restore(); -#if HIGHLIGHT_FOCUSED_FRAME_DEBUG - if (dom_node().content_frame()->is_focused_frame()) { - context.painter().draw_rect(absolute_rect().to<int>(), Color::Cyan); + if constexpr (HIGHLIGHT_FOCUSED_FRAME_DEBUG) { + if (dom_node().content_frame()->is_focused_frame()) { + context.painter().draw_rect(absolute_rect().to<int>(), Color::Cyan); + } } -#endif } } diff --git a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp index 8c1f6dd4c4..726bfead74 100644 --- a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp +++ b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp @@ -101,10 +101,8 @@ static bool build_gemini_document(DOM::Document& document, const ByteBuffer& dat auto gemini_document = Gemini::Document::parse(gemini_data, document.url()); String html_data = gemini_document->render_to_html(); -#if GEMINI_DEBUG - dbgln("Gemini data:\n\"\"\"{}\"\"\"", gemini_data); - dbgln("Converted to HTML:\n\"\"\"{}\"\"\"", html_data); -#endif + dbgln_if(GEMINI_DEBUG, "Gemini data:\n\"\"\"{}\"\"\"", gemini_data); + dbgln_if(GEMINI_DEBUG, "Converted to HTML:\n\"\"\"{}\"\"\"", html_data); HTML::HTMLDocumentParser parser(document, html_data, "utf-8"); parser.run(document.url()); diff --git a/Userland/Libraries/LibWeb/Loader/Resource.cpp b/Userland/Libraries/LibWeb/Loader/Resource.cpp index 9223145f96..9231ec341e 100644 --- a/Userland/Libraries/LibWeb/Loader/Resource.cpp +++ b/Userland/Libraries/LibWeb/Loader/Resource.cpp @@ -75,9 +75,7 @@ void Resource::did_load(Badge<ResourceLoader>, ReadonlyBytes data, const HashMap auto content_type = headers.get("Content-Type"); if (content_type.has_value()) { -#if RESOURCE_DEBUG - dbgln("Content-Type header: '{}'", content_type.value()); -#endif + dbgln_if(RESOURCE_DEBUG, "Content-Type header: '{}'", content_type.value()); m_encoding = encoding_from_content_type(content_type.value()); m_mime_type = mime_type_from_content_type(content_type.value()); } else if (url().protocol() == "data" && !url().data_mime_type().is_empty()) { @@ -85,9 +83,7 @@ void Resource::did_load(Badge<ResourceLoader>, ReadonlyBytes data, const HashMap m_encoding = "utf-8"; // FIXME: This doesn't seem nice. m_mime_type = url().data_mime_type(); } else { -#if RESOURCE_DEBUG - dbgln("No Content-Type header to go on! Guessing based on filename..."); -#endif + dbgln_if(RESOURCE_DEBUG, "No Content-Type header to go on! Guessing based on filename..."); m_encoding = "utf-8"; // FIXME: This doesn't seem nice. m_mime_type = Core::guess_mime_type_based_on_filename(url().path()); } diff --git a/Userland/Libraries/LibWeb/WebContentClient.cpp b/Userland/Libraries/LibWeb/WebContentClient.cpp index cb06f27cf1..ce31a3c2ee 100644 --- a/Userland/Libraries/LibWeb/WebContentClient.cpp +++ b/Userland/Libraries/LibWeb/WebContentClient.cpp @@ -49,9 +49,7 @@ void WebContentClient::handle(const Messages::WebContentClient::DidInvalidateCon void WebContentClient::handle(const Messages::WebContentClient::DidChangeSelection&) { -#if SPAM_DEBUG - dbgln("handle: WebContentClient::DidChangeSelection!"); -#endif + dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidChangeSelection!"); m_view.notify_server_did_change_selection({}); } @@ -105,9 +103,7 @@ void WebContentClient::handle(const Messages::WebContentClient::DidHoverLink& me void WebContentClient::handle(const Messages::WebContentClient::DidUnhoverLink&) { -#if SPAM_DEBUG - dbgln("handle: WebContentClient::DidUnhoverLink!"); -#endif + dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidUnhoverLink!"); m_view.notify_server_did_unhover_link({}); } diff --git a/Userland/Services/LookupServer/LookupServer.cpp b/Userland/Services/LookupServer/LookupServer.cpp index cac9f0f28e..0f8622cba9 100644 --- a/Userland/Services/LookupServer/LookupServer.cpp +++ b/Userland/Services/LookupServer/LookupServer.cpp @@ -113,9 +113,7 @@ void LookupServer::load_etc_hosts() Vector<DNSAnswer> LookupServer::lookup(const DNSName& name, unsigned short record_type) { -#if LOOKUPSERVER_DEBUG - dbgln("Got request for '{}'", name.as_string()); -#endif + dbgln_if(LOOKUPSERVER_DEBUG, "Got request for '{}'", name.as_string()); Vector<DNSAnswer> answers; auto add_answer = [&](const DNSAnswer& answer) { @@ -144,9 +142,7 @@ Vector<DNSAnswer> LookupServer::lookup(const DNSName& name, unsigned short recor for (auto& answer : cached_answers.value()) { // TODO: Actually remove expired answers from the cache. if (answer.type() == record_type && !answer.has_expired()) { -#if LOOKUPSERVER_DEBUG - dbgln("Cache hit: {} -> {}", name.as_string(), answer.record_data()); -#endif + dbgln_if(LOOKUPSERVER_DEBUG, "Cache hit: {} -> {}", name.as_string(), answer.record_data()); add_answer(answer); } } @@ -156,9 +152,7 @@ Vector<DNSAnswer> LookupServer::lookup(const DNSName& name, unsigned short recor // Third, ask the upstream nameservers. for (auto& nameserver : m_nameservers) { -#if LOOKUPSERVER_DEBUG - dbgln("Doing lookup using nameserver '{}'", nameserver); -#endif + dbgln_if(LOOKUPSERVER_DEBUG, "Doing lookup using nameserver '{}'", nameserver); bool did_get_response = false; int retries = 3; Vector<DNSAnswer> upstream_answers; diff --git a/Userland/Services/Taskbar/TaskbarWindow.cpp b/Userland/Services/Taskbar/TaskbarWindow.cpp index 25e25a2e2e..a6dd4da3f1 100644 --- a/Userland/Services/Taskbar/TaskbarWindow.cpp +++ b/Userland/Services/Taskbar/TaskbarWindow.cpp @@ -240,12 +240,12 @@ void TaskbarWindow::wm_event(GUI::WMEvent& event) WindowIdentifier identifier { event.client_id(), event.window_id() }; switch (event.type()) { case GUI::Event::WM_WindowRemoved: { -#if EVENT_DEBUG - auto& removed_event = static_cast<GUI::WMWindowRemovedEvent&>(event); - dbgln("WM_WindowRemoved: client_id={}, window_id={}", - removed_event.client_id(), - removed_event.window_id()); -#endif + if constexpr (EVENT_DEBUG) { + auto& removed_event = static_cast<GUI::WMWindowRemovedEvent&>(event); + dbgln("WM_WindowRemoved: client_id={}, window_id={}", + removed_event.client_id(), + removed_event.window_id()); + } if (auto* window = WindowList::the().window(identifier)) remove_window_button(*window, true); WindowList::the().remove_window(identifier); @@ -253,13 +253,13 @@ void TaskbarWindow::wm_event(GUI::WMEvent& event) break; } case GUI::Event::WM_WindowRectChanged: { -#if EVENT_DEBUG - auto& changed_event = static_cast<GUI::WMWindowRectChangedEvent&>(event); - dbgln("WM_WindowRectChanged: client_id={}, window_id={}, rect={}", - changed_event.client_id(), - changed_event.window_id(), - changed_event.rect()); -#endif + if constexpr (EVENT_DEBUG) { + auto& changed_event = static_cast<GUI::WMWindowRectChangedEvent&>(event); + dbgln("WM_WindowRectChanged: client_id={}, window_id={}, rect={}", + changed_event.client_id(), + changed_event.window_id(), + changed_event.rect()); + } break; } @@ -274,15 +274,15 @@ void TaskbarWindow::wm_event(GUI::WMEvent& event) case GUI::Event::WM_WindowStateChanged: { auto& changed_event = static_cast<GUI::WMWindowStateChangedEvent&>(event); -#if EVENT_DEBUG - dbgln("WM_WindowStateChanged: client_id={}, window_id={}, title={}, rect={}, is_active={}, is_minimized={}", - changed_event.client_id(), - changed_event.window_id(), - changed_event.title(), - changed_event.rect(), - changed_event.is_active(), - changed_event.is_minimized()); -#endif + if constexpr (EVENT_DEBUG) { + dbgln("WM_WindowStateChanged: client_id={}, window_id={}, title={}, rect={}, is_active={}, is_minimized={}", + changed_event.client_id(), + changed_event.window_id(), + changed_event.title(), + changed_event.rect(), + changed_event.is_active(), + changed_event.is_minimized()); + } if (changed_event.window_type() != GUI::WindowType::Normal || changed_event.is_frameless()) { if (auto* window = WindowList::the().window(identifier)) remove_window_button(*window, false); diff --git a/Userland/Services/WindowServer/Compositor.cpp b/Userland/Services/WindowServer/Compositor.cpp index 6d61f55ca3..b28e1288ce 100644 --- a/Userland/Services/WindowServer/Compositor.cpp +++ b/Userland/Services/WindowServer/Compositor.cpp @@ -865,9 +865,7 @@ void Compositor::recompute_occlusions() return IterationDecision::Continue; }); -#if OCCLUSIONS_DEBUG - dbgln("OCCLUSIONS:"); -#endif + dbgln_if(OCCLUSIONS_DEBUG, "OCCLUSIONS:"); auto screen_rect = Screen::the().rect(); diff --git a/Userland/Services/WindowServer/EventLoop.cpp b/Userland/Services/WindowServer/EventLoop.cpp index 632a5ac1e2..5bc5b4a062 100644 --- a/Userland/Services/WindowServer/EventLoop.cpp +++ b/Userland/Services/WindowServer/EventLoop.cpp @@ -97,9 +97,7 @@ void EventLoop::drain_mouse() return; for (size_t i = 0; i < npackets; ++i) { auto& packet = packets[i]; -#if WSMESSAGELOOP_DEBUG - dbgln("EventLoop: Mouse X {}, Y {}, Z {}, relative={}", packet.x, packet.y, packet.z, packet.is_relative); -#endif + dbgln_if(WSMESSAGELOOP_DEBUG, "EventLoop: Mouse X {}, Y {}, Z {}, relative={}", packet.x, packet.y, packet.z, packet.is_relative); buttons = packet.buttons; state.is_relative = packet.is_relative; @@ -115,9 +113,7 @@ void EventLoop::drain_mouse() if (buttons != state.buttons) { state.buttons = buttons; -#if WSMESSAGELOOP_DEBUG - dbgln("EventLoop: Mouse Button Event"); -#endif + dbgln_if(WSMESSAGELOOP_DEBUG, "EventLoop: Mouse Button Event"); screen.on_receive_mouse_data(state); if (state.is_relative) { state.x = 0; diff --git a/Userland/Services/WindowServer/Screen.cpp b/Userland/Services/WindowServer/Screen.cpp index e019dd07ea..381581f5fd 100644 --- a/Userland/Services/WindowServer/Screen.cpp +++ b/Userland/Services/WindowServer/Screen.cpp @@ -124,14 +124,10 @@ void Screen::on_receive_mouse_data(const MousePacket& packet) auto prev_location = m_physical_cursor_location / m_scale_factor; if (packet.is_relative) { m_physical_cursor_location.move_by(packet.x * m_acceleration_factor, packet.y * m_acceleration_factor); -#if WSSCREEN_DEBUG - dbgln("Screen: New Relative mouse point @ {}", m_physical_cursor_location); -#endif + dbgln_if(WSSCREEN_DEBUG, "Screen: New Relative mouse point @ {}", m_physical_cursor_location); } else { m_physical_cursor_location = { packet.x * physical_width() / 0xffff, packet.y * physical_height() / 0xffff }; -#if WSSCREEN_DEBUG - dbgln("Screen: New Absolute mouse point @ {}", m_physical_cursor_location); -#endif + dbgln_if(WSSCREEN_DEBUG, "Screen: New Absolute mouse point @ {}", m_physical_cursor_location); } m_physical_cursor_location.constrain(physical_rect()); |