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
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
2007-06-10 07:06:15 +04:00
|
|
|
#include "ruby/ruby.h"
|
2007-10-16 13:21:11 +04:00
|
|
|
#include "ruby/encoding.h"
|
2008-02-24 00:13:05 +03:00
|
|
|
#include "ruby/util.h"
|
2012-11-20 16:57:49 +04:00
|
|
|
#include "vm_debug.h"
|
2008-05-08 10:56:59 +04:00
|
|
|
#include "eval_intern.h"
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 08:25:46 +04:00
|
|
|
#include "vm_core.h"
|
2009-05-21 17:17:54 +04:00
|
|
|
#include "id.h"
|
2006-12-31 18:02:22 +03:00
|
|
|
|
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;
|
|
|
|
enum ruby_encoding_consts encoding_consts;
|
|
|
|
enum ruby_coderange_type enc_coderange_types;
|
|
|
|
enum ruby_econv_flag_type econv_flag_types;
|
2007-10-16 13:21:11 +04:00
|
|
|
enum {
|
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;
|
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
|
|
|
}
|
|
|
|
|
2016-07-25 11:00:46 +03:00
|
|
|
#include "gc.h"
|
|
|
|
|
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
|
|
|
|
UINT ruby_w32_codepage;
|
|
|
|
#endif
|
|
|
|
|
2008-02-24 00:13:05 +03:00
|
|
|
static void
|
|
|
|
set_debug_option(const char *str, int len, void *arg)
|
2007-06-29 11:57:24 +04:00
|
|
|
{
|
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); \
|
2008-02-24 00:13:05 +03:00
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2017-03-31 03:35:02 +03:00
|
|
|
#define NAME_MATCH_VALUE(name) \
|
|
|
|
((size_t)len > sizeof(name) && \
|
|
|
|
strncmp(str, (name), sizeof(name)-1) == 0 && \
|
|
|
|
str[sizeof(name)-1] == '=' && \
|
|
|
|
(str += sizeof(name), len -= sizeof(name), 1))
|
|
|
|
|
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);
|
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-03-31 10:34:46 +03:00
|
|
|
{
|
2017-03-31 03:35:02 +03:00
|
|
|
int ov;
|
|
|
|
size_t retlen;
|
2017-03-31 10:34:46 +03:00
|
|
|
unsigned long n;
|
|
|
|
if (NAME_MATCH_VALUE("codepage") &&
|
|
|
|
(n = ruby_scan_digits(str, len, 10, &retlen, &ov),
|
|
|
|
(size_t)len == retlen && !ov)) {
|
|
|
|
ruby_w32_codepage = (UINT)n;
|
|
|
|
}
|
2017-03-31 03:35:02 +03:00
|
|
|
return;
|
|
|
|
}
|
2009-02-16 10:46:24 +03:00
|
|
|
#endif
|
2008-02-24 00:13:05 +03:00
|
|
|
fprintf(stderr, "unexpected debug option: %.*s\n", len, str);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ruby_set_debug_option(const char *str)
|
|
|
|
{
|
|
|
|
ruby_each_words(str, set_debug_option, 0);
|
2007-06-29 11:57:24 +04:00
|
|
|
}
|