Skip to content

Commit cc15299

Browse files
Dave Pachecobnoordhuis
authored andcommitted
build: add support for DTrace and postmortem
* fixes nodejs#2110 * includes V8 postmortem metadata in Solaris builds * adds GYP support for DTrace probes and ustack helper * ustack helper derives constants dynamically from libv8_base.a * build with DTrace support by default on SunOS
1 parent 7bdeed2 commit cc15299

7 files changed

Lines changed: 283 additions & 95 deletions

File tree

common.gypi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
'library%': 'static_library', # allow override to 'shared_library' for DLL/.so builds
99
'component%': 'static_library', # NB. these names match with what V8 expects
1010
'msvs_multi_core_compile': '0', # we do enable multicore compiles, but not using the V8 way
11+
'v8_postmortem_support': 'true', # V8's postmortem metadata
1112
},
1213

1314
'target_defaults': {
@@ -42,6 +43,8 @@
4243
}],
4344
['OS=="solaris"', {
4445
'cflags': [ '-fno-omit-frame-pointer' ],
46+
# pull in V8's postmortem metadata
47+
'ldflags': [ '-Wl,-z,allextract' ]
4548
}],
4649
['strict_aliasing!="true"', {
4750
'cflags': [ '-fno-strict-aliasing' ],

configure

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,12 @@ parser.add_option("--shared-zlib-libname",
108108
parser.add_option("--with-dtrace",
109109
action="store_true",
110110
dest="with_dtrace",
111-
help="Build with DTrace (experimental)")
111+
help="Build with DTrace (default is true on supported systems)")
112+
113+
parser.add_option("--without-dtrace",
114+
action="store_true",
115+
dest="without_dtrace",
116+
help="Build without DTrace")
112117

113118
# CHECKME does this still work with recent releases of V8?
114119
parser.add_option("--gdb",
@@ -225,7 +230,6 @@ def gcc_version():
225230
def configure_node(o):
226231
# TODO add gdb
227232
o['variables']['node_prefix'] = options.prefix if options.prefix else ''
228-
o['variables']['node_use_dtrace'] = b(options.with_dtrace)
229233
o['variables']['node_install_npm'] = b(not options.without_npm)
230234
o['variables']['node_install_waf'] = b(not options.without_waf)
231235
o['variables']['host_arch'] = host_arch()
@@ -242,6 +246,16 @@ def configure_node(o):
242246
if 'clang' not in CC and gcc_version() < [False, 4, 0, 0]:
243247
o['variables']['visibility'] = ''
244248

249+
# By default, enable DTrace on SunOS systems. Don't allow it on other
250+
# systems, since it won't work. (The MacOS build process is different than
251+
# SunOS, and we haven't implemented it.)
252+
if sys.platform.startswith('sunos'):
253+
o['variables']['node_use_dtrace'] = b(not options.without_dtrace);
254+
elif b(options.with_dtrace) == 'true':
255+
raise Exception('DTrace is currently only supported on SunOS systems.')
256+
else:
257+
o['variables']['node_use_dtrace'] = 'false'
258+
245259

246260
def configure_libz(o):
247261
o['variables']['node_shared_zlib'] = b(options.shared_zlib)

node.gyp

Lines changed: 95 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Turn off -Werror in V8
55
# See http://codereview.chromium.org/8159015
66
'werror': '',
7-
'node_use_dtrace': 'false',
7+
'node_use_dtrace%': 'false',
88
'node_shared_v8%': 'false',
99
'node_shared_zlib%': 'false',
1010
'node_use_openssl%': 'true',
@@ -138,14 +138,26 @@
138138
}],
139139

140140
[ 'node_use_dtrace=="true"', {
141+
'defines': [ 'HAVE_DTRACE=1' ],
142+
'dependencies': [ 'node_dtrace_header' ],
143+
'include_dirs': [ '<(SHARED_INTERMEDIATE_DIR)' ],
144+
#
145+
# node_dtrace_provider.cc and node_dtrace_ustack.cc do not actually
146+
# exist. They're here to trick GYP into linking the corresponding
147+
# object files into the final "node" executable. These files are
148+
# generated by "dtrace -G" using custom actions below, and the
149+
# GYP-generated Makefiles will properly build them when needed.
150+
#
141151
'sources': [
142152
'src/node_dtrace.cc',
143-
'src/node_dtrace.h',
144-
# why does node_provider.h get generated into src and not
145-
# SHARED_INTERMEDIATE_DIR?
146-
'src/node_provider.h',
153+
'src/node_dtrace_provider.cc'
147154
],
148-
}],
155+
'conditions': [ [
156+
'target_arch=="ia32"', {
157+
'sources': [ 'src/node_dtrace_ustack.cc' ]
158+
}
159+
] ],
160+
} ],
149161

