Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: restore debug output indentation in catch clause #2134

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions libyara/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

Consider adding a comment explaining the purpose of this variable, specifically how it's used for debug indentation. For example, you could say something like "Thread-local variable to track the indentation level for debug output."

Suggested change
extern YR_TLS int yr_debug_indent;
extern YR_TLS int yr_debug_indent; // Thread-local variable to track the indentation level for debug output.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable is declared elsewhere. No need to comment on it here.

// 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_) \
Expand All @@ -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; \
Expand All @@ -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); \
Expand Down
Loading