-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -221,6 +221,17 @@ 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_RESET_INIT | ||
#define YR_DEBUG_INDENT_RESET_RESTORE | ||
#else | ||
extern YR_TLS int yr_debug_indent; | ||
// Ugly, but unfortunately cannot use ifdef macros inside a macro | ||
#define YR_DEBUG_INDENT_RESET_INIT int yr_debug_indent_before_jump = yr_debug_indent; | ||
#define YR_DEBUG_INDENT_RESET_RESTORE yr_debug_indent = yr_debug_indent_before_jump; | ||
#endif | ||
|
||
typedef struct sigaction sa; | ||
|
||
#define YR_TRYCATCH(_do_, _try_clause_, _catch_clause_) \ | ||
|
@@ -243,6 +254,8 @@ typedef struct sigaction sa; | |
} \ | ||
exception_handler_usecount++; \ | ||
pthread_mutex_unlock(&exception_handler_mutex); \ | ||
/* Save the current debug indentation level before the jump. */ \ | ||
YR_DEBUG_INDENT_RESET_INIT \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not using ... #if 0 == YR_DEBUG_VERBOSITY
int yr_debug_indent_before_jump = yr_debug_indent;
#endif Instead of declaring yet another macro. It's easier to follow the code this way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please correct me if I'm mistaken but I think you cannot do that within However, I pushed a slightly different approach which uses yet another function-like macro to set |
||
jumpinfo ji; \ | ||
ji.memfault_from = 0; \ | ||
ji.memfault_to = 0; \ | ||
|
@@ -256,6 +269,9 @@ typedef struct sigaction sa; | |
} \ | ||
else \ | ||
{ \ | ||
/* Restore debug output indentation in case of failure */ \ | ||
YR_DEBUG_INDENT_RESET_RESTORE \ | ||
plusvic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
\ | ||
_catch_clause_ \ | ||
} \ | ||
pthread_mutex_lock(&exception_handler_mutex); \ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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."
There was a problem hiding this comment.
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.