From 9dc8fc792e045cfa39508a4e9a1112fc4d782ed3 Mon Sep 17 00:00:00 2001 From: shahramn Date: Thu, 18 Jul 2024 12:44:46 +0100 Subject: [PATCH] Debugging: When triggers --- src/action_class_if.cc | 3 +-- src/action_class_when.cc | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/action_class_if.cc b/src/action_class_if.cc index 0302e0625..c310bada2 100644 --- a/src/action_class_if.cc +++ b/src/action_class_if.cc @@ -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); } - diff --git a/src/action_class_when.cc b/src/action_class_when.cc index 49fc325be..31f377b44 100644 --- a/src/action_class_when.cc +++ b/src/action_class_when.cc @@ -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); }