Skip to content

Commit

Permalink
TritonDataCenter#32: WIP fix buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
misterdjules committed Sep 4, 2015
1 parent c8b09cb commit 15421a2
Showing 1 changed file with 71 additions and 4 deletions.
75 changes: 71 additions & 4 deletions src/mdb_v8.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ intptr_t V8_TYPE_HEAPNUMBER = -1;
intptr_t V8_TYPE_ODDBALL = -1;
intptr_t V8_TYPE_FIXEDARRAY = -1;
intptr_t V8_TYPE_MAP = -1;
intptr_t V8_TYPE_JSTYPEDARRAY = -1;

static intptr_t V8_ELEMENTS_KIND_SHIFT;
static intptr_t V8_ELEMENTS_KIND_BITCOUNT;
Expand Down Expand Up @@ -221,6 +222,9 @@ ssize_t V8_OFF_SHAREDFUNCTIONINFO_NAME;
ssize_t V8_OFF_SLICEDSTRING_PARENT;
ssize_t V8_OFF_SLICEDSTRING_OFFSET;
ssize_t V8_OFF_STRING_LENGTH;
ssize_t V8_OFF_JSARRAYBUFFERVIEW_BUFFER;
ssize_t V8_OFF_JSTYPEDARRAY_LENGTH;
ssize_t V8_OFF_JSARRAYBUFFER_BACKINGSTORE;

/* see node_string.h */
#define NODE_OFF_EXTSTR_DATA sizeof (uintptr_t)
Expand Down Expand Up @@ -469,6 +473,12 @@ static v8_offset_t v8_offsets[] = {
"SlicedString", "parent", B_TRUE },
{ &V8_OFF_STRING_LENGTH,
"String", "length" },
{ &V8_OFF_JSARRAYBUFFERVIEW_BUFFER,
"JSArrayBufferView", "buffer" },
{ &V8_OFF_JSTYPEDARRAY_LENGTH,
"JSTypedArray", "length" },
{ &V8_OFF_JSARRAYBUFFER_BACKINGSTORE,
"JSArrayBuffer", "backing_store" },
};

static int v8_noffsets = sizeof (v8_offsets) / sizeof (v8_offsets[0]);
Expand Down Expand Up @@ -542,6 +552,7 @@ static int jsobj_print_number(uintptr_t, jsobj_print_t *);
static int jsobj_print_oddball(uintptr_t, jsobj_print_t *);
static int jsobj_print_jsobject(uintptr_t, jsobj_print_t *);
static int jsobj_print_jsarray(uintptr_t, jsobj_print_t *);
static int jsobj_print_jstyped_array(uintptr_t, jsobj_print_t *);
static int jsobj_print_jsfunction(uintptr_t, jsobj_print_t *);
static int jsobj_print_jsdate(uintptr_t, jsobj_print_t *);
static int jsobj_print_jsregexp(uintptr_t, jsobj_print_t *);
Expand Down Expand Up @@ -616,6 +627,7 @@ autoconfigure(v8_cfg_t *cfgp)

if (cfgp->v8cfg_readsym(cfgp,
cnp->v8c_symbol, cnp->v8c_valp) != -1) {
printf("%s = %" PRIdPTR "\n", cnp->v8c_symbol, *cnp->v8c_valp);
continue;
}

Expand Down Expand Up @@ -688,6 +700,9 @@ autoconfigure(v8_cfg_t *cfgp)

if (strcmp(ep->v8e_name, "Map") == 0)
V8_TYPE_MAP = ep->v8e_value;

if (strcmp(ep->v8e_name, "JSTypedArray") == 0)
V8_TYPE_JSTYPEDARRAY = ep->v8e_value;
}

