LookupServer: Put debug spam behind a macro

This commit is contained in:
Andreas Kling 2020-12-06 01:07:57 +01:00
parent 70c9cfddc5
commit 484134d818
Notes: sideshowbarker 2024-07-19 01:02:12 +09:00
3 changed files with 16 additions and 2 deletions

View File

@ -62,7 +62,7 @@ if (ALL_THE_DEBUG_MACROS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DICMP_DEBUG -DICO_DEBUG -DImage_DEBUG -DIMAGE_DECODER_CLIENT_DEBUG -DIMAGE_DECODER_DEBUG -DIMAGE_LOADER_DEBUG -DINTERPRETER_DEBUG -DINTERRUPT_DEBUG -DIOAPIC_DEBUG -DIPC_DEBUG -DIPV4_DEBUG -DIPV4_SOCKET_DEBUG -DIRC_DEBUG -DIRQ_DEBUG")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DJOB_DEBUG -DJPG_DEBUG")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DKEYBOARD_DEBUG -DKEYBOARD_SHORTCUTS_DEBUG -DKMALLOC_DEBUG_LARGE_ALLOCATIONS")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLEXER_DEBUG -DLoader_DEBUG -DLOCK_DEBUG")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLEXER_DEBUG -DLoader_DEBUG -DLOCK_DEBUG -DLOOKUPSERVER_DEBUG")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMALLOC_DEBUG -DMASTERPTY_DEBUG -DMBR_DEBUG -DMEMORY_DEBUG -DMENU_DEBUG -DMINIMIZE_ANIMATION_DEBUG -DMM_DEBUG -DMOVE_DEBUG -DMULTIPROCESSOR_DEBUG")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNETWORK_TASK_DEBUG -DNT_DEBUG")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOBJECT_DEBUG -DOCCLUSIONS_DEBUG -DOFFD_DEBUG")

View File

@ -62,11 +62,13 @@ Optional<DNSResponse> DNSResponse::from_raw_response(const u8* raw_data, size_t
}
auto& response_header = *(const DNSPacket*)(raw_data);
#ifdef LOOKUPSERVER_DEBUG
dbgln("Got response (ID: {})", response_header.id());
dbgln(" Question count: {}", response_header.question_count());
dbgln(" Answer count: {}", response_header.answer_count());
dbgln(" Authority count: {}", response_header.authority_count());
dbgln("Additional count: {}", response_header.additional_count());
#endif
DNSResponse response;
response.m_id = response_header.id();
@ -85,9 +87,11 @@ Optional<DNSResponse> DNSResponse::from_raw_response(const u8* raw_data, size_t
};
auto& record_and_class = *(const RawDNSAnswerQuestion*)&raw_data[offset];
response.m_questions.empend(name, record_and_class.record_type, record_and_class.class_code);
auto& question = response.m_questions.last();
offset += 4;
#ifdef LOOKUPSERVER_DEBUG
auto& question = response.m_questions.last();
dbgln("Question #{}: name=_{}_, type={}, class={}", i, question.name(), question.record_type(), question.class_code());
#endif
}
for (u16 i = 0; i < response_header.answer_count(); ++i) {
@ -108,7 +112,9 @@ Optional<DNSResponse> DNSResponse::from_raw_response(const u8* raw_data, size_t
// FIXME: Parse some other record types perhaps?
dbgln("data=(unimplemented record type {})", record.type());
}
#ifdef LOOKUPSERVER_DEBUG
dbgln("Answer #{}: name=_{}_, type={}, ttl={}, length={}, data=_{}_", i, name, record.type(), record.ttl(), record.data_length(), data);
#endif
response.m_answers.empend(name, record.type(), record.record_class(), record.ttl(), data);
offset += record.data_length();
}

View File

@ -40,6 +40,8 @@
#include <sys/time.h>
#include <unistd.h>
//#define LOOKUPSERVER_DEBUG
LookupServer::LookupServer()
{
auto config = Core::ConfigFile::get_for_system("LookupServer");
@ -114,7 +116,9 @@ void LookupServer::service_client(RefPtr<Core::LocalSocket> socket)
return;
}
auto hostname = String((const char*)client_buffer + 1, nrecv - 1, Chomp);
#ifdef LOOKUPSERVER_DEBUG
dbgln("Got request for '{}'", hostname);
#endif
Vector<String> responses;
@ -122,7 +126,9 @@ void LookupServer::service_client(RefPtr<Core::LocalSocket> socket)
responses.append(known_host.value());
} else if (!hostname.is_empty()) {
for (auto& nameserver : m_nameservers) {
#ifdef LOOKUPSERVER_DEBUG
dbgln("Doing lookup using nameserver '{}'", nameserver);
#endif
bool did_get_response = false;
int retries = 3;
do {
@ -171,7 +177,9 @@ Vector<String> LookupServer::lookup(const String& hostname, const String& namese
if (cached_lookup.question.record_type() == record_type) {
Vector<String> responses;
for (auto& cached_answer : cached_lookup.answers) {
#ifdef LOOKUPSERVER_DEBUG
dbgln("Cache hit: {} -> {}, expired: {}", hostname, cached_answer.record_data(), cached_answer.has_expired());
#endif
if (!cached_answer.has_expired())
responses.append(cached_answer.record_data());
}