From 13296e4b13b5ed192c4faa6501f3efec2ded8ac1 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Mon, 7 Jan 2013 22:53:50 +0400 Subject: [PATCH 1/2] dtrace: fix style in ustack helper --- src/v8ustack.d | 788 ++++++++++++++++++++++++------------------------- 1 file changed, 394 insertions(+), 394 deletions(-) diff --git a/src/v8ustack.d b/src/v8ustack.d index 27e903449240..8a25ee01f3d5 100644 --- a/src/v8ustack.d +++ b/src/v8ustack.d @@ -17,8 +17,10 @@ * V8 represents small integers (SMI) using the upper 31 bits of a 32-bit * value. To extract the actual integer value, we must shift it over. */ -#define IS_SMI(value) ((value & V8_SmiTagMask) == V8_SmiTag) -#define SMI_VALUE(value) ((uint32_t)(value) >> V8_SmiValueShift) +#define IS_SMI(value) \ + ((value & V8_SmiTagMask) == V8_SmiTag) +#define SMI_VALUE(value) \ + ((uint32_t)(value) >> V8_SmiValueShift) /* * Heap objects usually start off with a Map pointer, itself another heap @@ -26,106 +28,106 @@ * pointer (which are normally 01) are used to record GC state. Of course, we * have no idea if we're in GC or not, so we must always normalize the pointer. */ -#define V8_MAP_PTR(ptr) \ +#define V8_MAP_PTR(ptr) \ ((ptr & ~V8_HeapObjectTagMask) | V8_HeapObjectTag) /* * Determine the encoding and representation of a V8 string. */ -#define V8_TYPE_STRING(type) (((type) & V8_IsNotStringMask) == V8_StringTag) +#define V8_TYPE_STRING(type) (((type) & V8_IsNotStringMask) == V8_StringTag) -#define V8_STRENC_ASCII(type) \ +#define V8_STRENC_ASCII(type) \ (((type) & V8_StringEncodingMask) == V8_AsciiStringTag) -#define V8_STRREP_SEQ(type) \ +#define V8_STRREP_SEQ(type) \ (((type) & V8_StringRepresentationMask) == V8_SeqStringTag) -#define V8_STRREP_CONS(type) \ +#define V8_STRREP_CONS(type) \ (((type) & V8_StringRepresentationMask) == V8_ConsStringTag) -#define V8_STRREP_EXT(type) \ +#define V8_STRREP_EXT(type) \ (((type) & V8_StringRepresentationMask) == V8_ExternalStringTag) /* * String type predicates */ -#define ASCII_SEQSTR(value) \ +#define ASCII_SEQSTR(value) \ (V8_TYPE_STRING(value) && V8_STRENC_ASCII(value) && V8_STRREP_SEQ(value)) -#define ASCII_CONSSTR(value) \ +#define ASCII_CONSSTR(value) \ (V8_TYPE_STRING(value) && V8_STRENC_ASCII(value) && V8_STRREP_CONS(value)) -#define ASCII_EXTSTR(value) \ +#define ASCII_EXTSTR(value) \ (V8_TYPE_STRING(value) && V8_STRENC_ASCII(value) && V8_STRREP_EXT(value)) /* * General helper macros */ -#define COPYIN_UINT8(addr) (*(uint8_t *)copyin((addr), sizeof (uint8_t))) -#define COPYIN_UINT32(addr) (*(uint32_t *)copyin((addr), sizeof (uint32_t))) +#define COPYIN_UINT8(addr) (*(uint8_t*) copyin((addr), sizeof(uint8_t))) +#define COPYIN_UINT32(addr) (*(uint32_t*) copyin((addr), sizeof(uint32_t))) -#define APPEND_CHR(c) (this->buf[this->off++] = (c)) +#define APPEND_CHR(c) (this->buf[this->off++] = (c)) -#define APPEND_DGT(i, d) \ - (((i) / (d)) ? APPEND_CHR('0' + ((i)/(d) % 10)) : 0) +#define APPEND_DGT(i, d) \ + (((i) / (d)) ? APPEND_CHR('0' + ((i)/(d) % 10)) : 0) -#define APPEND_NUM(i) \ - APPEND_DGT((i), 10000); \ - APPEND_DGT((i), 1000); \ - APPEND_DGT((i), 100); \ - APPEND_DGT((i), 10); \ - APPEND_DGT((i), 1); +#define APPEND_NUM(i) \ + APPEND_DGT((i), 10000); \ + APPEND_DGT((i), 1000); \ + APPEND_DGT((i), 100); \ + APPEND_DGT((i), 10); \ + APPEND_DGT((i), 1); /* * The following macros are used to output ASCII SeqStrings, ConsStrings, and * Node.js ExternalStrings. To represent each string, we use three fields: * - * "str": a pointer to the string itself + * "str": a pointer to the string itself * - * "len": the string length + * "len": the string length * - * "attrs": the type identifier for the string, which indicates the - * encoding and representation. We're only interested in ASCII - * encoded strings whose representation is one of: + * "attrs": the type identifier for the string, which indicates the + * encoding and representation. We're only interested in ASCII + * encoded strings whose representation is one of: * - * SeqString stored directly as a char array inside the object + * SeqString stored directly as a char array inside the object * - * ConsString pointer to two strings that should be concatenated + * ConsString pointer to two strings that should be concatenated * - * ExternalString pointer to a char* outside the V8 heap + * ExternalString pointer to a char* outside the V8 heap */ - + /* * Load "len" and "attrs" for the given "str". */ -#define LOAD_STRFIELDS(str, len, attrs) \ - len = SMI_VALUE(COPYIN_UINT32(str + V8_OFF_STR_LENGTH)); \ - this->map = V8_MAP_PTR(COPYIN_UINT32(str + V8_OFF_HEAPOBJ_MAP)); \ +#define LOAD_STRFIELDS(str, len, attrs) \ + len = SMI_VALUE(COPYIN_UINT32(str + V8_OFF_STR_LENGTH)); \ + this->map = V8_MAP_PTR(COPYIN_UINT32(str + V8_OFF_HEAPOBJ_MAP)); \ attrs = COPYIN_UINT8(this->map + V8_OFF_MAP_ATTRS); /* * Print out the given SeqString, or do nothing if the string is not an ASCII * SeqString. */ -#define APPEND_SEQSTR(str, len, attrs) \ -dtrace:helper:ustack: \ -/!this->done && len > 0 && ASCII_SEQSTR(attrs)/ \ -{ \ - copyinto(str + V8_OFF_STR_CHARS, len, this->buf + this->off); \ - this->off += len; \ -} +#define APPEND_SEQSTR(str, len, attrs) \ + dtrace:helper:ustack: \ + /!this->done && len > 0 && ASCII_SEQSTR(attrs)/ \ + { \ + copyinto(str + V8_OFF_STR_CHARS, len, this->buf + this->off); \ + this->off += len; \ + } /* * Print out the given Node.js ExternalString, or do nothing if the string is * not an ASCII ExternalString. */ -#define APPEND_NODESTR(str, len, attrs) \ -dtrace:helper:ustack: \ -/!this->done && len > 0 && ASCII_EXTSTR(attrs)/ \ -{ \ - this->resource = COPYIN_UINT32(str + V8_OFF_EXTSTR_RSRC); \ - this->dataptr = COPYIN_UINT32(this->resource + NODE_OFF_EXTSTR_DATA); \ - copyinto(this->dataptr, len, this->buf + this->off); \ - this->off += len; \ -} +#define APPEND_NODESTR(str, len, attrs) \ + dtrace:helper:ustack: \ + /!this->done && len > 0 && ASCII_EXTSTR(attrs)/ \ + { \ + this->resource = COPYIN_UINT32(str + V8_OFF_EXTSTR_RSRC); \ + this->dataptr = COPYIN_UINT32(this->resource + NODE_OFF_EXTSTR_DATA); \ + copyinto(this->dataptr, len, this->buf + this->off); \ + this->off += len; \ + } /* * Recall that each ConsString points to two other strings which are @@ -140,11 +142,11 @@ dtrace:helper:ustack: \ * * +---- str ----+ * / \ <-- 1st expansion - * / \ + * / \ * s0 s7 - * / \ / \ + * / \ / \ * / \ / \ <-- 2nd expansion - * / \ / \ + * / \ / \ * s1 s4 s8 s11 * / \ / \ / \ / \ <-- 3rd expansion * s2 s3 s5 s6 s9 s10 s12 s13 @@ -156,90 +158,90 @@ dtrace:helper:ustack: \ * all non-zero-length strings in order (including both internal nodes and * leafs in the tree above) to get the final output. */ -#define EXPAND_START() \ -dtrace:helper:ustack: \ -/!this->done/ \ -{ \ - this->s0str = this->s1str = this->s2str = 0; \ - this->s3str = this->s4str = this->s5str = 0; \ - this->s6str = this->s7str = this->s8str = 0; \ - this->s9str = this->s10str = this->s11str = 0; \ - this->s12str = this->s13str = 0; \ - \ - this->s0len = this->s1len = this->s2len = 0; \ - this->s3len = this->s4len = this->s5len = 0; \ - this->s6len = this->s7len = this->s8len = 0; \ - this->s9len = this->s10len = this->s11len = 0; \ - this->s12len = this->s13len = 0; \ - \ - this->s0attrs = this->s1attrs = this->s2attrs = 0; \ - this->s3attrs = this->s4attrs = this->s5attrs = 0; \ - this->s6attrs = this->s7attrs = this->s8attrs = 0; \ - this->s9attrs = this->s10attrs = this->s11attrs = 0; \ - this->s12attrs = this->s13attrs = 0; \ -} +#define EXPAND_START() \ + dtrace:helper:ustack: \ + /!this->done/ \ + { \ + this->s0str = this->s1str = this->s2str = 0; \ + this->s3str = this->s4str = this->s5str = 0; \ + this->s6str = this->s7str = this->s8str = 0; \ + this->s9str = this->s10str = this->s11str = 0; \ + this->s12str = this->s13str = 0; \ + \ + this->s0len = this->s1len = this->s2len = 0; \ + this->s3len = this->s4len = this->s5len = 0; \ + this->s6len = this->s7len = this->s8len = 0; \ + this->s9len = this->s10len = this->s11len = 0; \ + this->s12len = this->s13len = 0; \ + \ + this->s0attrs = this->s1attrs = this->s2attrs = 0; \ + this->s3attrs = this->s4attrs = this->s5attrs = 0; \ + this->s6attrs = this->s7attrs = this->s8attrs = 0; \ + this->s9attrs = this->s10attrs = this->s11attrs = 0; \ + this->s12attrs = this->s13attrs = 0; \ + } /* * Expand the ConsString "str" (represented by "str", "len", and "attrs") into * strings "s1" (represented by "s1s", "s1l", and "s1a") and "s2" (represented * by "s2s", "s2l", "s2a"). If "str" is not a ConsString, do nothing. */ -#define EXPAND_STR(str, len, attrs, s1s, s1l, s1a, s2s, s2l, s2a) \ -dtrace:helper:ustack: \ -/!this->done && len > 0 && ASCII_CONSSTR(attrs)/ \ -{ \ - len = 0; \ - \ - s1s = COPYIN_UINT32(str + V8_OFF_CONSSTR_CAR); \ - LOAD_STRFIELDS(s1s, s1l, s1a) \ - \ - s2s = COPYIN_UINT32(str + V8_OFF_CONSSTR_CDR); \ - LOAD_STRFIELDS(s2s, s2l, s2a) \ -} +#define EXPAND_STR(str, len, attrs, s1s, s1l, s1a, s2s, s2l, s2a) \ + dtrace:helper:ustack: \ + /!this->done && len > 0 && ASCII_CONSSTR(attrs)/ \ + { \ + len = 0; \ + \ + s1s = COPYIN_UINT32(str + V8_OFF_CONSSTR_CAR); \ + LOAD_STRFIELDS(s1s, s1l, s1a) \ + \ + s2s = COPYIN_UINT32(str + V8_OFF_CONSSTR_CDR); \ + LOAD_STRFIELDS(s2s, s2l, s2a) \ + } /* * Print out a ConsString by expanding it up to three levels and printing out * the resulting SeqStrings. */ -#define APPEND_CONSSTR(str, len, attrs) \ - EXPAND_START() \ - EXPAND_STR(str, len, attrs, \ - this->s0str, this->s0len, this->s0attrs, \ - this->s7str, this->s7len, this->s7attrs) \ - EXPAND_STR(this->s0str, this->s0len, this->s0attrs, \ - this->s1str, this->s1len, this->s1attrs, \ - this->s4str, this->s4len, this->s4attrs) \ - EXPAND_STR(this->s1str, this->s1len, this->s1attrs, \ - this->s2str, this->s2len, this->s2attrs, \ - this->s3str, this->s3len, this->s3attrs) \ - EXPAND_STR(this->s4str, this->s4len, this->s4attrs, \ - this->s5str, this->s5len, this->s5attrs, \ - this->s6str, this->s6len, this->s6attrs) \ - EXPAND_STR(this->s7str, this->s7len, this->s7attrs, \ - this->s8str, this->s8len, this->s8attrs, \ - this->s11str, this->s11len, this->s11attrs) \ - EXPAND_STR(this->s8str, this->s8len, this->s8attrs, \ - this->s9str, this->s9len, this->s9attrs, \ - this->s10str, this->s10len, this->s10attrs) \ - EXPAND_STR(this->s11str, this->s11len, this->s11attrs, \ - this->s12str, this->s12len, this->s12attrs, \ - this->s13str, this->s13len, this->s13attrs) \ - \ - APPEND_SEQSTR(str, len, attrs) \ - APPEND_SEQSTR(this->s0str, this->s0len, this->s0attrs) \ - APPEND_SEQSTR(this->s1str, this->s1len, this->s1attrs) \ - APPEND_SEQSTR(this->s2str, this->s2len, this->s2attrs) \ - APPEND_SEQSTR(this->s3str, this->s3len, this->s3attrs) \ - APPEND_SEQSTR(this->s4str, this->s4len, this->s4attrs) \ - APPEND_SEQSTR(this->s5str, this->s5len, this->s5attrs) \ - APPEND_SEQSTR(this->s6str, this->s6len, this->s6attrs) \ - APPEND_SEQSTR(this->s7str, this->s7len, this->s7attrs) \ - APPEND_SEQSTR(this->s8str, this->s8len, this->s8attrs) \ - APPEND_SEQSTR(this->s9str, this->s9len, this->s9attrs) \ - APPEND_SEQSTR(this->s10str, this->s10len, this->s10attrs) \ - APPEND_SEQSTR(this->s11str, this->s11len, this->s11attrs) \ - APPEND_SEQSTR(this->s12str, this->s12len, this->s12attrs) \ - APPEND_SEQSTR(this->s13str, this->s13len, this->s13attrs) \ +#define APPEND_CONSSTR(str, len, attrs) \ + EXPAND_START() \ + EXPAND_STR(str, len, attrs, \ + this->s0str, this->s0len, this->s0attrs, \ + this->s7str, this->s7len, this->s7attrs) \ + EXPAND_STR(this->s0str, this->s0len, this->s0attrs, \ + this->s1str, this->s1len, this->s1attrs, \ + this->s4str, this->s4len, this->s4attrs) \ + EXPAND_STR(this->s1str, this->s1len, this->s1attrs, \ + this->s2str, this->s2len, this->s2attrs, \ + this->s3str, this->s3len, this->s3attrs) \ + EXPAND_STR(this->s4str, this->s4len, this->s4attrs, \ + this->s5str, this->s5len, this->s5attrs, \ + this->s6str, this->s6len, this->s6attrs) \ + EXPAND_STR(this->s7str, this->s7len, this->s7attrs, \ + this->s8str, this->s8len, this->s8attrs, \ + this->s11str, this->s11len, this->s11attrs) \ + EXPAND_STR(this->s8str, this->s8len, this->s8attrs, \ + this->s9str, this->s9len, this->s9attrs, \ + this->s10str, this->s10len, this->s10attrs) \ + EXPAND_STR(this->s11str, this->s11len, this->s11attrs, \ + this->s12str, this->s12len, this->s12attrs, \ + this->s13str, this->s13len, this->s13attrs) \ + \ + APPEND_SEQSTR(str, len, attrs) \ + APPEND_SEQSTR(this->s0str, this->s0len, this->s0attrs) \ + APPEND_SEQSTR(this->s1str, this->s1len, this->s1attrs) \ + APPEND_SEQSTR(this->s2str, this->s2len, this->s2attrs) \ + APPEND_SEQSTR(this->s3str, this->s3len, this->s3attrs) \ + APPEND_SEQSTR(this->s4str, this->s4len, this->s4attrs) \ + APPEND_SEQSTR(this->s5str, this->s5len, this->s5attrs) \ + APPEND_SEQSTR(this->s6str, this->s6len, this->s6attrs) \ + APPEND_SEQSTR(this->s7str, this->s7len, this->s7attrs) \ + APPEND_SEQSTR(this->s8str, this->s8len, this->s8attrs) \ + APPEND_SEQSTR(this->s9str, this->s9len, this->s9attrs) \ + APPEND_SEQSTR(this->s10str, this->s10len, this->s10attrs) \ + APPEND_SEQSTR(this->s11str, this->s11len, this->s11attrs) \ + APPEND_SEQSTR(this->s12str, this->s12len, this->s12attrs) \ + APPEND_SEQSTR(this->s13str, this->s13len, this->s13attrs) \ /* @@ -247,9 +249,9 @@ dtrace:helper:ustack: \ * APPEND_CONSSTR implicitly handles SeqStrings as the degenerate case of an * expanded ConsString. */ -#define APPEND_V8STR(str, len, attrs) \ - APPEND_CONSSTR(str, len, attrs) \ - APPEND_NODESTR(str, len, attrs) +#define APPEND_V8STR(str, len, attrs) \ + APPEND_CONSSTR(str, len, attrs) \ + APPEND_NODESTR(str, len, attrs) /* * In this first clause we initialize all variables. We must explicitly clear @@ -257,36 +259,36 @@ dtrace:helper:ustack: \ */ dtrace:helper:ustack: { - /* input */ - this->fp = arg1; - - /* output/flow control */ - this->buf = (char *)alloca(128); - this->off = 0; - this->done = 0; - - /* program state */ - this->ctx = 0; - this->marker = 0; - this->func = 0; - this->shared = 0; - this->map = 0; - this->attrs = 0; - this->funcnamestr = 0; - this->funcnamelen = 0; - this->funcnameattrs = 0; - this->script = 0; - this->scriptnamestr = 0; - this->scriptnamelen = 0; - this->scriptnameattrs = 0; - this->position = 0; - this->line_ends = 0; - this->le_attrs = 0; - - /* binary search fields */ - this->bsearch_min = 0; - this->bsearch_max = 0; - this->ii = 0; + /* input */ + this->fp = arg1; + + /* output/flow control */ + this->buf = (char*) alloca(128); + this->off = 0; + this->done = 0; + + /* program state */ + this->ctx = 0; + this->marker = 0; + this->func = 0; + this->shared = 0; + this->map = 0; + this->attrs = 0; + this->funcnamestr = 0; + this->funcnamelen = 0; + this->funcnameattrs = 0; + this->script = 0; + this->scriptnamestr = 0; + this->scriptnamelen = 0; + this->scriptnameattrs = 0; + this->position = 0; + this->line_ends = 0; + this->le_attrs = 0; + + /* binary search fields */ + this->bsearch_min = 0; + this->bsearch_max = 0; + this->ii = 0; } /* @@ -295,28 +297,28 @@ dtrace:helper:ustack: */ dtrace:helper:ustack: { - this->ctx = COPYIN_UINT32(this->fp + V8_OFF_FP_CONTEXT); + this->ctx = COPYIN_UINT32(this->fp + V8_OFF_FP_CONTEXT); } dtrace:helper:ustack: /IS_SMI(this->ctx) && SMI_VALUE(this->ctx) == V8_FT_ADAPTOR/ { - this->done = 1; - APPEND_CHR('<'); - APPEND_CHR('<'); - APPEND_CHR(' '); - APPEND_CHR('a'); - APPEND_CHR('d'); - APPEND_CHR('a'); - APPEND_CHR('p'); - APPEND_CHR('t'); - APPEND_CHR('o'); - APPEND_CHR('r'); - APPEND_CHR(' '); - APPEND_CHR('>'); - APPEND_CHR('>'); - APPEND_CHR('\0'); - stringof(this->buf); + this->done = 1; + APPEND_CHR('<'); + APPEND_CHR('<'); + APPEND_CHR(' '); + APPEND_CHR('a'); + APPEND_CHR('d'); + APPEND_CHR('a'); + APPEND_CHR('p'); + APPEND_CHR('t'); + APPEND_CHR('o'); + APPEND_CHR('r'); + APPEND_CHR(' '); + APPEND_CHR('>'); + APPEND_CHR('>'); + APPEND_CHR('\0'); + stringof(this->buf); } /* @@ -325,125 +327,125 @@ dtrace:helper:ustack: dtrace:helper:ustack: /!this->done/ { - this->marker = COPYIN_UINT32(this->fp + V8_OFF_FP_MARKER); + this->marker = COPYIN_UINT32(this->fp + V8_OFF_FP_MARKER); } dtrace:helper:ustack: /!this->done && IS_SMI(this->marker) && SMI_VALUE(this->marker) == V8_FT_ENTRY/ { - this->done = 1; - APPEND_CHR('<'); - APPEND_CHR('<'); - APPEND_CHR(' '); - APPEND_CHR('e'); - APPEND_CHR('n'); - APPEND_CHR('t'); - APPEND_CHR('r'); - APPEND_CHR('y'); - APPEND_CHR(' '); - APPEND_CHR('>'); - APPEND_CHR('>'); - APPEND_CHR('\0'); - stringof(this->buf); + this->done = 1; + APPEND_CHR('<'); + APPEND_CHR('<'); + APPEND_CHR(' '); + APPEND_CHR('e'); + APPEND_CHR('n'); + APPEND_CHR('t'); + APPEND_CHR('r'); + APPEND_CHR('y'); + APPEND_CHR(' '); + APPEND_CHR('>'); + APPEND_CHR('>'); + APPEND_CHR('\0'); + stringof(this->buf); } dtrace:helper:ustack: /!this->done && IS_SMI(this->marker) && SMI_VALUE(this->marker) == V8_FT_ENTRYCONSTRUCT/ { - this->done = 1; - APPEND_CHR('<'); - APPEND_CHR('<'); - APPEND_CHR(' '); - APPEND_CHR('e'); - APPEND_CHR('n'); - APPEND_CHR('t'); - APPEND_CHR('r'); - APPEND_CHR('y'); - APPEND_CHR('_'); - APPEND_CHR('c'); - APPEND_CHR('o'); - APPEND_CHR('n'); - APPEND_CHR('s'); - APPEND_CHR('t'); - APPEND_CHR('r'); - APPEND_CHR('u'); - APPEND_CHR('c'); - APPEND_CHR('t'); - APPEND_CHR(' '); - APPEND_CHR('>'); - APPEND_CHR('>'); - APPEND_CHR('\0'); - stringof(this->buf); + this->done = 1; + APPEND_CHR('<'); + APPEND_CHR('<'); + APPEND_CHR(' '); + APPEND_CHR('e'); + APPEND_CHR('n'); + APPEND_CHR('t'); + APPEND_CHR('r'); + APPEND_CHR('y'); + APPEND_CHR('_'); + APPEND_CHR('c'); + APPEND_CHR('o'); + APPEND_CHR('n'); + APPEND_CHR('s'); + APPEND_CHR('t'); + APPEND_CHR('r'); + APPEND_CHR('u'); + APPEND_CHR('c'); + APPEND_CHR('t'); + APPEND_CHR(' '); + APPEND_CHR('>'); + APPEND_CHR('>'); + APPEND_CHR('\0'); + stringof(this->buf); } dtrace:helper:ustack: /!this->done && IS_SMI(this->marker) && SMI_VALUE(this->marker) == V8_FT_EXIT/ { - this->done = 1; - APPEND_CHR('<'); - APPEND_CHR('<'); - APPEND_CHR(' '); - APPEND_CHR('e'); - APPEND_CHR('x'); - APPEND_CHR('i'); - APPEND_CHR('t'); - APPEND_CHR(' '); - APPEND_CHR('>'); - APPEND_CHR('>'); - APPEND_CHR('\0'); - stringof(this->buf); + this->done = 1; + APPEND_CHR('<'); + APPEND_CHR('<'); + APPEND_CHR(' '); + APPEND_CHR('e'); + APPEND_CHR('x'); + APPEND_CHR('i'); + APPEND_CHR('t'); + APPEND_CHR(' '); + APPEND_CHR('>'); + APPEND_CHR('>'); + APPEND_CHR('\0'); + stringof(this->buf); } dtrace:helper:ustack: /!this->done && IS_SMI(this->marker) && SMI_VALUE(this->marker) == V8_FT_INTERNAL/ { - this->done = 1; - APPEND_CHR('<'); - APPEND_CHR('<'); - APPEND_CHR(' '); - APPEND_CHR('i'); - APPEND_CHR('n'); - APPEND_CHR('t'); - APPEND_CHR('e'); - APPEND_CHR('r'); - APPEND_CHR('n'); - APPEND_CHR('a'); - APPEND_CHR('l'); - APPEND_CHR(' '); - APPEND_CHR('>'); - APPEND_CHR('>'); - APPEND_CHR('\0'); - stringof(this->buf); + this->done = 1; + APPEND_CHR('<'); + APPEND_CHR('<'); + APPEND_CHR(' '); + APPEND_CHR('i'); + APPEND_CHR('n'); + APPEND_CHR('t'); + APPEND_CHR('e'); + APPEND_CHR('r'); + APPEND_CHR('n'); + APPEND_CHR('a'); + APPEND_CHR('l'); + APPEND_CHR(' '); + APPEND_CHR('>'); + APPEND_CHR('>'); + APPEND_CHR('\0'); + stringof(this->buf); } dtrace:helper:ustack: /!this->done && IS_SMI(this->marker) && SMI_VALUE(this->marker) == V8_FT_CONSTRUCT/ { - this->done = 1; - APPEND_CHR('<'); - APPEND_CHR('<'); - APPEND_CHR(' '); - APPEND_CHR('c'); - APPEND_CHR('o'); - APPEND_CHR('n'); - APPEND_CHR('s'); - APPEND_CHR('t'); - APPEND_CHR('r'); - APPEND_CHR('u'); - APPEND_CHR('c'); - APPEND_CHR('t'); - APPEND_CHR('o'); - APPEND_CHR('r'); - APPEND_CHR(' '); - APPEND_CHR('>'); - APPEND_CHR('>'); - APPEND_CHR('\0'); - stringof(this->buf); + this->done = 1; + APPEND_CHR('<'); + APPEND_CHR('<'); + APPEND_CHR(' '); + APPEND_CHR('c'); + APPEND_CHR('o'); + APPEND_CHR('n'); + APPEND_CHR('s'); + APPEND_CHR('t'); + APPEND_CHR('r'); + APPEND_CHR('u'); + APPEND_CHR('c'); + APPEND_CHR('t'); + APPEND_CHR('o'); + APPEND_CHR('r'); + APPEND_CHR(' '); + APPEND_CHR('>'); + APPEND_CHR('>'); + APPEND_CHR('\0'); + stringof(this->buf); } /* @@ -454,36 +456,36 @@ dtrace:helper:ustack: dtrace:helper:ustack: /!this->done/ { - this->func = COPYIN_UINT32(this->fp + V8_OFF_FP_FUNC); - this->map = V8_MAP_PTR(COPYIN_UINT32(this->func + V8_OFF_HEAPOBJ_MAP)); - this->attrs = COPYIN_UINT8(this->map + V8_OFF_MAP_ATTRS); + this->func = COPYIN_UINT32(this->fp + V8_OFF_FP_FUNC); + this->map = V8_MAP_PTR(COPYIN_UINT32(this->func + V8_OFF_HEAPOBJ_MAP)); + this->attrs = COPYIN_UINT8(this->map + V8_OFF_MAP_ATTRS); } dtrace:helper:ustack: /!this->done && this->attrs == V8_IT_CODE/ { - this->done = 1; - APPEND_CHR('<'); - APPEND_CHR('<'); - APPEND_CHR(' '); - APPEND_CHR('i'); - APPEND_CHR('n'); - APPEND_CHR('t'); - APPEND_CHR('e'); - APPEND_CHR('r'); - APPEND_CHR('n'); - APPEND_CHR('a'); - APPEND_CHR('l'); - APPEND_CHR(' '); - APPEND_CHR('c'); - APPEND_CHR('o'); - APPEND_CHR('d'); - APPEND_CHR('e'); - APPEND_CHR(' '); - APPEND_CHR('>'); - APPEND_CHR('>'); - APPEND_CHR('\0'); - stringof(this->buf); + this->done = 1; + APPEND_CHR('<'); + APPEND_CHR('<'); + APPEND_CHR(' '); + APPEND_CHR('i'); + APPEND_CHR('n'); + APPEND_CHR('t'); + APPEND_CHR('e'); + APPEND_CHR('r'); + APPEND_CHR('n'); + APPEND_CHR('a'); + APPEND_CHR('l'); + APPEND_CHR(' '); + APPEND_CHR('c'); + APPEND_CHR('o'); + APPEND_CHR('d'); + APPEND_CHR('e'); + APPEND_CHR(' '); + APPEND_CHR('>'); + APPEND_CHR('>'); + APPEND_CHR('\0'); + stringof(this->buf); } /* @@ -494,48 +496,48 @@ dtrace:helper:ustack: dtrace:helper:ustack: /!this->done/ { - this->map = 0; - this->attrs = 0; + this->map = 0; + this->attrs = 0; - this->shared = COPYIN_UINT32(this->func + V8_OFF_FUNC_SHARED); - this->funcnamestr = COPYIN_UINT32(this->shared + V8_OFF_SHARED_NAME); - LOAD_STRFIELDS(this->funcnamestr, this->funcnamelen, - this->funcnameattrs); + this->shared = COPYIN_UINT32(this->func + V8_OFF_FUNC_SHARED); + this->funcnamestr = COPYIN_UINT32(this->shared + V8_OFF_SHARED_NAME); + LOAD_STRFIELDS(this->funcnamestr, this->funcnamelen, + this->funcnameattrs); } dtrace:helper:ustack: /!this->done && this->funcnamelen == 0/ { - /* - * This is an anonymous function, but if it was invoked as a method of - * some object then V8 will have computed an inferred name that we can - * include in the stack trace. - */ - APPEND_CHR('('); - APPEND_CHR('a'); - APPEND_CHR('n'); - APPEND_CHR('o'); - APPEND_CHR('n'); - APPEND_CHR(')'); - APPEND_CHR(' '); - APPEND_CHR('a'); - APPEND_CHR('s'); - APPEND_CHR(' '); - - this->funcnamestr = COPYIN_UINT32(this->shared + V8_OFF_SHARED_INFERRED); - LOAD_STRFIELDS(this->funcnamestr, this->funcnamelen, - this->funcnameattrs); + /* + * This is an anonymous function, but if it was invoked as a method of + * some object then V8 will have computed an inferred name that we can + * include in the stack trace. + */ + APPEND_CHR('('); + APPEND_CHR('a'); + APPEND_CHR('n'); + APPEND_CHR('o'); + APPEND_CHR('n'); + APPEND_CHR(')'); + APPEND_CHR(' '); + APPEND_CHR('a'); + APPEND_CHR('s'); + APPEND_CHR(' '); + + this->funcnamestr = COPYIN_UINT32(this->shared + V8_OFF_SHARED_INFERRED); + LOAD_STRFIELDS(this->funcnamestr, this->funcnamelen, + this->funcnameattrs); } dtrace:helper:ustack: /!this->done && this->funcnamelen == 0/ { - APPEND_CHR('('); - APPEND_CHR('a'); - APPEND_CHR('n'); - APPEND_CHR('o'); - APPEND_CHR('n'); - APPEND_CHR(')'); + APPEND_CHR('('); + APPEND_CHR('a'); + APPEND_CHR('n'); + APPEND_CHR('o'); + APPEND_CHR('n'); + APPEND_CHR(')'); } APPEND_V8STR(this->funcnamestr, this->funcnamelen, this->funcnameattrs) @@ -546,16 +548,15 @@ APPEND_V8STR(this->funcnamestr, this->funcnamelen, this->funcnameattrs) dtrace:helper:ustack: /!this->done/ { - this->script = COPYIN_UINT32(this->shared + V8_OFF_SHARED_SCRIPT); - this->scriptnamestr = COPYIN_UINT32(this->script + - V8_OFF_SCRIPT_NAME); - LOAD_STRFIELDS(this->scriptnamestr, this->scriptnamelen, - this->scriptnameattrs); - - APPEND_CHR(' '); - APPEND_CHR('a'); - APPEND_CHR('t'); - APPEND_CHR(' '); + this->script = COPYIN_UINT32(this->shared + V8_OFF_SHARED_SCRIPT); + this->scriptnamestr = COPYIN_UINT32(this->script + V8_OFF_SCRIPT_NAME); + LOAD_STRFIELDS(this->scriptnamestr, this->scriptnamelen, + this->scriptnameattrs); + + APPEND_CHR(' '); + APPEND_CHR('a'); + APPEND_CHR('t'); + APPEND_CHR(' '); } APPEND_V8STR(this->scriptnamestr, this->scriptnamelen, this->scriptnameattrs) @@ -566,35 +567,34 @@ APPEND_V8STR(this->scriptnamestr, this->scriptnamelen, this->scriptnameattrs) dtrace:helper:ustack: /!this->done/ { - this->position = COPYIN_UINT32(this->shared + V8_OFF_SHARED_FUNTOK); - this->line_ends = COPYIN_UINT32(this->script + V8_OFF_SCRIPT_LENDS); - this->map = V8_MAP_PTR(COPYIN_UINT32(this->line_ends + - V8_OFF_HEAPOBJ_MAP)); - this->le_attrs = COPYIN_UINT8(this->map + V8_OFF_MAP_ATTRS); + this->position = COPYIN_UINT32(this->shared + V8_OFF_SHARED_FUNTOK); + this->line_ends = COPYIN_UINT32(this->script + V8_OFF_SCRIPT_LENDS); + this->map = V8_MAP_PTR(COPYIN_UINT32(this->line_ends + V8_OFF_HEAPOBJ_MAP)); + this->le_attrs = COPYIN_UINT8(this->map + V8_OFF_MAP_ATTRS); } dtrace:helper:ustack: /!this->done && this->le_attrs != V8_IT_FIXEDARRAY/ { - /* - * If the line number array was not a valid FixedArray, it's probably - * undefined because V8 has not had to compute it yet. In this case we - * just show the raw position and call it a day. - */ - APPEND_CHR(' '); - APPEND_CHR('p'); - APPEND_CHR('o'); - APPEND_CHR('s'); - APPEND_CHR('i'); - APPEND_CHR('t'); - APPEND_CHR('i'); - APPEND_CHR('o'); - APPEND_CHR('n'); - APPEND_CHR(' '); - APPEND_NUM(this->position); - APPEND_CHR('\0'); - this->done = 1; - stringof(this->buf); + /* + * If the line number array was not a valid FixedArray, it's probably + * undefined because V8 has not had to compute it yet. In this case we + * just show the raw position and call it a day. + */ + APPEND_CHR(' '); + APPEND_CHR('p'); + APPEND_CHR('o'); + APPEND_CHR('s'); + APPEND_CHR('i'); + APPEND_CHR('t'); + APPEND_CHR('i'); + APPEND_CHR('o'); + APPEND_CHR('n'); + APPEND_CHR(' '); + APPEND_NUM(this->position); + APPEND_CHR('\0'); + this->done = 1; + stringof(this->buf); } /* @@ -606,12 +606,12 @@ dtrace:helper:ustack: dtrace:helper:ustack: /!this->done/ { - /* initialize binary search */ - this->bsearch_line = this->position < COPYIN_UINT32( - this->line_ends + V8_OFF_FA_DATA) ? 1 : 0; - this->bsearch_min = 0; - this->bsearch_max = this->bsearch_line != 0 ? 0 : - SMI_VALUE(COPYIN_UINT32(this->line_ends + V8_OFF_FA_SIZE)) - 1; + /* initialize binary search */ + this->bsearch_line = this->position < + COPYIN_UINT32(this->line_ends + V8_OFF_FA_DATA) ? 1 : 0; + this->bsearch_min = 0; + this->bsearch_max = this->bsearch_line != 0 ? 0 : + SMI_VALUE(COPYIN_UINT32(this->line_ends + V8_OFF_FA_SIZE)) - 1; } /* @@ -619,28 +619,28 @@ dtrace:helper:ustack: * iterations. That's enough to precisely identify the line number in files up * to 32768 lines of code. */ -#define BSEARCH_LOOP \ -dtrace:helper:ustack: \ -/!this->done && this->bsearch_max >= 1/ \ -{ \ - this->ii = (this->bsearch_min + this->bsearch_max) >> 1; \ -} \ - \ -dtrace:helper:ustack: \ -/!this->done && this->bsearch_max >= 1 && \ - this->position > COPYIN_UINT32(this->line_ends + V8_OFF_FA_DATA + \ - this->ii * sizeof (uint32_t))/ \ -{ \ - this->bsearch_min = this->ii + 1; \ -} \ - \ -dtrace:helper:ustack: \ -/!this->done && this->bsearch_max >= 1 && \ - this->position <= COPYIN_UINT32(this->line_ends + V8_OFF_FA_DATA + \ - (this->ii - 1) * sizeof (uint32_t))/ \ -{ \ - this->bsearch_max = this->ii - 1; \ -} +#define BSEARCH_LOOP \ + dtrace:helper:ustack: \ + /!this->done && this->bsearch_max >= 1/ \ + { \ + this->ii = (this->bsearch_min + this->bsearch_max) >> 1; \ + } \ + \ + dtrace:helper:ustack: \ + /!this->done && this->bsearch_max >= 1 && \ + this->position > COPYIN_UINT32(this->line_ends + V8_OFF_FA_DATA + \ + this->ii * sizeof (uint32_t))/ \ + { \ + this->bsearch_min = this->ii + 1; \ + } \ + \ + dtrace:helper:ustack: \ + /!this->done && this->bsearch_max >= 1 && \ + this->position <= COPYIN_UINT32(this->line_ends + V8_OFF_FA_DATA + \ + (this->ii - 1) * sizeof (uint32_t))/ \ + { \ + this->bsearch_max = this->ii - 1; \ + } BSEARCH_LOOP BSEARCH_LOOP @@ -661,20 +661,20 @@ BSEARCH_LOOP dtrace:helper:ustack: /!this->done && !this->bsearch_line/ { - this->bsearch_line = this->ii + 1; + this->bsearch_line = this->ii + 1; } dtrace:helper:ustack: /!this->done/ { - APPEND_CHR(' '); - APPEND_CHR('l'); - APPEND_CHR('i'); - APPEND_CHR('n'); - APPEND_CHR('e'); - APPEND_CHR(' '); - APPEND_NUM(this->bsearch_line); - APPEND_CHR('\0'); - this->done = 1; - stringof(this->buf); + APPEND_CHR(' '); + APPEND_CHR('l'); + APPEND_CHR('i'); + APPEND_CHR('n'); + APPEND_CHR('e'); + APPEND_CHR(' '); + APPEND_NUM(this->bsearch_line); + APPEND_CHR('\0'); + this->done = 1; + stringof(this->buf); } From f9afb3f01002e5667a0df80ee784af0dfe2305c2 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Thu, 27 Dec 2012 07:16:23 +0400 Subject: [PATCH 2/2] dtrace: x64 ustack helper --- node.gyp | 26 ++-- src/v8abbr.h | 14 +- src/v8ustack.d | 300 +++++++++++++++------------------------- tools/genv8constants.py | 52 ++++--- 4 files changed, 173 insertions(+), 219 deletions(-) diff --git a/node.gyp b/node.gyp index bbded8089598..64a4ab62ff92 100644 --- a/node.gyp +++ b/node.gyp @@ -169,13 +169,9 @@ # 'sources': [ 'src/node_dtrace.cc', - 'src/node_dtrace_provider.cc' + 'src/node_dtrace_provider.cc', + 'src/node_dtrace_ustack.cc', ], - 'conditions': [ [ - 'target_arch=="ia32"', { - 'sources': [ 'src/node_dtrace_ustack.cc' ] - } - ] ], } ], [ 'node_use_systemtap=="true"', { 'defines': [ 'HAVE_SYSTEMTAP=1', 'STAP_SDT_V1=1' ], @@ -424,7 +420,7 @@ 'target_name': 'node_dtrace_ustack', 'type': 'none', 'conditions': [ - [ 'node_use_dtrace=="true" and target_arch=="ia32"', { + [ 'node_use_dtrace=="true"', { 'actions': [ { 'action_name': 'node_dtrace_ustack_constants', @@ -449,9 +445,19 @@ 'outputs': [ '<(PRODUCT_DIR)/obj.target/node/src/node_dtrace_ustack.o' ], - 'action': [ - 'dtrace', '-32', '-I<(SHARED_INTERMEDIATE_DIR)', '-Isrc', - '-C', '-G', '-s', 'src/v8ustack.d', '-o', '<@(_outputs)', + 'conditions': [ + [ 'target_arch=="ia32"', { + 'action': [ + 'dtrace', '-32', '-I<(SHARED_INTERMEDIATE_DIR)', '-Isrc', + '-C', '-G', '-s', 'src/v8ustack.d', '-o', '<@(_outputs)', + ] + } ], + [ 'target_arch=="x64"', { + 'action': [ + 'dtrace', '-64', '-I<(SHARED_INTERMEDIATE_DIR)', '-Isrc', + '-C', '-G', '-s', 'src/v8ustack.d', '-o', '<@(_outputs)', + ] + } ], ] } ] diff --git a/src/v8abbr.h b/src/v8abbr.h index 9bc425eb8446..95ddb6a6611a 100644 --- a/src/v8abbr.h +++ b/src/v8abbr.h @@ -7,9 +7,9 @@ #define V8_ABBR_H /* Frame pointer offsets */ -#define V8_OFF_FP_FUNC ((uint32_t)V8DBG_OFF_FP_FUNCTION) -#define V8_OFF_FP_CONTEXT ((uint32_t)V8DBG_OFF_FP_CONTEXT) -#define V8_OFF_FP_MARKER ((uint32_t)V8DBG_OFF_FP_MARKER) +#define V8_OFF_FP_FUNC V8DBG_OFF_FP_FUNCTION +#define V8_OFF_FP_CONTEXT V8DBG_OFF_FP_CONTEXT +#define V8_OFF_FP_MARKER V8DBG_OFF_FP_MARKER /* Stack frame types */ #define V8_FT_ENTRY V8DBG_FRAMETYPE_ENTRYFRAME @@ -22,9 +22,9 @@ #define V8_FT_ADAPTOR V8DBG_FRAMETYPE_ARGUMENTSADAPTORFRAME /* Identification masks and tags */ -#define V8_SmiTagMask V8DBG_SMITAGMASK -#define V8_SmiTag V8DBG_SMITAG -#define V8_SmiValueShift V8_SmiTagMask +#define V8_SmiTagMask (V8DBG_SMITAGMASK) +#define V8_SmiTag (V8DBG_SMITAG) +#define V8_SmiValueShift (V8DBG_SMISHIFTSIZE + V8DBG_SMITAGMASK) #define V8_HeapObjectTagMask V8DBG_HEAPOBJECTTAGMASK #define V8_HeapObjectTag V8DBG_HEAPOBJECTTAG @@ -45,7 +45,7 @@ #define V8_IT_CODE V8DBG_TYPE_CODE__CODE_TYPE /* Node-specific offsets */ -#define NODE_OFF_EXTSTR_DATA 0x4 +#define NODE_OFF_EXTSTR_DATA sizeof(void*) /* Heap class->field offsets */ #define V8_OFF_HEAP(off) ((off) - 1) diff --git a/src/v8ustack.d b/src/v8ustack.d index 8a25ee01f3d5..f55148cfda03 100644 --- a/src/v8ustack.d +++ b/src/v8ustack.d @@ -14,13 +14,13 @@ #include /* - * V8 represents small integers (SMI) using the upper 31 bits of a 32-bit + * V8 represents small integers (SMI) using the upper 31 bits of a 32/64-bit * value. To extract the actual integer value, we must shift it over. */ #define IS_SMI(value) \ ((value & V8_SmiTagMask) == V8_SmiTag) #define SMI_VALUE(value) \ - ((uint32_t)(value) >> V8_SmiValueShift) + ((uint32_t) ((value) >> V8_SmiValueShift)) /* * Heap objects usually start off with a Map pointer, itself another heap @@ -34,7 +34,8 @@ /* * Determine the encoding and representation of a V8 string. */ -#define V8_TYPE_STRING(type) (((type) & V8_IsNotStringMask) == V8_StringTag) +#define V8_TYPE_STRING(type) \ + (((type) & V8_IsNotStringMask) == V8_StringTag) #define V8_STRENC_ASCII(type) \ (((type) & V8_StringEncodingMask) == V8_AsciiStringTag) @@ -63,19 +64,56 @@ */ #define COPYIN_UINT8(addr) (*(uint8_t*) copyin((addr), sizeof(uint8_t))) #define COPYIN_UINT32(addr) (*(uint32_t*) copyin((addr), sizeof(uint32_t))) +#define COPYIN_UINT64(addr) (*(uint64_t*) copyin((addr), sizeof(uint64_t))) + +#if defined(__i386) +# define COPYIN_PTR(addr) COPYIN_UINT32(addr) +# define off_t uint32_t +# define APPEND_PTR(p) APPEND_PTR_32(p) +#else +# define COPYIN_PTR(addr) COPYIN_UINT64(addr) +# define off_t uint64_t +# define APPEND_PTR(p) APPEND_PTR_64(p) +#endif #define APPEND_CHR(c) (this->buf[this->off++] = (c)) +#define APPEND_CHR4(s0, s1, s2, s3) \ + APPEND_CHR(s0); \ + APPEND_CHR(s1); \ + APPEND_CHR(s2); \ + APPEND_CHR(s3); +#define APPEND_CHR8(s0, s1, s2, s3, s4, s5, s6, s7) \ + APPEND_CHR4(s0, s1, s2, s3) \ + APPEND_CHR4(s4, s5, s6, s7) #define APPEND_DGT(i, d) \ (((i) / (d)) ? APPEND_CHR('0' + ((i)/(d) % 10)) : 0) #define APPEND_NUM(i) \ + APPEND_DGT((i), 100000); \ APPEND_DGT((i), 10000); \ APPEND_DGT((i), 1000); \ APPEND_DGT((i), 100); \ APPEND_DGT((i), 10); \ APPEND_DGT((i), 1); +#define APPEND_HEX(d) \ + APPEND_CHR((d) < 10 ? '0' + (d) : 'a' - 10 + (d)) + +#define APPEND_PTR_32(p) \ + APPEND_HEX((p >> 28) & 0xf); \ + APPEND_HEX((p >> 24) & 0xf); \ + APPEND_HEX((p >> 20) & 0xf); \ + APPEND_HEX((p >> 16) & 0xf); \ + APPEND_HEX((p >> 12) & 0xf); \ + APPEND_HEX((p >> 8) & 0xf); \ + APPEND_HEX((p >> 4) & 0xf); \ + APPEND_HEX((p) & 0xf); + +#define APPEND_PTR_64(p) \ + APPEND_PTR_32(p >> 32) \ + APPEND_PTR_32(p) + /* * The following macros are used to output ASCII SeqStrings, ConsStrings, and * Node.js ExternalStrings. To represent each string, we use three fields: @@ -99,8 +137,8 @@ * Load "len" and "attrs" for the given "str". */ #define LOAD_STRFIELDS(str, len, attrs) \ - len = SMI_VALUE(COPYIN_UINT32(str + V8_OFF_STR_LENGTH)); \ - this->map = V8_MAP_PTR(COPYIN_UINT32(str + V8_OFF_HEAPOBJ_MAP)); \ + len = SMI_VALUE(COPYIN_PTR(str + V8_OFF_STR_LENGTH)); \ + this->map = V8_MAP_PTR(COPYIN_PTR(str + V8_OFF_HEAPOBJ_MAP)); \ attrs = COPYIN_UINT8(this->map + V8_OFF_MAP_ATTRS); /* @@ -123,8 +161,8 @@ dtrace:helper:ustack: \ /!this->done && len > 0 && ASCII_EXTSTR(attrs)/ \ { \ - this->resource = COPYIN_UINT32(str + V8_OFF_EXTSTR_RSRC); \ - this->dataptr = COPYIN_UINT32(this->resource + NODE_OFF_EXTSTR_DATA); \ + this->resource = COPYIN_PTR(str + V8_OFF_EXTSTR_RSRC); \ + this->dataptr = COPYIN_PTR(this->resource + NODE_OFF_EXTSTR_DATA); \ copyinto(this->dataptr, len, this->buf + this->off); \ this->off += len; \ } @@ -146,7 +184,7 @@ * s0 s7 * / \ / \ * / \ / \ <-- 2nd expansion - * / \ / \ + * / \ / \ * s1 s4 s8 s11 * / \ / \ / \ / \ <-- 3rd expansion * s2 s3 s5 s6 s9 s10 s12 s13 @@ -162,17 +200,17 @@ dtrace:helper:ustack: \ /!this->done/ \ { \ - this->s0str = this->s1str = this->s2str = 0; \ - this->s3str = this->s4str = this->s5str = 0; \ - this->s6str = this->s7str = this->s8str = 0; \ - this->s9str = this->s10str = this->s11str = 0; \ - this->s12str = this->s13str = 0; \ + this->s0str = this->s1str = this->s2str = (off_t) 0; \ + this->s3str = this->s4str = this->s5str = (off_t) 0; \ + this->s6str = this->s7str = this->s8str = (off_t) 0; \ + this->s9str = this->s10str = this->s11str = (off_t) 0; \ + this->s12str = this->s13str = (off_t) 0; \ \ - this->s0len = this->s1len = this->s2len = 0; \ - this->s3len = this->s4len = this->s5len = 0; \ - this->s6len = this->s7len = this->s8len = 0; \ - this->s9len = this->s10len = this->s11len = 0; \ - this->s12len = this->s13len = 0; \ + this->s0len = this->s1len = this->s2len = (off_t) 0; \ + this->s3len = this->s4len = this->s5len = (off_t) 0; \ + this->s6len = this->s7len = this->s8len = (off_t) 0; \ + this->s9len = this->s10len = this->s11len = (off_t) 0; \ + this->s12len = this->s13len = (off_t) 0; \ \ this->s0attrs = this->s1attrs = this->s2attrs = 0; \ this->s3attrs = this->s4attrs = this->s5attrs = 0; \ @@ -192,10 +230,10 @@ { \ len = 0; \ \ - s1s = COPYIN_UINT32(str + V8_OFF_CONSSTR_CAR); \ + s1s = COPYIN_PTR(str + V8_OFF_CONSSTR_CAR); \ LOAD_STRFIELDS(s1s, s1l, s1a) \ \ - s2s = COPYIN_UINT32(str + V8_OFF_CONSSTR_CDR); \ + s2s = COPYIN_PTR(str + V8_OFF_CONSSTR_CDR); \ LOAD_STRFIELDS(s2s, s2l, s2a) \ } @@ -268,21 +306,21 @@ dtrace:helper:ustack: this->done = 0; /* program state */ - this->ctx = 0; - this->marker = 0; - this->func = 0; - this->shared = 0; - this->map = 0; + this->ctx = (off_t) 0; + this->marker = (off_t) 0; + this->func = (off_t) 0; + this->shared = (off_t) 0; + this->map = (off_t) 0; this->attrs = 0; - this->funcnamestr = 0; + this->funcnamestr = (off_t) 0; this->funcnamelen = 0; this->funcnameattrs = 0; - this->script = 0; - this->scriptnamestr = 0; + this->script = (off_t) 0; + this->scriptnamestr = (off_t) 0; this->scriptnamelen = 0; this->scriptnameattrs = 0; this->position = 0; - this->line_ends = 0; + this->line_ends = (off_t) 0; this->le_attrs = 0; /* binary search fields */ @@ -297,27 +335,15 @@ dtrace:helper:ustack: */ dtrace:helper:ustack: { - this->ctx = COPYIN_UINT32(this->fp + V8_OFF_FP_CONTEXT); + this->ctx = COPYIN_PTR(this->fp + V8_OFF_FP_CONTEXT); } dtrace:helper:ustack: /IS_SMI(this->ctx) && SMI_VALUE(this->ctx) == V8_FT_ADAPTOR/ { this->done = 1; - APPEND_CHR('<'); - APPEND_CHR('<'); - APPEND_CHR(' '); - APPEND_CHR('a'); - APPEND_CHR('d'); - APPEND_CHR('a'); - APPEND_CHR('p'); - APPEND_CHR('t'); - APPEND_CHR('o'); - APPEND_CHR('r'); - APPEND_CHR(' '); - APPEND_CHR('>'); - APPEND_CHR('>'); - APPEND_CHR('\0'); + APPEND_CHR8('<','<',' ','a','d','a','p','t'); + APPEND_CHR8('o','r',' ','>','>','\0','\0','\0'); stringof(this->buf); } @@ -327,7 +353,7 @@ dtrace:helper:ustack: dtrace:helper:ustack: /!this->done/ { - this->marker = COPYIN_UINT32(this->fp + V8_OFF_FP_MARKER); + this->marker = COPYIN_PTR(this->fp + V8_OFF_FP_MARKER); } dtrace:helper:ustack: @@ -335,18 +361,8 @@ dtrace:helper:ustack: SMI_VALUE(this->marker) == V8_FT_ENTRY/ { this->done = 1; - APPEND_CHR('<'); - APPEND_CHR('<'); - APPEND_CHR(' '); - APPEND_CHR('e'); - APPEND_CHR('n'); - APPEND_CHR('t'); - APPEND_CHR('r'); - APPEND_CHR('y'); - APPEND_CHR(' '); - APPEND_CHR('>'); - APPEND_CHR('>'); - APPEND_CHR('\0'); + APPEND_CHR8('<','<',' ','e','n','t','r','y'); + APPEND_CHR4(' ','>','>','\0'); stringof(this->buf); } @@ -355,27 +371,9 @@ dtrace:helper:ustack: SMI_VALUE(this->marker) == V8_FT_ENTRYCONSTRUCT/ { this->done = 1; - APPEND_CHR('<'); - APPEND_CHR('<'); - APPEND_CHR(' '); - APPEND_CHR('e'); - APPEND_CHR('n'); - APPEND_CHR('t'); - APPEND_CHR('r'); - APPEND_CHR('y'); - APPEND_CHR('_'); - APPEND_CHR('c'); - APPEND_CHR('o'); - APPEND_CHR('n'); - APPEND_CHR('s'); - APPEND_CHR('t'); - APPEND_CHR('r'); - APPEND_CHR('u'); - APPEND_CHR('c'); - APPEND_CHR('t'); - APPEND_CHR(' '); - APPEND_CHR('>'); - APPEND_CHR('>'); + APPEND_CHR8('<','<',' ','e','n','t','r','y'); + APPEND_CHR8('_','c','o','n','s','t','r','u'); + APPEND_CHR4('t',' ','>','>'); APPEND_CHR('\0'); stringof(this->buf); } @@ -385,17 +383,8 @@ dtrace:helper:ustack: SMI_VALUE(this->marker) == V8_FT_EXIT/ { this->done = 1; - APPEND_CHR('<'); - APPEND_CHR('<'); - APPEND_CHR(' '); - APPEND_CHR('e'); - APPEND_CHR('x'); - APPEND_CHR('i'); - APPEND_CHR('t'); - APPEND_CHR(' '); - APPEND_CHR('>'); - APPEND_CHR('>'); - APPEND_CHR('\0'); + APPEND_CHR8('<','<',' ','e','x','i','t',' '); + APPEND_CHR4('>','>','\0','\0'); stringof(this->buf); } @@ -404,21 +393,8 @@ dtrace:helper:ustack: SMI_VALUE(this->marker) == V8_FT_INTERNAL/ { this->done = 1; - APPEND_CHR('<'); - APPEND_CHR('<'); - APPEND_CHR(' '); - APPEND_CHR('i'); - APPEND_CHR('n'); - APPEND_CHR('t'); - APPEND_CHR('e'); - APPEND_CHR('r'); - APPEND_CHR('n'); - APPEND_CHR('a'); - APPEND_CHR('l'); - APPEND_CHR(' '); - APPEND_CHR('>'); - APPEND_CHR('>'); - APPEND_CHR('\0'); + APPEND_CHR8('<','<',' ','i','n','t','e','r'); + APPEND_CHR8('n','a','l',' ','>','>','\0','\0'); stringof(this->buf); } @@ -427,24 +403,9 @@ dtrace:helper:ustack: SMI_VALUE(this->marker) == V8_FT_CONSTRUCT/ { this->done = 1; - APPEND_CHR('<'); - APPEND_CHR('<'); - APPEND_CHR(' '); - APPEND_CHR('c'); - APPEND_CHR('o'); - APPEND_CHR('n'); - APPEND_CHR('s'); - APPEND_CHR('t'); - APPEND_CHR('r'); - APPEND_CHR('u'); - APPEND_CHR('c'); - APPEND_CHR('t'); - APPEND_CHR('o'); - APPEND_CHR('r'); - APPEND_CHR(' '); - APPEND_CHR('>'); - APPEND_CHR('>'); - APPEND_CHR('\0'); + APPEND_CHR8('<','<',' ','c','o','n','s','t'); + APPEND_CHR8('r','u','c','t','o','r',' ','>'); + APPEND_CHR4('>','\0','\0','\0'); stringof(this->buf); } @@ -456,8 +417,8 @@ dtrace:helper:ustack: dtrace:helper:ustack: /!this->done/ { - this->func = COPYIN_UINT32(this->fp + V8_OFF_FP_FUNC); - this->map = V8_MAP_PTR(COPYIN_UINT32(this->func + V8_OFF_HEAPOBJ_MAP)); + this->func = COPYIN_PTR(this->fp + V8_OFF_FP_FUNC); + this->map = V8_MAP_PTR(COPYIN_PTR(this->func + V8_OFF_HEAPOBJ_MAP)); this->attrs = COPYIN_UINT8(this->map + V8_OFF_MAP_ATTRS); } @@ -465,26 +426,9 @@ dtrace:helper:ustack: /!this->done && this->attrs == V8_IT_CODE/ { this->done = 1; - APPEND_CHR('<'); - APPEND_CHR('<'); - APPEND_CHR(' '); - APPEND_CHR('i'); - APPEND_CHR('n'); - APPEND_CHR('t'); - APPEND_CHR('e'); - APPEND_CHR('r'); - APPEND_CHR('n'); - APPEND_CHR('a'); - APPEND_CHR('l'); - APPEND_CHR(' '); - APPEND_CHR('c'); - APPEND_CHR('o'); - APPEND_CHR('d'); - APPEND_CHR('e'); - APPEND_CHR(' '); - APPEND_CHR('>'); - APPEND_CHR('>'); - APPEND_CHR('\0'); + APPEND_CHR8('<','<',' ','i','n','t','e','r'); + APPEND_CHR8('n','a','l',' ','c','o','d','e'); + APPEND_CHR4(' ','>','>','\0'); stringof(this->buf); } @@ -499,8 +443,8 @@ dtrace:helper:ustack: this->map = 0; this->attrs = 0; - this->shared = COPYIN_UINT32(this->func + V8_OFF_FUNC_SHARED); - this->funcnamestr = COPYIN_UINT32(this->shared + V8_OFF_SHARED_NAME); + this->shared = COPYIN_PTR(this->func + V8_OFF_FUNC_SHARED); + this->funcnamestr = COPYIN_PTR(this->shared + V8_OFF_SHARED_NAME); LOAD_STRFIELDS(this->funcnamestr, this->funcnamelen, this->funcnameattrs); } @@ -513,18 +457,11 @@ dtrace:helper:ustack: * some object then V8 will have computed an inferred name that we can * include in the stack trace. */ - APPEND_CHR('('); - APPEND_CHR('a'); - APPEND_CHR('n'); - APPEND_CHR('o'); - APPEND_CHR('n'); - APPEND_CHR(')'); - APPEND_CHR(' '); - APPEND_CHR('a'); + APPEND_CHR8('(','a','n','o','n',')',' ','a'); APPEND_CHR('s'); APPEND_CHR(' '); - this->funcnamestr = COPYIN_UINT32(this->shared + V8_OFF_SHARED_INFERRED); + this->funcnamestr = COPYIN_PTR(this->shared + V8_OFF_SHARED_INFERRED); LOAD_STRFIELDS(this->funcnamestr, this->funcnamelen, this->funcnameattrs); } @@ -533,10 +470,7 @@ dtrace:helper:ustack: /!this->done && this->funcnamelen == 0/ { APPEND_CHR('('); - APPEND_CHR('a'); - APPEND_CHR('n'); - APPEND_CHR('o'); - APPEND_CHR('n'); + APPEND_CHR4('a','n','o','n'); APPEND_CHR(')'); } @@ -548,15 +482,19 @@ APPEND_V8STR(this->funcnamestr, this->funcnamelen, this->funcnameattrs) dtrace:helper:ustack: /!this->done/ { - this->script = COPYIN_UINT32(this->shared + V8_OFF_SHARED_SCRIPT); - this->scriptnamestr = COPYIN_UINT32(this->script + V8_OFF_SCRIPT_NAME); + this->script = COPYIN_PTR(this->shared + V8_OFF_SHARED_SCRIPT); + this->scriptnamestr = COPYIN_PTR(this->script + V8_OFF_SCRIPT_NAME); LOAD_STRFIELDS(this->scriptnamestr, this->scriptnamelen, this->scriptnameattrs); - APPEND_CHR(' '); - APPEND_CHR('a'); - APPEND_CHR('t'); - APPEND_CHR(' '); + APPEND_CHR4(' ','a','t',' '); +} + +dtrace:helper:ustack: +/!this->done && this->scriptnamelen == 0/ +{ + APPEND_CHR8('<','u','n','k','n','o','w','n'); + APPEND_CHR('>'); } APPEND_V8STR(this->scriptnamestr, this->scriptnamelen, this->scriptnameattrs) @@ -568,8 +506,8 @@ dtrace:helper:ustack: /!this->done/ { this->position = COPYIN_UINT32(this->shared + V8_OFF_SHARED_FUNTOK); - this->line_ends = COPYIN_UINT32(this->script + V8_OFF_SCRIPT_LENDS); - this->map = V8_MAP_PTR(COPYIN_UINT32(this->line_ends + V8_OFF_HEAPOBJ_MAP)); + this->line_ends = COPYIN_PTR(this->script + V8_OFF_SCRIPT_LENDS); + this->map = V8_MAP_PTR(COPYIN_PTR(this->line_ends + V8_OFF_HEAPOBJ_MAP)); this->le_attrs = COPYIN_UINT8(this->map + V8_OFF_MAP_ATTRS); } @@ -581,14 +519,7 @@ dtrace:helper:ustack: * undefined because V8 has not had to compute it yet. In this case we * just show the raw position and call it a day. */ - APPEND_CHR(' '); - APPEND_CHR('p'); - APPEND_CHR('o'); - APPEND_CHR('s'); - APPEND_CHR('i'); - APPEND_CHR('t'); - APPEND_CHR('i'); - APPEND_CHR('o'); + APPEND_CHR8(' ','p','o','s','i','t','i','o'); APPEND_CHR('n'); APPEND_CHR(' '); APPEND_NUM(this->position); @@ -608,10 +539,10 @@ dtrace:helper:ustack: { /* initialize binary search */ this->bsearch_line = this->position < - COPYIN_UINT32(this->line_ends + V8_OFF_FA_DATA) ? 1 : 0; + SMI_VALUE(COPYIN_PTR(this->line_ends + V8_OFF_FA_DATA)) ? 1 : 0; this->bsearch_min = 0; this->bsearch_max = this->bsearch_line != 0 ? 0 : - SMI_VALUE(COPYIN_UINT32(this->line_ends + V8_OFF_FA_SIZE)) - 1; + SMI_VALUE(COPYIN_PTR(this->line_ends + V8_OFF_FA_SIZE)) - 1; } /* @@ -628,16 +559,18 @@ dtrace:helper:ustack: \ dtrace:helper:ustack: \ /!this->done && this->bsearch_max >= 1 && \ - this->position > COPYIN_UINT32(this->line_ends + V8_OFF_FA_DATA + \ - this->ii * sizeof (uint32_t))/ \ + this->position > SMI_VALUE( \ + COPYIN_PTR(this->line_ends + V8_OFF_FA_DATA + \ + this->ii * sizeof (uint32_t)))/ \ { \ this->bsearch_min = this->ii + 1; \ } \ \ dtrace:helper:ustack: \ /!this->done && this->bsearch_max >= 1 && \ - this->position <= COPYIN_UINT32(this->line_ends + V8_OFF_FA_DATA + \ - (this->ii - 1) * sizeof (uint32_t))/ \ + this->position <= SMI_VALUE( \ + COPYIN_PTR(this->line_ends + V8_OFF_FA_DATA + \ + (this->ii - 1) * sizeof (uint32_t)))/ \ { \ this->bsearch_max = this->ii - 1; \ } @@ -668,10 +601,7 @@ dtrace:helper:ustack: /!this->done/ { APPEND_CHR(' '); - APPEND_CHR('l'); - APPEND_CHR('i'); - APPEND_CHR('n'); - APPEND_CHR('e'); + APPEND_CHR4('l','i','n','e'); APPEND_CHR(' '); APPEND_NUM(this->bsearch_line); APPEND_CHR('\0'); diff --git a/tools/genv8constants.py b/tools/genv8constants.py index efc644152dc9..fb8b5ffa8c69 100755 --- a/tools/genv8constants.py +++ b/tools/genv8constants.py @@ -18,8 +18,10 @@ outfile = file(sys.argv[1], 'w'); pipe = subprocess.Popen([ 'objdump', '-z', '-D', sys.argv[2] ], bufsize=-1, stdout=subprocess.PIPE).stdout; -pattern = re.compile('00000000 <(v8dbg_.*)>:'); -numpattern = re.compile('[0-9a-fA-F]{2}'); +pattern = re.compile('(00000000|0000000000000000) <(.*)>:'); +v8dbg = re.compile('^v8dbg.*$') +numpattern = re.compile('^[0-9a-fA-F]{2} $'); +octets = 4 outfile.write(""" /* @@ -32,13 +34,27 @@ #ifndef V8_CONSTANTS_H #define V8_CONSTANTS_H -#if defined(__i386) """); curr_sym = None; curr_val = 0; curr_octet = 0; +def out_reset(): + global curr_sym, curr_val, curr_octet + curr_sym = None; + curr_val = 0; + curr_octet = 0; + +def out_define(): + global curr_sym, curr_val, curr_octet, outfile, octets + if curr_sym != None: + if curr_val & 0x80000000 != 0: + outfile.write("#define %s -0x%x\n" % (curr_sym.upper(), 0x100000000 - curr_val)); + else: + outfile.write("#define %s 0x%x\n" % (curr_sym.upper(), curr_val)); + out_reset(); + for line in pipe: if curr_sym != None: # @@ -51,32 +67,34 @@ for i in range (0, 3): # 6-character margin, 2-characters + 1 space for each field idx = 6 + i * 3; - octetstr = line[idx:idx+2] + octetstr = line[idx:idx+3] if not numpattern.match(octetstr): break; + if curr_octet > octets: + break; + curr_val += int('0x%s' % octetstr, 16) << (curr_octet * 8); curr_octet += 1; - if curr_octet < 4: - continue; - - outfile.write("#define %s 0x%x\n" % (curr_sym.upper(), curr_val)); - curr_sym = None; - curr_val = 0; - curr_octet = 0; - continue; - match = pattern.match(line) if match == None: continue; - curr_sym = match.group(1); + octets = len(match.group(1)) / 2; + + # Print previous symbol + out_define(); + + v8match = v8dbg.match(match.group(2)); + if v8match != None: + out_reset(); + curr_sym = match.group(2); + +# Print last symbol +out_define(); outfile.write(""" -#else -#error "only i386 is supported for DTrace ustack helper" -#endif #endif /* V8_CONSTANTS_H */ """);