Skip to content

Commit 4fe78fe

Browse files
committed
build: enable V8 gdb/lldb plugin support
Build `v8_debug_helper.{so|dylib}` to enable V8 gdb/lldb postmortem plugin support for the V8 version that Node.js built with. Signed-off-by: Chengzhong Wu <[email protected]>
1 parent 1e9fd95 commit 4fe78fe

6 files changed

Lines changed: 198 additions & 136 deletions

File tree

common.gypi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
'emulator%': [],
1818

1919
'node_shared%': 'false',
20+
'node_enable_v8debughelper%': 'false',
2021
'node_enable_experimentals%': 'false',
2122
'force_dynamic_crt%': 0,
2223
'node_use_v8_platform%': 'true',
@@ -654,7 +655,9 @@
654655
'cflags!': [ '-pthread' ],
655656
'ldflags!': [ '-pthread' ],
656657
}],
657-
[ 'node_shared=="true"', {
658+
# The V8 static libraries get linked into libv8_debug_helper, so they
659+
# have to be position independent too.
660+
[ 'node_shared=="true" or node_enable_v8debughelper=="true"', {
658661
'cflags': [ '-fPIC' ],
659662
'ldflags': [ '-fPIC' ],
660663
}],

configure.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,13 @@
850850
default=None,
851851
help=argparse.SUPPRESS) # Undocumented.
852852

853+
parser.add_argument('--enable-v8debughelper',
854+
action='store_true',
855+
dest='enable_v8debughelper',
856+
default=None,
857+
help='Build V8\'s debug helper as a shared library, loadable by a debugger '
858+
'extension.')
859+
853860
parser.add_argument('--enable-trace-maps',
854861
action='store_true',
855862
dest='trace_maps',
@@ -2248,13 +2255,16 @@ def configure_v8(o, configs):
22482255
o['variables']['force_dynamic_crt'] = 1 if options.shared else 0
22492256
o['variables']['node_enable_d8'] = b(options.enable_d8)
22502257
o['variables']['node_enable_v8windbg'] = b(options.enable_v8windbg)
2258+
o['variables']['node_enable_v8debughelper'] = b(options.enable_v8debughelper)
22512259
if options.enable_d8:
22522260
o['variables']['test_isolation_mode'] = 'noop' # Needed by d8.gyp.
22532261
if options.without_bundled_v8:
22542262
if options.enable_d8:
22552263
raise Exception('--enable-d8 is incompatible with --without-bundled-v8.')
22562264
if options.enable_v8windbg:
22572265
raise Exception('--enable-v8windbg is incompatible with --without-bundled-v8.')
2266+
if options.enable_v8debughelper:
2267+
raise Exception('--enable-v8debughelper is incompatible with --without-bundled-v8.')
22582268
(pkg_libs, pkg_cflags, pkg_libpath, _) = pkg_config("v8")
22592269
if pkg_libs and pkg_libpath:
22602270
output['libraries'] += [pkg_libpath] + pkg_libs.split()

node.gypi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@
9999
[ 'node_enable_v8windbg=="true"', {
100100
'dependencies': [ 'tools/v8_gypfiles/v8windbg.gyp:build_v8windbg' ],
101101
}],
102+
[ 'node_enable_v8debughelper=="true"', {
103+
'dependencies': [ 'tools/v8_gypfiles/v8_debug_helper.gyp:build_v8_debug_helper' ],
104+
}],
102105
[ 'node_use_bundled_v8=="true"', {
103106
'dependencies': [
104107
'tools/v8_gypfiles/v8.gyp:v8_snapshot',

tools/v8_gypfiles/v8.gyp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@
6262
'BUILDING_V8_PLATFORM_SHARED', # Make V8_PLATFORM_EXPORT visible.
6363
]
6464
}],
65-
['node_shared=="true"', {
65+
# The V8 static libraries get linked into libv8_debug_helper too, and
66+
# the local-exec TLS model is only valid in an executable.
67+
['node_shared=="true" or node_enable_v8debughelper=="true"', {
6668
'defines': [
6769
'V8_TLS_USED_IN_LIBRARY', # Enable V8_TLS_LIBRARY_MODE.
6870
],
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
{
2+
'variables': {
3+
'V8_ROOT': '../../deps/v8',
4+
'v8_code': 1,
5+
# v8windbg links the helper statically. When the helper is the requested
6+
# artifact it is built as a shared library instead, so a debugger
7+
# extension can load it on its own.
8+
'v8_debug_helper_type%': 'static_library',
9+
'conditions': [
10+
[ 'node_enable_v8debughelper=="true"', {
11+
'v8_debug_helper_type': 'shared_library',
12+
}],
13+
],
14+
},
15+
'includes': ['toolchain.gypi', 'features.gypi'],
16+
'targets': [
17+
{
18+
# Intermediate target to build the debug helper. dependencies_traverse
19+
# stops gyp from propagating the library up to node.gypi as a link
20+
# input. The library is only supposed to be loaded by a debugger.
21+
'target_name': 'build_v8_debug_helper',
22+
'type': 'none',
23+
'dependencies_traverse': 0,
24+
'hard_dependency': 1,
25+
'dependencies': [
26+
'v8_debug_helper',
27+
],
28+
}, # build_v8_debug_helper
29+
{
30+
'target_name': 'v8_debug_helper',
31+
'type': '<(v8_debug_helper_type)',
32+
'include_dirs': [
33+
'<(V8_ROOT)',
34+
'<(V8_ROOT)/include',
35+
],
36+
'dependencies': [
37+
'gen_heap_constants',
38+
39+
'v8.gyp:generate_bytecode_builtins_list',
40+
'v8.gyp:run_torque',
41+
'v8.gyp:v8_maybe_icu',
42+
'v8.gyp:fp16',
43+
'v8.gyp:v8_libbase',
44+
'v8.gyp:v8_snapshot',
45+
],
46+
'sources': [
47+
'<!@pymod_do_main(GN-scraper "<(V8_ROOT)/tools/debug_helper/BUILD.gn" "\"v8_debug_helper_internal\".*?sources = ")',
48+
"<(SHARED_INTERMEDIATE_DIR)/torque-generated/class-debug-readers.cc",
49+
"<(SHARED_INTERMEDIATE_DIR)/torque-generated/class-debug-readers.h",
50+
"<(SHARED_INTERMEDIATE_DIR)/torque-generated/debug-macros.cc",
51+
"<(SHARED_INTERMEDIATE_DIR)/torque-generated/debug-macros.h",
52+
"<(SHARED_INTERMEDIATE_DIR)/torque-generated/instance-types.h",
53+
],
54+
# Enable RTTI //build/config/compiler:rtti
55+
'cflags_cc': [ '-frtti' ],
56+
'cflags_cc!': [ '-fno-rtti' ],
57+
'xcode_settings': {
58+
'GCC_ENABLE_CPP_RTTI': 'YES', # -frtti
59+
},
60+
'msvs_settings': {
61+
'VCCLCompilerTool': {
62+
'RuntimeTypeInfo': 'true',
63+
},
64+
},
65+
'configurations': {
66+
'Release': { # Override target_defaults.Release in common.gypi
67+
'msvs_settings': {
68+
'VCCLCompilerTool': {
69+
'RuntimeTypeInfo': 'true',
70+
},
71+
},
72+
},
73+
},
74+
'conditions': [
75+
['node_shared_abseil=="false"', {
76+
'dependencies': ['abseil.gyp:abseil'],
77+
}],
78+
[ 'v8_enable_temporal_support==1 and node_shared_temporal_capi=="false"', {
79+
'dependencies': [
80+
'../../deps/crates/crates.gyp:temporal_capi',
81+
],
82+
}],
83+
[ 'v8_debug_helper_type=="shared_library"', {
84+
# The entry points in debug-helper.h are only given default
85+
# visibility, or dllexport on Windows, when this is defined. Node
86+
# builds with hidden visibility, so without it the library exports
87+
# nothing.
88+
'defines': [ 'BUILDING_V8_DEBUG_HELPER' ],
89+
'direct_dependent_settings': {
90+
'defines': [ 'USING_V8_DEBUG_HELPER' ],
91+
},
92+
}],
93+
],
94+
}, # v8_debug_helper
95+
{
96+
'target_name': 'gen_heap_constants',
97+
'type': 'none',
98+
'hard_dependency': 1,
99+
'dependencies': [
100+
'run_mkgrokdump',
101+
],
102+
'direct_dependent_settings': {
103+
'sources': [
104+
'<(SHARED_INTERMEDIATE_DIR)/heap-constants-gen.cc',
105+
],
106+
},
107+
'actions': [
108+
{
109+
'action_name': 'run_gen_heap_constants',
110+
'inputs': [
111+
'<(V8_ROOT)/tools/debug_helper/gen-heap-constants.py',
112+
],
113+
'outputs': [
114+
'<(SHARED_INTERMEDIATE_DIR)/heap-constants-gen.cc',
115+
],
116+
'action': [
117+
'<(python)',
118+
'<(V8_ROOT)/tools/debug_helper/gen-heap-constants.py',
119+
'<(SHARED_INTERMEDIATE_DIR)',
120+
'<@(_outputs)',
121+
]
122+
}
123+
]
124+
}, # gen_heap_constants
125+
{
126+
'target_name': 'run_mkgrokdump',
127+
'type': 'none',
128+
'hard_dependency': 1,
129+
'dependencies': [
130+
'mkgrokdump',
131+
],
132+
'actions': [
133+
{
134+
'action_name': 'run_gen_heap_constants',
135+
'inputs': [
136+
'<(V8_ROOT)/tools/run.py',
137+
],
138+
'outputs': [
139+
'<(SHARED_INTERMEDIATE_DIR)/v8heapconst.py',
140+
],
141+
'action': [
142+
'<(python)',
143+
'<(V8_ROOT)/tools/run.py',
144+
'<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)mkgrokdump<(EXECUTABLE_SUFFIX)',
145+
'--outfile',
146+
'<@(_outputs)',
147+
]
148+
}
149+
]
150+
}, # run_mkgrokdump
151+
{
152+
'target_name': 'mkgrokdump',
153+
'type': 'executable',
154+
'include_dirs': [
155+
'<(V8_ROOT)',
156+
'<(V8_ROOT)/include',
157+
],
158+
'dependencies': [
159+
'v8.gyp:v8_snapshot',
160+
'v8.gyp:v8_libbase',
161+
'v8.gyp:v8_libplatform',
162+
'v8.gyp:v8_maybe_icu',
163+
'v8.gyp:fp16',
164+
'v8.gyp:generate_bytecode_builtins_list',
165+
'v8.gyp:run_torque',
166+
],
167+
'conditions': [
168+
['node_shared_abseil=="false"', {
169+
'dependencies': ['abseil.gyp:abseil'],
170+
}],
171+
],
172+
'sources': [
173+
'<!@pymod_do_main(GN-scraper "<(V8_ROOT)/test/mkgrokdump/BUILD.gn" "mkgrokdump.*?sources = ")',
174+
]
175+
}, # mkgrokdump
176+
],
177+
}

tools/v8_gypfiles/v8windbg.gyp

Lines changed: 1 addition & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
'<(V8_ROOT)/include',
2525
],
2626
'dependencies': [
27-
'v8_debug_helper',
27+
'v8_debug_helper.gyp:v8_debug_helper',
2828
'v8.gyp:v8_libbase',
2929
],
3030
'sources': [
@@ -40,138 +40,5 @@
4040
],
4141
},
4242
}, # v8windbg
43-
{
44-
'target_name': 'v8_debug_helper',
45-
'type': 'static_library',
46-
'include_dirs': [
47-
'<(V8_ROOT)',
48-
'<(V8_ROOT)/include',
49-
],
50-
'dependencies': [
51-
'gen_heap_constants',
52-
53-
'v8.gyp:generate_bytecode_builtins_list',
54-
'v8.gyp:run_torque',
55-
'v8.gyp:v8_maybe_icu',
56-
'v8.gyp:fp16',
57-
'v8.gyp:v8_libbase',
58-
'v8.gyp:v8_snapshot',
59-
],
60-
'sources': [
61-
'<!@pymod_do_main(GN-scraper "<(V8_ROOT)/tools/debug_helper/BUILD.gn" "\"v8_debug_helper_internal\".*?sources = ")',
62-
"<(SHARED_INTERMEDIATE_DIR)/torque-generated/class-debug-readers.cc",
63-
"<(SHARED_INTERMEDIATE_DIR)/torque-generated/class-debug-readers.h",
64-
"<(SHARED_INTERMEDIATE_DIR)/torque-generated/debug-macros.cc",
65-
"<(SHARED_INTERMEDIATE_DIR)/torque-generated/debug-macros.h",
66-
"<(SHARED_INTERMEDIATE_DIR)/torque-generated/instance-types.h",
67-
],
68-
# Enable RTTI //build/config/compiler:rtti
69-
'cflags_cc': [ '-frtti' ],
70-
'cflags_cc!': [ '-fno-rtti' ],
71-
'xcode_settings': {
72-
'GCC_ENABLE_CPP_RTTI': 'YES', # -frtti
73-
},
74-
'msvs_settings': {
75-
'VCCLCompilerTool': {
76-
'RuntimeTypeInfo': 'true',
77-
},
78-
},
79-
'configurations': {
80-
'Release': { # Override target_defaults.Release in common.gypi
81-
'msvs_settings': {
82-
'VCCLCompilerTool': {
83-
'RuntimeTypeInfo': 'true',
84-
},
85-
},
86-
},
87-
},
88-
89-
'conditions': [
90-
['node_shared_abseil=="false"', {
91-
'dependencies': ['abseil.gyp:abseil'],
92-
}],
93-
],
94-
}, # v8_debug_helper
95-
{
96-
'target_name': 'gen_heap_constants',
97-
'type': 'none',
98-
'hard_dependency': 1,
99-
'dependencies': [
100-
'run_mkgrokdump',
101-
],
102-
'direct_dependent_settings': {
103-
'sources': [
104-
'<(SHARED_INTERMEDIATE_DIR)/heap-constants-gen.cc',
105-
],
106-
},
107-
'actions': [
108-
{
109-
'action_name': 'run_gen_heap_constants',
110-
'inputs': [
111-
'<(V8_ROOT)/tools/debug_helper/gen-heap-constants.py',
112-
],
113-
'outputs': [
114-
'<(SHARED_INTERMEDIATE_DIR)/heap-constants-gen.cc',
115-
],
116-
'action': [
117-
'<(python)',
118-
'<(V8_ROOT)/tools/debug_helper/gen-heap-constants.py',
119-
'<(SHARED_INTERMEDIATE_DIR)',
120-
'<@(_outputs)',
121-
]
122-
}
123-
]
124-
}, # gen_heap_constants
125-
{
126-
'target_name': 'run_mkgrokdump',
127-
'type': 'none',
128-
'hard_dependency': 1,
129-
'dependencies': [
130-
'mkgrokdump',
131-
],
132-
'actions': [
133-
{
134-
'action_name': 'run_gen_heap_constants',
135-
'inputs': [
136-
'<(V8_ROOT)/tools/run.py',
137-
],
138-
'outputs': [
139-
'<(SHARED_INTERMEDIATE_DIR)/v8heapconst.py',
140-
],
141-
'action': [
142-
'<(python)',
143-
'<(V8_ROOT)/tools/run.py',
144-
'<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)mkgrokdump<(EXECUTABLE_SUFFIX)',
145-
'--outfile',
146-
'<@(_outputs)',
147-
]
148-
}
149-
]
150-
}, # run_mkgrokdump
151-
{
152-
'target_name': 'mkgrokdump',
153-
'type': 'executable',
154-
'include_dirs': [
155-
'<(V8_ROOT)',
156-
'<(V8_ROOT)/include',
157-
],
158-
'dependencies': [
159-
'v8.gyp:v8_snapshot',
160-
'v8.gyp:v8_libbase',
161-
'v8.gyp:v8_libplatform',
162-
'v8.gyp:v8_maybe_icu',
163-
'v8.gyp:fp16',
164-
'v8.gyp:generate_bytecode_builtins_list',
165-
'v8.gyp:run_torque',
166-
],
167-
'conditions': [
168-
['node_shared_abseil=="false"', {
169-
'dependencies': ['abseil.gyp:abseil'],
170-
}],
171-
],
172-
'sources': [
173-
'<!@pymod_do_main(GN-scraper "<(V8_ROOT)/test/mkgrokdump/BUILD.gn" "mkgrokdump.*?sources = ")',
174-
]
175-
}, # mkgrokdump
17643
],
17744
}

0 commit comments

Comments
 (0)