Ruby 4.1.0dev (2026-10-02 revision bac5fe37358bdf2c0dc72c676eec8ca34392b970)
debug.c (bac5fe37358bdf2c0dc72c676eec8ca34392b970)
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_rmodule_flags rmodule_flags;
56 enum ruby_rstring_flags rstring_flags;
57 enum ruby_rarray_flags rarray_flags;
58 enum ruby_rarray_consts rarray_consts;
59 enum rbimpl_typeddata_flags rtypeddata_consts;
60 enum {
61 RUBY_FMODE_READABLE = FMODE_READABLE,
62 RUBY_FMODE_WRITABLE = FMODE_WRITABLE,
63 RUBY_FMODE_READWRITE = FMODE_READWRITE,
64 RUBY_FMODE_BINMODE = FMODE_BINMODE,
65 RUBY_FMODE_SYNC = FMODE_SYNC,
66 RUBY_FMODE_TTY = FMODE_TTY,
67 RUBY_FMODE_DUPLEX = FMODE_DUPLEX,
68 RUBY_FMODE_APPEND = FMODE_APPEND,
69 RUBY_FMODE_CREATE = FMODE_CREATE,
70 RUBY_FMODE_NOREVLOOKUP = 0x00000100,
71 RUBY_FMODE_TRUNC = FMODE_TRUNC,
72 RUBY_FMODE_TEXTMODE = FMODE_TEXTMODE,
73 RUBY_FMODE_EXTERNAL = 0x00010000,
74 RUBY_FMODE_SETENC_BY_BOM = FMODE_SETENC_BY_BOM,
75 RUBY_FMODE_UNIX = 0x00200000,
76 RUBY_FMODE_INET = 0x00400000,
77 RUBY_FMODE_INET6 = 0x00800000,
78
79 RUBY_NODE_TYPESHIFT = NODE_TYPESHIFT,
80 RUBY_NODE_TYPEMASK = NODE_TYPEMASK,
81 RUBY_NODE_LSHIFT = NODE_LSHIFT,
82 RUBY_NODE_FL_NEWLINE = NODE_FL_NEWLINE
83 } various;
84 union {
85 enum imemo_type types;
86 enum {RUBY_IMEMO_MASK = IMEMO_MASK} mask;
87 struct RIMemo *ptr;
88 } imemo;
89 struct RSymbol *symbol_ptr;
90 enum vm_call_flag_bits vm_call_flags;
91} ruby_dummy_gdb_enums;
92
93const SIGNED_VALUE RUBY_NODE_LMASK = NODE_LMASK;
94
95int
96ruby_debug_print_indent(int level, int debug_level, int indent_level)
97{
98 if (level < debug_level) {
99 fprintf(stderr, "%*s", indent_level, "");
100 fflush(stderr);
101 return TRUE;
102 }
103 return FALSE;
104}
105
106void
107ruby_debug_printf(const char *format, ...)
108{
109 va_list ap;
110 va_start(ap, format);
111 vfprintf(stderr, format, ap);
112 va_end(ap);
113}
114
115#include "internal/gc.h"
116
117VALUE
118ruby_debug_print_value(int level, int debug_level, const char *header, VALUE obj)
119{
120 if (level < debug_level) {
121 char buff[0x100];
122 rb_raw_obj_info(buff, 0x100, obj);
123
124 fprintf(stderr, "DBG> %s: %s\n", header, buff);
125 fflush(stderr);
126 }
127 return obj;
128}
129
130void
131ruby_debug_print_v(VALUE v)
132{
133 ruby_debug_print_value(0, 1, "", v);
134}
135
136ID
137ruby_debug_print_id(int level, int debug_level, const char *header, ID id)
138{
139 if (level < debug_level) {
140 fprintf(stderr, "DBG> %s: %s\n", header, rb_id2name(id));
141 fflush(stderr);
142 }
143 return id;
144}
145
146NODE *
147ruby_debug_print_node(int level, int debug_level, const char *header, const NODE *node)
148{
149 if (level < debug_level) {
150 fprintf(stderr, "DBG> %s: %s (id: %d, line: %d, location: (%d,%d)-(%d,%d))\n",
151 header, ruby_node_name(nd_type(node)), nd_node_id(node), nd_line(node),
152 nd_first_lineno(node), nd_first_column(node),
153 nd_last_lineno(node), nd_last_column(node));
154 }
155 return (NODE *)node;
156}
157
158void
159ruby_debug_print_n(const NODE *node)
160{
161 ruby_debug_print_node(0, 1, "", node);
162}
163
164void
165ruby_debug_breakpoint(void)
166{
167 /* */
168}
169
170#if defined _WIN32
171extern int ruby_w32_rtc_error;
172extern int ruby_w32_wer;
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 SET_WHEN("wer", ruby_w32_wer, 1);
237#endif
238#if defined _WIN32 || defined __CYGWIN__
239 SET_WHEN_UINT("codepage", ruby_w32_codepage, numberof(ruby_w32_codepage),
240 fprintf(stderr, "missing codepage argument"));
241#endif
242 return 0;
243}
244
245static void
246set_debug_option(const char *str, int len, void *arg)
247{
248 if (!ruby_env_debug_option(str, len, arg)) {
249 fprintf(stderr, "unexpected debug option: %.*s\n", len, str);
250 }
251}
252
253#if USE_RUBY_DEBUG_LOG
254static void setup_debug_log(void);
255#else
256#define setup_debug_log()
257#endif
258
259void
260ruby_set_debug_option(const char *str)
261{
262 ruby_each_words(str, set_debug_option, 0);
263 setup_debug_log();
264}
265
266#if USE_RUBY_DEBUG_LOG
267
268// RUBY_DEBUG_LOG features
269// See vm_debug.h comments for details.
270
271#define MAX_DEBUG_LOG 0x1000
272#define MAX_DEBUG_LOG_MESSAGE_LEN 0x0200
273#define MAX_DEBUG_LOG_FILTER_LEN 0x0020
274#define MAX_DEBUG_LOG_FILTER_NUM 0x0010
275
276enum ruby_debug_log_mode ruby_debug_log_mode;
277
278struct debug_log_filter {
279 enum debug_log_filter_type {
280 dlf_all,
281 dlf_file, // "file:..."
282 dlf_func, // "func:..."
283 } type;
284 bool negative;
285 char str[MAX_DEBUG_LOG_FILTER_LEN];
286};
287
288static const char *dlf_type_names[] = {
289 "all",
290 "file",
291 "func",
292};
293
294#ifdef MAX_PATH
295#define DEBUG_LOG_MAX_PATH (MAX_PATH-1)
296#else
297#define DEBUG_LOG_MAX_PATH 255
298#endif
299
300static struct {
301 char *mem;
302 unsigned int cnt;
303 struct debug_log_filter filters[MAX_DEBUG_LOG_FILTER_NUM];
304 unsigned int filters_num;
305 bool show_pid;
306 rb_nativethread_lock_t lock;
307 char output_file[DEBUG_LOG_MAX_PATH+1];
308 FILE *output;
309} debug_log;
310
311static char *
312RUBY_DEBUG_LOG_MEM_ENTRY(unsigned int index)
313{
314 return &debug_log.mem[MAX_DEBUG_LOG_MESSAGE_LEN * index];
315}
316
317static enum debug_log_filter_type
318filter_type(const char *str, int *skiplen)
319{
320 if (strncmp(str, "file:", 5) == 0) {
321 *skiplen = 5;
322 return dlf_file;
323 }
324 else if(strncmp(str, "func:", 5) == 0) {
325 *skiplen = 5;
326 return dlf_func;
327 }
328 else {
329 *skiplen = 0;
330 return dlf_all;
331 }
332}
333
334static void
335setup_debug_log_filter(void)
336{
337 const char *filter_config = getenv("RUBY_DEBUG_LOG_FILTER");
338
339 if (filter_config && strlen(filter_config) > 0) {
340 unsigned int i;
341 for (i=0; i<MAX_DEBUG_LOG_FILTER_NUM && filter_config; i++) {
342 size_t len;
343 const char *str = filter_config;
344 const char *p;
345
346 if ((p = strchr(str, ',')) == NULL) {
347 len = strlen(str);
348 filter_config = NULL;
349 }
350 else {
351 len = p - str - 1; // 1 is ','
352 filter_config = p + 1;
353 }
354
355 // positive/negative
356 if (*str == '-') {
357 debug_log.filters[i].negative = true;
358 str++;
359 }
360 else if (*str == '+') {
361 // negative is false on default.
362 str++;
363 }
364
365 // type
366 int skiplen;
367 debug_log.filters[i].type = filter_type(str, &skiplen);
368 len -= skiplen;
369
370 if (len >= MAX_DEBUG_LOG_FILTER_LEN) {
371 fprintf(stderr, "too long: %s (max:%d)\n", str, MAX_DEBUG_LOG_FILTER_LEN - 1);
372 exit(EXIT_FAILURE);
373 }
374
375 // body
376 strncpy(debug_log.filters[i].str, str + skiplen, len);
377 debug_log.filters[i].str[len] = 0;
378 }
379 debug_log.filters_num = i;
380
381 for (i=0; i<debug_log.filters_num; i++) {
382 fprintf(stderr, "RUBY_DEBUG_LOG_FILTER[%d]=%s (%s%s)\n", i,
383 debug_log.filters[i].str,
384 debug_log.filters[i].negative ? "-" : "",
385 dlf_type_names[debug_log.filters[i].type]);
386 }
387 }
388}
389
390static void
391setup_debug_log(void)
392{
393 // check RUBY_DEBUG_LOG
394 const char *log_config = getenv("RUBY_DEBUG_LOG");
395 if (log_config && strlen(log_config) > 0) {
396 if (strcmp(log_config, "mem") == 0) {
397 debug_log.mem = (char *)malloc(MAX_DEBUG_LOG * MAX_DEBUG_LOG_MESSAGE_LEN);
398 if (debug_log.mem == NULL) {
399 fprintf(stderr, "setup_debug_log failed (can't allocate memory)\n");
400 exit(EXIT_FAILURE);
401 }
402 ruby_debug_log_mode |= ruby_debug_log_memory;
403 }
404 else if (strcmp(log_config, "stderr") == 0) {
405 ruby_debug_log_mode |= ruby_debug_log_stderr;
406 }
407 else {
408 ruby_debug_log_mode |= ruby_debug_log_file;
409
410 // pid extension with %p
411 unsigned long len = strlen(log_config);
412
413 for (unsigned long i=0, j=0; i<len; i++) {
414 const char c = log_config[i];
415
416 if (c == '%') {
417 i++;
418 switch (log_config[i]) {
419 case '%':
420 debug_log.output_file[j++] = '%';
421 break;
422 case 'p':
423 snprintf(debug_log.output_file + j, DEBUG_LOG_MAX_PATH - j, "%d", getpid());
424 j = strlen(debug_log.output_file);
425 break;
426 default:
427 fprintf(stderr, "can not parse RUBY_DEBUG_LOG filename: %s\n", log_config);
428 exit(EXIT_FAILURE);
429 }
430 }
431 else {
432 debug_log.output_file[j++] = c;
433 }
434
435 if (j >= DEBUG_LOG_MAX_PATH) {
436 fprintf(stderr, "RUBY_DEBUG_LOG=%s is too long\n", log_config);
437 exit(EXIT_FAILURE);
438 }
439 }
440
441 if ((debug_log.output = fopen(debug_log.output_file, "w")) == NULL) {
442 fprintf(stderr, "can not open %s for RUBY_DEBUG_LOG\n", log_config);
443 exit(EXIT_FAILURE);
444 }
445 setvbuf(debug_log.output, NULL, _IONBF, 0);
446 }
447
448 fprintf(stderr, "RUBY_DEBUG_LOG=%s %s%s%s\n", log_config,
449 (ruby_debug_log_mode & ruby_debug_log_memory) ? "[mem]" : "",
450 (ruby_debug_log_mode & ruby_debug_log_stderr) ? "[stderr]" : "",
451 (ruby_debug_log_mode & ruby_debug_log_file) ? "[file]" : "");
452 if (debug_log.output_file[0]) {
453 fprintf(stderr, "RUBY_DEBUG_LOG filename=%s\n", debug_log.output_file);
454 }
455
456 rb_nativethread_lock_initialize(&debug_log.lock);
457
458 setup_debug_log_filter();
459
460 if (getenv("RUBY_DEBUG_LOG_PID")) {
461 debug_log.show_pid = true;
462 }
463 }
464}
465
466static bool
467check_filter(const char *str, const struct debug_log_filter *filter, bool *state)
468{
469 if (filter->negative) {
470 if (strstr(str, filter->str) == NULL) {
471 *state = true;
472 return false;
473 }
474 else {
475 *state = false;
476 return true;
477 }
478 }
479 else {
480 if (strstr(str, filter->str) != NULL) {
481 *state = true;
482 return true;
483 }
484 else {
485 *state = false;
486 return false;
487 }
488 }
489}
490
491//
492// RUBY_DEBUG_LOG_FILTER=-foo,-bar,baz,boo
493// returns true if
494// (func_name or file_name) doesn't contain foo
495// and
496// (func_name or file_name) doesn't contain bar
497// and
498// (func_name or file_name) contains baz or boo
499//
500// RUBY_DEBUG_LOG_FILTER=foo,bar,-baz,-boo
501// returns true if
502// (func_name or file_name) contains foo or bar
503// or
504// (func_name or file_name) doesn't contain baz and
505// (func_name or file_name) doesn't contain boo and
506//
507// You can specify "file:" (ex file:foo) or "func:" (ex func:foo)
508// prefixes to specify the filter for.
509//
510bool
511ruby_debug_log_filter(const char *func_name, const char *file_name)
512{
513 if (debug_log.filters_num > 0) {
514 bool state = false;
515
516 for (unsigned int i = 0; i<debug_log.filters_num; i++) {
517 const struct debug_log_filter *filter = &debug_log.filters[i];
518
519 switch (filter->type) {
520 case dlf_all:
521 if (check_filter(func_name, filter, &state)) return state;
522 if (check_filter(file_name, filter, &state)) return state;
523 break;
524 case dlf_func:
525 if (check_filter(func_name, filter, &state)) return state;
526 break;
527 case dlf_file:
528 if (check_filter(file_name, filter, &state)) return state;
529 break;
530 }
531 }
532 return state;
533 }
534 else {
535 return true;
536 }
537}
538
539static const char *
540pretty_filename(const char *path)
541{
542 // basename is one idea.
543 const char *s;
544 while ((s = strchr(path, '/')) != NULL) {
545 path = s+1;
546 }
547 return path;
548}
549
550#undef ruby_debug_log
551void
552ruby_debug_log(const char *file, int line, const char *func_name, const char *fmt, ...)
553{
554 char buff[MAX_DEBUG_LOG_MESSAGE_LEN] = {0};
555 int len = 0;
556 int r = 0;
557
558 if (debug_log.show_pid) {
559 r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN, "pid:%d\t", getpid());
560 if (r < 0) rb_bug("ruby_debug_log returns %d", r);
561 len += r;
562 }
563
564 // message title
565 if (func_name && len < MAX_DEBUG_LOG_MESSAGE_LEN) {
566 r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN, "%s\t", func_name);
567 if (r < 0) rb_bug("ruby_debug_log returns %d", r);
568 len += r;
569 }
570
571 // message
572 if (fmt && len < MAX_DEBUG_LOG_MESSAGE_LEN) {
573 va_list args;
574 va_start(args, fmt);
575 r = vsnprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, fmt, args);
576 va_end(args);
577 if (r < 0) rb_bug("ruby_debug_log vsnprintf() returns %d", r);
578 len += r;
579 }
580
581 // optional information
582
583 // C location
584 if (file && len < MAX_DEBUG_LOG_MESSAGE_LEN) {
585 r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN, "\t%s:%d", pretty_filename(file), line);
586 if (r < 0) rb_bug("ruby_debug_log returns %d", r);
587 len += r;
588 }
589
590 rb_execution_context_t *ec = rb_current_execution_context(false);
591
592 // Ruby location
593 int ruby_line;
594 const char *ruby_file = ec ? rb_source_location_cstr(&ruby_line) : NULL;
595
596 if (len < MAX_DEBUG_LOG_MESSAGE_LEN) {
597 if (ruby_file) {
598 r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\t%s:%d", pretty_filename(ruby_file), ruby_line);
599 }
600 else {
601 r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\t");
602 }
603 if (r < 0) rb_bug("ruby_debug_log returns %d", r);
604 len += r;
605 }
606
607#ifdef RUBY_NT_SERIAL
608 // native thread information
609 if (len < MAX_DEBUG_LOG_MESSAGE_LEN) {
610 r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\tnt:%d", ruby_nt_serial);
611 if (r < 0) rb_bug("ruby_debug_log returns %d", r);
612 len += r;
613 }
614#endif
615
616 if (ec) {
617 rb_thread_t *th = ec ? rb_ec_thread_ptr(ec) : NULL;
618
619 // ractor information
620 if (ruby_single_main_ractor == NULL) {
621 rb_ractor_t *cr = th ? th->ractor : NULL;
622 rb_vm_t *vm = GET_VM();
623
624 if (r && len < MAX_DEBUG_LOG_MESSAGE_LEN) {
625 r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\tr:#%d/%u",
626 cr ? (int)rb_ractor_id(cr) : -1, vm->ractor.cnt);
627
628 if (r < 0) rb_bug("ruby_debug_log returns %d", r);
629 len += r;
630 }
631 }
632
633 // thread information
634 if (th && r && len < MAX_DEBUG_LOG_MESSAGE_LEN) {
635 rb_execution_context_t *rec = th->ractor ? th->ractor->threads.running_ec : NULL;
636 const rb_thread_t *rth = rec ? rec->thread_ptr : NULL;
637 const rb_thread_t *sth = th->ractor ? th->ractor->threads.sched.running : NULL;
638
639 if (rth != th || sth != th) {
640 r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\tth:%u (rth:%d,sth:%d)",
641 rb_th_serial(th), rth ? (int)rb_th_serial(rth) : -1, sth ? (int)rb_th_serial(sth) : -1);
642 }
643 else {
644 r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\tth:%u", rb_th_serial(th));
645 }
646 if (r < 0) rb_bug("ruby_debug_log returns %d", r);
647 len += r;
648 }
649 }
650
651 rb_nativethread_lock_lock(&debug_log.lock);
652 {
653 unsigned int cnt = debug_log.cnt++;
654
655 if (ruby_debug_log_mode & ruby_debug_log_memory) {
656 unsigned int index = cnt % MAX_DEBUG_LOG;
657 char *dst = RUBY_DEBUG_LOG_MEM_ENTRY(index);
658 strncpy(dst, buff, MAX_DEBUG_LOG_MESSAGE_LEN);
659 }
660 if (ruby_debug_log_mode & ruby_debug_log_stderr) {
661 fprintf(stderr, "%4u: %s\n", cnt, buff);
662 }
663 if (ruby_debug_log_mode & ruby_debug_log_file) {
664 fprintf(debug_log.output, "%u\t%s\n", cnt, buff);
665 }
666 }
667 rb_nativethread_lock_unlock(&debug_log.lock);
668}
669
670// for debugger
671static void
672debug_log_dump(FILE *out, unsigned int n)
673{
674 if (ruby_debug_log_mode & ruby_debug_log_memory) {
675 unsigned int size = debug_log.cnt > MAX_DEBUG_LOG ? MAX_DEBUG_LOG : debug_log.cnt;
676 unsigned int current_index = debug_log.cnt % MAX_DEBUG_LOG;
677 if (n == 0) n = size;
678 if (n > size) n = size;
679
680 for (unsigned int i=0; i<n; i++) {
681 int index = current_index - size + i;
682 if (index < 0) index += MAX_DEBUG_LOG;
683 VM_ASSERT(index <= MAX_DEBUG_LOG);
684 const char *mesg = RUBY_DEBUG_LOG_MEM_ENTRY(index);
685 fprintf(out, "%4u: %s\n", debug_log.cnt - size + i, mesg);
686 }
687 }
688 else {
689 fprintf(stderr, "RUBY_DEBUG_LOG=mem is not specified.");
690 }
691}
692
693// for debuggers
694
695void
696ruby_debug_log_print(unsigned int n)
697{
698 debug_log_dump(stderr, n);
699}
700
701void
702ruby_debug_log_dump(const char *fname, unsigned int n)
703{
704 FILE *fp = fopen(fname, "w");
705 if (fp == NULL) {
706 fprintf(stderr, "can't open %s. give up.\n", fname);
707 }
708 else {
709 debug_log_dump(fp, n);
710 fclose(fp);
711 }
712}
713
714#else
715
716#undef ruby_debug_log
717void
718ruby_debug_log(const char *file, int line, const char *func_name, const char *fmt, ...)
719{
720 va_list args;
721
722 fprintf(stderr, "[%s:%d] %s: ", file, line, func_name);
723
724 va_start(args, fmt);
725 vfprintf(stderr, fmt, args);
726 va_end(args);
727
728 fprintf(stderr, "\n");
729}
730
731#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:121
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:319
void rb_nativethread_lock_unlock(rb_nativethread_lock_t *lock)
Releases a lock.
Definition thread.c:325
void rb_nativethread_lock_initialize(rb_nativethread_lock_t *lock)
Fills the passed lock with an initial value.
Definition thread.c:307
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