1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:47:45 +00:00

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.
This commit is contained in:
asynts 2021-01-18 17:25:44 +01:00 committed by Andreas Kling
parent fb8d3635d9
commit ea7b7d8ceb
10 changed files with 99 additions and 74 deletions

View file

@ -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

View file

@ -235,7 +235,7 @@ void dump_bytes(ReadonlyBytes bytes)
builder.append(" }");
dbg() << builder.to_string();
dbgln("{}", builder.string_view());
}
}

View file

@ -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

View file

@ -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 "/"
}
```

View file

@ -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 "/"
}
```

View file

@ -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 constexpr (debug_lock_trace) {
if (mode == Mode::Exclusive)
dbg() << "Lock::lock @ " << this << ": acquire " << mode_to_string(mode) << ", currently exclusive, holding: " << m_times_locked;
dbgln("Lock::lock @ {}: acquire {}, currently exclusive, holding: {}", this, mode_to_string(mode), m_times_locked);
else
dbg() << "Lock::lock @ " << this << ": acquire exclusive (requested " << mode_to_string(mode) << "), currently exclusive, holding " << m_times_locked;
#endif
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 constexpr (debug_lock_trace) {
if (current_mode == Mode::Shared)
dbg() << "Lock::unlock @ " << this << ": release " << mode_to_string(current_mode) << ", locks held: " << m_times_locked;
dbgln("Lock::unlock @ {}: release {}, locks held: {}", this, mode_to_string(current_mode), m_times_locked);
else
dbg() << "Lock::unlock @ " << this << ": release " << mode_to_string(current_mode) << ", holding: " << m_times_locked;
#endif
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);

View file

@ -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

View file

@ -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")

View file

@ -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
if constexpr (debug_path) {
print_instruction(instruction);
#endif
}
bool clear_last_control_point = true;

View file

@ -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;