Jelajahi Sumber

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.
asynts 4 tahun lalu
induk
melakukan
7d783d8b84

+ 25 - 0
AK/Debug.h

@@ -417,3 +417,28 @@ constexpr bool debug_tls = true;
 #else
 constexpr bool debug_tls = false;
 #endif
+
+#ifdef DEBUG_SPAM
+constexpr bool debug_spam = true;
+#else
+constexpr bool debug_spam = false;
+#endif
+
+#ifdef WRAPPER_GERNERATOR_DEBUG
+constexpr bool debug_wrapper_generator = true;
+#else
+constexpr bool debug_wrapper_generator = false;
+#endif
+
+#ifdef PARSER_DEBUG
+constexpr bool debug_parser = true;
+#else
+constexpr bool debug_parser = false;
+#endif
+
+#ifdef TOKENIZER_TRACE
+constexpr bool debug_trace_tokenizer = true;
+#else
+constexpr bool debug_trace_tokenizer = false;
+#endif
+

+ 1 - 0
Meta/CMake/all_the_debug_macros.cmake

@@ -166,6 +166,7 @@ add_compile_definitions("WAITBLOCK_DEBUG")
 add_compile_definitions("WAITQUEUE_DEBUG")
 add_compile_definitions("WEAKABLE_DEBUG")
 add_compile_definitions("WINDOWMANAGER_DEBUG")
+add_compile_definitions("WRAPPER_GERNERATOR_DEBUG")
 add_compile_definitions("WSMESSAGELOOP_DEBUG")
 add_compile_definitions("DEBUG_SOCKET")
 add_compile_definitions("WSSCREEN_DEBUG")

+ 31 - 42
Userland/Libraries/LibTLS/TLSv12.cpp

@@ -24,6 +24,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <AK/Debug.h>
 #include <AK/Endian.h>
 #include <LibCore/ConfigFile.h>
 #include <LibCore/DateTime.h>
@@ -37,8 +38,6 @@
 #    include <sys/ioctl.h>
 #endif
 
-//#define TLS_DEBUG
-
 namespace {
 struct OIDChain {
     OIDChain* root { nullptr };
@@ -407,9 +406,7 @@ static ssize_t _parse_asn1(const Context& context, Certificate& cert, const u8*
             hash.initialize(Crypto::Hash::HashKind::SHA512);
             break;
         default:
-#ifdef TLS_DEBUG
-            dbg() << "Unsupported hash mode " << (u32)cert.key_algorithm;
-#endif
+            dbgln<debug_tls>("Unsupported hash mode {}", (u32)cert.key_algorithm);
             // fallback to md5, it will fail later
             hash.initialize(Crypto::Hash::HashKind::MD5);
             break;
@@ -439,9 +436,7 @@ Optional<Certificate> TLSv12::parse_asn1(ReadonlyBytes buffer, bool) const
 
     _parse_asn1(m_context, cert, buffer.data(), buffer.size(), 1, fields, nullptr, 0, nullptr, nullptr);
 
-#ifdef TLS_DEBUG
-    dbg() << "Certificate issued for " << cert.subject << " by " << cert.issuer_subject;
-#endif
+    dbgln<debug_tls>("Certificate issued for {} by {}", cert.subject, cert.issuer_subject);
 
     return cert;
 }
@@ -459,9 +454,7 @@ ssize_t TLSv12::handle_certificate(ReadonlyBytes buffer)
 
     u32 certificate_total_length = buffer[0] * 0x10000 + buffer[1] * 0x100 + buffer[2];
 
-#ifdef TLS_DEBUG
-    dbg() << "total length: " << certificate_total_length;
-#endif
+    dbgln<debug_tls>("total length: {}", certificate_total_length);
 
     if (certificate_total_length <= 4)
         return 3 * certificate_total_length;
@@ -508,7 +501,7 @@ ssize_t TLSv12::handle_certificate(ReadonlyBytes buffer)
             }
             ++certificates_in_chain;
             if (buffer.size() < (size_t)res_cert + 3) {
-                dbg() << "not enough data to read cert size (" << buffer.size() << " < " << res_cert + 3 << ")";
+                dbgln("not enough data to read cert size ({} < {})", buffer.size(), res_cert + 3);
                 break;
             }
             size_t certificate_size_specific = buffer[res_cert] * 0x10000 + buffer[res_cert + 1] * 0x100 + buffer[res_cert + 2];
@@ -516,7 +509,7 @@ ssize_t TLSv12::handle_certificate(ReadonlyBytes buffer)
             remaining -= 3;
 
             if (certificate_size_specific > remaining) {
-                dbg() << "invalid certificate size (expected " << remaining << " but got " << certificate_size_specific << ")";
+                dbgln("invalid certificate size (expected {} but got {})", remaining, certificate_size_specific);
                 break;
             }
             remaining -= certificate_size_specific;
@@ -531,7 +524,7 @@ ssize_t TLSv12::handle_certificate(ReadonlyBytes buffer)
             res_cert += certificate_size_specific;
         } while (remaining > 0);
         if (remaining) {
-            dbg() << "extraneous " << remaining << " bytes left over after parsing certificates";
+            dbgln("extraneous {} bytes left over after parsing certificates", remaining);
         }
         size -= certificate_size + 3;
         res += certificate_size;
