From a97fbc108bd23e669a27356be83c1a515d469af0 Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 20 May 2022 18:00:49 +0900 Subject: [PATCH] extend `RUBY_DEBUG_LOG_FILTER` to reject words support reject words with `-word` like RUBY_DEBUG_LOG_FILTER=-foo,-bar,baz,boo`. --- debug.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/debug.c b/debug.c index 1c102ba953..3a6caca58a 100644 --- a/debug.c +++ b/debug.c @@ -268,14 +268,15 @@ ruby_set_debug_option(const char *str) #define MAX_DEBUG_LOG 0x1000 #define MAX_DEBUG_LOG_MESSAGE_LEN 0x0200 -#define MAX_DEBUG_LOG_FILTER 0x0010 +#define MAX_DEBUG_LOG_FILTER_LEN 0x0020 +#define MAX_DEBUG_LOG_FILTER_NUM 0x0010 enum ruby_debug_log_mode ruby_debug_log_mode; static struct { char *mem; unsigned int cnt; - char filters[MAX_DEBUG_LOG_FILTER][MAX_DEBUG_LOG_FILTER]; + char filters[MAX_DEBUG_LOG_FILTER_NUM][MAX_DEBUG_LOG_FILTER_LEN]; unsigned int filters_num; rb_nativethread_lock_t lock; FILE *output; @@ -322,21 +323,21 @@ setup_debug_log(void) const char *filter_config = getenv("RUBY_DEBUG_LOG_FILTER"); if (filter_config && strlen(filter_config) > 0) { unsigned int i; - for (i=0; i= MAX_DEBUG_LOG_FILTER) { - fprintf(stderr, "too long: %s (max:%d)\n", filter_config, MAX_DEBUG_LOG_FILTER); + if (strlen(filter_config) >= MAX_DEBUG_LOG_FILTER_LEN) { + fprintf(stderr, "too long: %s (max:%d)\n", filter_config, MAX_DEBUG_LOG_FILTER_LEN); exit(1); } - strncpy(debug_log.filters[i], filter_config, MAX_DEBUG_LOG_FILTER - 1); + strncpy(debug_log.filters[i], filter_config, MAX_DEBUG_LOG_FILTER_LEN - 1); i++; break; } else { size_t n = p - filter_config; - if (n >= MAX_DEBUG_LOG_FILTER) { - fprintf(stderr, "too long: %s (max:%d)\n", filter_config, MAX_DEBUG_LOG_FILTER); + if (n >= MAX_DEBUG_LOG_FILTER_LEN) { + fprintf(stderr, "too long: %s (max:%d)\n", filter_config, MAX_DEBUG_LOG_FILTER_LEN); exit(1); } strncpy(debug_log.filters[i], filter_config, n); @@ -350,16 +351,50 @@ setup_debug_log(void) } } +// +// RUBY_DEBUG_LOG_FILTER=-foo,-bar,baz,boo +// returns true if +// func_name doesn't contain foo +// and +// func_name doesn't contain bar +// and +// func_name contains baz or boo +// +// RUBY_DEBUG_LOG_FILTER=foo,bar,-baz,-boo +// retunrs true if +// func_name contains foo or bar +// or +// func_name doesn't contain baz and +// func_name doesn't contain boo and +// bool ruby_debug_log_filter(const char *func_name) { if (debug_log.filters_num > 0) { + bool status = false; + for (unsigned int i = 0; i