diff options
author | asynts <asynts@gmail.com> | 2021-01-18 17:25:44 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-22 22:14:30 +0100 |
commit | ea7b7d8ceb2f48127b196a4eaf958bb387bb61da (patch) | |
tree | 81ef2a3848a8b64ed0960f0c9055c216390b8baf | |
parent | fb8d3635d912a40a66a9e4b50454cfdd83f71d16 (diff) | |
download | serenity-ea7b7d8ceb2f48127b196a4eaf958bb387bb61da.zip |
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.
-rw-r--r-- | AK/Debug.h | 18 | ||||
-rw-r--r-- | AK/LogStream.cpp | 2 | ||||
-rw-r--r-- | Base/usr/share/man/man1/test-js.md | 2 | ||||
-rw-r--r-- | Base/usr/share/man/man3/basename.md | 8 | ||||
-rw-r--r-- | Base/usr/share/man/man3/dirname.md | 8 | ||||
-rw-r--r-- | Kernel/Lock.cpp | 67 | ||||
-rw-r--r-- | Kernel/Thread.cpp | 7 | ||||
-rw-r--r-- | Meta/CMake/all_the_debug_macros.cmake | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp | 55 | ||||
-rw-r--r-- | Userland/Utilities/test-js.cpp | 2 |
10 files changed, 99 insertions, 74 deletions
diff --git a/AK/Debug.h b/AK/Debug.h index daf2dffc52..fa4297948a 100644 --- a/AK/Debug.h +++ b/AK/Debug.h @@ -555,3 +555,21 @@ constexpr bool debug_disasm_dump = true; #else constexpr bool debug_disasm_dump = false; #endif + +#ifdef DEBUG_PATH +constexpr bool debug_path = true; +#else +constexpr bool debug_path = false; +#endif + +#ifdef LOCK_TRACE_DEBUG +constexpr bool debug_lock_trace = true; +#else +constexpr bool debug_lock_trace = false; +#endif + +#ifdef LOCK_RESTORE_DEBUG +constexpr bool debug_lock_restore = true; +#else +constexpr bool debug_lock_restore = false; +#endif diff --git a/AK/LogStream.cpp b/AK/LogStream.cpp index d150adfcc1..416e3ce2b3 100644 --- a/AK/LogStream.cpp +++ b/AK/LogStream.cpp @@ -235,7 +235,7 @@ void dump_bytes(ReadonlyBytes bytes) builder.append(" }"); - dbg() << builder.to_string(); + dbgln("{}", builder.string_view()); } } diff --git a/Base/usr/share/man/man1/test-js.md b/Base/usr/share/man/man1/test-js.md index d1a6be034e..451743720f 100644 --- a/Base/usr/share/man/man1/test-js.md +++ b/Base/usr/share/man/man1/test-js.md @@ -19,7 +19,7 @@ It also supports the [test262 parser tests](https://github.com/tc39/test262-pars The test root directory is assumed to be `/home/anon/js-tests`, or `$SERENITY_ROOT/Libraries/LibJS/Tests` when using the Lagom build. Optionally you can pass a custom path to `test-js` to override these defaults. -You can disable output from `dbg()` calls by setting the `DISABLE_DBG_OUTPUT` environment variable. +You can disable output from `dbgln()` calls by setting the `DISABLE_DBG_OUTPUT` environment variable. ## Options diff --git a/Base/usr/share/man/man3/basename.md b/Base/usr/share/man/man3/basename.md index 716ef8f29e..f670f4129f 100644 --- a/Base/usr/share/man/man3/basename.md +++ b/Base/usr/share/man/man3/basename.md @@ -35,16 +35,16 @@ buffer while using the returned string. int main() { char path1[] = "/home/anon/ReadMe.md"; - dbg() << basename(path1); // should be "ReadMe.md" + dbgln("{}", basename(path1)); // should be "ReadMe.md" char path2[] = "foo/bar/"; - dbg() << basename(path2); // should be "bar" + dbgln("{}", basename(path2)); // should be "bar" char path3[] = "foo"; - dbg() << basename(path3); // should be "foo" + dbgln("{}", basename(path3)); // should be "foo" char path4[] = "/"; - dbg() << basename(path4); // should be "/" + dbgln("{}", basename(path4)); // should be "/" } ``` diff --git a/Base/usr/share/man/man3/dirname.md b/Base/usr/share/man/man3/dirname.md index 6a101d9dbf..509628716d 100644 --- a/Base/usr/share/man/man3/dirname.md +++ b/Base/usr/share/man/man3/dirname.md @@ -36,16 +36,16 @@ buffer while using the returned string. int main() { char path1[] = "/home/anon/ReadMe.md"; - dbg() << dirname(path1); // should be "/home/anon" + dbgln("{}", dirname(path1)); // should be "/home/anon" char path2[] = "foo/bar/"; - dbg() << dirname(path2); // should be "foo" + dbgln("{}", dirname(path2)); // should be "foo" char path3[] = "foo"; - dbg() << dirname(path3); // should be "." + dbgln("{}", dirname(path3)); // should be "." char path4[] = "/"; - dbg() << dirname(path4); // should be "/" + dbgln("{}", dirname(path4)); // should be "/" } ``` diff --git a/Kernel/Lock.cpp b/Kernel/Lock.cpp index f543bf22f7..9b0ddb5090 100644 --- a/Kernel/Lock.cpp +++ b/Kernel/Lock.cpp @@ -24,14 +24,12 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include <AK/Debug.h> #include <AK/TemporaryChange.h> #include <Kernel/KSyms.h> #include <Kernel/Lock.h> #include <Kernel/Thread.h> -//#define LOCK_TRACE_DEBUG -//#define LOCK_RESTORE_DEBUG - namespace Kernel { #ifdef LOCK_DEBUG @@ -58,9 +56,7 @@ void Lock::lock(Mode mode) Mode current_mode = m_mode; switch (current_mode) { case Mode::Unlocked: { -#ifdef LOCK_TRACE_DEBUG - dbg() << "Lock::lock @ " << this << ": acquire " << mode_to_string(mode) << ", currently unlocked"; -#endif + dbgln<debug_lock_trace>("Lock::lock @ {}: acquire {}, currently unlocked", this, mode_to_string(mode)); m_mode = mode; ASSERT(!m_holder); ASSERT(m_shared_holders.is_empty()); @@ -83,12 +79,14 @@ void Lock::lock(Mode mode) if (m_holder != current_thread) break; ASSERT(m_shared_holders.is_empty()); -#ifdef LOCK_TRACE_DEBUG - if (mode == Mode::Exclusive) - dbg() << "Lock::lock @ " << this << ": acquire " << mode_to_string(mode) << ", currently exclusive, holding: " << m_times_locked; - else - dbg() << "Lock::lock @ " << this << ": acquire exclusive (requested " << mode_to_string(mode) << "), currently exclusive, holding " << m_times_locked; -#endif + + if constexpr (debug_lock_trace) { + if (mode == Mode::Exclusive) + dbgln("Lock::lock @ {}: acquire {}, currently exclusive, holding: {}", this, mode_to_string(mode), m_times_locked); + else + dbgln("Lock::lock @ {}: acquire exclusive (requested {}), currently exclusive, holding: {}", this, mode_to_string(mode), m_times_locked); + } + ASSERT(mode == Mode::Exclusive || mode == Mode::Shared); ASSERT(m_times_locked > 0); m_times_locked++; @@ -102,9 +100,9 @@ void Lock::lock(Mode mode) ASSERT(!m_holder); if (mode != Mode::Shared) break; -#ifdef LOCK_TRACE_DEBUG - dbg() << "Lock::lock @ " << this << ": acquire " << mode_to_string(mode) << ", currently shared, locks held: " << m_times_locked; -#endif + + dbgln<debug_lock_trace>("Lock::lock @ {}: acquire {}, currently shared, locks held {}", this, mode_to_string(mode), m_times_locked); + ASSERT(m_times_locked > 0); m_times_locked++; ASSERT(!m_shared_holders.is_empty()); @@ -141,12 +139,13 @@ void Lock::unlock() for (;;) { if (m_lock.exchange(true, AK::memory_order_acq_rel) == false) { Mode current_mode = m_mode; -#ifdef LOCK_TRACE_DEBUG - if (current_mode == Mode::Shared) - dbg() << "Lock::unlock @ " << this << ": release " << mode_to_string(current_mode) << ", locks held: " << m_times_locked; - else - dbg() << "Lock::unlock @ " << this << ": release " << mode_to_string(current_mode) << ", holding: " << m_times_locked; -#endif + if constexpr (debug_lock_trace) { + if (current_mode == Mode::Shared) + dbgln("Lock::unlock @ {}: release {}, locks held: {}", this, mode_to_string(current_mode), m_times_locked); + else + dbgln("Lock::unlock @ {}: release {}, holding: {}", this, mode_to_string(current_mode), m_times_locked); + } + ASSERT(current_mode != Mode::Unlocked); ASSERT(m_times_locked > 0); @@ -211,9 +210,9 @@ auto Lock::force_unlock_if_locked(u32& lock_count_to_restore) -> Mode lock_count_to_restore = 0; return Mode::Unlocked; } -#ifdef LOCK_RESTORE_DEBUG - dbg() << "Lock::force_unlock_if_locked @ " << this << ": unlocking exclusive with lock count: " << m_times_locked; -#endif + + dbgln<debug_lock_restore>("Lock::force_unlock_if_locked @ {}: unlocking exclusive with lock count: {}", this, m_times_locked); + m_holder = nullptr; ASSERT(m_times_locked > 0); lock_count_to_restore = m_times_locked; @@ -234,9 +233,10 @@ auto Lock::force_unlock_if_locked(u32& lock_count_to_restore) -> Mode lock_count_to_restore = 0; return Mode::Unlocked; } -#ifdef LOCK_RESTORE_DEBUG - dbg() << "Lock::force_unlock_if_locked @ " << this << ": unlocking exclusive with lock count: " << it->value << ", total locks: " << m_times_locked; -#endif + + dbgln<debug_lock_restore>("Lock::force_unlock_if_locked @ {}: unlocking exclusive with lock count: {}, total locks: {}", + this, it->value, m_times_locked); + ASSERT(it->value > 0); lock_count_to_restore = it->value; ASSERT(lock_count_to_restore > 0); @@ -292,9 +292,9 @@ void Lock::restore_lock(Mode mode, u32 lock_count) auto expected_mode = Mode::Unlocked; if (!m_mode.compare_exchange_strong(expected_mode, Mode::Exclusive)) break; -#ifdef LOCK_RESTORE_DEBUG - dbg() << "Lock::restore_lock @ " << this << ": restoring " << mode_to_string(mode) << " with lock count " << lock_count << ", was unlocked"; -#endif + + dbgln<debug_lock_restore>("Lock::restore_lock @ {}: restoring {} with lock count {}, was unlocked", this, mode_to_string(mode), lock_count); + ASSERT(m_times_locked == 0); m_times_locked = lock_count; ASSERT(!m_holder); @@ -310,9 +310,10 @@ void Lock::restore_lock(Mode mode, u32 lock_count) auto expected_mode = Mode::Unlocked; if (!m_mode.compare_exchange_strong(expected_mode, Mode::Shared) && expected_mode != Mode::Shared) break; -#ifdef LOCK_RESTORE_DEBUG - dbg() << "Lock::restore_lock @ " << this << ": restoring " << mode_to_string(mode) << " with lock count " << lock_count << ", was " << mode_to_string(expected_mode); -#endif + + dbgln<debug_lock_restore>("Lock::restore_lock @ {}: restoring {} with lock count {}, was {}", + this, mode_to_string(mode), lock_count, mode_to_string(expected_mode)); + ASSERT(expected_mode == Mode::Shared || m_times_locked == 0); m_times_locked += lock_count; ASSERT(!m_holder); diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index 5e7a89eda5..8a4bef44fb 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -43,9 +43,6 @@ #include <Kernel/VM/ProcessPagingScope.h> #include <LibC/signal_numbers.h> -//#define SIGNAL_DEBUG -//#define THREAD_DEBUG - namespace Kernel { Thread::Thread(NonnullRefPtr<Process> process) @@ -363,10 +360,10 @@ void Thread::finalize() #ifdef LOCK_DEBUG ASSERT(!m_lock.own_lock()); if (lock_count() > 0) { - dbg() << "Thread " << *this << " leaking " << lock_count() << " Locks!"; + dbgln("Thread {} leaking {} Locks!", *this, lock_count()); ScopedSpinLock list_lock(m_holding_locks_lock); for (auto& info : m_holding_locks_list) - dbg() << " - " << info.lock->name() << " @ " << info.lock << " locked at " << info.file << ":" << info.line << " count: " << info.count; + dbgln(" - {} @ {} locked at {}:{} count: {}", info.lock->name(), info.lock, info.file, info.line, info.count); ASSERT_NOT_REACHED(); } #endif diff --git a/Meta/CMake/all_the_debug_macros.cmake b/Meta/CMake/all_the_debug_macros.cmake index cba732260c..bbc5930692 100644 --- a/Meta/CMake/all_the_debug_macros.cmake +++ b/Meta/CMake/all_the_debug_macros.cmake @@ -166,11 +166,13 @@ 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") +add_compile_definitions("DEBUG_PATH") # False positive: IF_BMP_DEBUG is not actually a flag. # add_compile_definitions("IF_BMP_DEBUG") # False positive: LOG_DEBUG is a flag, but for a bitset, not a feature. # add_compile_definitions("LOG_DEBUG") +# Clogs up build: The WrapperGenerator stuff is run at compile time. +# add_compile_definitions("WRAPPER_GERNERATOR_DEBUG") diff --git a/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp index e5812a4f30..a11ac8c7fd 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp @@ -36,66 +36,73 @@ namespace Web::SVG { -#ifdef PATH_DEBUG static void print_instruction(const PathInstruction& instruction) { + ASSERT(debug_path); + auto& data = instruction.data; switch (instruction.type) { case PathInstructionType::Move: - dbg() << "Move (absolute=" << instruction.absolute << ")"; + dbgln("Move (absolute={})", instruction.absolute); for (size_t i = 0; i < data.size(); i += 2) - dbg() << " x=" << data[i] << ", y=" << data[i + 1]; + dbgln(" x={}, y={}", data[i], data[i + 1]); break; case PathInstructionType::ClosePath: - dbg() << "ClosePath (absolute=" << instruction.absolute << ")"; + dbgln("ClosePath (absolute={})", instruction.absolute); break; case PathInstructionType::Line: - dbg() << "Line (absolute=" << instruction.absolute << ")"; + dbgln("Line (absolute={})", instruction.absolute); for (size_t i = 0; i < data.size(); i += 2) - dbg() << " x=" << data[i] << ", y=" << data[i + 1]; + dbgln(" x={}, y={}", data[i], data[i + 1]); break; case PathInstructionType::HorizontalLine: - dbg() << "HorizontalLine (absolute=" << instruction.absolute << ")"; + dbgln("HorizontalLine (absolute={})", instruction.absolute); for (size_t i = 0; i < data.size(); ++i) - dbg() << " x=" << data[i]; + dbgln(" x={}", data[i]); break; case PathInstructionType::VerticalLine: - dbg() << "VerticalLine (absolute=" << instruction.absolute << ")"; + dbgln("VerticalLine (absolute={})", instruction.absolute); for (size_t i = 0; i < data.size(); ++i) - dbg() << " y=" << data[i]; + dbgln(" y={}", data[i]); break; case PathInstructionType::Curve: - dbg() << "Curve (absolute=" << instruction.absolute << ")"; + dbgln("Curve (absolute={})", instruction.absolute); for (size_t i = 0; i < data.size(); i += 6) - dbg() << " (x1=" << data[i] << ", y1=" << data[i + 1] << "), (x2=" << data[i + 2] << ", y2=" << data[i + 3] << "), (x=" << data[i + 4] << ", y=" << data[i + 5] << ")"; + dbgln(" (x1={}, y1={}, x2={}, y2={}), (x={}, y={})", data[i], data[i + 1], data[i + 2], data[i + 3], data[i + 4], data[i + 5]); break; case PathInstructionType::SmoothCurve: - dbg() << "SmoothCurve (absolute=" << instruction.absolute << ")"; + dbgln("SmoothCurve (absolute={})", instruction.absolute); for (size_t i = 0; i < data.size(); i += 4) - dbg() << " (x2=" << data[i] << ", y2=" << data[i + 1] << "), (x=" << data[i + 2] << ", y=" << data[i + 3] << ")"; + dbgln(" (x2={}, y2={}), (x={}, y={})", data[i], data[i + 1], data[i + 2], data[i + 3]); break; case PathInstructionType::QuadraticBezierCurve: - dbg() << "QuadraticBezierCurve (absolute=" << instruction.absolute << ")"; + dbgln("QuadraticBezierCurve (absolute={})", instruction.absolute); for (size_t i = 0; i < data.size(); i += 4) - dbg() << " (x1=" << data[i] << ", y1=" << data[i + 1] << "), (x=" << data[i + 2] << ", y=" << data[i + 3] << ")"; + dbgln(" (x1={}, y1={}), (x={}, y={})", data[i], data[i + 1], data[i + 2], data[i + 3]); break; case PathInstructionType::SmoothQuadraticBezierCurve: - dbg() << "SmoothQuadraticBezierCurve (absolute=" << instruction.absolute << ")"; + dbgln("SmoothQuadraticBezierCurve (absolute={})", instruction.absolute); for (size_t i = 0; i < data.size(); i += 2) - dbg() << " x=" << data[i] << ", y=" << data[i + 1]; + dbgln(" x={}, y={}", data[i], data[i + 1]); break; case PathInstructionType::EllipticalArc: - dbg() << "EllipticalArc (absolute=" << instruction.absolute << ")"; + dbgln("EllipticalArc (absolute={})", instruction.absolute); for (size_t i = 0; i < data.size(); i += 7) - dbg() << " (rx=" << data[i] << ", ry=" << data[i + 1] << ") x-axis-rotation=" << data[i + 2] << ", large-arc-flag=" << data[i + 3] << ", sweep-flag=" << data[i + 4] << ", (x=" << data[i + 5] << ", y=" << data[i + 6] << ")"; + dbgln(" (rx={}, ry={}) x-axis-rotation={}, large-arc-flag={}, sweep-flag={}, (x={}, y={})", + data[i], + data[i + 1], + data[i + 2], + data[i + 3], + data[i + 4], + data[i + 5], + data[i + 6]); break; case PathInstructionType::Invalid: dbgln("Invalid"); break; } } -#endif PathDataParser::PathDataParser(const String& source) : m_source(source) @@ -456,9 +463,9 @@ Gfx::Path& SVGPathElement::get_path() auto& absolute = instruction.absolute; auto& data = instruction.data; -#ifdef PATH_DEBUG - print_instruction(instruction); -#endif + if constexpr (debug_path) { + print_instruction(instruction); + } bool clear_last_control_point = true; diff --git a/Userland/Utilities/test-js.cpp b/Userland/Utilities/test-js.cpp index c429a75009..52996c6b93 100644 --- a/Userland/Utilities/test-js.cpp +++ b/Userland/Utilities/test-js.cpp @@ -728,7 +728,7 @@ int main(int argc, char** argv) } if (getenv("DISABLE_DBG_OUTPUT")) { - DebugLogStream::set_enabled(false); + AK::set_debug_enabled(false); } String test_root; |