diff --git a/AK/Debug.h b/AK/Debug.h index 6ff72e73f0..0d1db45ecf 100644 --- a/AK/Debug.h +++ b/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 + diff --git a/Meta/CMake/all_the_debug_macros.cmake b/Meta/CMake/all_the_debug_macros.cmake index f0a3456eb6..cba732260c 100644 --- a/Meta/CMake/all_the_debug_macros.cmake +++ b/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") diff --git a/Userland/Libraries/LibTLS/TLSv12.cpp b/Userland/Libraries/LibTLS/TLSv12.cpp index aa0d70e0ed..06d4a0072e 100644 --- a/Userland/Libraries/LibTLS/TLSv12.cpp +++ b/Userland/Libraries/LibTLS/TLSv12.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -37,8 +38,6 @@ # include #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("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 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("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("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("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("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("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 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; diff --git a/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp b/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp index d50186e88a..7df091e171 100644 --- a/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp +++ b/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp @@ -25,6 +25,7 @@ */ #include +#include #include #include #include @@ -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); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp index e59818ba82..f13eeebf3f 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -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); } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp index 323c642d61..1fc7a38240 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp @@ -25,6 +25,7 @@ */ #include +#include #include #include #include @@ -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; } diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp index 446888aeb3..12fea07e4e 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp @@ -26,6 +26,7 @@ //#define PARSER_DEBUG +#include #include #include #include @@ -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 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("[{}] {}", 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("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
  • current node, but had <" << current_node().local_name() << ">"; + dbgln("Expected
  • 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; diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp index 1bf1dab3c3..28213ffe62 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -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 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("(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("[{}] 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("[{}] Reconsume in {}", state_name(m_state), state_name(new_state)); } void HTMLTokenizer::switch_to(Badge, State new_state) { -#ifdef TOKENIZER_TRACE - dbg() << "[" << state_name(m_state) << "] Parser switches tokenizer state to " << state_name(new_state); -#endif + dbgln("[{}] Parser switches tokenizer state to {}", state_name(m_state), state_name(new_state)); m_state = new_state; } diff --git a/Userland/Libraries/LibWeb/WebContentClient.cpp b/Userland/Libraries/LibWeb/WebContentClient.cpp index 7032924600..c98418e1ef 100644 --- a/Userland/Libraries/LibWeb/WebContentClient.cpp +++ b/Userland/Libraries/LibWeb/WebContentClient.cpp @@ -26,6 +26,7 @@ #include "WebContentClient.h" #include "OutOfProcessWebView.h" +#include 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("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("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("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("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("handle: WebContentClient::DidHoverLink! url={}", message.url()); m_view.notify_server_did_hover_link({}, message.url()); }