diff options
Diffstat (limited to 'debug.c')
-rw-r--r-- | debug.c | 40 |
1 files changed, 33 insertions, 7 deletions
@@ -533,7 +533,9 @@ ruby_debug_log(const char *file, int line, const char *func_name, const char *fm len += r; } - if (rb_current_execution_context(false)) { + rb_execution_context_t *ec = rb_current_execution_context(false); + + if (ec) { // Ruby location int ruby_line; const char *ruby_file = rb_source_location_cstr(&ruby_line); @@ -547,22 +549,46 @@ ruby_debug_log(const char *file, int line, const char *func_name, const char *fm if (r < 0) rb_bug("ruby_debug_log returns %d\n", r); len += r; } + } + +#ifdef RUBY_NT_SERIAL + // native thread information + if (len < MAX_DEBUG_LOG_MESSAGE_LEN) { + r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\tnt:%d", ruby_nt_serial); + if (r < 0) rb_bug("ruby_debug_log returns %d\n", r); + len += r; + } +#endif + + if (ec) { + rb_thread_t *th = ec ? rb_ec_thread_ptr(ec) : NULL; // ractor information if (ruby_single_main_ractor == NULL) { - rb_ractor_t *cr = GET_RACTOR(); + rb_ractor_t *cr = th ? th->ractor : NULL; + 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); + r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\tr:#%d/%u", + cr ? (int)rb_ractor_id(cr) : -1, 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:%u", rb_th_serial(th)); + if (th && r && len < MAX_DEBUG_LOG_MESSAGE_LEN) { + rb_execution_context_t *rec = th->ractor ? th->ractor->threads.running_ec : NULL; + const rb_thread_t *rth = rec ? rec->thread_ptr : NULL; + const rb_thread_t *sth = th->ractor ? th->ractor->threads.sched.running : NULL; + + if (rth != th || sth != th) { + r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\tth:%u (rth:%d,sth:%d)", + rb_th_serial(th), rth ? (int)rb_th_serial(rth) : -1, sth ? (int)rb_th_serial(sth) : -1); + } + else { + r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\tth:%u", rb_th_serial(th)); + } if (r < 0) rb_bug("ruby_debug_log returns %d\n", r); len += r; } |