@@ -540,7 +533,7 @@ ssize_t TLSv12::handle_certificate(ReadonlyBytes buffer)
         return (i8)Error::UnsupportedCertificate;
 
     if ((size_t)res != buffer.size())
-        dbg() << "some data left unread: " << (size_t)res << " bytes out of " << buffer.size();
+        dbgln("some data left unread: {} bytes out of {}", res, buffer.size());
 
     return res;
 }
@@ -548,7 +541,7 @@ ssize_t TLSv12::handle_certificate(ReadonlyBytes buffer)
 void TLSv12::consume(ReadonlyBytes record)
 {
     if (m_context.critical_error) {
-        dbg() << "There has been a critical error (" << (i8)m_context.critical_error << "), refusing to continue";
+        dbgln("There has been a critical error ({}), refusing to continue", (i8)m_context.critical_error);
         return;
     }
 
@@ -556,9 +549,7 @@ void TLSv12::consume(ReadonlyBytes record)
         return;
     }
 
-#ifdef TLS_DEBUG
-    dbg() << "Consuming " << record.size() << " bytes";
-#endif
+    dbgln<debug_tls>("Consuming {} bytes", record.size());
 
     m_context.message_buffer.append(record.data(), record.size());
 
@@ -567,29 +558,27 @@ void TLSv12::consume(ReadonlyBytes record)
 
     size_t size_offset { 3 }; // read the common record header
     size_t header_size { 5 };
-#ifdef TLS_DEBUG
-    dbg() << "message buffer length " << buffer_length;
-#endif
+
+    dbgln<debug_tls>("message buffer length {}", buffer_length);
+
     while (buffer_length >= 5) {
         auto length = AK::convert_between_host_and_network_endian(*(u16*)m_context.message_buffer.offset_pointer(index + size_offset)) + header_size;
         if (length > buffer_length) {
-#ifdef TLS_DEBUG
-            dbg() << "Need more data: " << length << " | " << buffer_length;
-#endif
+            dbgln<debug_tls>("Need more data: {} > {}", length, buffer_length);
             break;
         }
         auto consumed = handle_message(m_context.message_buffer.bytes().slice(index, length));
 
-#ifdef TLS_DEBUG
-        if (consumed > 0)
-            dbg() << "consumed " << (size_t)consumed << " bytes";
-        else
-            dbg() << "error: " << (int)consumed;
-#endif
+        if constexpr (debug_tls) {
+            if (consumed > 0)
+                dbgln("consumed {} bytes", consumed);
+            else
+                dbgln("error: {}", consumed);
+        }
 
         if (consumed != (i8)Error::NeedMoreData) {
             if (consumed < 0) {
-                dbg() << "Consumed an error: " << (int)consumed;
+                dbgln("Consumed an error: {}", consumed);
                 if (!m_context.critical_error)
                     m_context.critical_error = (i8)consumed;
                 m_context.error_code = (Error)consumed;
@@ -608,7 +597,7 @@ void TLSv12::consume(ReadonlyBytes record)
         }
     }
     if (m_context.error_code != Error::NoError && m_context.error_code != Error::NeedMoreData) {
-        dbg() << "consume error: " << (i8)m_context.error_code;
+        dbgln("consume error: {}", (i8)m_context.error_code);
         m_context.message_buffer.clear();
         return;
     }
@@ -639,7 +628,7 @@ void TLSv12::ensure_hmac(size_t digest_size, bool local)
         hash_kind = Crypto::Hash::HashKind::SHA512;
         break;
     default:
-        dbg() << "Failed to find a suitable hash for size " << digest_size;
+        dbgln("Failed to find a suitable hash for size {}", digest_size);
         break;
     }
 
