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. */
This commit is contained in:
João Valverde 2023-04-17 01:52:16 +01:00
parent 36c5741558
commit 8ce3bac131
2 changed files with 29 additions and 6 deletions

View File

@ -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);

View File

@ -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');
}