Skip to content

Commit

Permalink
TritonDataCenter#23 support V8 4.4.x and 4.5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Gilli committed Sep 8, 2015
1 parent 5af967f commit 18ae78f
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

## Unreleased changes

* #23 support V8 4.4.x and 4.5.x

* #25 fix ia32 build

* #20 want ::jsfunctions -l
Expand Down
75 changes: 61 additions & 14 deletions src/mdb_v8.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ intptr_t V8_NotStringTag;
intptr_t V8_StringEncodingMask;
intptr_t V8_TwoByteStringTag;
intptr_t V8_AsciiStringTag;
intptr_t V8_OneByteStringTag;
intptr_t V8_StringRepresentationMask;
intptr_t V8_SeqStringTag;
intptr_t V8_ConsStringTag;
Expand All @@ -130,8 +131,8 @@ static intptr_t V8_DICT_SHIFT;
static intptr_t V8_DICT_PREFIX_SIZE;
static intptr_t V8_DICT_ENTRY_SIZE;
static intptr_t V8_DICT_START_INDEX;
static intptr_t V8_FIELDINDEX_MASK;
static intptr_t V8_FIELDINDEX_SHIFT;
static intptr_t V8_PROPINDEX_MASK;
static intptr_t V8_PROPINDEX_SHIFT;
static intptr_t V8_PROP_IDX_CONTENT;
static intptr_t V8_PROP_IDX_FIRST;
static intptr_t V8_PROP_TYPE_FIELD;
Expand Down Expand Up @@ -225,13 +226,14 @@ ssize_t V8_OFF_STRING_LENGTH;
#define V8_CONSTANT_OPTIONAL 1
#define V8_CONSTANT_HASFALLBACK 2
#define V8_CONSTANT_REMOVED 4
#define V8_CONSTANT_ADDED 8

#define V8_CONSTANT_MAJORSHIFT 3
#define V8_CONSTANT_MAJORSHIFT 4
#define V8_CONSTANT_MAJORMASK ((1 << 4) - 1)
#define V8_CONSTANT_MAJOR(flags) \
(((flags) >> V8_CONSTANT_MAJORSHIFT) & V8_CONSTANT_MAJORMASK)

#define V8_CONSTANT_MINORSHIFT 7
#define V8_CONSTANT_MINORSHIFT 8
#define V8_CONSTANT_MINORMASK ((1 << 9) - 1)
#define V8_CONSTANT_MINOR(flags) \
(((flags) >> V8_CONSTANT_MINORSHIFT) & V8_CONSTANT_MINORMASK)
Expand All @@ -244,6 +246,10 @@ ssize_t V8_OFF_STRING_LENGTH;
(V8_CONSTANT_REMOVED | \
((maj) << V8_CONSTANT_MAJORSHIFT) | ((min) << V8_CONSTANT_MINORSHIFT))

#define V8_CONSTANT_ADDED_SINCE(maj, min) \
(V8_CONSTANT_ADDED | \
((maj) << V8_CONSTANT_MAJORSHIFT) | ((min) << V8_CONSTANT_MINORSHIFT))

