]> The Tcpdump Group git mirrors - libpcap/commitdiff
Have routines to set various internal debugging flags.
authorGuy Harris <[email protected]>
Thu, 31 Dec 2015 02:23:35 +0000 (18:23 -0800)
committerGuy Harris <[email protected]>
Thu, 31 Dec 2015 02:23:35 +0000 (18:23 -0800)
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.

grammar.y
optimize.c
pcap.c

index 2078a3ecd36c2cc4d162e7bdaebd67f02f0c57a8..5af2972c1976adf7946ce82549ab103eceb7e121 100644 (file)
--- 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 <net/if.h>
 #include <net/pfvar.h>
index 0a136b7a031a0ab5239beeb4e6d7e7aaadd7f847..714194539c4e49ff886aac7589c4d6da9c87fec7 100644 (file)
@@ -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 3974c1fc19f8b95645c5cc98c783fee3a319731a..d26f77e638e77f4ab491d5676cb91e1b6834b07a 100644 (file)
--- 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