diff --git a/AK/Debug.h b/AK/Debug.h index 5e59789db6..3184aae2b6 100644 --- a/AK/Debug.h +++ b/AK/Debug.h @@ -297,3 +297,57 @@ constexpr bool debug_gzip = true; #else constexpr bool debug_gzip = false; #endif + +#ifdef CNETWORKJOB_DEBUG +constexpr bool debug_cnetworkjob = true; +#else +constexpr bool debug_cnetworkjob = false; +#endif + +#ifdef CSOCKET_DEBUG +constexpr bool debug_csocket = true; +#else +constexpr bool debug_csocket = false; +#endif + +#ifdef SAFE_SYSCALL_DEBUG +constexpr bool debug_safe_syscall = true; +#else +constexpr bool debug_safe_syscall = false; +#endif + +#ifdef GHASH_PROCESS_DEBUG +constexpr bool debug_ghash_process = true; +#else +constexpr bool debug_ghash_process = false; +#endif + +#ifdef NT_DEBUG +constexpr bool debug_nt = true; +#else +constexpr bool debug_nt = false; +#endif + +#ifdef CRYPTO_DEBUG +constexpr bool debug_crypto = true; +#else +constexpr bool debug_crypto = false; +#endif + +#ifdef DWARF_DEBUG +constexpr bool debug_dwarf = true; +#else +constexpr bool debug_dwarf = false; +#endif + +#ifdef DEBUG_HUNKS +constexpr bool debug_hunks = true; +#else +constexpr bool debug_hunks = false; +#endif + +#ifdef JOB_DEBUG +constexpr bool debug_job = true; +#else +constexpr bool debug_job = false; +#endif diff --git a/AK/IPv4Address.h b/AK/IPv4Address.h index 504ea2f863..4f557f8424 100644 --- a/AK/IPv4Address.h +++ b/AK/IPv4Address.h @@ -148,6 +148,14 @@ inline const LogStream& operator<<(const LogStream& stream, const IPv4Address& v return stream << value.to_string(); } +template<> +struct Formatter : Formatter { + void format(FormatBuilder& builder, IPv4Address value) + { + return Formatter::format(builder, value.to_string()); + } +}; + } using AK::IPv4Address; diff --git a/Userland/Libraries/LibCore/NetworkJob.cpp b/Userland/Libraries/LibCore/NetworkJob.cpp index 0b48a93a72..1c981e3ad9 100644 --- a/Userland/Libraries/LibCore/NetworkJob.cpp +++ b/Userland/Libraries/LibCore/NetworkJob.cpp @@ -24,12 +24,11 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include -//#define CNETWORKJOB_DEBUG - namespace Core { NetworkJob::NetworkJob(OutputStream& output_stream) @@ -56,9 +55,7 @@ void NetworkJob::did_finish(NonnullRefPtr&& response) NonnullRefPtr protector(*this); m_response = move(response); -#ifdef CNETWORKJOB_DEBUG - dbg() << *this << " job did_finish!"; -#endif + dbgln("{} job did_finish", *this); ASSERT(on_finish); on_finish(true); shutdown(); diff --git a/Userland/Libraries/LibCore/NetworkJob.h b/Userland/Libraries/LibCore/NetworkJob.h index 94ead44805..00b1a553fc 100644 --- a/Userland/Libraries/LibCore/NetworkJob.h +++ b/Userland/Libraries/LibCore/NetworkJob.h @@ -81,3 +81,7 @@ private: const char* to_string(NetworkJob::Error); } + +template<> +struct AK::Formatter : Formatter { +}; diff --git a/Userland/Libraries/LibCore/Socket.cpp b/Userland/Libraries/LibCore/Socket.cpp index 4ced6734b1..3adbed2d4f 100644 --- a/Userland/Libraries/LibCore/Socket.cpp +++ b/Userland/Libraries/LibCore/Socket.cpp @@ -25,6 +25,7 @@ */ #include +#include #include #include #include @@ -37,8 +38,6 @@ #include #include -//#define CSOCKET_DEBUG - namespace Core { Socket::Socket(Type type, Object* parent) @@ -80,9 +79,7 @@ bool Socket::connect(const String& hostname, int port) } IPv4Address host_address((const u8*)hostent->h_addr_list[0]); -#ifdef CSOCKET_DEBUG - dbg() << "Socket::connect: Resolved '" << hostname << "' to " << host_address; -#endif + dbgln("Socket::connect: Resolved '{}' to {}", hostname, host_address); return connect(host_address, port); } @@ -101,9 +98,7 @@ bool Socket::connect(const SocketAddress& address, int port) { ASSERT(!is_connected()); ASSERT(address.type() == SocketAddress::Type::IPv4); -#ifdef CSOCKET_DEBUG - dbg() << *this << " connecting to " << address << "..."; -#endif + dbgln("{} connecting to {}...", *this, address); ASSERT(port > 0 && port <= 65535); @@ -124,9 +119,7 @@ bool Socket::connect(const SocketAddress& address) { ASSERT(!is_connected()); ASSERT(address.type() == SocketAddress::Type::Local); -#ifdef CSOCKET_DEBUG - dbg() << *this << " connecting to " << address << "..."; -#endif + dbgln("{} connecting to {}...", *this, address); sockaddr_un saddr; saddr.sun_family = AF_LOCAL; @@ -145,9 +138,7 @@ bool Socket::connect(const SocketAddress& address) bool Socket::common_connect(const struct sockaddr* addr, socklen_t addrlen) { auto connected = [this] { -#ifdef CSOCKET_DEBUG - dbg() << *this << " connected!"; -#endif + dbgln("{} connected!", *this); if (!m_connected) { m_connected = true; ensure_read_notifier(); @@ -162,9 +153,7 @@ bool Socket::common_connect(const struct sockaddr* addr, socklen_t addrlen) int rc = ::connect(fd(), addr, addrlen); if (rc < 0) { if (errno == EINPROGRESS) { -#ifdef CSOCKET_DEBUG - dbg() << *this << " connection in progress (EINPROGRESS)"; -#endif + dbgln("{} connection in progress (EINPROGRESS)", *this); m_notifier = Notifier::construct(fd(), Notifier::Event::Write, this); m_notifier->on_ready_to_write = move(connected); return true; @@ -174,9 +163,7 @@ bool Socket::common_connect(const struct sockaddr* addr, socklen_t addrlen) errno = saved_errno; return false; } -#ifdef CSOCKET_DEBUG - dbg() << *this << " connected ok!"; -#endif + dbgln("{} connected ok!", *this); connected(); return true; } diff --git a/Userland/Libraries/LibCore/Socket.h b/Userland/Libraries/LibCore/Socket.h index fcbd2af31d..1ecb32010b 100644 --- a/Userland/Libraries/LibCore/Socket.h +++ b/Userland/Libraries/LibCore/Socket.h @@ -87,3 +87,7 @@ private: }; } + +template<> +struct AK::Formatter : Formatter { +}; diff --git a/Userland/Libraries/LibCore/SocketAddress.h b/Userland/Libraries/LibCore/SocketAddress.h index 717f4e8fd3..4a5334225b 100644 --- a/Userland/Libraries/LibCore/SocketAddress.h +++ b/Userland/Libraries/LibCore/SocketAddress.h @@ -113,3 +113,11 @@ private: const LogStream& operator<<(const LogStream&, const SocketAddress&); } + +template<> +struct AK::Formatter : Formatter { + void format(FormatBuilder& builder, const Core::SocketAddress& value) + { + return Formatter::format(builder, value.to_string()); + } +}; diff --git a/Userland/Libraries/LibCore/SyscallUtils.h b/Userland/Libraries/LibCore/SyscallUtils.h index 1c24efd9c2..5815fb67cd 100644 --- a/Userland/Libraries/LibCore/SyscallUtils.h +++ b/Userland/Libraries/LibCore/SyscallUtils.h @@ -26,6 +26,7 @@ #pragma once +#include #include #include #include @@ -41,10 +42,11 @@ inline int safe_syscall(Syscall syscall, Args&&... args) for (;;) { int sysret = syscall(forward(args)...); if (sysret == -1) { -#ifdef SAFE_SYSCALL_DEBUG - int saved_errno = errno; - dbg() << "Core::safe_syscall: " << sysret << " (" << saved_errno << ": " << strerror(saved_errno) << ")"; -#endif + if constexpr (debug_safe_syscall) { + int saved_errno = errno; + dbgln("Core::safe_syscall: {} ({}: {})", sysret, saved_errno, strerror(saved_errno)); + } + if (errno == EINTR) continue; ASSERT_NOT_REACHED(); diff --git a/Userland/Libraries/LibCrypto/Authentication/GHash.cpp b/Userland/Libraries/LibCrypto/Authentication/GHash.cpp index d932ae51f4..9ac2247a77 100644 --- a/Userland/Libraries/LibCrypto/Authentication/GHash.cpp +++ b/Userland/Libraries/LibCrypto/Authentication/GHash.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -88,21 +89,18 @@ GHash::TagType GHash::process(ReadonlyBytes aad, ReadonlyBytes cipher) auto high = [](u64 value) -> u32 { return value >> 32; }; auto low = [](u64 value) -> u32 { return value & 0xffffffff; }; -#ifdef GHASH_PROCESS_DEBUG - dbg() << "AAD bits: " << high(aad_bits) << " : " << low(aad_bits); - dbg() << "Cipher bits: " << high(cipher_bits) << " : " << low(cipher_bits); - - dbg() << "Tag bits: " << tag[0] << " : " << tag[1] << " : " << tag[2] << " : " << tag[3]; -#endif + if constexpr (debug_ghash_process) { + dbgln("AAD bits: {} : {}", high(aad_bits), low(aad_bits)); + dbgln("Cipher bits: {} : {}", high(cipher_bits), low(cipher_bits)); + dbgln("Tag bits: {} : {} : {} : {}", tag[0], tag[1], tag[2], tag[3]); + } tag[0] ^= high(aad_bits); tag[1] ^= low(aad_bits); tag[2] ^= high(cipher_bits); tag[3] ^= low(cipher_bits); -#ifdef GHASH_PROCESS_DEBUG - dbg() << "Tag bits: " << tag[0] << " : " << tag[1] << " : " << tag[2] << " : " << tag[3]; -#endif + dbgln("Tag bits: {} : {} : {} : {}", tag[0], tag[1], tag[2], tag[3]); galois_multiply(tag, m_key, tag); diff --git a/Userland/Libraries/LibCrypto/NumberTheory/ModularFunctions.cpp b/Userland/Libraries/LibCrypto/NumberTheory/ModularFunctions.cpp index 9f6e49ef45..71f16d284e 100644 --- a/Userland/Libraries/LibCrypto/NumberTheory/ModularFunctions.cpp +++ b/Userland/Libraries/LibCrypto/NumberTheory/ModularFunctions.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include namespace Crypto { @@ -230,9 +231,7 @@ UnsignedBigInteger LCM(const UnsignedBigInteger& a, const UnsignedBigInteger& b) UnsignedBigInteger::divide_without_allocation(a, gcd_output, temp_1, temp_2, temp_3, temp_4, temp_quotient, temp_remainder); UnsignedBigInteger::multiply_without_allocation(temp_quotient, b, temp_1, temp_2, temp_3, temp_4, output); -#ifdef NT_DEBUG - dbg() << "quot: " << temp_quotient << " rem: " << temp_remainder << " out: " << output; -#endif + dbgln("quot: {} rem: {} out: {}", temp_quotient, temp_remainder, output); return output; } diff --git a/Userland/Libraries/LibCrypto/PK/RSA.cpp b/Userland/Libraries/LibCrypto/PK/RSA.cpp index 452da97acc..d6e2320bdd 100644 --- a/Userland/Libraries/LibCrypto/PK/RSA.cpp +++ b/Userland/Libraries/LibCrypto/PK/RSA.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -115,9 +116,7 @@ RSA::KeyPairType RSA::parse_rsa_key(ReadonlyBytes in) void RSA::encrypt(ReadonlyBytes in, Bytes& out) { -#ifdef CRYPTO_DEBUG - dbg() << "in size: " << in.size(); -#endif + dbgln("in size: {}", in.size()); auto in_integer = UnsignedBigInteger::import_data(in.data(), in.size()); if (!(in_integer < m_public_key.modulus())) { dbgln("value too large for key"); @@ -231,9 +230,7 @@ VerificationConsistency RSA_EMSA_PSS::verify(ReadonlyBytes in) void RSA_PKCS1_EME::encrypt(ReadonlyBytes in, Bytes& out) { auto mod_len = (m_public_key.modulus().trimmed_length() * sizeof(u32) * 8 + 7) / 8; -#ifdef CRYPTO_DEBUG - dbg() << "key size: " << mod_len; -#endif + dbgln("key size: {}", mod_len); if (in.size() > mod_len - 11) { dbgln("message too long :("); out = out.trim(0); @@ -265,9 +262,7 @@ void RSA_PKCS1_EME::encrypt(ReadonlyBytes in, Bytes& out) out.overwrite(3 + ps_length, in.data(), in.size()); out = out.trim(3 + ps_length + in.size()); // should be a single block -#ifdef CRYPTO_DEBUG - dbg() << "padded output size: " << 3 + ps_length + in.size() << " buffer size: " << out.size(); -#endif + dbgln("padded output size: {} buffer size: {}", 3 + ps_length + in.size(), out.size()); RSA::encrypt(out, out); } diff --git a/Userland/Libraries/LibDebug/Dwarf/LineProgram.cpp b/Userland/Libraries/LibDebug/Dwarf/LineProgram.cpp index 2bc89a885f..180c0f7c95 100644 --- a/Userland/Libraries/LibDebug/Dwarf/LineProgram.cpp +++ b/Userland/Libraries/LibDebug/Dwarf/LineProgram.cpp @@ -25,11 +25,10 @@ */ #include "LineProgram.h" +#include #include #include -//#define DWARF_DEBUG - namespace Debug::Dwarf { LineProgram::LineProgram(InputMemoryStream& stream) @@ -236,10 +235,10 @@ void LineProgram::handle_sepcial_opcode(u8 opcode) m_address += address_increment; m_line += line_increment; -#ifdef DWARF_DEBUG - dbgln("Special adjusted_opcode: {}, address_increment: {}, line_increment: {}", adjusted_opcode, address_increment, line_increment); - dbg() << "Address is now:" << (void*)m_address << ", and line is: " << m_source_files[m_file_index].name << ":" << m_line; -#endif + if constexpr (debug_dwarf) { + dbgln("Special adjusted_opcode: {}, address_increment: {}, line_increment: {}", adjusted_opcode, address_increment, line_increment); + dbgln("Address is now: {:p}, and line is: {}:{}", m_address, m_source_files[m_file_index].name, m_line); + } append_to_line_info(); } @@ -252,9 +251,7 @@ void LineProgram::run_program() u8 opcode = 0; m_stream >> opcode; -#ifdef DWARF_DEBUG - dbg() << (void*)(m_stream.offset() - 1) << ": opcode: " << opcode; -#endif + dbgln("{:p}: opcode: {}", m_stream.offset() - 1, opcode); if (opcode == 0) { handle_extended_opcode(); diff --git a/Userland/Libraries/LibDiff/Hunks.cpp b/Userland/Libraries/LibDiff/Hunks.cpp index d806b2b386..2d9c77405a 100644 --- a/Userland/Libraries/LibDiff/Hunks.cpp +++ b/Userland/Libraries/LibDiff/Hunks.cpp @@ -25,8 +25,7 @@ */ #include "Hunks.h" - -// #define DEBUG_HUNKS +#include namespace Diff { Vector parse_hunks(const String& diff) @@ -78,21 +77,19 @@ Vector parse_hunks(const String& diff) hunks.append(hunk); } -#ifdef DEBUG_HUNKS - for (const auto& hunk : hunks) { - dbgln("Hunk location:"); - dbg() << "orig: " << hunk.original_start_line; - dbg() << "target: " << hunk.target_start_line; - dbgln("removed:"); - for (const auto& line : hunk.removed_lines) { - dbg() << "- " << line; - } - dbgln("added:"); - for (const auto& line : hunk.added_lines) { - dbg() << "+ " << line; + if constexpr (debug_hunks) { + for (const auto& hunk : hunks) { + dbgln("Hunk location:"); + dbgln(" orig: {}", hunk.original_start_line); + dbgln(" target: {}", hunk.target_start_line); + dbgln(" removed:"); + for (const auto& line : hunk.removed_lines) + dbgln("- {}", line); + dbgln(" added:"); + for (const auto& line : hunk.added_lines) + dbgln("+ {}", line); } } -#endif return hunks; } diff --git a/Userland/Libraries/LibGemini/Job.cpp b/Userland/Libraries/LibGemini/Job.cpp index c260951e70..ee75cdc742 100644 --- a/Userland/Libraries/LibGemini/Job.cpp +++ b/Userland/Libraries/LibGemini/Job.cpp @@ -24,13 +24,12 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include #include -//#define JOB_DEBUG - namespace Gemini { Job::Job(const GeminiRequest& request, OutputStream& output_stream) @@ -67,10 +66,11 @@ void Job::on_socket_connected() return; m_sent_data = true; auto raw_request = m_request.to_raw_request(); -#ifdef JOB_DEBUG - dbgln("Job: raw_request:"); - dbg() << String::copy(raw_request).characters(); -#endif + + if constexpr (debug_job) { + dbgln("Job: raw_request:"); + dbgln("{}", String::copy(raw_request)); + } bool success = write(raw_request); if (!success) deferred_invoke([this](auto&) { did_fail(Core::NetworkJob::Error::TransmissionFailed); });