1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:47:34 +00:00

Everywhere: Replace a bundle of dbg with dbgln.

These changes are arbitrarily divided into multiple commits to make it
easier to find potentially introduced bugs with git bisect.
This commit is contained in:
asynts 2021-01-15 21:46:23 +01:00 committed by Andreas Kling
parent 27bc48e06c
commit 9229ba0fe9
14 changed files with 130 additions and 80 deletions

View file

@ -297,3 +297,57 @@ constexpr bool debug_gzip = true;
#else #else
constexpr bool debug_gzip = false; constexpr bool debug_gzip = false;
#endif #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

View file

@ -148,6 +148,14 @@ inline const LogStream& operator<<(const LogStream& stream, const IPv4Address& v
return stream << value.to_string(); return stream << value.to_string();
} }
template<>
struct Formatter<IPv4Address> : Formatter<String> {
void format(FormatBuilder& builder, IPv4Address value)
{
return Formatter<String>::format(builder, value.to_string());
}
};
} }
using AK::IPv4Address; using AK::IPv4Address;

View file

@ -24,12 +24,11 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <AK/Debug.h>
#include <LibCore/NetworkJob.h> #include <LibCore/NetworkJob.h>
#include <LibCore/NetworkResponse.h> #include <LibCore/NetworkResponse.h>
#include <stdio.h> #include <stdio.h>
//#define CNETWORKJOB_DEBUG
namespace Core { namespace Core {
NetworkJob::NetworkJob(OutputStream& output_stream) NetworkJob::NetworkJob(OutputStream& output_stream)
@ -56,9 +55,7 @@ void NetworkJob::did_finish(NonnullRefPtr<NetworkResponse>&& response)
NonnullRefPtr<NetworkJob> protector(*this); NonnullRefPtr<NetworkJob> protector(*this);
m_response = move(response); m_response = move(response);
#ifdef CNETWORKJOB_DEBUG dbgln<debug_cnetworkjob>("{} job did_finish", *this);
dbg() << *this << " job did_finish!";
#endif
ASSERT(on_finish); ASSERT(on_finish);
on_finish(true); on_finish(true);
shutdown(); shutdown();

View file

@ -81,3 +81,7 @@ private:
const char* to_string(NetworkJob::Error); const char* to_string(NetworkJob::Error);
} }
template<>
struct AK::Formatter<Core::NetworkJob> : Formatter<Core::Object> {
};

View file