150162
[ 'node_shared_v8=="true"', {
151163
'sources': [
@@ -254,6 +266,83 @@
254266
},
255267
],
256268
}, # end node_js2c
269+
{
270+
'target_name': 'node_dtrace_header',
271+
'type': 'none',
272+
'conditions': [
273+
[ 'node_use_dtrace=="true"', {
274+
'actions': [
275+
{
276+
'action_name': 'node_dtrace_header',
277+
'inputs': [ 'src/node_provider.d' ],
278+
'outputs': [ '<(SHARED_INTERMEDIATE_DIR)/node_provider.h' ],
279+
'action': [ 'dtrace', '-h', '-xnolibs', '-s', '<@(_inputs)',
280+
'-o', '<@(_outputs)' ]
281+
}
282+
]
283+
} ]
284+
]
285+
},
286+
{
287+
'target_name': 'node_dtrace_provider',
288+
'type': 'none',
289+
'conditions': [
290+
[ 'node_use_dtrace=="true"', {
291+
'actions': [
292+
{
293+
'action_name': 'node_dtrace_provider_o',
294+
'inputs': [
295+
'src/node_provider.d',
296+
'<(PRODUCT_DIR)/obj.target/node/src/node_dtrace.o'
297+
],
298+
'outputs': [
299+
'<(PRODUCT_DIR)/obj.target/node/src/node_dtrace_provider.o'
300+
],
301+
'action': [ 'dtrace', '-G', '-xnolibs', '-s', '<@(_inputs)',
302+
'-o', '<@(_outputs)' ]
303+
}
304+
]
305+
} ]
306+
]
307+
},
308+
{
309+
'target_name': 'node_dtrace_ustack',
310+
'type': 'none',
311+
'conditions': [
312+
[ 'node_use_dtrace=="true"', {
313+
'actions': [
314+
{
315+
'action_name': 'node_dtrace_ustack_constants',
316+
'inputs': [
317+
'<(PRODUCT_DIR)/obj.target/deps/v8/tools/gyp/libv8_base.a'
318+
],
319+
'outputs': [
320+
'<(SHARED_INTERMEDIATE_DIR)/v8constants.h'
321+
],
322+
'action': [
323+
'tools/genv8constants.py',
324+
'<@(_outputs)',
325+
'<@(_inputs)'
326+
]
327+
},
328+
{
329+
'action_name': 'node_dtrace_ustack',
330+
'inputs': [
331+
'src/v8ustack.d',
332+
'<(SHARED_INTERMEDIATE_DIR)/v8constants.h'
333+
],
334+
'outputs': [
335+
'<(PRODUCT_DIR)/obj.target/node/src/node_dtrace_ustack.o'
336+
],
337+
'action': [
338+
'dtrace', '-32', '-I<(SHARED_INTERMEDIATE_DIR)', '-Isrc',
339+
'-C', '-G', '-s', 'src/v8ustack.d', '-o', '<@(_outputs)',
340+
]
341+
}
342+
]
343+
} ],
344+
]
345+
}
257346
] # end targets
258347
}
259348

