aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dfilter
diff options
context:
space:
mode:
authorJoão Valverde <j@v6e.pt>2022-12-30 04:00:22 +0000
committerJoão Valverde <j@v6e.pt>2022-12-30 13:42:26 +0000
commitd3d06c25527c769276c7dc2064a03717329e4f99 (patch)
treedb0e143aaa51708ed68ab8ef5dcca3d4fa03a38a /epan/dfilter
parent55ffdb08bb5c12cfd5e2fee05f8c01d23ceaf9a3 (diff)
dftest: Add debug command-line options
Diffstat (limited to 'epan/dfilter')
-rw-r--r--epan/dfilter/dfilter.c20
-rw-r--r--epan/dfilter/dfilter.h4
-rw-r--r--epan/dfilter/scanner.l10
3 files changed, 26 insertions, 8 deletions
diff --git a/epan/dfilter/dfilter.c b/epan/dfilter/dfilter.c
index c5bd2dbe50..c3cc4017b2 100644
--- a/epan/dfilter/dfilter.c
+++ b/epan/dfilter/dfilter.c
@@ -121,14 +121,6 @@ dfilter_init(void)
/* Allocate an instance of our Lemon-based parser */
ParserObj = DfilterAlloc(g_malloc);
-/* Enable parser tracing by defining AM_CFLAGS
- * so that it contains "-DDFTRACE".
- */
-#ifdef DFTRACE
- /* Trace parser */
- DfilterTrace(stdout, "lemon> ");
-#endif
-
/* Initialize the syntax-tree sub-sub-system */
sttype_init();
@@ -433,6 +425,18 @@ dfilter_compile_real(const gchar *text, dfilter_t **dfp,
df_set_extra(&state, scanner);
+ /* Enable/disable debugging for Flex. */
+ df_set_debug(flags & DF_DEBUG_FLEX, scanner);
+
+#ifndef NDEBUG
+ /* Enable/disable debugging for Lemon. */
+ DfilterTrace(flags & DF_DEBUG_LEMON ? stderr : NULL, "lemon> ");
+#else
+ if (flags & DF_DEBUG_LEMON) {
+ ws_message("Compile Wireshark without NDEBUG to enable Lemon debug traces");
+ }
+#endif
+
while (1) {
df_lval = stnode_new_empty(STTYPE_UNINITIALIZED);
token = df_lex(scanner);
diff --git a/epan/dfilter/dfilter.h b/epan/dfilter/dfilter.h
index 4bfdc89335..6d3eed6ae6 100644
--- a/epan/dfilter/dfilter.h
+++ b/epan/dfilter/dfilter.h
@@ -73,6 +73,10 @@ dfilter_error_free(df_error_t *);
#define DF_EXPAND_MACROS (1U << 1)
/* Do an optimization pass on the compiled filter. */
#define DF_OPTIMIZE (1U << 2)
+/* Enable debug trace for flex. */
+#define DF_DEBUG_FLEX (1U << 3)
+/* Enable debug trace for lemon. */
+#define DF_DEBUG_LEMON (1U << 4)
WS_DLL_PUBLIC
gboolean
diff --git a/epan/dfilter/scanner.l b/epan/dfilter/scanner.l
index 89005befbf..3a8d2c789b 100644
--- a/epan/dfilter/scanner.l
+++ b/epan/dfilter/scanner.l
@@ -16,6 +16,16 @@
}
/*
+ * Always generate warnings.
+ */
+%option warn
+
+/*
+ * Generate debug code (output is off by default for reentrant scanners).
+ */
+%option debug
+
+/*
* We want a reentrant scanner.
*/
%option reentrant