2006-12-31 18:02:22 +03:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
debug.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
created at: 04/08/25 02:31:54 JST
|
|
|
|
|
* blockinlining.c, compile.c, compile.h, debug.c, debug.h,
id.c, insnhelper.h, insns.def, thread.c, thread_pthread.ci,
thread_pthread.h, thread_win32.ci, thread_win32.h, vm.h,
vm_dump.c, vm_evalbody.ci, vm_opts.h: fix comments and
copyright year.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13920 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-11-14 01:13:04 +03:00
|
|
|
Copyright (C) 2004-2007 Koichi Sasada
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
2020-05-08 12:31:09 +03:00
|
|
|
#include "ruby/internal/config.h"
|
2019-12-04 11:16:30 +03:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "eval_intern.h"
|
2021-09-28 13:55:07 +03:00
|
|
|
#include "encindex.h"
|
2019-12-04 11:16:30 +03:00
|
|
|
#include "id.h"
|
|
|
|
#include "internal/signal.h"
|
2007-10-16 13:21:11 +04:00
|
|
|
#include "ruby/encoding.h"
|
2018-01-09 09:24:10 +03:00
|
|
|
#include "ruby/io.h"
|
2019-12-04 11:16:30 +03:00
|
|
|
#include "ruby/ruby.h"
|
2008-02-24 00:13:05 +03:00
|
|
|
#include "ruby/util.h"
|
2017-10-25 03:33:29 +03:00
|
|
|
#include "symbol.h"
|
2019-12-04 11:16:30 +03:00
|
|
|
#include "vm_core.h"
|
|
|
|
#include "vm_debug.h"
|
VALUE size packed callinfo (ci).
Now, rb_call_info contains how to call the method with tuple of
(mid, orig_argc, flags, kwarg). Most of cases, kwarg == NULL and
mid+argc+flags only requires 64bits. So this patch packed
rb_call_info to VALUE (1 word) on such cases. If we can not
represent it in VALUE, then use imemo_callinfo which contains
conventional callinfo (rb_callinfo, renamed from rb_call_info).
iseq->body->ci_kw_size is removed because all of callinfo is VALUE
size (packed ci or a pointer to imemo_callinfo).
To access ci information, we need to use these functions:
vm_ci_mid(ci), _flag(ci), _argc(ci), _kwarg(ci).
struct rb_call_info_kw_arg is renamed to rb_callinfo_kwarg.
rb_funcallv_with_cc() and rb_method_basic_definition_p_with_cc()
is temporary removed because cd->ci should be marked.
2020-01-08 02:20:36 +03:00
|
|
|
#include "vm_callinfo.h"
|
RUBY_DEBUG_LOG: Logging debug information mechanism (#3279)
* RUBY_DEBUG_LOG: Logging debug information mechanism
This feature provides a mechanism to store logging information
to a file, stderr or memory space with simple macros.
The following information will be stored.
* (1) __FILE__, __LINE__ in C
* (2) __FILE__, __LINE__ in Ruby
* (3) __func__ in C (message title)
* (4) given string with sprintf format
* (5) Thread number (if multiple threads are running)
This feature is enabled only USE_RUBY_DEBUG_LOG is enabled.
Release version should not enable it.
Running with the `RUBY_DEBUG_LOG` environment variable enables
this feature.
# logging into a file
RUBY_DEBUG_LOG=/path/to/file STDERR
# logging into STDERR
RUBY_DEBUG_LOG=stderr
# logging into memory space (check with a debugger)
# It will help if the timing is important.
RUBY_DEBUG_LOG=mem
RUBY_DEBUG_LOG_FILTER environment variable can specify the fileter string.
If "(3) __func__ in C (message title)" contains the specified string, the
infomation will be stored (example: RUBY_DEBUG_LOG_FILTER=str will enable
only on str related information).
In a MRI source code, you can use the following macros:
* RUBY_DEBUG_LOG(fmt, ...): Above (1) to (4) will be logged.
* RUBY_DEBUG_LOG2(file, line, fmt, ...):
Same as RUBY_DEBUG_LOG(), but (1) will be replaced with given file, line.
2020-07-03 10:55:54 +03:00
|
|
|
#include "ruby/thread_native.h"
|
2020-11-17 10:40:47 +03:00
|
|
|
#include "ractor_core.h"
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2019-12-03 08:42:53 +03:00
|
|
|
/* This is the only place struct RIMemo is actually used */
|
|
|
|
struct RIMemo {
|
|
|
|
VALUE flags;
|
|
|
|
VALUE v0;
|
|
|
|
VALUE v1;
|
|
|
|
VALUE v2;
|
|
|
|
VALUE v3;
|
|
|
|
};
|
|
|
|
|
2007-10-16 13:21:11 +04:00
|
|
|
/* for gdb */
|
2009-08-05 13:46:07 +04:00
|
|
|
const union {
|
2007-10-16 13:21:11 +04:00
|
|
|
enum ruby_special_consts special_consts;
|
|
|
|
enum ruby_value_type value_type;
|
2008-05-08 10:56:59 +04:00
|
|
|
enum ruby_tag_type tag_type;
|
2007-10-16 13:21:11 +04:00
|
|
|
enum node_type node_type;
|
2009-05-21 17:17:54 +04:00
|
|
|
enum ruby_method_ids method_ids;
|
2013-09-20 08:53:08 +04:00
|
|
|
enum ruby_id_types id_types;
|
2015-09-13 05:03:31 +03:00
|
|
|
enum ruby_fl_type fl_types;
|
2020-04-18 10:35:20 +03:00
|
|
|
enum ruby_fl_ushift fl_ushift;
|
2015-09-13 05:03:31 +03:00
|
|
|
enum ruby_encoding_consts encoding_consts;
|
|
|
|
enum ruby_coderange_type enc_coderange_types;
|
|
|
|
enum ruby_econv_flag_type econv_flag_types;
|
2020-04-25 11:52:27 +03:00
|
|
|
rb_econv_result_t econv_result;
|
2021-09-28 13:55:07 +03:00
|
|
|
enum ruby_preserved_encindex encoding_index;
|
2017-06-01 07:43:03 +03:00
|
|
|
enum ruby_robject_flags robject_flags;
|
2022-07-11 17:09:39 +03:00
|
|
|
#if !USE_RVARGC
|
2020-04-25 11:52:27 +03:00
|
|
|
enum ruby_robject_consts robject_consts;
|
2022-07-11 17:09:39 +03:00
|
|
|
#endif
|
2017-06-01 07:43:03 +03:00
|
|
|
enum ruby_rmodule_flags rmodule_flags;
|
|
|
|
enum ruby_rstring_flags rstring_flags;
|
2021-08-26 17:06:32 +03:00
|
|
|
#if !USE_RVARGC
|
2020-04-25 11:52:27 +03:00
|
|
|
enum ruby_rstring_consts rstring_consts;
|
2021-08-26 17:06:32 +03:00
|
|
|
#endif
|
2017-06-01 07:43:03 +03:00
|
|
|
enum ruby_rarray_flags rarray_flags;
|
2020-04-25 11:52:27 +03:00
|
|
|
enum ruby_rarray_consts rarray_consts;
|
2007-10-16 13:21:11 +04:00
|
|
|
enum {
|
2017-07-05 09:32:54 +03:00
|
|
|
RUBY_FMODE_READABLE = FMODE_READABLE,
|
|
|
|
RUBY_FMODE_WRITABLE = FMODE_WRITABLE,
|
|
|
|
RUBY_FMODE_READWRITE = FMODE_READWRITE,
|
|
|
|
RUBY_FMODE_BINMODE = FMODE_BINMODE,
|
|
|
|
RUBY_FMODE_SYNC = FMODE_SYNC,
|
|
|
|
RUBY_FMODE_TTY = FMODE_TTY,
|
|
|
|
RUBY_FMODE_DUPLEX = FMODE_DUPLEX,
|
|
|
|
RUBY_FMODE_APPEND = FMODE_APPEND,
|
|
|
|
RUBY_FMODE_CREATE = FMODE_CREATE,
|
|
|
|
RUBY_FMODE_NOREVLOOKUP = 0x00000100,
|
|
|
|
RUBY_FMODE_TRUNC = FMODE_TRUNC,
|
|
|
|
RUBY_FMODE_TEXTMODE = FMODE_TEXTMODE,
|
|
|
|
RUBY_FMODE_PREP = 0x00010000,
|
|
|
|
RUBY_FMODE_SETENC_BY_BOM = FMODE_SETENC_BY_BOM,
|
|
|
|
RUBY_FMODE_UNIX = 0x00200000,
|
|
|
|
RUBY_FMODE_INET = 0x00400000,
|
|
|
|
RUBY_FMODE_INET6 = 0x00800000,
|
|
|
|
|
2007-10-16 13:29:32 +04:00
|
|
|
RUBY_NODE_TYPESHIFT = NODE_TYPESHIFT,
|
|
|
|
RUBY_NODE_TYPEMASK = NODE_TYPEMASK,
|
|
|
|
RUBY_NODE_LSHIFT = NODE_LSHIFT,
|
2008-07-01 12:27:58 +04:00
|
|
|
RUBY_NODE_FL_NEWLINE = NODE_FL_NEWLINE
|
2007-10-16 13:21:11 +04:00
|
|
|
} various;
|
2017-11-23 06:14:12 +03:00
|
|
|
union {
|
|
|
|
enum imemo_type types;
|
|
|
|
enum {RUBY_IMEMO_MASK = IMEMO_MASK} mask;
|
|
|
|
struct RIMemo *ptr;
|
|
|
|
} imemo;
|
2017-10-25 03:33:29 +03:00
|
|
|
struct RSymbol *symbol_ptr;
|
2017-11-02 10:52:48 +03:00
|
|
|
enum vm_call_flag_bits vm_call_flags;
|
2009-08-05 13:46:07 +04:00
|
|
|
} ruby_dummy_gdb_enums;
|
2007-10-16 13:21:11 +04:00
|
|
|
|
2010-05-05 08:31:48 +04:00
|
|
|
const SIGNED_VALUE RUBY_NODE_LMASK = NODE_LMASK;
|
2007-10-16 13:21:11 +04:00
|
|
|
|
2008-04-14 09:34:04 +04:00
|
|
|
int
|
2007-06-24 21:19:22 +04:00
|
|
|
ruby_debug_print_indent(int level, int debug_level, int indent_level)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
if (level < debug_level) {
|
2008-02-23 22:03:32 +03:00
|
|
|
fprintf(stderr, "%*s", indent_level, "");
|
2006-12-31 18:02:22 +03:00
|
|
|
fflush(stderr);
|
2009-09-14 11:39:16 +04:00
|
|
|
return TRUE;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2009-09-14 11:39:16 +04:00
|
|
|
return FALSE;
|
2008-04-14 09:34:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ruby_debug_printf(const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
|
|
|
vfprintf(stderr, format, ap);
|
|
|
|
va_end(ap);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2023-02-08 14:56:53 +03:00
|
|
|
#include "internal/gc.h"
|
2016-07-25 11:00:46 +03:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE
|
2007-06-29 11:57:24 +04:00
|
|
|
ruby_debug_print_value(int level, int debug_level, const char *header, VALUE obj)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
if (level < debug_level) {
|
2016-07-25 11:00:46 +03:00
|
|
|
char buff[0x100];
|
|
|
|
rb_raw_obj_info(buff, 0x100, obj);
|
|
|
|
|
|
|
|
fprintf(stderr, "DBG> %s: %s\n", header, buff);
|
2006-12-31 18:02:22 +03:00
|
|
|
fflush(stderr);
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-06-24 21:19:22 +04:00
|
|
|
ruby_debug_print_v(VALUE v)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2007-06-24 21:19:22 +04:00
|
|
|
ruby_debug_print_value(0, 1, "", v);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ID
|
2007-06-29 11:57:24 +04:00
|
|
|
ruby_debug_print_id(int level, int debug_level, const char *header, ID id)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
if (level < debug_level) {
|
2015-05-23 19:36:26 +03:00
|
|
|
fprintf(stderr, "DBG> %s: %s\n", header, rb_id2name(id));
|
2006-12-31 18:02:22 +03:00
|
|
|
fflush(stderr);
|
|
|
|
}
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
NODE *
|
2007-06-29 11:57:24 +04:00
|
|
|
ruby_debug_print_node(int level, int debug_level, const char *header, const NODE *node)
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
{
|
|
|
|
if (level < debug_level) {
|
2009-09-14 11:39:16 +04:00
|
|
|
fprintf(stderr, "DBG> %s: %s (%u)\n", header,
|
2007-05-17 08:00:36 +04:00
|
|
|
ruby_node_name(nd_type(node)), nd_line(node));
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
}
|
2007-06-29 11:57:24 +04:00
|
|
|
return (NODE *)node;
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
void
|
* this commit is a result of refactoring. only renaming functions,
moving definitions place, add/remove prototypes, deleting
unused variables and removing yarv.h.
This commit doesn't change any behavior of ruby/vm.
* yarv.h, common.mk: remove yarv.h (contents are moved to yarvcore.h).
* error.c, eval_intern.h: include yarvcore.h instead yarv.h
* rename some functions:
* debug.[ch]: debug_*() -> ruby_debug_*()
* iseq.c: iseq_*() -> rb_iseq_*(), ruby_iseq_disasm()
* iseq.c: node_name() -> ruby_node_name()
* vm.c: yarv_check_redefinition_opt_method() ->
rb_vm_check_redefinition_opt_method()
* some refactoring with checking -Wall.
* array.c: remove rb_ary_ptr() (unused) and remove unused
local variables.
* object.c: add a prototype of rb_mod_module_exec().
* eval_intern.h (ruby_cref): set it inline.
* eval_load.c (rb_load), yarvcore.c: yarv_load() -> rb_load_internal().
* parse.y: add a prototype of rb_parse_in_eval() (in eval.c).
* process.c: add a prototype of rb_thread_stop_timer_thread() (in thread.c).
* thread.c: remove raw_gets() function (unused) and fix some format
mismatch (format mismatchs have remained yet. this is todo).
* thread.c (rb_thread_wait_fd_rw): fix typo on label name.
* thread_pthread.ci: comment out codes with USE_THREAD_CACHE.
* vm.c (rb_svar, rb_backref_get, rb_backref_get,
rb_lastline_get, rb_lastline_set) : moved from yarvcore.c.
* vm.c (yarv_init_redefined_flag): add a prototype and rename
yarv_opt_method_table to vm_opt_method_table.
* vm.c (rb_thread_eval): moved from yarvcore.c.
* yarvcore.c: remove unused global variables and fix to use nsdr().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-07 04:25:05 +03:00
|
|
|
ruby_debug_breakpoint(void)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
/* */
|
|
|
|
}
|
2007-06-29 11:57:24 +04:00
|
|
|
|
2017-03-31 03:35:02 +03:00
|
|
|
#if defined _WIN32
|
|
|
|
# if RUBY_MSVCRT_VERSION >= 80
|
|
|
|
extern int ruby_w32_rtc_error;
|
|
|
|
# endif
|
2017-05-16 03:15:54 +03:00
|
|
|
#endif
|
|
|
|
#if defined _WIN32 || defined __CYGWIN__
|
|
|
|
#include <windows.h>
|
2017-06-06 06:45:02 +03:00
|
|
|
UINT ruby_w32_codepage[2];
|
2017-03-31 03:35:02 +03:00
|
|
|
#endif
|
2017-06-19 17:36:18 +03:00
|
|
|
extern int ruby_rgengc_debug;
|
2019-12-05 08:39:03 +03:00
|
|
|
extern int ruby_on_ci;
|
2017-03-31 03:35:02 +03:00
|
|
|
|
2017-06-21 05:44:23 +03:00
|
|
|
int
|
|
|
|
ruby_env_debug_option(const char *str, int len, void *arg)
|
2007-06-29 11:57:24 +04:00
|
|
|
{
|
2017-06-19 17:36:18 +03:00
|
|
|
int ov;
|
|
|
|
size_t retlen;
|
|
|
|
unsigned long n;
|
2014-11-18 17:58:03 +03:00
|
|
|
#define SET_WHEN(name, var, val) do { \
|
2007-06-29 11:57:24 +04:00
|
|
|
if (len == sizeof(name) - 1 && \
|
2010-12-07 15:16:10 +03:00
|
|
|
strncmp(str, (name), len) == 0) { \
|
2014-11-18 17:58:03 +03:00
|
|
|
(var) = (val); \
|
2017-06-21 05:44:23 +03:00
|
|
|
return 1; \
|
2008-02-24 00:13:05 +03:00
|
|
|
} \
|
|
|
|
} while (0)
|
2017-06-19 17:36:18 +03:00
|
|
|
#define NAME_MATCH_VALUE(name) \
|
|
|
|
((size_t)len >= sizeof(name)-1 && \
|
|
|
|
strncmp(str, (name), sizeof(name)-1) == 0 && \
|
|
|
|
((len == sizeof(name)-1 && !(len = 0)) || \
|
|
|
|
(str[sizeof(name)-1] == '=' && \
|
|
|
|
(str += sizeof(name), len -= sizeof(name), 1))))
|
|
|
|
#define SET_UINT(val) do { \
|
|
|
|
n = ruby_scan_digits(str, len, 10, &retlen, &ov); \
|
|
|
|
if (!ov && retlen) { \
|
|
|
|
val = (unsigned int)n; \
|
|
|
|
} \
|
|
|
|
str += retlen; \
|
|
|
|
len -= retlen; \
|
|
|
|
} while (0)
|
|
|
|
#define SET_UINT_LIST(name, vals, num) do { \
|
|
|
|
int i; \
|
|
|
|
for (i = 0; i < (num); ++i) { \
|
|
|
|
SET_UINT((vals)[i]); \
|
|
|
|
if (!len || *str != ':') break; \
|
|
|
|
++str; \
|
|
|
|
--len; \
|
|
|
|
} \
|
|
|
|
if (len > 0) { \
|
|
|
|
fprintf(stderr, "ignored "name" option: `%.*s'\n", len, str); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
#define SET_WHEN_UINT(name, vals, num, req) \
|
|
|
|
if (NAME_MATCH_VALUE(name)) SET_UINT_LIST(name, vals, num);
|
2017-03-31 03:35:02 +03:00
|
|
|
|
2014-11-18 17:58:03 +03:00
|
|
|
SET_WHEN("gc_stress", *ruby_initial_gc_stress_ptr, Qtrue);
|
|
|
|
SET_WHEN("core", ruby_enable_coredump, 1);
|
2019-12-05 08:39:03 +03:00
|
|
|
SET_WHEN("ci", ruby_on_ci, 1);
|
2017-06-19 17:36:18 +03:00
|
|
|
if (NAME_MATCH_VALUE("rgengc")) {
|
|
|
|
if (!len) ruby_rgengc_debug = 1;
|
|
|
|
else SET_UINT_LIST("rgengc", &ruby_rgengc_debug, 1);
|
2017-06-21 05:44:23 +03:00
|
|
|
return 1;
|
2017-06-19 17:36:18 +03:00
|
|
|
}
|
2017-03-31 03:35:02 +03:00
|
|
|
#if defined _WIN32
|
|
|
|
# if RUBY_MSVCRT_VERSION >= 80
|
2014-11-18 17:58:03 +03:00
|
|
|
SET_WHEN("rtc_error", ruby_w32_rtc_error, 1);
|
2017-03-31 03:35:02 +03:00
|
|
|
# endif
|
2017-05-16 03:15:54 +03:00
|
|
|
#endif
|
|
|
|
#if defined _WIN32 || defined __CYGWIN__
|
2017-06-06 06:45:02 +03:00
|
|
|
if (NAME_MATCH_VALUE("codepage")) {
|
2017-06-19 17:36:18 +03:00
|
|
|
if (!len) fprintf(stderr, "missing codepage argument");
|
|
|
|
else SET_UINT_LIST("codepage", ruby_w32_codepage, numberof(ruby_w32_codepage));
|
2017-06-21 05:44:23 +03:00
|
|
|
return 1;
|
2017-03-31 03:35:02 +03:00
|
|
|
}
|
2009-02-16 10:46:24 +03:00
|
|
|
#endif
|
2017-06-21 05:44:23 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_debug_option(const char *str, int len, void *arg)
|
|
|
|
{
|
|
|
|
if (!ruby_env_debug_option(str, len, arg)) {
|
|
|
|
fprintf(stderr, "unexpected debug option: %.*s\n", len, str);
|
|
|
|
}
|
2008-02-24 00:13:05 +03:00
|
|
|
}
|
|
|
|
|
2021-12-28 11:58:39 +03:00
|
|
|
#if USE_RUBY_DEBUG_LOG
|
RUBY_DEBUG_LOG: Logging debug information mechanism (#3279)
* RUBY_DEBUG_LOG: Logging debug information mechanism
This feature provides a mechanism to store logging information
to a file, stderr or memory space with simple macros.
The following information will be stored.
* (1) __FILE__, __LINE__ in C
* (2) __FILE__, __LINE__ in Ruby
* (3) __func__ in C (message title)
* (4) given string with sprintf format
* (5) Thread number (if multiple threads are running)
This feature is enabled only USE_RUBY_DEBUG_LOG is enabled.
Release version should not enable it.
Running with the `RUBY_DEBUG_LOG` environment variable enables
this feature.
# logging into a file
RUBY_DEBUG_LOG=/path/to/file STDERR
# logging into STDERR
RUBY_DEBUG_LOG=stderr
# logging into memory space (check with a debugger)
# It will help if the timing is important.
RUBY_DEBUG_LOG=mem
RUBY_DEBUG_LOG_FILTER environment variable can specify the fileter string.
If "(3) __func__ in C (message title)" contains the specified string, the
infomation will be stored (example: RUBY_DEBUG_LOG_FILTER=str will enable
only on str related information).
In a MRI source code, you can use the following macros:
* RUBY_DEBUG_LOG(fmt, ...): Above (1) to (4) will be logged.
* RUBY_DEBUG_LOG2(file, line, fmt, ...):
Same as RUBY_DEBUG_LOG(), but (1) will be replaced with given file, line.
2020-07-03 10:55:54 +03:00
|
|
|
static void setup_debug_log(void);
|
|
|
|
#else
|
|
|
|
#define setup_debug_log()
|
|
|
|
#endif
|
|
|
|
|
2008-02-24 00:13:05 +03:00
|
|
|
void
|
|
|
|
ruby_set_debug_option(const char *str)
|
|
|
|
{
|
|
|
|
ruby_each_words(str, set_debug_option, 0);
|
RUBY_DEBUG_LOG: Logging debug information mechanism (#3279)
* RUBY_DEBUG_LOG: Logging debug information mechanism
This feature provides a mechanism to store logging information
to a file, stderr or memory space with simple macros.
The following information will be stored.
* (1) __FILE__, __LINE__ in C
* (2) __FILE__, __LINE__ in Ruby
* (3) __func__ in C (message title)
* (4) given string with sprintf format
* (5) Thread number (if multiple threads are running)
This feature is enabled only USE_RUBY_DEBUG_LOG is enabled.
Release version should not enable it.
Running with the `RUBY_DEBUG_LOG` environment variable enables
this feature.
# logging into a file
RUBY_DEBUG_LOG=/path/to/file STDERR
# logging into STDERR
RUBY_DEBUG_LOG=stderr
# logging into memory space (check with a debugger)
# It will help if the timing is important.
RUBY_DEBUG_LOG=mem
RUBY_DEBUG_LOG_FILTER environment variable can specify the fileter string.
If "(3) __func__ in C (message title)" contains the specified string, the
infomation will be stored (example: RUBY_DEBUG_LOG_FILTER=str will enable
only on str related information).
In a MRI source code, you can use the following macros:
* RUBY_DEBUG_LOG(fmt, ...): Above (1) to (4) will be logged.
* RUBY_DEBUG_LOG2(file, line, fmt, ...):
Same as RUBY_DEBUG_LOG(), but (1) will be replaced with given file, line.
2020-07-03 10:55:54 +03:00
|
|
|
setup_debug_log();
|
|
|
|
}
|
|
|
|
|
2021-12-28 11:58:39 +03:00
|
|
|
#if USE_RUBY_DEBUG_LOG
|
RUBY_DEBUG_LOG: Logging debug information mechanism (#3279)
* RUBY_DEBUG_LOG: Logging debug information mechanism
This feature provides a mechanism to store logging information
to a file, stderr or memory space with simple macros.
The following information will be stored.
* (1) __FILE__, __LINE__ in C
* (2) __FILE__, __LINE__ in Ruby
* (3) __func__ in C (message title)
* (4) given string with sprintf format
* (5) Thread number (if multiple threads are running)
This feature is enabled only USE_RUBY_DEBUG_LOG is enabled.
Release version should not enable it.
Running with the `RUBY_DEBUG_LOG` environment variable enables
this feature.
# logging into a file
RUBY_DEBUG_LOG=/path/to/file STDERR
# logging into STDERR
RUBY_DEBUG_LOG=stderr
# logging into memory space (check with a debugger)
# It will help if the timing is important.
RUBY_DEBUG_LOG=mem
RUBY_DEBUG_LOG_FILTER environment variable can specify the fileter string.
If "(3) __func__ in C (message title)" contains the specified string, the
infomation will be stored (example: RUBY_DEBUG_LOG_FILTER=str will enable
only on str related information).
In a MRI source code, you can use the following macros:
* RUBY_DEBUG_LOG(fmt, ...): Above (1) to (4) will be logged.
* RUBY_DEBUG_LOG2(file, line, fmt, ...):
Same as RUBY_DEBUG_LOG(), but (1) will be replaced with given file, line.
2020-07-03 10:55:54 +03:00
|
|
|
|
|
|
|
// RUBY_DEBUG_LOG features
|
|
|
|
// See vm_debug.h comments for details.
|
|
|
|
|
|
|
|
#define MAX_DEBUG_LOG 0x1000
|
|
|
|
#define MAX_DEBUG_LOG_MESSAGE_LEN 0x0200
|
2022-05-20 12:00:49 +03:00
|
|
|
#define MAX_DEBUG_LOG_FILTER_LEN 0x0020
|
|
|
|
#define MAX_DEBUG_LOG_FILTER_NUM 0x0010
|
RUBY_DEBUG_LOG: Logging debug information mechanism (#3279)
* RUBY_DEBUG_LOG: Logging debug information mechanism
This feature provides a mechanism to store logging information
to a file, stderr or memory space with simple macros.
The following information will be stored.
* (1) __FILE__, __LINE__ in C
* (2) __FILE__, __LINE__ in Ruby
* (3) __func__ in C (message title)
* (4) given string with sprintf format
* (5) Thread number (if multiple threads are running)
This feature is enabled only USE_RUBY_DEBUG_LOG is enabled.
Release version should not enable it.
Running with the `RUBY_DEBUG_LOG` environment variable enables
this feature.
# logging into a file
RUBY_DEBUG_LOG=/path/to/file STDERR
# logging into STDERR
RUBY_DEBUG_LOG=stderr
# logging into memory space (check with a debugger)
# It will help if the timing is important.
RUBY_DEBUG_LOG=mem
RUBY_DEBUG_LOG_FILTER environment variable can specify the fileter string.
If "(3) __func__ in C (message title)" contains the specified string, the
infomation will be stored (example: RUBY_DEBUG_LOG_FILTER=str will enable
only on str related information).
In a MRI source code, you can use the following macros:
* RUBY_DEBUG_LOG(fmt, ...): Above (1) to (4) will be logged.
* RUBY_DEBUG_LOG2(file, line, fmt, ...):
Same as RUBY_DEBUG_LOG(), but (1) will be replaced with given file, line.
2020-07-03 10:55:54 +03:00
|
|
|
|
|
|
|
enum ruby_debug_log_mode ruby_debug_log_mode;
|
|
|
|
|
2022-06-08 10:14:20 +03:00
|
|
|
struct debug_log_filter {
|
|
|
|
enum debug_log_filter_type {
|
|
|
|
dlf_all,
|
|
|
|
dlf_file, // "file:..."
|
|
|
|
dlf_func, // "func:..."
|
|
|
|
} type;
|
|
|
|
bool negative;
|
|
|
|
char str[MAX_DEBUG_LOG_FILTER_LEN];
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *dlf_type_names[] = {
|
|
|
|
"all",
|
|
|
|
"file",
|
|
|
|
"func",
|
|
|
|
};
|
|
|
|
|
RUBY_DEBUG_LOG: Logging debug information mechanism (#3279)
* RUBY_DEBUG_LOG: Logging debug information mechanism
This feature provides a mechanism to store logging information
to a file, stderr or memory space with simple macros.
The following information will be stored.
* (1) __FILE__, __LINE__ in C
* (2) __FILE__, __LINE__ in Ruby
* (3) __func__ in C (message title)
* (4) given string with sprintf format
* (5) Thread number (if multiple threads are running)
This feature is enabled only USE_RUBY_DEBUG_LOG is enabled.
Release version should not enable it.
Running with the `RUBY_DEBUG_LOG` environment variable enables
this feature.
# logging into a file
RUBY_DEBUG_LOG=/path/to/file STDERR
# logging into STDERR
RUBY_DEBUG_LOG=stderr
# logging into memory space (check with a debugger)
# It will help if the timing is important.
RUBY_DEBUG_LOG=mem
RUBY_DEBUG_LOG_FILTER environment variable can specify the fileter string.
If "(3) __func__ in C (message title)" contains the specified string, the
infomation will be stored (example: RUBY_DEBUG_LOG_FILTER=str will enable
only on str related information).
In a MRI source code, you can use the following macros:
* RUBY_DEBUG_LOG(fmt, ...): Above (1) to (4) will be logged.
* RUBY_DEBUG_LOG2(file, line, fmt, ...):
Same as RUBY_DEBUG_LOG(), but (1) will be replaced with given file, line.
2020-07-03 10:55:54 +03:00
|
|
|
static struct {
|
|
|
|
char *mem;
|
|
|
|
unsigned int cnt;
|
2022-06-08 10:14:20 +03:00
|
|
|
struct debug_log_filter filters[MAX_DEBUG_LOG_FILTER_NUM];
|
RUBY_DEBUG_LOG: Logging debug information mechanism (#3279)
* RUBY_DEBUG_LOG: Logging debug information mechanism
This feature provides a mechanism to store logging information
to a file, stderr or memory space with simple macros.
The following information will be stored.
* (1) __FILE__, __LINE__ in C
* (2) __FILE__, __LINE__ in Ruby
* (3) __func__ in C (message title)
* (4) given string with sprintf format
* (5) Thread number (if multiple threads are running)
This feature is enabled only USE_RUBY_DEBUG_LOG is enabled.
Release version should not enable it.
Running with the `RUBY_DEBUG_LOG` environment variable enables
this feature.
# logging into a file
RUBY_DEBUG_LOG=/path/to/file STDERR
# logging into STDERR
RUBY_DEBUG_LOG=stderr
# logging into memory space (check with a debugger)
# It will help if the timing is important.
RUBY_DEBUG_LOG=mem
RUBY_DEBUG_LOG_FILTER environment variable can specify the fileter string.
If "(3) __func__ in C (message title)" contains the specified string, the
infomation will be stored (example: RUBY_DEBUG_LOG_FILTER=str will enable
only on str related information).
In a MRI source code, you can use the following macros:
* RUBY_DEBUG_LOG(fmt, ...): Above (1) to (4) will be logged.
* RUBY_DEBUG_LOG2(file, line, fmt, ...):
Same as RUBY_DEBUG_LOG(), but (1) will be replaced with given file, line.
2020-07-03 10:55:54 +03:00
|
|
|
unsigned int filters_num;
|
|
|
|
rb_nativethread_lock_t lock;
|
|
|
|
FILE *output;
|
|
|
|
} debug_log;
|
|
|
|
|
|
|
|
static char *
|
|
|
|
RUBY_DEBUG_LOG_MEM_ENTRY(unsigned int index)
|
|
|
|
{
|
|
|
|
return &debug_log.mem[MAX_DEBUG_LOG_MESSAGE_LEN * index];
|
|
|
|
}
|
|
|
|
|
2022-06-08 10:14:20 +03:00
|
|
|
static enum debug_log_filter_type
|
|
|
|
filter_type(const char *str, int *skiplen)
|
|
|
|
{
|
|
|
|
if (strncmp(str, "file:", 5) == 0) {
|
|
|
|
*skiplen = 5;
|
|
|
|
return dlf_file;
|
|
|
|
}
|
|
|
|
else if(strncmp(str, "func:", 5) == 0) {
|
|
|
|
*skiplen = 5;
|
|
|
|
return dlf_func;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*skiplen = 0;
|
|
|
|
return dlf_all;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
RUBY_DEBUG_LOG: Logging debug information mechanism (#3279)
* RUBY_DEBUG_LOG: Logging debug information mechanism
This feature provides a mechanism to store logging information
to a file, stderr or memory space with simple macros.
The following information will be stored.
* (1) __FILE__, __LINE__ in C
* (2) __FILE__, __LINE__ in Ruby
* (3) __func__ in C (message title)
* (4) given string with sprintf format
* (5) Thread number (if multiple threads are running)
This feature is enabled only USE_RUBY_DEBUG_LOG is enabled.
Release version should not enable it.
Running with the `RUBY_DEBUG_LOG` environment variable enables
this feature.
# logging into a file
RUBY_DEBUG_LOG=/path/to/file STDERR
# logging into STDERR
RUBY_DEBUG_LOG=stderr
# logging into memory space (check with a debugger)
# It will help if the timing is important.
RUBY_DEBUG_LOG=mem
RUBY_DEBUG_LOG_FILTER environment variable can specify the fileter string.
If "(3) __func__ in C (message title)" contains the specified string, the
infomation will be stored (example: RUBY_DEBUG_LOG_FILTER=str will enable
only on str related information).
In a MRI source code, you can use the following macros:
* RUBY_DEBUG_LOG(fmt, ...): Above (1) to (4) will be logged.
* RUBY_DEBUG_LOG2(file, line, fmt, ...):
Same as RUBY_DEBUG_LOG(), but (1) will be replaced with given file, line.
2020-07-03 10:55:54 +03:00
|
|
|
static void
|
2022-06-10 09:40:12 +03:00
|
|
|
setup_debug_log_filter(void)
|
RUBY_DEBUG_LOG: Logging debug information mechanism (#3279)
* RUBY_DEBUG_LOG: Logging debug information mechanism
This feature provides a mechanism to store logging information
to a file, stderr or memory space with simple macros.
The following information will be stored.
* (1) __FILE__, __LINE__ in C
* (2) __FILE__, __LINE__ in Ruby
* (3) __func__ in C (message title)
* (4) given string with sprintf format
* (5) Thread number (if multiple threads are running)
This feature is enabled only USE_RUBY_DEBUG_LOG is enabled.
Release version should not enable it.
Running with the `RUBY_DEBUG_LOG` environment variable enables
this feature.
# logging into a file
RUBY_DEBUG_LOG=/path/to/file STDERR
# logging into STDERR
RUBY_DEBUG_LOG=stderr
# logging into memory space (check with a debugger)
# It will help if the timing is important.
RUBY_DEBUG_LOG=mem
RUBY_DEBUG_LOG_FILTER environment variable can specify the fileter string.
If "(3) __func__ in C (message title)" contains the specified string, the
infomation will be stored (example: RUBY_DEBUG_LOG_FILTER=str will enable
only on str related information).
In a MRI source code, you can use the following macros:
* RUBY_DEBUG_LOG(fmt, ...): Above (1) to (4) will be logged.
* RUBY_DEBUG_LOG2(file, line, fmt, ...):
Same as RUBY_DEBUG_LOG(), but (1) will be replaced with given file, line.
2020-07-03 10:55:54 +03:00
|
|
|
{
|
|
|
|
const char *filter_config = getenv("RUBY_DEBUG_LOG_FILTER");
|
2022-06-10 09:40:12 +03:00
|
|
|
|
2020-08-01 22:24:47 +03:00
|
|
|
if (filter_config && strlen(filter_config) > 0) {
|
|
|
|
unsigned int i;
|
2022-06-08 10:14:20 +03:00
|
|
|
for (i=0; i<MAX_DEBUG_LOG_FILTER_NUM && filter_config; i++) {
|
|
|
|
size_t len;
|
|
|
|
const char *str = filter_config;
|
2020-08-01 22:24:47 +03:00
|
|
|
const char *p;
|
2022-06-08 10:14:20 +03:00
|
|
|
|
|
|
|
if ((p = strchr(str, ',')) == NULL) {
|
|
|
|
len = strlen(str);
|
|
|
|
filter_config = NULL;
|
2020-08-01 22:24:47 +03:00
|
|
|
}
|
|
|
|
else {
|
2022-06-08 10:14:20 +03:00
|
|
|
len = p - str - 1; // 1 is ','
|
|
|
|
filter_config = p + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// positive/negative
|
|
|
|
if (*str == '-') {
|
|
|
|
debug_log.filters[i].negative = true;
|
|
|
|
str++;
|
2022-07-27 12:42:27 +03:00
|
|
|
}
|
|
|
|
else if (*str == '+') {
|
2022-06-08 10:14:20 +03:00
|
|
|
// negative is false on default.
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// type
|
|
|
|
int skiplen;
|
|
|
|
debug_log.filters[i].type = filter_type(str, &skiplen);
|
|
|
|
len -= skiplen;
|
|
|
|
|
|
|
|
if (len >= MAX_DEBUG_LOG_FILTER_LEN) {
|
|
|
|
fprintf(stderr, "too long: %s (max:%d)\n", str, MAX_DEBUG_LOG_FILTER_LEN - 1);
|
|
|
|
exit(1);
|
2020-08-01 22:24:47 +03:00
|
|
|
}
|
2022-06-08 10:14:20 +03:00
|
|
|
|
|
|
|
// body
|
|
|
|
strncpy(debug_log.filters[i].str, str + skiplen, len);
|
|
|
|
debug_log.filters[i].str[len] = 0;
|
2020-08-01 22:24:47 +03:00
|
|
|
}
|
|
|
|
debug_log.filters_num = i;
|
2022-06-08 10:14:20 +03:00
|
|
|
|
2020-08-01 22:24:47 +03:00
|
|
|
for (i=0; i<debug_log.filters_num; i++) {
|
2022-06-08 10:14:20 +03:00
|
|
|
fprintf(stderr, "RUBY_DEBUG_LOG_FILTER[%d]=%s (%s%s)\n", i,
|
|
|
|
debug_log.filters[i].str,
|
|
|
|
debug_log.filters[i].negative ? "-" : "",
|
|
|
|
dlf_type_names[debug_log.filters[i].type]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-10 09:40:12 +03:00
|
|
|
static void
|
|
|
|
setup_debug_log(void)
|
|
|
|
{
|
|
|
|
// check RUBY_DEBUG_LOG
|
|
|
|
const char *log_config = getenv("RUBY_DEBUG_LOG");
|
|
|
|
if (log_config && strlen(log_config) > 0) {
|
|
|
|
if (strcmp(log_config, "mem") == 0) {
|
|
|
|
debug_log.mem = (char *)malloc(MAX_DEBUG_LOG * MAX_DEBUG_LOG_MESSAGE_LEN);
|
|
|
|
if (debug_log.mem == NULL) {
|
|
|
|
fprintf(stderr, "setup_debug_log failed (can't allocate memory)\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
ruby_debug_log_mode |= ruby_debug_log_memory;
|
|
|
|
}
|
|
|
|
else if (strcmp(log_config, "stderr") == 0) {
|
|
|
|
ruby_debug_log_mode |= ruby_debug_log_stderr;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ruby_debug_log_mode |= ruby_debug_log_file;
|
|
|
|
if ((debug_log.output = fopen(log_config, "w")) == NULL) {
|
|
|
|
fprintf(stderr, "can not open %s for RUBY_DEBUG_LOG\n", log_config);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
setvbuf(debug_log.output, NULL, _IONBF, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr, "RUBY_DEBUG_LOG=%s %s%s%s\n", log_config,
|
|
|
|
(ruby_debug_log_mode & ruby_debug_log_memory) ? "[mem]" : "",
|
|
|
|
(ruby_debug_log_mode & ruby_debug_log_stderr) ? "[stderr]" : "",
|
|
|
|
(ruby_debug_log_mode & ruby_debug_log_file) ? "[file]" : "");
|
|
|
|
rb_nativethread_lock_initialize(&debug_log.lock);
|
|
|
|
|
|
|
|
setup_debug_log_filter();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-08 10:14:20 +03:00
|
|
|
static bool
|
|
|
|
check_filter(const char *str, const struct debug_log_filter *filter, bool *state)
|
|
|
|
{
|
|
|
|
if (filter->negative) {
|
|
|
|
if (strstr(str, filter->str) == NULL) {
|
|
|
|
*state = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*state = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (strstr(str, filter->str) != NULL) {
|
|
|
|
*state = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*state = false;
|
|
|
|
return false;
|
2020-08-01 22:24:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
RUBY_DEBUG_LOG: Logging debug information mechanism (#3279)
* RUBY_DEBUG_LOG: Logging debug information mechanism
This feature provides a mechanism to store logging information
to a file, stderr or memory space with simple macros.
The following information will be stored.
* (1) __FILE__, __LINE__ in C
* (2) __FILE__, __LINE__ in Ruby
* (3) __func__ in C (message title)
* (4) given string with sprintf format
* (5) Thread number (if multiple threads are running)
This feature is enabled only USE_RUBY_DEBUG_LOG is enabled.
Release version should not enable it.
Running with the `RUBY_DEBUG_LOG` environment variable enables
this feature.
# logging into a file
RUBY_DEBUG_LOG=/path/to/file STDERR
# logging into STDERR
RUBY_DEBUG_LOG=stderr
# logging into memory space (check with a debugger)
# It will help if the timing is important.
RUBY_DEBUG_LOG=mem
RUBY_DEBUG_LOG_FILTER environment variable can specify the fileter string.
If "(3) __func__ in C (message title)" contains the specified string, the
infomation will be stored (example: RUBY_DEBUG_LOG_FILTER=str will enable
only on str related information).
In a MRI source code, you can use the following macros:
* RUBY_DEBUG_LOG(fmt, ...): Above (1) to (4) will be logged.
* RUBY_DEBUG_LOG2(file, line, fmt, ...):
Same as RUBY_DEBUG_LOG(), but (1) will be replaced with given file, line.
2020-07-03 10:55:54 +03:00
|
|
|
|
2022-05-20 12:00:49 +03:00
|
|
|
//
|
|
|
|
// RUBY_DEBUG_LOG_FILTER=-foo,-bar,baz,boo
|
|
|
|
// returns true if
|
2022-06-08 10:14:20 +03:00
|
|
|
// (func_name or file_name) doesn't contain foo
|
2022-05-20 12:00:49 +03:00
|
|
|
// and
|
2022-06-08 10:14:20 +03:00
|
|
|
// (func_name or file_name) doesn't contain bar
|
2022-05-20 12:00:49 +03:00
|
|
|
// and
|
2022-06-08 10:14:20 +03:00
|
|
|
// (func_name or file_name) contains baz or boo
|
2022-05-20 12:00:49 +03:00
|
|
|
//
|
|
|
|
// RUBY_DEBUG_LOG_FILTER=foo,bar,-baz,-boo
|
2023-02-27 20:56:06 +03:00
|
|
|
// returns true if
|
2022-06-08 10:14:20 +03:00
|
|
|
// (func_name or file_name) contains foo or bar
|
2022-05-20 12:00:49 +03:00
|
|
|
// or
|
2022-06-08 10:14:20 +03:00
|
|
|
// (func_name or file_name) doesn't contain baz and
|
|
|
|
// (func_name or file_name) doesn't contain boo and
|
|
|
|
//
|
|
|
|
// You can specify "file:" (ex file:foo) or "func:" (ex func:foo)
|
|
|
|
// prefixes to specify the filter for.
|
2022-05-20 12:00:49 +03:00
|
|
|
//
|
2020-08-01 22:24:47 +03:00
|
|
|
bool
|
2022-06-08 10:14:20 +03:00
|
|
|
ruby_debug_log_filter(const char *func_name, const char *file_name)
|
2020-08-01 22:24:47 +03:00
|
|
|
{
|
|
|
|
if (debug_log.filters_num > 0) {
|
2022-06-08 10:14:20 +03:00
|
|
|
bool state = false;
|
2022-05-20 12:00:49 +03:00
|
|
|
|
2020-08-01 22:24:47 +03:00
|
|
|
for (unsigned int i = 0; i<debug_log.filters_num; i++) {
|
2022-06-08 10:14:20 +03:00
|
|
|
const struct debug_log_filter *filter = &debug_log.filters[i];
|
|
|
|
|
|
|
|
switch (filter->type) {
|
|
|
|
case dlf_all:
|
|
|
|
if (check_filter(func_name, filter, &state)) return state;
|
|
|
|
if (check_filter(file_name, filter, &state)) return state;
|
|
|
|
break;
|
|
|
|
case dlf_func:
|
|
|
|
if (check_filter(func_name, filter, &state)) return state;
|
|
|
|
break;
|
|
|
|
case dlf_file:
|
|
|
|
if (check_filter(file_name, filter, &state)) return state;
|
|
|
|
break;
|
2020-08-01 22:24:47 +03:00
|
|
|
}
|
|
|
|
}
|
2022-06-08 10:14:20 +03:00
|
|
|
return state;
|
2020-08-01 22:24:47 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return true;
|
RUBY_DEBUG_LOG: Logging debug information mechanism (#3279)
* RUBY_DEBUG_LOG: Logging debug information mechanism
This feature provides a mechanism to store logging information
to a file, stderr or memory space with simple macros.
The following information will be stored.
* (1) __FILE__, __LINE__ in C
* (2) __FILE__, __LINE__ in Ruby
* (3) __func__ in C (message title)
* (4) given string with sprintf format
* (5) Thread number (if multiple threads are running)
This feature is enabled only USE_RUBY_DEBUG_LOG is enabled.
Release version should not enable it.
Running with the `RUBY_DEBUG_LOG` environment variable enables
this feature.
# logging into a file
RUBY_DEBUG_LOG=/path/to/file STDERR
# logging into STDERR
RUBY_DEBUG_LOG=stderr
# logging into memory space (check with a debugger)
# It will help if the timing is important.
RUBY_DEBUG_LOG=mem
RUBY_DEBUG_LOG_FILTER environment variable can specify the fileter string.
If "(3) __func__ in C (message title)" contains the specified string, the
infomation will be stored (example: RUBY_DEBUG_LOG_FILTER=str will enable
only on str related information).
In a MRI source code, you can use the following macros:
* RUBY_DEBUG_LOG(fmt, ...): Above (1) to (4) will be logged.
* RUBY_DEBUG_LOG2(file, line, fmt, ...):
Same as RUBY_DEBUG_LOG(), but (1) will be replaced with given file, line.
2020-07-03 10:55:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
pretty_filename(const char *path)
|
|
|
|
{
|
|
|
|
// basename is one idea.
|
|
|
|
const char *s;
|
|
|
|
while ((s = strchr(path, '/')) != NULL) {
|
|
|
|
path = s+1;
|
|
|
|
}
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2022-08-30 05:21:20 +03:00
|
|
|
#undef ruby_debug_log
|
RUBY_DEBUG_LOG: Logging debug information mechanism (#3279)
* RUBY_DEBUG_LOG: Logging debug information mechanism
This feature provides a mechanism to store logging information
to a file, stderr or memory space with simple macros.
The following information will be stored.
* (1) __FILE__, __LINE__ in C
* (2) __FILE__, __LINE__ in Ruby
* (3) __func__ in C (message title)
* (4) given string with sprintf format
* (5) Thread number (if multiple threads are running)
This feature is enabled only USE_RUBY_DEBUG_LOG is enabled.
Release version should not enable it.
Running with the `RUBY_DEBUG_LOG` environment variable enables
this feature.
# logging into a file
RUBY_DEBUG_LOG=/path/to/file STDERR
# logging into STDERR
RUBY_DEBUG_LOG=stderr
# logging into memory space (check with a debugger)
# It will help if the timing is important.
RUBY_DEBUG_LOG=mem
RUBY_DEBUG_LOG_FILTER environment variable can specify the fileter string.
If "(3) __func__ in C (message title)" contains the specified string, the
infomation will be stored (example: RUBY_DEBUG_LOG_FILTER=str will enable
only on str related information).
In a MRI source code, you can use the following macros:
* RUBY_DEBUG_LOG(fmt, ...): Above (1) to (4) will be logged.
* RUBY_DEBUG_LOG2(file, line, fmt, ...):
Same as RUBY_DEBUG_LOG(), but (1) will be replaced with given file, line.
2020-07-03 10:55:54 +03:00
|
|
|
void
|
|
|
|
ruby_debug_log(const char *file, int line, const char *func_name, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
char buff[MAX_DEBUG_LOG_MESSAGE_LEN] = {0};
|
|
|
|
int len = 0;
|
2020-08-12 03:52:12 +03:00
|
|
|
int r = 0;
|
RUBY_DEBUG_LOG: Logging debug information mechanism (#3279)
* RUBY_DEBUG_LOG: Logging debug information mechanism
This feature provides a mechanism to store logging information
to a file, stderr or memory space with simple macros.
The following information will be stored.
* (1) __FILE__, __LINE__ in C
* (2) __FILE__, __LINE__ in Ruby
* (3) __func__ in C (message title)
* (4) given string with sprintf format
* (5) Thread number (if multiple threads are running)
This feature is enabled only USE_RUBY_DEBUG_LOG is enabled.
Release version should not enable it.
Running with the `RUBY_DEBUG_LOG` environment variable enables
this feature.
# logging into a file
RUBY_DEBUG_LOG=/path/to/file STDERR
# logging into STDERR
RUBY_DEBUG_LOG=stderr
# logging into memory space (check with a debugger)
# It will help if the timing is important.
RUBY_DEBUG_LOG=mem
RUBY_DEBUG_LOG_FILTER environment variable can specify the fileter string.
If "(3) __func__ in C (message title)" contains the specified string, the
infomation will be stored (example: RUBY_DEBUG_LOG_FILTER=str will enable
only on str related information).
In a MRI source code, you can use the following macros:
* RUBY_DEBUG_LOG(fmt, ...): Above (1) to (4) will be logged.
* RUBY_DEBUG_LOG2(file, line, fmt, ...):
Same as RUBY_DEBUG_LOG(), but (1) will be replaced with given file, line.
2020-07-03 10:55:54 +03:00
|
|
|
|
|
|
|
// message title
|
|
|
|
if (func_name && len < MAX_DEBUG_LOG_MESSAGE_LEN) {
|
|
|
|
r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN, "%s\t", func_name);
|
|
|
|
if (r < 0) rb_bug("ruby_debug_log returns %d\n", r);
|
|
|
|
len += r;
|
|
|
|
}
|
|
|
|
|
|
|
|
// message
|
|
|
|
if (fmt && len < MAX_DEBUG_LOG_MESSAGE_LEN) {
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
|
|
r = vsnprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
if (r < 0) rb_bug("ruby_debug_log vsnprintf() returns %d", r);
|
|
|
|
len += r;
|
|
|
|
}
|
|
|
|
|
|
|
|
// optional information
|
|
|
|
|
|
|
|
// C location
|
|
|
|
if (file && len < MAX_DEBUG_LOG_MESSAGE_LEN) {
|
|
|
|
r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN, "\t%s:%d", pretty_filename(file), line);
|
|
|
|
if (r < 0) rb_bug("ruby_debug_log returns %d\n", r);
|
|
|
|
len += r;
|
|
|
|
}
|
|
|
|
|
2022-05-20 09:47:20 +03:00
|
|
|
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");
|
|
|
|
}
|
RUBY_DEBUG_LOG: Logging debug information mechanism (#3279)
* RUBY_DEBUG_LOG: Logging debug information mechanism
This feature provides a mechanism to store logging information
to a file, stderr or memory space with simple macros.
The following information will be stored.
* (1) __FILE__, __LINE__ in C
* (2) __FILE__, __LINE__ in Ruby
* (3) __func__ in C (message title)
* (4) given string with sprintf format
* (5) Thread number (if multiple threads are running)
This feature is enabled only USE_RUBY_DEBUG_LOG is enabled.
Release version should not enable it.
Running with the `RUBY_DEBUG_LOG` environment variable enables
this feature.
# logging into a file
RUBY_DEBUG_LOG=/path/to/file STDERR
# logging into STDERR
RUBY_DEBUG_LOG=stderr
# logging into memory space (check with a debugger)
# It will help if the timing is important.
RUBY_DEBUG_LOG=mem
RUBY_DEBUG_LOG_FILTER environment variable can specify the fileter string.
If "(3) __func__ in C (message title)" contains the specified string, the
infomation will be stored (example: RUBY_DEBUG_LOG_FILTER=str will enable
only on str related information).
In a MRI source code, you can use the following macros:
* RUBY_DEBUG_LOG(fmt, ...): Above (1) to (4) will be logged.
* RUBY_DEBUG_LOG2(file, line, fmt, ...):
Same as RUBY_DEBUG_LOG(), but (1) will be replaced with given file, line.
2020-07-03 10:55:54 +03:00
|
|
|
if (r < 0) rb_bug("ruby_debug_log returns %d\n", r);
|
|
|
|
len += r;
|
|
|
|
}
|
|
|
|
|
2022-05-20 09:47:20 +03:00
|
|
|
// 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
|
RUBY_DEBUG_LOG: Logging debug information mechanism (#3279)
* RUBY_DEBUG_LOG: Logging debug information mechanism
This feature provides a mechanism to store logging information
to a file, stderr or memory space with simple macros.
The following information will be stored.
* (1) __FILE__, __LINE__ in C
* (2) __FILE__, __LINE__ in Ruby
* (3) __func__ in C (message title)
* (4) given string with sprintf format
* (5) Thread number (if multiple threads are running)
This feature is enabled only USE_RUBY_DEBUG_LOG is enabled.
Release version should not enable it.
Running with the `RUBY_DEBUG_LOG` environment variable enables
this feature.
# logging into a file
RUBY_DEBUG_LOG=/path/to/file STDERR
# logging into STDERR
RUBY_DEBUG_LOG=stderr
# logging into memory space (check with a debugger)
# It will help if the timing is important.
RUBY_DEBUG_LOG=mem
RUBY_DEBUG_LOG_FILTER environment variable can specify the fileter string.
If "(3) __func__ in C (message title)" contains the specified string, the
infomation will be stored (example: RUBY_DEBUG_LOG_FILTER=str will enable
only on str related information).
In a MRI source code, you can use the following macros:
* RUBY_DEBUG_LOG(fmt, ...): Above (1) to (4) will be logged.
* RUBY_DEBUG_LOG2(file, line, fmt, ...):
Same as RUBY_DEBUG_LOG(), but (1) will be replaced with given file, line.
2020-07-03 10:55:54 +03:00
|
|
|
const rb_thread_t *th = GET_THREAD();
|
|
|
|
if (r && len < MAX_DEBUG_LOG_MESSAGE_LEN) {
|
2022-05-23 21:57:06 +03:00
|
|
|
r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\tth:%u", rb_th_serial(th));
|
RUBY_DEBUG_LOG: Logging debug information mechanism (#3279)
* RUBY_DEBUG_LOG: Logging debug information mechanism
This feature provides a mechanism to store logging information
to a file, stderr or memory space with simple macros.
The following information will be stored.
* (1) __FILE__, __LINE__ in C
* (2) __FILE__, __LINE__ in Ruby
* (3) __func__ in C (message title)
* (4) given string with sprintf format
* (5) Thread number (if multiple threads are running)
This feature is enabled only USE_RUBY_DEBUG_LOG is enabled.
Release version should not enable it.
Running with the `RUBY_DEBUG_LOG` environment variable enables
this feature.
# logging into a file
RUBY_DEBUG_LOG=/path/to/file STDERR
# logging into STDERR
RUBY_DEBUG_LOG=stderr
# logging into memory space (check with a debugger)
# It will help if the timing is important.
RUBY_DEBUG_LOG=mem
RUBY_DEBUG_LOG_FILTER environment variable can specify the fileter string.
If "(3) __func__ in C (message title)" contains the specified string, the
infomation will be stored (example: RUBY_DEBUG_LOG_FILTER=str will enable
only on str related information).
In a MRI source code, you can use the following macros:
* RUBY_DEBUG_LOG(fmt, ...): Above (1) to (4) will be logged.
* RUBY_DEBUG_LOG2(file, line, fmt, ...):
Same as RUBY_DEBUG_LOG(), but (1) will be replaced with given file, line.
2020-07-03 10:55:54 +03:00
|
|
|
if (r < 0) rb_bug("ruby_debug_log returns %d\n", r);
|
|
|
|
len += r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_nativethread_lock_lock(&debug_log.lock);
|
|
|
|
{
|
|
|
|
unsigned int cnt = debug_log.cnt++;
|
|
|
|
|
|
|
|
if (ruby_debug_log_mode & ruby_debug_log_memory) {
|
|
|
|
unsigned int index = cnt % MAX_DEBUG_LOG;
|
|
|
|
char *dst = RUBY_DEBUG_LOG_MEM_ENTRY(index);
|
|
|
|
strncpy(dst, buff, MAX_DEBUG_LOG_MESSAGE_LEN);
|
|
|
|
}
|
|
|
|
if (ruby_debug_log_mode & ruby_debug_log_stderr) {
|
|
|
|
fprintf(stderr, "%4u: %s\n", cnt, buff);
|
|
|
|
}
|
|
|
|
if (ruby_debug_log_mode & ruby_debug_log_file) {
|
|
|
|
fprintf(debug_log.output, "%u\t%s\n", cnt, buff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rb_nativethread_lock_unlock(&debug_log.lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
// for debugger
|
|
|
|
static void
|
|
|
|
debug_log_dump(FILE *out, unsigned int n)
|
|
|
|
{
|
|
|
|
if (ruby_debug_log_mode & ruby_debug_log_memory) {
|
|
|
|
unsigned int size = debug_log.cnt > MAX_DEBUG_LOG ? MAX_DEBUG_LOG : debug_log.cnt;
|
|
|
|
unsigned int current_index = debug_log.cnt % MAX_DEBUG_LOG;
|
|
|
|
if (n == 0) n = size;
|
|
|
|
if (n > size) n = size;
|
|
|
|
|
|
|
|
for (unsigned int i=0; i<n; i++) {
|
|
|
|
int index = current_index - size + i;
|
|
|
|
if (index < 0) index += MAX_DEBUG_LOG;
|
|
|
|
VM_ASSERT(index <= MAX_DEBUG_LOG);
|
|
|
|
const char *mesg = RUBY_DEBUG_LOG_MEM_ENTRY(index);;
|
|
|
|
fprintf(out, "%4u: %s\n", debug_log.cnt - size + i, mesg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "RUBY_DEBUG_LOG=mem is not specified.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// for debuggers
|
|
|
|
|
|
|
|
void
|
|
|
|
ruby_debug_log_print(unsigned int n)
|
|
|
|
{
|
|
|
|
debug_log_dump(stderr, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ruby_debug_log_dump(const char *fname, unsigned int n)
|
|
|
|
{
|
|
|
|
FILE *fp = fopen(fname, "w");
|
|
|
|
if (fp == NULL) {
|
|
|
|
fprintf(stderr, "can't open %s. give up.\n", fname);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
debug_log_dump(fp, n);
|
|
|
|
fclose(fp);
|
|
|
|
}
|
2007-06-29 11:57:24 +04:00
|
|
|
}
|
2021-12-28 11:58:39 +03:00
|
|
|
#endif // #if USE_RUBY_DEBUG_LOG
|