diff options
author | Koichi Sasada <ko1@atdot.net> | 2022-05-20 15:47:20 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2022-05-20 17:37:46 +0900 |
commit | eab99b1d4b61fb85d994534826922f96cd14ae58 (patch) | |
tree | 16f57c273520f5ae7987d8879d13dcf39e64d5c2 /debug.c | |
parent | aeea88174d88264469b406003765c7efdcd53edf (diff) |
`rb_thread_t::serial` for debug
`rb_thread_t::serial` is auto-incremented serial number for
threads and it can overflow, it means the serial is not a ID
for each thread, it is only for debug print.
`RUBY_DEBUG_LOG` shows this information.
Also skip EC related information if EC is NULL. This patch
enable to use `RUBY_DEBUG_LOG` without setup EC.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5921
Diffstat (limited to 'debug.c')
-rw-r--r-- | debug.c | 48 |
1 files changed, 24 insertions, 24 deletions
@@ -410,36 +410,36 @@ ruby_debug_log(const char *file, int line, const char *func_name, const char *fm len += r; } - // Ruby location - int ruby_line; - const char *ruby_file = rb_source_location_cstr(&ruby_line); - if (len < MAX_DEBUG_LOG_MESSAGE_LEN) { - if (ruby_file) { - r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\t%s:%d", pretty_filename(ruby_file), ruby_line); - } - else { - r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\t"); - } - if (r < 0) rb_bug("ruby_debug_log returns %d\n", r); - len += r; - } - - // ractor information - if (ruby_single_main_ractor == NULL) { - rb_ractor_t *cr = GET_RACTOR(); - if (r && len < MAX_DEBUG_LOG_MESSAGE_LEN) { - r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\tr:#%u/%u", - (unsigned int)rb_ractor_id(cr), GET_VM()->ractor.cnt); + if (rb_current_execution_context(false)) { + // Ruby location + int ruby_line; + const char *ruby_file = rb_source_location_cstr(&ruby_line); + if (len < MAX_DEBUG_LOG_MESSAGE_LEN) { + if (ruby_file) { + r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\t%s:%d", pretty_filename(ruby_file), ruby_line); + } + else { + r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\t"); + } if (r < 0) rb_bug("ruby_debug_log returns %d\n", r); len += r; } - } - // thread information - if (!rb_thread_alone()) { + // ractor information + if (ruby_single_main_ractor == NULL) { + rb_ractor_t *cr = GET_RACTOR(); + if (r && len < MAX_DEBUG_LOG_MESSAGE_LEN) { + r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\tr:#%u/%u", + (unsigned int)rb_ractor_id(cr), GET_VM()->ractor.cnt); + if (r < 0) rb_bug("ruby_debug_log returns %d\n", r); + len += r; + } + } + + // thread information const rb_thread_t *th = GET_THREAD(); if (r && len < MAX_DEBUG_LOG_MESSAGE_LEN) { - r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\tth:%p", (void *)th); + r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\tth:%u", (unsigned int)th->serial); if (r < 0) rb_bug("ruby_debug_log returns %d\n", r); len += r; } |