1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:17:35 +00:00

Everywhere: Turn #if *_DEBUG into dbgln_if/if constexpr

This commit is contained in:
Gunnar Beutner 2021-05-01 21:10:08 +02:00 committed by Andreas Kling
parent 4e6f03a860
commit 6cf59b6ae9
58 changed files with 315 additions and 469 deletions

View file

@ -54,9 +54,10 @@ bool WavLoaderPlugin::sniff()
RefPtr<Buffer> WavLoaderPlugin::get_more_samples(size_t max_bytes_to_read_from_input)
{
#if AWAVLOADER_DEBUG
dbgln("Read {} bytes WAV with num_channels {} sample rate {}, bits per sample {}, sample format {}", max_bytes_to_read_from_input, m_num_channels, m_sample_rate, pcm_bits_per_sample(m_sample_format), sample_format_name(m_sample_format));
#endif
dbgln_if(AWAVLOADER_DEBUG, "Read {} bytes WAV with num_channels {} sample rate {}, "
"bits per sample {}, sample format {}",
max_bytes_to_read_from_input, m_num_channels,
m_sample_rate, pcm_bits_per_sample(m_sample_format), sample_format_name(m_sample_format));
size_t samples_to_read = static_cast<int>(max_bytes_to_read_from_input) / (m_num_channels * (pcm_bits_per_sample(m_sample_format) / 8));
RefPtr<Buffer> buffer;
if (m_file) {
@ -215,9 +216,8 @@ bool WavLoaderPlugin::parse_header()
}
}
#if AWAVLOADER_DEBUG
dbgln("WAV format {} at {}bit, {} channels, rate {}Hz ", sample_format_name(m_sample_format), pcm_bits_per_sample(m_sample_format), m_num_channels, m_sample_rate);
#endif
dbgln_if(AWAVLOADER_DEBUG, "WAV format {} at {} bit, {} channels, rate {}Hz ",
sample_format_name(m_sample_format), pcm_bits_per_sample(m_sample_format), m_num_channels, m_sample_rate);
// Read chunks until we find DATA
bool found_data = false;

View file

