diff --git a/src/mdb_v8.c b/src/mdb_v8.c index f4ca854..c959a8a 100644 --- a/src/mdb_v8.c +++ b/src/mdb_v8.c @@ -361,12 +361,12 @@ static v8_constant_t v8_constants[] = { V8_CONSTANT_FALLBACK(3, 7), 2 }, { &V8_SCOPEINFO_OFFSET_STACK_LOCALS, "v8dbg_scopeinfo_offset_stack_locals", - V8_CONSTANT_ADDED_SINCE(4, 4) }, + V8_CONSTANT_FALLBACK(4, 4), 1 }, { &V8_SCOPEINFO_IDX_NCONTEXTLOCALS, "v8dbg_scopeinfo_idx_ncontextlocals", V8_CONSTANT_FALLBACK(3, 7), 3 }, { &V8_SCOPEINFO_IDX_FIRST_VARS, "v8dbg_scopeinfo_idx_first_vars", - V8_CONSTANT_FALLBACK(3, 7), 4 }, + V8_CONSTANT_FALLBACK(4, 5), 6 }, }; static int v8_nconstants = sizeof (v8_constants) / sizeof (v8_constants[0]); @@ -809,6 +809,24 @@ autoconfigure(v8_cfg_t *cfgp) if (V8_OFF_MAP_BIT_FIELD2 == -1) V8_OFF_MAP_BIT_FIELD2 = V8_OFF_MAP_INSTANCE_ATTRIBUTES + 3; + /* + * V8_SCOPEINFO_IDX_FIRST_VARS' value was 4 in V8 3.7 and up, + * then 5 when StrongModeFreeVariableCount was added with + * https://codereview.chromium.org/1005063002, and 6 when + * ContextGlobalCount was added with + * https://codereview.chromium.org/1218783005. + * Since the current V8_CONSTANT_FALLBACK macro doesn't allow + * us to specify different values for different V8 versions, + * these are hardcoded below. + */ + if (V8_SCOPEINFO_IDX_FIRST_VARS == -1) { + if (v8_major > 4 || (v8_major == 4 && v8_minor >= 3)) { + V8_SCOPEINFO_IDX_FIRST_VARS = 5; + } else if (v8_major > 3 || (v8_major == 3 && v8_minor >= 7)) { + V8_SCOPEINFO_IDX_FIRST_VARS = 4; + } + } + return (failed ? -1 : 0); } diff --git a/src/mdb_v8_context.c b/src/mdb_v8_context.c index 0478a7a..5edd6ab 100644 --- a/src/mdb_v8_context.c +++ b/src/mdb_v8_context.c @@ -387,19 +387,8 @@ v8scopeinfo_iter_vars(v8scopeinfo_t *sip, 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. + * Skip to the start of the ScopeInfo's dynamic part. See mdb_v8_db.h + * for more details on the layout of ScopeInfo objects. */ nskip = V8_SCOPEINFO_IDX_FIRST_VARS; @@ -425,8 +414,8 @@ v8scopeinfo_iter_vars(v8scopeinfo_t *sip, } /* - * The current variable type is the one we're interested in, - * do not add anything to the offset, we're done. + * If 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; @@ -435,9 +424,8 @@ v8scopeinfo_iter_vars(v8scopeinfo_t *sip, /* * 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. + * layout. Add the number of entries for this variable type to + * the offset. */ nskip += v8scopeinfo_vartype_nvars(sip, ogrp->v8vti_vartype); }