@@ -656,14 +645,14 @@ bool Certificate::is_valid() const
 
     if (!not_before.is_empty()) {
         if (now.is_before(not_before)) {
-            dbg() << "certificate expired (not yet valid, signed for " << not_before << ")";
+            dbgln("certificate expired (not yet valid, signed for {})", not_before);
             return false;
         }
     }
 
     if (!not_after.is_empty()) {
         if (!now.is_before(not_after)) {
-            dbg() << "certificate expired (expiry date " << not_after << ")";
+            dbgln("certificate expired (expiry date {})", not_after);
             return false;
         }
     }
@@ -677,13 +666,13 @@ void TLSv12::try_disambiguate_error() const
     switch ((AlertDescription)m_context.critical_error) {
     case AlertDescription::HandshakeFailure:
         if (!m_context.cipher_spec_set) {
-            dbg() << "- No cipher suite in common with " << m_context.SNI;
+            dbgln("- No cipher suite in common with {}", m_context.SNI);
         } else {
             dbgln("- Unknown internal issue");
         }
         break;
     case AlertDescription::InsufficientSecurity:
-        dbg() << "- No cipher suite in common with " << m_context.SNI << " (the server is oh so secure)";
+        dbgln("- No cipher suite in common with {} (the server is oh so secure)", m_context.SNI);
         break;
     case AlertDescription::ProtocolVersion:
         dbgln("- The server refused to negotiate with TLS 1.2 :(");
@@ -739,7 +728,7 @@ void TLSv12::set_root_certificates(Vector<Certificate> certificates)
 
     for (auto& cert : certificates) {
         if (!cert.is_valid())
-            dbg() << "Certificate for " << cert.subject << " by " << cert.issuer_subject << " is invalid, things may or may not work!";
+            dbgln("Certificate for {} by {} is invalid, things may or may not work!", cert.subject, cert.issuer_subject);
         // FIXME: Figure out what we should do when our root certs are invalid.
     }
     m_context.root_ceritificates = move(certificates);
@@ -774,18 +763,18 @@ bool Context::verify_chain() const
     for (auto& it : chain) {
         if (it.key == it.value) { // Allow self-signed certificates.
             if (!roots.contains(it.key))
-                dbg() << "Self-signed warning: Certificate for " << it.key << " is self-signed";
+                dbgln("Self-signed warning: Certificate for {} is self-signed", it.key);
             continue;
         }
 
         auto ref = chain.get(it.value);
         if (!ref.has_value()) {
-            dbg() << "Certificate for " << it.key << " is not signed by anyone we trust (" << it.value << ")";
+            dbgln("Certificate for {} is not signed by anyone we trust ({})", it.key, it.value);
             return false;
         }
 
         if (ref.value() == it.key) // Allow (but warn about) mutually recursively signed cert A <-> B.
-            dbg() << "Co-dependency warning: Certificate for " << ref.value() << " is issued by " << it.key << ", which itself is issued by " << ref.value();
+            dbgln("Co-dependency warning: Certificate for {} is issued by {}, which itself is issued by {}", ref.value(), it.key, ref.value());
     }
 
     return true;

+ 22 - 14
Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp

@@ -25,6 +25,7 @@
  */
 
 #include <AK/ByteBuffer.h>
+#include <AK/Debug.h>
 #include <AK/GenericLexer.h>
 #include <AK/HashMap.h>
 #include <AK/LexicalPath.h>
@@ -373,23 +374,30 @@ int main(int argc, char** argv)
         interface->fully_qualified_name = interface->name;
     }
 