src/v8abbr.h

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* This header defines short names for V8 constants for use by the ustack
3+
* helper.
4+
*/
5+
6+
#ifndef V8_ABBR_H
7+
#define V8_ABBR_H
8+
9+
/* Frame pointer offsets */
10+
#define V8_OFF_FP_FUNC ((uint32_t)V8DBG_OFF_FP_FUNCTION)
11+
#define V8_OFF_FP_CONTEXT ((uint32_t)V8DBG_OFF_FP_CONTEXT)
12+
#define V8_OFF_FP_MARKER ((uint32_t)V8DBG_OFF_FP_MARKER)
13+
14+
/* Stack frame types */
15+
#define V8_FT_ENTRY V8DBG_FRAMETYPE_ENTRYFRAME
16+
#define V8_FT_ENTRYCONSTRUCT V8DBG_FRAMETYPE_ENTRYCONSTRUCTFRAME
17+
#define V8_FT_EXIT V8DBG_FRAMETYPE_EXITFRAME
18+
#define V8_FT_JAVASCRIPT V8DBG_FRAMETYPE_JAVASCRIPTFRAME
19+
#define V8_FT_OPTIMIZED V8DBG_FRAMETYPE_OPTIMIZEDFRAME
20+
#define V8_FT_INTERNAL V8DBG_FRAMETYPE_INTERNALFRAME
21+
#define V8_FT_CONSTRUCT V8DBG_FRAMETYPE_CONSTRUCTFRAME
22+
#define V8_FT_ADAPTOR V8DBG_FRAMETYPE_ARGUMENTSADAPTORFRAME
23+
24+
/* Identification masks and tags */
25+
#define V8_SmiTagMask V8DBG_SMITAGMASK
26+
#define V8_SmiTag V8DBG_SMITAG
27+
#define V8_SmiValueShift V8_SmiTagMask
28+
29+
#define V8_HeapObjectTagMask V8DBG_HEAPOBJECTTAGMASK
30+
#define V8_HeapObjectTag V8DBG_HEAPOBJECTTAG
31+
32+
#define V8_IsNotStringMask V8DBG_ISNOTSTRINGMASK
33+
#define V8_StringTag V8DBG_STRINGTAG
34+
35+
#define V8_StringEncodingMask V8DBG_STRINGENCODINGMASK
36+
#define V8_AsciiStringTag V8DBG_ASCIISTRINGTAG
37+
38+
#define V8_StringRepresentationMask V8DBG_STRINGREPRESENTATIONMASK
39+
#define V8_SeqStringTag V8DBG_SEQSTRINGTAG
40+
#define V8_ConsStringTag V8DBG_CONSSTRINGTAG
41+
#define V8_ExternalStringTag V8DBG_EXTERNALSTRINGTAG
42+
43+
/* Instance types */
44+
#define V8_IT_FIXEDARRAY V8DBG_TYPE_FIXEDARRAY__FIXED_ARRAY_TYPE
45+
#define V8_IT_CODE V8DBG_TYPE_CODE__CODE_TYPE
46+
47+
/* Node-specific offsets */
48+
#define NODE_OFF_EXTSTR_DATA 0x4
49+
50+
/* Heap class->field offsets */
51+
#define V8_OFF_HEAP(off) ((off) - 1)
52+
53+
#define V8_OFF_FUNC_SHARED \
54+
V8_OFF_HEAP(V8DBG_CLASS_JSFUNCTION__SHARED__SHAREDFUNCTIONINFO)
55+
#define V8_OFF_SHARED_NAME \
56+
V8_OFF_HEAP(V8DBG_CLASS_SHAREDFUNCTIONINFO__NAME__OBJECT)
57+
#define V8_OFF_SHARED_INFERRED \
58+
V8_OFF_HEAP(V8DBG_CLASS_SHAREDFUNCTIONINFO__INFERRED_NAME__STRING)
59+
#define V8_OFF_SHARED_SCRIPT \
60+
V8_OFF_HEAP(V8DBG_CLASS_SHAREDFUNCTIONINFO__SCRIPT__OBJECT)
61+
#define V8_OFF_SHARED_FUNTOK \
62+
V8_OFF_HEAP(V8DBG_CLASS_SHAREDFUNCTIONINFO__FUNCTION_TOKEN_POSITION__SMI)
63+
#define V8_OFF_SCRIPT_NAME \
64+
V8_OFF_HEAP(V8DBG_CLASS_SCRIPT__NAME__OBJECT)
65+
#define V8_OFF_SCRIPT_LENDS \
66+
V8_OFF_HEAP(V8DBG_CLASS_SCRIPT__LINE_ENDS__OBJECT)
67+
#define V8_OFF_STR_LENGTH \
68+
V8_OFF_HEAP(V8DBG_CLASS_STRING__LENGTH__SMI)
69+
#define V8_OFF_STR_CHARS \
70+
V8_OFF_HEAP(V8DBG_CLASS_SEQASCIISTRING__CHARS__CHAR)
71+
#define V8_OFF_CONSSTR_CAR \
72+
V8_OFF_HEAP(V8DBG_CLASS_CONSSTRING__FIRST__STRING)
73+
#define V8_OFF_CONSSTR_CDR \
74+
V8_OFF_HEAP(V8DBG_CLASS_CONSSTRING__SECOND__STRING)
75+
#define V8_OFF_EXTSTR_RSRC \
76+
V8_OFF_HEAP(V8DBG_CLASS_EXTERNALSTRING__RESOURCE__OBJECT)
77+
#define V8_OFF_FA_SIZE \
78+
V8_OFF_HEAP(V8DBG_CLASS_FIXEDARRAYBASE__LENGTH__SMI)
79+
#define V8_OFF_FA_DATA \
80+
V8_OFF_HEAP(V8DBG_CLASS_FIXEDARRAY__DATA__UINTPTR_T)
81+
#define V8_OFF_HEAPOBJ_MAP \
82+
V8_OFF_HEAP(V8DBG_CLASS_HEAPOBJECT__MAP__MAP)
83+
#define V8_OFF_MAP_ATTRS \
84+
V8_OFF_HEAP(V8DBG_CLASS_MAP__INSTANCE_ATTRIBUTES__INT)
85+
86+
#endif /* V8_ABBR_H */

src/v8constants.h

Lines changed: 0 additions & 87 deletions
This file was deleted.

src/v8ustack.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212

1313
#include <v8constants.h>
14+
#include <v8abbr.h>
1415

1516
/*
1617
* V8 represents small integers (SMI) using the upper 31 bits of a 32-bit

0 commit comments

Comments
 (0)