diff --git a/AK/Debug.h b/AK/Debug.h index 80ac26ec837..5e59789db66 100644 --- a/AK/Debug.h +++ b/AK/Debug.h @@ -255,3 +255,45 @@ constexpr bool debug_ptmx = true; #else constexpr bool debug_ptmx = false; #endif + +#ifdef TTY_DEBUG +constexpr bool debug_tty = true; +#else +constexpr bool debug_tty = false; +#endif + +#ifdef CONTIGUOUS_VMOBJECT_DEBUG +constexpr bool debug_contiguous_vmobject = true; +#else +constexpr bool debug_contiguous_vmobject = false; +#endif + +#ifdef VRA_DEBUG +constexpr bool debug_vra = true; +#else +constexpr bool debug_vra = false; +#endif + +#ifdef COPY_DEBUG +constexpr bool debug_copy = true; +#else +constexpr bool debug_copy = false; +#endif + +#ifdef DEBUG_CURSOR_TOOL +constexpr bool debug_cursor_tool = true; +#else +constexpr bool debug_cursor_tool = false; +#endif + +#ifdef DEBUG_FILE_CONTENT +constexpr bool debug_file_content = true; +#else +constexpr bool debug_file_content = false; +#endif + +#ifdef DEBUG_GZIP +constexpr bool debug_gzip = true; +#else +constexpr bool debug_gzip = false; +#endif diff --git a/Kernel/TTY/TTY.cpp b/Kernel/TTY/TTY.cpp index b7425f9b562..2ffcdaefb35 100644 --- a/Kernel/TTY/TTY.cpp +++ b/Kernel/TTY/TTY.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -304,19 +305,19 @@ void TTY::flush_input() void TTY::set_termios(const termios& t) { m_termios = t; -#ifdef TTY_DEBUG - dbg() << tty_name() << " set_termios: " - << "ECHO=" << should_echo_input() - << ", ISIG=" << should_generate_signals() - << ", ICANON=" << in_canonical_mode() - << ", ECHOE=" << ((m_termios.c_lflag & ECHOE) != 0) - << ", ECHOK=" << ((m_termios.c_lflag & ECHOK) != 0) - << ", ECHONL=" << ((m_termios.c_lflag & ECHONL) != 0) - << ", ISTRIP=" << ((m_termios.c_iflag & ISTRIP) != 0) - << ", ICRNL=" << ((m_termios.c_iflag & ICRNL) != 0) - << ", INLCR=" << ((m_termios.c_iflag & INLCR) != 0) - << ", IGNCR=" << ((m_termios.c_iflag & IGNCR) != 0); -#endif + + dbgln("{} set_termios: ECHO={}, ISIG={}, ICANON={}, ECHOE={}, ECHOK={}, ECHONL={}, ISTRIP={}, ICRNL={}, INLCR={}, IGNCR={}", + tty_name(), + should_echo_input(), + should_generate_signals(), + in_canonical_mode(), + ((m_termios.c_lflag & ECHOE) != 0), + ((m_termios.c_lflag & ECHOK) != 0), + ((m_termios.c_lflag & ECHONL) != 0), + ((m_termios.c_iflag & ISTRIP) != 0), + ((m_termios.c_iflag & ICRNL) != 0), + ((m_termios.c_iflag & INLCR) != 0), + ((m_termios.c_iflag & IGNCR) != 0)); } int TTY::ioctl(FileDescription&, unsigned request, FlatPtr arg) diff --git a/Kernel/VM/AnonymousVMObject.cpp b/Kernel/VM/AnonymousVMObject.cpp index e1ef68bc480..3bd055e69e4 100644 --- a/Kernel/VM/AnonymousVMObject.cpp +++ b/Kernel/VM/AnonymousVMObject.cpp @@ -24,14 +24,12 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include #include -//#define COMMIT_DEBUG -//#define PAGE_FAULT_DEBUG - namespace Kernel { RefPtr AnonymousVMObject::clone() @@ -474,9 +472,7 @@ PageFaultResponse AnonymousVMObject::handle_cow_fault(size_t page_index, Virtual } u8* dest_ptr = MM.quickmap_page(*page); -#ifdef PAGE_FAULT_DEBUG - dbg() << " >> COW " << page->paddr() << " <- " << page_slot->paddr(); -#endif + dbgln(" >> COW {} <- {}", page->paddr(), page_slot->paddr()); { SmapDisabler disabler; void* fault_at; diff --git a/Kernel/VM/ContiguousVMObject.cpp b/Kernel/VM/ContiguousVMObject.cpp index 13238a6041b..b17dcbd59f2 100644 --- a/Kernel/VM/ContiguousVMObject.cpp +++ b/Kernel/VM/ContiguousVMObject.cpp @@ -24,14 +24,13 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include namespace Kernel { -//#define CONTIGUOUS_VMOBJECT_DEBUG - NonnullRefPtr ContiguousVMObject::create_with_size(size_t size) { return adopt(*new ContiguousVMObject(size)); @@ -43,9 +42,7 @@ ContiguousVMObject::ContiguousVMObject(size_t size) auto contiguous_physical_pages = MM.allocate_contiguous_supervisor_physical_pages(size); for (size_t i = 0; i < page_count(); i++) { physical_pages()[i] = contiguous_physical_pages[i]; -#ifdef CONTIGUOUS_VMOBJECT_DEBUG - dbg() << "Contiguous page[" << i << "]: " << physical_pages()[i]->paddr(); -#endif + dbgln("Contiguous page[{}]: {}", i, physical_pages()[i]->paddr()); } } diff --git a/Kernel/VM/RangeAllocator.cpp b/Kernel/VM/RangeAllocator.cpp index e8454e8a7f7..44ed6a74005 100644 --- a/Kernel/VM/RangeAllocator.cpp +++ b/Kernel/VM/RangeAllocator.cpp @@ -25,12 +25,12 @@ */ #include +#include #include #include #include #include -//#define VRA_DEBUG #define VM_GUARD_PAGES namespace Kernel { @@ -78,11 +78,18 @@ Vector Range::carve(const Range& taken) parts.append({ base(), taken.base().get() - base().get() }); if (taken.end() < end()) parts.append({ taken.end(), end().get() - taken.end().get() }); -#ifdef VRA_DEBUG - dbg() << "VRA: carve: take " << String::format("%x", taken.base().get()) << "-" << String::format("%x", taken.end().get() - 1) << " from " << String::format("%x", base().get()) << "-" << String::format("%x", end().get() - 1); - for (size_t i = 0; i < parts.size(); ++i) - dbg() << " " << String::format("%x", parts[i].base().get()) << "-" << String::format("%x", parts[i].end().get() - 1); -#endif + + if constexpr (debug_vra) { + dbgln("VRA: carve: take {:x}-{:x} from {:x}-{:x}", + taken.base().get(), + taken.end().get() - 1, + base().get(), + end().get() - 1); + + for (size_t i = 0; i < parts.size(); ++i) + dbgln(" {:x}-{:x}", parts[i].base().get(), parts[i].end().get() - 1); + } + return parts; } @@ -122,17 +129,15 @@ Range RangeAllocator::allocate_anywhere(size_t size, size_t alignment) Range allocated_range(VirtualAddress(aligned_base), size); if (available_range == allocated_range) { -#ifdef VRA_DEBUG - dbg() << "VRA: Allocated perfect-fit anywhere(" << String::format("%zu", size) << ", " << String::format("%zu", alignment) << "): " << String::format("%x", allocated_range.base().get()); -#endif + dbgln("VRA: Allocated perfect-fit anywhere({}, {}): {}", size, alignment, allocated_range.base().get()); m_available_ranges.remove(i); return allocated_range; } carve_at_index(i, allocated_range); -#ifdef VRA_DEBUG - dbg() << "VRA: Allocated anywhere(" << String::format("%zu", size) << ", " << String::format("%zu", alignment) << "): " << String::format("%x", allocated_range.base().get()); - dump(); -#endif + if constexpr (debug_vra) { + dbgln("VRA: Allocated anywhere({}, {}): {}", size, alignment, allocated_range.base().get()); + dump(); + } return allocated_range; } klog() << "VRA: Failed to allocate anywhere: " << size << ", " << alignment; @@ -155,10 +160,12 @@ Range RangeAllocator::allocate_specific(VirtualAddress base, size_t size) return allocated_range; } carve_at_index(i, allocated_range); -#ifdef VRA_DEBUG - dbg() << "VRA: Allocated specific(" << size << "): " << String::format("%x", available_range.base().get()); - dump(); -#endif + + if constexpr (debug_vra) { + dbgln("VRA: Allocated specific({}): {}", size, available_range.base().get()); + dump(); + } + return allocated_range; } dbgln("VRA: Failed to allocate specific range: {}({})", base, size); @@ -172,10 +179,10 @@ void RangeAllocator::deallocate(Range range) ASSERT(range.size()); ASSERT(range.base() < range.end()); -#ifdef VRA_DEBUG - dbg() << "VRA: Deallocate: " << String::format("%x", range.base().get()) << "(" << range.size() << ")"; - dump(); -#endif + if constexpr (debug_vra) { + dbgln("VRA: Deallocate: {}({})", range.base().get(), range.size()); + dump(); + } ASSERT(!m_available_ranges.is_empty()); diff --git a/Kernel/VM/Region.cpp b/Kernel/VM/Region.cpp index 41c59faab24..54828e4e96b 100644 --- a/Kernel/VM/Region.cpp +++ b/Kernel/VM/Region.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -35,8 +36,6 @@ #include #include -//#define PAGE_FAULT_DEBUG - namespace Kernel { Region::Region(const Range& range, NonnullRefPtr vmobject, size_t offset_in_vmobject, const String& name, u8 access, bool cacheable, bool kernel, bool shared) @@ -411,9 +410,7 @@ PageFaultResponse Region::handle_fault(const PageFault& fault) return PageFaultResponse::ShouldCrash; } if (vmobject().is_inode()) { -#ifdef PAGE_FAULT_DEBUG - dbg() << "NP(inode) fault in Region{" << this << "}[" << page_index_in_region << "]"; -#endif + dbgln("NP(inode) fault in Region({})[{}]", this, page_index_in_region); return handle_inode_fault(page_index_in_region); } @@ -438,14 +435,10 @@ PageFaultResponse Region::handle_fault(const PageFault& fault) } ASSERT(fault.type() == PageFault::Type::ProtectionViolation); if (fault.access() == PageFault::Access::Write && is_writable() && should_cow(page_index_in_region)) { -#ifdef PAGE_FAULT_DEBUG - dbg() << "PV(cow) fault in Region{" << this << "}[" << page_index_in_region << "] at " << fault.vaddr(); -#endif + dbgln("PV(cow) fault in Region({})[{}] at {}", this, page_index_in_region, fault.vaddr()); auto* phys_page = physical_page(page_index_in_region); if (phys_page->is_shared_zero_page() || phys_page->is_lazy_committed_page()) { -#ifdef PAGE_FAULT_DEBUG - dbg() << "NP(zero) fault in Region{" << this << "}[" << page_index_in_region << "] at " << fault.vaddr(); -#endif + dbgln("NP(zero) fault in Region({})[{}] at {}", this, page_index_in_region, fault.vaddr()); return handle_zero_fault(page_index_in_region); } return handle_cow_fault(page_index_in_region); @@ -479,18 +472,14 @@ PageFaultResponse Region::handle_zero_fault(size_t page_index_in_region) if (page_slot->is_lazy_committed_page()) { page_slot = static_cast(*m_vmobject).allocate_committed_page(page_index_in_vmobject); -#ifdef PAGE_FAULT_DEBUG - dbg() << " >> ALLOCATED COMMITTED " << page_slot->paddr(); -#endif + dbgln(" >> ALLOCATED COMMITTED {}", page_slot->paddr()); } else { page_slot = MM.allocate_user_physical_page(MemoryManager::ShouldZeroFill::Yes); if (page_slot.is_null()) { klog() << "MM: handle_zero_fault was unable to allocate a physical page"; return PageFaultResponse::OutOfMemory; } -#ifdef PAGE_FAULT_DEBUG - dbg() << " >> ALLOCATED " << page_slot->paddr(); -#endif + dbgln(" >> ALLOCATED {}", page_slot->paddr()); } if (!remap_vmobject_page(page_index_in_vmobject)) { @@ -529,14 +518,10 @@ PageFaultResponse Region::handle_inode_fault(size_t page_index_in_region) auto page_index_in_vmobject = translate_to_vmobject_page(page_index_in_region); auto& vmobject_physical_page_entry = inode_vmobject.physical_pages()[page_index_in_vmobject]; -#ifdef PAGE_FAULT_DEBUG - dbg() << "Inode fault in " << name() << " page index: " << page_index_in_region; -#endif + dbgln("Inode fault in {} page index: {}", name(), page_index_in_region); if (!vmobject_physical_page_entry.is_null()) { -#ifdef PAGE_FAULT_DEBUG - dbg() << ("MM: page_in_from_inode() but page already present. Fine with me!"); -#endif + dbgln("MM: page_in_from_inode() 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/Spreadsheet/Spreadsheet.cpp b/Userland/Applications/Spreadsheet/Spreadsheet.cpp index 0d20b22fddb..4fec43e653c 100644 --- a/Userland/Applications/Spreadsheet/Spreadsheet.cpp +++ b/Userland/Applications/Spreadsheet/Spreadsheet.cpp @@ -28,6 +28,7 @@ #include "JSIntegration.h" #include "Workbook.h" #include +#include #include #include #include @@ -354,9 +355,7 @@ void Sheet::copy_cells(Vector from, Vector to, Optional("Paste from '{}' to '{}'", position.to_url(), target.to_url()); copy_to(position, resolve_relative_to.has_value() ? offset_relative_to(target, position, resolve_relative_to.value()) : target); } @@ -367,9 +366,7 @@ void Sheet::copy_cells(Vector from, Vector to, Optional("Paste from '{}' to '{}'", source.to_url(), position.to_url()); copy_to(source, resolve_relative_to.has_value() ? offset_relative_to(position, source, resolve_relative_to.value()) : position); } return; diff --git a/Userland/DevTools/HackStudio/CursorTool.cpp b/Userland/DevTools/HackStudio/CursorTool.cpp index b59963af7c6..aed955e8885 100644 --- a/Userland/DevTools/HackStudio/CursorTool.cpp +++ b/Userland/DevTools/HackStudio/CursorTool.cpp @@ -28,11 +28,10 @@ #include "FormEditorWidget.h" #include "FormWidget.h" #include "WidgetTreeModel.h" +#include #include #include -//#define DEBUG_CURSOR_TOOL - namespace HackStudio { void CursorTool::on_mousedown(GUI::MouseEvent& event) @@ -49,9 +48,7 @@ void CursorTool::on_mousedown(GUI::MouseEvent& event) m_editor.selection().toggle(*result.widget); } else if (!event.modifiers()) { if (!m_editor.selection().contains(*result.widget)) { -#ifdef DEBUG_CURSOR_TOOL - dbg() << "Selection didn't contain " << *result.widget << ", making it the only selected one"; -#endif + dbgln("Selection didn't contain {}, making it the only selected one", *result.widget); m_editor.selection().set(*result.widget); } diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.cpp b/Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.cpp index c8194636f4b..ec61984e54b 100644 --- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.cpp +++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.cpp @@ -26,13 +26,11 @@ #include "ClientConnection.h" #include "AutoComplete.h" +#include #include #include #include -// #define DEBUG_CPP_LANGUAGE_SERVER -// #define DEBUG_FILE_CONTENT - namespace LanguageServers::Cpp { static HashMap> s_connections; @@ -89,9 +87,7 @@ void ClientConnection::handle(const Messages::LanguageServer::FileOpened& messag auto document = GUI::TextDocument::create(&s_default_document_client); document->set_text(content_view); m_open_files.set(message.file_name(), document); -#ifdef DEBUG_FILE_CONTENT - dbg() << document->text(); -#endif + dbgln("{}", document->text()); } void ClientConnection::handle(const Messages::LanguageServer::FileEditInsertText& message) diff --git a/Userland/DevTools/HackStudio/LanguageServers/Shell/ClientConnection.cpp b/Userland/DevTools/HackStudio/LanguageServers/Shell/ClientConnection.cpp index ef856468680..cf71dc2134d 100644 --- a/Userland/DevTools/HackStudio/LanguageServers/Shell/ClientConnection.cpp +++ b/Userland/DevTools/HackStudio/LanguageServers/Shell/ClientConnection.cpp @@ -26,13 +26,11 @@ #include "ClientConnection.h" #include "AutoComplete.h" +#include #include #include #include -// #define DEBUG_SH_LANGUAGE_SERVER -// #define DEBUG_FILE_CONTENT - namespace LanguageServers::Shell { static HashMap> s_connections; @@ -89,9 +87,7 @@ void ClientConnection::handle(const Messages::LanguageServer::FileOpened& messag auto document = GUI::TextDocument::create(&s_default_document_client); document->set_text(content_view); m_open_files.set(message.file_name(), document); -#ifdef DEBUG_FILE_CONTENT - dbg() << document->text(); -#endif + dbgln("{}", document->text()); } void ClientConnection::handle(const Messages::LanguageServer::FileEditInsertText& message) @@ -133,9 +129,7 @@ void ClientConnection::handle(const Messages::LanguageServer::FileEditRemoveText }; document->remove(range); -#ifdef DEBUG_FILE_CONTENT - dbg() << document->text(); -#endif + dbgln("{}", document->text()); } void ClientConnection::handle(const Messages::LanguageServer::AutoCompleteSuggestions& message) diff --git a/Userland/Libraries/LibCore/Gzip.cpp b/Userland/Libraries/LibCore/Gzip.cpp index 49cf14c3a09..afa2bb6319d 100644 --- a/Userland/Libraries/LibCore/Gzip.cpp +++ b/Userland/Libraries/LibCore/Gzip.cpp @@ -25,14 +25,13 @@ */ #include +#include #include #include #include #include #include -//#define DEBUG_GZIP - namespace Core { bool Gzip::is_compressed(const ByteBuffer& data) @@ -103,9 +102,7 @@ static Optional get_gzip_payload(const ByteBuffer& data) } auto new_size = data.size() - current; -#ifdef DEBUG_GZIP - dbg() << "get_gzip_payload: Returning slice from " << current << " with size " << new_size; -#endif + dbgln("get_gzip_payload: Returning slice from {} with size {}", current, new_size); return data.slice(current, new_size); } @@ -113,9 +110,7 @@ Optional Gzip::decompress(const ByteBuffer& data) { ASSERT(is_compressed(data)); -#ifdef DEBUG_GZIP - dbg() << "Gzip::decompress: Decompressing gzip compressed data. Size = " << data.size(); -#endif + dbgln("Gzip::decompress: Decompressing gzip compressed data. size={}", data.size()); auto optional_payload = get_gzip_payload(data); if (!optional_payload.has_value()) { return Optional(); @@ -127,13 +122,13 @@ Optional Gzip::decompress(const ByteBuffer& data) while (true) { unsigned long destination_len = destination.size(); -#ifdef DEBUG_GZIP - dbg() << "Gzip::decompress: Calling puff()\n" - << " destination_data = " << destination.data() << "\n" - << " destination_len = " << destination_len << "\n" - << " source_data = " << source.data() << "\n" - << " source_len = " << source_len; -#endif + if constexpr (debug_gzip) { + dbgln("Gzip::decompress: Calling puff()"); + dbgln(" destination_data = {}", destination.data()); + dbgln(" destination_len = {}", destination_len); + dbgln(" source_data = {}", source.data()); + dbgln(" source_len = {}", source_len); + } auto puff_ret = puff( destination.data(), &destination_len,