diff --git a/libyara/exception.h b/libyara/exception.h index 1bb17400f1..4de8cadee3 100644 --- a/libyara/exception.h +++ b/libyara/exception.h @@ -221,6 +221,18 @@ static void exception_handler(int sig, siginfo_t * info, void *context) } } +// Keep debug output indentation level consistent +#if 0 == YR_DEBUG_VERBOSITY +#define YR_DEBUG_INDENT_INITIAL 0 +#define YR_DEBUG_INDENT_SET(x) ; +#else +extern YR_TLS int yr_debug_indent; +// Ugly, but unfortunately cannot use ifdef macros inside a macro +#define YR_DEBUG_INDENT_INITIAL yr_debug_indent +#define YR_DEBUG_INDENT_SET(x) yr_debug_indent = (x); + +#endif + typedef struct sigaction sa; #define YR_TRYCATCH(_do_, _try_clause_, _catch_clause_) \ @@ -243,6 +255,8 @@ typedef struct sigaction sa; } \ exception_handler_usecount++; \ pthread_mutex_unlock(&exception_handler_mutex); \ + /* Save the current debug indentation level before the jump. */ \ + int yr_debug_indent_before_jump = YR_DEBUG_INDENT_INITIAL; \ jumpinfo ji; \ ji.memfault_from = 0; \ ji.memfault_to = 0; \ @@ -256,6 +270,9 @@ typedef struct sigaction sa; } \ else \ { \ + /* Restore debug output indentation in case of failure */ \ + YR_DEBUG_INDENT_SET(yr_debug_indent_before_jump); \ + \ _catch_clause_ \ } \ pthread_mutex_lock(&exception_handler_mutex); \