/*
* Table of constants used directly by this file.
*/
Expand All @@ -266,7 +272,10 @@ static v8_constant_t v8_constants[] = {
{ &V8_NotStringTag, "v8dbg_NotStringTag" },
{ &V8_StringEncodingMask, "v8dbg_StringEncodingMask" },
{ &V8_TwoByteStringTag, "v8dbg_TwoByteStringTag" },
{ &V8_AsciiStringTag, "v8dbg_AsciiStringTag" },
{ &V8_AsciiStringTag, "v8dbg_AsciiStringTag",
V8_CONSTANT_REMOVED_SINCE(3, 29) },
{ &V8_OneByteStringTag, "v8dbg_OneByteStringTag",
V8_CONSTANT_ADDED_SINCE(3, 29) },
{ &V8_StringRepresentationMask, "v8dbg_StringRepresentationMask" },
{ &V8_SeqStringTag, "v8dbg_SeqStringTag" },
{ &V8_ConsStringTag, "v8dbg_ConsStringTag" },
Expand Down Expand Up @@ -298,9 +307,9 @@ static v8_constant_t v8_constants[] = {
V8_CONSTANT_FALLBACK(3, 11), 3 },
{ &V8_DICT_START_INDEX, "v8dbg_dict_start_index",
V8_CONSTANT_FALLBACK(3, 11), 3 },
{ &V8_FIELDINDEX_MASK, "v8dbg_fieldindex_mask",
{ &V8_PROPINDEX_MASK, "v8dbg_propindex_mask",
V8_CONSTANT_FALLBACK(3, 26), 0x3ff00000 },
{ &V8_FIELDINDEX_SHIFT, "v8dbg_fieldindex_shift",
{ &V8_PROPINDEX_SHIFT, "v8dbg_propindex_shift",
V8_CONSTANT_FALLBACK(3, 26), 20 },
{ &V8_ISSHARED_SHIFT, "v8dbg_isshared_shift",
V8_CONSTANT_FALLBACK(3, 11), 0 },
Expand Down Expand Up @@ -363,6 +372,7 @@ typedef struct v8_offset {
const char *v8o_class;
const char *v8o_member;
boolean_t v8o_optional;
uint32_t v8o_flags;
} v8_offset_t;

static v8_offset_t v8_offsets[] = {
Expand Down Expand Up @@ -399,7 +409,11 @@ static v8_offset_t v8_offsets[] = {
{ &V8_OFF_JSREGEXP_DATA,
"JSRegExp", "data", B_TRUE },
{ &V8_OFF_MAP_CONSTRUCTOR,
"Map", "constructor" },
"Map", "constructor",
B_FALSE, V8_CONSTANT_REMOVED_SINCE(4, 3)},
{ &V8_OFF_MAP_CONSTRUCTOR,
"Map", "constructor_or_backpointer",
B_FALSE, V8_CONSTANT_ADDED_SINCE(4, 3)},
{ &V8_OFF_MAP_INOBJECT_PROPERTIES,
"Map", "inobject_properties" },
{ &V8_OFF_MAP_INSTANCE_ATTRIBUTES,
Expand Down Expand Up @@ -539,6 +553,18 @@ v8_version_older(uintptr_t v8_major, uintptr_t v8_minor, uint32_t flags) {
v8_minor < V8_CONSTANT_MINOR(flags)));
}

/*
* Returns 1 if the V8 version v8_major.v8.minor is newer or equal than
* the V8 version represented by "flags".
* Returns 0 otherwise.
*/
static int
v8_version_at_least(uintptr_t v8_major, uintptr_t v8_minor, uint32_t flags) {
return (v8_major > V8_CONSTANT_MAJOR(flags) ||
(v8_major == V8_CONSTANT_MAJOR(flags) &&
v8_minor >= V8_CONSTANT_MINOR(flags)));
}

/*
* Invoked when this dmod is initially loaded to load the set of classes, enums,
* and other constants from the metadata in the target binary.
Expand All @@ -551,6 +577,9 @@ autoconfigure(v8_cfg_t *cfgp)
struct v8_constant *cnp;
int ii;
int failed = 0;
int constant_optional, constant_removed, constant_added;
int offset_optional, offset_removed, offset_added;
int v8_older, v8_at_least;

assert(v8_classes == NULL);

Expand Down Expand Up @@ -585,9 +614,16 @@ autoconfigure(v8_cfg_t *cfgp)
continue;
}

if (!(cnp->v8c_flags & V8_CONSTANT_OPTIONAL) &&
(!(cnp->v8c_flags & V8_CONSTANT_REMOVED) ||
v8_version_older(v8_major, v8_minor, cnp->v8c_flags))) {
constant_optional = cnp->v8c_flags & V8_CONSTANT_OPTIONAL;
constant_removed = cnp->v8c_flags & V8_CONSTANT_REMOVED;
constant_added = cnp->v8c_flags & V8_CONSTANT_ADDED;
v8_older = v8_version_older(v8_major, v8_minor, cnp->v8c_flags);
v8_at_least = v8_version_at_least(v8_major,
v8_minor, cnp->v8c_flags);

if (!constant_optional &&
(!constant_removed || v8_older) &&
(!constant_added || v8_at_least)) {
mdb_warn("failed to read \"%s\"", cnp->v8c_symbol);
failed++;
continue;
Expand Down Expand Up @@ -712,9 +748,20 @@ autoconfigure(v8_cfg_t *cfgp)
continue;
}

mdb_warn("couldn't find class \"%s\", field \"%s\"\n",
offp->v8o_class, offp->v8o_member);
failed++;
offset_optional = offp->v8o_flags & V8_CONSTANT_OPTIONAL;
offset_removed = offp->v8o_flags & V8_CONSTANT_REMOVED;
offset_added = offp->v8o_flags & V8_CONSTANT_ADDED;
v8_older = v8_version_older(v8_major, v8_minor, cnp->v8c_flags);
v8_at_least = v8_version_at_least(v8_major,
v8_minor, offp->v8o_flags);

if (!offset_optional &&
(!offset_removed || v8_older) &&
(!offset_added || v8_at_least)) {
mdb_warn("couldn't find class \"%s\", field \"%s\"\n",
offp->v8o_class, offp->v8o_member);
failed++;
}
}

if (!((V8_OFF_SEQASCIISTR_CHARS != -1) ^
Expand Down
5 changes: 3 additions & 2 deletions src/v8dbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
#define V8_TYPE_STRING(type) (((type) & V8_IsNotStringMask) == V8_StringTag)

#define V8_STRENC_ASCII(type) \
(((type) & V8_StringEncodingMask) == V8_AsciiStringTag)
(((type) & V8_StringEncodingMask) == V8_AsciiStringTag || \
((type) & V8_StringEncodingMask) == V8_OneByteStringTag)

#define V8_STRREP_SEQ(type) \
(((type) & V8_StringRepresentationMask) == V8_SeqStringTag)
Expand All @@ -72,6 +73,6 @@
((V8_SMI_VALUE(x) & V8_PROP_TYPE_MASK) == V8_PROP_TYPE_FIELD)

#define V8_PROP_FIELDINDEX(value) \
((V8_SMI_VALUE(value) & V8_FIELDINDEX_MASK) >> V8_FIELDINDEX_SHIFT)
((V8_SMI_VALUE(value) & V8_PROPINDEX_MASK) >> V8_PROPINDEX_SHIFT)

#endif /* _V8DBG_H */
2 changes: 1 addition & 1 deletion test/standalone/tst.postmortem_details.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ gcore.on('exit', function (code) {

var mdb = spawn('mdb', args, { stdio: 'pipe' });

mdb.on('exit', function (code2) {
mdb.stdin.on('end', function (code2) {
unlinkSync(tmpfile);
var retained = '; core retained as ' + corefile;

Expand Down
2 changes: 1 addition & 1 deletion test/standalone/tst.postmortem_findjsobjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ gcore.on('exit', function (code) {

var mdb = spawn('mdb', args, { stdio: 'pipe' });

mdb.on('exit', function (code2) {
mdb.stdin.on('end', function (code2) {
var retained = '; core retained as ' + corefile;

if (code2 != 0) {
Expand Down

0 comments on commit 18ae78f

Please sign in to comment.