Debugging: When triggers

This commit is contained in:
shahramn 2024-07-18 12:44:46 +01:00
parent b4211f1f87
commit 9dc8fc792e
2 changed files with 23 additions and 2 deletions

View File

@ -133,7 +133,7 @@ static int create_accessor(grib_section* p, grib_action* act, grib_loader* h)
{
grib_action_if* a = (grib_action_if*)act;
grib_action* next = NULL;
int ret = 0;
int ret = GRIB_SUCCESS;
long lres = 0;
grib_accessor* as = NULL;
@ -304,4 +304,3 @@ static void destroy(grib_context* context, grib_action* act)
grib_context_free_persistent(context, act->debug_info);
grib_context_free_persistent(context, act->op);
}

View File

@ -108,6 +108,19 @@ grib_action* grib_action_create_when(grib_context* context,
snprintf(name, nameLen, "_when%p", (void*)expression);
act->debug_info = NULL;
if (context->debug > 0) {
/* Construct debug information showing definition file and line */
/* number of IF statement */
const char* fbp = file_being_parsed();
if (fbp) {
char debug_info[1024];
const size_t infoLen = sizeof(debug_info);
snprintf(debug_info, infoLen, "File=%s", fbp);
act->debug_info = grib_context_strdup_persistent(context, debug_info);
}
}
act->name = grib_context_strdup_persistent(context, name);
return act;
@ -189,6 +202,14 @@ static int notify_change(grib_action* a, grib_accessor* observer, grib_accessor*
#endif
SET_LOOP(self, 1);
if (hand->context->debug > 0) {
grib_context_log(hand->context, GRIB_LOG_DEBUG,
"------------- SECTION action %s is triggered by [%s] (%s)",
a->name, observed->name, a->debug_info ? a->debug_info : "no debug info");
//grib_expression_print(observed->context, self->expression, 0);
//fprintf(stderr, "\n");
}
if (lres)
b = self->block_true;
else
@ -229,5 +250,6 @@ static void destroy(grib_context* context, grib_action* act)
grib_expression_free(context, self->expression);
grib_context_free_persistent(context, act->name);
grib_context_free_persistent(context, act->debug_info);
grib_context_free_persistent(context, act->op);
}