2006-12-31 10:02:22 -05: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-13 17:13:04 -05:00
|
|
|
Copyright (C) 2004-2007 Koichi Sasada
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
2020-04-08 00:28:13 -04:00
|
|
|
#include "ruby/3/config.h"
|
2019-12-04 03:16:30 -05:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "eval_intern.h"
|
|
|
|
#include "id.h"
|
|
|
|
#include "internal/signal.h"
|
|
|
|
#include "internal/util.h"
|
2007-10-16 05:21:11 -04:00
|
|
|
#include "ruby/encoding.h"
|
2018-01-09 01:24:10 -05:00
|
|
|
#include "ruby/io.h"
|
2019-12-04 03:16:30 -05:00
|
|
|
#include "ruby/ruby.h"
|
2008-02-23 16:13:05 -05:00
|
|
|
#include "ruby/util.h"
|
2017-10-24 20:33:29 -04:00
|
|
|
#include "symbol.h"
|
2019-12-04 03:16:30 -05: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-07 18:20:36 -05:00
|
|
|
#include "vm_callinfo.h"
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2019-12-03 00:42:53 -05: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 05:21:11 -04:00
|
|
|
/* for gdb */
|
2009-08-05 05:46:07 -04:00
|
|
|
const union {
|
2007-10-16 05:21:11 -04:00
|
|
|
enum ruby_special_consts special_consts;
|
|
|
|
enum ruby_value_type value_type;
|
2008-05-08 02:56:59 -04:00
|
|
|
enum ruby_tag_type tag_type;
|
2007-10-16 05:21:11 -04:00
|
|
|
enum node_type node_type;
|
2009-05-21 09:17:54 -04:00
|
|
|
enum ruby_method_ids method_ids;
|
2013-09-20 00:53:08 -04:00
|
|
|
enum ruby_id_types id_types;
|
2015-09-12 22:03:31 -04:00
|
|
|
enum ruby_fl_type fl_types;
|
2020-04-18 03:35:20 -04:00
|
|
|
enum ruby_fl_ushift fl_ushift;
|
2015-09-12 22:03:31 -04:00
|
|
|
enum ruby_encoding_consts encoding_consts;
|
|
|
|
enum ruby_coderange_type enc_coderange_types;
|
|
|
|
enum ruby_econv_flag_type econv_flag_types;
|
2017-06-01 00:43:03 -04:00
|
|
|
enum ruby_robject_flags robject_flags;
|
|
|
|
enum ruby_rmodule_flags rmodule_flags;
|
|
|
|
enum ruby_rstring_flags rstring_flags;
|
|
|
|
enum ruby_rarray_flags rarray_flags;
|
2007-10-16 05:21:11 -04:00
|
|
|
enum {
|
2017-07-05 02:32:54 -04: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 05:29:32 -04:00
|
|
|
RUBY_NODE_TYPESHIFT = NODE_TYPESHIFT,
|
|
|
|
RUBY_NODE_TYPEMASK = NODE_TYPEMASK,
|
|
|
|
RUBY_NODE_LSHIFT = NODE_LSHIFT,
|
2008-07-01 04:27:58 -04:00
|
|
|
RUBY_NODE_FL_NEWLINE = NODE_FL_NEWLINE
|
2007-10-16 05:21:11 -04:00
|
|
|
} various;
|
2017-11-22 22:14:12 -05:00
|
|
|
union {
|
|
|
|
enum imemo_type types;
|
|
|
|
enum {RUBY_IMEMO_MASK = IMEMO_MASK} mask;
|
|
|
|
struct RIMemo *ptr;
|
|
|
|
} imemo;
|
2017-10-24 20:33:29 -04:00
|
|
|
struct RSymbol *symbol_ptr;
|
2017-11-02 03:52:48 -04:00
|
|
|
enum vm_call_flag_bits vm_call_flags;
|
2009-08-05 05:46:07 -04:00
|
|
|
} ruby_dummy_gdb_enums;
|
2007-10-16 05:21:11 -04:00
|
|
|
|
2010-05-05 00:31:48 -04:00
|
|
|
const SIGNED_VALUE RUBY_NODE_LMASK = NODE_LMASK;
|
2007-10-16 05:21:11 -04:00
|
|
|
|
2008-04-14 01:34:04 -04:00
|
|
|
int
|
2007-06-24 13:19:22 -04:00
|
|
|
ruby_debug_print_indent(int level, int debug_level, int indent_level)
|
2006-12-31 10:02:22 -05:00
|
|
|
{
|
|
|
|
if (level < debug_level) {
|
2008-02-23 14:03:32 -05:00
|
|
|
fprintf(stderr, "%*s", indent_level, "");
|
2006-12-31 10:02:22 -05:00
|
|
|
fflush(stderr);
|
2009-09-14 03:39:16 -04:00
|
|
|
return TRUE;
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
2009-09-14 03:39:16 -04:00
|
|
|
return FALSE;
|
2008-04-14 01: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 10:02:22 -05:00
|
|
|
}
|
|
|
|
|
2016-07-25 04:00:46 -04:00
|
|
|
#include "gc.h"
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
VALUE
|
2007-06-29 03:57:24 -04:00
|
|
|
ruby_debug_print_value(int level, int debug_level, const char *header, VALUE obj)
|
2006-12-31 10:02:22 -05:00
|
|
|
{
|
|
|
|
if (level < debug_level) {
|
2016-07-25 04:00:46 -04:00
|
|
|
char buff[0x100];
|
|
|
|
rb_raw_obj_info(buff, 0x100, obj);
|
|
|
|
|
|
|
|
fprintf(stderr, "DBG> %s: %s\n", header, buff);
|
2006-12-31 10:02:22 -05:00
|
|
|
fflush(stderr);
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-06-24 13:19:22 -04:00
|
|
|
ruby_debug_print_v(VALUE v)
|
2006-12-31 10:02:22 -05:00
|
|
|
{
|
2007-06-24 13:19:22 -04:00
|
|
|
ruby_debug_print_value(0, 1, "", v);
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ID
|
2007-06-29 03:57:24 -04:00
|
|
|
ruby_debug_print_id(int level, int debug_level, const char *header, ID id)
|
2006-12-31 10:02:22 -05:00
|
|
|
{
|
|
|
|
if (level < debug_level) {
|
2015-05-23 12:36:26 -04:00
|
|
|
fprintf(stderr, "DBG> %s: %s\n", header, rb_id2name(id));
|
2006-12-31 10:02:22 -05: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 07:15:15 -04:00
|
|
|
NODE *
|
2007-06-29 03: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 07:15:15 -04:00
|
|
|
{
|
|
|
|
if (level < debug_level) {
|
2009-09-14 03:39:16 -04:00
|
|
|
fprintf(stderr, "DBG> %s: %s (%u)\n", header,
|
2007-05-17 00: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 07:15:15 -04:00
|
|
|
}
|
2007-06-29 03: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 07:15:15 -04:00
|
|
|
}
|
|
|
|
|
2006-12-31 10:02:22 -05: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-06 20:25:05 -05:00
|
|
|
ruby_debug_breakpoint(void)
|
2006-12-31 10:02:22 -05:00
|
|
|
{
|
|
|
|
/* */
|
|
|
|
}
|
2007-06-29 03:57:24 -04:00
|
|
|
|
2017-03-30 20:35:02 -04:00
|
|
|
#if defined _WIN32
|
|
|
|
# if RUBY_MSVCRT_VERSION >= 80
|
|
|
|
extern int ruby_w32_rtc_error;
|
|
|
|
# endif
|
2017-05-15 20:15:54 -04:00
|
|
|
#endif
|
|
|
|
#if defined _WIN32 || defined __CYGWIN__
|
|
|
|
#include <windows.h>
|
2017-06-05 23:45:02 -04:00
|
|
|
UINT ruby_w32_codepage[2];
|
2017-03-30 20:35:02 -04:00
|
|
|
#endif
|
2017-06-19 10:36:18 -04:00
|
|
|
extern int ruby_rgengc_debug;
|
2019-12-05 00:39:03 -05:00
|
|
|
extern int ruby_on_ci;
|
2017-03-30 20:35:02 -04:00
|
|
|
|
2017-06-20 22:44:23 -04:00
|
|
|
int
|
|
|
|
ruby_env_debug_option(const char *str, int len, void *arg)
|
2007-06-29 03:57:24 -04:00
|
|
|
{
|
2017-06-19 10:36:18 -04:00
|
|
|
int ov;
|
|
|
|
size_t retlen;
|
|
|
|
unsigned long n;
|
2014-11-18 09:58:03 -05:00
|
|
|
#define SET_WHEN(name, var, val) do { \
|
2007-06-29 03:57:24 -04:00
|
|
|
if (len == sizeof(name) - 1 && \
|
2010-12-07 07:16:10 -05:00
|
|
|
strncmp(str, (name), len) == 0) { \
|
2014-11-18 09:58:03 -05:00
|
|
|
(var) = (val); \
|
2017-06-20 22:44:23 -04:00
|
|
|
return 1; \
|
2008-02-23 16:13:05 -05:00
|
|
|
} \
|
|
|
|
} while (0)
|
2017-06-19 10:36:18 -04: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-30 20:35:02 -04:00
|
|
|
|
2014-11-18 09:58:03 -05:00
|
|
|
SET_WHEN("gc_stress", *ruby_initial_gc_stress_ptr, Qtrue);
|
|
|
|
SET_WHEN("core", ruby_enable_coredump, 1);
|
2019-12-05 00:39:03 -05:00
|
|
|
SET_WHEN("ci", ruby_on_ci, 1);
|
2017-06-19 10:36:18 -04:00
|
|
|
if (NAME_MATCH_VALUE("rgengc")) {
|
|
|
|
if (!len) ruby_rgengc_debug = 1;
|
|
|
|
else SET_UINT_LIST("rgengc", &ruby_rgengc_debug, 1);
|
2017-06-20 22:44:23 -04:00
|
|
|
return 1;
|
2017-06-19 10:36:18 -04:00
|
|
|
}
|
2017-03-30 20:35:02 -04:00
|
|
|
#if defined _WIN32
|
|
|
|
# if RUBY_MSVCRT_VERSION >= 80
|
2014-11-18 09:58:03 -05:00
|
|
|
SET_WHEN("rtc_error", ruby_w32_rtc_error, 1);
|
2017-03-30 20:35:02 -04:00
|
|
|
# endif
|
2017-05-15 20:15:54 -04:00
|
|
|
#endif
|
|
|
|
#if defined _WIN32 || defined __CYGWIN__
|
2017-06-05 23:45:02 -04:00
|
|
|
if (NAME_MATCH_VALUE("codepage")) {
|
2017-06-19 10:36:18 -04:00
|
|
|
if (!len) fprintf(stderr, "missing codepage argument");
|
|
|
|
else SET_UINT_LIST("codepage", ruby_w32_codepage, numberof(ruby_w32_codepage));
|
2017-06-20 22:44:23 -04:00
|
|
|
return 1;
|
2017-03-30 20:35:02 -04:00
|
|
|
}
|
2009-02-16 02:46:24 -05:00
|
|
|
#endif
|
2017-06-20 22:44:23 -04: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-23 16:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ruby_set_debug_option(const char *str)
|
|
|
|
{
|
|
|
|
ruby_each_words(str, set_debug_option, 0);
|
2007-06-29 03:57:24 -04:00
|
|
|
}
|