summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Siegl <stesie@brokenpipe.de>2005-03-17 19:56:51 +0000
committerStefan Siegl <stesie@brokenpipe.de>2005-03-17 19:56:51 +0000
commit39bbe4a679d98afe2e16801bdf23243b2e1e82d5 (patch)
treebcda29a8e7e84120ccbe169003bf9b744d7c683e
parent42a2d190380a9a145c12436f672e79baae0e2346 (diff)
adding debug cruft.
-rw-r--r--cvsfs.c27
-rw-r--r--cvsfs.h53
2 files changed, 73 insertions, 7 deletions
diff --git a/cvsfs.c b/cvsfs.c
index 60dd9341e..5346d2389 100644
--- a/cvsfs.c
+++ b/cvsfs.c
@@ -1,7 +1,7 @@
/**********************************************************
* cvsfs.c
*
- * Copyright 2004, Stefan Siegl <ssiegl@gmx.de>, Germany
+ * Copyright (C) 2004, 2005 by Stefan Siegl <ssiegl@gmx.de>, Germany
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Publice License,
@@ -57,7 +57,7 @@ static const struct argp_child argp_children[] =
/* documentation, written out when called with either --usage or --help */
const char *argp_program_version = "cvsfs (" PACKAGE ") " VERSION "\n"
"Written by Stefan Siegl\n\n"
-"Copyright (C) 2004, Stefan Siegl <ssiegl@gmx.de>, Germany\n"
+"Copyright (C) 2004,05 Stefan Siegl <ssiegl@gmx.de>, Germany\n"
"This is free software; see the source for copying conditions. There is NO\n"
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
"\n";
@@ -76,6 +76,7 @@ enum
OPT_HOMEDIR = 'h',
OPT_REMOTE = 'r',
OPT_NOSTATS = 'n',
+ OPT_DEBUG = 'd',
#ifdef HAVE_LIBZ
OPT_GZIP = 'z',
#endif
@@ -93,6 +94,8 @@ static const struct argp_option cvsfs_options[] =
"connect through :ext: remote shell client CLIENT to cvs host", 0 },
{ "nostats", OPT_NOSTATS, 0, 0,
"do not download revisions to aquire stats information", 0 },
+ { "debug", OPT_DEBUG, "FILE", OPTION_ARG_OPTIONAL,
+ "print debug output to FILE or stderr", 0 },
#if HAVE_LIBZ
{ "gzip", OPT_GZIP, "LEVEL", 0,
"use gzip compression of specified level for file transfers", 0 },
@@ -121,14 +124,11 @@ main(int argc, char **argv)
cvs_connect_init();
- /* stderr = fopen("cvsfs.log", "w");
- * setvbuf(stderr, NULL, _IONBF, 0);
- */
-
/* reset configuration structure to sane defaults */
memset(&config, 0, sizeof(config));
config.cvs_mode = PSERVER;
config.cvs_username = "anonymous";
+ config.debug_port = NULL; /* no debugging by default */
#if HAVE_LIBZ
config.gzip_level = 3;
#endif
@@ -210,6 +210,21 @@ parse_cvsfs_opt(int key, char *arg, struct argp_state *state)
config.nostats = 1;
break;
+ case OPT_DEBUG:
+ if(arg)
+ {
+ config.debug_port = fopen(arg, "w");
+ if(errno)
+ perror(PACKAGE);
+ }
+
+ /* if either no file was specified or in case we cannot open it,
+ * write debugging output to standard error */
+ if(! config.debug_port)
+ config.debug_port = stderr;
+
+ break;
+
#if HAVE_LIBZ
case OPT_GZIP:
config.gzip_level = atoi(arg);
diff --git a/cvsfs.h b/cvsfs.h
index 6e25fa03d..576a27a80 100644
--- a/cvsfs.h
+++ b/cvsfs.h
@@ -1,7 +1,7 @@
/**********************************************************
* cvsfs_config.h
*
- * Copyright 2004, Stefan Siegl <ssiegl@gmx.de>, Germany
+ * Copyright (C) 2004, 2005 by Stefan Siegl <ssiegl@gmx.de>, Germany
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Publice License,
@@ -47,6 +47,10 @@ typedef struct {
unsigned gzip_level :4;
#endif
+ /* file-handle to write debug information out to,
+ * NULL, if no debug info is to be written out */
+ FILE *debug_port;
+
} cvsfs_config;
extern cvsfs_config config;
@@ -135,4 +139,51 @@ struct netnode {
/* pointer to root netnode */
extern struct netnode *rootdir;
+
+
+/* helper macros for debugging ****/
+#define DEBUG(cat,msg...) \
+ if(config.debug_port) \
+ fprintf(config.debug_port, PACKAGE ": " cat ": " msg);
+
+#define FUNC_PROLOGUE_(func_name, fmt...) \
+ do \
+ { \
+ const char *debug_func_name = func_name; \
+ DEBUG("tracing", "entering %s ", debug_func_name); \
+ if(config.debug_port) \
+ { \
+ fmt; \
+ fprintf(config.debug_port, "\n"); \
+ }
+
+#define FUNC_PROLOGUE(func_name) \
+ FUNC_PROLOGUE_(func_name, (void)0)
+
+#define FUNC_PROLOGUE_FMT(func_name, fmt...) \
+ FUNC_PROLOGUE_(func_name, fprintf(config.debug_port, fmt))
+
+#define FUNC_PROLOGUE_NODE(func_name, node) \
+ FUNC_PROLOGUE_FMT(func_name, "node=%s", (node)->nn->name)
+
+#define FUNC_EPILOGUE_NORET() \
+ DEBUG("tracing", "leaving %s\n", debug_func_name); \
+ } while(0);
+
+#define FUNC_EPILOGUE_(ret, fmt) \
+ DEBUG("tracing", "leaving %s ret=%d ", debug_func_name, ret); \
+ if(config.debug_port) \
+ { \
+ fmt; \
+ fprintf(config.debug_port, "\n"); \
+ } \
+ return ret; \
+ } while(0);
+
+#define FUNC_EPILOGUE_FMT(ret, fmt...) \
+ FUNC_EPILOGUE_(ret, fprintf(config.debug_port, fmt))
+
+#define FUNC_EPILOGUE(ret) \
+ FUNC_EPILOGUE_(ret, (void)0)
+
#endif /* CVSFS_CONFIG_H */