2006-12-31 18:02:22 +03:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
vm_dump.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
|
* 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"
|
2010-11-26 06:28:50 +03:00
|
|
|
#include "addr2line.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"
|
2012-06-02 19:59:37 +04:00
|
|
|
#include "internal.h"
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2011-07-27 06:04:51 +04:00
|
|
|
/* see vm_insnhelper.h for the values */
|
|
|
|
#ifndef VMDEBUG
|
|
|
|
#define VMDEBUG 0
|
|
|
|
#endif
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
#define MAX_POSBUF 128
|
|
|
|
|
* common.mk: clean up
- remove blockinlining.$(OBJEXT) to built
- make ENCODING_H_INCLDUES variable (include/ruby/encoding.h)
- make VM_CORE_H_INCLUDES variable (vm_core.h)
- simplify rules.
- make depends rule to output depend status using gcc -MM.
* include/ruby/mvm.h, include/ruby/vm.h: rename mvm.h to vm.h.
* include/ruby.h: ditto.
* load.c: add inclusion explicitly.
* enumerator.c, object.c, parse.y, thread.c, vm_dump.c:
remove useless inclusion.
* eval_intern.h: cleanup inclusion.
* vm_core.h: rb_thread_t should be defined in this file.
* vm_evalbody.c, vm_exec.c: rename vm_evalbody.c to vm_exec.c.
* vm.h, vm_exec.h: rename vm.h to vm_exec.h.
* insnhelper.h, vm_insnhelper.h: rename insnhelper.h to vm_insnhelper.h.
* vm.c, vm_insnhelper.c, vm_insnhelper.h:
- rename vm_eval() to vm_exec_core().
- rename vm_eval_body() to vm_exec().
- cleanup include order.
* vm_method.c: fix comment.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 04:20:28 +04:00
|
|
|
#define VM_CFP_CNT(th, cfp) \
|
2011-01-12 13:37:32 +03:00
|
|
|
((rb_control_frame_t *)((th)->stack + (th)->stack_size) - (rb_control_frame_t *)(cfp))
|
* common.mk: clean up
- remove blockinlining.$(OBJEXT) to built
- make ENCODING_H_INCLDUES variable (include/ruby/encoding.h)
- make VM_CORE_H_INCLUDES variable (vm_core.h)
- simplify rules.
- make depends rule to output depend status using gcc -MM.
* include/ruby/mvm.h, include/ruby/vm.h: rename mvm.h to vm.h.
* include/ruby.h: ditto.
* load.c: add inclusion explicitly.
* enumerator.c, object.c, parse.y, thread.c, vm_dump.c:
remove useless inclusion.
* eval_intern.h: cleanup inclusion.
* vm_core.h: rb_thread_t should be defined in this file.
* vm_evalbody.c, vm_exec.c: rename vm_evalbody.c to vm_exec.c.
* vm.h, vm_exec.h: rename vm.h to vm_exec.h.
* insnhelper.h, vm_insnhelper.h: rename insnhelper.h to vm_insnhelper.h.
* vm.c, vm_insnhelper.c, vm_insnhelper.h:
- rename vm_eval() to vm_exec_core().
- rename vm_eval_body() to vm_exec().
- cleanup include order.
* vm_method.c: fix comment.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 04:20:28 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static void
|
* blockinlining.c, error.c, eval.c, eval_error.h, eval_intern.h,
eval_jump.h, eval_load.c, eval_safe.h, gc.c, proc.c, signal.c,
thread.c, thread_pthread.ci, thread_win32.ci, vm.c, vm.h,
vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fix typo (rb_thead_t -> rb_thread_t).
* eval_intern.h: remove unused definitions.
* common.mk: fix around vm_opts.h path
and remove harmful argument passed to insns2vm.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-08 09:37:46 +03:00
|
|
|
control_frame_dump(rb_thread_t *th, rb_control_frame_t *cfp)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2012-09-28 08:05:36 +04:00
|
|
|
ptrdiff_t pc = -1;
|
2012-06-11 07:14:59 +04:00
|
|
|
ptrdiff_t ep = cfp->ep - th->stack;
|
|
|
|
char ep_in_heap = ' ';
|
2006-12-31 18:02:22 +03:00
|
|
|
char posbuf[MAX_POSBUF+1];
|
* compile.c, cont.c, gc.c, insns.def, iseq.c, iseq.h, process.c,
thread.c, vm.c, vm_core.h, vm_dump.c, vm_eval.c,
vm_insnhelper.c, vm_method.c, template/insns_info.inc.tmpl,
tool/instruction.rb: fixed types.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-09-22 00:58:26 +04:00
|
|
|
int line = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
const char *magic, *iseq_name = "-", *selfstr = "-", *biseq_name = "-";
|
|
|
|
VALUE tmp;
|
|
|
|
|
|
|
|
if (cfp->block_iseq != 0 && BUILTIN_TYPE(cfp->block_iseq) != T_NODE) {
|
2012-06-04 06:49:37 +04:00
|
|
|
biseq_name = ""; /* RSTRING(cfp->block_iseq->location.label)->ptr; */
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2012-06-11 07:14:59 +04:00
|
|
|
if (ep < 0 || (size_t)ep > th->stack_size) {
|
|
|
|
ep = (ptrdiff_t)cfp->ep;
|
|
|
|
ep_in_heap = 'p';
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2007-07-05 14:49:45 +04:00
|
|
|
switch (VM_FRAME_TYPE(cfp)) {
|
* vm.c, eval_intern.h (PASS_PASSED_BLOCK):
set a VM_FRAME_FLAG_PASSED flag to skip this frame when
searching ruby-level-cfp.
* eval.c, eval_intern.h, proc.c: fix to check cfp. if there is
no valid ruby-level-cfp, cause RuntimeError exception.
[ruby-dev:34128]
* vm_core.h, vm_evalbody.c, vm.c, vm_dump.c, vm_insnhelper.c,
insns.def: rename FRAME_MAGIC_* to VM_FRAME_MAGIC_*.
* KNOWNBUGS.rb, bootstraptest/test*.rb: move solved bugs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17084 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-11 01:46:43 +04:00
|
|
|
case VM_FRAME_MAGIC_TOP:
|
2006-12-31 18:02:22 +03:00
|
|
|
magic = "TOP";
|
|
|
|
break;
|
* vm.c, eval_intern.h (PASS_PASSED_BLOCK):
set a VM_FRAME_FLAG_PASSED flag to skip this frame when
searching ruby-level-cfp.
* eval.c, eval_intern.h, proc.c: fix to check cfp. if there is
no valid ruby-level-cfp, cause RuntimeError exception.
[ruby-dev:34128]
* vm_core.h, vm_evalbody.c, vm.c, vm_dump.c, vm_insnhelper.c,
insns.def: rename FRAME_MAGIC_* to VM_FRAME_MAGIC_*.
* KNOWNBUGS.rb, bootstraptest/test*.rb: move solved bugs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17084 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-11 01:46:43 +04:00
|
|
|
case VM_FRAME_MAGIC_METHOD:
|
2006-12-31 18:02:22 +03:00
|
|
|
magic = "METHOD";
|
|
|
|
break;
|
* vm.c, eval_intern.h (PASS_PASSED_BLOCK):
set a VM_FRAME_FLAG_PASSED flag to skip this frame when
searching ruby-level-cfp.
* eval.c, eval_intern.h, proc.c: fix to check cfp. if there is
no valid ruby-level-cfp, cause RuntimeError exception.
[ruby-dev:34128]
* vm_core.h, vm_evalbody.c, vm.c, vm_dump.c, vm_insnhelper.c,
insns.def: rename FRAME_MAGIC_* to VM_FRAME_MAGIC_*.
* KNOWNBUGS.rb, bootstraptest/test*.rb: move solved bugs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17084 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-11 01:46:43 +04:00
|
|
|
case VM_FRAME_MAGIC_CLASS:
|
2006-12-31 18:02:22 +03:00
|
|
|
magic = "CLASS";
|
|
|
|
break;
|
* vm.c, eval_intern.h (PASS_PASSED_BLOCK):
set a VM_FRAME_FLAG_PASSED flag to skip this frame when
searching ruby-level-cfp.
* eval.c, eval_intern.h, proc.c: fix to check cfp. if there is
no valid ruby-level-cfp, cause RuntimeError exception.
[ruby-dev:34128]
* vm_core.h, vm_evalbody.c, vm.c, vm_dump.c, vm_insnhelper.c,
insns.def: rename FRAME_MAGIC_* to VM_FRAME_MAGIC_*.
* KNOWNBUGS.rb, bootstraptest/test*.rb: move solved bugs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17084 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-11 01:46:43 +04:00
|
|
|
case VM_FRAME_MAGIC_BLOCK:
|
2006-12-31 18:02:22 +03:00
|
|
|
magic = "BLOCK";
|
|
|
|
break;
|
* vm.c, eval_intern.h (PASS_PASSED_BLOCK):
set a VM_FRAME_FLAG_PASSED flag to skip this frame when
searching ruby-level-cfp.
* eval.c, eval_intern.h, proc.c: fix to check cfp. if there is
no valid ruby-level-cfp, cause RuntimeError exception.
[ruby-dev:34128]
* vm_core.h, vm_evalbody.c, vm.c, vm_dump.c, vm_insnhelper.c,
insns.def: rename FRAME_MAGIC_* to VM_FRAME_MAGIC_*.
* KNOWNBUGS.rb, bootstraptest/test*.rb: move solved bugs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17084 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-11 01:46:43 +04:00
|
|
|
case VM_FRAME_MAGIC_CFUNC:
|
2006-12-31 18:02:22 +03:00
|
|
|
magic = "CFUNC";
|
|
|
|
break;
|
* vm.c, eval_intern.h (PASS_PASSED_BLOCK):
set a VM_FRAME_FLAG_PASSED flag to skip this frame when
searching ruby-level-cfp.
* eval.c, eval_intern.h, proc.c: fix to check cfp. if there is
no valid ruby-level-cfp, cause RuntimeError exception.
[ruby-dev:34128]
* vm_core.h, vm_evalbody.c, vm.c, vm_dump.c, vm_insnhelper.c,
insns.def: rename FRAME_MAGIC_* to VM_FRAME_MAGIC_*.
* KNOWNBUGS.rb, bootstraptest/test*.rb: move solved bugs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17084 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-11 01:46:43 +04:00
|
|
|
case VM_FRAME_MAGIC_PROC:
|
2006-12-31 18:02:22 +03:00
|
|
|
magic = "PROC";
|
|
|
|
break;
|
* vm.c, eval_intern.h (PASS_PASSED_BLOCK):
set a VM_FRAME_FLAG_PASSED flag to skip this frame when
searching ruby-level-cfp.
* eval.c, eval_intern.h, proc.c: fix to check cfp. if there is
no valid ruby-level-cfp, cause RuntimeError exception.
[ruby-dev:34128]
* vm_core.h, vm_evalbody.c, vm.c, vm_dump.c, vm_insnhelper.c,
insns.def: rename FRAME_MAGIC_* to VM_FRAME_MAGIC_*.
* KNOWNBUGS.rb, bootstraptest/test*.rb: move solved bugs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17084 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-11 01:46:43 +04:00
|
|
|
case VM_FRAME_MAGIC_LAMBDA:
|
2006-12-31 18:02:22 +03:00
|
|
|
magic = "LAMBDA";
|
|
|
|
break;
|
* vm.c, eval_intern.h (PASS_PASSED_BLOCK):
set a VM_FRAME_FLAG_PASSED flag to skip this frame when
searching ruby-level-cfp.
* eval.c, eval_intern.h, proc.c: fix to check cfp. if there is
no valid ruby-level-cfp, cause RuntimeError exception.
[ruby-dev:34128]
* vm_core.h, vm_evalbody.c, vm.c, vm_dump.c, vm_insnhelper.c,
insns.def: rename FRAME_MAGIC_* to VM_FRAME_MAGIC_*.
* KNOWNBUGS.rb, bootstraptest/test*.rb: move solved bugs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17084 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-11 01:46:43 +04:00
|
|
|
case VM_FRAME_MAGIC_IFUNC:
|
2006-12-31 18:02:22 +03:00
|
|
|
magic = "IFUNC";
|
|
|
|
break;
|
* vm.c, eval_intern.h (PASS_PASSED_BLOCK):
set a VM_FRAME_FLAG_PASSED flag to skip this frame when
searching ruby-level-cfp.
* eval.c, eval_intern.h, proc.c: fix to check cfp. if there is
no valid ruby-level-cfp, cause RuntimeError exception.
[ruby-dev:34128]
* vm_core.h, vm_evalbody.c, vm.c, vm_dump.c, vm_insnhelper.c,
insns.def: rename FRAME_MAGIC_* to VM_FRAME_MAGIC_*.
* KNOWNBUGS.rb, bootstraptest/test*.rb: move solved bugs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17084 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-11 01:46:43 +04:00
|
|
|
case VM_FRAME_MAGIC_EVAL:
|
2006-12-31 18:02:22 +03:00
|
|
|
magic = "EVAL";
|
|
|
|
break;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
case 0:
|
2006-12-31 18:02:22 +03:00
|
|
|
magic = "------";
|
|
|
|
break;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
default:
|
2006-12-31 18:02:22 +03:00
|
|
|
magic = "(none)";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0) {
|
|
|
|
tmp = rb_inspect(cfp->self);
|
|
|
|
selfstr = StringValueCStr(tmp);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
selfstr = "";
|
|
|
|
}
|
|
|
|
|
* vm_core.h: remove VM_FRAME_MAGIC_FINISH (finish frame type).
Before this commit:
`finish frame' was place holder which indicates that VM loop
needs to return function.
If a C method calls a Ruby methods (a method written by Ruby),
then VM loop will be (re-)invoked. When the Ruby method returns,
then also VM loop should be escaped. `finish frame' has only
one instruction `finish', which returns VM loop function.
VM loop function executes `finish' instruction, then VM loop
function returns itself.
With such mechanism, `leave' instruction (which returns one
frame from current scope) doesn't need to check that this `leave'
should also return from VM loop function.
Strictly, one branch can be removed from `leave' instructon.
Consideration:
However, pushing the `finish frame' needs costs because
it needs several memory accesses. The number of pushing
`finish frame' is greater than I had assumed. Of course,
pushing `finish frame' consumes additional control frame.
Moreover, recent processors has good branch prediction,
with which we can ignore such trivial checking.
After this commit:
Finally, I decide to remove `finish frame' and `finish'
instruction. Some parts of VM depend on `finish frame',
so the new frame flag VM_FRAME_FLAG_FINISH is introduced.
If this frame should escape from VM function loop, then
the result of VM_FRAME_TYPE_FINISH_P(cfp) is true.
`leave' instruction checks this flag every time.
I measured performance on it. However on my environments,
it improves some benchmarks and slows some benchmarks down.
Maybe it is because of C compiler optimization parameters.
I'll re-visit here if this cause problems.
* insns.def (leave, finish): remove finish instruction.
* vm.c, vm_eval.c, vm_exec.c, vm_backtrace.c, vm_dump.c:
apply above changes.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36099 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-15 14:22:34 +04:00
|
|
|
if (cfp->iseq != 0) {
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
if (RUBY_VM_IFUNC_P(cfp->iseq)) {
|
2006-12-31 18:02:22 +03:00
|
|
|
iseq_name = "<ifunc>";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pc = cfp->pc - cfp->iseq->iseq_encoded;
|
2012-06-04 06:49:37 +04:00
|
|
|
iseq_name = RSTRING_PTR(cfp->iseq->location.label);
|
* vm.c: add a prefix "rb_" to exposed functions
vm_get_ruby_level_next_cfp(), rb_vm_make_env_object(),
vm_stack_to_heap(), vm_make_proc(), vm_invoke_proc(),
vm_get_sourceline(), vm_cref(), vm_localjump_error(),
vm_make_jump_tag_but_local_jump(), vm_jump_tag_but_local_jump().
This changes may affect only core because most of renamed functions
require a pointer of not-exposed struct such as rb_thread_t or NODE.
In short, they are core functions.
* cont.c, eval.c, eval_intern.h, load.c, proc.c, thread.c,
vm_core.h, vm_dump.c, vm_eval.c, vm_exec.c, vm_insnhelper.c:
ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-01-19 05:38:11 +03:00
|
|
|
line = rb_vm_get_sourceline(cfp);
|
2006-12-31 18:02:22 +03:00
|
|
|
if (line) {
|
2012-06-04 06:49:37 +04:00
|
|
|
snprintf(posbuf, MAX_POSBUF, "%s:%d", RSTRING_PTR(cfp->iseq->location.path), line);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-15 18:59:41 +04:00
|
|
|
else if (cfp->me) {
|
2009-08-28 06:45:41 +04:00
|
|
|
iseq_name = rb_id2name(cfp->me->def->original_id);
|
|
|
|
snprintf(posbuf, MAX_POSBUF, ":%s", iseq_name);
|
2006-12-31 18:02:22 +03:00
|
|
|
line = -1;
|
|
|
|
}
|
|
|
|
|
2008-07-12 17:17:29 +04:00
|
|
|
fprintf(stderr, "c:%04"PRIdPTRDIFF" ",
|
|
|
|
((rb_control_frame_t *)(th->stack + th->stack_size) - cfp));
|
2006-12-31 18:02:22 +03:00
|
|
|
if (pc == -1) {
|
|
|
|
fprintf(stderr, "p:---- ");
|
|
|
|
}
|
|
|
|
else {
|
* compile.c, cont.c, gc.c, insns.def, iseq.c, iseq.h, process.c,
thread.c, vm.c, vm_core.h, vm_dump.c, vm_eval.c,
vm_insnhelper.c, vm_method.c, template/insns_info.inc.tmpl,
tool/instruction.rb: fixed types.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-09-22 00:58:26 +04:00
|
|
|
fprintf(stderr, "p:%04"PRIdPTRDIFF" ", pc);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2012-09-28 08:05:36 +04:00
|
|
|
fprintf(stderr, "s:%04"PRIdPTRDIFF" ", cfp->sp - th->stack);
|
2013-02-04 07:46:12 +04:00
|
|
|
fprintf(stderr, ep_in_heap == ' ' ? "e:%06"PRIdPTRDIFF" " : "E:%06"PRIxPTRDIFF" ", ep % 10000);
|
2008-11-08 22:10:36 +03:00
|
|
|
fprintf(stderr, "%-6s", magic);
|
* vm_core.h: remove VM_FRAME_MAGIC_FINISH (finish frame type).
Before this commit:
`finish frame' was place holder which indicates that VM loop
needs to return function.
If a C method calls a Ruby methods (a method written by Ruby),
then VM loop will be (re-)invoked. When the Ruby method returns,
then also VM loop should be escaped. `finish frame' has only
one instruction `finish', which returns VM loop function.
VM loop function executes `finish' instruction, then VM loop
function returns itself.
With such mechanism, `leave' instruction (which returns one
frame from current scope) doesn't need to check that this `leave'
should also return from VM loop function.
Strictly, one branch can be removed from `leave' instructon.
Consideration:
However, pushing the `finish frame' needs costs because
it needs several memory accesses. The number of pushing
`finish frame' is greater than I had assumed. Of course,
pushing `finish frame' consumes additional control frame.
Moreover, recent processors has good branch prediction,
with which we can ignore such trivial checking.
After this commit:
Finally, I decide to remove `finish frame' and `finish'
instruction. Some parts of VM depend on `finish frame',
so the new frame flag VM_FRAME_FLAG_FINISH is introduced.
If this frame should escape from VM function loop, then
the result of VM_FRAME_TYPE_FINISH_P(cfp) is true.
`leave' instruction checks this flag every time.
I measured performance on it. However on my environments,
it improves some benchmarks and slows some benchmarks down.
Maybe it is because of C compiler optimization parameters.
I'll re-visit here if this cause problems.
* insns.def (leave, finish): remove finish instruction.
* vm.c, vm_eval.c, vm_exec.c, vm_backtrace.c, vm_dump.c:
apply above changes.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36099 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-15 14:22:34 +04:00
|
|
|
if (line) {
|
2008-11-08 22:10:36 +03:00
|
|
|
fprintf(stderr, " %s", posbuf);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
* vm_core.h: remove VM_FRAME_MAGIC_FINISH (finish frame type).
Before this commit:
`finish frame' was place holder which indicates that VM loop
needs to return function.
If a C method calls a Ruby methods (a method written by Ruby),
then VM loop will be (re-)invoked. When the Ruby method returns,
then also VM loop should be escaped. `finish frame' has only
one instruction `finish', which returns VM loop function.
VM loop function executes `finish' instruction, then VM loop
function returns itself.
With such mechanism, `leave' instruction (which returns one
frame from current scope) doesn't need to check that this `leave'
should also return from VM loop function.
Strictly, one branch can be removed from `leave' instructon.
Consideration:
However, pushing the `finish frame' needs costs because
it needs several memory accesses. The number of pushing
`finish frame' is greater than I had assumed. Of course,
pushing `finish frame' consumes additional control frame.
Moreover, recent processors has good branch prediction,
with which we can ignore such trivial checking.
After this commit:
Finally, I decide to remove `finish frame' and `finish'
instruction. Some parts of VM depend on `finish frame',
so the new frame flag VM_FRAME_FLAG_FINISH is introduced.
If this frame should escape from VM function loop, then
the result of VM_FRAME_TYPE_FINISH_P(cfp) is true.
`leave' instruction checks this flag every time.
I measured performance on it. However on my environments,
it improves some benchmarks and slows some benchmarks down.
Maybe it is because of C compiler optimization parameters.
I'll re-visit here if this cause problems.
* insns.def (leave, finish): remove finish instruction.
* vm.c, vm_eval.c, vm_exec.c, vm_backtrace.c, vm_dump.c:
apply above changes.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36099 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-15 14:22:34 +04:00
|
|
|
if (VM_FRAME_TYPE_FINISH_P(cfp)) {
|
|
|
|
fprintf(stderr, " [FINISH]");
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
if (0) {
|
2008-11-08 22:10:36 +03:00
|
|
|
fprintf(stderr, " \t");
|
2006-12-31 18:02:22 +03:00
|
|
|
fprintf(stderr, "iseq: %-24s ", iseq_name);
|
|
|
|
fprintf(stderr, "self: %-24s ", selfstr);
|
|
|
|
fprintf(stderr, "%-1s ", biseq_name);
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
* vm_dump.c: add a prefix "rb_vmdebug_" to
vm_stack_dump_raw(), vm_stack_dump_raw_current(),
vm_env_dump_raw(), vm_proc_dump_raw(), vm_stack_dump_th(),
vm_debug_print_register(), vm_thread_dump_regs(),
vm_debug_print_pre(), vm_debug_print_post(),
vm_thread_dump_state().
This change also may affect core (in fact, user of
above functions may be only ko1).
* vm_core.h: ditto.
* vm_exec.h (SDR2): remove duplicate definition.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21657 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-01-19 05:09:43 +03:00
|
|
|
rb_vmdebug_stack_dump_raw(rb_thread_t *th, rb_control_frame_t *cfp)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2008-06-15 20:49:19 +04:00
|
|
|
#if 0
|
2012-09-28 08:05:36 +04:00
|
|
|
VALUE *sp = cfp->sp, *ep = cfp->ep;
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE *p, *st, *t;
|
|
|
|
|
|
|
|
fprintf(stderr, "-- stack frame ------------\n");
|
|
|
|
for (p = st = th->stack; p < sp; p++) {
|
2008-05-23 07:25:30 +04:00
|
|
|
fprintf(stderr, "%04ld (%p): %08"PRIxVALUE, (long)(p - st), p, *p);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
t = (VALUE *)*p;
|
|
|
|
if (th->stack <= t && t < sp) {
|
2008-05-23 07:25:30 +04:00
|
|
|
fprintf(stderr, " (= %ld)", (long)((VALUE *)GC_GUARDED_PTR_REF(t) - th->stack));
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2012-06-11 07:14:59 +04:00
|
|
|
if (p == ep)
|
|
|
|
fprintf(stderr, " <- ep");
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
2007-06-17 21:47:35 +04:00
|
|
|
#endif
|
* vm.c: some refactoring.
* rename th_* to vm_*.
* remove unused variables functions.
* add prototypes.
* blockinlining.c, compile.c, cont.c, eval.c, eval_intern.h,
eval_jump.h, eval_load.c, inits.c, insns.def, iseq.c, parse.y,
proc.c, process.c, signal.c, thread.c, vm.c, vm_dump.c,
vm_evalbody.ci, yarvcore.c, yarvcore.h: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12603 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-24 19:42:41 +04:00
|
|
|
|
2010-10-23 06:02:50 +04:00
|
|
|
fprintf(stderr, "-- Control frame information "
|
|
|
|
"-----------------------------------------------\n");
|
2006-12-31 18:02:22 +03:00
|
|
|
while ((void *)cfp < (void *)(th->stack + th->stack_size)) {
|
|
|
|
control_frame_dump(th, cfp);
|
|
|
|
cfp++;
|
|
|
|
}
|
2010-10-23 06:02:50 +04:00
|
|
|
fprintf(stderr, "\n");
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
* vm.c, insns.def, eval.c, vm_insnhelper.c: fix CREF handling.
VM value stack frame of block contains cref information.
(dfp[-1] points CREF)
* compile.c, eval_intern.h, eval_method.c, load.c, proc.c,
vm_dump.h, vm_core.h: ditto.
* include/ruby/ruby.h, gc.c: remove T_VALUES because of above
changes.
* bootstraptest/test_eval.rb, test_knownbug.rb: move solved test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16468 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-05-19 07:08:50 +04:00
|
|
|
void
|
* vm_dump.c: add a prefix "rb_vmdebug_" to
vm_stack_dump_raw(), vm_stack_dump_raw_current(),
vm_env_dump_raw(), vm_proc_dump_raw(), vm_stack_dump_th(),
vm_debug_print_register(), vm_thread_dump_regs(),
vm_debug_print_pre(), vm_debug_print_post(),
vm_thread_dump_state().
This change also may affect core (in fact, user of
above functions may be only ko1).
* vm_core.h: ditto.
* vm_exec.h (SDR2): remove duplicate definition.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21657 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-01-19 05:09:43 +03:00
|
|
|
rb_vmdebug_stack_dump_raw_current(void)
|
* vm.c, insns.def, eval.c, vm_insnhelper.c: fix CREF handling.
VM value stack frame of block contains cref information.
(dfp[-1] points CREF)
* compile.c, eval_intern.h, eval_method.c, load.c, proc.c,
vm_dump.h, vm_core.h: ditto.
* include/ruby/ruby.h, gc.c: remove T_VALUES because of above
changes.
* bootstraptest/test_eval.rb, test_knownbug.rb: move solved test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16468 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-05-19 07:08:50 +04:00
|
|
|
{
|
|
|
|
rb_thread_t *th = GET_THREAD();
|
* vm_dump.c: add a prefix "rb_vmdebug_" to
vm_stack_dump_raw(), vm_stack_dump_raw_current(),
vm_env_dump_raw(), vm_proc_dump_raw(), vm_stack_dump_th(),
vm_debug_print_register(), vm_thread_dump_regs(),
vm_debug_print_pre(), vm_debug_print_post(),
vm_thread_dump_state().
This change also may affect core (in fact, user of
above functions may be only ko1).
* vm_core.h: ditto.
* vm_exec.h (SDR2): remove duplicate definition.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21657 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-01-19 05:09:43 +03:00
|
|
|
rb_vmdebug_stack_dump_raw(th, th->cfp);
|
* vm.c, insns.def, eval.c, vm_insnhelper.c: fix CREF handling.
VM value stack frame of block contains cref information.
(dfp[-1] points CREF)
* compile.c, eval_intern.h, eval_method.c, load.c, proc.c,
vm_dump.h, vm_core.h: ditto.
* include/ruby/ruby.h, gc.c: remove T_VALUES because of above
changes.
* bootstraptest/test_eval.rb, test_knownbug.rb: move solved test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16468 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-05-19 07:08:50 +04:00
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
void
|
2012-06-11 07:14:59 +04:00
|
|
|
rb_vmdebug_env_dump_raw(rb_env_t *env, VALUE *ep)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
fprintf(stderr, "-- env --------------------\n");
|
|
|
|
|
|
|
|
while (env) {
|
|
|
|
fprintf(stderr, "--\n");
|
|
|
|
for (i = 0; i < env->env_size; i++) {
|
2010-10-12 19:03:51 +04:00
|
|
|
fprintf(stderr, "%04d: %08"PRIxVALUE" (%p)", -env->local_size + i, env->env[i],
|
* compile.c (iseq_compile_each), gc.c (assign_heap_slot),
(gc_mark_children), parse.y (vtable_alloc, vtable_free, vtable_add),
proc.c (proc_to_s), thread.c (terminate_i, rb_thread_terminate_all),
(thread_start_func_2, blocking_region_begin, blocking_region_end),
(rb_thread_kill), thread_pthread.c (native_thread_create),
(ubf_pthread_cond_signal), vm.c (check_env, thread_free), vm_dump.c
(vm_env_dump_raw, vm_stack_dump_each, vm_thread_dump_state),
(vm_call0): use void pointer for %p.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-12-09 07:33:55 +03:00
|
|
|
(void *)&env->env[i]);
|
2012-06-11 07:14:59 +04:00
|
|
|
if (&env->env[i] == ep)
|
|
|
|
fprintf(stderr, " <- ep");
|
2006-12-31 18:02:22 +03:00
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (env->prev_envval != 0) {
|
|
|
|
GetEnvPtr(env->prev_envval, env);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
env = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(stderr, "---------------------------\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
* vm_dump.c: add a prefix "rb_vmdebug_" to
vm_stack_dump_raw(), vm_stack_dump_raw_current(),
vm_env_dump_raw(), vm_proc_dump_raw(), vm_stack_dump_th(),
vm_debug_print_register(), vm_thread_dump_regs(),
vm_debug_print_pre(), vm_debug_print_post(),
vm_thread_dump_state().
This change also may affect core (in fact, user of
above functions may be only ko1).
* vm_core.h: ditto.
* vm_exec.h (SDR2): remove duplicate definition.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21657 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-01-19 05:09:43 +03:00
|
|
|
rb_vmdebug_proc_dump_raw(rb_proc_t *proc)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
rb_env_t *env;
|
2006-12-31 18:02:22 +03:00
|
|
|
char *selfstr;
|
|
|
|
VALUE val = rb_inspect(proc->block.self);
|
|
|
|
selfstr = StringValueCStr(val);
|
|
|
|
|
|
|
|
fprintf(stderr, "-- proc -------------------\n");
|
|
|
|
fprintf(stderr, "self: %s\n", selfstr);
|
|
|
|
GetEnvPtr(proc->envval, env);
|
2012-06-11 07:14:59 +04:00
|
|
|
rb_vmdebug_env_dump_raw(env, proc->block.ep);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
* vm_dump.c: add a prefix "rb_vmdebug_" to
vm_stack_dump_raw(), vm_stack_dump_raw_current(),
vm_env_dump_raw(), vm_proc_dump_raw(), vm_stack_dump_th(),
vm_debug_print_register(), vm_thread_dump_regs(),
vm_debug_print_pre(), vm_debug_print_post(),
vm_thread_dump_state().
This change also may affect core (in fact, user of
above functions may be only ko1).
* vm_core.h: ditto.
* vm_exec.h (SDR2): remove duplicate definition.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21657 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-01-19 05:09:43 +03:00
|
|
|
rb_vmdebug_stack_dump_th(VALUE thval)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
* blockinlining.c, error.c, eval.c, eval_error.h, eval_intern.h,
eval_jump.h, eval_load.c, eval_safe.h, gc.c, proc.c, signal.c,
thread.c, thread_pthread.ci, thread_win32.ci, vm.c, vm.h,
vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fix typo (rb_thead_t -> rb_thread_t).
* eval_intern.h: remove unused definitions.
* common.mk: fix around vm_opts.h path
and remove harmful argument passed to insns2vm.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-08 09:37:46 +03:00
|
|
|
rb_thread_t *th;
|
2006-12-31 18:02:22 +03:00
|
|
|
GetThreadPtr(thval, th);
|
* vm_dump.c: add a prefix "rb_vmdebug_" to
vm_stack_dump_raw(), vm_stack_dump_raw_current(),
vm_env_dump_raw(), vm_proc_dump_raw(), vm_stack_dump_th(),
vm_debug_print_register(), vm_thread_dump_regs(),
vm_debug_print_pre(), vm_debug_print_post(),
vm_thread_dump_state().
This change also may affect core (in fact, user of
above functions may be only ko1).
* vm_core.h: ditto.
* vm_exec.h (SDR2): remove duplicate definition.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21657 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-01-19 05:09:43 +03:00
|
|
|
rb_vmdebug_stack_dump_raw(th, th->cfp);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2009-01-19 11:22:58 +03:00
|
|
|
#if VMDEBUG > 2
|
2012-10-10 21:55:57 +04:00
|
|
|
|
|
|
|
/* copy from vm.c */
|
|
|
|
static VALUE *
|
|
|
|
vm_base_ptr(rb_control_frame_t *cfp)
|
|
|
|
{
|
|
|
|
rb_control_frame_t *prev_cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
|
|
|
|
VALUE *bp = prev_cfp->sp + cfp->iseq->local_size + 1;
|
|
|
|
|
|
|
|
if (cfp->iseq->type == ISEQ_TYPE_METHOD) {
|
|
|
|
bp += 1;
|
|
|
|
}
|
|
|
|
return bp;
|
|
|
|
}
|
|
|
|
|
* vm_dump.c: add a prefix "rb_vmdebug_" to
vm_stack_dump_raw(), vm_stack_dump_raw_current(),
vm_env_dump_raw(), vm_proc_dump_raw(), vm_stack_dump_th(),
vm_debug_print_register(), vm_thread_dump_regs(),
vm_debug_print_pre(), vm_debug_print_post(),
vm_thread_dump_state().
This change also may affect core (in fact, user of
above functions may be only ko1).
* vm_core.h: ditto.
* vm_exec.h (SDR2): remove duplicate definition.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21657 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-01-19 05:09:43 +03:00
|
|
|
static void
|
2008-09-04 16:04:09 +04:00
|
|
|
vm_stack_dump_each(rb_thread_t *th, rb_control_frame_t *cfp)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
VALUE rstr;
|
|
|
|
VALUE *sp = cfp->sp;
|
2012-06-11 07:14:59 +04:00
|
|
|
VALUE *ep = cfp->ep;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2009-01-17 05:11:21 +03:00
|
|
|
int argc = 0, local_size = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
const char *name;
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
rb_iseq_t *iseq = cfp->iseq;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
if (iseq == 0) {
|
2007-05-01 08:35:58 +04:00
|
|
|
if (RUBYVM_CFUNC_FRAME_P(cfp)) {
|
2012-10-10 21:55:57 +04:00
|
|
|
name = rb_id2name(cfp->me->called_id);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
name = "?";
|
|
|
|
}
|
|
|
|
}
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
else if (RUBY_VM_IFUNC_P(iseq)) {
|
2006-12-31 18:02:22 +03:00
|
|
|
name = "<ifunc>";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
argc = iseq->argc;
|
|
|
|
local_size = iseq->local_size;
|
2012-06-04 06:49:37 +04:00
|
|
|
name = RSTRING_PTR(iseq->location.label);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* stack trace header */
|
|
|
|
|
* vm.c, eval_intern.h (PASS_PASSED_BLOCK):
set a VM_FRAME_FLAG_PASSED flag to skip this frame when
searching ruby-level-cfp.
* eval.c, eval_intern.h, proc.c: fix to check cfp. if there is
no valid ruby-level-cfp, cause RuntimeError exception.
[ruby-dev:34128]
* vm_core.h, vm_evalbody.c, vm.c, vm_dump.c, vm_insnhelper.c,
insns.def: rename FRAME_MAGIC_* to VM_FRAME_MAGIC_*.
* KNOWNBUGS.rb, bootstraptest/test*.rb: move solved bugs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17084 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-11 01:46:43 +04:00
|
|
|
if (VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_METHOD ||
|
|
|
|
VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_TOP ||
|
|
|
|
VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_BLOCK ||
|
|
|
|
VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_CLASS ||
|
|
|
|
VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_PROC ||
|
|
|
|
VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_LAMBDA ||
|
|
|
|
VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_CFUNC ||
|
|
|
|
VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_IFUNC ||
|
|
|
|
VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_EVAL) {
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2012-06-11 07:14:59 +04:00
|
|
|
VALUE *ptr = ep - local_size;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
control_frame_dump(th, cfp);
|
|
|
|
|
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
rstr = rb_inspect(*ptr);
|
|
|
|
fprintf(stderr, " arg %2d: %8s (%p)\n", i, StringValueCStr(rstr),
|
* compile.c (iseq_compile_each), gc.c (assign_heap_slot),
(gc_mark_children), parse.y (vtable_alloc, vtable_free, vtable_add),
proc.c (proc_to_s), thread.c (terminate_i, rb_thread_terminate_all),
(thread_start_func_2, blocking_region_begin, blocking_region_end),
(rb_thread_kill), thread_pthread.c (native_thread_create),
(ubf_pthread_cond_signal), vm.c (check_env, thread_free), vm_dump.c
(vm_env_dump_raw, vm_stack_dump_each, vm_thread_dump_state),
(vm_call0): use void pointer for %p.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-12-09 07:33:55 +03:00
|
|
|
(void *)ptr++);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
for (; i < local_size - 1; i++) {
|
|
|
|
rstr = rb_inspect(*ptr);
|
|
|
|
fprintf(stderr, " local %2d: %8s (%p)\n", i, StringValueCStr(rstr),
|
* compile.c (iseq_compile_each), gc.c (assign_heap_slot),
(gc_mark_children), parse.y (vtable_alloc, vtable_free, vtable_add),
proc.c (proc_to_s), thread.c (terminate_i, rb_thread_terminate_all),
(thread_start_func_2, blocking_region_begin, blocking_region_end),
(rb_thread_kill), thread_pthread.c (native_thread_create),
(ubf_pthread_cond_signal), vm.c (check_env, thread_free), vm_dump.c
(vm_env_dump_raw, vm_stack_dump_each, vm_thread_dump_state),
(vm_call0): use void pointer for %p.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-12-09 07:33:55 +03:00
|
|
|
(void *)ptr++);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2012-10-10 21:55:57 +04:00
|
|
|
ptr = vm_base_ptr(cfp);
|
2006-12-31 18:02:22 +03:00
|
|
|
for (; ptr < sp; ptr++, i++) {
|
|
|
|
if (*ptr == Qundef) {
|
|
|
|
rstr = rb_str_new2("undef");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rstr = rb_inspect(*ptr);
|
|
|
|
}
|
2008-07-12 17:17:29 +04:00
|
|
|
fprintf(stderr, " stack %2d: %8s (%"PRIdPTRDIFF")\n", i, StringValueCStr(rstr),
|
|
|
|
(ptr - th->stack));
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
2012-10-10 21:55:57 +04:00
|
|
|
else if (VM_FRAME_TYPE_FINISH_P(cfp)) {
|
* vm_core.h: remove VM_FRAME_MAGIC_FINISH (finish frame type).
Before this commit:
`finish frame' was place holder which indicates that VM loop
needs to return function.
If a C method calls a Ruby methods (a method written by Ruby),
then VM loop will be (re-)invoked. When the Ruby method returns,
then also VM loop should be escaped. `finish frame' has only
one instruction `finish', which returns VM loop function.
VM loop function executes `finish' instruction, then VM loop
function returns itself.
With such mechanism, `leave' instruction (which returns one
frame from current scope) doesn't need to check that this `leave'
should also return from VM loop function.
Strictly, one branch can be removed from `leave' instructon.
Consideration:
However, pushing the `finish frame' needs costs because
it needs several memory accesses. The number of pushing
`finish frame' is greater than I had assumed. Of course,
pushing `finish frame' consumes additional control frame.
Moreover, recent processors has good branch prediction,
with which we can ignore such trivial checking.
After this commit:
Finally, I decide to remove `finish frame' and `finish'
instruction. Some parts of VM depend on `finish frame',
so the new frame flag VM_FRAME_FLAG_FINISH is introduced.
If this frame should escape from VM function loop, then
the result of VM_FRAME_TYPE_FINISH_P(cfp) is true.
`leave' instruction checks this flag every time.
I measured performance on it. However on my environments,
it improves some benchmarks and slows some benchmarks down.
Maybe it is because of C compiler optimization parameters.
I'll re-visit here if this cause problems.
* insns.def (leave, finish): remove finish instruction.
* vm.c, vm_eval.c, vm_exec.c, vm_backtrace.c, vm_dump.c:
apply above changes.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36099 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-15 14:22:34 +04:00
|
|
|
if ((th)->stack + (th)->stack_size > (VALUE *)(cfp + 1)) {
|
2008-09-04 16:04:09 +04:00
|
|
|
vm_stack_dump_each(th, cfp + 1);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
else {
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 19:26:04 +03:00
|
|
|
/* SDR(); */
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2007-07-05 14:49:45 +04:00
|
|
|
rb_bug("unsupport frame type: %08lx", VM_FRAME_TYPE(cfp));
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
2009-01-19 11:22:58 +03:00
|
|
|
#endif
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
void
|
* vm_dump.c: add a prefix "rb_vmdebug_" to
vm_stack_dump_raw(), vm_stack_dump_raw_current(),
vm_env_dump_raw(), vm_proc_dump_raw(), vm_stack_dump_th(),
vm_debug_print_register(), vm_thread_dump_regs(),
vm_debug_print_pre(), vm_debug_print_post(),
vm_thread_dump_state().
This change also may affect core (in fact, user of
above functions may be only ko1).
* vm_core.h: ditto.
* vm_exec.h (SDR2): remove duplicate definition.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21657 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-01-19 05:09:43 +03:00
|
|
|
rb_vmdebug_debug_print_register(rb_thread_t *th)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
rb_control_frame_t *cfp = th->cfp;
|
* compile.c, cont.c, gc.c, insns.def, iseq.c, iseq.h, process.c,
thread.c, vm.c, vm_core.h, vm_dump.c, vm_eval.c,
vm_insnhelper.c, vm_method.c, template/insns_info.inc.tmpl,
tool/instruction.rb: fixed types.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-09-22 00:58:26 +04:00
|
|
|
ptrdiff_t pc = -1;
|
2012-06-11 07:14:59 +04:00
|
|
|
ptrdiff_t ep = cfp->ep - th->stack;
|
* compile.c, cont.c, gc.c, insns.def, iseq.c, iseq.h, process.c,
thread.c, vm.c, vm_core.h, vm_dump.c, vm_eval.c,
vm_insnhelper.c, vm_method.c, template/insns_info.inc.tmpl,
tool/instruction.rb: fixed types.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-09-22 00:58:26 +04:00
|
|
|
ptrdiff_t cfpi;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) {
|
2006-12-31 18:02:22 +03:00
|
|
|
pc = cfp->pc - cfp->iseq->iseq_encoded;
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:14:59 +04:00
|
|
|
if (ep < 0 || (size_t)ep > th->stack_size) {
|
|
|
|
ep = -1;
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
cfpi = ((rb_control_frame_t *)(th->stack + th->stack_size)) - cfp;
|
2012-06-11 07:14:59 +04:00
|
|
|
fprintf(stderr, " [PC] %04"PRIdPTRDIFF", [SP] %04"PRIdPTRDIFF", [EP] %04"PRIdPTRDIFF", [CFP] %04"PRIdPTRDIFF"\n",
|
|
|
|
pc, (cfp->sp - th->stack), ep, cfpi);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
* vm_dump.c: add a prefix "rb_vmdebug_" to
vm_stack_dump_raw(), vm_stack_dump_raw_current(),
vm_env_dump_raw(), vm_proc_dump_raw(), vm_stack_dump_th(),
vm_debug_print_register(), vm_thread_dump_regs(),
vm_debug_print_pre(), vm_debug_print_post(),
vm_thread_dump_state().
This change also may affect core (in fact, user of
above functions may be only ko1).
* vm_core.h: ditto.
* vm_exec.h (SDR2): remove duplicate definition.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21657 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-01-19 05:09:43 +03:00
|
|
|
rb_vmdebug_thread_dump_regs(VALUE thval)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
* blockinlining.c, error.c, eval.c, eval_error.h, eval_intern.h,
eval_jump.h, eval_load.c, eval_safe.h, gc.c, proc.c, signal.c,
thread.c, thread_pthread.ci, thread_win32.ci, vm.c, vm.h,
vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fix typo (rb_thead_t -> rb_thread_t).
* eval_intern.h: remove unused definitions.
* common.mk: fix around vm_opts.h path
and remove harmful argument passed to insns2vm.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-08 09:37:46 +03:00
|
|
|
rb_thread_t *th;
|
2006-12-31 18:02:22 +03:00
|
|
|
GetThreadPtr(thval, th);
|
* vm_dump.c: add a prefix "rb_vmdebug_" to
vm_stack_dump_raw(), vm_stack_dump_raw_current(),
vm_env_dump_raw(), vm_proc_dump_raw(), vm_stack_dump_th(),
vm_debug_print_register(), vm_thread_dump_regs(),
vm_debug_print_pre(), vm_debug_print_post(),
vm_thread_dump_state().
This change also may affect core (in fact, user of
above functions may be only ko1).
* vm_core.h: ditto.
* vm_exec.h (SDR2): remove duplicate definition.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21657 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-01-19 05:09:43 +03:00
|
|
|
rb_vmdebug_debug_print_register(th);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-11-29 16:01:18 +04:00
|
|
|
rb_vmdebug_debug_print_pre(rb_thread_t *th, rb_control_frame_t *cfp,VALUE *_pc)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
rb_iseq_t *iseq = cfp->iseq;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2012-08-07 15:13:57 +04:00
|
|
|
if (iseq != 0) {
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE *seq = iseq->iseq;
|
2013-11-29 16:01:18 +04:00
|
|
|
ptrdiff_t pc = _pc - iseq->iseq_encoded;
|
2012-06-11 07:14:59 +04:00
|
|
|
int i;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2012-06-11 07:14:59 +04:00
|
|
|
for (i=0; i<(int)VM_CFP_CNT(th, cfp); i++) {
|
|
|
|
printf(" ");
|
|
|
|
}
|
|
|
|
printf("| ");
|
2013-11-30 13:05:45 +04:00
|
|
|
if(0)printf("[%03ld] ", (long)(cfp->sp - th->stack));
|
2013-11-29 16:01:18 +04:00
|
|
|
|
2012-06-11 07:14:59 +04:00
|
|
|
/* printf("%3"PRIdPTRDIFF" ", VM_CFP_CNT(th, cfp)); */
|
* compile.c, cont.c, gc.c, insns.def, iseq.c, iseq.h, process.c,
thread.c, vm.c, vm_core.h, vm_dump.c, vm_eval.c,
vm_insnhelper.c, vm_method.c, template/insns_info.inc.tmpl,
tool/instruction.rb: fixed types.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-09-22 00:58:26 +04:00
|
|
|
if (pc >= 0) {
|
|
|
|
rb_iseq_disasm_insn(0, seq, (size_t)pc, iseq, 0);
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#if VMDEBUG > 3
|
|
|
|
fprintf(stderr, " (1)");
|
* vm_dump.c: add a prefix "rb_vmdebug_" to
vm_stack_dump_raw(), vm_stack_dump_raw_current(),
vm_env_dump_raw(), vm_proc_dump_raw(), vm_stack_dump_th(),
vm_debug_print_register(), vm_thread_dump_regs(),
vm_debug_print_pre(), vm_debug_print_post(),
vm_thread_dump_state().
This change also may affect core (in fact, user of
above functions may be only ko1).
* vm_core.h: ditto.
* vm_exec.h (SDR2): remove duplicate definition.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21657 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-01-19 05:09:43 +03:00
|
|
|
rb_vmdebug_debug_print_register(th);
|
2006-12-31 18:02:22 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
* vm_dump.c: add a prefix "rb_vmdebug_" to
vm_stack_dump_raw(), vm_stack_dump_raw_current(),
vm_env_dump_raw(), vm_proc_dump_raw(), vm_stack_dump_th(),
vm_debug_print_register(), vm_thread_dump_regs(),
vm_debug_print_pre(), vm_debug_print_post(),
vm_thread_dump_state().
This change also may affect core (in fact, user of
above functions may be only ko1).
* vm_core.h: ditto.
* vm_exec.h (SDR2): remove duplicate definition.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21657 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-01-19 05:09:43 +03:00
|
|
|
rb_vmdebug_debug_print_post(rb_thread_t *th, rb_control_frame_t *cfp
|
2006-12-31 18:02:22 +03:00
|
|
|
#if OPT_STACK_CACHING
|
|
|
|
, VALUE reg_a, VALUE reg_b
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
{
|
|
|
|
#if VMDEBUG > 9
|
|
|
|
SDR2(cfp);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if VMDEBUG > 3
|
|
|
|
fprintf(stderr, " (2)");
|
* vm_dump.c: add a prefix "rb_vmdebug_" to
vm_stack_dump_raw(), vm_stack_dump_raw_current(),
vm_env_dump_raw(), vm_proc_dump_raw(), vm_stack_dump_th(),
vm_debug_print_register(), vm_thread_dump_regs(),
vm_debug_print_pre(), vm_debug_print_post(),
vm_thread_dump_state().
This change also may affect core (in fact, user of
above functions may be only ko1).
* vm_core.h: ditto.
* vm_exec.h (SDR2): remove duplicate definition.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21657 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-01-19 05:09:43 +03:00
|
|
|
rb_vmdebug_debug_print_register(th);
|
2006-12-31 18:02:22 +03:00
|
|
|
#endif
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 19:26:04 +03:00
|
|
|
/* stack_dump_raw(th, cfp); */
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
#if VMDEBUG > 2
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 19:26:04 +03:00
|
|
|
/* stack_dump_thobj(th); */
|
2008-09-04 16:04:09 +04:00
|
|
|
vm_stack_dump_each(th, th->cfp);
|
2012-10-10 21:55:57 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
#if OPT_STACK_CACHING
|
|
|
|
{
|
|
|
|
VALUE rstr;
|
|
|
|
rstr = rb_inspect(reg_a);
|
|
|
|
fprintf(stderr, " sc reg A: %s\n", StringValueCStr(rstr));
|
|
|
|
rstr = rb_inspect(reg_b);
|
|
|
|
fprintf(stderr, " sc reg B: %s\n", StringValueCStr(rstr));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
printf
|
|
|
|
("--------------------------------------------------------------\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* vm_dump.c: add a prefix "rb_vmdebug_" to
vm_stack_dump_raw(), vm_stack_dump_raw_current(),
vm_env_dump_raw(), vm_proc_dump_raw(), vm_stack_dump_th(),
vm_debug_print_register(), vm_thread_dump_regs(),
vm_debug_print_pre(), vm_debug_print_post(),
vm_thread_dump_state().
This change also may affect core (in fact, user of
above functions may be only ko1).
* vm_core.h: ditto.
* vm_exec.h (SDR2): remove duplicate definition.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21657 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-01-19 05:09:43 +03:00
|
|
|
rb_vmdebug_thread_dump_state(VALUE self)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
* blockinlining.c, error.c, eval.c, eval_error.h, eval_intern.h,
eval_jump.h, eval_load.c, eval_safe.h, gc.c, proc.c, signal.c,
thread.c, thread_pthread.ci, thread_win32.ci, vm.c, vm.h,
vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fix typo (rb_thead_t -> rb_thread_t).
* eval_intern.h: remove unused definitions.
* common.mk: fix around vm_opts.h path
and remove harmful argument passed to insns2vm.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-08 09:37:46 +03:00
|
|
|
rb_thread_t *th;
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
rb_control_frame_t *cfp;
|
2006-12-31 18:02:22 +03:00
|
|
|
GetThreadPtr(self, th);
|
|
|
|
cfp = th->cfp;
|
|
|
|
|
|
|
|
fprintf(stderr, "Thread state dump:\n");
|
* compile.c (iseq_compile_each), gc.c (assign_heap_slot),
(gc_mark_children), parse.y (vtable_alloc, vtable_free, vtable_add),
proc.c (proc_to_s), thread.c (terminate_i, rb_thread_terminate_all),
(thread_start_func_2, blocking_region_begin, blocking_region_end),
(rb_thread_kill), thread_pthread.c (native_thread_create),
(ubf_pthread_cond_signal), vm.c (check_env, thread_free), vm_dump.c
(vm_env_dump_raw, vm_stack_dump_each, vm_thread_dump_state),
(vm_call0): use void pointer for %p.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-12-09 07:33:55 +03:00
|
|
|
fprintf(stderr, "pc : %p, sp : %p\n", (void *)cfp->pc, (void *)cfp->sp);
|
2012-06-11 07:14:59 +04:00
|
|
|
fprintf(stderr, "cfp: %p, ep : %p\n", (void *)cfp, (void *)cfp->ep);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2013-02-19 01:46:00 +04:00
|
|
|
#if defined(HAVE_BACKTRACE)
|
|
|
|
# if HAVE_LIBUNWIND
|
|
|
|
# undef backtrace
|
|
|
|
# define backtrace unw_backtrace
|
2013-03-18 08:31:59 +04:00
|
|
|
# elif defined(__APPLE__) && defined(__x86_64__)
|
|
|
|
# define UNW_LOCAL_ONLY
|
|
|
|
# include <libunwind.h>
|
|
|
|
# undef backtrace
|
|
|
|
int backtrace (void **trace, int size) {
|
|
|
|
unw_cursor_t cursor; unw_context_t uc;
|
|
|
|
unw_word_t ip;
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
unw_getcontext(&uc);
|
|
|
|
unw_init_local(&cursor, &uc);
|
|
|
|
while (unw_step(&cursor) > 0) {
|
|
|
|
unw_get_reg(&cursor, UNW_REG_IP, &ip);
|
|
|
|
trace[n++] = (void *)ip;
|
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
unw_get_proc_name(&cursor, buf, 256, &ip);
|
|
|
|
if (strncmp("_sigtramp", buf, sizeof("_sigtramp")) == 0) {
|
|
|
|
goto darwin_sigtramp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
darwin_sigtramp:
|
2013-03-18 21:39:39 +04:00
|
|
|
/* darwin's bundled libunwind doesn't support signal trampoline */
|
2013-03-18 08:31:59 +04:00
|
|
|
{
|
|
|
|
ucontext_t *uctx;
|
2013-03-18 21:39:39 +04:00
|
|
|
/* get _sigtramp's ucontext_t and set values to cursor
|
|
|
|
* http://www.opensource.apple.com/source/Libc/Libc-825.25/i386/sys/_sigtramp.s
|
|
|
|
* http://www.opensource.apple.com/source/libunwind/libunwind-35.1/src/unw_getcontext.s
|
|
|
|
*/
|
2013-03-18 08:31:59 +04:00
|
|
|
unw_get_reg(&cursor, UNW_X86_64_RBX, &ip);
|
|
|
|
uctx = (ucontext_t *)ip;
|
|
|
|
unw_set_reg(&cursor, UNW_X86_64_RAX, uctx->uc_mcontext->__ss.__rax);
|
|
|
|
unw_set_reg(&cursor, UNW_X86_64_RBX, uctx->uc_mcontext->__ss.__rbx);
|
|
|
|
unw_set_reg(&cursor, UNW_X86_64_RCX, uctx->uc_mcontext->__ss.__rcx);
|
|
|
|
unw_set_reg(&cursor, UNW_X86_64_RDX, uctx->uc_mcontext->__ss.__rdx);
|
|
|
|
unw_set_reg(&cursor, UNW_X86_64_RDI, uctx->uc_mcontext->__ss.__rdi);
|
|
|
|
unw_set_reg(&cursor, UNW_X86_64_RSI, uctx->uc_mcontext->__ss.__rsi);
|
|
|
|
unw_set_reg(&cursor, UNW_X86_64_RBP, uctx->uc_mcontext->__ss.__rbp);
|
|
|
|
unw_set_reg(&cursor, UNW_X86_64_RSP, 8+(uctx->uc_mcontext->__ss.__rsp));
|
|
|
|
unw_set_reg(&cursor, UNW_X86_64_R8, uctx->uc_mcontext->__ss.__r8);
|
|
|
|
unw_set_reg(&cursor, UNW_X86_64_R9, uctx->uc_mcontext->__ss.__r9);
|
|
|
|
unw_set_reg(&cursor, UNW_X86_64_R10, uctx->uc_mcontext->__ss.__r10);
|
|
|
|
unw_set_reg(&cursor, UNW_X86_64_R11, uctx->uc_mcontext->__ss.__r11);
|
|
|
|
unw_set_reg(&cursor, UNW_X86_64_R12, uctx->uc_mcontext->__ss.__r12);
|
|
|
|
unw_set_reg(&cursor, UNW_X86_64_R13, uctx->uc_mcontext->__ss.__r13);
|
|
|
|
unw_set_reg(&cursor, UNW_X86_64_R14, uctx->uc_mcontext->__ss.__r14);
|
|
|
|
unw_set_reg(&cursor, UNW_X86_64_R15, uctx->uc_mcontext->__ss.__r15);
|
|
|
|
ip = *(unw_word_t*)uctx->uc_mcontext->__ss.__rsp;
|
|
|
|
unw_set_reg(&cursor, UNW_REG_IP, ip);
|
2013-03-18 21:39:39 +04:00
|
|
|
trace[n++] = (void *)uctx->uc_mcontext->__ss.__rip;
|
2013-03-18 08:31:59 +04:00
|
|
|
trace[n++] = (void *)ip;
|
|
|
|
}
|
|
|
|
while (unw_step(&cursor) > 0) {
|
|
|
|
unw_get_reg(&cursor, UNW_REG_IP, &ip);
|
|
|
|
trace[n++] = (void *)ip;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
2013-02-19 01:46:00 +04:00
|
|
|
# elif defined(BROKEN_BACKTRACE)
|
|
|
|
# undef HAVE_BACKTRACE
|
|
|
|
# define HAVE_BACKTRACE 0
|
|
|
|
# endif
|
|
|
|
#else
|
2013-02-19 01:20:59 +04:00
|
|
|
# define HAVE_BACKTRACE 0
|
|
|
|
#endif
|
2013-02-19 01:46:00 +04:00
|
|
|
|
2009-04-01 13:53:52 +04:00
|
|
|
#if HAVE_BACKTRACE
|
2010-09-28 15:08:56 +04:00
|
|
|
# include <execinfo.h>
|
|
|
|
#elif defined(_WIN32)
|
|
|
|
# include <imagehlp.h>
|
|
|
|
# ifndef SYMOPT_DEBUG
|
|
|
|
# define SYMOPT_DEBUG 0x80000000
|
|
|
|
# endif
|
|
|
|
# ifndef MAX_SYM_NAME
|
|
|
|
# define MAX_SYM_NAME 2000
|
|
|
|
typedef struct {
|
|
|
|
DWORD64 Offset;
|
|
|
|
WORD Segment;
|
|
|
|
ADDRESS_MODE Mode;
|
|
|
|
} ADDRESS64;
|
|
|
|
typedef struct {
|
|
|
|
DWORD64 Thread;
|
|
|
|
DWORD ThCallbackStack;
|
|
|
|
DWORD ThCallbackBStore;
|
|
|
|
DWORD NextCallback;
|
|
|
|
DWORD FramePointer;
|
|
|
|
DWORD64 KiCallUserMode;
|
|
|
|
DWORD64 KeUserCallbackDispatcher;
|
|
|
|
DWORD64 SystemRangeStart;
|
|
|
|
DWORD64 KiUserExceptionDispatcher;
|
|
|
|
DWORD64 StackBase;
|
|
|
|
DWORD64 StackLimit;
|
|
|
|
DWORD64 Reserved[5];
|
|
|
|
} KDHELP64;
|
|
|
|
typedef struct {
|
|
|
|
ADDRESS64 AddrPC;
|
|
|
|
ADDRESS64 AddrReturn;
|
|
|
|
ADDRESS64 AddrFrame;
|
|
|
|
ADDRESS64 AddrStack;
|
|
|
|
ADDRESS64 AddrBStore;
|
|
|
|
void *FuncTableEntry;
|
|
|
|
DWORD64 Params[4];
|
|
|
|
BOOL Far;
|
|
|
|
BOOL Virtual;
|
|
|
|
DWORD64 Reserved[3];
|
|
|
|
KDHELP64 KdHelp;
|
|
|
|
} STACKFRAME64;
|
|
|
|
typedef struct {
|
|
|
|
ULONG SizeOfStruct;
|
|
|
|
ULONG TypeIndex;
|
|
|
|
ULONG64 Reserved[2];
|
|
|
|
ULONG Index;
|
|
|
|
ULONG Size;
|
|
|
|
ULONG64 ModBase;
|
|
|
|
ULONG Flags;
|
|
|
|
ULONG64 Value;
|
|
|
|
ULONG64 Address;
|
|
|
|
ULONG Register;
|
|
|
|
ULONG Scope;
|
|
|
|
ULONG Tag;
|
|
|
|
ULONG NameLen;
|
|
|
|
ULONG MaxNameLen;
|
|
|
|
char Name[1];
|
|
|
|
} SYMBOL_INFO;
|
|
|
|
typedef struct {
|
|
|
|
DWORD SizeOfStruct;
|
|
|
|
void *Key;
|
|
|
|
DWORD LineNumber;
|
|
|
|
char *FileName;
|
|
|
|
DWORD64 Address;
|
|
|
|
} IMAGEHLP_LINE64;
|
|
|
|
typedef void *PREAD_PROCESS_MEMORY_ROUTINE64;
|
|
|
|
typedef void *PFUNCTION_TABLE_ACCESS_ROUTINE64;
|
|
|
|
typedef void *PGET_MODULE_BASE_ROUTINE64;
|
|
|
|
typedef void *PTRANSLATE_ADDRESS_ROUTINE64;
|
|
|
|
# endif
|
|
|
|
|
|
|
|
static void
|
|
|
|
dump_thread(void *arg)
|
|
|
|
{
|
|
|
|
HANDLE dbghelp;
|
|
|
|
BOOL (WINAPI *pSymInitialize)(HANDLE, const char *, BOOL);
|
|
|
|
BOOL (WINAPI *pSymCleanup)(HANDLE);
|
|
|
|
BOOL (WINAPI *pStackWalk64)(DWORD, HANDLE, HANDLE, STACKFRAME64 *, void *, PREAD_PROCESS_MEMORY_ROUTINE64, PFUNCTION_TABLE_ACCESS_ROUTINE64, PGET_MODULE_BASE_ROUTINE64, PTRANSLATE_ADDRESS_ROUTINE64);
|
2010-10-12 07:22:13 +04:00
|
|
|
DWORD64 (WINAPI *pSymGetModuleBase64)(HANDLE, DWORD64);
|
2010-09-28 15:08:56 +04:00
|
|
|
BOOL (WINAPI *pSymFromAddr)(HANDLE, DWORD64, DWORD64 *, SYMBOL_INFO *);
|
|
|
|
BOOL (WINAPI *pSymGetLineFromAddr64)(HANDLE, DWORD64, DWORD *, IMAGEHLP_LINE64 *);
|
|
|
|
HANDLE (WINAPI *pOpenThread)(DWORD, BOOL, DWORD);
|
|
|
|
DWORD tid = *(DWORD *)arg;
|
|
|
|
HANDLE ph;
|
|
|
|
HANDLE th;
|
|
|
|
|
|
|
|
dbghelp = LoadLibrary("dbghelp.dll");
|
|
|
|
if (!dbghelp) return;
|
|
|
|
pSymInitialize = (BOOL (WINAPI *)(HANDLE, const char *, BOOL))GetProcAddress(dbghelp, "SymInitialize");
|
|
|
|
pSymCleanup = (BOOL (WINAPI *)(HANDLE))GetProcAddress(dbghelp, "SymCleanup");
|
|
|
|
pStackWalk64 = (BOOL (WINAPI *)(DWORD, HANDLE, HANDLE, STACKFRAME64 *, void *, PREAD_PROCESS_MEMORY_ROUTINE64, PFUNCTION_TABLE_ACCESS_ROUTINE64, PGET_MODULE_BASE_ROUTINE64, PTRANSLATE_ADDRESS_ROUTINE64))GetProcAddress(dbghelp, "StackWalk64");
|
2010-10-12 07:22:13 +04:00
|
|
|
pSymGetModuleBase64 = (DWORD64 (WINAPI *)(HANDLE, DWORD64))GetProcAddress(dbghelp, "SymGetModuleBase64");
|
2010-09-28 15:08:56 +04:00
|
|
|
pSymFromAddr = (BOOL (WINAPI *)(HANDLE, DWORD64, DWORD64 *, SYMBOL_INFO *))GetProcAddress(dbghelp, "SymFromAddr");
|
|
|
|
pSymGetLineFromAddr64 = (BOOL (WINAPI *)(HANDLE, DWORD64, DWORD *, IMAGEHLP_LINE64 *))GetProcAddress(dbghelp, "SymGetLineFromAddr64");
|
|
|
|
pOpenThread = (HANDLE (WINAPI *)(DWORD, BOOL, DWORD))GetProcAddress(GetModuleHandle("kernel32.dll"), "OpenThread");
|
|
|
|
if (pSymInitialize && pSymCleanup && pStackWalk64 && pSymGetModuleBase64 &&
|
|
|
|
pSymFromAddr && pSymGetLineFromAddr64 && pOpenThread) {
|
|
|
|
SymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS | SYMOPT_DEBUG | SYMOPT_LOAD_LINES);
|
|
|
|
ph = GetCurrentProcess();
|
|
|
|
pSymInitialize(ph, NULL, TRUE);
|
2010-11-26 05:42:46 +03:00
|
|
|
th = pOpenThread(THREAD_SUSPEND_RESUME|THREAD_GET_CONTEXT, FALSE, tid);
|
2010-09-28 15:08:56 +04:00
|
|
|
if (th) {
|
|
|
|
if (SuspendThread(th) != (DWORD)-1) {
|
|
|
|
CONTEXT context;
|
|
|
|
memset(&context, 0, sizeof(context));
|
|
|
|
context.ContextFlags = CONTEXT_FULL;
|
|
|
|
if (GetThreadContext(th, &context)) {
|
|
|
|
char libpath[MAX_PATH];
|
|
|
|
char buf[sizeof(SYMBOL_INFO) + MAX_SYM_NAME];
|
|
|
|
SYMBOL_INFO *info = (SYMBOL_INFO *)buf;
|
|
|
|
DWORD mac;
|
|
|
|
STACKFRAME64 frame;
|
|
|
|
memset(&frame, 0, sizeof(frame));
|
|
|
|
#if defined(_M_AMD64) || defined(__x86_64__)
|
|
|
|
mac = IMAGE_FILE_MACHINE_AMD64;
|
|
|
|
frame.AddrPC.Mode = AddrModeFlat;
|
|
|
|
frame.AddrPC.Offset = context.Rip;
|
|
|
|
frame.AddrFrame.Mode = AddrModeFlat;
|
|
|
|
frame.AddrFrame.Offset = context.Rbp;
|
|
|
|
frame.AddrStack.Mode = AddrModeFlat;
|
|
|
|
frame.AddrStack.Offset = context.Rsp;
|
|
|
|
#elif defined(_M_IA64) || defined(__ia64__)
|
|
|
|
mac = IMAGE_FILE_MACHINE_IA64;
|
|
|
|
frame.AddrPC.Mode = AddrModeFlat;
|
|
|
|
frame.AddrPC.Offset = context.StIIP;
|
|
|
|
frame.AddrBStore.Mode = AddrModeFlat;
|
|
|
|
frame.AddrBStore.Offset = context.RsBSP;
|
|
|
|
frame.AddrStack.Mode = AddrModeFlat;
|
|
|
|
frame.AddrStack.Offset = context.IntSp;
|
|
|
|
#else /* i386 */
|
|
|
|
mac = IMAGE_FILE_MACHINE_I386;
|
|
|
|
frame.AddrPC.Mode = AddrModeFlat;
|
|
|
|
frame.AddrPC.Offset = context.Eip;
|
|
|
|
frame.AddrFrame.Mode = AddrModeFlat;
|
|
|
|
frame.AddrFrame.Offset = context.Ebp;
|
|
|
|
frame.AddrStack.Mode = AddrModeFlat;
|
|
|
|
frame.AddrStack.Offset = context.Esp;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
while (pStackWalk64(mac, ph, th, &frame, &context, NULL,
|
|
|
|
NULL, NULL, NULL)) {
|
|
|
|
DWORD64 addr = frame.AddrPC.Offset;
|
|
|
|
IMAGEHLP_LINE64 line;
|
2010-11-26 05:10:25 +03:00
|
|
|
DWORD64 displacement;
|
2010-11-26 03:34:04 +03:00
|
|
|
DWORD tmp;
|
2010-09-28 15:08:56 +04:00
|
|
|
|
2010-09-30 04:35:23 +04:00
|
|
|
if (addr == frame.AddrReturn.Offset || addr == 0 ||
|
|
|
|
frame.AddrReturn.Offset == 0)
|
2010-09-28 15:08:56 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
info->SizeOfStruct = sizeof(SYMBOL_INFO);
|
|
|
|
info->MaxNameLen = MAX_SYM_NAME;
|
2010-11-26 05:10:25 +03:00
|
|
|
if (pSymFromAddr(ph, addr, &displacement, info)) {
|
2010-10-13 18:08:29 +04:00
|
|
|
if (GetModuleFileName((HANDLE)(uintptr_t)pSymGetModuleBase64(ph, addr), libpath, sizeof(libpath)))
|
2010-09-28 15:08:56 +04:00
|
|
|
fprintf(stderr, "%s", libpath);
|
2010-11-26 05:10:25 +03:00
|
|
|
fprintf(stderr, "(%s+0x%I64x)",
|
|
|
|
info->Name, displacement);
|
2010-09-28 15:08:56 +04:00
|
|
|
}
|
2010-11-26 04:50:18 +03:00
|
|
|
fprintf(stderr, " [0x%p]", (void *)(VALUE)addr);
|
2010-09-28 15:08:56 +04:00
|
|
|
memset(&line, 0, sizeof(line));
|
|
|
|
line.SizeOfStruct = sizeof(line);
|
2010-11-26 03:34:04 +03:00
|
|
|
if (pSymGetLineFromAddr64(ph, addr, &tmp, &line))
|
2010-09-28 15:08:56 +04:00
|
|
|
fprintf(stderr, " %s:%lu", line.FileName, line.LineNumber);
|
2010-11-26 04:50:18 +03:00
|
|
|
fprintf(stderr, "\n");
|
2010-09-28 15:08:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ResumeThread(th);
|
|
|
|
}
|
|
|
|
CloseHandle(th);
|
|
|
|
}
|
|
|
|
pSymCleanup(ph);
|
|
|
|
}
|
|
|
|
FreeLibrary(dbghelp);
|
|
|
|
}
|
2009-04-01 13:53:52 +04:00
|
|
|
#endif
|
2010-09-28 15:08:56 +04:00
|
|
|
|
2013-04-02 11:02:54 +04:00
|
|
|
void
|
|
|
|
rb_print_backtrace(void)
|
|
|
|
{
|
|
|
|
#if HAVE_BACKTRACE
|
|
|
|
#define MAX_NATIVE_TRACE 1024
|
|
|
|
static void *trace[MAX_NATIVE_TRACE];
|
|
|
|
int n = backtrace(trace, MAX_NATIVE_TRACE);
|
|
|
|
char **syms = backtrace_symbols(trace, n);
|
|
|
|
|
|
|
|
if (syms) {
|
|
|
|
#ifdef USE_ELF
|
|
|
|
rb_dump_backtrace_with_lines(n, trace, syms);
|
|
|
|
#else
|
|
|
|
int i;
|
|
|
|
for (i=0; i<n; i++) {
|
|
|
|
fprintf(stderr, "%s\n", syms[i]);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
free(syms);
|
|
|
|
}
|
|
|
|
#elif defined(_WIN32)
|
|
|
|
DWORD tid = GetCurrentThreadId();
|
|
|
|
HANDLE th = (HANDLE)_beginthread(dump_thread, 0, &tid);
|
|
|
|
if (th != (HANDLE)-1)
|
|
|
|
WaitForSingleObject(th, INFINITE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-03-10 21:10:57 +04:00
|
|
|
#ifdef __FreeBSD__
|
|
|
|
#include <sys/user.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <libprocstat.h>
|
|
|
|
# ifndef KVME_TYPE_MGTDEVICE
|
|
|
|
# define KVME_TYPE_MGTDEVICE 8
|
|
|
|
# endif
|
|
|
|
void
|
|
|
|
procstat_vm(struct procstat *procstat, struct kinfo_proc *kipp)
|
|
|
|
{
|
|
|
|
struct kinfo_vmentry *freep, *kve;
|
|
|
|
int ptrwidth;
|
|
|
|
unsigned int i, cnt;
|
|
|
|
const char *str;
|
|
|
|
#ifdef __x86_64__
|
|
|
|
ptrwidth = 14;
|
|
|
|
#else
|
|
|
|
ptrwidth = 2*sizeof(void *) + 2;
|
|
|
|
#endif
|
|
|
|
fprintf(stderr, "%*s %*s %3s %4s %4s %3s %3s %4s %-2s %-s\n",
|
|
|
|
ptrwidth, "START", ptrwidth, "END", "PRT", "RES",
|
|
|
|
"PRES", "REF", "SHD", "FL", "TP", "PATH");
|
|
|
|
|
|
|
|
freep = procstat_getvmmap(procstat, kipp, &cnt);
|
|
|
|
if (freep == NULL)
|
|
|
|
return;
|
|
|
|
for (i = 0; i < cnt; i++) {
|
|
|
|
kve = &freep[i];
|
|
|
|
fprintf(stderr, "%#*jx ", ptrwidth, (uintmax_t)kve->kve_start);
|
|
|
|
fprintf(stderr, "%#*jx ", ptrwidth, (uintmax_t)kve->kve_end);
|
|
|
|
fprintf(stderr, "%s", kve->kve_protection & KVME_PROT_READ ? "r" : "-");
|
|
|
|
fprintf(stderr, "%s", kve->kve_protection & KVME_PROT_WRITE ? "w" : "-");
|
|
|
|
fprintf(stderr, "%s ", kve->kve_protection & KVME_PROT_EXEC ? "x" : "-");
|
|
|
|
fprintf(stderr, "%4d ", kve->kve_resident);
|
|
|
|
fprintf(stderr, "%4d ", kve->kve_private_resident);
|
|
|
|
fprintf(stderr, "%3d ", kve->kve_ref_count);
|
|
|
|
fprintf(stderr, "%3d ", kve->kve_shadow_count);
|
|
|
|
fprintf(stderr, "%-1s", kve->kve_flags & KVME_FLAG_COW ? "C" : "-");
|
|
|
|
fprintf(stderr, "%-1s", kve->kve_flags & KVME_FLAG_NEEDS_COPY ? "N" :
|
|
|
|
"-");
|
|
|
|
fprintf(stderr, "%-1s", kve->kve_flags & KVME_FLAG_SUPER ? "S" : "-");
|
|
|
|
fprintf(stderr, "%-1s ", kve->kve_flags & KVME_FLAG_GROWS_UP ? "U" :
|
|
|
|
kve->kve_flags & KVME_FLAG_GROWS_DOWN ? "D" : "-");
|
|
|
|
switch (kve->kve_type) {
|
|
|
|
case KVME_TYPE_NONE:
|
|
|
|
str = "--";
|
|
|
|
break;
|
|
|
|
case KVME_TYPE_DEFAULT:
|
|
|
|
str = "df";
|
|
|
|
break;
|
|
|
|
case KVME_TYPE_VNODE:
|
|
|
|
str = "vn";
|
|
|
|
break;
|
|
|
|
case KVME_TYPE_SWAP:
|
|
|
|
str = "sw";
|
|
|
|
break;
|
|
|
|
case KVME_TYPE_DEVICE:
|
|
|
|
str = "dv";
|
|
|
|
break;
|
|
|
|
case KVME_TYPE_PHYS:
|
|
|
|
str = "ph";
|
|
|
|
break;
|
|
|
|
case KVME_TYPE_DEAD:
|
|
|
|
str = "dd";
|
|
|
|
break;
|
|
|
|
case KVME_TYPE_SG:
|
|
|
|
str = "sg";
|
|
|
|
break;
|
|
|
|
case KVME_TYPE_MGTDEVICE:
|
|
|
|
str = "md";
|
|
|
|
break;
|
|
|
|
case KVME_TYPE_UNKNOWN:
|
|
|
|
default:
|
|
|
|
str = "??";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fprintf(stderr, "%-2s ", str);
|
|
|
|
fprintf(stderr, "%-s\n", kve->kve_path);
|
|
|
|
}
|
|
|
|
free(freep);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
void
|
* 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
|
|
|
rb_vm_bugreport(void)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2011-11-11 12:09:48 +04:00
|
|
|
#ifdef __linux__
|
|
|
|
# define PROC_MAPS_NAME "/proc/self/maps"
|
|
|
|
#endif
|
|
|
|
#ifdef PROC_MAPS_NAME
|
|
|
|
enum {other_runtime_info = 1};
|
|
|
|
#else
|
|
|
|
enum {other_runtime_info = 0};
|
|
|
|
#endif
|
|
|
|
const rb_vm_t *const vm = GET_VM();
|
2013-01-30 10:21:33 +04:00
|
|
|
|
|
|
|
#if defined __APPLE__
|
|
|
|
fputs("-- Crash Report log information "
|
|
|
|
"--------------------------------------------\n"
|
|
|
|
" See Crash Report log file under the one of following:\n"
|
|
|
|
" * ~/Library/Logs/CrashReporter\n"
|
|
|
|
" * /Library/Logs/CrashReporter\n"
|
|
|
|
" * ~/Library/Logs/DiagnosticReports\n"
|
|
|
|
" * /Library/Logs/DiagnosticReports\n"
|
2013-12-20 03:18:14 +04:00
|
|
|
" for more details.\n"
|
2013-01-30 10:21:33 +04:00
|
|
|
"\n",
|
|
|
|
stderr);
|
|
|
|
#endif
|
2010-10-23 06:02:50 +04:00
|
|
|
if (vm) {
|
2006-12-31 18:02:22 +03:00
|
|
|
SDR();
|
2012-05-25 08:50:10 +04:00
|
|
|
rb_backtrace_print_as_bugreport();
|
|
|
|
fputs("\n", stderr);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2011-11-11 12:09:48 +04:00
|
|
|
if (other_runtime_info || vm) {
|
|
|
|
fprintf(stderr, "-- Other runtime information "
|
|
|
|
"-----------------------------------------------\n\n");
|
|
|
|
}
|
|
|
|
if (vm) {
|
2010-10-23 06:02:50 +04:00
|
|
|
int i;
|
2011-11-11 12:09:48 +04:00
|
|
|
VALUE name;
|
2012-12-12 07:12:37 +04:00
|
|
|
long len;
|
|
|
|
const int max_name_length = 1024;
|
|
|
|
# define LIMITED_NAME_LENGTH(s) \
|
|
|
|
(((len = RSTRING_LEN(s)) > max_name_length) ? max_name_length : (int)len)
|
2010-10-23 06:02:50 +04:00
|
|
|
|
2011-11-11 12:09:48 +04:00
|
|
|
name = vm->progname;
|
2012-12-12 07:12:37 +04:00
|
|
|
fprintf(stderr, "* Loaded script: %.*s\n",
|
|
|
|
LIMITED_NAME_LENGTH(name), RSTRING_PTR(name));
|
2010-10-23 06:02:50 +04:00
|
|
|
fprintf(stderr, "\n");
|
|
|
|
fprintf(stderr, "* Loaded features:\n\n");
|
|
|
|
for (i=0; i<RARRAY_LEN(vm->loaded_features); i++) {
|
2013-05-13 13:56:22 +04:00
|
|
|
name = RARRAY_AREF(vm->loaded_features, i);
|
2012-12-11 21:13:18 +04:00
|
|
|
if (RB_TYPE_P(name, T_STRING)) {
|
2012-12-12 07:12:37 +04:00
|
|
|
fprintf(stderr, " %4d %.*s\n", i,
|
|
|
|
LIMITED_NAME_LENGTH(name), RSTRING_PTR(name));
|
2012-12-11 21:13:18 +04:00
|
|
|
}
|
2013-05-22 12:03:53 +04:00
|
|
|
else if (RB_TYPE_P(name, T_CLASS) || RB_TYPE_P(name, T_MODULE)) {
|
|
|
|
const char *const type = RB_TYPE_P(name, T_CLASS) ?
|
|
|
|
"class" : "module";
|
|
|
|
name = rb_class_name(name);
|
|
|
|
fprintf(stderr, " %4d %s:%.*s\n", i, type,
|
|
|
|
LIMITED_NAME_LENGTH(name), RSTRING_PTR(name));
|
|
|
|
}
|
2012-12-11 21:13:18 +04:00
|
|
|
else {
|
2013-05-22 12:03:51 +04:00
|
|
|
VALUE klass = rb_class_name(CLASS_OF(name));
|
|
|
|
fprintf(stderr, " %4d #<%.*s:%p>\n", i,
|
|
|
|
LIMITED_NAME_LENGTH(klass), RSTRING_PTR(klass),
|
|
|
|
(void *)name);
|
2012-12-11 21:13:18 +04:00
|
|
|
}
|
2010-10-23 06:02:50 +04:00
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
2011-11-11 12:09:48 +04:00
|
|
|
}
|
2010-10-23 06:02:50 +04:00
|
|
|
|
2011-11-11 12:09:48 +04:00
|
|
|
{
|
|
|
|
#ifdef PROC_MAPS_NAME
|
2010-10-23 06:02:50 +04:00
|
|
|
{
|
2011-11-11 12:09:48 +04:00
|
|
|
FILE *fp = fopen(PROC_MAPS_NAME, "r");
|
2010-10-23 06:02:50 +04:00
|
|
|
if (fp) {
|
|
|
|
fprintf(stderr, "* Process memory map:\n\n");
|
|
|
|
|
|
|
|
while (!feof(fp)) {
|
|
|
|
char buff[0x100];
|
|
|
|
size_t rn = fread(buff, 1, 0x100, fp);
|
2011-11-27 16:06:10 +04:00
|
|
|
if (fwrite(buff, 1, rn, stderr) != rn)
|
|
|
|
break;
|
2010-10-23 06:02:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
fprintf(stderr, "\n\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* __linux__ */
|
2014-03-10 21:10:57 +04:00
|
|
|
#ifdef __FreeBSD__
|
|
|
|
# define MIB_KERN_PROC_PID_LEN 4
|
|
|
|
int mib[MIB_KERN_PROC_PID_LEN];
|
|
|
|
struct kinfo_proc kp;
|
|
|
|
size_t len = sizeof(struct kinfo_proc);
|
|
|
|
mib[0] = CTL_KERN;
|
|
|
|
mib[1] = KERN_PROC;
|
|
|
|
mib[2] = KERN_PROC_PID;
|
|
|
|
mib[3] = getpid();
|
|
|
|
if (sysctl(mib, MIB_KERN_PROC_PID_LEN, &kp, &len, NULL, 0) == -1) {
|
|
|
|
perror("sysctl");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
struct procstat *prstat = procstat_open_sysctl();
|
|
|
|
fprintf(stderr, "* Process memory map:\n\n");
|
|
|
|
procstat_vm(prstat, &kp);
|
|
|
|
procstat_close(prstat);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
#endif /* __FreeBSD__ */
|
2014-03-26 03:55:58 +04:00
|
|
|
#if HAVE_BACKTRACE || defined(_WIN32)
|
|
|
|
fprintf(stderr, "-- C level backtrace information "
|
|
|
|
"-------------------------------------------\n");
|
|
|
|
rb_print_backtrace();
|
|
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
#endif /* HAVE_BACKTRACE */
|
|
|
|
|
2010-10-23 06:02:50 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|