From d7e8cb24d75e13a1d2dc4471d2ba3403f2972955 Mon Sep 17 00:00:00 2001 From: jay Date: Sun, 5 Dec 2004 22:52:30 +0000 Subject: [PATCH] Allow debug output to be turned on or off by saying --enable-debug on the configure command line --- README | 7 ++++++ configure.in | 17 ++++++++++++- find/defs.h | 5 ++-- find/find.c | 23 ++++++++++++------ find/parser.c | 15 ++++++------ find/pred.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++------------ find/tree.c | 4 +-- 7 files changed, 115 insertions(+), 34 deletions(-) diff --git a/README b/README index 222fd4f..f23736e 100644 --- a/README +++ b/README @@ -22,6 +22,13 @@ getpwuid or getgrgid when needed. Speeds up -nouser and -nogroup unless you are running NIS or Hesiod, which make password and group calls very expensive. +--enable-debug + Produce output on the standard error output indicating what find is +doing. This information includes details about how the command line +has been parsed and what files have been stat()ed. This output is +normally interesting only to the maintainer, and so is off by default. + + To gain speed, GNU find avoids statting files whenever possible. It does this by: 1. Checking the number of links to directories and not statting files diff --git a/configure.in b/configure.in index 163bb9d..440211e 100644 --- a/configure.in +++ b/configure.in @@ -7,7 +7,7 @@ AC_CONFIG_MACRO_DIR(gnulib/m4) dnl Set of available languages. ALL_LINGUAS="da de es et fr gl id it ko nl pl pt_BR ru sv tr sk" -AM_INIT_AUTOMAKE(findutils, 4.2.9) +AM_INIT_AUTOMAKE(findutils, 4.2.10-CVS) AC_SUBST(INCLUDES)dnl AC_ARG_ENABLE(id-cache, @@ -18,6 +18,21 @@ AC_ARG_ENABLE(id-cache, are running NIS or Hesiod, which make password and group calls very expensive.])) +AC_ARG_ENABLE(debug, + AC_HELP_STRING([--enable-debug],[Enable debugging output which is likely to be interesting to people debugging findutils]), + [ac_cv_debug=$withval],[ac_cv_debug=no]) + +AC_MSG_CHECKING([whether debug output should be produced]) +if test x$ac_cv_debug = x; then + AC_MSG_RESULT([no]) +else + AC_MSG_RESULT([yes]) + AC_DEFINE(DEBUG, 1, [Define if you want to see find's innards]) + AC_DEFINE(DEBUG_STAT, 1, [Define if you want to see a message every time find calls the stat() system call]) +fi + + + dnl Checks for programs. AC_PROG_CC AC_PROG_CPP diff --git a/find/defs.h b/find/defs.h index 5cfa62e..8961e33 100644 --- a/find/defs.h +++ b/find/defs.h @@ -401,8 +401,9 @@ boolean pred_user PARAMS((char *pathname, struct stat *stat_buf, struct predicat boolean pred_xtype PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)); char *find_pred_name PARAMS((PFB pred_func)); #ifdef DEBUG -void print_tree PARAMS((struct predicate *node, int indent)); -void print_list PARAMS((struct predicate *node)); +void print_tree PARAMS((FILE*, struct predicate *node, int indent)); +void print_list PARAMS((FILE*, struct predicate *node)); +void print_optlist PARAMS((FILE *fp, struct predicate *node)); #endif /* DEBUG */ /* tree.c */ diff --git a/find/find.c b/find/find.c index 0bea189..7ce595f 100644 --- a/find/find.c +++ b/find/find.c @@ -200,6 +200,9 @@ fallback_stat(const char *name, struct stat *p, int prev_rv) { case ENOENT: case ENOTDIR: +#ifdef DEBUG_STAT + fprintf(stderr, "fallback_stat(): stat(%s) failed; falling back on lstat()\n", name); +#endif return lstat(name, p); case EACCES: @@ -270,9 +273,12 @@ optionp_stat(const char *name, struct stat *p) } #ifdef DEBUG_STAT +static uintmax_t stat_count = 0u; + static int debug_stat (const char *file, struct stat *bufp) { + ++stat_count; fprintf (stderr, "debug_stat (%s)\n", file); switch (symlink_handling) { @@ -381,7 +387,7 @@ main (int argc, char **argv) #endif #ifdef DEBUG - printf ("cur_day_start = %s", ctime (&cur_day_start)); + fprintf (stderr, "cur_day_start = %s", ctime (&cur_day_start)); #endif /* DEBUG */ /* Check for -P, -H or -L options. */ @@ -481,8 +487,8 @@ main (int argc, char **argv) } #ifdef DEBUG - printf (_("Predicate List:\n")); - print_list (predicates); + fprintf (stderr, _("Predicate List:\n")); + print_list (stderr, predicates); #endif /* DEBUG */ /* Done parsing the predicates. Build the evaluation tree. */ @@ -498,8 +504,8 @@ main (int argc, char **argv) } #ifdef DEBUG - printf (_("Eval Tree:\n")); - print_tree (eval_tree, 0); + fprintf (stderr, _("Eval Tree:\n")); + print_tree (stderr, eval_tree, 0); #endif /* DEBUG */ /* Rearrange the eval tree in optimal-predicate order. */ @@ -509,8 +515,11 @@ main (int argc, char **argv) mark_stat (eval_tree); #ifdef DEBUG - printf (_("Optimized Eval Tree:\n")); - print_tree (eval_tree, 0); + fprintf (stderr, _("Optimized Eval Tree:\n")); + print_tree (stderr, eval_tree, 0); + fprintf (stderr, _("Optimized command line:\n")); + print_optlist(stderr, eval_tree); + fprintf(stderr, "\n"); #endif /* DEBUG */ starting_desc = open (".", O_RDONLY); diff --git a/find/parser.c b/find/parser.c index 5555b78..ffb74b1 100644 --- a/find/parser.c +++ b/find/parser.c @@ -1937,18 +1937,19 @@ insert_time (char **argv, int *arg_ptr, PFB pred) our_pred->args.info.l_val = t; (*arg_ptr)++; #ifdef DEBUG - printf (_("inserting %s\n"), our_pred->p_name); - printf (_(" type: %s %s "), + fprintf (stderr, _("inserting %s\n"), our_pred->p_name); + fprintf (stderr, _(" type: %s %s "), (c_type == COMP_GT) ? "gt" : ((c_type == COMP_LT) ? "lt" : ((c_type == COMP_EQ) ? "eq" : "?")), (c_type == COMP_GT) ? " >" : ((c_type == COMP_LT) ? " <" : ((c_type == COMP_EQ) ? ">=" : " ?"))); t = our_pred->args.info.l_val; - printf ("%ju %s", (uintmax_t) our_pred->args.info.l_val, ctime (&t)); + fprintf (stderr, "%ju %s", (uintmax_t) our_pred->args.info.l_val, ctime (&t)); if (c_type == COMP_EQ) { t = our_pred->args.info.l_val += DAYSECS; - printf (" < %ju %s", + fprintf (stderr, + " < %ju %s", (uintmax_t) our_pred->args.info.l_val, ctime (&t)); our_pred->args.info.l_val -= DAYSECS; } @@ -2017,13 +2018,13 @@ insert_num (char **argv, int *arg_ptr, PFB pred) our_pred->args.info.l_val = num; (*arg_ptr)++; #ifdef DEBUG - printf (_("inserting %s\n"), our_pred->p_name); - printf (_(" type: %s %s "), + fprintf (stderr, _("inserting %s\n"), our_pred->p_name); + fprintf (stderr, _(" type: %s %s "), (c_type == COMP_GT) ? "gt" : ((c_type == COMP_LT) ? "lt" : ((c_type == COMP_EQ) ? "eq" : "?")), (c_type == COMP_GT) ? " >" : ((c_type == COMP_LT) ? " <" : ((c_type == COMP_EQ) ? " =" : " ?"))); - printf ("%ju\n", our_pred->args.info.l_val); + fprintf (stderr, "%ju\n", our_pred->args.info.l_val); #endif /* DEBUG */ return (true); } diff --git a/find/pred.c b/find/pred.c index 38508a8..2189d38 100644 --- a/find/pred.c +++ b/find/pred.c @@ -1520,27 +1520,25 @@ prec_name (prec) INDENT is the number of levels to indent the left margin. */ void -print_tree (node, indent) - struct predicate *node; - int indent; +print_tree (FILE *fp, struct predicate *node, int indent) { int i; if (node == NULL) return; for (i = 0; i < indent; i++) - printf (" "); - printf ("pred = %s type = %s prec = %s addr = %x\n", + fprintf (fp, " "); + fprintf (fp, "pred = %s type = %s prec = %s addr = %x\n", find_pred_name (node->pred_func), type_name (node->p_type), prec_name (node->p_prec), node); for (i = 0; i < indent; i++) - printf (" "); - printf (_("left:\n")); - print_tree (node->pred_left, indent + 1); + fprintf (fp, " "); + fprintf (fp, _("left:\n")); + print_tree (fp, node->pred_left, indent + 1); for (i = 0; i < indent; i++) - printf (" "); - printf (_("right:\n")); - print_tree (node->pred_right, indent + 1); + fprintf (fp, " "); + fprintf (fp, _("right:\n")); + print_tree (fp, node->pred_right, indent + 1); } /* Copy STR into BUF and trim blanks from the end of BUF. @@ -1566,8 +1564,7 @@ blank_rtrim (str, buf) /* Print out the predicate list starting at NODE. */ void -print_list (node) - struct predicate *node; +print_list (FILE *fp, struct predicate *node) { struct predicate *cur; char name[256]; @@ -1575,9 +1572,60 @@ print_list (node) cur = node; while (cur != NULL) { - printf ("%s ", blank_rtrim (find_pred_name (cur->pred_func), name)); + fprintf (fp, "%s ", blank_rtrim (find_pred_name (cur->pred_func), name)); cur = cur->pred_next; } - printf ("\n"); + fprintf (fp, "\n"); } + + +/* Print out the predicate list starting at NODE. */ + + +static void +print_parenthesised(FILE *fp, struct predicate *node) +{ + int parens = 0; + + if (node) + { + if ( ( (node->pred_func == pred_or) + || (node->pred_func == pred_and) ) + && node->pred_left == NULL) + { + /* We print " or X" as just "X" + * We print " and X" as just "X" + */ + print_parenthesised(fp, node->pred_right); + } + else + { + if (node->pred_left || node->pred_right) + parens = 1; + + if (parens) + fprintf(fp, "%s", " ( "); + print_optlist(fp, node); + if (parens) + fprintf(fp, "%s", " ) "); + } + } +} + +void +print_optlist (FILE *fp, struct predicate *p) +{ + char name[256]; + + if (p) + { + print_parenthesised(fp, p->pred_left); + fprintf (fp, + "%s%s ", + p->need_stat ? _("[stat called here] ") : "", + blank_rtrim (find_pred_name (p->pred_func), name)); + print_parenthesised(fp, p->pred_right); + } +} + #endif /* DEBUG */ diff --git a/find/tree.c b/find/tree.c index c4e4a12..995a04f 100644 --- a/find/tree.c +++ b/find/tree.c @@ -230,8 +230,8 @@ opt_expr (struct predicate **eval_treep) #ifdef DEBUG /* Normalized tree. */ - printf (_("Normalized Eval Tree:\n")); - print_tree (*eval_treep, 0); + fprintf (stderr, _("Normalized Eval Tree:\n")); + print_tree (stderr, *eval_treep, 0); #endif /* Rearrange the predicates. */ -- 2.11.4.GIT