if (V8_TYPE_JSOBJECT == -1) {
Expand Down Expand Up @@ -736,8 +751,10 @@ autoconfigure(v8_cfg_t *cfgp)
const char *klass = offp->v8o_class;

again:
if (heap_offset(klass, offp->v8o_member, offp->v8o_valp) == 0)
if (heap_offset(klass, offp->v8o_member, offp->v8o_valp) == 0) {
printf("%s::%s = %" PRIdPTR "\n", klass, offp->v8o_member, *offp->v8o_valp);
continue;
}

if (strcmp(klass, "FixedArray") == 0) {
/*
Expand Down Expand Up @@ -1574,7 +1591,7 @@ obj_jsconstructor(uintptr_t addr, char **bufp, size_t *lenp, boolean_t verbose)

if (!V8_IS_HEAPOBJECT(addr) ||
read_typebyte(&type, addr) != 0 ||
(type != V8_TYPE_JSOBJECT && type != V8_TYPE_JSARRAY)) {
(type != V8_TYPE_JSOBJECT && type != V8_TYPE_JSARRAY && type != V8_TYPE_JSTYPEDARRAY)) {
mdb_warn("%p is not a JSObject\n", addr);
return (-1);
}
Expand Down Expand Up @@ -2239,7 +2256,8 @@ jsobj_maybe_garbage(uintptr_t addr)
type != V8_TYPE_JSARRAY &&
type != V8_TYPE_JSFUNCTION &&
type != V8_TYPE_JSDATE &&
type != V8_TYPE_JSREGEXP)));
type != V8_TYPE_JSREGEXP &&
type != V8_TYPE_JSTYPEDARRAY)));
}

/*
Expand Down Expand Up @@ -3063,6 +3081,7 @@ jsobj_print(uintptr_t addr, jsobj_print_t *jsop)
{ "Oddball", jsobj_print_oddball },
{ "JSObject", jsobj_print_jsobject },
{ "JSArray", jsobj_print_jsarray },
{ "JSTypedArray", jsobj_print_jstyped_array },
{ "JSFunction", jsobj_print_jsfunction },
{ "JSDate", jsobj_print_jsdate },
{ "JSRegExp", jsobj_print_jsregexp },
Expand Down Expand Up @@ -3404,6 +3423,29 @@ jsobj_print_jsarray(uintptr_t addr, jsobj_print_t *jsop)
return (0);
}

static int
jsobj_print_jstyped_array(uintptr_t addr, jsobj_print_t *jsop)
{
char **bufp = jsop->jsop_bufp;
size_t *lenp = jsop->jsop_lenp;
int indent = jsop->jsop_indent;
uintptr_t length;

if (read_heap_smi(&length, addr, V8_OFF_JSTYPEDARRAY_LENGTH) != 0) {
(void) bsnprintf(bufp, lenp,
"<array (failed to read jstypedarray length)>");
return (-1);
}

(void) bsnprintf(bufp, lenp, "{\n");
(void) bsnprintf(bufp, lenp, "%*s", indent + 4, "");
(void) bsnprintf(bufp, lenp, "\"length\": %d\n", (int)length);
(void) bsnprintf(bufp, lenp, "%*s", indent, "");
(void) bsnprintf(bufp, lenp, "}");

return (0);
}

static int
jsobj_print_jsfunction(uintptr_t addr, jsobj_print_t *jsop)
{
Expand Down Expand Up @@ -5310,6 +5352,31 @@ dcmd_findjsobjects(uintptr_t addr,
return (DCMD_OK);
}

/*
static int
print_nodebuffer_jstypedarray(uintptr_t addr)
{
uintptr_t buffer;
uintptr_t buffer_backing_store;
printf("Reading buffer address at 0x%016" PRIXPTR "\n", addr + V8_OFF_JSARRAYBUFFERVIEW_BUFFER);
if (read_heap_ptr(&buffer, addr, V8_OFF_JSARRAYBUFFERVIEW_BUFFER) != 0) {
(void) bsnprintf(bufp, lenp,
"<array (failed to read jstypedarray buffer)>");
return (-1);
}
printf("Reading JSArrayBuffer backing store at 0x%016" PRIXPTR "\n", buffer + V8_OFF_JSARRAYBUFFER_BACKINGSTORE);
if (read_heap_ptr(&buffer_backing_store, buffer, V8_OFF_JSARRAYBUFFER_BACKINGSTORE) != 0) {
(void) bsnprintf(bufp, lenp,
"<array (failed to read jsarraybuffer backing store)>");
return (-1);
}
return (0);
}
*/

/*
* Given a Node Buffer object, print out details about it. With "-a", just
* print the address.
Expand Down Expand Up @@ -5337,7 +5404,7 @@ dcmd_nodebuffer(uintptr_t addr, uint_t flags, int argc,
if (obj_jsconstructor(addr, &bufp, &len, B_FALSE) != 0)
return (DCMD_ERR);

if (strcmp(buf, "Buffer") != 0) {
if (strcmp(buf, "Buffer") != 0 && strcmp(buf, "Uint8Array") != 0) {
mdb_warn("%p does not appear to be a buffer\n", addr);
return (DCMD_ERR);
}
Expand Down

0 comments on commit 15421a2

Please sign in to comment.