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
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
2007-06-09 23:06:15 -04:00
|
|
|
#include "ruby/ruby.h"
|
2007-10-16 05:21:11 -04:00
|
|
|
#include "ruby/encoding.h"
|
2008-02-23 16:13:05 -05:00
|
|
|
#include "ruby/util.h"
|
2012-11-20 07:57:49 -05:00
|
|
|
#include "vm_debug.h"
|
2008-05-08 02: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 00:25:46 -04:00
|
|
|
#include "vm_core.h"
|
2009-05-21 09:17:54 -04:00
|
|
|
#include "id.h"
|
2006-12-31 10:02:22 -05:00
|
|
|
|
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;
|
|
|
|
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 {
|
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;
|
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
|
|
|
|
|
2008-02-23 16:13:05 -05:00
|
|
|
static void
|
|
|
|
set_debug_option(const char *str, int len, void *arg)
|
2007-06-29 03:57:24 -04:00
|
|
|
{
|
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); \
|
2008-02-23 16:13:05 -05:00
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2017-03-30 20:35:02 -04:00
|
|
|
#define NAME_MATCH_VALUE(name) \
|
2017-06-05 23:45:02 -04:00
|
|
|
((size_t)len >= sizeof(name) && \
|
2017-03-30 20:35:02 -04:00
|
|
|
strncmp(str, (name), sizeof(name)-1) == 0 && \
|
|
|
|
str[sizeof(name)-1] == '=' && \
|
|
|
|
(str += sizeof(name), len -= sizeof(name), 1))
|
|
|
|
|
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);
|
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")) {
|
|
|
|
int i;
|
2017-03-30 20:35:02 -04:00
|
|
|
int ov;
|
|
|
|
size_t retlen;
|
2017-03-31 03:34:46 -04:00
|
|
|
unsigned long n;
|
2017-06-05 23:45:02 -04:00
|
|
|
for (i = 0; i < numberof(ruby_w32_codepage); ++i) {
|
|
|
|
n = ruby_scan_digits(str, len, 10, &retlen, &ov);
|
|
|
|
if (!ov && retlen) {
|
|
|
|
ruby_w32_codepage[i] = (UINT)n;
|
|
|
|
}
|
|
|
|
if ((size_t)len <= retlen) break;
|
|
|
|
str += retlen;
|
|
|
|
len -= retlen;
|
|
|
|
if (*str != ':') break;
|
|
|
|
++str;
|
|
|
|
--len;
|
|
|
|
}
|
|
|
|
if (len > 0) {
|
|
|
|
fprintf(stderr, "ignored codepage option: `%.*s'\n", len, str);
|
2017-03-31 03:34:46 -04:00
|
|
|
}
|
2017-03-30 20:35:02 -04:00
|
|
|
return;
|
|
|
|
}
|
2009-02-16 02:46:24 -05:00
|
|
|
#endif
|
2008-02-23 16:13:05 -05: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 03:57:24 -04:00
|
|
|
}
|