Pārlūkot izejas kodu

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 gadi atpakaļ
vecāks
revīzija
fb8d3635d9

+ 42 - 0
AK/Debug.h

@@ -513,3 +513,45 @@ constexpr bool debug_occlusions = true;
 #else
 constexpr bool debug_occlusions = false;
 #endif
+
+#ifdef DEBUG_MENUS
+constexpr bool debug_menus = true;
+#else
+constexpr bool debug_menus = false;
+#endif
+
+#ifdef WSSCREEN_DEBUG
+constexpr bool debug_wsscreen = true;
+#else
+constexpr bool debug_wsscreen = false;
+#endif
+
+#ifdef WINDOWMANAGER_DEBUG
+constexpr bool debug_window_manager = true;
+#else
+constexpr bool debug_window_manager = false;
+#endif
+
+#ifdef RESIZE_DEBUG
+constexpr bool debug_resize = true;
+#else
+constexpr bool debug_resize = false;
+#endif
+
+#ifdef MOVE_DEBUG
+constexpr bool debug_move = true;
+#else
+constexpr bool debug_move = false;
+#endif
+
+#ifdef DOUBLECLICK_DEBUG
+constexpr bool debug_double_click = true;
+#else
+constexpr bool debug_double_click = false;
+#endif
+
+#ifdef DISASM_DUMP
+constexpr bool debug_disasm_dump = true;
+#else
+constexpr bool debug_disasm_dump = false;
+#endif

+ 3 - 3
Userland/Services/WindowServer/Cursor.cpp

@@ -67,7 +67,7 @@ CursorParams CursorParams::parse_from_file_name(const StringView& cursor_path, c
             return parsed_number.value();
         }();
         if (!value.has_value()) {
-            dbg() << "Failed to parse value for property '" << property << "' from parsed cursor path: " << cursor_path;
+            dbgln("Failed to parse value for property '{}' from parsed cursor path: {}", property, cursor_path);
             return { default_hotspot };
         }
         switch (property) {
@@ -93,7 +93,7 @@ CursorParams CursorParams::parse_from_file_name(const StringView& cursor_path, c
             in_display_scale_part = true;
             break;
         default:
-            dbg() << "Ignore unknown property '" << property << "' with value " << value.value() << " parsed from cursor path: " << cursor_path;
+            dbgln("Ignore unknown property '{}' with value {} parsed from cursor path: {}", property, value.value(), cursor_path);
             return { default_hotspot };
         }
     }
@@ -108,7 +108,7 @@ CursorParams CursorParams::constrained(const Gfx::Bitmap& bitmap) const
         if (rect.width() % params.m_frames == 0) {
             rect.set_width(rect.width() / (int)params.m_frames);
         } else {
-            dbg() << "Cannot divide cursor dimensions " << rect << " into " << params.m_frames << " frames";
+            dbgln("Cannot divide cursor dimensions {} into {} frames", rect, params.m_frames);
             params.m_frames = 1;
         }
     }

+ 4 - 5
Userland/Services/WindowServer/MenuManager.cpp

@@ -26,6 +26,7 @@
  */
 
 #include <AK/Badge.h>
+#include <AK/Debug.h>
 #include <AK/QuickSort.h>
 #include <LibCore/DirIterator.h>
 #include <LibGfx/Font.h>
@@ -36,8 +37,6 @@
 #include <WindowServer/WindowManager.h>
 #include <unistd.h>
 