@ -25,6 +25,7 @@
*/ */
#include <AK/ByteBuffer.h> #include <AK/ByteBuffer.h>
#include <AK/Debug.h>
#include <LibCore/Notifier.h> #include <LibCore/Notifier.h>
#include <LibCore/Socket.h> #include <LibCore/Socket.h>
#include <arpa/inet.h> #include <arpa/inet.h>
@ -37,8 +38,6 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <unistd.h> #include <unistd.h>
//#define CSOCKET_DEBUG
namespace Core { namespace Core {
Socket::Socket(Type type, Object* parent) 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]); IPv4Address host_address((const u8*)hostent->h_addr_list[0]);
#ifdef CSOCKET_DEBUG dbgln<debug_csocket>("Socket::connect: Resolved '{}' to {}", hostname, host_address);
dbg() << "Socket::connect: Resolved '" << hostname << "' to " << host_address;
#endif
return connect(host_address, port); return connect(host_address, port);
} }
@ -101,9 +98,7 @@ bool Socket::connect(const SocketAddress& address, int port)
{ {
ASSERT(!is_connected()); ASSERT(!is_connected());
ASSERT(address.type() == SocketAddress::Type::IPv4); ASSERT(address.type() == SocketAddress::Type::IPv4);
#ifdef CSOCKET_DEBUG dbgln<debug_csocket>("{} connecting to {}...", *this, address);
dbg() << *this << " connecting to " << address << "...";
#endif
ASSERT(port > 0 && port <= 65535); ASSERT(port > 0 && port <= 65535);
@ -124,9 +119,7 @@ bool Socket::connect(const SocketAddress& address)
{ {
ASSERT(!is_connected()); ASSERT(!is_connected());
ASSERT(address.type() == SocketAddress::Type::Local); ASSERT(address.type() == SocketAddress::Type::Local);
#ifdef CSOCKET_DEBUG dbgln<debug_csocket>("{} connecting to {}...", *this, address);
dbg() << *this << " connecting to " << address << "...";
#endif
sockaddr_un saddr; sockaddr_un saddr;
saddr.sun_family = AF_LOCAL; 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) bool Socket::common_connect(const struct sockaddr* addr, socklen_t addrlen)
{ {
auto connected = [this] { auto connected = [this] {
#ifdef CSOCKET_DEBUG dbgln<debug_csocket>("{} connected!", *this);
dbg() << *this << " connected!";
#endif
if (!m_connected) { if (!m_connected) {
m_connected = true; m_connected = true;
ensure_read_notifier(); ensure_read_notifier();
@ -162,9 +153,7 @@ bool Socket::common_connect(const struct sockaddr* addr, socklen_t addrlen)
int rc = ::connect(fd(), addr, addrlen); int rc = ::connect(fd(), addr, addrlen);
if (rc < 0) { if (rc < 0) {
if (errno == EINPROGRESS) { if (errno == EINPROGRESS) {
#ifdef CSOCKET_DEBUG dbgln<debug_csocket>("{} connection in progress (EINPROGRESS)", *this);
dbg() << *this << " connection in progress (EINPROGRESS)";
#endif
m_notifier = Notifier::construct(fd(), Notifier::Event::Write, this); m_notifier = Notifier::construct(fd(), Notifier::Event::Write, this);
m_notifier->on_ready_to_write = move(connected); m_notifier->on_ready_to_write = move(connected);
return true; return true;
@ -174,9 +163,7 @@ bool Socket::common_connect(const struct sockaddr* addr, socklen_t addrlen)
errno = saved_errno; errno = saved_errno;
return false; return false;
} }
#ifdef CSOCKET_DEBUG dbgln<debug_csocket>("{} connected ok!", *this);
dbg() << *this << " connected ok!";
#endif
connected(); connected();
return true; return true;
} }

View file

@ -87,3 +87,7 @@ private:
}; };
} }
template<>
struct AK::Formatter<Core::Socket> : Formatter<Core::Object> {
};

View file

@ -113,3 +113,11 @@ private:
const LogStream& operator<<(const LogStream&, const SocketAddress&); const LogStream& operator<<(const LogStream&, const SocketAddress&);
} }
template<>
struct AK::Formatter<Core::SocketAddress> : Formatter<String> {
void format(FormatBuilder& builder, const Core::SocketAddress& value)
{
return Formatter<String>::format(builder, value.to_string());
}
};

View file

@ -26,6 +26,7 @@
#pragma once #pragma once
#include <AK/Debug.h>
#include <AK/LogStream.h> #include <AK/LogStream.h>
#include <AK/StdLibExtras.h> #include <AK/StdLibExtras.h>
#include <errno.h> #include <errno.h>
@ -41,10 +42,11 @@ inline int safe_syscall(Syscall syscall, Args&&... args)
for (;;) { for (;;) {
int sysret = syscall(forward<Args>(args)...); int sysret = syscall(forward<Args>(args)...);
if (sysret == -1) { if (sysret == -1) {
#ifdef SAFE_SYSCALL_DEBUG if constexpr (debug_safe_syscall) {
int saved_errno = errno; int saved_errno = errno;
dbg() << "Core::safe_syscall: " << sysret << " (" << saved_errno << ": " << strerror(saved_errno) << ")"; dbgln<debug_safe_syscall>("Core::safe_syscall: {} ({}: {})", sysret, saved_errno, strerror(saved_errno));
#endif }
if (errno == EINTR) if (errno == EINTR)
continue; continue;
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <AK/Debug.h>
#include <AK/MemoryStream.h> #include <AK/MemoryStream.h>
#include <AK/Types.h> #include <AK/Types.h>
#include <AK/Vector.h> #include <AK/Vector.h>
@ -88,21 +89,18 @@ GHash::TagType GHash::process(ReadonlyBytes aad, ReadonlyBytes cipher)
auto high = [](u64 value) -> u32 { return value >> 32; }; auto high = [](u64 value) -> u32 { return value >> 32; };
auto low = [](u64 value) -> u32 { return value & 0xffffffff; }; auto low = [](u64 value) -> u32 { return value & 0xffffffff; };
#ifdef GHASH_PROCESS_DEBUG if constexpr (debug_ghash_process) {
dbg() << "AAD bits: " << high(aad_bits) << " : " << low(aad_bits); dbgln("AAD bits: {} : {}", high(aad_bits), low(aad_bits));
dbg() << "Cipher bits: " << high(cipher_bits) << " : " << low(cipher_bits); dbgln("Cipher bits: {} : {}", high(cipher_bits), low(cipher_bits));
dbgln("Tag bits: {} : {} : {} : {}", tag[0], tag[1], tag[2], tag[3]);
dbg() << "Tag bits: " << tag[0] << " : " << tag[1] << " : " << tag[2] << " : " << tag[3]; }
#endif
tag[0] ^= high(aad_bits); tag[0] ^= high(aad_bits);
tag[1] ^= low(aad_bits); tag[1] ^= low(aad_bits);
tag[2] ^= high(cipher_bits); tag[2] ^= high(cipher_bits);
tag[3] ^= low(cipher_bits); tag[3] ^= low(cipher_bits);
#ifdef GHASH_PROCESS_DEBUG dbgln<debug_ghash_process>("Tag bits: {} : {} : {} : {}", tag[0], tag[1], tag[2], tag[3]);
dbg() << "Tag bits: " << tag[0] << " : " << tag[1] << " : " << tag[2] << " : " << tag[3];
#endif
galois_multiply(tag, m_key, tag); galois_multiply(tag, m_key, tag);

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <AK/Debug.h>
#include <LibCrypto/NumberTheory/ModularFunctions.h> #include <LibCrypto/NumberTheory/ModularFunctions.h>
namespace Crypto { 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::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); UnsignedBigInteger::multiply_without_allocation(temp_quotient, b, temp_1, temp_2, temp_3, temp_4, output);
#ifdef NT_DEBUG dbgln<debug_nt>("quot: {} rem: {} out: {}", temp_quotient, temp_remainder, output);
dbg() << "quot: " << temp_quotient << " rem: " << temp_remainder << " out: " << output;
#endif
return output; return output;
} }

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <AK/Debug.h>
#include <AK/Random.h> #include <AK/Random.h>
#include <LibCrypto/ASN1/ASN1.h> #include <LibCrypto/ASN1/ASN1.h>
#include <LibCrypto/ASN1/DER.h> #include <LibCrypto/ASN1/DER.h>
@ -115,9 +116,7 @@ RSA::KeyPairType RSA::parse_rsa_key(ReadonlyBytes in)
void RSA::encrypt(ReadonlyBytes in, Bytes& out) void RSA::encrypt(ReadonlyBytes in, Bytes& out)
{ {
#ifdef CRYPTO_DEBUG dbgln<debug_crypto>("in size: {}", in.size());
dbg() << "in size: " << in.size();
#endif
auto in_integer = UnsignedBigInteger::import_data(in.data(), in.size()); auto in_integer = UnsignedBigInteger::import_data(in.data(), in.size());
if (!(in_integer < m_public_key.modulus())) { if (!(in_integer < m_public_key.modulus())) {
dbgln("value too large for key"); dbgln("value too large for key");
@ -231,9 +230,7 @@ VerificationConsistency RSA_EMSA_PSS<HashFunction>::verify(ReadonlyBytes in)
void RSA_PKCS1_EME::encrypt(ReadonlyBytes in, Bytes& out) void RSA_PKCS1_EME::encrypt(ReadonlyBytes in, Bytes& out)
{ {
auto mod_len = (m_public_key.modulus().trimmed_length() * sizeof(u32) * 8 + 7) / 8; auto mod_len = (m_public_key.modulus().trimmed_length() * sizeof(u32) * 8 + 7) / 8;
#ifdef CRYPTO_DEBUG dbgln<debug_crypto>("key size: {}", mod_len);
dbg() << "key size: " << mod_len;
#endif
if (in.size() > mod_len - 11) { if (in.size() > mod_len - 11) {
dbgln("message too long :("); dbgln("message too long :(");
out = out.trim(0); 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.overwrite(3 + ps_length, in.data(), in.size());
out = out.trim(3 + ps_length + in.size()); // should be a single block out = out.trim(3 + ps_length + in.size()); // should be a single block
#ifdef CRYPTO_DEBUG dbgln<debug_crypto>("padded output size: {} buffer size: {}", 3 + ps_length + in.size(), out.size());
dbg() << "padded output size: " << 3 + ps_length + in.size() << " buffer size: " << out.size();
#endif
RSA::encrypt(out, out); RSA::encrypt(out, out);
} }

View file

@ -25,11 +25,10 @@
*/ */
#include "LineProgram.h" #include "LineProgram.h"
#include <AK/Debug.h>
#include <AK/String.h> #include <AK/String.h>
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
//#define DWARF_DEBUG
namespace Debug::Dwarf { namespace Debug::Dwarf {
LineProgram::LineProgram(InputMemoryStream& stream) LineProgram::LineProgram(InputMemoryStream& stream)
@ -236,10 +235,10 @@ void LineProgram::handle_sepcial_opcode(u8 opcode)
m_address += address_increment; m_address += address_increment;
m_line += line_increment; m_line += line_increment;
#ifdef DWARF_DEBUG if constexpr (debug_dwarf) {
dbgln("Special adjusted_opcode: {}, address_increment: {}, line_increment: {}", adjusted_opcode, address_increment, line_increment); 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; dbgln("Address is now: {:p}, and line is: {}:{}", m_address, m_source_files[m_file_index].name, m_line);
#endif }
append_to_line_info(); append_to_line_info();
} }
@ -252,9 +251,7 @@ void LineProgram::run_program()
u8 opcode = 0; u8 opcode = 0;
m_stream >> opcode; m_stream >> opcode;
#ifdef DWARF_DEBUG dbgln<debug_dwarf>("{:p}: opcode: {}", m_stream.offset() - 1, opcode);
dbg() << (void*)(m_stream.offset() - 1) << ": opcode: " << opcode;
#endif
if (opcode == 0) { if (opcode == 0) {
handle_extended_opcode(); handle_extended_opcode();

View file

@ -25,8 +25,7 @@
*/ */
#include "Hunks.h" #include "Hunks.h"
#include <AK/Debug.h>
// #define DEBUG_HUNKS
namespace Diff { namespace Diff {
Vector<Hunk> parse_hunks(const String& diff) Vector<Hunk> parse_hunks(const String& diff)
@ -78,21 +77,19 @@ Vector<Hunk> parse_hunks(const String& diff)
hunks.append(hunk); hunks.append(hunk);
} }
#ifdef DEBUG_HUNKS if constexpr (debug_hunks) {
for (const auto& hunk : hunks) { for (const auto& hunk : hunks) {
dbgln("Hunk location:"); dbgln("Hunk location:");
dbg() << "orig: " << hunk.original_start_line; dbgln(" orig: {}", hunk.original_start_line);
dbg() << "target: " << hunk.target_start_line; dbgln(" target: {}", hunk.target_start_line);
dbgln("removed:"); dbgln(" removed:");
for (const auto& line : hunk.removed_lines) { for (const auto& line : hunk.removed_lines)
dbg() << "- " << line; dbgln("- {}", line);
} dbgln(" added:");
dbgln("added:"); for (const auto& line : hunk.added_lines)
for (const auto& line : hunk.added_lines) { dbgln("+ {}", line);
dbg() << "+ " << line;
} }
} }
#endif
return hunks; return hunks;
} }

View file

@ -24,13 +24,12 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <AK/Debug.h>
#include <LibGemini/GeminiResponse.h> #include <LibGemini/GeminiResponse.h>
#include <LibGemini/Job.h> #include <LibGemini/Job.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
//#define JOB_DEBUG
namespace Gemini { namespace Gemini {
Job::Job(const GeminiRequest& request, OutputStream& output_stream) Job::Job(const GeminiRequest& request, OutputStream& output_stream)
@ -67,10 +66,11 @@ void Job::on_socket_connected()
return; return;
m_sent_data = true; m_sent_data = true;
auto raw_request = m_request.to_raw_request(); auto raw_request = m_request.to_raw_request();
#ifdef JOB_DEBUG
dbgln("Job: raw_request:"); if constexpr (debug_job) {
dbg() << String::copy(raw_request).characters(); dbgln("Job: raw_request:");
#endif dbgln("{}", String::copy(raw_request));
}
bool success = write(raw_request); bool success = write(raw_request);
if (!success) if (!success)
deferred_invoke([this](auto&) { did_fail(Core::NetworkJob::Error::TransmissionFailed); }); deferred_invoke([this](auto&) { did_fail(Core::NetworkJob::Error::TransmissionFailed); });