mirror of
https://gitlab.nic.cz/knot/knot-dns.git
synced 2026-02-03 18:49:28 -05:00
debug: sample of a signal debug handler
In this example this debugging tool uses records specific data in put_additional() (in knot/nameserver/internet.c)
and prints them out in case of SIGSEGV signal arrives during processing of the same function.
In other uses, the examined data and their print-out format must be modified.
WARNING: This simple solution isn't thread-safe -- the debug data can be overwritten by another thread
processing the same function. If code is being processed in parallel, this debugging helper
should be used to debug short parts of code at most.
This commit is contained in:
parent
eb37d2ab9c
commit
a5738dc673
6 changed files with 94 additions and 0 deletions
|
|
@ -541,6 +541,8 @@ src/libzscanner/functions.h
|
|||
src/libzscanner/scanner.h
|
||||
src/libzscanner/scanner.rl
|
||||
src/libzscanner/scanner_body.rl
|
||||
src/knot/common/dbg_signal.c
|
||||
src/knot/common/dbg_signal.h
|
||||
src/utils/common/exec.c
|
||||
src/utils/common/exec.h
|
||||
src/utils/common/hex.c
|
||||
|
|
|
|||
|
|
@ -125,6 +125,8 @@ libknotd_la_SOURCES = \
|
|||
knot/query/query.h \
|
||||
knot/query/requestor.c \
|
||||
knot/query/requestor.h \
|
||||
knot/common/dbg_signal.c \
|
||||
knot/common/dbg_signal.h \
|
||||
knot/common/evsched.c \
|
||||
knot/common/evsched.h \
|
||||
knot/common/fdset.c \
|
||||
|
|
|
|||
54
src/knot/common/dbg_signal.c
Normal file
54
src/knot/common/dbg_signal.c
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/* Copyright (C) 2023 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "knot/common/dbg_signal.h"
|
||||
|
||||
#include "knot/common/log.h"
|
||||
#include "libknot/libknot.h"
|
||||
|
||||
/*! \brief Temporary debug helper - signal handler. */
|
||||
static void dbg_signal_handler(int signum)
|
||||
{
|
||||
printf("%s\n", strsignal(signum));
|
||||
|
||||
extern dbg_data_t dbg_data;
|
||||
if (dbg_data.valid) {
|
||||
knot_dname_txt_storage_t name_str;
|
||||
(void)knot_dname_to_str(name_str, knot_pkt_qname(dbg_data.qdata->query),
|
||||
sizeof(name_str));
|
||||
|
||||
char rrtype_str[32];
|
||||
int len = knot_rrtype_to_string(knot_pkt_qtype(dbg_data.qdata->query),
|
||||
rrtype_str, sizeof(rrtype_str));
|
||||
|
||||
log_fatal("corrupted glue: name=%s, type=%s",
|
||||
name_str, (len > 0) ? rrtype_str : "<error>");
|
||||
}
|
||||
|
||||
abort();
|
||||
}
|
||||
|
||||
/*! \brief Temporary debug helper - signal handler setup. */
|
||||
void dbg_signal_setup(void)
|
||||
{
|
||||
struct sigaction action = { .sa_handler = dbg_signal_handler };
|
||||
sigaction(SIGSEGV, &action, NULL);
|
||||
}
|
||||
27
src/knot/common/dbg_signal.h
Normal file
27
src/knot/common/dbg_signal.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* Copyright (C) 2023 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "knot/nameserver/internet.h"
|
||||
|
||||
typedef struct dbg_data_struct {
|
||||
bool valid;
|
||||
knotd_qdata_t *qdata;
|
||||
} dbg_data_t;
|
||||
|
||||
/*! \brief Temporary debug helper - signal handler setup. */
|
||||
void dbg_signal_setup(void);
|
||||
|
|
@ -21,8 +21,11 @@
|
|||
#include "knot/nameserver/nsec_proofs.h"
|
||||
#include "knot/nameserver/query_module.h"
|
||||
#include "knot/zone/serial.h"
|
||||
#include "knot/common/dbg_signal.h" // Temporary debug helper.
|
||||
#include "contrib/mempattern.h"
|
||||
|
||||
dbg_data_t dbg_data = { 0 }; // Temporary debug helper.
|
||||
|
||||
/*! \brief Check if given node was already visited. */
|
||||
static int wildcard_has_visited(knotd_qdata_t *qdata, const zone_node_t *node)
|
||||
{
|
||||
|
|
@ -247,7 +250,9 @@ static int put_additional(knot_pkt_t *pkt, const knot_rrset_t *rr,
|
|||
uint16_t hint = knot_compr_hint(info, KNOT_COMPR_HINT_RDATA +
|
||||
glue->ns_pos);
|
||||
const zone_node_t *gluenode = glue_node(glue, qdata->extra->node);
|
||||
dbg_data = (dbg_data_t){ .qdata = qdata, .valid = true }; // Temporary debug helper.
|
||||
knot_rrset_t rrsigs = node_rrset(gluenode, KNOT_RRTYPE_RRSIG);
|
||||
dbg_data.valid = false; // Temporary debug helper.
|
||||
for (int k = 0; k < ar_type_count; ++k) {
|
||||
knot_rrset_t rrset = node_rrset(gluenode, ar_type_list[k]);
|
||||
if (knot_rrset_empty(&rrset)) {
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@
|
|||
#include "knot/conf/conf.h"
|
||||
#include "knot/conf/migration.h"
|
||||
#include "knot/conf/module.h"
|
||||
#include "knot/common/dbg_signal.h" /* Temporary debug helper. */
|
||||
#include "knot/common/log.h"
|
||||
#include "knot/common/process.h"
|
||||
#include "knot/common/stats.h"
|
||||
|
|
@ -507,6 +508,9 @@ int main(int argc, char **argv)
|
|||
/* Setup base signal handling. */
|
||||
setup_signals();
|
||||
|
||||
/* Temporary debug helper - signal handler setup. */
|
||||
dbg_signal_setup();
|
||||
|
||||
/* Initialize cryptographic backend. */
|
||||
dnssec_crypto_init();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue