Ruby: debug.c Source File

Ruby 4.0.6p0 (2026-07-14 revision 03b6d3f8898a28604fe6cb00eae3226b821168f4)

debug.c
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 */
32 struct 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 {
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
117 VALUE
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
136 ID
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;
172#endif
173#if defined _WIN32 || defined __CYGWIN__
174#include <windows.h>
175UINT ruby_w32_codepage[2];
176#endif
177extern int ruby_rgengc_debug;
178extern int ruby_on_ci;
179
180int
181ruby_env_debug_option(const char *str, int len, void *arg)
182{
183 int ov;
184 size_t retlen;
185 unsigned long n;
186#define NAME_MATCH(name) (len == sizeof(name) - 1 && strncmp(str, (name), len) == 0)
187#define SET_WHEN(name, var, val) do { \
188 if (NAME_MATCH(name)) { \
189 (var) = (val); \
190 return 1; \
191 } \
192 } while (0)
193#define NAME_MATCH_VALUE(name) \
194 ((size_t)len >= sizeof(name)-1 && \
195 strncmp(str, (name), sizeof(name)-1) == 0 && \
196 ((len == sizeof(name)-1 && !(len = 0)) || \
197 (str[sizeof(name)-1] == '=' && \
198 (str += sizeof(name), len -= sizeof(name), 1))))
199#define SET_UINT(val) do { \
200 n = ruby_scan_digits(str, len, 10, &retlen, &ov); \
201 if (!ov && retlen) { \
202 val = (unsigned int)n; \
203 } \
204 str += retlen; \
205 len -= retlen; \
206 } while (0)
207#define SET_UINT_LIST(name, vals, num) do { \
208 int i; \
209 for (i = 0; i < (num); ++i) { \
210 SET_UINT((vals)[i]); \
211 if (!len || *str != ':') break; \
212 ++str; \
213 --len; \
214 } \
215 if (len > 0) { \
216 fprintf(stderr, "ignored "name" option: '%.*s'\n", len, str); \
217 } \
218 } while (0)
219#define SET_WHEN_UINT(name, vals, num, req) \
220 if (NAME_MATCH_VALUE(name)) { \
221 if (!len) req; \
222 else SET_UINT_LIST(name, vals, num); \
223 return 1; \
224 }
225
226 if (NAME_MATCH("gc_stress")) {
227 rb_gc_initial_stress_set(Qtrue);
228 return 1;
229 }
230 SET_WHEN("core", ruby_enable_coredump, 1);
231 SET_WHEN("ci", ruby_on_ci, 1);
232 SET_WHEN_UINT("rgengc", &ruby_rgengc_debug, 1, ruby_rgengc_debug = 1);
233#if defined _WIN32
234 SET_WHEN("rtc_error", ruby_w32_rtc_error, 1);
235#endif
236#if defined _WIN32 || defined __CYGWIN__
237 SET_WHEN_UINT("codepage", ruby_w32_codepage, numberof(ruby_w32_codepage),
238 fprintf(stderr, "missing codepage argument"));
239#endif
240 return 0;
241}
242
243static void
244set_debug_option(const char *str, int len, void *arg)
245{
246 if (!ruby_env_debug_option(str, len, arg)) {
247 fprintf(stderr, "unexpected debug option: %.*s\n", len, str);
248 }
249}
250
251#if USE_RUBY_DEBUG_LOG
252static void setup_debug_log(void);
253#else
254#define setup_debug_log()
255#endif
256
257void
258ruby_set_debug_option(const char *str)
259{
260 ruby_each_words(str, set_debug_option, 0);
261 setup_debug_log();
262}
263
264#if USE_RUBY_DEBUG_LOG
265
266// RUBY_DEBUG_LOG features
267// See vm_debug.h comments for details.
268
269#define MAX_DEBUG_LOG 0x1000
270#define MAX_DEBUG_LOG_MESSAGE_LEN 0x0200
271#define MAX_DEBUG_LOG_FILTER_LEN 0x0020
272#define MAX_DEBUG_LOG_FILTER_NUM 0x0010
273
274enum ruby_debug_log_mode ruby_debug_log_mode;
275
276struct debug_log_filter {
277 enum debug_log_filter_type {
278 dlf_all,
279 dlf_file, // "file:..."
280 dlf_func, // "func:..."
281 } type;
282 bool negative;
283 char str[MAX_DEBUG_LOG_FILTER_LEN];
284};
285
286static const char *dlf_type_names[] = {
287 "all",
288 "file",
289 "func",
290};
291
292#ifdef MAX_PATH
293#define DEBUG_LOG_MAX_PATH (MAX_PATH-1)
294#else
295#define DEBUG_LOG_MAX_PATH 255
296#endif
297
298static struct {
299 char *mem;
300 unsigned int cnt;
301 struct debug_log_filter filters[MAX_DEBUG_LOG_FILTER_NUM];
302 unsigned int filters_num;
303 bool show_pid;
304 rb_nativethread_lock_t lock;
305 char output_file[DEBUG_LOG_MAX_PATH+1];
306 FILE *output;
307} debug_log;
308
309static char *
310RUBY_DEBUG_LOG_MEM_ENTRY(unsigned int index)
311{
312 return &debug_log.mem[MAX_DEBUG_LOG_MESSAGE_LEN * index];
313}
314
315static enum debug_log_filter_type
316filter_type(const char *str, int *skiplen)
317{
318 if (strncmp(str, "file:", 5) == 0) {
319 *skiplen = 5;
320 return dlf_file;
321 }
322 else if(strncmp(str, "func:", 5) == 0) {
323 *skiplen = 5;
324 return dlf_func;
325 }
326 else {
327 *skiplen = 0;
328 return dlf_all;
329 }
330}
331
332static void
333setup_debug_log_filter(void)
334{
335 const char *filter_config = getenv("RUBY_DEBUG_LOG_FILTER");
336
337 if (filter_config && strlen(filter_config) > 0) {
338 unsigned int i;
339 for (i=0; i<MAX_DEBUG_LOG_FILTER_NUM && filter_config; i++) {
340 size_t len;
341 const char *str = filter_config;
342 const char *p;
343
344 if ((p = strchr(str, ',')) == NULL) {
345 len = strlen(str);
346 filter_config = NULL;
347 }
348 else {
349 len = p - str - 1; // 1 is ','
350 filter_config = p + 1;
351 }
352
353 // positive/negative
354 if (*str == '-') {
355 debug_log.filters[i].negative = true;
356 str++;
357 }
358 else if (*str == '+') {
359 // negative is false on default.
360 str++;
361 }
362
363 // type
364 int skiplen;
365 debug_log.filters[i].type = filter_type(str, &skiplen);
366 len -= skiplen;
367
368 if (len >= MAX_DEBUG_LOG_FILTER_LEN) {
369 fprintf(stderr, "too long: %s (max:%d)\n", str, MAX_DEBUG_LOG_FILTER_LEN - 1);
370 exit(1);
371 }
372
373 // body
374 strncpy(debug_log.filters[i].str, str + skiplen, len);
375 debug_log.filters[i].str[len] = 0;
376 }
377 debug_log.filters_num = i;
378
379 for (i=0; i<debug_log.filters_num; i++) {
380 fprintf(stderr, "RUBY_DEBUG_LOG_FILTER[%d]=%s (%s%s)\n", i,
381 debug_log.filters[i].str,
382 debug_log.filters[i].negative ? "-" : "",
383 dlf_type_names[debug_log.filters[i].type]);
384 }
385 }
386}
387
388static void
389setup_debug_log(void)
390{
391 // check RUBY_DEBUG_LOG
392 const char *log_config = getenv("RUBY_DEBUG_LOG");
393 if (log_config && strlen(log_config) > 0) {
394 if (strcmp(log_config, "mem") == 0) {
395 debug_log.mem = (char *)malloc(MAX_DEBUG_LOG * MAX_DEBUG_LOG_MESSAGE_LEN);
396 if (debug_log.mem == NULL) {
397 fprintf(stderr, "setup_debug_log failed (can't allocate memory)\n");
398 exit(1);
399 }
400 ruby_debug_log_mode |= ruby_debug_log_memory;
401 }
402 else if (strcmp(log_config, "stderr") == 0) {
403 ruby_debug_log_mode |= ruby_debug_log_stderr;
404 }
405 else {
406 ruby_debug_log_mode |= ruby_debug_log_file;
407
408 // pid extension with %p
409 unsigned long len = strlen(log_config);
410
411 for (unsigned long i=0, j=0; i<len; i++) {
412 const char c = log_config[i];
413
414 if (c == '%') {
415 i++;
416 switch (log_config[i]) {
417 case '%':
418 debug_log.output_file[j++] = '%';
419 break;
420 case 'p':
421 snprintf(debug_log.output_file + j, DEBUG_LOG_MAX_PATH - j, "%d", getpid());
422 j = strlen(debug_log.output_file);
423 break;
424 default:
425 fprintf(stderr, "can not parse RUBY_DEBUG_LOG filename: %s\n", log_config);
426 exit(1);
427 }
428 }
429 else {
430 debug_log.output_file[j++] = c;
431 }
432
433 if (j >= DEBUG_LOG_MAX_PATH) {
434 fprintf(stderr, "RUBY_DEBUG_LOG=%s is too long\n", log_config);
435 exit(1);
436 }
437 }
438
439 if ((debug_log.output = fopen(debug_log.output_file, "w")) == NULL) {
440 fprintf(stderr, "can not open %s for RUBY_DEBUG_LOG\n", log_config);
441 exit(1);
442 }
443 setvbuf(debug_log.output, NULL, _IONBF, 0);
444 }
445
446 fprintf(stderr, "RUBY_DEBUG_LOG=%s %s%s%s\n", log_config,
447 (ruby_debug_log_mode & ruby_debug_log_memory) ? "[mem]" : "",
448 (ruby_debug_log_mode & ruby_debug_log_stderr) ? "[stderr]" : "",
449 (ruby_debug_log_mode & ruby_debug_log_file) ? "[file]" : "");
450 if (debug_log.output_file[0]) {
451 fprintf(stderr, "RUBY_DEBUG_LOG filename=%s\n", debug_log.output_file);
452 }
453
454 rb_nativethread_lock_initialize(&debug_log.lock);
455
456 setup_debug_log_filter();
457
458 if (getenv("RUBY_DEBUG_LOG_PID")) {
459 debug_log.show_pid = true;
460 }
461 }
462}
463
464static bool
465check_filter(const char *str, const struct debug_log_filter *filter, bool *state)
466{
467 if (filter->negative) {
468 if (strstr(str, filter->str) == NULL) {
469 *state = true;
470 return false;
471 }
472 else {
473 *state = false;
474 return true;
475 }
476 }
477 else {
478 if (strstr(str, filter->str) != NULL) {
479 *state = true;
480 return true;
481 }
482 else {
483 *state = false;
484 return false;
485 }
486 }
487}
488
489//
490// RUBY_DEBUG_LOG_FILTER=-foo,-bar,baz,boo
491// returns true if
492// (func_name or file_name) doesn't contain foo
493// and
494// (func_name or file_name) doesn't contain bar
495// and
496// (func_name or file_name) contains baz or boo
497//
498// RUBY_DEBUG_LOG_FILTER=foo,bar,-baz,-boo
499// returns true if
500// (func_name or file_name) contains foo or bar
501// or
502// (func_name or file_name) doesn't contain baz and
503// (func_name or file_name) doesn't contain boo and
504//
505// You can specify "file:" (ex file:foo) or "func:" (ex func:foo)
506// prefixes to specify the filter for.
507//
508bool
509ruby_debug_log_filter(const char *func_name, const char *file_name)
510{
511 if (debug_log.filters_num > 0) {
512 bool state = false;
513
514 for (unsigned int i = 0; i<debug_log.filters_num; i++) {
515 const struct debug_log_filter *filter = &debug_log.filters[i];
516
517 switch (filter->type) {
518 case dlf_all:
519 if (check_filter(func_name, filter, &state)) return state;
520 if (check_filter(file_name, filter, &state)) return state;
521 break;
522 case dlf_func:
523 if (check_filter(func_name, filter, &state)) return state;
524 break;
525 case dlf_file:
526 if (check_filter(file_name, filter, &state)) return state;
527 break;
528 }
529 }
530 return state;
531 }
532 else {
533 return true;
534 }
535}
536
537static const char *
538pretty_filename(const char *path)
539{
540 // basename is one idea.
541 const char *s;
542 while ((s = strchr(path, '/')) != NULL) {
543 path = s+1;
544 }
545 return path;
546}
547
548#undef ruby_debug_log
549void
550ruby_debug_log(const char *file, int line, const char *func_name, const char *fmt, ...)
551{
552 char buff[MAX_DEBUG_LOG_MESSAGE_LEN] = {0};
553 int len = 0;
554 int r = 0;
555
556 if (debug_log.show_pid) {
557 r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN, "pid:%d\t", getpid());
558 if (r < 0) rb_bug("ruby_debug_log returns %d", r);
559 len += r;
560 }
561
562 // message title
563 if (func_name && len < MAX_DEBUG_LOG_MESSAGE_LEN) {
564 r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN, "%s\t", func_name);
565 if (r < 0) rb_bug("ruby_debug_log returns %d", r);
566 len += r;
567 }
568
569 // message
570 if (fmt && len < MAX_DEBUG_LOG_MESSAGE_LEN) {
571 va_list args;
572 va_start(args, fmt);
573 r = vsnprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, fmt, args);
574 va_end(args);
575 if (r < 0) rb_bug("ruby_debug_log vsnprintf() returns %d", r);
576 len += r;
577 }
578
579 // optional information
580
581 // C location
582 if (file && len < MAX_DEBUG_LOG_MESSAGE_LEN) {
583 r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN, "\t%s:%d", pretty_filename(file), line);
584 if (r < 0) rb_bug("ruby_debug_log returns %d", r);
585 len += r;
586 }
587
588 rb_execution_context_t *ec = rb_current_execution_context(false);
589
590 // Ruby location
591 int ruby_line;
592 const char *ruby_file = ec ? rb_source_location_cstr(&ruby_line) : NULL;
593
594 if (len < MAX_DEBUG_LOG_MESSAGE_LEN) {
595 if (ruby_file) {
596 r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\t%s:%d", pretty_filename(ruby_file), ruby_line);
597 }
598 else {
599 r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\t");
600 }
601 if (r < 0) rb_bug("ruby_debug_log returns %d", r);
602 len += r;
603 }
604
605#ifdef RUBY_NT_SERIAL
606 // native thread information
607 if (len < MAX_DEBUG_LOG_MESSAGE_LEN) {
608 r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\tnt:%d", ruby_nt_serial);
609 if (r < 0) rb_bug("ruby_debug_log returns %d", r);
610 len += r;
611 }
612#endif
613
614 if (ec) {
615 rb_thread_t *th = ec ? rb_ec_thread_ptr(ec) : NULL;
616
617 // ractor information
618 if (ruby_single_main_ractor == NULL) {
619 rb_ractor_t *cr = th ? th->ractor : NULL;
620 rb_vm_t *vm = GET_VM();
621
622 if (r && len < MAX_DEBUG_LOG_MESSAGE_LEN) {
623 r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\tr:#%d/%u (%u)",
624 cr ? (int)rb_ractor_id(cr) : -1, vm->ractor.cnt, vm->ractor.sched.running_cnt);
625
626 if (r < 0) rb_bug("ruby_debug_log returns %d", r);
627 len += r;
628 }
629 }
630
631 // thread information
632 if (th && r && len < MAX_DEBUG_LOG_MESSAGE_LEN) {
633 rb_execution_context_t *rec = th->ractor ? th->ractor->threads.running_ec : NULL;
634 const rb_thread_t *rth = rec ? rec->thread_ptr : NULL;
635 const rb_thread_t *sth = th->ractor ? th->ractor->threads.sched.running : NULL;
636
637 if (rth != th || sth != th) {
638 r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\tth:%u (rth:%d,sth:%d)",
639 rb_th_serial(th), rth ? (int)rb_th_serial(rth) : -1, sth ? (int)rb_th_serial(sth) : -1);
640 }
641 else {
642 r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\tth:%u", rb_th_serial(th));
643 }
644 if (r < 0) rb_bug("ruby_debug_log returns %d", r);
645 len += r;
646 }
647 }
648
649 rb_nativethread_lock_lock(&debug_log.lock);
650 {
651 unsigned int cnt = debug_log.cnt++;
652
653 if (ruby_debug_log_mode & ruby_debug_log_memory) {
654 unsigned int index = cnt % MAX_DEBUG_LOG;
655 char *dst = RUBY_DEBUG_LOG_MEM_ENTRY(index);
656 strncpy(dst, buff, MAX_DEBUG_LOG_MESSAGE_LEN);
657 }
658 if (ruby_debug_log_mode & ruby_debug_log_stderr) {
659 fprintf(stderr, "%4u: %s\n", cnt, buff);
660 }
661 if (ruby_debug_log_mode & ruby_debug_log_file) {
662 fprintf(debug_log.output, "%u\t%s\n", cnt, buff);
663 }
664 }
665 rb_nativethread_lock_unlock(&debug_log.lock);
666}
667
668// for debugger
669static void
670debug_log_dump(FILE *out, unsigned int n)
671{
672 if (ruby_debug_log_mode & ruby_debug_log_memory) {
673 unsigned int size = debug_log.cnt > MAX_DEBUG_LOG ? MAX_DEBUG_LOG : debug_log.cnt;
674 unsigned int current_index = debug_log.cnt % MAX_DEBUG_LOG;
675 if (n == 0) n = size;
676 if (n > size) n = size;
677
678 for (unsigned int i=0; i<n; i++) {
679 int index = current_index - size + i;
680 if (index < 0) index += MAX_DEBUG_LOG;
681 VM_ASSERT(index <= MAX_DEBUG_LOG);
682 const char *mesg = RUBY_DEBUG_LOG_MEM_ENTRY(index);
683 fprintf(out, "%4u: %s\n", debug_log.cnt - size + i, mesg);
684 }
685 }
686 else {
687 fprintf(stderr, "RUBY_DEBUG_LOG=mem is not specified.");
688 }
689}
690
691// for debuggers
692
693void
694ruby_debug_log_print(unsigned int n)
695{
696 debug_log_dump(stderr, n);
697}
698
699void
700ruby_debug_log_dump(const char *fname, unsigned int n)
701{
702 FILE *fp = fopen(fname, "w");
703 if (fp == NULL) {
704 fprintf(stderr, "can't open %s. give up.\n", fname);
705 }
706 else {
707 debug_log_dump(fp, n);
708 fclose(fp);
709 }
710}
711
712#else
713
714#undef ruby_debug_log
715void
716ruby_debug_log(const char *file, int line, const char *func_name, const char *fmt, ...)
717{
718 va_list args;
719
720 fprintf(stderr, "[%s:%d] %s: ", file, line, func_name);
721
722 va_start(args, fmt);
723 vfprintf(stderr, fmt, args);
724 va_end(args);
725
726 fprintf(stderr, "\n");
727}
728
729#endif // #if USE_RUBY_DEBUG_LOG
ruby_coderange_type
ruby_coderange_type
What rb_enc_str_coderange() returns.
Definition coderange.h:33
ruby_fl_ushift
ruby_fl_ushift
This is an enum because GDB wants it (rather than a macro).
Definition fl_type.h:153
ruby_fl_type
ruby_fl_type
The flags.
Definition fl_type.h:184
Qtrue
#define Qtrue
Old name of RUBY_Qtrue.
Definition special_consts.h:61
encoding.h
Encoding relates APIs.
rb_econv_result_t
rb_econv_result_t
return value of rb_econv_convert()
Definition transcode.h:30
ruby_econv_flag_type
ruby_econv_flag_type
This enum is kind of omnibus.
Definition transcode.h:452
io.h
FMODE_READABLE
#define FMODE_READABLE
The IO is opened for reading.
Definition io.h:162
FMODE_SETENC_BY_BOM
#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
FMODE_READWRITE
#define FMODE_READWRITE
The IO is opened for both read/write.
Definition io.h:168
FMODE_TTY
#define FMODE_TTY
The IO is a TTY.
Definition io.h:192
FMODE_CREATE
#define FMODE_CREATE
The IO is opened for creating.
Definition io.h:215
FMODE_WRITABLE
#define FMODE_WRITABLE
The IO is opened for writing.
Definition io.h:165
FMODE_APPEND
#define FMODE_APPEND
The IO is opened for appending.
Definition io.h:207
FMODE_DUPLEX
#define FMODE_DUPLEX
Ruby eventually detects that the IO is bidirectional.
Definition io.h:200
FMODE_BINMODE
#define FMODE_BINMODE
The IO is in "binary mode".
Definition io.h:179
FMODE_SYNC
#define FMODE_SYNC
The IO is in "sync mode".
Definition io.h:186
FMODE_TEXTMODE
#define FMODE_TEXTMODE
The IO is in "text mode".
Definition io.h:243
FMODE_TRUNC
#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
len
int len
Length of the buffer.
Definition io.h:8
util.h
ruby_each_words
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".
Definition util.c:596
ruby::backward::cxxanyargs::type
VALUE type(ANYARGS)
ANYARGS-ed function type.
Definition cxxanyargs.hpp:56
ruby_rarray_consts
ruby_rarray_consts
This is an enum because GDB wants it (rather than a macro).
Definition rarray.h:122
ruby.h
ruby_special_consts
ruby_special_consts
special constants - i.e.
Definition special_consts.h:86
RIMemo
Definition debug.c:32
RSymbol
Definition symbol.h:26
thread_native.h
rb_nativethread_lock_lock
void rb_nativethread_lock_lock(rb_nativethread_lock_t *lock)
Blocks until the current thread obtains a lock.
Definition thread.c:307
rb_nativethread_lock_unlock
void rb_nativethread_lock_unlock(rb_nativethread_lock_t *lock)
Releases a lock.
Definition thread.c:313
rb_nativethread_lock_initialize
void rb_nativethread_lock_initialize(rb_nativethread_lock_t *lock)
Fills the passed lock with an initial value.
Definition thread.c:295
SIGNED_VALUE
intptr_t SIGNED_VALUE
A signed integer type that has the same width with VALUE.
Definition value.h:63
ID
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
Definition value.h:52
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40
ruby_value_type
ruby_value_type
C-level type of an object.
Definition value_type.h:113