From 8ce3bac131a398c6aae6e0814bbb6a91c59b8b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Valverde?= Date: Mon, 17 Apr 2023 01:52:16 +0100 Subject: [PATCH] dftest: Add --refs option Add option to dump runtime data structures in a compiled display filter. As the comment notes: /* NOTE: References are loaded during runtime and dftest only does compilation. * Unless some static reference data is hard-coded at compile time during * development the --refs option to dftest is useless because it will just * print empty reference vectors. */ --- dftest.c | 13 +++++++++++++ epan/dfilter/dfvm.c | 22 ++++++++++++++++------ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/dftest.c b/dftest.c index 71e02b3f85..f60f891973 100644 --- a/dftest.c +++ b/dftest.c @@ -53,6 +53,7 @@ static int opt_syntax_tree = 0; static int opt_timer = 0; static long opt_optimize = 1; static int opt_show_types = 0; +static int opt_dump_refs = 0; static gdouble elapsed_expand = 0; static gdouble elapsed_compile = 0; @@ -107,6 +108,11 @@ print_usage(int status) fprintf(fp, " -t, --timer print elapsed compilation time\n"); fprintf(fp, " -0, --optimize=0 do not optimize (check syntax)\n"); fprintf(fp, " --types show field value types\n"); + /* NOTE: References are loaded during runtime and dftest only does compilation. + * Unless some static reference data is hard-coded at compile time during + * development the --refs option to dftest is useless because it will just + * print empty reference vectors. */ + fprintf(fp, " --refs dump some runtime data structures\n"); fprintf(fp, " -h, --help display this help and exit\n"); fprintf(fp, " -v, --version print version\n"); fprintf(fp, "\n"); @@ -248,6 +254,7 @@ main(int argc, char **argv) { "verbose", ws_no_argument, 0, 'V' }, { "optimize", ws_required_argument, 0, 1000 }, { "types", ws_no_argument, 0, 2000 }, + { "refs", ws_no_argument, 0, 3000 }, { NULL, 0, 0, 0 } }; int opt; @@ -294,6 +301,9 @@ main(int argc, char **argv) case 2000: opt_show_types = 1; break; + case 3000: + opt_dump_refs = 1; + break; case 'v': show_help_header(NULL); exit(EXIT_SUCCESS); @@ -430,6 +440,9 @@ main(int argc, char **argv) uint16_t dump_flags = 0; if (opt_show_types) dump_flags |= DF_DUMP_SHOW_FTYPE; + if (opt_dump_refs) + dump_flags |= DF_DUMP_REFERENCES; + dfilter_dump(stdout, df, dump_flags); print_warnings(df); diff --git a/epan/dfilter/dfvm.c b/epan/dfilter/dfvm.c index fb7de28d8d..9d93ce243d 100644 --- a/epan/dfilter/dfvm.c +++ b/epan/dfilter/dfvm.c @@ -598,15 +598,25 @@ dfvm_dump_str(wmem_allocator_t *alloc, dfilter_t *df, uint16_t flags) buf = wmem_strbuf_new(alloc, NULL); - if ((flags & DF_DUMP_REFERENCES) && g_hash_table_size(df->references) > 0) { - wmem_strbuf_append(buf, "References:\n"); - append_references(buf, df->references, FALSE); + if (flags & DF_DUMP_REFERENCES) { + if (g_hash_table_size(df->references) > 0) { + wmem_strbuf_append(buf, "References:\n"); + append_references(buf, df->references, FALSE); + } + else { + wmem_strbuf_append(buf, "References: (none)\n"); + } wmem_strbuf_append_c(buf, '\n'); } - if ((flags & DF_DUMP_REFERENCES) && g_hash_table_size(df->raw_references) > 0) { - wmem_strbuf_append(buf, "Raw references:\n"); - append_references(buf, df->raw_references, TRUE); + if (flags & DF_DUMP_REFERENCES) { + if (g_hash_table_size(df->raw_references) > 0) { + wmem_strbuf_append(buf, "Raw references:\n"); + append_references(buf, df->raw_references, TRUE); + } + else { + wmem_strbuf_append(buf, "Raw references: (none)\n"); + } wmem_strbuf_append_c(buf, '\n'); }