• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3// This test verifies that expected postmortem debugging metadata is present
4// in the Node.js binary. These constants are used by tools such as llnode and
5// mdb_v8, so this test ensures that they don't vanish between V8 updates.
6
7const common = require('../common');
8const assert = require('assert');
9const { spawnSync } = require('child_process');
10const { getSharedLibPath } = require('../common/shared-lib-util.js');
11
12// For shared lib case, check shared lib instead
13const args = [
14  process.config.variables.node_shared ?
15    getSharedLibPath() : process.execPath
16];
17
18if (common.isAIX)
19  args.unshift('-Xany', '-B');
20
21if (common.isOpenBSD)
22  common.skip('no v8 debug symbols on OpenBSD');
23
24const nm = spawnSync('nm', args, { maxBuffer: Infinity });
25
26if (nm.error && nm.error.errno === 'ENOENT')
27  common.skip('nm not found on system');
28
29const stderr = nm.stderr.toString();
30if (stderr.length > 0) {
31  common.skip(`Failed to execute nm: ${stderr}`);
32}
33
34const symbolRe = /\s_?(v8dbg_.+)$/;
35const symbols = nm.stdout.toString().split('\n').reduce((filtered, line) => {
36  const match = line.match(symbolRe);
37  const symbol = match && match[1];
38
39  if (symbol)
40    filtered.push(symbol);
41
42  return filtered;
43}, []);
44
45assert.notStrictEqual(symbols.length, 0, 'No postmortem metadata detected');
46
47const missing = getExpectedSymbols().filter((symbol) => {
48  return !symbols.includes(symbol);
49});
50
51assert.strictEqual(missing.length, 0,
52                   `Missing constants: \n${missing.join('\n')}`);
53
54// This is only a function so that the long list of expected symbols can be
55// pushed to the bottom of the file for improved readability.
56function getExpectedSymbols() {
57  return [
58    // Disable the maximum line length for the remainder of the file since it
59    // should only consist of postmortem constants, and some of them can be
60    // relatively long.
61    /* eslint-disable max-len */
62    'v8dbg_class_DescriptorArray__header_size__uintptr_t',
63    'v8dbg_bit_field3_is_dictionary_map_shift',
64    'v8dbg_bit_field3_number_of_own_descriptors_shift',
65    'v8dbg_class_Code__instruction_size__int',
66    'v8dbg_class_Code__instruction_start__uintptr_t',
67    'v8dbg_class_ConsString__first__String',
68    'v8dbg_class_ConsString__second__String',
69    'v8dbg_class_FixedArray__data__uintptr_t',
70    'v8dbg_class_FixedArrayBase__length__SMI',
71    'v8dbg_class_JSTypedArray__base_pointer__Object',
72    'v8dbg_class_JSTypedArray__external_pointer__uintptr_t',
73    'v8dbg_class_HeapNumber__value__double',
74    'v8dbg_class_HeapObject__map__Map',
75    'v8dbg_class_JSArray__length__Object',
76    'v8dbg_class_JSArrayBuffer__backing_store__uintptr_t',
77    'v8dbg_class_JSArrayBuffer__byte_length__size_t',
78    'v8dbg_class_JSArrayBufferView__buffer__Object',
79    'v8dbg_class_JSArrayBufferView__byte_length__size_t',
80    'v8dbg_class_JSArrayBufferView__byte_offset__size_t',
81    'v8dbg_class_JSDate__value__Object',
82    'v8dbg_class_JSFunction__context__Context',
83    'v8dbg_class_JSFunction__shared__SharedFunctionInfo',
84    'v8dbg_class_JSObject__elements__Object',
85    'v8dbg_class_JSObject__internal_fields__uintptr_t',
86    'v8dbg_class_JSReceiver__raw_properties_or_hash__Object',
87    'v8dbg_class_JSRegExp__source__Object',
88    'v8dbg_class_Map__bit_field3__int',
89    'v8dbg_class_Map__constructor_or_backpointer__Object',
90    'v8dbg_class_Map__inobject_properties_start_or_constructor_function_index__char',
91    'v8dbg_class_Map__instance_type__uint16_t',
92    'v8dbg_class_Map__instance_descriptors_offset',
93    'v8dbg_class_Map__instance_size_in_words__char',
94    'v8dbg_class_Oddball__kind_offset__int',
95    'v8dbg_class_Script__line_ends__Object',
96    'v8dbg_class_Script__line_offset__SMI',
97    'v8dbg_class_Script__name__Object',
98    'v8dbg_class_Script__source__Object',
99    'v8dbg_class_SeqOneByteString__chars__char',
100    'v8dbg_class_SeqTwoByteString__chars__char',
101    'v8dbg_class_SharedFunctionInfo__function_data__Object',
102    'v8dbg_class_SharedFunctionInfo__flags__int',
103    'v8dbg_class_UncompiledData__end_position__int32_t',
104    'v8dbg_class_UncompiledData__inferred_name__String',
105    'v8dbg_class_SharedFunctionInfo__internal_formal_parameter_count__uint16_t',
106    'v8dbg_class_SharedFunctionInfo__name_or_scope_info__Object',
107    'v8dbg_class_SharedFunctionInfo__script_or_debug_info__Object',
108    'v8dbg_class_UncompiledData__start_position__int32_t',
109    'v8dbg_class_SlicedString__offset__SMI',
110    'v8dbg_class_SlicedString__parent__String',
111    'v8dbg_class_String__length__int32_t',
112    'v8dbg_class_ThinString__actual__String',
113    'v8dbg_context_idx_scope_info',
114    'v8dbg_context_idx_prev',
115    'v8dbg_context_min_slots',
116    'v8dbg_frametype_ArgumentsAdaptorFrame',
117    'v8dbg_frametype_ConstructEntryFrame',
118    'v8dbg_frametype_ConstructFrame',
119    'v8dbg_frametype_EntryFrame',
120    'v8dbg_frametype_ExitFrame',
121    'v8dbg_frametype_InternalFrame',
122    'v8dbg_frametype_OptimizedFrame',
123    'v8dbg_frametype_StubFrame',
124    'v8dbg_jsarray_buffer_was_detached_mask',
125    'v8dbg_jsarray_buffer_was_detached_shift',
126    'v8dbg_namedictionary_prefix_start_index',
127    'v8dbg_namedictionaryshape_entry_size',
128    'v8dbg_namedictionaryshape_prefix_size',
129    'v8dbg_off_fp_args',
130    'v8dbg_off_fp_context',
131    'v8dbg_off_fp_function',
132    'v8dbg_prop_attributes_mask',
133    'v8dbg_prop_attributes_shift',
134    'v8dbg_prop_attributes_DONT_ENUM',
135    'v8dbg_prop_attributes_DONT_ENUM',
136    'v8dbg_prop_attributes_NONE',
137    'v8dbg_prop_attributes_READ_ONLY',
138    'v8dbg_prop_desc_details',
139    'v8dbg_prop_desc_key',
140    'v8dbg_prop_desc_size',
141    'v8dbg_prop_desc_value',
142    'v8dbg_prop_index_mask',
143    'v8dbg_prop_index_shift',
144    'v8dbg_prop_kind_mask',
145    'v8dbg_prop_kind_Accessor',
146    'v8dbg_prop_kind_Data',
147    'v8dbg_prop_location_mask',
148    'v8dbg_prop_location_shift',
149    'v8dbg_prop_location_Descriptor',
150    'v8dbg_prop_location_Field',
151    'v8dbg_prop_representation_double',
152    'v8dbg_prop_representation_mask',
153    'v8dbg_prop_representation_shift',
154    'v8dbg_scopeinfo_idx_first_vars',
155    'v8dbg_scopeinfo_idx_ncontextlocals',
156    'v8dbg_scopeinfo_idx_nparams',
157    'v8dbg_type_Code__CODE_TYPE',
158    'v8dbg_type_FixedArray__FIXED_ARRAY_TYPE',
159    'v8dbg_type_HeapNumber__HEAP_NUMBER_TYPE',
160    'v8dbg_type_JSArray__JS_ARRAY_TYPE',
161    'v8dbg_type_JSArrayBuffer__JS_ARRAY_BUFFER_TYPE',
162    'v8dbg_type_JSDate__JS_DATE_TYPE',
163    'v8dbg_type_JSFunction__JS_FUNCTION_TYPE',
164    'v8dbg_type_JSGlobalObject__JS_GLOBAL_OBJECT_TYPE',
165    'v8dbg_type_JSGlobalProxy__JS_GLOBAL_PROXY_TYPE',
166    'v8dbg_type_JSObject__JS_OBJECT_TYPE',
167    'v8dbg_type_JSRegExp__JS_REGEXP_TYPE',
168    'v8dbg_type_JSTypedArray__JS_TYPED_ARRAY_TYPE',
169    'v8dbg_type_Map__MAP_TYPE',
170    'v8dbg_type_Oddball__ODDBALL_TYPE',
171    'v8dbg_type_Script__SCRIPT_TYPE',
172    'v8dbg_type_SharedFunctionInfo__SHARED_FUNCTION_INFO_TYPE',
173    'v8dbg_APIObjectType',
174    'v8dbg_ConsStringTag',
175    'v8dbg_ExternalStringTag',
176    'v8dbg_FirstNonstringType',
177    'v8dbg_HeapObjectTag',
178    'v8dbg_HeapObjectTagMask',
179    'v8dbg_OddballException',
180    'v8dbg_OddballFalse',
181    'v8dbg_OddballNull',
182    'v8dbg_OddballTheHole',
183    'v8dbg_OddballTrue',
184    'v8dbg_OddballUndefined',
185    'v8dbg_OddballUninitialized',
186    'v8dbg_OneByteStringTag',
187    'v8dbg_SystemPointerSize',
188    'v8dbg_SystemPointerSizeLog2',
189    'v8dbg_TaggedSize',
190    'v8dbg_TaggedSizeLog2',
191    'v8dbg_SeqStringTag',
192    'v8dbg_SlicedStringTag',
193    'v8dbg_SmiShiftSize',
194    'v8dbg_SmiTag',
195    'v8dbg_SmiTagMask',
196    'v8dbg_SpecialAPIObjectType',
197    'v8dbg_StringEncodingMask',
198    'v8dbg_StringRepresentationMask',
199    'v8dbg_ThinStringTag',
200    'v8dbg_TwoByteStringTag',
201  ];
202}
203