From a2f143cfcc068a93ee46c278e2d4072d27ac1373 Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Fri, 7 Dec 2007 08:29:09 +0000 Subject: [PATCH] debug option. git-svn-id: file:///svn/unbound/trunk@813 be551aaa-1e26-0410-a405-d3ace91eadb9 --- doc/Changelog | 4 ++++ libunbound/ubsyms.def | 1 + libunbound/unbound.c | 10 ++++++++++ libunbound/unbound.h | 10 ++++++++++ smallapp/unbound-host.c | 10 +++++++++- 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/doc/Changelog b/doc/Changelog index 07fcf6241..63e7a9712 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,7 @@ +7 December 2007: Wouter + - unbound-host has a -d option to show what happens. This can help + with debugging (why do I get this answer). + 6 December 2007: Wouter - library resolution works in foreground mode, unbound-host app receives data. diff --git a/libunbound/ubsyms.def b/libunbound/ubsyms.def index 966c2bc28..8e4ae9d48 100644 --- a/libunbound/ubsyms.def +++ b/libunbound/ubsyms.def @@ -4,6 +4,7 @@ ub_val_ctx_config ub_val_ctx_add_ta ub_val_ctx_add_ta_file ub_val_ctx_trustedkeys +ub_val_ctx_debuglevel ub_val_ctx_async ub_val_ctx_poll ub_val_ctx_wait diff --git a/libunbound/unbound.c b/libunbound/unbound.c index ea02141bf..fc39982b3 100644 --- a/libunbound/unbound.c +++ b/libunbound/unbound.c @@ -221,6 +221,16 @@ ub_val_ctx_trustedkeys(struct ub_val_ctx* ctx, char* fname) return UB_NOERROR; } +int +ub_val_ctx_debuglevel(struct ub_val_ctx* ctx, int d) +{ + lock_basic_lock(&ctx->cfglock); + verbosity = d; + ctx->env->cfg->verbosity = d; + lock_basic_unlock(&ctx->cfglock); + return UB_NOERROR; +} + int ub_val_ctx_async(struct ub_val_ctx* ctx, int dothread) { diff --git a/libunbound/unbound.h b/libunbound/unbound.h index 7f2538c91..8a2a87811 100644 --- a/libunbound/unbound.h +++ b/libunbound/unbound.h @@ -239,6 +239,16 @@ int ub_val_ctx_add_ta_file(struct ub_val_ctx* ctx, char* fname); */ int ub_val_ctx_trustedkeys(struct ub_val_ctx* ctx, char* fname); +/** + * Set debug verbosity for the context + * Output is directed to stderr. + * @param ctx: context. + * @param d: debug level, 0 is off, 1 is very minimal, 2 is detailed, + * and 3 is lots. + * @return 0 if OK, else error. + */ +int ub_val_ctx_debuglevel(struct ub_val_ctx* ctx, int d); + /** * Set a context behaviour for asynchronous action. * @param ctx: context. diff --git a/smallapp/unbound-host.c b/smallapp/unbound-host.c index 9d6594a98..68150f38b 100644 --- a/smallapp/unbound-host.c +++ b/smallapp/unbound-host.c @@ -64,6 +64,7 @@ usage() printf(" -f keyfile read trust anchors from file, with lines as -y.\n"); printf(" -F keyfile read named.conf-style trust anchors.\n"); printf(" -v be more verbose, shows nodata and security.\n"); + printf(" -d debug, traces the action, -d -d shows more.\n"); printf(" -h show this usage help.\n"); printf("Version %s\n", PACKAGE_VERSION); printf("BSD licensed, see LICENSE in source package for details.\n"); @@ -375,6 +376,7 @@ int main(int argc, char* argv[]) char* qclass = NULL; char* qtype = NULL; struct ub_val_ctx* ctx = NULL; + int debuglevel = 0; ctx = ub_val_ctx_create(); if(!ctx) { @@ -383,11 +385,17 @@ int main(int argc, char* argv[]) } /* parse the options */ - while( (c=getopt(argc, argv, "F:c:f:ht:vy:")) != -1) { + while( (c=getopt(argc, argv, "F:c:df:ht:vy:")) != -1) { switch(c) { case 'c': qclass = optarg; break; + case 'd': + debuglevel++; + if(debuglevel < 2) + debuglevel = 2; /* at least VERB_DETAIL */ + ub_val_ctx_debuglevel(ctx, debuglevel); + break; case 't': qtype = optarg; break; -- 2.47.2