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-16 15:51:56 +01:00 committed by Andreas Kling
parent 7dc3a5ce3f
commit 6dc2c38fd0
10 changed files with 105 additions and 112 deletions

View file

@ -363,3 +363,39 @@ constexpr bool debug_jpg = true;
#else
constexpr bool debug_jpg = false;
#endif
#ifdef EMOJI_DEBUG
constexpr bool debug_emoji = true;
#else
constexpr bool debug_emoji = false;
#endif
#ifdef FILL_PATH_DEBUG
constexpr bool debug_fill_path = true;
#else
constexpr bool debug_fill_path = false;
#endif
#ifdef PNG_DEBUG
constexpr bool debug_png = true;
#else
constexpr bool debug_png = false;
#endif
#ifdef PORTABLE_IMAGE_LOADER_DEBUG
constexpr bool debug_portable_image_loader = true;
#else
constexpr bool debug_portable_image_loader = false;
#endif
#ifdef DEBUG_SYNTAX_HIGHLIGHTING
constexpr bool debug_syntax_highlighting = true;
#else
constexpr bool debug_syntax_highlighting = false;
#endif
#ifdef KEYBOARD_SHORTCUTS_DEBUG
constexpr bool debug_keyboard_shortcuts = true;
#else
constexpr bool debug_keyboard_shortcuts = false;
#endif

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/Debug.h>
#include <LibCpp/Lexer.h>
#include <LibGUI/CppSyntaxHighlighter.h>
#include <LibGUI/TextEditor.h>
@ -83,9 +84,7 @@ void CppSyntaxHighlighter::rehighlight(Gfx::Palette palette)
Vector<GUI::TextDocumentSpan> spans;
for (auto& token : tokens) {
#ifdef DEBUG_SYNTAX_HIGHLIGHTING
dbg() << token.to_string() << " @ " << token.m_start.line << ":" << token.m_start.column << " - " << token.m_end.line << ":" << token.m_end.column;
#endif
dbgln<debug_syntax_highlighting>("{} @ {}:{} - {}:{}", token.to_string(), token.m_start.line, token.m_start.column, token.m_end.line, token.m_end.column);
GUI::TextDocumentSpan span;
span.range.set_start({ token.m_start.line, token.m_start.column });
span.range.set_end({ token.m_end.line, token.m_end.column });

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/Debug.h>
#include <LibGUI/JSSyntaxHighlighter.h>
#include <LibGUI/TextEditor.h>
#include <LibGfx/Font.h>
@ -107,11 +108,12 @@ void JSSyntaxHighlighter::rehighlight(Gfx::Palette palette)
spans.append(span);
advance_position(str[str.length() - 1]);
#ifdef DEBUG_SYNTAX_HIGHLIGHTING
dbg() << token.name() << (is_trivia ? " (trivia) @ \"" : " @ \"") << token.value() << "\" "
<< span.range.start().line() << ":" << span.range.start().column() << " - "
<< span.range.end().line() << ":" << span.range.end().column();
#endif
dbgln<debug_syntax_highlighting>("{}{} @ '{}' {}:{} - {}:{}",
token.name(),
is_trivia ? " (trivia)" : "",
token.value(),
span.range.start().line(), span.range.start().column(),
span.range.end().line(), span.range.end().column());
};
bool was_eof = false;

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/Debug.h>
#include <AK/JsonObject.h>
#include <LibCore/File.h>
#include <LibGUI/JsonArrayModel.h>
@ -34,7 +35,7 @@ void JsonArrayModel::update()
{
auto file = Core::File::construct(m_json_path);
if (!file->open(Core::IODevice::ReadOnly)) {
dbg() << "Unable to open " << file->filename();
dbgln("Unable to open {}", file->filename());
m_array.clear();
did_update();
return;
@ -53,7 +54,7 @@ bool JsonArrayModel::store()
{
auto file = Core::File::construct(m_json_path);
if (!file->open(Core::IODevice::WriteOnly)) {
dbg() << "Unable to open " << file->filename();
dbgln("Unable to open {}", file->filename());
return false;
}

View file

@ -267,3 +267,7 @@ private:
};
}
template<>
struct AK::Formatter<GUI::Window> : Formatter<Core::Object> {
};

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/Debug.h>
#include <AK/StringBuilder.h>
#include <LibCore/EventLoop.h>
#include <LibCore/MimeData.h>
@ -43,8 +44,6 @@
#include <LibGfx/Palette.h>
#include <LibGfx/SystemTheme.h>
//#define KEYBOARD_SHORTCUTS_DEBUG
namespace GUI {
WindowServerConnection& WindowServerConnection::the()
@ -142,32 +141,25 @@ void WindowServerConnection::handle(const Messages::WindowClient::KeyDown& messa
auto key_event = make<KeyEvent>(Event::KeyDown, (KeyCode)message.key(), message.modifiers(), message.code_point(), message.scancode());
Action* action = nullptr;
#ifdef KEYBOARD_SHORTCUTS_DEBUG
dbg() << "Looking up action for " << key_event->to_string();
#endif
dbgln<debug_keyboard_shortcuts>("Looking up action for {}", key_event->to_string());
if (auto* focused_widget = window->focused_widget()) {
for (auto* widget = focused_widget; widget && !action; widget = widget->parent_widget()) {
action = widget->action_for_key_event(*key_event);
#ifdef KEYBOARD_SHORTCUTS_DEBUG
dbg() << " > Focused widget " << *widget << " gave action: " << action;
#endif
dbgln<debug_keyboard_shortcuts>(" > Focused widget {} gave action: {}", *widget, action);
}
}
if (!action) {
action = window->action_for_key_event(*key_event);
#ifdef KEYBOARD_SHORTCUTS_DEBUG
dbg() << " > Asked window " << *window << ", got action: " << action;
#endif
dbgln<debug_keyboard_shortcuts>(" > Asked window {}, got action: {}", *window, action);
}
// NOTE: Application-global shortcuts are ignored while a modal window is up.
if (!action && !window->is_modal()) {
action = Application::the()->action_for_key_event(*key_event);
#ifdef KEYBOARD_SHORTCUTS_DEBUG
dbg() << " > Asked application, got action: " << action;
#endif
dbgln<debug_keyboard_shortcuts>(" > Asked application, got action: {}", action);
}
if (action) {

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/Debug.h>
#include <AK/Endian.h>
#include <AK/LexicalPath.h>
#include <AK/MappedFile.h>
@ -41,8 +42,6 @@
# include <serenity.h>
#endif
//#define PNG_DEBUG
namespace Gfx {
static const u8 png_header[8] = { 0x89, 'P', 'N', 'G', 13, 10, 26, 10 };
@ -614,9 +613,7 @@ static bool decode_png_bitmap_simple(PNGLoadingContext& context)
}
if (filter > 4) {
#ifdef PNG_DEBUG
dbg() << "Invalid PNG filter: " << filter;
#endif
dbgln<debug_png>("Invalid PNG filter: {}", filter);
context.state = PNGLoadingContext::State::Error;
return false;
}
@ -718,9 +715,7 @@ static bool decode_adam7_pass(PNGLoadingContext& context, Streamer& streamer, in
}
if (filter > 4) {
#ifdef PNG_DEBUG
dbg() << "Invalid PNG filter: " << filter;
#endif
dbgln<debug_png>("Invalid PNG filter: {}", filter);
context.state = PNGLoadingContext::State::Error;
return false;
}

View file

@ -31,6 +31,7 @@
#include "FontDatabase.h"
#include "Gamma.h"
#include <AK/Assertions.h>
#include <AK/Debug.h>
#include <AK/Function.h>
#include <AK/Memory.h>
#include <AK/QuickSort.h>
@ -915,9 +916,7 @@ void Painter::draw_glyph_or_emoji(const IntPoint& point, u32 code_point, const F
// Perhaps it's an emoji?
auto* emoji = Emoji::emoji_for_code_point(code_point);
if (emoji == nullptr) {
#ifdef EMOJI_DEBUG
dbg() << "Failed to find an emoji for code_point " << code_point;
#endif
dbgln<debug_emoji>("Failed to find an emoji for code_point {}", code_point);
draw_glyph(point, '?', font, color);
return;
}
@ -1632,9 +1631,8 @@ void Painter::fill_path(Path& path, Color color, WindingRule winding_rule)
if (is_inside_shape(winding_number)) {
// The points between this segment and the previous are
// inside the shape
#ifdef FILL_PATH_DEBUG
dbg() << "y=" << scanline << ": " << winding_number << " at " << i << ": " << from << " -- " << to;
#endif
dbgln<debug_fill_path>("y={}: {} at {}: {} -- {}", scanline, winding_number, i, from, to);
draw_line(from, to, color, 1);
}

View file

@ -28,6 +28,7 @@
#pragma once
#include <AK/Array.h>
#include <AK/Debug.h>
#include <AK/Endian.h>
#include <AK/LexicalPath.h>
#include <AK/MappedFile.h>
@ -41,8 +42,6 @@
#include <LibGfx/ImageDecoder.h>
#include <LibGfx/Streamer.h>
//#define PORTABLE_IMAGE_LOADER_DEBUG
namespace Gfx {
static constexpr Color adjust_color(u16 max_val, Color color)
@ -105,18 +104,14 @@ static bool read_magic_number(TContext& context, Streamer& streamer)
if (!context.data || context.data_size < 2) {
context.state = TContext::State::Error;
#ifdef PORTABLE_IMAGE_LOADER_DEBUG
dbg() << "There is no enough data for " << TContext::image_type;
#endif
dbgln<debug_portable_image_loader>("There is no enough data for {}", TContext::image_type);
return false;
}
u8 magic_number[2] {};
if (!streamer.read_bytes(magic_number, 2)) {
context.state = TContext::State::Error;
#ifdef PORTABLE_IMAGE_LOADER_DEBUG
dbg() << "We can't read magic number for " << TContext::image_type;
#endif
dbgln<debug_portable_image_loader>("We can't read magic number for {}", TContext::image_type);
return false;
}
@ -133,10 +128,7 @@ static bool read_magic_number(TContext& context, Streamer& streamer)
}
context.state = TContext::State::Error;
#ifdef PORTABLE_IMAGE_LOADER_DEBUG
dbg() << "Magic number is not valid for "
<< magic_number[0] << magic_number[1] << TContext::image_type;
#endif
dbgln<debug_portable_image_loader>("Magic number is not valid for {}{}{}", magic_number[0], magic_number[1], TContext::image_type);
return false;
}
@ -194,9 +186,7 @@ static bool read_max_val(TContext& context, Streamer& streamer)
}
if (context.max_val > 255) {
#ifdef PORTABLE_IMAGE_LOADER_DEBUG
dbg() << "We can't parse 2 byte color for " << TContext::image_type;
#endif
dbgln<debug_portable_image_loader>("We can't parse 2 byte color for {}", TContext::image_type);
context.state = TContext::Error;
return false;
}

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/Debug.h>
#include <LibCore/Gzip.h>
#include <LibCore/TCPSocket.h>
#include <LibHTTP/HttpResponse.h>
@ -31,24 +32,18 @@
#include <stdio.h>
#include <unistd.h>
//#define JOB_DEBUG
namespace HTTP {
static ByteBuffer handle_content_encoding(const ByteBuffer& buf, const String& content_encoding)
{
#ifdef JOB_DEBUG
dbg() << "Job::handle_content_encoding: buf has content_encoding = " << content_encoding;
#endif
dbgln<debug_job>("Job::handle_content_encoding: buf has content_encoding={}", content_encoding);
if (content_encoding == "gzip") {
if (!Core::Gzip::is_compressed(buf)) {
dbgln("Job::handle_content_encoding: buf is not gzip compressed!");
}
#ifdef JOB_DEBUG
dbgln("Job::handle_content_encoding: buf is gzip compressed!");
#endif
dbgln<debug_job>("Job::handle_content_encoding: buf is gzip compressed!");
auto uncompressed = Core::Gzip::decompress(buf);
if (!uncompressed.has_value()) {
@ -56,11 +51,11 @@ static ByteBuffer handle_content_encoding(const ByteBuffer& buf, const String& c
return buf;
}
#ifdef JOB_DEBUG
dbg() << "Job::handle_content_encoding: Gzip::decompress() successful.\n"
<< " Input size = " << buf.size() << "\n"
<< " Output size = " << uncompressed.value().size();
#endif
if constexpr (debug_job) {
dbgln("Job::handle_content_encoding: Gzip::decompress() successful.");
dbgln(" Input size: {}", buf.size());
dbgln(" Output size: {}", uncompressed.value().size());
}
return uncompressed.value();
}
@ -82,9 +77,7 @@ void Job::flush_received_buffers()
{
if (!m_can_stream_response || m_buffered_size == 0)
return;
#ifdef JOB_DEBUG
dbg() << "Job: Flushing received buffers: have " << m_buffered_size << " bytes in " << m_received_buffers.size() << " buffers";
#endif
dbgln<debug_job>("Job: Flushing received buffers: have {} bytes in {} buffers", m_buffered_size, m_received_buffers.size());
for (size_t i = 0; i < m_received_buffers.size(); ++i) {
auto& payload = m_received_buffers[i];
auto written = do_write(payload);
@ -97,14 +90,9 @@ void Job::flush_received_buffers()
}
ASSERT(written < payload.size());
payload = payload.slice(written, payload.size() - written);
#ifdef JOB_DEBUG
dbg() << "Job: Flushing received buffers done: have " << m_buffered_size << " bytes in " << m_received_buffers.size() << " buffers";
#endif
return;
break;
}
#ifdef JOB_DEBUG
dbg() << "Job: Flushing received buffers done: have " << m_buffered_size << " bytes in " << m_received_buffers.size() << " buffers";
#endif
dbgln<debug_job>("Job: Flushing received buffers done: have {} bytes in {} buffers", m_buffered_size, m_received_buffers.size());
}
void Job::on_socket_connected()
@ -114,10 +102,12 @@ void Job::on_socket_connected()
return;
m_sent_data = true;
auto raw_request = m_request.to_raw_request();
#ifdef JOB_DEBUG
dbgln("Job: raw_request:");
dbg() << String::copy(raw_request).characters();
#endif
if constexpr (debug_job) {
dbgln("Job: raw_request:");
dbgln("{}", String::copy(raw_request));
}
bool success = write(raw_request);
if (!success)
deferred_invoke([this](auto&) { did_fail(Core::NetworkJob::Error::TransmissionFailed); });
@ -208,14 +198,10 @@ void Job::on_socket_connected()
m_headers.set(name, value);
if (name.equals_ignoring_case("Content-Encoding")) {
// Assume that any content-encoding means that we can't decode it as a stream :(
#ifdef JOB_DEBUG
dbg() << "Content-Encoding " << value << " detected, cannot stream output :(";
#endif
dbgln<debug_job>("Content-Encoding {} detected, cannot stream output :(", value);
m_can_stream_response = false;
}
#ifdef JOB_DEBUG
dbg() << "Job: [" << name << "] = '" << value << "'";
#endif
dbgln<debug_job>("Job: [{}] = '{}'", name, value);
return;
}
ASSERT(m_state == State::InBody);
@ -230,9 +216,7 @@ void Job::on_socket_connected()
// read size
auto size_data = read_line(PAGE_SIZE);
auto size_lines = size_data.view().lines();
#ifdef JOB_DEBUG
dbg() << "Job: Received a chunk with size _" << size_data << "_";
#endif
dbgln<debug_job>("Job: Received a chunk with size '{}'", size_data);
if (size_lines.size() == 0) {
dbgln("Job: Reached end of stream");
finish_up();
@ -254,36 +238,32 @@ void Job::on_socket_connected()
read_size = 0;
m_current_chunk_total_size = 0;
m_current_chunk_remaining_size = 0;
#ifdef JOB_DEBUG
dbg() << "Job: Received the last chunk with extensions _" << size_string.substring_view(1, size_string.length() - 1) << "_";
#endif
dbgln<debug_job>("Job: Received the last chunk with extensions '{}'", size_string.substring_view(1, size_string.length() - 1));
} else {
m_current_chunk_total_size = size;
m_current_chunk_remaining_size = size;
read_size = size;
#ifdef JOB_DEBUG
dbg() << "Job: Chunk of size _" << size << "_ started";
#endif
dbgln<debug_job>("Job: Chunk of size '{}' started", size);
}
}
} else {
read_size = remaining;
#ifdef JOB_DEBUG
dbg() << "Job: Resuming chunk with _" << remaining << "_ bytes left over";
#endif
dbgln<debug_job>("Job: Resuming chunk with '{}' bytes left over", remaining);
}
} else {
auto transfer_encoding = m_headers.get("Transfer-Encoding");
if (transfer_encoding.has_value()) {
auto encoding = transfer_encoding.value();
#ifdef JOB_DEBUG
dbg() << "Job: This content has transfer encoding '" << encoding << "'";
#endif
dbgln<debug_job>("Job: This content has transfer encoding '{}'", encoding);
if (encoding.equals_ignoring_case("chunked")) {
m_current_chunk_remaining_size = -1;
goto read_chunk_size;
} else {
dbg() << "Job: Unknown transfer encoding _" << encoding << "_, the result will likely be wrong!";
dbgln("Job: Unknown transfer encoding '{}', the result will likely be wrong!", encoding);
}
}
}
@ -308,13 +288,10 @@ void Job::on_socket_connected()
if (m_current_chunk_remaining_size.has_value()) {
auto size = m_current_chunk_remaining_size.value() - payload.size();
#ifdef JOB_DEBUG
dbg() << "Job: We have " << size << " bytes left over in this chunk";
#endif
dbgln<debug_job>("Job: We have {} bytes left over in this chunk", size);
if (size == 0) {
#ifdef JOB_DEBUG
dbg() << "Job: Finished a chunk of " << m_current_chunk_total_size.value() << " bytes";
#endif
dbgln<debug_job>("Job: Finished a chunk of {} bytes", m_current_chunk_total_size.value());
if (m_current_chunk_total_size.value() == 0) {
m_state = State::Trailers;
@ -323,10 +300,9 @@ void Job::on_socket_connected()
// we've read everything, now let's get the next chunk
size = -1;
[[maybe_unused]] auto line = read_line(PAGE_SIZE);
#ifdef JOB_DEBUG
dbg() << "Line following (should be empty): _" << line << "_";
#endif
if constexpr (debug_job)
dbgln("Line following (should be empty): '{}'", read_line(PAGE_SIZE));
}
m_current_chunk_remaining_size = size;
}