Skip to content

Commit b438426

Browse files
author
Julien Gilli
committed
#23: do not rely on V8's metadata
Hardcode handling of V8_SCOPEINFO_IDX_FIRST_VARS' fallback value for different versions of V8. Do not rely on V8's metadata for getting V8_SCOPEINFO_OFFSET_STACK_LOCALS' value, use V8_CONSTANT_FALLBACK instead.
1 parent ccda2ad commit b438426

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

src/mdb_v8.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,12 @@ static v8_constant_t v8_constants[] = {
361361
V8_CONSTANT_FALLBACK(3, 7), 2 },
362362
{ &V8_SCOPEINFO_OFFSET_STACK_LOCALS,
363363
"v8dbg_scopeinfo_offset_stack_locals",
364-
V8_CONSTANT_ADDED_SINCE(4, 4) },
364+
V8_CONSTANT_FALLBACK(4, 4), 1 },
365365
{ &V8_SCOPEINFO_IDX_NCONTEXTLOCALS,
366366
"v8dbg_scopeinfo_idx_ncontextlocals",
367367
V8_CONSTANT_FALLBACK(3, 7), 3 },
368368
{ &V8_SCOPEINFO_IDX_FIRST_VARS, "v8dbg_scopeinfo_idx_first_vars",
369-
V8_CONSTANT_FALLBACK(3, 7), 4 },
369+
V8_CONSTANT_FALLBACK(4, 5), 6 },
370370
};
371371

372372
static int v8_nconstants = sizeof (v8_constants) / sizeof (v8_constants[0]);
@@ -809,6 +809,24 @@ autoconfigure(v8_cfg_t *cfgp)
809809
if (V8_OFF_MAP_BIT_FIELD2 == -1)
810810
V8_OFF_MAP_BIT_FIELD2 = V8_OFF_MAP_INSTANCE_ATTRIBUTES + 3;
811811

812+
/*
813+
* V8_SCOPEINFO_IDX_FIRST_VARS' value was 4 in V8 3.7 and up,
814+
* then 5 when StrongModeFreeVariableCount was added with
815+
* https://codereview.chromium.org/1005063002, and 6 when
816+
* ContextGlobalCount was added with
817+
* https://codereview.chromium.org/1218783005.
818+
* Since the current V8_CONSTANT_FALLBACK macro doesn't allow
819+
* us to specify different values for different V8 versions,
820+
* these are hardcoded below.
821+
*/
822+
if (V8_SCOPEINFO_IDX_FIRST_VARS == -1) {
823+
if (v8_major > 4 || (v8_major == 4 && v8_minor >= 3)) {
824+
V8_SCOPEINFO_IDX_FIRST_VARS = 5;
825+
} else if (v8_major > 3 || (v8_major == 3 && v8_minor >= 7)) {
826+
V8_SCOPEINFO_IDX_FIRST_VARS = 4;
827+
}
828+
}
829+
812830
return (failed ? -1 : 0);
813831
}
814832

src/mdb_v8_context.c

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -387,19 +387,8 @@ v8scopeinfo_iter_vars(v8scopeinfo_t *sip,
387387
nvars = v8scopeinfo_vartype_nvars(sip, scopevartype);
388388

389389
/*
390-
* A ScopeInfo instance has two distinct parts:
391-
*
392-
* 1) A static part that contains information about the number of
393-
* entries for each variable type.
394-
*
395-
* 2) A dynamic part of variable size that contains the actual data for
396-
* each variable type (parameters, stack local and context local
397-
* entries' names).
398-
*
399-
* V8_SCOPEINFO_IDX_FIRST_VARS is the offset from the beginning of the
400-
* ScopeInfo layout to the start of the variable part that contains the
401-
* actual information for each variable type, so we start by skipping to
402-
* that offset.
390+
* Skip to the start of the ScopeInfo's dynamic part. See mdb_v8_db.h
391+
* for more details on the layout of ScopeInfo objects.
403392
*/
404393
nskip = V8_SCOPEINFO_IDX_FIRST_VARS;
405394

@@ -425,8 +414,8 @@ v8scopeinfo_iter_vars(v8scopeinfo_t *sip,
425414
}
426415

427416
/*
428-
* The current variable type is the one we're interested in,
429-
* do not add anything to the offset, we're done.
417+
* If the current variable type is the one we're interested in,
418+
* do not add anything to the offset. We're done.
430419
*/
431420
if (*(ogrp->v8vti_idx_countp) == *(vtip->v8vti_idx_countp)) {
432421
break;
@@ -435,9 +424,8 @@ v8scopeinfo_iter_vars(v8scopeinfo_t *sip,
435424
/*
436425
* The data for the current variable type is before the one
437426
* we're interested in in the variable part of the ScopeInfo
438-
* layout.
439-
* Add the number of entries for this variable type to the
440-
* offset.
427+
* layout. Add the number of entries for this variable type to
428+
* the offset.
441429
*/
442430
nskip += v8scopeinfo_vartype_nvars(sip, ogrp->v8vti_vartype);
443431
}

0 commit comments

Comments
 (0)