aboutsummaryrefslogtreecommitdiffstats
path: root/debug.c
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2022-05-20 15:47:20 +0900
committerKoichi Sasada <ko1@atdot.net>2022-05-20 17:37:46 +0900
commiteab99b1d4b61fb85d994534826922f96cd14ae58 (patch)
tree16f57c273520f5ae7987d8879d13dcf39e64d5c2 /debug.c
parentaeea88174d88264469b406003765c7efdcd53edf (diff)
downloadruby-eab99b1d4b61fb85d994534826922f96cd14ae58.tar.gz
`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.
Diffstat (limited to 'debug.c')
-rw-r--r--debug.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/debug.c b/debug.c
index 95a994e63c..1c102ba953 100644
--- a/debug.c
+++ b/debug.c
@@ -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;
}