-//#define DEBUG_MENUS
-
 namespace WindowServer {
 
 static MenuManager* s_the;
@@ -459,9 +458,9 @@ void MenuManager::set_current_menubar(MenuBar* menubar)
         m_current_menubar = *menubar;
     else
         m_current_menubar = nullptr;
-#ifdef DEBUG_MENUS
-    dbg() << "[WM] Current menubar is now " << menubar;
-#endif
+
+    dbgln<debug_menus>("[WM] Current menubar is now {}", menubar);
+
     Gfx::IntPoint next_menu_location { MenuManager::menubar_menu_margin() / 2, 0 };
     for_each_active_menubar_menu([&](Menu& menu) {
         int text_width = menu.title_font().width(menu.name());

+ 4 - 4
Userland/Services/WindowServer/Screen.cpp

@@ -29,6 +29,7 @@
 #include "Event.h"
 #include "EventLoop.h"
 #include "WindowManager.h"
+#include <AK/Debug.h>
 #include <Kernel/API/FB.h>
 #include <Kernel/API/MousePacket.h>
 #include <fcntl.h>
@@ -81,15 +82,14 @@ bool Screen::set_resolution(int width, int height, int new_scale_factor)
 
     FBResolution physical_resolution { 0, (unsigned)new_physical_width, (unsigned)new_physical_height };
     int rc = fb_set_resolution(m_framebuffer_fd, &physical_resolution);
-#ifdef WSSCREEN_DEBUG
-    dbg() << "fb_set_resolution() - return code " << rc;
-#endif
+    dbgln<debug_wsscreen>("fb_set_resolution() - return code {}", rc);
+
     if (rc == 0) {
         on_change_resolution(physical_resolution.pitch, physical_resolution.width, physical_resolution.height, new_scale_factor);
         return true;
     }
     if (rc == -1) {
-        dbg() << "Invalid resolution " << width << "x" << height;
+        dbgln("Invalid resolution {}x{}", width, height);
         on_change_resolution(physical_resolution.pitch, physical_resolution.width, physical_resolution.height, new_scale_factor);
         return false;
     }

+ 34 - 45
Userland/Services/WindowServer/WindowManager.cpp

@@ -139,13 +139,13 @@ bool WindowManager::set_resolution(int width, int height, int scale)
     }
     if (m_config) {
         if (success) {
-            dbg() << "Saving resolution: " << Gfx::IntSize(width, height) << " @ " << scale << "x to config file at " << m_config->file_name();
+            dbgln("Saving resolution: {} @ {}x to config file at {}", Gfx::IntSize(width, height), scale, m_config->file_name());
             m_config->write_num_entry("Screen", "Width", width);
             m_config->write_num_entry("Screen", "Height", height);
             m_config->write_num_entry("Screen", "ScaleFactor", scale);
             m_config->sync();
         } else {
-            dbg() << "Saving fallback resolution: " << resolution() << " @ 1x to config file at " << m_config->file_name();
+            dbgln("Saving fallback resolution: {} @1x to config file at {}", resolution(), m_config->file_name());
             m_config->write_num_entry("Screen", "Width", resolution().width());
             m_config->write_num_entry("Screen", "Height", resolution().height());
             m_config->write_num_entry("Screen", "ScaleFactor", 1);
@@ -347,9 +347,9 @@ void WindowManager::notify_title_changed(Window& window)
 {
     if (window.type() != WindowType::Normal)
         return;
-#ifdef WINDOWMANAGER_DEBUG
-    dbg() << "[WM] Window{" << &window << "} title set to \"" << window.title() << '"';
-#endif
+
+    dbgln<debug_window_manager>("[WM] Window({}) title set to '{}'", &window, window.title());
+
     if (m_switcher.is_visible())
         m_switcher.refresh();
 
@@ -360,20 +360,19 @@ void WindowManager::notify_modal_unparented(Window& window)
 {
     if (window.type() != WindowType::Normal)
         return;
-#ifdef WINDOWMANAGER_DEBUG
-    dbg() << "[WM] Modal Window{" << &window << "} was unparented";
-#endif
+
+    dbgln<debug_window_manager>("[WM] Window({}) was unparented", &window);
+
     if (m_switcher.is_visible())
         m_switcher.refresh();
 
     tell_wm_listeners_window_state_changed(window);
 }
 
-void WindowManager::notify_rect_changed(Window& window, [[maybe_unused]] const Gfx::IntRect& old_rect, [[maybe_unused]] const Gfx::IntRect& new_rect)
+void WindowManager::notify_rect_changed(Window& window, const Gfx::IntRect& old_rect, const Gfx::IntRect& new_rect)
 {
-#ifdef RESIZE_DEBUG
-    dbg() << "[WM] Window " << &window << " rect changed " << old_rect << " -> " << new_rect;
-#endif
+    dbgln<debug_resize>("[WM] Window({}) rect changed {} -> {}", &window, old_rect, new_rect);
+
     if (m_switcher.is_visible() && window.type() != WindowType::WindowSwitcher)
         m_switcher.refresh();
 
@@ -437,9 +436,8 @@ bool WindowManager::pick_new_active_window(Window* previous_active)
 
 void WindowManager::start_window_move(Window& window, const MouseEvent& event)
 {
-#ifdef MOVE_DEBUG
-    dbg() << "[WM] Begin moving Window{" << &window << "}";
-#endif
+    dbgln<debug_move>("[WM] Begin moving Window({})", &window);
+
     move_to_front_and_make_active(window);
     m_move_window = window;
     m_move_window->set_default_positioned(false);
@@ -459,7 +457,7 @@ void WindowManager::start_window_resize(Window& window, const Gfx::IntPoint& pos
     Gfx::IntRect outer_rect = window.frame().rect();
     if (!outer_rect.contains(position)) {
         // FIXME: This used to be an ASSERT but crashing WindowServer over this seems silly.
-        dbg() << "FIXME: !outer_rect.contains(position): outer_rect=" << outer_rect << ", position=" << position;
+        dbgln("FIXME: !outer_rect.contains(position): outer_rect={}, position={}", outer_rect, position);
     }
     int window_relative_x = position.x() - outer_rect.x();
     int window_relative_y = position.y() - outer_rect.y();
@@ -471,9 +469,8 @@ void WindowManager::start_window_resize(Window& window, const Gfx::IntPoint& pos
         return;
     }
 
-#ifdef RESIZE_DEBUG
-    dbg() << "[WM] Begin resizing Window{" << &window << "}";
-#endif
+    dbgln<debug_resize>("[WM] Begin resizing Window({})", &window);
+
     m_resizing_mouse_button = button;
     m_resize_window = window;
     m_resize_origin = position;
@@ -498,9 +495,8 @@ bool WindowManager::process_ongoing_window_move(MouseEvent& event, Window*& hove
     if (!m_move_window)
         return false;
     if (event.type() == Event::MouseUp && event.button() == MouseButton::Left) {
-#ifdef MOVE_DEBUG
-        dbg() << "[WM] Finish moving Window{" << m_move_window << "}";
-#endif
+
+        dbgln<debug_move>("[WM] Finish moving Window({})", m_move_window);
 
         m_move_window->invalidate();
         if (m_move_window->rect().contains(event.position()))
@@ -518,21 +514,17 @@ bool WindowManager::process_ongoing_window_move(MouseEvent& event, Window*& hove
         return true;
     }
     if (event.type() == Event::MouseMove) {
-
-#ifdef MOVE_DEBUG
-        dbg() << "[WM] Moving, origin: " << m_move_origin << ", now: " << event.position();
-        if (m_move_window->is_maximized()) {
-            dbgln("  [!] The window is still maximized. Not moving yet.");
+        if constexpr (debug_move) {
+            dbgln("[WM] Moving, origin: {}, now: {}", m_move_origin, event.position());
+            if (m_move_window->is_maximized())
+                dbgln("  [!] The window is still maximized. Not moving yet.");
         }
 
-#endif
-
         const int tiling_deadzone = 10;
         const int secondary_deadzone = 2;
 
         if (m_move_window->is_maximized()) {
             auto pixels_moved_from_start = event.position().pixels_moved(m_move_origin);
-            // dbg() << "[WM] " << pixels_moved_from_start << " moved since start of window move";
             if (pixels_moved_from_start > 5) {
                 // dbgln("[WM] de-maximizing window");
                 m_move_origin = event.position();
@@ -585,9 +577,8 @@ bool WindowManager::process_ongoing_window_resize(const MouseEvent& event, Windo
         return false;
 
     if (event.type() == Event::MouseUp && event.button() == m_resizing_mouse_button) {
-#ifdef RESIZE_DEBUG
-        dbg() << "[WM] Finish resizing Window{" << m_resize_window << "}";
-#endif
+        dbgln<debug_resize>("[WM] Finish resizing Window({})", m_resize_window);
+
         Core::EventLoop::current().post_event(*m_resize_window, make<ResizeEvent>(m_resize_window->rect()));
         m_resize_window->invalidate();
         if (m_resize_window->rect().contains(event.position()))
@@ -693,9 +684,9 @@ bool WindowManager::process_ongoing_window_resize(const MouseEvent& event, Windo
 
     if (m_resize_window->rect() == new_rect)
         return true;
-#ifdef RESIZE_DEBUG
-    dbg() << "[WM] Resizing, original: " << m_resize_window_original_rect << ", now: " << new_rect;
-#endif
+
+    dbgln<debug_resize>("[WM] Resizing, original: {}, now: {}", m_resize_window_original_rect, new_rect);
+
     m_resize_window->set_rect(new_rect);
     Core::EventLoop::current().post_event(*m_resize_window, make<ResizeEvent>(new_rect));
     return true;
@@ -817,9 +808,9 @@ void WindowManager::start_menu_doubleclick(Window& window, const MouseEvent& eve
     if (&window != m_double_click_info.m_clicked_window) {
         // we either haven't clicked anywhere, or we haven't clicked on this
         // window. set the current click window, and reset the timers.
-#if defined(DOUBLECLICK_DEBUG)
-        dbg() << "Initial mousedown on window " << &window << " for menu (previous was " << m_double_click_info.m_clicked_window << ')';
-#endif
+
+        dbgln<debug_double_click>("Initial mousedown on Window({}) for menus (previous was {})", &window, m_double_click_info.m_clicked_window);
+
         m_double_click_info.m_clicked_window = window;
         m_double_click_info.reset();
     }
@@ -850,9 +841,8 @@ void WindowManager::process_event_for_doubleclick(Window& window, MouseEvent& ev
     if (&window != m_double_click_info.m_clicked_window) {
         // we either haven't clicked anywhere, or we haven't clicked on this
         // window. set the current click window, and reset the timers.
-#if defined(DOUBLECLICK_DEBUG)
-        dbg() << "Initial mouseup on window " << &window << " (previous was " << m_double_click_info.m_clicked_window << ')';
-#endif
+        dbgln<debug_double_click>("Initial mouseup on Window({}) for menus (previous was {})", &window, m_double_click_info.m_clicked_window);
+
         m_double_click_info.m_clicked_window = window;
         m_double_click_info.reset();
     }
@@ -866,9 +856,8 @@ void WindowManager::process_event_for_doubleclick(Window& window, MouseEvent& ev
         // clock
         metadata.clock.start();
     } else {
-#if defined(DOUBLECLICK_DEBUG)
-        dbg() << "Transforming MouseUp to MouseDoubleClick (" << metadata.clock.elapsed() << " < " << m_double_click_speed << ")!";
-#endif
+        dbgln<debug_double_click>("Transforming MouseUp to MouseDoubleClick ({} < {})!", metadata.clock.elapsed(), m_double_click_speed);
+
         event = MouseEvent(Event::MouseDoubleClick, event.position(), event.buttons(), event.button(), event.modifiers(), event.wheel_delta());
         // invalidate this now we've delivered a doubleclick, otherwise
         // tripleclick will deliver two doubleclick events (incorrectly).

+ 1 - 1
Userland/Shell/Job.h

@@ -55,7 +55,7 @@ public:
         if (m_active) {
             auto elapsed = m_command_timer.elapsed();
             // Don't mistake this for the command!
-            dbg() << "Job entry \"" << m_cmd << "\" deleted in " << elapsed << " ms";
+            dbgln("Job entry '{}' deleted in {} ms", m_cmd, elapsed);
         }
 #endif
     }

+ 5 - 6
Userland/Utilities/disasm.cpp

@@ -24,6 +24,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <AK/Debug.h>
 #include <AK/LogStream.h>
 #include <AK/MappedFile.h>
 #include <AK/QuickSort.h>
@@ -35,8 +36,6 @@
 #include <stdio.h>
 #include <string.h>
 
-//#define DISASM_DUMP
-
 int main(int argc, char** argv)
 {
     const char* path = nullptr;
@@ -100,10 +99,10 @@ int main(int argc, char** argv)
                     return a.size < b.size;
                 return a.name < b.name;
             });
-#ifdef DISASM_DUMP
-            for (size_t i = 0; i < symbols.size(); ++i)
-                dbg() << symbols[i].name << ": " << (void*)(uintptr_t)symbols[i].value << ", " << symbols[i].size;
-#endif
+            if constexpr (debug_disasm_dump) {
+                for (size_t i = 0; i < symbols.size(); ++i)
+                    dbgln("{}: {:p}, {}", symbols[i].name, symbols[i].value, symbols[i].size);
+            }
         }
     }
 

+ 2 - 2
Userland/Utilities/mount.cpp

@@ -121,8 +121,8 @@ static bool mount_all()
 
         int fd = get_source_fd(filename);
 
-        dbg() << "Mounting " << filename << "(" << fstype << ")"
-              << " on " << mountpoint;
+        dbgln("Mounting {} ({}) on {}", filename, fstype, mountpoint);
+
         int rc = mount(fd, mountpoint, fstype, flags);
         if (rc != 0) {
             fprintf(stderr, "Failed to mount %s (FD: %d) (%s) on %s: %s\n", filename, fd, fstype, mountpoint, strerror(errno));

+ 4 - 3
Userland/Utilities/test-crypto.cpp

@@ -1832,7 +1832,7 @@ static void rsa_test_encrypt()
         if (memcmp(buf.data(), "hellohellohellohellohellohellohellohellohello123-", 49))
             FAIL(Invalid encryption);
         else {
-            dbg() << "out size " << buf.size() << " values: " << StringView { (char*)buf.data(), buf.size() };
+            dbgln("out size {} values {}", buf.size(), StringView { (char*)buf.data(), buf.size() });
 
             PASS;
         }
@@ -1999,7 +1999,8 @@ static void rsa_test_encrypt_decrypt()
         "9527497237087650398000977129550904920919162360737979403539302312977329868395261515707123424679295515888026193056908173564681660256268221509339074678416049"_bigint,
         "39542231845947188736992321577701849924317746648774438832456325878966594812143638244746284968851807975097653255909707366086606867657273809465195392910913"_bigint,
         "65537"_bigint);
-    dbg() << "Output size: " << rsa.output_size();
+
+    dbgln("Output size: {}", rsa.output_size());
 
     u8 enc_buffer[rsa.output_size()];
     u8 dec_buffer[rsa.output_size()];
@@ -2012,7 +2013,7 @@ static void rsa_test_encrypt_decrypt()
     rsa.encrypt(enc, dec);
     rsa.decrypt(dec, enc);
 
-    dbg() << "enc size " << enc.size() << " dec size " << dec.size();
+    dbgln("enc size {} dec size {}", enc.size(), dec.size());
 
     if (memcmp(enc.data(), "WellHelloFriendsWellHelloFriendsWellHelloFriendsWellHelloFriends", 64) != 0) {
         FAIL(Could not encrypt then decrypt);