Skip to content

Commit

Permalink
#23: fix scopeinfo for v8 > 3.28.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Gilli committed Sep 8, 2015
1 parent 0d17bf7 commit ccda2ad
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/mdb_v8.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ intptr_t V8_CONTEXT_IDX_GLOBAL;

intptr_t V8_SCOPEINFO_IDX_NPARAMS;
intptr_t V8_SCOPEINFO_IDX_NSTACKLOCALS;
intptr_t V8_SCOPEINFO_OFFSET_STACK_LOCALS;
intptr_t V8_SCOPEINFO_IDX_NCONTEXTLOCALS;
intptr_t V8_SCOPEINFO_IDX_FIRST_VARS;

Expand Down Expand Up @@ -355,14 +356,17 @@ static v8_constant_t v8_constants[] = {
V8_CONSTANT_FALLBACK(0, 0), 3 },

{ &V8_SCOPEINFO_IDX_NPARAMS, "v8dbg_scopeinfo_idx_nparams",
V8_CONSTANT_FALLBACK(0, 0), 1 },
V8_CONSTANT_FALLBACK(3, 7), 1 },
{ &V8_SCOPEINFO_IDX_NSTACKLOCALS, "v8dbg_scopeinfo_idx_nstacklocals",
V8_CONSTANT_FALLBACK(0, 0), 2 },
V8_CONSTANT_FALLBACK(3, 7), 2 },
{ &V8_SCOPEINFO_OFFSET_STACK_LOCALS,
"v8dbg_scopeinfo_offset_stack_locals",
V8_CONSTANT_ADDED_SINCE(4, 4) },
{ &V8_SCOPEINFO_IDX_NCONTEXTLOCALS,
"v8dbg_scopeinfo_idx_ncontextlocals",
V8_CONSTANT_FALLBACK(0, 0), 3 },
V8_CONSTANT_FALLBACK(3, 7), 3 },
{ &V8_SCOPEINFO_IDX_FIRST_VARS, "v8dbg_scopeinfo_idx_first_vars",
V8_CONSTANT_FALLBACK(0, 0), 4 },
V8_CONSTANT_FALLBACK(3, 7), 4 },
};

static int v8_nconstants = sizeof (v8_constants) / sizeof (v8_constants[0]);
Expand Down
53 changes: 50 additions & 3 deletions src/mdb_v8_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ typedef struct {
v8scopeinfo_vartype_t v8vti_vartype;
const char *v8vti_label;
intptr_t *v8vti_idx_countp;
intptr_t *v8vti_offset;
} v8scopeinfo_vartype_info_t;

static v8scopeinfo_vartype_info_t v8scopeinfo_vartypes[] = {
{ V8SV_PARAMS, "parameter", &V8_SCOPEINFO_IDX_NPARAMS },
{ V8SV_STACKLOCALS, "stack local variable",
&V8_SCOPEINFO_IDX_NSTACKLOCALS },
&V8_SCOPEINFO_IDX_NSTACKLOCALS, &V8_SCOPEINFO_OFFSET_STACK_LOCALS },
{ V8SV_CONTEXTLOCALS, "context local variable",
&V8_SCOPEINFO_IDX_NCONTEXTLOCALS },
};
Expand Down Expand Up @@ -385,13 +386,59 @@ v8scopeinfo_iter_vars(v8scopeinfo_t *sip,
assert(vtip != NULL);
nvars = v8scopeinfo_vartype_nvars(sip, scopevartype);

/*
* A ScopeInfo instance has two distinct parts:
*
* 1) A static part that contains information about the number of
* entries for each variable type.
*
* 2) A dynamic part of variable size that contains the actual data for
* each variable type (parameters, stack local and context local
* entries' names).
*
* V8_SCOPEINFO_IDX_FIRST_VARS is the offset from the beginning of the
* ScopeInfo layout to the start of the variable part that contains the
* actual information for each variable type, so we start by skipping to
* that offset.
*/
nskip = V8_SCOPEINFO_IDX_FIRST_VARS;

/*
* Iterate over variable types so that we can add the offset from the
* beginning of the actual data (the dynamic part) to the region of the
* dynamic part that is specific to the variable type we're interested
* in.
*/
for (i = 0; i < v8scopeinfo_nvartypes; i++) {
ogrp = &v8scopeinfo_vartypes[i];
if (*(ogrp->v8vti_idx_countp) >= *(vtip->v8vti_idx_countp)) {
continue;

/*
* In the variable/dynamic part of a ScopeInfo layout, some
* variable types have static metadata, e.g stack local entries
* have a StackLocalFirstSlot, before the actual data. Add that
* offset for each variable type, including for the one we're
* interested in.
*/
if (v8scopeinfo_vartypes[i].v8vti_offset != NULL &&
*(v8scopeinfo_vartypes[i].v8vti_offset) != -1) {
nskip += *(v8scopeinfo_vartypes[i].v8vti_offset);
}

/*
* The current variable type is the one we're interested in,
* do not add anything to the offset, we're done.
*/
if (*(ogrp->v8vti_idx_countp) == *(vtip->v8vti_idx_countp)) {
break;
}

/*
* The data for the current variable type is before the one
* we're interested in in the variable part of the ScopeInfo
* layout.
* Add the number of entries for this variable type to the
* offset.
*/
nskip += v8scopeinfo_vartype_nvars(sip, ogrp->v8vti_vartype);
}

Expand Down
1 change: 1 addition & 0 deletions src/mdb_v8_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ extern intptr_t V8_SCOPEINFO_IDX_FIRST_VARS;
extern intptr_t V8_SCOPEINFO_IDX_NCONTEXTLOCALS;
extern intptr_t V8_SCOPEINFO_IDX_NPARAMS;
extern intptr_t V8_SCOPEINFO_IDX_NSTACKLOCALS;
extern intptr_t V8_SCOPEINFO_OFFSET_STACK_LOCALS;

extern intptr_t V8_HeapObjectTag;
extern intptr_t V8_HeapObjectTagMask;
Expand Down

0 comments on commit ccda2ad

Please sign in to comment.