summaryrefslogtreecommitdiff
path: root/vm_dump.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-06-11 03:14:59 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-06-11 03:14:59 +0000
commit0a71db8a7497df37b984ea97abfce6b6ffd82df3 (patch)
treea8fc12e5b436e09ce0144b79315d32abe06c8c49 /vm_dump.c
parent9b29e5f7e1855f5381227363970e4ff21f3e4ae6 (diff)
downloadruby-0a71db8a7497df37b984ea97abfce6b6ffd82df3.tar.gz
* vm_core.h: remove lfp (local frame pointer) and rename
dfp (dynamic frame pointer) to ep (environment pointer). This change make VM `normal' (similar to other interpreters). Before this commit: Each frame has two env pointers lfp and dfp. lfp points local environment which is method/class/toplevel frame. lfp[0] is block pointer. dfp is block local frame. dfp[0] points previous (parent) environment pointer. lfp == dfp when frame is method/class/toplevel. You can get lfp from dfp by traversing previous environment pointers. After this commit: Each frame has only `ep' to point respective enviornoment. If there is parent environment, then ep[0] points parent envioenment (as dfp). If there are no more environment, then ep[0] points block pointer (as lfp). We call such ep as `LEP' (local EP). We add some macros to get LEP and to detect LEP or not. In short, we replace dfp and lfp with ep and LEP. rb_block_t and rb_binding_t member `lfp' and `dfp' are removed and member `ep' is added. rename rb_thread_t's member `local_lfp' and `local_svar' to `root_lep' and `root_svar'. (VM_EP_PREV_EP(ep)): get previous environment pointer. This macro assume that ep is not LEP. (VM_EP_BLOCK_PTR(ep)): get block pointer. This macro assume that ep is LEP. (VM_EP_LEP_P(ep)): detect ep is LEP or not. (VM_ENVVAL_BLOCK_PTR(ptr)): make block pointer. (VM_ENVVAL_BLOCK_PTR_P(v)): detect v is block pointer. (VM_ENVVAL_PREV_EP_PTR(ptr)): make prev environment pointer. (VM_ENVVAL_PREV_EP_PTR_P(v)): detect v is prev env pointer. * vm.c: apply above changes. (VM_EP_LEP(ep)): get LEP. (VM_CF_LEP(cfp)): get LEP of cfp->ep. (VM_CF_PREV_EP(cfp)): utility function VM_EP_PREV_EP(cfp->ep). (VM_CF_BLOCK_PTR(cfp)): utility function VM_EP_BLOCK_PTR(cfp->ep). * vm.c, vm_eval.c, vm_insnhelper.c, vm_insnhelper.h, insns.def: apply above changes. * cont.c: ditto. * eval.c, eval_intern.h: ditto. * proc.c: ditto. * thread.c: ditto. * vm_dump.c: ditto. * vm_exec.h: fix function name (on vm debug mode). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_dump.c')
-rw-r--r--vm_dump.c78
1 files changed, 32 insertions, 46 deletions
diff --git a/vm_dump.c b/vm_dump.c
index 2766677cf3..d38f114b86 100644
--- a/vm_dump.c
+++ b/vm_dump.c
@@ -28,9 +28,8 @@ static void
control_frame_dump(rb_thread_t *th, rb_control_frame_t *cfp)
{
ptrdiff_t pc = -1, bp = -1;
- ptrdiff_t lfp = cfp->lfp - th->stack;
- ptrdiff_t dfp = cfp->dfp - th->stack;
- char lfp_in_heap = ' ', dfp_in_heap = ' ';
+ ptrdiff_t ep = cfp->ep - th->stack;
+ char ep_in_heap = ' ';
char posbuf[MAX_POSBUF+1];
int line = 0;
int nopos = 0;
@@ -42,13 +41,9 @@ control_frame_dump(rb_thread_t *th, rb_control_frame_t *cfp)
biseq_name = ""; /* RSTRING(cfp->block_iseq->location.label)->ptr; */
}
- if (lfp < 0 || (size_t)lfp > th->stack_size) {
- lfp = (ptrdiff_t)cfp->lfp;
- lfp_in_heap = 'p';
- }
- if (dfp < 0 || (size_t)dfp > th->stack_size) {
- dfp = (ptrdiff_t)cfp->dfp;
- dfp_in_heap = 'p';
+ if (ep < 0 || (size_t)ep > th->stack_size) {
+ ep = (ptrdiff_t)cfp->ep;
+ ep_in_heap = 'p';
}
if (cfp->bp) {
bp = cfp->bp - th->stack;
@@ -133,8 +128,7 @@ control_frame_dump(rb_thread_t *th, rb_control_frame_t *cfp)
fprintf(stderr, "p:%04"PRIdPTRDIFF" ", pc);
}
fprintf(stderr, "s:%04"PRIdPTRDIFF" b:%04"PRIdPTRDIFF" ", (cfp->sp - th->stack), bp);
- fprintf(stderr, lfp_in_heap == ' ' ? "l:%06"PRIdPTRDIFF" " : "l:%06"PRIxPTRDIFF" ", lfp % 10000);
- fprintf(stderr, dfp_in_heap == ' ' ? "d:%06"PRIdPTRDIFF" " : "d:%06"PRIxPTRDIFF" ", dfp % 10000);
+ fprintf(stderr, ep_in_heap == ' ' ? "e:%06"PRIdPTRDIFF" " : "e:%06"PRIxPTRDIFF" ", ep % 10000);
fprintf(stderr, "%-6s", magic);
if (line && !nopos) {
fprintf(stderr, " %s", posbuf);
@@ -152,9 +146,7 @@ void
rb_vmdebug_stack_dump_raw(rb_thread_t *th, rb_control_frame_t *cfp)
{
#if 0
- VALUE *sp = cfp->sp, *bp = cfp->bp;
- VALUE *lfp = cfp->lfp;
- VALUE *dfp = cfp->dfp;
+ VALUE *sp = cfp->sp, *bp = cfp->bp, *ep = cfp->ep;
VALUE *p, *st, *t;
fprintf(stderr, "-- stack frame ------------\n");
@@ -166,10 +158,8 @@ rb_vmdebug_stack_dump_raw(rb_thread_t *th, rb_control_frame_t *cfp)
fprintf(stderr, " (= %ld)", (long)((VALUE *)GC_GUARDED_PTR_REF(t) - th->stack));
}
- if (p == lfp)
- fprintf(stderr, " <- lfp");
- if (p == dfp)
- fprintf(stderr, " <- dfp");
+ if (p == ep)
+ fprintf(stderr, " <- ep");
if (p == bp)
fprintf(stderr, " <- bp"); /* should not be */
@@ -194,7 +184,7 @@ rb_vmdebug_stack_dump_raw_current(void)
}
void
-rb_vmdebug_env_dump_raw(rb_env_t *env, VALUE *lfp, VALUE *dfp)
+rb_vmdebug_env_dump_raw(rb_env_t *env, VALUE *ep)
{
int i;
fprintf(stderr, "-- env --------------------\n");
@@ -204,10 +194,8 @@ rb_vmdebug_env_dump_raw(rb_env_t *env, VALUE *lfp, VALUE *dfp)
for (i = 0; i < env->env_size; i++) {
fprintf(stderr, "%04d: %08"PRIxVALUE" (%p)", -env->local_size + i, env->env[i],
(void *)&env->env[i]);
- if (&env->env[i] == lfp)
- fprintf(stderr, " <- lfp");
- if (&env->env[i] == dfp)
- fprintf(stderr, " <- dfp");
+ if (&env->env[i] == ep)
+ fprintf(stderr, " <- ep");
fprintf(stderr, "\n");
}
@@ -232,7 +220,7 @@ rb_vmdebug_proc_dump_raw(rb_proc_t *proc)
fprintf(stderr, "-- proc -------------------\n");
fprintf(stderr, "self: %s\n", selfstr);
GetEnvPtr(proc->envval, env);
- rb_vmdebug_env_dump_raw(env, proc->block.lfp, proc->block.dfp);
+ rb_vmdebug_env_dump_raw(env, proc->block.ep);
}
void
@@ -251,8 +239,7 @@ vm_stack_dump_each(rb_thread_t *th, rb_control_frame_t *cfp)
VALUE rstr;
VALUE *sp = cfp->sp;
- VALUE *lfp = cfp->lfp;
- VALUE *dfp = cfp->dfp;
+ VALUE *ep = cfp->ep;
int argc = 0, local_size = 0;
const char *name;
@@ -287,14 +274,11 @@ vm_stack_dump_each(rb_thread_t *th, rb_control_frame_t *cfp)
VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_IFUNC ||
VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_EVAL) {
- VALUE *ptr = dfp - local_size;
+ VALUE *ptr = ep - local_size;
vm_stack_dump_each(th, cfp + 1);
control_frame_dump(th, cfp);
- if (lfp != dfp) {
- local_size++;
- }
for (i = 0; i < argc; i++) {
rstr = rb_inspect(*ptr);
fprintf(stderr, " arg %2d: %8s (%p)\n", i, StringValueCStr(rstr),
@@ -337,22 +321,20 @@ rb_vmdebug_debug_print_register(rb_thread_t *th)
{
rb_control_frame_t *cfp = th->cfp;
ptrdiff_t pc = -1;
- ptrdiff_t lfp = cfp->lfp - th->stack;
- ptrdiff_t dfp = cfp->dfp - th->stack;
+ ptrdiff_t ep = cfp->ep - th->stack;
ptrdiff_t cfpi;
if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) {
pc = cfp->pc - cfp->iseq->iseq_encoded;
}
- if (lfp < 0 || (size_t)lfp > th->stack_size)
- lfp = -1;
- if (dfp < 0 || (size_t)dfp > th->stack_size)
- dfp = -1;
+ if (ep < 0 || (size_t)ep > th->stack_size) {
+ ep = -1;
+ }
cfpi = ((rb_control_frame_t *)(th->stack + th->stack_size)) - cfp;
- fprintf(stderr, " [PC] %04"PRIdPTRDIFF", [SP] %04"PRIdPTRDIFF", [LFP] %04"PRIdPTRDIFF", [DFP] %04"PRIdPTRDIFF", [CFP] %04"PRIdPTRDIFF"\n",
- pc, (cfp->sp - th->stack), lfp, dfp, cfpi);
+ fprintf(stderr, " [PC] %04"PRIdPTRDIFF", [SP] %04"PRIdPTRDIFF", [EP] %04"PRIdPTRDIFF", [CFP] %04"PRIdPTRDIFF"\n",
+ pc, (cfp->sp - th->stack), ep, cfpi);
}
void
@@ -371,8 +353,13 @@ rb_vmdebug_debug_print_pre(rb_thread_t *th, rb_control_frame_t *cfp)
if (iseq != 0 && VM_FRAME_TYPE(cfp) != VM_FRAME_MAGIC_FINISH) {
VALUE *seq = iseq->iseq;
ptrdiff_t pc = cfp->pc - iseq->iseq_encoded;
+ int i;
- printf("%3"PRIdPTRDIFF" ", VM_CFP_CNT(th, cfp));
+ for (i=0; i<(int)VM_CFP_CNT(th, cfp); i++) {
+ printf(" ");
+ }
+ printf("| ");
+ /* printf("%3"PRIdPTRDIFF" ", VM_CFP_CNT(th, cfp)); */
if (pc >= 0) {
rb_iseq_disasm_insn(0, seq, (size_t)pc, iseq, 0);
}
@@ -518,11 +505,10 @@ vm_analysis_register(int reg, int isset)
static const char regstrs[][5] = {
"pc", /* 0 */
"sp", /* 1 */
- "cfp", /* 2 */
- "lfp", /* 3 */
- "dfp", /* 4 */
- "self", /* 5 */
- "iseq", /* 6 */
+ "ep", /* 2 */
+ "cfp", /* 3 */
+ "self", /* 4 */
+ "iseq", /* 5 */
};
static const char getsetstr[][4] = {
"get",
@@ -568,7 +554,7 @@ rb_vmdebug_thread_dump_state(VALUE self)
fprintf(stderr, "Thread state dump:\n");
fprintf(stderr, "pc : %p, sp : %p\n", (void *)cfp->pc, (void *)cfp->sp);
- fprintf(stderr, "cfp: %p, lfp: %p, dfp: %p\n", (void *)cfp, (void *)cfp->lfp, (void *)cfp->dfp);
+ fprintf(stderr, "cfp: %p, ep : %p\n", (void *)cfp, (void *)cfp->ep);
return Qnil;
}