summaryrefslogtreecommitdiff
path: root/debug.c
diff options
context:
space:
mode:
authorKoichi Sasada <[email protected]>2022-06-08 16:14:20 +0900
committerKoichi Sasada <[email protected]>2022-06-09 01:51:19 +0900
commit5a4f997b2e8e819ed40731cd769826112072a9d4 ()
treedf6b99101e156fab3e7c4fa15ece1a5bfe5071fb /debug.c
parent8d57336360497e94403a71bd13de8faa76f1dbcb (diff)
func: and file: prefix for `RUBY_DEBUG_LOG_FILTER`
`RUBY_DEBUG_LOG_FILTER` specified only function names but this also check file names for each log events. If you specify `file:` or `func:` prefix, it's only filter file names or func names (otherwize check both). foo # show log when file or func names are mached with foo func:foo # show log when func name matches foo file:foo # show log when file name matches foo -file:foo,func:bar # show log when file name does not contains foo # and func name matches bar
Notes: Merged: https://.com/ruby/ruby/pull/5988
-rw-r--r--debug.c166
1 files changed, 121 insertions, 45 deletions
@@ -273,10 +273,26 @@ ruby_set_debug_option(const char *str)
enum ruby_debug_log_mode ruby_debug_log_mode;
static struct {
char *mem;
unsigned int cnt;
- char filters[MAX_DEBUG_LOG_FILTER_NUM][MAX_DEBUG_LOG_FILTER_LEN];
unsigned int filters_num;
rb_nativethread_lock_t lock;
FILE *output;
@@ -288,6 +304,23 @@ RUBY_DEBUG_LOG_MEM_ENTRY(unsigned int index)
return &debug_log.mem[MAX_DEBUG_LOG_MESSAGE_LEN * index];
}
static void
setup_debug_log(void)
{
@@ -323,30 +356,75 @@ 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_NUM; i++) {
const char *p;
- if ((p = strchr(filter_config, ',')) == NULL) {
- 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_LEN - 1);
- i++;
- break;
}
else {
- size_t n = p - filter_config;
- 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);
- filter_config = p+1;
}
}
debug_log.filters_num = i;
for (i=0; i<debug_log.filters_num; i++) {
- fprintf(stderr, "RUBY_DEBUG_LOG_FILTER[%d]=%s\n", i, debug_log.filters[i]);
}
}
}
@@ -354,47 +432,45 @@ 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<debug_log.filters_num; i++) {
- const char *filter = debug_log.filters[i];
-
- if (*filter == '-') {
- if (strstr(func_name, &filter[1]) == NULL) {
- status = true;
- }
- else {
- return false;
- }
- }
- else {
- if (strstr(func_name, filter) != NULL) {
- return true;
- }
- else {
- status = false;
- }
}
}
-
- return status;
}
else {
return true;