From 3f23a58fa1a0de922e36d82adccfccfb78b4049f Mon Sep 17 00:00:00 2001 From: asynts Date: Sun, 17 Jan 2021 18:17:00 +0100 Subject: [PATCH] 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. --- AK/Debug.h | 29 +++++++++ .../Libraries/LibWeb/Loader/FrameLoader.cpp | 13 ++-- .../Libraries/LibWeb/Loader/ImageLoader.cpp | 15 +++-- Userland/Libraries/LibWeb/Loader/Resource.cpp | 5 +- .../LibWeb/Loader/ResourceLoader.cpp | 20 +++--- .../Libraries/LibWeb/SVG/SVGPathElement.cpp | 5 +- Userland/Services/ChessEngine/ChessEngine.cpp | 7 +- Userland/Services/DHCPClient/DHCPv4.cpp | 9 +-- Userland/Services/DHCPClient/DHCPv4Client.cpp | 64 ++++++++++--------- 9 files changed, 97 insertions(+), 70 deletions(-) diff --git a/AK/Debug.h b/AK/Debug.h index 0d1db45ecf..56b00bbea5 100644 --- a/AK/Debug.h +++ b/AK/Debug.h @@ -442,3 +442,32 @@ constexpr bool debug_trace_tokenizer = true; constexpr bool debug_trace_tokenizer = false; #endif +#ifdef IMAGE_LOADER_DEBUG +constexpr bool debug_image_loader = true; +#else +constexpr bool debug_image_loader = false; +#endif + +#ifdef RESOURCE_DEBUG +constexpr bool debug_resource = true; +#else +constexpr bool debug_resource = false; +#endif + +#ifdef CACHE_DEBUG +constexpr bool debug_cache = true; +#else +constexpr bool debug_cache = false; +#endif + +#ifdef DHCPV4_DEBUG +constexpr bool debug_dhcpv4 = true; +#else +constexpr bool debug_dhcpv4 = false; +#endif + +#ifdef DHCPV4CLIENT_DEBUG +constexpr bool debug_dhcpv4_client = true; +#else +constexpr bool debug_dhcpv4_client = false; +#endif diff --git a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp index 172a9e1b2a..47103bfab9 100644 --- a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp +++ b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -39,8 +40,6 @@ #include #include -//#define GEMINI_DEBUG 1 - namespace Web { FrameLoader::FrameLoader(Frame& frame) @@ -180,14 +179,14 @@ bool FrameLoader::load(const LoadRequest& request, Type type) ResourceLoader::the().load( favicon_url, [this, favicon_url](auto data, auto&) { - dbg() << "Favicon downloaded, " << data.size() << " bytes from " << favicon_url; + dbgln("Favicon downloaded, {} bytes from {}", data.size(), favicon_url); auto decoder = Gfx::ImageDecoder::create(data.data(), data.size()); auto bitmap = decoder->bitmap(); if (!bitmap) { - dbg() << "Could not decode favicon " << favicon_url; + dbgln("Could not decode favicon {}", favicon_url); return; } - dbg() << "Decoded favicon, " << bitmap->size(); + dbgln("Decoded favicon, {}", bitmap->size()); if (auto* page = frame().page()) page->client().page_did_change_favicon(*bitmap); }); @@ -198,7 +197,7 @@ bool FrameLoader::load(const LoadRequest& request, Type type) bool FrameLoader::load(const URL& url, Type type) { - dbg() << "FrameLoader::load: " << url; + dbgln("FrameLoader::load: {}", url); if (!url.is_valid()) { load_error_page(url, "Invalid URL"); @@ -240,7 +239,7 @@ void FrameLoader::load_error_page(const URL& failed_url, const String& error) frame().set_document(document); }, [](auto error) { - dbg() << "Failed to load error page: " << error; + dbgln("Failed to load error page: {}", error); ASSERT_NOT_REACHED(); }); } diff --git a/Userland/Libraries/LibWeb/Loader/ImageLoader.cpp b/Userland/Libraries/LibWeb/Loader/ImageLoader.cpp index b56ab98abd..ad4901587e 100644 --- a/Userland/Libraries/LibWeb/Loader/ImageLoader.cpp +++ b/Userland/Libraries/LibWeb/Loader/ImageLoader.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -71,13 +72,13 @@ void ImageLoader::resource_did_load() m_loading_state = LoadingState::Loaded; -#ifdef IMAGE_LOADER_DEBUG - if (!resource()->has_encoded_data()) { - dbg() << "ImageLoader: Resource did load, no encoded data. URL: " << resource()->url(); - } else { - dbg() << "ImageLoader: Resource did load, has encoded data. URL: " << resource()->url(); + if constexpr (debug_image_loader) { + if (!resource()->has_encoded_data()) { + dbgln("ImageLoader: Resource did load, no encoded data. URL: {}", resource()->url()); + } else { + dbgln("ImageLoader: Resource did load, has encoded data. URL: {}", resource()->url()); + } } -#endif if (resource()->should_decode_in_process()) { auto& decoder = resource()->ensure_decoder(); @@ -121,7 +122,7 @@ void ImageLoader::animate() void ImageLoader::resource_did_fail() { - dbg() << "ImageLoader: Resource did fail. URL: " << resource()->url(); + dbgln("ImageLoader: Resource did fail. URL: {}", resource()->url()); m_loading_state = LoadingState::Failed; if (on_fail) on_fail(); diff --git a/Userland/Libraries/LibWeb/Loader/Resource.cpp b/Userland/Libraries/LibWeb/Loader/Resource.cpp index 2cb6ebc52d..be5f38a5fd 100644 --- a/Userland/Libraries/LibWeb/Loader/Resource.cpp +++ b/Userland/Libraries/LibWeb/Loader/Resource.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -99,9 +100,7 @@ void Resource::did_load(Badge, ReadonlyBytes data, const HashMap m_encoding = encoding_from_content_type(content_type.value()); m_mime_type = mime_type_from_content_type(content_type.value()); } else if (url().protocol() == "data" && !url().data_mime_type().is_empty()) { -#ifdef RESOURCE_DEBUG - dbg() << "This is a data URL with mime-type _" << url().data_mime_type() << "_"; -#endif + dbgln("This is a data URL with mime-type _{}_", url().data_mime_type()); m_encoding = "utf-8"; // FIXME: This doesn't seem nice. m_mime_type = url().data_mime_type(); } else { diff --git a/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp b/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp index 42387e88e6..14f3fd68d3 100644 --- a/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp +++ b/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp @@ -25,6 +25,7 @@ */ #include +#include #include #include #include @@ -35,8 +36,6 @@ #include #include -//#define CACHE_DEBUG - namespace Web { ResourceLoader& ResourceLoader::the() @@ -82,11 +81,9 @@ RefPtr ResourceLoader::load_resource(Resource::Type type, const LoadRe auto it = s_resource_cache.find(request); if (it != s_resource_cache.end()) { if (it->value->type() != type) { - dbg() << "FIXME: Not using cached resource for " << request.url() << " since there's a type mismatch."; + dbgln("FIXME: Not using cached resource for {} since there's a type mismatch.", request.url()); } else { -#ifdef CACHE_DEBUG - dbg() << "Reusing cached resource for: " << request.url(); -#endif + dbgln("Reusing cached resource for: {}", request.url()); return it->value; } } @@ -112,7 +109,7 @@ void ResourceLoader::load(const LoadRequest& request, Functionset_filename(url.path()); if (!f->open(Core::IODevice::OpenMode::ReadOnly)) { - dbg() << "ResourceLoader::load: Error: " << f->error_string(); + dbgln("ResourceLoader::load: Error: {}", f->error_string()); if (error_callback) error_callback(f->error_string()); return; diff --git a/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp index 5a3c01fc4c..e5812a4f30 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -33,8 +34,6 @@ #include #include -//#define PATH_DEBUG - namespace Web::SVG { #ifdef PATH_DEBUG @@ -136,7 +135,7 @@ void PathDataParser::parse_drawto() } else if (match('A') || match('a')) { parse_elliptical_arc(); } else { - dbg() << "PathDataParser::parse_drawto failed to match: '" << ch() << "'"; + dbgln("PathDataParser::parse_drawto failed to match: '{}'", ch()); TODO(); } } diff --git a/Userland/Services/ChessEngine/ChessEngine.cpp b/Userland/Services/ChessEngine/ChessEngine.cpp index 16394d443c..e45965d771 100644 --- a/Userland/Services/ChessEngine/ChessEngine.cpp +++ b/Userland/Services/ChessEngine/ChessEngine.cpp @@ -26,6 +26,7 @@ #include "ChessEngine.h" #include "MCTSTree.h" +#include #include using namespace Chess::UCI; @@ -68,9 +69,9 @@ void ChessEngine::handle_go(const GoCommand& command) mcts.do_round(); ++rounds; } - dbg() << "MCTS finished " << rounds << " rounds."; - dbg() << "MCTS evaluation " << mcts.expected_value(); + dbgln("MCTS finished {} rounds.", rounds); + dbgln("MCTS evaluation {}", mcts.expected_value()); auto best_move = mcts.best_move(); - dbg() << "MCTS best move " << best_move.to_long_algebraic(); + dbgln("MCTS best move {}", best_move.to_long_algebraic()); send_command(BestMoveCommand(best_move)); } diff --git a/Userland/Services/DHCPClient/DHCPv4.cpp b/Userland/Services/DHCPClient/DHCPv4.cpp index 36430f4eec..0d2041405e 100644 --- a/Userland/Services/DHCPClient/DHCPv4.cpp +++ b/Userland/Services/DHCPClient/DHCPv4.cpp @@ -25,8 +25,7 @@ */ #include "DHCPv4.h" - -//#define DHCPV4_DEBUG +#include ParsedDHCPv4Options DHCPv4Packet::parse_options() const { @@ -42,12 +41,10 @@ ParsedDHCPv4Options DHCPv4Packet::parse_options() const ++index; auto length = m_options[index]; if ((size_t)length > DHCPV4_OPTION_FIELD_MAX_LENGTH - index) { - dbg() << "Bogus option length " << length << " assuming forgotten END"; + dbgln("Bogus option length {} assuming forgotten END", length); break; } -#ifdef DHCPV4_DEBUG - dbg() << "DHCP Option " << (u8)opt_name << " with length " << length; -#endif + dbgln("DHCP Option {} with length {}", (u8)opt_name, length); ++index; options.options.set(opt_name, { length, &m_options[index] }); index += length - 1; diff --git a/Userland/Services/DHCPClient/DHCPv4Client.cpp b/Userland/Services/DHCPClient/DHCPv4Client.cpp index 7a759ed427..59b1668266 100644 --- a/Userland/Services/DHCPClient/DHCPv4Client.cpp +++ b/Userland/Services/DHCPClient/DHCPv4Client.cpp @@ -26,24 +26,23 @@ #include "DHCPv4Client.h" #include +#include #include #include #include #include #include -//#define DHCPV4CLIENT_DEBUG - static void send(const InterfaceDescriptor& iface, const DHCPv4Packet& packet, Core::Object*) { int fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (fd < 0) { - dbg() << "ERROR: socket :: " << strerror(errno); + dbgln("ERROR: socket :: {}", strerror(errno)); return; } if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, iface.m_ifname.characters(), IFNAMSIZ) < 0) { - dbg() << "ERROR: setsockopt(SO_BINDTODEVICE) :: " << strerror(errno); + dbgln("ERROR: setsockopt(SO_BINDTODEVICE) :: {}", strerror(errno)); return; } @@ -56,7 +55,7 @@ static void send(const InterfaceDescriptor& iface, const DHCPv4Packet& packet, C auto rc = sendto(fd, &packet, sizeof(packet), 0, (sockaddr*)&dst, sizeof(dst)); if (rc < 0) { - dbg() << "sendto failed with " << strerror(errno); + dbgln("sendto failed with {}", strerror(errno)); // FIXME: what do we do here? } } @@ -65,7 +64,7 @@ static void set_params(const InterfaceDescriptor& iface, const IPv4Address& ipv4 { int fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP); if (fd < 0) { - dbg() << "ERROR: socket :: " << strerror(errno); + dbgln("ERROR: socket :: {}", strerror(errno)); return; } @@ -83,14 +82,14 @@ static void set_params(const InterfaceDescriptor& iface, const IPv4Address& ipv4 ((sockaddr_in&)ifr.ifr_addr).sin_addr.s_addr = ipv4_addr.to_in_addr_t(); if (ioctl(fd, SIOCSIFADDR, &ifr) < 0) { - dbg() << "ERROR: ioctl(SIOCSIFADDR) :: " << strerror(errno); + dbgln("ERROR: ioctl(SIOCSIFADDR) :: {}", strerror(errno)); } // set the network mask ((sockaddr_in&)ifr.ifr_netmask).sin_addr.s_addr = netmask.to_in_addr_t(); if (ioctl(fd, SIOCSIFNETMASK, &ifr) < 0) { - dbg() << "ERROR: ioctl(SIOCSIFNETMASK) :: " << strerror(errno); + dbgln("ERROR: ioctl(SIOCSIFNETMASK) :: {}", strerror(errno)); } // set the default gateway @@ -103,7 +102,7 @@ static void set_params(const InterfaceDescriptor& iface, const IPv4Address& ipv4 rt.rt_flags = RTF_UP | RTF_GATEWAY; if (ioctl(fd, SIOCADDRT, &rt) < 0) { - dbg() << "Error: ioctl(SIOCADDRT) :: " << strerror(errno); + dbgln("Error: ioctl(SIOCADDRT) :: {}", strerror(errno)); } } @@ -113,9 +112,9 @@ DHCPv4Client::DHCPv4Client(Vector ifnames) m_server = Core::UDPServer::construct(this); m_server->on_ready_to_receive = [this] { auto buffer = m_server->receive(sizeof(DHCPv4Packet)); - dbg() << "Received " << buffer.size() << " bytes"; + dbgln("Received {} bytes", buffer.size()); if (buffer.size() != sizeof(DHCPv4Packet)) { - dbg() << "we expected " << sizeof(DHCPv4Packet) << " bytes, this is a bad packet"; + dbgln("we expected {} bytes, this is a bad packet", sizeof(DHCPv4Packet)); return; } auto& packet = *(DHCPv4Packet*)buffer.data(); @@ -137,10 +136,10 @@ DHCPv4Client::~DHCPv4Client() void DHCPv4Client::handle_offer(const DHCPv4Packet& packet, const ParsedDHCPv4Options& options) { - dbg() << "We were offered " << packet.yiaddr().to_string() << " for " << options.get(DHCPOption::IPAddressLeaseTime).value_or(0); + dbgln("We were offered {} for {}", packet.yiaddr().to_string(), options.get(DHCPOption::IPAddressLeaseTime).value_or(0)); auto* transaction = const_cast(m_ongoing_transactions.get(packet.xid()).value_or(nullptr)); if (!transaction) { - dbg() << "we're not looking for " << packet.xid(); + dbgln("we're not looking for {}", packet.xid()); return; } if (transaction->has_ip) @@ -157,13 +156,14 @@ void DHCPv4Client::handle_offer(const DHCPv4Packet& packet, const ParsedDHCPv4Op void DHCPv4Client::handle_ack(const DHCPv4Packet& packet, const ParsedDHCPv4Options& options) { -#ifdef DHCPV4CLIENT_DEBUG - dbg() << "The DHCP server handed us " << packet.yiaddr().to_string(); - dbg() << "Here are the options: " << options.to_string(); -#endif + if constexpr (debug_dhcpv4_client) { + dbgln("The DHCP server handed us {}", packet.yiaddr().to_string()); + dbgln("Here are the options: {}", options.to_string()); + } + auto* transaction = const_cast(m_ongoing_transactions.get(packet.xid()).value_or(nullptr)); if (!transaction) { - dbg() << "we're not looking for " << packet.xid(); + dbgln("we're not looking for {}", packet.xid()); return; } transaction->has_ip = true; @@ -184,12 +184,12 @@ void DHCPv4Client::handle_ack(const DHCPv4Packet& packet, const ParsedDHCPv4Opti void DHCPv4Client::handle_nak(const DHCPv4Packet& packet, const ParsedDHCPv4Options& options) { - dbg() << "The DHCP server told us to go chase our own tail about " << packet.yiaddr().to_string(); - dbg() << "Here are the options: " << options.to_string(); + dbgln("The DHCP server told us to go chase our own tail about {}", packet.yiaddr().to_string()); + dbgln("Here are the options: {}", options.to_string()); // make another request a bit later :shrug: auto* transaction = const_cast(m_ongoing_transactions.get(packet.xid()).value_or(nullptr)); if (!transaction) { - dbg() << "we're not looking for " << packet.xid(); + dbgln("we're not looking for {}", packet.xid()); return; } transaction->accepted_offer = false; @@ -206,9 +206,9 @@ void DHCPv4Client::handle_nak(const DHCPv4Packet& packet, const ParsedDHCPv4Opti void DHCPv4Client::process_incoming(const DHCPv4Packet& packet) { auto options = packet.parse_options(); -#ifdef DHCPV4CLIENT_DEBUG - dbg() << "Here are the options: " << options.to_string(); -#endif + + dbgln("Here are the options: {}", options.to_string()); + auto value = options.get(DHCPOption::DHCPMessageType).value(); switch (value) { case DHCPMessageType::DHCPOffer: @@ -229,7 +229,7 @@ void DHCPv4Client::process_incoming(const DHCPv4Packet& packet) break; case DHCPMessageType::DHCPDecline: default: - dbg() << "I dunno what to do with this " << (u8)value; + dbgln("I dunno what to do with this {}", (u8)value); ASSERT_NOT_REACHED(); break; } @@ -238,11 +238,13 @@ void DHCPv4Client::process_incoming(const DHCPv4Packet& packet) void DHCPv4Client::dhcp_discover(const InterfaceDescriptor& iface, IPv4Address previous) { auto transaction_id = rand(); -#ifdef DHCPV4CLIENT_DEBUG - dbg() << "Trying to lease an IP for " << iface.m_ifname << " with ID " << transaction_id; - if (!previous.is_zero()) - dbg() << "going to request the server to hand us " << previous.to_string(); -#endif + + if constexpr (debug_dhcpv4_client) { + dbgln("Trying to lease an IP for {} with ID {}", iface.m_ifname, transaction_id); + if (!previous.is_zero()) + dbgln("going to request the server to hand us {}", previous.to_string()); + } + DHCPv4PacketBuilder builder; DHCPv4Packet& packet = builder.peek(); @@ -267,7 +269,7 @@ void DHCPv4Client::dhcp_discover(const InterfaceDescriptor& iface, IPv4Address p void DHCPv4Client::dhcp_request(DHCPv4Transaction& transaction, const DHCPv4Packet& offer) { auto& iface = transaction.interface; - dbg() << "Leasing the IP " << offer.yiaddr().to_string() << " for adapter " << iface.m_ifname; + dbgln("Leasing the IP {} for adapter {}", offer.yiaddr().to_string(), iface.m_ifname); DHCPv4PacketBuilder builder; DHCPv4Packet& packet = builder.peek();