-#if 0
-    dbgln("Attributes:");
-    for (auto& attribute : interface->attributes) {
-        dbg() << "  " << (attribute.readonly ? "Readonly " : "")
-              << attribute.type.name << (attribute.type.nullable ? "?" : "")
-              << " " << attribute.name;
-    }
+    if constexpr (debug_wrapper_generator) {
+        dbgln("Attributes:");
+        for (auto& attribute : interface->attributes) {
+            dbgln("  {}{}{} {}",
+                attribute.readonly ? "readonly " : "",
+                attribute.type.name,
+                attribute.type.nullable ? "?" : "",
+                attribute.name);
+        }
 
-    dbgln("Functions:");
-    for (auto& function : interface->functions) {
-        dbg() << "  " << function.return_type.name << (function.return_type.nullable ? "?" : "")
-              << " " << function.name;
-        for (auto& parameter : function.parameters) {
-            dbg() << "    " << parameter.type.name << (parameter.type.nullable ? "?" : "") << " " << parameter.name;
+        dbgln("Functions:");
+        for (auto& function : interface->functions) {
+            dbgln("  {}{} {}",
+                function.return_type.name,
+                function.return_type.nullable ? "?" : "",
+                function.name);
+            for (auto& parameter : function.parameters) {
+                dbgln("    {}{} {}",
+                    parameter.type.name,
+                    parameter.type.nullable ? "?" : "",
+                    parameter.name);
+            }
         }
     }
-#endif
 
     if (header_mode)
         generate_header(*interface);

+ 4 - 3
Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp

@@ -24,6 +24,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <AK/Debug.h>
 #include <LibGUI/Button.h>
 #include <LibGUI/TextBox.h>
 #include <LibWeb/Bindings/WindowObject.h>
@@ -71,15 +72,15 @@ void HTMLIFrameElement::load_src(const String& value)
 {
     auto url = document().complete_url(value);
     if (!url.is_valid()) {
-        dbg() << "iframe failed to load URL: Invalid URL: " << value;
+        dbgln("iframe failed to load URL: Invalid URL: {}", value);
         return;
     }
     if (url.protocol() == "file" && document().origin().protocol() != "file") {
-        dbg() << "iframe failed to load URL: Security violation: " << document().url() << " may not load " << url;
+        dbgln("iframe failed to load URL: Security violation: {} may not load {}", document().url(), url);
         return;
     }
 
-    dbg() << "Loading iframe document from " << value;
+    dbgln("Loading iframe document from {}", value);
     m_content_frame->loader().load(url, FrameLoader::Type::IFrame);
 }
 

+ 3 - 2
Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp

@@ -25,6 +25,7 @@
  */
 
 #include <AK/ByteBuffer.h>
+#include <AK/Debug.h>
 #include <AK/URL.h>
 #include <LibCore/File.h>
 #include <LibWeb/CSS/Parser/CSSParser.h>
@@ -61,11 +62,11 @@ void HTMLLinkElement::resource_did_load()
     if (!resource()->has_encoded_data())
         return;
 
-    dbg() << "HTMLLinkElement: Resource did load, looks good! " << href();
+    dbgln("HTMLLinkElement: Resource did load, looks good! {}", href());
 
     auto sheet = parse_css(CSS::ParsingContext(document()), resource()->encoded_data());
     if (!sheet) {
-        dbg() << "HTMLLinkElement: Failed to parse stylesheet: " << href();
+        dbgln("HTMLLinkElement: Failed to parse stylesheet: {}", href());
         return;
     }
 

+ 8 - 10
Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp

@@ -26,6 +26,7 @@
 
 //#define PARSER_DEBUG
 
+#include <AK/Debug.h>
 #include <AK/Utf32View.h>
 #include <LibTextCodec/Decoder.h>
 #include <LibWeb/DOM/Comment.h>
@@ -47,9 +48,9 @@
 
 namespace Web::HTML {
 
-#define PARSE_ERROR()                                                         \
-    do {                                                                      \
-        dbg() << "Parse error! " << __PRETTY_FUNCTION__ << " @ " << __LINE__; \
+#define PARSE_ERROR()                                                 \
+    do {                                                              \
+        dbgln("Parse error! {} @ {}", __PRETTY_FUNCTION__, __LINE__); \
     } while (0)
 
 static Vector<FlyString> s_quirks_public_ids = {
@@ -142,9 +143,8 @@ void HTMLDocumentParser::run(const URL& url)
             break;
         auto& token = optional_token.value();
 
-#ifdef PARSER_DEBUG
-        dbg() << "[" << insertion_mode_name() << "] " << token.to_string();
-#endif
+        dbgln<debug_parser>("[{}] {}", insertion_mode_name(), token.to_string());
+
         // FIXME: If the adjusted current node is a MathML text integration point and the token is a start tag whose tag name is neither "mglyph" nor "malignmark"
         // FIXME: If the adjusted current node is a MathML text integration point and the token is a character token
         // FIXME: If the adjusted current node is a MathML annotation-xml element and the token is a start tag whose tag name is "svg"
@@ -159,9 +159,7 @@ void HTMLDocumentParser::run(const URL& url)
         }
 
         if (m_stop_parsing) {
-#ifdef PARSER_DEBUG
-            dbg() << "Stop parsing" << (m_parsing_fragment ? " fragment" : "") << "! :^)";
-#endif
+            dbgln<debug_parser>("Stop parsing{}! :^)", m_parsing_fragment ? " fragment" : "");
             break;
         }
     }
@@ -1407,7 +1405,7 @@ void HTMLDocumentParser::handle_in_body(HTMLToken& token)
         generate_implied_end_tags(HTML::TagNames::li);
         if (current_node().local_name() != HTML::TagNames::li) {
             PARSE_ERROR();
-            dbg() << "Expected <li> current node, but had <" << current_node().local_name() << ">";
+            dbgln("Expected <li> current node, but had <{}>", current_node().local_name());
         }
         m_stack_of_open_elements.pop_until_an_element_with_tag_name_has_been_popped(HTML::TagNames::li);
         return;

+ 8 - 17
Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp

@@ -24,6 +24,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <AK/Debug.h>
 #include <LibTextCodec/Decoder.h>
 #include <LibWeb/HTML/Parser/Entities.h>
 #include <LibWeb/HTML/Parser/HTMLToken.h>
@@ -35,12 +36,10 @@ namespace Web::HTML {
 
 #pragma GCC diagnostic ignored "-Wunused-label"
 
-//#define TOKENIZER_TRACE
-
 #ifdef TOKENIZER_TRACE
-#    define PARSE_ERROR()                                                                      \
-        do {                                                                                   \
-            dbg() << "Parse error (tokenization)" << __PRETTY_FUNCTION__ << " @ " << __LINE__; \
+#    define PARSE_ERROR()                                                              \
+        do {                                                                           \
+            dbgln("Parse error (tokenization) {} @ {}", __PRETTY_FUNCTION__, __LINE__) \
         } while (0)
 #else
 #    define PARSE_ERROR()
@@ -222,9 +221,7 @@ Optional<u32> HTMLTokenizer::next_code_point()
         return {};
     m_prev_utf8_iterator = m_utf8_iterator;
     ++m_utf8_iterator;
-#ifdef TOKENIZER_TRACE
-    dbg() << "(Tokenizer) Next code_point: " << (char)*m_prev_utf8_iterator;
-#endif
+    dbgln<debug_trace_tokenizer>("(Tokenizer) Next code_point: {}", (char)*m_prev_utf8_iterator);
     return *m_prev_utf8_iterator;
 }
 
@@ -2621,23 +2618,17 @@ HTMLTokenizer::HTMLTokenizer(const StringView& input, const String& encoding)
 
 void HTMLTokenizer::will_switch_to([[maybe_unused]] State new_state)
 {
-#ifdef TOKENIZER_TRACE
-    dbg() << "[" << state_name(m_state) << "] Switch to " << state_name(new_state);
-#endif
+    dbgln<debug_trace_tokenizer>("[{}] Switch to {}", state_name(m_state), state_name(new_state));
 }
 
 void HTMLTokenizer::will_reconsume_in([[maybe_unused]] State new_state)
 {
-#ifdef TOKENIZER_TRACE
-    dbg() << "[" << state_name(m_state) << "] Reconsume in " << state_name(new_state);
-#endif
+    dbgln<debug_trace_tokenizer>("[{}] Reconsume in {}", state_name(m_state), state_name(new_state));
 }
 
 void HTMLTokenizer::switch_to(Badge<HTMLDocumentParser>, State new_state)
 {
-#ifdef TOKENIZER_TRACE
-    dbg() << "[" << state_name(m_state) << "] Parser switches tokenizer state to " << state_name(new_state);
-#endif
+    dbgln<debug_trace_tokenizer>("[{}] Parser switches tokenizer state to {}", state_name(m_state), state_name(new_state));
     m_state = new_state;
 }
 

+ 6 - 15
Userland/Libraries/LibWeb/WebContentClient.cpp

@@ -26,6 +26,7 @@
 
 #include "WebContentClient.h"
 #include "OutOfProcessWebView.h"
+#include <AK/Debug.h>
 
 namespace Web {
 
@@ -55,9 +56,7 @@ void WebContentClient::handle([[maybe_unused]] const Messages::WebContentClient:
 
 void WebContentClient::handle(const Messages::WebContentClient::DidInvalidateContentRect& message)
 {
-#ifdef DEBUG_SPAM
-    dbg() << "handle: WebContentClient::DidInvalidateContentRect! content_rect=" << message.content_rect();
-#endif
+    dbgln<debug_spam>("handle: WebContentClient::DidInvalidateContentRect! content_rect={}", message.content_rect());
 
     // FIXME: Figure out a way to coalesce these messages to reduce unnecessary painting
     m_view.notify_server_did_invalidate_content_rect({}, message.content_rect());
@@ -73,33 +72,25 @@ void WebContentClient::handle(const Messages::WebContentClient::DidChangeSelecti
 
 void WebContentClient::handle(const Messages::WebContentClient::DidLayout& message)
 {
-#ifdef DEBUG_SPAM
-    dbg() << "handle: WebContentClient::DidLayout! content_size=" << message.content_size();
-#endif
+    dbgln<debug_spam>("handle: WebContentClient::DidLayout! content_size={}", message.content_size());
     m_view.notify_server_did_layout({}, message.content_size());
 }
 
 void WebContentClient::handle(const Messages::WebContentClient::DidChangeTitle& message)
 {
-#ifdef DEBUG_SPAM
-    dbg() << "handle: WebContentClient::DidChangeTitle! title=" << message.title();
-#endif
+    dbgln<debug_spam>("handle: WebContentClient::DidChangeTitle! title={}", message.title());
     m_view.notify_server_did_change_title({}, message.title());
 }
 
 void WebContentClient::handle(const Messages::WebContentClient::DidRequestScrollIntoView& message)
 {
-#ifdef DEBUG_SPAM
-    dbg() << "handle: WebContentClient::DidRequestScrollIntoView! rect=" << message.rect();
-#endif
+    dbgln<debug_spam>("handle: WebContentClient::DidRequestScrollIntoView! rect={}", message.rect());
     m_view.notify_server_did_request_scroll_into_view({}, message.rect());
 }
 
 void WebContentClient::handle(const Messages::WebContentClient::DidHoverLink& message)
 {
-#ifdef DEBUG_SPAM
-    dbg() << "handle: WebContentClient::DidHoverLink! url=" << message.url();
-#endif
+    dbgln<debug_spam>("handle: WebContentClient::DidHoverLink! url={}", message.url());
     m_view.notify_server_did_hover_link({}, message.url());
 }