@ -21,9 +21,8 @@ char* BC;
int tgetent([[maybe_unused]] char* bp, [[maybe_unused]] const char* name)
{
#if TERMCAP_DEBUG
fprintf(stderr, "tgetent: bp=%p, name='%s'\n", bp, name);
#endif
if constexpr (TERMCAP_DEBUG)
fprintf(stderr, "tgetent: bp=%p, name='%s'\n", bp, name);
PC = '\0';
BC = const_cast<char*>("\033[D");
UP = const_cast<char*>("\033[A");
@ -81,9 +80,8 @@ static void ensure_caps()
char* tgetstr(const char* id, char** area)
{
ensure_caps();
#if TERMCAP_DEBUG
fprintf(stderr, "tgetstr: id='%s'\n", id);
#endif
if constexpr (TERMCAP_DEBUG)
fprintf(stderr, "tgetstr: id='%s'\n", id);
auto it = caps->find(id);
if (it != caps->end()) {
char* ret = *area;
@ -100,9 +98,8 @@ char* tgetstr(const char* id, char** area)
int tgetflag([[maybe_unused]] const char* id)
{
#if TERMCAP_DEBUG
fprintf(stderr, "tgetflag: '%s'\n", id);
#endif
if constexpr (TERMCAP_DEBUG)
fprintf(stderr, "tgetflag: '%s'\n", id);
auto it = caps->find(id);
if (it != caps->end())
return 1;
@ -111,9 +108,8 @@ int tgetflag([[maybe_unused]] const char* id)
int tgetnum(const char* id)
{
#if TERMCAP_DEBUG
fprintf(stderr, "tgetnum: '%s'\n", id);
#endif
if constexpr (TERMCAP_DEBUG)
fprintf(stderr, "tgetnum: '%s'\n", id);
auto it = caps->find(id);
if (it != caps->end())
return atoi((*it).value);

View file

@ -23,9 +23,7 @@ Endpoint::Endpoint(NonnullRefPtr<Core::IODevice> in, NonnullRefPtr<Core::IODevic
void Endpoint::send_command(const Command& command)
{
#if UCI_DEBUG
dbgln("{} Sent UCI Command: {}", class_name(), String(command.to_string().characters(), Chomp));
#endif
dbgln_if(UCI_DEBUG, "{} Sent UCI Command: {}", class_name(), String(command.to_string().characters(), Chomp));
m_out->write(command.to_string());
}
@ -74,9 +72,7 @@ NonnullOwnPtr<Command> Endpoint::read_command()
{
String line(ReadonlyBytes(m_in->read_line(4096).bytes()), Chomp);
#if UCI_DEBUG
dbgln("{} Received UCI Command: {}", class_name(), line);
#endif
dbgln_if(UCI_DEBUG, "{} Received UCI Command: {}", class_name(), line);
if (line == "uci") {
return make<UCICommand>(UCICommand::from_string(line));

View file

@ -393,9 +393,7 @@ void EventLoop::pump(WaitMode mode)
break;
}
} else if (event.type() == Event::Type::DeferredInvoke) {
#if DEFERRED_INVOKE_DEBUG
dbgln("DeferredInvoke: receiver = {}", *receiver);
#endif
dbgln_if(DEFERRED_INVOKE_DEBUG, "DeferredInvoke: receiver = {}", *receiver);
static_cast<DeferredInvocationEvent&>(event).m_invokee(*receiver);
} else {
NonnullRefPtr<Object> protector(*receiver);

View file

@ -22,17 +22,17 @@ Parser::Parser(const StringView& program, const String& filename, Preprocessor::
, m_filename(filename)
{
initialize_program_tokens(program);
#if CPP_DEBUG
dbgln("Tokens:");
for (auto& token : m_tokens) {
StringView text;
if (token.start().line != token.end().line || token.start().column > token.end().column)
text = {};
else
text = text_of_token(token);
dbgln("{} {}:{}-{}:{} ({})", token.to_string(), token.start().line, token.start().column, token.end().line, token.end().column, text);
if constexpr (CPP_DEBUG) {
dbgln("Tokens:");
for (auto& token : m_tokens) {
StringView text;
if (token.start().line != token.end().line || token.start().column > token.end().column)
text = {};
else
text = text_of_token(token);
dbgln("{} {}:{}-{}:{} ({})", token.to_string(), token.start().line, token.start().column, token.end().line, token.end().column, text);
}
}
#endif
}
void Parser::initialize_program_tokens(const StringView& program)

View file

@ -208,9 +208,7 @@ UnsignedBigInteger LCM(const UnsignedBigInteger& a, const UnsignedBigInteger& b)
GCD_without_allocation(a, b, temp_a, temp_b, temp_1, temp_2, temp_3, temp_4, temp_quotient, temp_remainder, gcd_output);
if (gcd_output == 0) {
#if NT_DEBUG
dbgln("GCD is zero");
#endif
dbgln_if(NT_DEBUG, "GCD is zero");
return output;
}

View file

@ -42,15 +42,11 @@ void DebugInfo::parse_scopes_impl(const Dwarf::DIE& die)
return;
if (child.get_attribute(Dwarf::Attribute::Inline).has_value()) {
#if SPAM_DEBUG
dbgln("DWARF inlined functions are not supported");
#endif
dbgln_if(SPAM_DEBUG, "DWARF inlined functions are not supported");
return;
}
if (child.get_attribute(Dwarf::Attribute::Ranges).has_value()) {
#if SPAM_DEBUG
dbgln("DWARF ranges are not supported");
#endif
dbgln_if(SPAM_DEBUG, "DWARF ranges are not supported");
return;
}
auto name = child.get_attribute(Dwarf::Attribute::Name);
@ -61,9 +57,7 @@ void DebugInfo::parse_scopes_impl(const Dwarf::DIE& die)
scope.name = name.value().data.as_string;
if (!child.get_attribute(Dwarf::Attribute::LowPc).has_value()) {
#if SPAM_DEBUG
dbgln("DWARF: Couldn't find attribute LowPc for scope");
#endif
dbgln_if(SPAM_DEBUG, "DWARF: Couldn't find attribute LowPc for scope");
return;
}
scope.address_low = child.get_attribute(Dwarf::Attribute::LowPc).value().data.as_u32;

View file

@ -263,9 +263,7 @@ Image::RelocationSection Image::Section::relocations() const
if (relocation_section.type() != SHT_REL)
return static_cast<const RelocationSection>(m_image.section(0));
#if ELF_IMAGE_DEBUG
dbgln("Found relocations for {} in {}", name(), relocation_section.name());
#endif
dbgln_if(ELF_IMAGE_DEBUG, "Found relocations for {} in {}", name(), relocation_section.name());
return static_cast<const RelocationSection>(relocation_section);
}

View file

@ -87,9 +87,7 @@ int Menu::realize_menu(RefPtr<Action> default_action)
unrealize_menu();
m_menu_id = WindowServerConnection::the().send_sync<Messages::WindowServer::CreateMenu>(m_name)->menu_id();
#if MENU_DEBUG
dbgln("GUI::Menu::realize_menu(): New menu ID: {}", m_menu_id);
#endif
dbgln_if(MENU_DEBUG, "GUI::Menu::realize_menu(): New menu ID: {}", m_menu_id);
VERIFY(m_menu_id > 0);
for (size_t i = 0; i < m_items.size(); ++i) {
auto& item = m_items[i];

View file

@ -474,9 +474,8 @@ void TextEditor::paint_event(PaintEvent& event)
for_each_visual_line(line_index, [&](const Gfx::IntRect& visual_line_rect, auto& visual_line_text, size_t start_of_visual_line, [[maybe_unused]] bool is_last_visual_line) {
if (is_multi_line() && line_index == m_cursor.line())
painter.fill_rect(visual_line_rect, widget_background_color.darkened(0.9f));
#if TEXTEDITOR_DEBUG
painter.draw_rect(visual_line_rect, Color::Cyan);
#endif
if constexpr (TEXTEDITOR_DEBUG)
painter.draw_rect(visual_line_rect, Color::Cyan);
if (!placeholder().is_empty() && document().is_empty() && !is_focused() && line_index == 0) {
auto line_rect = visual_line_rect;

View file

@ -238,9 +238,8 @@ void TreeView::paint_event(PaintEvent& event)
auto rect = a_rect.translated(0, y_offset);
auto toggle_rect = a_toggle_rect.translated(0, y_offset);
#if ITEM_RECTS_DEBUG
painter.fill_rect(rect, Color::WarmGray);
#endif
if constexpr (ITEM_RECTS_DEBUG)
painter.fill_rect(rect, Color::WarmGray);
bool is_selected_row = selection().contains(index);

View file

@ -609,9 +609,7 @@ void Window::update(const Gfx::IntRect& a_rect)
for (auto& pending_rect : m_pending_paint_event_rects) {
if (pending_rect.contains(a_rect)) {
#if UPDATE_COALESCING_DEBUG
dbgln("Ignoring {} since it's contained by pending rect {}", a_rect, pending_rect);
#endif
dbgln_if(UPDATE_COALESCING_DEBUG, "Ignoring {} since it's contained by pending rect {}", a_rect, pending_rect);
return;
}
}

View file

@ -20,9 +20,7 @@ void GeminiJob::start()
m_socket = TLS::TLSv12::construct(this);
m_socket->set_root_certificates(m_override_ca_certificates ? *m_override_ca_certificates : DefaultRootCACertificates::the().certificates());
m_socket->on_tls_connected = [this] {
#if GEMINIJOB_DEBUG
dbgln("GeminiJob: on_connected callback");
#endif
dbgln_if(GEMINIJOB_DEBUG, "GeminiJob: on_connected callback");
on_socket_connected();
};
m_socket->on_tls_error = [this](TLS::AlertDescription error) {

View file

@ -132,9 +132,7 @@ void Job::on_socket_connected()
});
if (!is_established()) {
#if JOB_DEBUG
dbgln("Connection appears to have closed, finishing up");
#endif
dbgln_if(JOB_DEBUG, "Connection appears to have closed, finishing up");
finish_up();
}
});

View file

@ -350,9 +350,7 @@ static bool decode_frame(GIFLoadingContext& context, size_t frame_index)
while (true) {
Optional<u16> code = decoder.next_code();
if (!code.has_value()) {
#if GIF_DEBUG
dbgln("Unexpectedly reached end of gif frame data");
#endif
dbgln_if(GIF_DEBUG, "Unexpectedly reached end of gif frame data");
return false;
}
@ -499,9 +497,7 @@ static bool load_gif_frame_descriptors(GIFLoadingContext& context)
if (extension_type == 0xF9) {
if (sub_block.size() != 4) {
#if GIF_DEBUG
dbgln("Unexpected graphic control size");
#endif
dbgln_if(GIF_DEBUG, "Unexpected graphic control size");
continue;
}

View file

@ -169,25 +169,22 @@ static bool load_ico_directory(ICOLoadingContext& context)
for (size_t i = 0; i < image_count.value(); ++i) {
auto maybe_desc = decode_ico_direntry(stream);
if (!maybe_desc.has_value()) {
#if ICO_DEBUG
printf("load_ico_directory: error loading entry: %lu\n", i);
#endif
if constexpr (ICO_DEBUG)
printf("load_ico_directory: error loading entry: %lu\n", i);
return false;
}
auto& desc = maybe_desc.value();
if (desc.offset + desc.size < desc.offset // detect integer overflow
|| (desc.offset + desc.size) > context.data_size) {
#if ICO_DEBUG
printf("load_ico_directory: offset: %lu size: %lu doesn't fit in ICO size: %lu\n",
desc.offset, desc.size, context.data_size);
#endif
if constexpr (ICO_DEBUG)
printf("load_ico_directory: offset: %lu size: %lu doesn't fit in ICO size: %lu\n",
desc.offset, desc.size, context.data_size);
return false;
}
#if ICO_DEBUG
printf("load_ico_directory: index %zu width: %u height: %u offset: %lu size: %lu\n",
i, desc.width, desc.height, desc.offset, desc.size);
#endif
if constexpr (ICO_DEBUG)
printf("load_ico_directory: index %zu width: %u height: %u offset: %lu size: %lu\n",
i, desc.width, desc.height, desc.offset, desc.size);
context.images.append(desc);
}
context.largest_index = find_largest_image(context);
@ -203,16 +200,14 @@ static bool load_ico_bmp(ICOLoadingContext& context, ImageDescriptor& desc)
memcpy(&info, context.data + desc.offset, sizeof(info));
if (info.size != sizeof(info)) {
#if ICO_DEBUG
printf("load_ico_bmp: info size: %u, expected: %lu\n", info.size, sizeof(info));
#endif
if constexpr (ICO_DEBUG)
printf("load_ico_bmp: info size: %u, expected: %lu\n", info.size, sizeof(info));
return false;
}
if (info.width < 0) {
#if ICO_DEBUG
printf("load_ico_bmp: width %d < 0\n", info.width);
#endif
if constexpr (ICO_DEBUG)
printf("load_ico_bmp: width %d < 0\n", info.width);
return false;
}
bool topdown = false;
@ -222,37 +217,32 @@ static bool load_ico_bmp(ICOLoadingContext& context, ImageDescriptor& desc)
}
if (info.planes != 1) {
#if ICO_DEBUG
printf("load_ico_bmp: planes: %d != 1", info.planes);
#endif
if constexpr (ICO_DEBUG)
printf("load_ico_bmp: planes: %d != 1", info.planes);
return false;
}
if (info.bpp != 32) {
#if ICO_DEBUG
printf("load_ico_bmp: unsupported bpp: %u\n", info.bpp);
#endif
if constexpr (ICO_DEBUG)
printf("load_ico_bmp: unsupported bpp: %u\n", info.bpp);
return false;
}
#if ICO_DEBUG
printf("load_ico_bmp: width: %d height: %d direction: %s bpp: %d size_image: %u\n",
info.width, info.height, topdown ? "TopDown" : "BottomUp", info.bpp, info.size_image);
#endif
if constexpr (ICO_DEBUG)
printf("load_ico_bmp: width: %d height: %d direction: %s bpp: %d size_image: %u\n",
info.width, info.height, topdown ? "TopDown" : "BottomUp", info.bpp, info.size_image);
if (info.compression != 0 || info.palette_size != 0 || info.important_colors != 0) {
#if ICO_DEBUG
printf("load_ico_bmp: following fields must be 0: compression: %u palette_size: %u important_colors: %u\n",
info.compression, info.palette_size, info.important_colors);
#endif
if constexpr (ICO_DEBUG)
printf("load_ico_bmp: following fields must be 0: compression: %u palette_size: %u important_colors: %u\n",
info.compression, info.palette_size, info.important_colors);
return false;
}
if (info.width != desc.width || info.height != 2 * desc.height) {
#if ICO_DEBUG
printf("load_ico_bmp: size mismatch: ico %dx%d, bmp %dx%d\n",
desc.width, desc.height, info.width, info.height);
#endif
if constexpr (ICO_DEBUG)
printf("load_ico_bmp: size mismatch: ico %dx%d, bmp %dx%d\n",
desc.width, desc.height, info.width, info.height);
return false;
}
@ -261,10 +251,9 @@ static bool load_ico_bmp(ICOLoadingContext& context, ImageDescriptor& desc)
size_t required_len = desc.height * (desc.width * sizeof(BMP_ARGB) + mask_row_len);
size_t available_len = desc.size - sizeof(info);
if (required_len > available_len) {
#if ICO_DEBUG
printf("load_ico_bmp: required_len: %lu > available_len: %lu\n",
required_len, available_len);
#endif
if constexpr (ICO_DEBUG)
printf("load_ico_bmp: required_len: %lu > available_len: %lu\n",
required_len, available_len);
return false;
}
@ -310,17 +299,15 @@ static bool load_ico_bitmap(ICOLoadingContext& context, Optional<size_t> index)
if (png_decoder.sniff()) {
desc.bitmap = png_decoder.bitmap();
if (!desc.bitmap) {
#if ICO_DEBUG
printf("load_ico_bitmap: failed to load PNG encoded image index: %lu\n", real_index);
#endif
if constexpr (ICO_DEBUG)
printf("load_ico_bitmap: failed to load PNG encoded image index: %lu\n", real_index);
return false;
}
return true;
} else {
if (!load_ico_bmp(context, desc)) {
#if ICO_DEBUG
printf("load_ico_bitmap: failed to load BMP encoded image index: %lu\n", real_index);
#endif
if constexpr (ICO_DEBUG)
printf("load_ico_bitmap: failed to load BMP encoded image index: %lu\n", real_index);
return false;
}
return true;

View file

@ -247,9 +247,7 @@ static Optional<u8> get_next_symbol(HuffmanStreamState& hstream, const HuffmanTa
}
}
#if JPG_DEBUG
dbgln("If you're seeing this...the jpeg decoder needs to support more kinds of JPEGs!");
#endif
dbgln_if(JPG_DEBUG, "If you're seeing this...the jpeg decoder needs to support more kinds of JPEGs!");
return {};
}

View file

@ -1880,11 +1880,11 @@ void Painter::fill_path(Path& path, Color color, WindingRule winding_rule)
quick_sort(active_list, [](const auto& line0, const auto& line1) {
return line1.x < line0.x;
});
#if FILL_PATH_DEBUG
if ((int)scanline % 10 == 0) {
draw_text(IntRect(active_list.last().x - 20, scanline, 20, 10), String::number((int)scanline));
if constexpr (FILL_PATH_DEBUG) {
if ((int)scanline % 10 == 0) {
draw_text(IntRect(active_list.last().x - 20, scanline, 20, 10), String::number((int)scanline));
}
}
#endif
if (active_list.size() > 1) {
auto winding_number { winding_rule == WindingRule::Nonzero ? 1 : 0 };
@ -1952,12 +1952,12 @@ void Painter::fill_path(Path& path, Color color, WindingRule winding_rule)
}
}
#if FILL_PATH_DEBUG
size_t i { 0 };
for (auto& segment : segments) {
draw_line(Point<int>(segment.from), Point<int>(segment.to), Color::from_hsv(i++ * 360.0 / segments.size(), 1.0, 1.0), 1);
if constexpr (FILL_PATH_DEBUG) {
size_t i { 0 };
for (auto& segment : segments) {
draw_line(Point<int>(segment.from), Point<int>(segment.to), Color::from_hsv(i++ * 360.0 / segments.size(), 1.0, 1.0), 1);
}
}
#endif
}
void Painter::blit_disabled(const IntPoint& location, const Gfx::Bitmap& bitmap, const IntRect& rect, const Palette& palette)

View file

@ -17,9 +17,7 @@ void HttpJob::start()
VERIFY(!m_socket);
m_socket = Core::TCPSocket::construct(this);
m_socket->on_connected = [this] {
#if CHTTPJOB_DEBUG
dbgln("HttpJob: on_connected callback");
#endif
dbgln_if(CHTTPJOB_DEBUG, "HttpJob: on_connected callback");
on_socket_connected();
};
bool success = m_socket->connect(m_request.url().host(), m_request.url().port());

View file

@ -20,9 +20,7 @@ void HttpsJob::start()
m_socket = TLS::TLSv12::construct(this);
m_socket->set_root_certificates(m_override_ca_certificates ? *m_override_ca_certificates : DefaultRootCACertificates::the().certificates());
m_socket->on_tls_connected = [this] {
#if HTTPSJOB_DEBUG
dbgln("HttpsJob: on_connected callback");
#endif
dbgln_if(HTTPSJOB_DEBUG, "HttpsJob: on_connected callback");
on_socket_connected();
};
m_socket->on_tls_error = [&](TLS::AlertDescription error) {

View file

@ -346,9 +346,7 @@ void Job::on_socket_connected()
});
if (!is_established()) {
#if JOB_DEBUG
dbgln("Connection appears to have closed, finishing up");
#endif
dbgln_if(JOB_DEBUG, "Connection appears to have closed, finishing up");
finish_up();
}
});

View file

@ -20,9 +20,7 @@ void KeyCallbackMachine::register_key_input_callback(Vector<Key> keys, Function<
void KeyCallbackMachine::key_pressed(Editor& editor, Key key)
{
#if CALLBACK_MACHINE_DEBUG
dbgln("Key<{}, {}> pressed, seq_length={}, {} things in the matching vector", key.key, key.modifiers, m_sequence_length, m_current_matching_keys.size());
#endif
dbgln_if(CALLBACK_MACHINE_DEBUG, "Key<{}, {}> pressed, seq_length={}, {} things in the matching vector", key.key, key.modifiers, m_sequence_length, m_current_matching_keys.size());
if (m_sequence_length == 0) {
VERIFY(m_current_matching_keys.is_empty());
@ -61,14 +59,14 @@ void KeyCallbackMachine::key_pressed(Editor& editor, Key key)
return;
}
#if CALLBACK_MACHINE_DEBUG
dbgln("seq_length={}, matching vector:", m_sequence_length);
for (auto& key : m_current_matching_keys) {
for (auto& k : key)
dbgln(" {}, {}", k.key, k.modifiers);
dbgln("");
if constexpr (CALLBACK_MACHINE_DEBUG) {
dbgln("seq_length={}, matching vector:", m_sequence_length);
for (auto& key : m_current_matching_keys) {
for (auto& k : key)
dbgln(" {}, {}", k.key, k.modifiers);
dbgln("");
}
}
#endif
m_should_process_this_key = false;
for (auto& key : m_current_matching_keys) {

View file

@ -222,17 +222,15 @@ Optional<Text> Text::parse(const StringView& str)
current_link_is_actually_img = true;
break;
case '[':
#if MARKDOWN_DEBUG
if (first_span_in_the_current_link != -1)
dbgln("Dropping the outer link");
#endif
if constexpr (MARKDOWN_DEBUG) {
if (first_span_in_the_current_link != -1)
dbgln("Dropping the outer link");
}
first_span_in_the_current_link = spans.size();
break;
case ']': {
if (first_span_in_the_current_link == -1) {
#if MARKDOWN_DEBUG
dbgln("Unmatched ]");
#endif
dbgln_if(MARKDOWN_DEBUG, "Unmatched ]");
continue;
}
ScopeGuard guard = [&] {

View file

@ -10,8 +10,6 @@
#include "LibRegex/RegexMatcher.h"
#include <AK/Debug.h>
#if REGEX_DEBUG
namespace regex {
class RegexDebug {
@ -131,5 +129,3 @@ private:
}
using regex::RegexDebug;
#endif

View file

@ -130,9 +130,8 @@ Token Lexer::next()
case '\\':
return 2;
default:
#if REGEX_DEBUG
fprintf(stderr, "[LEXER] Found invalid escape sequence: \\%c (the parser will have to deal with this!)\n", peek(1));
#endif
if constexpr (REGEX_DEBUG)
fprintf(stderr, "[LEXER] Found invalid escape sequence: \\%c (the parser will have to deal with this!)\n", peek(1));
return 0;
}
};

View file

@ -148,9 +148,8 @@ Parser::Result Parser::parse(Optional<AllOptions> regex_options)
else
set_error(Error::InvalidPattern);
#if REGEX_DEBUG
fprintf(stderr, "[PARSER] Produced bytecode with %lu entries (opcodes + arguments)\n", m_parser_state.bytecode.size());
#endif
if constexpr (REGEX_DEBUG)
fprintf(stderr, "[PARSER] Produced bytecode with %lu entries (opcodes + arguments)\n", m_parser_state.bytecode.size());
return {
move(m_parser_state.bytecode),
move(m_parser_state.capture_groups_count),
@ -461,9 +460,8 @@ ALWAYS_INLINE bool PosixExtendedParser::parse_sub_expression(ByteCode& stack, si
if (match(TokenType::EscapeSequence)) {
length = 1;
Token t = consume();
#if REGEX_DEBUG
printf("[PARSER] EscapeSequence with substring %s\n", String(t.value()).characters());
#endif
if constexpr (REGEX_DEBUG)
printf("[PARSER] EscapeSequence with substring %s\n", String(t.value()).characters());
bytecode.insert_bytecode_compare_values({ { CharacterCompareType::Char, (u32)t.value().characters_without_null_termination()[1] } });
should_parse_repetition_symbol = true;

View file

@ -356,21 +356,21 @@ TEST_CASE(ini_file_entries)
Regex<PosixExtended> re("[[:alpha:]]*=([[:digit:]]*)|\\[(.*)\\]");
RegexResult result;
#if REGEX_DEBUG
RegexDebug regex_dbg(stderr);
regex_dbg.print_raw_bytecode(re);
regex_dbg.print_header();
regex_dbg.print_bytecode(re);
#endif
if constexpr (REGEX_DEBUG) {
RegexDebug regex_dbg(stderr);
regex_dbg.print_raw_bytecode(re);
regex_dbg.print_header();
regex_dbg.print_bytecode(re);
}
String haystack = "[Window]\nOpacity=255\nAudibleBeep=0\n";
EXPECT_EQ(re.search(haystack.view(), result, PosixFlags::Multiline), true);
EXPECT_EQ(result.count, 3u);
#if REGEX_DEBUG
for (auto& v : result.matches)
fprintf(stderr, "%s\n", v.view.to_string().characters());
#endif
if constexpr (REGEX_DEBUG) {
for (auto& v : result.matches)
fprintf(stderr, "%s\n", v.view.to_string().characters());
}
EXPECT_EQ(result.matches.at(0).view, "[Window]");
EXPECT_EQ(result.capture_group_matches.at(0).at(0).view, "Window");
@ -405,12 +405,12 @@ TEST_CASE(named_capture_group)
Regex<PosixExtended> re("[[:alpha:]]*=(?<Test>[[:digit:]]*)");
RegexResult result;
#if REGEX_DEBUG
RegexDebug regex_dbg(stderr);
regex_dbg.print_raw_bytecode(re);
regex_dbg.print_header();
regex_dbg.print_bytecode(re);
#endif
if constexpr (REGEX_DEBUG) {
RegexDebug regex_dbg(stderr);
regex_dbg.print_raw_bytecode(re);
regex_dbg.print_header();
regex_dbg.print_bytecode(re);
}
String haystack = "[Window]\nOpacity=255\nAudibleBeep=0\n";
EXPECT_EQ(re.search(haystack, result, PosixFlags::Multiline), true);
@ -426,12 +426,12 @@ TEST_CASE(a_star)
Regex<PosixExtended> re("a*");
RegexResult result;
#if REGEX_DEBUG
RegexDebug regex_dbg(stderr);
regex_dbg.print_raw_bytecode(re);
regex_dbg.print_header();
regex_dbg.print_bytecode(re);
#endif
if constexpr (REGEX_DEBUG) {
RegexDebug regex_dbg(stderr);
regex_dbg.print_raw_bytecode(re);
regex_dbg.print_header();
regex_dbg.print_bytecode(re);
}
String haystack = "[Window]\nOpacity=255\nAudibleBeep=0\n";
EXPECT_EQ(re.search(haystack.view(), result, PosixFlags::Multiline), true);
@ -488,14 +488,14 @@ TEST_CASE(ECMA262_parse)
for (auto& test : tests) {
Regex<ECMA262> re(test.pattern);
EXPECT_EQ(re.parser_result.error, test.expected_error);
#if REGEX_DEBUG
dbgln("\n");
RegexDebug regex_dbg(stderr);
regex_dbg.print_raw_bytecode(re);
regex_dbg.print_header();
regex_dbg.print_bytecode(re);
dbgln("\n");
#endif
if constexpr (REGEX_DEBUG) {
dbgln("\n");
RegexDebug regex_dbg(stderr);
regex_dbg.print_raw_bytecode(re);
regex_dbg.print_header();
regex_dbg.print_bytecode(re);
dbgln("\n");
}
}
}
@ -550,14 +550,14 @@ TEST_CASE(ECMA262_match)
for (auto& test : tests) {
Regex<ECMA262> re(test.pattern, test.options);
#if REGEX_DEBUG
dbgln("\n");
RegexDebug regex_dbg(stderr);
regex_dbg.print_raw_bytecode(re);
regex_dbg.print_header();
regex_dbg.print_bytecode(re);
dbgln("\n");
#endif
if constexpr (REGEX_DEBUG) {
dbgln("\n");
RegexDebug regex_dbg(stderr);
regex_dbg.print_raw_bytecode(re);
regex_dbg.print_header();
regex_dbg.print_bytecode(re);
dbgln("\n");
}
EXPECT_EQ(re.parser_result.error, Error::NoError);
EXPECT_EQ(re.match(test.subject).success, test.matches);
}
@ -583,14 +583,14 @@ TEST_CASE(replace)
for (auto& test : tests) {
Regex<ECMA262> re(test.pattern, test.options);
#if REGEX_DEBUG
dbgln("\n");
RegexDebug regex_dbg(stderr);
regex_dbg.print_raw_bytecode(re);
regex_dbg.print_header();
regex_dbg.print_bytecode(re);
dbgln("\n");
#endif
if constexpr (REGEX_DEBUG) {
dbgln("\n");
RegexDebug regex_dbg(stderr);
regex_dbg.print_raw_bytecode(re);
regex_dbg.print_header();
regex_dbg.print_bytecode(re);
dbgln("\n");
}
EXPECT_EQ(re.parser_result.error, Error::NoError);
EXPECT_EQ(re.replace(test.subject, test.replacement), test.expected);
}

View file

@ -71,10 +71,10 @@ ssize_t TLSv12::handle_hello(ReadonlyBytes buffer, WritePacketStage& write_packe
if (session_length && session_length <= 32) {
memcpy(m_context.session_id, buffer.offset_pointer(res), session_length);
m_context.session_id_size = session_length;
#if TLS_DEBUG
dbgln("Remote session ID:");
print_buffer(ReadonlyBytes { m_context.session_id, session_length });
#endif
if constexpr (TLS_DEBUG) {
dbgln("Remote session ID:");
print_buffer(ReadonlyBytes { m_context.session_id, session_length });
}
} else {
m_context.session_id_size = 0;
}
@ -268,10 +268,10 @@ void TLSv12::build_random(PacketBuilder& builder)
}
auto& certificate = m_context.certificates[certificate_option.value()];
#if TLS_DEBUG
dbgln("PreMaster secret");
print_buffer(m_context.premaster_key);
#endif
if constexpr (TLS_DEBUG) {
dbgln("PreMaster secret");
print_buffer(m_context.premaster_key);
}
Crypto::PK::RSA_PKCS1_EME rsa(certificate.public_key.modulus(), 0, certificate.public_key.public_exponent());
@ -279,10 +279,10 @@ void TLSv12::build_random(PacketBuilder& builder)
auto outbuf = Bytes { out, rsa.output_size() };
rsa.encrypt(m_context.premaster_key, outbuf);
#if TLS_DEBUG
dbgln("Encrypted: ");
print_buffer(outbuf);
#endif
if constexpr (TLS_DEBUG) {
dbgln("Encrypted: ");
print_buffer(outbuf);
}
if (!compute_master_secret(bytes)) {
dbgln("oh noes we could not derive a master key :(");

View file

@ -53,22 +53,22 @@ bool TLSv12::expand_key()
auto server_iv = key + offset;
offset += iv_size;
#if TLS_DEBUG
dbgln("client key");
print_buffer(client_key, key_size);
dbgln("server key");
print_buffer(server_key, key_size);
dbgln("client iv");
print_buffer(client_iv, iv_size);
dbgln("server iv");
print_buffer(server_iv, iv_size);
if (!is_aead) {
dbgln("client mac key");
print_buffer(m_context.crypto.local_mac, mac_size);
dbgln("server mac key");
print_buffer(m_context.crypto.remote_mac, mac_size);
if constexpr (TLS_DEBUG) {
dbgln("client key");
print_buffer(client_key, key_size);
dbgln("server key");
print_buffer(server_key, key_size);
dbgln("client iv");
print_buffer(client_iv, iv_size);
dbgln("server iv");
print_buffer(server_iv, iv_size);
if (!is_aead) {
dbgln("client mac key");
print_buffer(m_context.crypto.local_mac, mac_size);
dbgln("server mac key");
print_buffer(m_context.crypto.remote_mac, mac_size);
}
}
#endif
if (is_aead) {
memcpy(m_context.crypto.local_aead_iv, client_iv, iv_size);
@ -153,10 +153,10 @@ bool TLSv12::compute_master_secret(size_t length)
ReadonlyBytes { m_context.remote_random, sizeof(m_context.remote_random) });
m_context.premaster_key.clear();
#if TLS_DEBUG
dbgln("master key:");
print_buffer(m_context.master_key);
#endif
if constexpr (TLS_DEBUG) {
dbgln("master key:");
print_buffer(m_context.master_key);
}
expand_key();
return true;
}
@ -195,9 +195,7 @@ ByteBuffer TLSv12::build_certificate()
builder.append((u8)HandshakeType::CertificateMessage);
if (!total_certificate_size) {
#if TLS_DEBUG
dbgln("No certificates, sending empty certificate message");
#endif
dbgln_if(TLS_DEBUG, "No certificates, sending empty certificate message");
builder.append_u24(certificate_vector_header_size);
builder.append_u24(total_certificate_size);
} else {

View file

@ -57,9 +57,7 @@ String TLSv12::read_line(size_t max_size)
bool TLSv12::write(ReadonlyBytes buffer)
{
if (m_context.connection_status != ConnectionStatus::Established) {
#if TLS_DEBUG
dbgln("write request while not connected");
#endif
dbgln_if(TLS_DEBUG, "write request while not connected");
return false;
}
@ -186,9 +184,7 @@ bool TLSv12::check_connection_state(bool read)
{
if (!Core::Socket::is_open() || !Core::Socket::is_connected() || Core::Socket::eof()) {
// an abrupt closure (the server is a jerk)
#if TLS_DEBUG
dbgln("Socket not open, assuming abrupt closure");
#endif
dbgln_if(TLS_DEBUG, "Socket not open, assuming abrupt closure");
m_context.connection_finished = true;
}
if (m_context.critical_error) {
@ -209,9 +205,7 @@ bool TLSv12::check_connection_state(bool read)
m_context.application_buffer.size());
} else {
m_context.connection_finished = false;
#if TLS_DEBUG
dbgln("FINISHED");
#endif
dbgln_if(TLS_DEBUG, "FINISHED");
}
if (!m_context.application_buffer.size()) {
m_context.connection_status = ConnectionStatus::Disconnected;
@ -230,10 +224,10 @@ bool TLSv12::flush()
if (out_buffer_length == 0)
return true;
#if TLS_DEBUG
dbgln("SENDING...");
print_buffer(out_buffer, out_buffer_length);
#endif
if constexpr (TLS_DEBUG) {
dbgln("SENDING...");
print_buffer(out_buffer, out_buffer_length);
}
if (Core::Socket::write(&out_buffer[out_buffer_index], out_buffer_length)) {
write_buffer().clear();
return true;

View file

@ -493,9 +493,7 @@ ssize_t TLSv12::handle_certificate(ReadonlyBytes buffer)
ssize_t res = 0;
if (buffer.size() < 3) {
#if TLS_DEBUG
dbgln("not enough certificate header data");
#endif
dbgln_if(TLS_DEBUG, "not enough certificate header data");
return (i8)Error::NeedMoreData;
}
@ -509,9 +507,7 @@ ssize_t TLSv12::handle_certificate(ReadonlyBytes buffer)
res += 3;
if (certificate_total_length > buffer.size() - res) {
#if TLS_DEBUG
dbgln("not enough data for claimed total cert length");
#endif
dbgln_if(TLS_DEBUG, "not enough data for claimed total cert length");
return (i8)Error::NeedMoreData;
}
size_t size = certificate_total_length;
@ -522,18 +518,14 @@ ssize_t TLSv12::handle_certificate(ReadonlyBytes buffer)
while (size > 0) {
++index;
if (buffer.size() - res < 3) {
#if TLS_DEBUG
dbgln("not enough data for certificate length");
#endif
dbgln_if(TLS_DEBUG, "not enough data for certificate length");
return (i8)Error::NeedMoreData;
}
size_t certificate_size = buffer[res] * 0x10000 + buffer[res + 1] * 0x100 + buffer[res + 2];
res += 3;
if (buffer.size() - res < certificate_size) {
#if TLS_DEBUG
dbgln("not enough data for certificate body");
#endif
dbgln_if(TLS_DEBUG, "not enough data for certificate body");
return (i8)Error::NeedMoreData;
}

View file

@ -797,9 +797,7 @@ void Terminal::ICH(const ParamVector& params)
void Terminal::on_input(u8 ch)
{
#if TERMINAL_DEBUG
dbgln("Terminal::on_input: {:#02x} ({:c}), fg={}, bg={}\n", ch, ch, m_current_attribute.foreground_color, m_current_attribute.background_color);
#endif
dbgln_if(TERMINAL_DEBUG, "Terminal::on_input: {:#02x} ({:c}), fg={}, bg={}\n", ch, ch, m_current_attribute.foreground_color, m_current_attribute.background_color);
auto fail_utf8_parse = [this] {
m_parser_state = Normal;

View file

@ -58,11 +58,11 @@ void FrameBox::paint(PaintContext& context, PaintPhase phase)
context.set_viewport_rect(old_viewport_rect);
context.painter().restore();
#if HIGHLIGHT_FOCUSED_FRAME_DEBUG
if (dom_node().content_frame()->is_focused_frame()) {
context.painter().draw_rect(absolute_rect().to<int>(), Color::Cyan);
if constexpr (HIGHLIGHT_FOCUSED_FRAME_DEBUG) {
if (dom_node().content_frame()->is_focused_frame()) {
context.painter().draw_rect(absolute_rect().to<int>(), Color::Cyan);
}
}
#endif
}
}

View file

@ -101,10 +101,8 @@ static bool build_gemini_document(DOM::Document& document, const ByteBuffer& dat
auto gemini_document = Gemini::Document::parse(gemini_data, document.url());
String html_data = gemini_document->render_to_html();
#if GEMINI_DEBUG
dbgln("Gemini data:\n\"\"\"{}\"\"\"", gemini_data);
dbgln("Converted to HTML:\n\"\"\"{}\"\"\"", html_data);
#endif
dbgln_if(GEMINI_DEBUG, "Gemini data:\n\"\"\"{}\"\"\"", gemini_data);
dbgln_if(GEMINI_DEBUG, "Converted to HTML:\n\"\"\"{}\"\"\"", html_data);
HTML::HTMLDocumentParser parser(document, html_data, "utf-8");
parser.run(document.url());

View file

@ -75,9 +75,7 @@ void Resource::did_load(Badge<ResourceLoader>, ReadonlyBytes data, const HashMap
auto content_type = headers.get("Content-Type");
if (content_type.has_value()) {
#if RESOURCE_DEBUG
dbgln("Content-Type header: '{}'", content_type.value());
#endif
dbgln_if(RESOURCE_DEBUG, "Content-Type header: '{}'", content_type.value());
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()) {
@ -85,9 +83,7 @@ void Resource::did_load(Badge<ResourceLoader>, ReadonlyBytes data, const HashMap
m_encoding = "utf-8"; // FIXME: This doesn't seem nice.
m_mime_type = url().data_mime_type();
} else {
#if RESOURCE_DEBUG
dbgln("No Content-Type header to go on! Guessing based on filename...");
#endif
dbgln_if(RESOURCE_DEBUG, "No Content-Type header to go on! Guessing based on filename...");
m_encoding = "utf-8"; // FIXME: This doesn't seem nice.
m_mime_type = Core::guess_mime_type_based_on_filename(url().path());
}

View file

@ -49,9 +49,7 @@ void WebContentClient::handle(const Messages::WebContentClient::DidInvalidateCon
void WebContentClient::handle(const Messages::WebContentClient::DidChangeSelection&)
{
#if SPAM_DEBUG
dbgln("handle: WebContentClient::DidChangeSelection!");
#endif
dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidChangeSelection!");
m_view.notify_server_did_change_selection({});
}
@ -105,9 +103,7 @@ void WebContentClient::handle(const Messages::WebContentClient::DidHoverLink& me
void WebContentClient::handle(const Messages::WebContentClient::DidUnhoverLink&)
{
#if SPAM_DEBUG
dbgln("handle: WebContentClient::DidUnhoverLink!");
#endif
dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidUnhoverLink!");
m_view.notify_server_did_unhover_link({});
}