From: Guy Harris Date: Thu, 31 Dec 2015 02:23:35 +0000 (-0800) Subject: Have routines to set various internal debugging flags. X-Git-Tag: libpcap-1.8.0-bp~68 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/131f5a8b1cb158788f41b5726a5f58e62ae74823?ds=sidebyside Have routines to set various internal debugging flags. Those flags are available only in versions of libpcap built with support for them; they're not intended to be real APIs, they're intended to be used if you're doing debugging of libpcap itself, and it's expected that you'll be linking with a program that knows about them and that declares them itself. There's no clean way of discouraging their use except in special cases - it's really ugly providing them in a header if they're not going to be present by default, so this is about the best we can do. This is, at least, cleaner than exporting them as data. Clean up some spacing while we're at it. --- diff --git a/grammar.y b/grammar.y index 2078a3ec..5af2972c 100644 --- a/grammar.y +++ b/grammar.y @@ -72,10 +72,6 @@ struct rtentry; #include "grammar.h" #include "scanner.h" -#if YYDEBUG -PCAP_API_DEF int pcap_debug; -#endif - #ifdef HAVE_NET_PFVAR_H #include #include diff --git a/optimize.c b/optimize.c index 0a136b7a..71419453 100644 --- a/optimize.c +++ b/optimize.c @@ -55,7 +55,7 @@ #endif #ifdef BDEBUG -extern int dflag; +int pcap_optimizer_debug; #endif #if defined(MSDOS) && !defined(__DJGPP__) @@ -1675,7 +1675,7 @@ opt_loop(struct block *root, int do_stmts) { #ifdef BDEBUG - if (dflag > 1) { + if (pcap_optimizer_debug > 1) { printf("opt_loop(root, %d) begin\n", do_stmts); opt_dump(root); } @@ -1689,7 +1689,7 @@ opt_loop(struct block *root, int do_stmts) find_edom(root); opt_blks(root, do_stmts); #ifdef BDEBUG - if (dflag > 1) { + if (pcap_optimizer_debug > 1) { printf("opt_loop(root, %d) bottom, done=%d\n", do_stmts, done); opt_dump(root); } @@ -1712,14 +1712,14 @@ bpf_optimize(struct block **rootp) opt_loop(root, 1); intern_blocks(root); #ifdef BDEBUG - if (dflag > 1) { + if (pcap_optimizer_debug > 1) { printf("after intern_blocks()\n"); opt_dump(root); } #endif opt_root(rootp); #ifdef BDEBUG - if (dflag > 1) { + if (pcap_optimizer_debug > 1) { printf("after opt_root()\n"); opt_dump(root); } @@ -2292,6 +2292,7 @@ dot_dump_node(struct block *block, struct bpf_program *prog, FILE *out) dot_dump_node(JT(block), prog, out); dot_dump_node(JF(block), prog, out); } + static void dot_dump_edge(struct block *block, FILE *out) { @@ -2308,6 +2309,7 @@ dot_dump_edge(struct block *block, FILE *out) dot_dump_edge(JT(block), out); dot_dump_edge(JF(block), out); } + /* Output the block CFG using graphviz/DOT language * In the CFG, block's code, value index for each registers at EXIT, * and the jump relationship is show. @@ -2357,17 +2359,17 @@ plain_dump(struct block *root) putchar('\n'); free((char *)f.bf_insns); } + static void opt_dump(struct block *root) { /* if optimizer debugging is enabled, output DOT graph - * `dflag=4' is equivalent to -dddd to follow -d/-dd/-ddd - * convention in tcpdump command line + * `pcap_optimizer_debug=4' is equivalent to -dddd to follow -d/-dd/-ddd + * convention in tcpdump command line */ - if (dflag > 3) + if (pcap_optimizer_debug > 3) dot_dump(root); else plain_dump(root); } - #endif diff --git a/pcap.c b/pcap.c index 3974c1fc..d26f77e6 100644 --- a/pcap.c +++ b/pcap.c @@ -2231,3 +2231,51 @@ pcap_lib_version(void) return (pcap_version_string); } #endif + +#ifdef YYDEBUG +/* + * Set the internal "debug printout" flag for the filter expression parser. + * The code to print that stuff is present only if YYDEBUG is defined, so + * the flag, and the routine to set it, are defined only if YYDEBUG is + * defined. + * + * This is intended for libpcap developers, not for general use. + * If you want to set these in a program, you'll have to declare this + * routine yourself, with the appropriate DLL import attribute on Windows; + * it's not declared in any header file, and won't be declared in any + * header file provided by libpcap. + */ +PCAP_API void pcap_set_parser_debug(int value); + +PCAP_API_DEF void +pcap_set_parser_debug(int value) +{ + extern int pcap_debug; + + pcap_debug = value; +} +#endif + +#ifdef BDEBUG +/* + * Set the internal "debug printout" flag for the filter expression optimizer. + * The code to print that stuff is present only if BDEBUG is defined, so + * the flag, and the routine to set it, are defined only if BDEBUG is + * defined. + * + * This is intended for libpcap developers, not for general use. + * If you want to set these in a program, you'll have to declare this + * routine yourself, with the appropriate DLL import attribute on Windows; + * it's not declared in any header file, and won't be declared in any + * header file provided by libpcap. + */ +PCAP_API void pcap_set_optimizer_debug(int value); + +PCAP_API_DEF void +pcap_set_optimizer_debug(int value) +{ + extern int pcap_optimizer_debug; + + pcap_optimizer_debug = value; +} +#endif