Ruby 4.1.0dev (2026-04-04 revision 3b6245536cf55da9e8bfcdb03c845fe9ef931d7f)
debug.c (3b6245536cf55da9e8bfcdb03c845fe9ef931d7f)
1/**********************************************************************
2
3 debug.c -
4
5 $Author$
6 created at: 04/08/25 02:31:54 JST
7
8 Copyright (C) 2004-2007 Koichi Sasada
9
10**********************************************************************/
11
12#include "ruby/internal/config.h"
13
14#include <stdio.h>
15
16#include "eval_intern.h"
17#include "encindex.h"
18#include "id.h"
19#include "internal/signal.h"
20#include "ruby/encoding.h"
21#include "ruby/io.h"
22#include "ruby/ruby.h"
23#include "ruby/util.h"
24#include "symbol.h"
25#include "vm_core.h"
26#include "vm_debug.h"
27#include "vm_callinfo.h"
28#include "ruby/thread_native.h"
29#include "ractor_core.h"
30
31/* This is the only place struct RIMemo is actually used */
32struct RIMemo {
33 VALUE flags;
34 VALUE v0;
35 VALUE v1;
36 VALUE v2;
37 VALUE v3;
38};
39
40/* for gdb */
41const union {
42 enum ruby_special_consts special_consts;
43 enum ruby_value_type value_type;
44 enum ruby_tag_type tag_type;
45 enum node_type node_type;
46 enum ruby_method_ids method_ids;
47 enum ruby_id_types id_types;
48 enum ruby_fl_type fl_types;
49 enum ruby_fl_ushift fl_ushift;
50 enum ruby_encoding_consts encoding_consts;
51 enum ruby_coderange_type enc_coderange_types;
52 enum ruby_econv_flag_type econv_flag_types;
53 rb_econv_result_t econv_result;
54 enum ruby_preserved_encindex encoding_index;
55 enum ruby_robject_flags robject_flags;
56 enum ruby_rmodule_flags rmodule_flags;
57 enum ruby_rstring_flags rstring_flags;
58 enum ruby_rarray_flags rarray_flags;
59 enum ruby_rarray_consts rarray_consts;
60 enum rbimpl_typeddata_flags rtypeddata_consts;
61 enum {
62 RUBY_FMODE_READABLE = FMODE_READABLE,
63 RUBY_FMODE_WRITABLE = FMODE_WRITABLE,
64 RUBY_FMODE_READWRITE = FMODE_READWRITE,
65 RUBY_FMODE_BINMODE = FMODE_BINMODE,
66 RUBY_FMODE_SYNC = FMODE_SYNC,
67 RUBY_FMODE_TTY = FMODE_TTY,
68 RUBY_FMODE_DUPLEX = FMODE_DUPLEX,
69 RUBY_FMODE_APPEND = FMODE_APPEND,
70 RUBY_FMODE_CREATE = FMODE_CREATE,
71 RUBY_FMODE_NOREVLOOKUP = 0x00000100,
72 RUBY_FMODE_TRUNC = FMODE_TRUNC,
73 RUBY_FMODE_TEXTMODE = FMODE_TEXTMODE,
74 RUBY_FMODE_EXTERNAL = 0x00010000,
75 RUBY_FMODE_SETENC_BY_BOM = FMODE_SETENC_BY_BOM,
76 RUBY_FMODE_UNIX = 0x00200000,
77 RUBY_FMODE_INET = 0x00400000,
78 RUBY_FMODE_INET6 = 0x00800000,
79
80 RUBY_NODE_TYPESHIFT = NODE_TYPESHIFT,
81 RUBY_NODE_TYPEMASK = NODE_TYPEMASK,
82 RUBY_NODE_LSHIFT = NODE_LSHIFT,
83 RUBY_NODE_FL_NEWLINE = NODE_FL_NEWLINE
84 } various;
85 union {
86 enum imemo_type types;
87 enum {RUBY_IMEMO_MASK = IMEMO_MASK} mask;
88 struct RIMemo *ptr;
89 } imemo;
90 struct RSymbol *symbol_ptr;
91 enum vm_call_flag_bits vm_call_flags;
92} ruby_dummy_gdb_enums;
93
94const SIGNED_VALUE RUBY_NODE_LMASK = NODE_LMASK;
95
96int
97ruby_debug_print_indent(int level, int debug_level, int indent_level)
98{
99 if (level < debug_level) {
100 fprintf(stderr, "%*s", indent_level, "");
101 fflush(stderr);
102 return TRUE;
103 }
104 return FALSE;
105}
106
107void
108ruby_debug_printf(const char *format, ...)
109{
110 va_list ap;
111 va_start(ap, format);
112 vfprintf(stderr, format, ap);
113 va_end(ap);
114}
115
116#include "internal/gc.h"
117
118VALUE
119ruby_debug_print_value(int level, int debug_level, const char *header, VALUE obj)
120{
121 if (level < debug_level) {
122 char buff[0x100];
123 rb_raw_obj_info(buff, 0x100, obj);
124
125 fprintf(stderr, "DBG> %s: %s\n", header, buff);
126 fflush(stderr);
127 }
128 return obj;
129}
130
131void
132ruby_debug_print_v(VALUE v)
133{
134 ruby_debug_print_value(0, 1, "", v);
135}
136
137ID
138ruby_debug_print_id(int level, int debug_level, const char *header, ID id)
139{
140 if (level < debug_level) {
141 fprintf(stderr, "DBG> %s: %s\n", header, rb_id2name(id));
142 fflush(stderr);
143 }
144 return id;
145}
146
147NODE *
148ruby_debug_print_node(int level, int debug_level, const char *header, const NODE *node)
149{
150 if (level < debug_level) {
151 fprintf(stderr, "DBG> %s: %s (id: %d, line: %d, location: (%d,%d)-(%d,%d))\n",
152 header, ruby_node_name(nd_type(node)), nd_node_id(node), nd_line(node),
153 nd_first_lineno(node), nd_first_column(node),
154 nd_last_lineno(node), nd_last_column(node));
155 }
156 return (NODE *)node;
157}
158
159void
160ruby_debug_print_n(const NODE *node)
161{
162 ruby_debug_print_node(0, 1, "", node);
163}
164
165void
166ruby_debug_breakpoint(void)
167{
168 /* */
169}
170
171#if defined _WIN32
172extern int ruby_w32_rtc_error;
173#endif
174#if defined _WIN32 || defined __CYGWIN__
175#include <windows.h>
176UINT ruby_w32_codepage[2];
177#endif
178extern int ruby_rgengc_debug;
179extern int ruby_on_ci;
180
181int
182ruby_env_debug_option(const char *str, int len, void *arg)
183{
184 int ov;
185 size_t retlen;
186 unsigned long n;
187#define NAME_MATCH(name) (len == sizeof(name) - 1 && strncmp(str, (name), len) == 0)
188#define SET_WHEN(name, var, val) do { \
189 if (NAME_MATCH(name)) { \
190 (var) = (val); \
191 return 1; \
192 } \
193 } while (0)
194#define NAME_MATCH_VALUE(name) \
195 ((size_t)len >= sizeof(name)-1 && \
196 strncmp(str, (name), sizeof(name)-1) == 0 && \
197 ((len == sizeof(name)-1 && !(len = 0)) || \
198 (str[sizeof(name)-1] == '=' && \
199 (str += sizeof(name), len -= sizeof(name), 1))))
200#define SET_UINT(val) do { \
201 n = ruby_scan_digits(str, len, 10, &retlen, &ov); \
202 if (!ov && retlen) { \
203 val = (unsigned int)n; \
204 } \
205 str += retlen; \
206 len -= retlen; \
207 } while (0)
208#define SET_UINT_LIST(name, vals, num) do { \
209 int i; \
210 for (i = 0; i < (num); ++i) { \
211 SET_UINT((vals)[i]); \
212 if (!len || *str != ':') break; \
213 ++str; \
214 --len; \
215 } \
216 if (len > 0) { \
217 fprintf(stderr, "ignored "name" option: '%.*s'\n", len, str); \
218 } \
219 } while (0)
220#define SET_WHEN_UINT(name, vals, num, req) \
221 if (NAME_MATCH_VALUE(name)) { \
222 if (!len) req; \
223 else SET_UINT_LIST(name, vals, num); \
224 return 1; \
225 }
226
227 if (NAME_MATCH("gc_stress")) {
228 rb_gc_initial_stress_set(Qtrue);
229 return 1;
230 }
231 SET_WHEN("core", ruby_enable_coredump, 1);
232 SET_WHEN("ci", ruby_on_ci, 1);
233 SET_WHEN_UINT("rgengc", &ruby_rgengc_debug, 1, ruby_rgengc_debug = 1);
234#if defined _WIN32
235 SET_WHEN("rtc_error", ruby_w32_rtc_error, 1);
236#endif
237#if defined _WIN32 || defined __CYGWIN__
238 SET_WHEN_UINT("codepage", ruby_w32_codepage, numberof(ruby_w32_codepage),
239 fprintf(stderr, "missing codepage argument"));
240#endif
241 return 0;
242}
243
244static void
245set_debug_option(const char *str, int len, void *arg)
246{
247 if (!ruby_env_debug_option(str, len, arg)) {
248 fprintf(stderr, "unexpected debug option: %.*s\n", len, str);
249 }
250}
251
252#if USE_RUBY_DEBUG_LOG
253static void setup_debug_log(void);
254#else
255#define setup_debug_log()
256#endif
257
258void
259ruby_set_debug_option(const char *str)
260{
261 ruby_each_words(str, set_debug_option, 0);
262 setup_debug_log();
263}
264
265#if USE_RUBY_DEBUG_LOG
266
267// RUBY_DEBUG_LOG features
268// See vm_debug.h comments for details.
269
270#define MAX_DEBUG_LOG 0x1000
271#define MAX_DEBUG_LOG_MESSAGE_LEN 0x0200
272#define MAX_DEBUG_LOG_FILTER_LEN 0x0020
273#define MAX_DEBUG_LOG_FILTER_NUM 0x0010
274
275enum ruby_debug_log_mode ruby_debug_log_mode;
276
277struct debug_log_filter {
278 enum debug_log_filter_type {
279 dlf_all,
280 dlf_file, // "file:..."
281 dlf_func, // "func:..."
282 } type;
283 bool negative;
284 char str[MAX_DEBUG_LOG_FILTER_LEN];
285};
286
287static const char *dlf_type_names[] = {
288 "all",
289 "file",
290 "func",
291};
292
293#ifdef MAX_PATH
294#define DEBUG_LOG_MAX_PATH (MAX_PATH-1)
295#else
296#define DEBUG_LOG_MAX_PATH 255
297#endif
298
299static struct {
300 char *mem;
301 unsigned int cnt;
302 struct debug_log_filter filters[MAX_DEBUG_LOG_FILTER_NUM];
303 unsigned int filters_num;
304 bool show_pid;
305 rb_nativethread_lock_t lock;
306 char output_file[DEBUG_LOG_MAX_PATH+1];
307 FILE *output;
308} debug_log;
309
310static char *
311RUBY_DEBUG_LOG_MEM_ENTRY(unsigned int index)
312{
313 return &debug_log.mem[MAX_DEBUG_LOG_MESSAGE_LEN * index];
314}
315
316static enum debug_log_filter_type
317filter_type(const char *str, int *skiplen)
318{
319 if (strncmp(str, "file:", 5) == 0) {
320 *skiplen = 5;
321 return dlf_file;
322 }
323 else if(strncmp(str, "func:", 5) == 0) {
324 *skiplen = 5;
325 return dlf_func;
326 }
327 else {
328 *skiplen = 0;
329 return dlf_all;
330 }
331}
332
333static void
334setup_debug_log_filter(void)
335{
336 const char *filter_config = getenv("RUBY_DEBUG_LOG_FILTER");
337
338 if (filter_config && strlen(filter_config) > 0) {
339 unsigned int i;
340 for (i=0; i<MAX_DEBUG_LOG_FILTER_NUM && filter_config; i++) {
341 size_t len;
342 const char *str = filter_config;
343 const char *p;
344
345 if ((p = strchr(str, ',')) == NULL) {
346 len = strlen(str);
347 filter_config = NULL;
348 }
349 else {
350 len = p - str - 1; // 1 is ','
351 filter_config = p + 1;
352 }
353
354 // positive/negative
355 if (*str == '-') {
356 debug_log.filters[i].negative = true;
357 str++;
358 }
359 else if (*str == '+') {
360 // negative is false on default.
361 str++;
362 }
363
364 // type
365 int skiplen;
366 debug_log.filters[i].type = filter_type(str, &skiplen);
367 len -= skiplen;
368
369 if (len >= MAX_DEBUG_LOG_FILTER_LEN) {
370 fprintf(stderr, "too long: %s (max:%d)\n", str, MAX_DEBUG_LOG_FILTER_LEN - 1);
371 exit(EXIT_FAILURE);
372 }
373
374 // body
375 strncpy(debug_log.filters[i].str, str + skiplen, len);
376 debug_log.filters[i].str[len] = 0;
377 }
378 debug_log.filters_num = i;
379
380 for (i=0; i<debug_log.filters_num; i++) {
381 fprintf(stderr, "RUBY_DEBUG_LOG_FILTER[%d]=%s (%s%s)\n", i,
382 debug_log.filters[i].str,
383 debug_log.filters[i].negative ? "-" : "",
384 dlf_type_names[debug_log.filters[i].type]);
385 }
386 }
387}
388
389static void
390setup_debug_log(void)
391{
392 // check RUBY_DEBUG_LOG
393 const char *log_config = getenv("RUBY_DEBUG_LOG");
394 if (log_config && strlen(log_config) > 0) {
395 if (strcmp(log_config, "mem") == 0) {
396 debug_log.mem = (char *)malloc(MAX_DEBUG_LOG * MAX_DEBUG_LOG_MESSAGE_LEN);
397 if (debug_log.mem == NULL) {
398 fprintf(stderr, "setup_debug_log failed (can't allocate memory)\n");
399 exit(EXIT_FAILURE);
400 }
401 ruby_debug_log_mode |= ruby_debug_log_memory;
402 }
403 else if (strcmp(log_config, "stderr") == 0) {
404 ruby_debug_log_mode |= ruby_debug_log_stderr;
405 }
406 else {
407 ruby_debug_log_mode |= ruby_debug_log_file;
408
409 // pid extension with %p
410 unsigned long len = strlen(log_config);
411
412 for (unsigned long i=0, j=0; i<len; i++) {
413 const char c = log_config[i];
414
415 if (c == '%') {
416 i++;
417 switch (log_config[i]) {
418 case '%':
419 debug_log.output_file[j++] = '%';
420 break;
421 case 'p':
422 snprintf(debug_log.output_file + j, DEBUG_LOG_MAX_PATH - j, "%d", getpid());
423 j = strlen(debug_log.output_file);
424 break;
425 default:
426 fprintf(stderr, "can not parse RUBY_DEBUG_LOG filename: %s\n", log_config);
427 exit(EXIT_FAILURE);
428 }
429 }
430 else {
431 debug_log.output_file[j++] = c;
432 }
433
434 if (j >= DEBUG_LOG_MAX_PATH) {
435 fprintf(stderr, "RUBY_DEBUG_LOG=%s is too long\n", log_config);
436 exit(EXIT_FAILURE);
437 }
438 }
439
440 if ((debug_log.output = fopen(debug_log.output_file, "w")) == NULL) {
441 fprintf(stderr, "can not open %s for RUBY_DEBUG_LOG\n", log_config);
442 exit(EXIT_FAILURE);
443 }
444 setvbuf(debug_log.output, NULL, _IONBF, 0);
445 }
446
447 fprintf(stderr, "RUBY_DEBUG_LOG=%s %s%s%s\n", log_config,
448 (ruby_debug_log_mode & ruby_debug_log_memory) ? "[mem]" : "",
449 (ruby_debug_log_mode & ruby_debug_log_stderr) ? "[stderr]" : "",
450 (ruby_debug_log_mode & ruby_debug_log_file) ? "[file]" : "");
451 if (debug_log.output_file[0]) {
452 fprintf(stderr, "RUBY_DEBUG_LOG filename=%s\n", debug_log.output_file);
453 }
454
455 rb_nativethread_lock_initialize(&debug_log.lock);
456
457 setup_debug_log_filter();
458
459 if (getenv("RUBY_DEBUG_LOG_PID")) {
460 debug_log.show_pid = true;
461 }
462 }
463}
464
465static bool
466check_filter(const char *str, const struct debug_log_filter *filter, bool *state)
467{
468 if (filter->negative) {
469 if (strstr(str, filter->str) == NULL) {
470 *state = true;
471 return false;
472 }
473 else {
474 *state = false;
475 return true;
476 }
477 }
478 else {
479 if (strstr(str, filter->str) != NULL) {
480 *state = true;
481 return true;
482 }
483 else {
484 *state = false;
485 return false;
486 }
487 }
488}
489
490//
491// RUBY_DEBUG_LOG_FILTER=-foo,-bar,baz,boo
492// returns true if
493// (func_name or file_name) doesn't contain foo
494// and
495// (func_name or file_name) doesn't contain bar
496// and
497// (func_name or file_name) contains baz or boo
498//
499// RUBY_DEBUG_LOG_FILTER=foo,bar,-baz,-boo
500// returns true if
501// (func_name or file_name) contains foo or bar
502// or
503// (func_name or file_name) doesn't contain baz and
504// (func_name or file_name) doesn't contain boo and
505//
506// You can specify "file:" (ex file:foo) or "func:" (ex func:foo)
507// prefixes to specify the filter for.
508//
509bool
510ruby_debug_log_filter(const char *func_name, const char *file_name)
511{
512 if (debug_log.filters_num > 0) {
513 bool state = false;
514
515 for (unsigned int i = 0; i<debug_log.filters_num; i++) {
516 const struct debug_log_filter *filter = &debug_log.filters[i];
517
518 switch (filter->type) {
519 case dlf_all:
520 if (check_filter(func_name, filter, &state)) return state;
521 if (check_filter(file_name, filter, &state)) return state;
522 break;
523 case dlf_func:
524 if (check_filter(func_name, filter, &state)) return state;
525 break;
526 case dlf_file:
527 if (check_filter(file_name, filter, &state)) return state;
528 break;
529 }
530 }
531 return state;
532 }
533 else {
534 return true;
535 }
536}
537
538static const char *
539pretty_filename(const char *path)
540{
541 // basename is one idea.
542 const char *s;
543 while ((s = strchr(path, '/')) != NULL) {
544 path = s+1;
545 }
546 return path;
547}
548
549#undef ruby_debug_log
550void
551ruby_debug_log(const char *file, int line, const char *func_name, const char *fmt, ...)
552{
553 char buff[MAX_DEBUG_LOG_MESSAGE_LEN] = {0};
554 int len = 0;
555 int r = 0;
556
557 if (debug_log.show_pid) {
558 r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN, "pid:%d\t", getpid());
559 if (r < 0) rb_bug("ruby_debug_log returns %d", r);
560 len += r;
561 }
562
563 // message title
564 if (func_name && len < MAX_DEBUG_LOG_MESSAGE_LEN) {
565 r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN, "%s\t", func_name);
566 if (r < 0) rb_bug("ruby_debug_log returns %d", r);
567 len += r;
568 }
569
570 // message
571 if (fmt && len < MAX_DEBUG_LOG_MESSAGE_LEN) {
572 va_list args;
573 va_start(args, fmt);
574 r = vsnprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, fmt, args);
575 va_end(args);
576 if (r < 0) rb_bug("ruby_debug_log vsnprintf() returns %d", r);
577 len += r;
578 }
579
580 // optional information
581
582 // C location
583 if (file && len < MAX_DEBUG_LOG_MESSAGE_LEN) {
584 r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN, "\t%s:%d", pretty_filename(file), line);
585 if (r < 0) rb_bug("ruby_debug_log returns %d", r);
586 len += r;
587 }
588
589 rb_execution_context_t *ec = rb_current_execution_context(false);
590
591 // Ruby location
592 int ruby_line;
593 const char *ruby_file = ec ? rb_source_location_cstr(&ruby_line) : NULL;
594
595 if (len < MAX_DEBUG_LOG_MESSAGE_LEN) {
596 if (ruby_file) {
597 r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\t%s:%d", pretty_filename(ruby_file), ruby_line);
598 }
599 else {
600 r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\t");
601 }
602 if (r < 0) rb_bug("ruby_debug_log returns %d", r);
603 len += r;
604 }
605
606#ifdef RUBY_NT_SERIAL
607 // native thread information
608 if (len < MAX_DEBUG_LOG_MESSAGE_LEN) {
609 r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\tnt:%d", ruby_nt_serial);
610 if (r < 0) rb_bug("ruby_debug_log returns %d", r);
611 len += r;
612 }
613#endif
614
615 if (ec) {
616 rb_thread_t *th = ec ? rb_ec_thread_ptr(ec) : NULL;
617
618 // ractor information
619 if (ruby_single_main_ractor == NULL) {
620 rb_ractor_t *cr = th ? th->ractor : NULL;
621 rb_vm_t *vm = GET_VM();
622
623 if (r && len < MAX_DEBUG_LOG_MESSAGE_LEN) {
624 r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\tr:#%d/%u (%u)",
625 cr ? (int)rb_ractor_id(cr) : -1, vm->ractor.cnt, vm->ractor.sched.running_cnt);
626
627 if (r < 0) rb_bug("ruby_debug_log returns %d", r);
628 len += r;
629 }
630 }
631
632 // thread information
633 if (th && r && len < MAX_DEBUG_LOG_MESSAGE_LEN) {
634 rb_execution_context_t *rec = th->ractor ? th->ractor->threads.running_ec : NULL;
635 const rb_thread_t *rth = rec ? rec->thread_ptr : NULL;
636 const rb_thread_t *sth = th->ractor ? th->ractor->threads.sched.running : NULL;
637
638 if (rth != th || sth != th) {
639 r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\tth:%u (rth:%d,sth:%d)",
640 rb_th_serial(th), rth ? (int)rb_th_serial(rth) : -1, sth ? (int)rb_th_serial(sth) : -1);
641 }
642 else {
643 r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\tth:%u", rb_th_serial(th));
644 }
645 if (r < 0) rb_bug("ruby_debug_log returns %d", r);
646 len += r;
647 }
648 }
649
650 rb_nativethread_lock_lock(&debug_log.lock);
651 {
652 unsigned int cnt = debug_log.cnt++;
653
654 if (ruby_debug_log_mode & ruby_debug_log_memory) {
655 unsigned int index = cnt % MAX_DEBUG_LOG;
656 char *dst = RUBY_DEBUG_LOG_MEM_ENTRY(index);
657 strncpy(dst, buff, MAX_DEBUG_LOG_MESSAGE_LEN);
658 }
659 if (ruby_debug_log_mode & ruby_debug_log_stderr) {
660 fprintf(stderr, "%4u: %s\n", cnt, buff);
661 }
662 if (ruby_debug_log_mode & ruby_debug_log_file) {
663 fprintf(debug_log.output, "%u\t%s\n", cnt, buff);
664 }
665 }
666 rb_nativethread_lock_unlock(&debug_log.lock);
667}
668
669// for debugger
670static void
671debug_log_dump(FILE *out, unsigned int n)
672{
673 if (ruby_debug_log_mode & ruby_debug_log_memory) {
674 unsigned int size = debug_log.cnt > MAX_DEBUG_LOG ? MAX_DEBUG_LOG : debug_log.cnt;
675 unsigned int current_index = debug_log.cnt % MAX_DEBUG_LOG;
676 if (n == 0) n = size;
677 if (n > size) n = size;
678
679 for (unsigned int i=0; i<n; i++) {
680 int index = current_index - size + i;
681 if (index < 0) index += MAX_DEBUG_LOG;
682 VM_ASSERT(index <= MAX_DEBUG_LOG);
683 const char *mesg = RUBY_DEBUG_LOG_MEM_ENTRY(index);
684 fprintf(out, "%4u: %s\n", debug_log.cnt - size + i, mesg);
685 }
686 }
687 else {
688 fprintf(stderr, "RUBY_DEBUG_LOG=mem is not specified.");
689 }
690}
691
692// for debuggers
693
694void
695ruby_debug_log_print(unsigned int n)
696{
697 debug_log_dump(stderr, n);
698}
699
700void
701ruby_debug_log_dump(const char *fname, unsigned int n)
702{
703 FILE *fp = fopen(fname, "w");
704 if (fp == NULL) {
705 fprintf(stderr, "can't open %s. give up.\n", fname);
706 }
707 else {
708 debug_log_dump(fp, n);
709 fclose(fp);
710 }
711}
712
713#else
714
715#undef ruby_debug_log
716void
717ruby_debug_log(const char *file, int line, const char *func_name, const char *fmt, ...)
718{
719 va_list args;
720
721 fprintf(stderr, "[%s:%d] %s: ", file, line, func_name);
722
723 va_start(args, fmt);
724 vfprintf(stderr, fmt, args);
725 va_end(args);
726
727 fprintf(stderr, "\n");
728}
729
730#endif // #if USE_RUBY_DEBUG_LOG
ruby_coderange_type
What rb_enc_str_coderange() returns.
Definition coderange.h:33
ruby_fl_ushift
This is an enum because GDB wants it (rather than a macro).
Definition fl_type.h:141
ruby_fl_type
The flags.
Definition fl_type.h:172
#define Qtrue
Old name of RUBY_Qtrue.
Encoding relates APIs.
rb_econv_result_t
return value of rb_econv_convert()
Definition transcode.h:30
ruby_econv_flag_type
This enum is kind of omnibus.
Definition transcode.h:452
#define FMODE_READABLE
The IO is opened for reading.
Definition io.h:162
#define FMODE_SETENC_BY_BOM
This flag amends the encoding of the IO so that the BOM of the contents of the IO takes effect.
Definition io.h:260
#define FMODE_READWRITE
The IO is opened for both read/write.
Definition io.h:168
#define FMODE_TTY
The IO is a TTY.
Definition io.h:192
#define FMODE_CREATE
The IO is opened for creating.
Definition io.h:215
#define FMODE_WRITABLE
The IO is opened for writing.
Definition io.h:165
#define FMODE_APPEND
The IO is opened for appending.
Definition io.h:207
#define FMODE_DUPLEX
Ruby eventually detects that the IO is bidirectional.
Definition io.h:200
#define FMODE_BINMODE
The IO is in "binary mode".
Definition io.h:179
#define FMODE_SYNC
The IO is in "sync mode".
Definition io.h:186
#define FMODE_TEXTMODE
The IO is in "text mode".
Definition io.h:243
#define FMODE_TRUNC
This flag amends the effect of FMODE_CREATE, so that if there already is a file at the given path it ...
Definition io.h:229
int len
Length of the buffer.
Definition io.h:8
void ruby_each_words(const char *str, void(*func)(const char *word, int len, void *argv), void *argv)
Scans the passed string, with calling the callback function every time it encounters a "word".
VALUE type(ANYARGS)
ANYARGS-ed function type.
ruby_rarray_consts
This is an enum because GDB wants it (rather than a macro).
Definition rarray.h:122
ruby_special_consts
special constants - i.e.
Definition debug.c:32
void rb_nativethread_lock_lock(rb_nativethread_lock_t *lock)
Blocks until the current thread obtains a lock.
Definition thread.c:308
void rb_nativethread_lock_unlock(rb_nativethread_lock_t *lock)
Releases a lock.
Definition thread.c:314
void rb_nativethread_lock_initialize(rb_nativethread_lock_t *lock)
Fills the passed lock with an initial value.
Definition thread.c:296
intptr_t SIGNED_VALUE
A signed integer type that has the same width with VALUE.
Definition value.h:63
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
Definition value.h:52
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40
ruby_value_type
C-level type of an object.
Definition value_type.h:113