Skip to content

Commit a735c16

Browse files
danbevitaloacasas
authored andcommitted
deps: backport ec1ffe3 from upstream V8
This commit adds lldbinit files from upstream V8 and also adds these so that they get installed when `make install` is run. Original commit message: [tools] add lldbinit The goal of this commit is to add the equivalent to gdbinit but for lldb. I've tried to replicate the commands as close as possible but I'm unsure about the jss command and hoping to get some feedback on it in addition to the bta command which I'm not sure how/when this could be used. This is probably just inexperience on my part. The lldbinit file can be placed into a directory prefixed with dot (.lldbinit) and the python script is currently expected to be in the same directory. The path to the script can be changed manually if needed as well. NOTRY=true Review-Url: https://codereview.chromium.org/2758373002 Cr-Commit-Position: refs/heads/master@{#44136} PR-URL: #12061 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent d641164 commit a735c16

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

deps/v8/tools/lldb_commands.py

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Copyright 2017 the V8 project authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
import lldb
6+
import re
7+
8+
def jst(debugger, *args):
9+
"""Print the current JavaScript stack trace"""
10+
target = debugger.GetSelectedTarget()
11+
process = target.GetProcess()
12+
thread = process.GetSelectedThread()
13+
frame = thread.GetSelectedFrame()
14+
frame.EvaluateExpression("_v8_internal_Print_StackTrace();")
15+
print("")
16+
17+
def jss(debugger, *args):
18+
"""Skip the jitted stack on x64 to where we entered JS last"""
19+
target = debugger.GetSelectedTarget()
20+
process = target.GetProcess()
21+
thread = process.GetSelectedThread()
22+
frame = thread.GetSelectedFrame()
23+
js_entry_sp = frame.EvaluateExpression(
24+
"v8::internal::Isolate::Current()->thread_local_top()->js_entry_sp_;") \
25+
.GetValue()
26+
sizeof_void = frame.EvaluateExpression("sizeof(void*)").GetValue()
27+
rbp = frame.FindRegister("rbp")
28+
rsp = frame.FindRegister("rsp")
29+
pc = frame.FindRegister("pc")
30+
rbp = js_entry_sp
31+
rsp = js_entry_sp + 2 *sizeof_void
32+
pc.value = js_entry_sp + sizeof_void
33+
34+
def bta(debugger, *args):
35+
"""Print stack trace with assertion scopes"""
36+
func_name_re = re.compile("([^(<]+)(?:\(.+\))?")
37+
assert_re = re.compile(
38+
"^v8::internal::Per\w+AssertType::(\w+)_ASSERT, (false|true)>")
39+
target = debugger.GetSelectedTarget()
40+
process = target.GetProcess()
41+
thread = process.GetSelectedThread()
42+
frame = thread.GetSelectedFrame()
43+
for frame in thread:
44+
functionSignature = frame.GetDisplayFunctionName()
45+
if functionSignature is None:
46+
continue
47+
functionName = func_name_re.match(functionSignature)
48+
line = frame.GetLineEntry().GetLine()
49+
sourceFile = frame.GetLineEntry().GetFileSpec().GetFilename()
50+
if line:
51+
sourceFile = sourceFile + ":" + str(line)
52+
53+
if sourceFile is None:
54+
sourceFile = ""
55+
print("[%-2s] %-60s %-40s" % (frame.GetFrameID(),
56+
functionName.group(1),
57+
sourceFile))
58+
match = assert_re.match(str(functionSignature))
59+
if match:
60+
if match.group(3) == "false":
61+
prefix = "Disallow"
62+
color = "\033[91m"
63+
else:
64+
prefix = "Allow"
65+
color = "\033[92m"
66+
print("%s -> %s %s (%s)\033[0m" % (
67+
color, prefix, match.group(2), match.group(1)))
68+
69+
def __lldb_init_module (debugger, dict):
70+
debugger.HandleCommand('command script add -f lldb_commands.jst jst')
71+
debugger.HandleCommand('command script add -f lldb_commands.jss jss')
72+
debugger.HandleCommand('command script add -f lldb_commands.bta bta')

deps/v8/tools/lldbinit

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2017 the V8 project authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
# Print HeapObjects.
6+
command regex -h 'Print a v8 JavaScript object' job 's/(.+)/expr -- '_v8_internal_Print_Object((void*)(%1))/'
7+
8+
# Print v8::Local handle value.
9+
command regex -h 'Print content of a v8::Local handle' jlh 's/(.+)/expr -- '_v8_internal_Print_Object(*(v8::internal::Object**)(*%1))/'
10+
11+
# Print Code objects containing given PC.
12+
command regex -h 'Print a v8 Code object from an internal code address' jco 's/(.+)/expr -- '_v8_internal_Print_Code((void*)(*%1))/'
13+
14+
# Print FeedbackVector
15+
command regex -h 'Print a v8 FeedbackVector object' jfv 's/(.+)/expr -- '_v8_internal_Print_FeedbackVector((void*)(%1))/'
16+
17+
# Print DescriptorArray.
18+
command regex -h 'Print a v8 DescriptorArray object' jda 's/(.+)/expr -- '_v8_internal_Print_DescriptorArray((void*)(%1))/'
19+
20+
# Print LayoutDescriptor.
21+
command regex -h 'Print a v8 LayoutDescriptor object' jld 's/(.+)/expr -- '_v8_internal_Print_LayoutDescriptor((void*)(%1))/'
22+
23+
# Print TransitionArray.
24+
command regex -h 'Print a v8 TransitionArray object' jta 's/(.+)/expr -- '_v8_internal_Print_TransitionArray((void*)(%1))/'
25+
26+
command script import ~/lldb_commands.py

tools/install.py

+2
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ def files(action):
133133
action(['src/node.stp'], 'share/systemtap/tapset/')
134134

135135
action(['deps/v8/tools/gdbinit'], 'share/doc/node/')
136+
action(['deps/v8/tools/lldbinit'], 'share/doc/node/')
137+
action(['deps/v8/tools/lldb_commands.py'], 'share/doc/node/')
136138

137139
if 'freebsd' in sys.platform or 'openbsd' in sys.platform:
138140
action(['doc/node.1'], 'man/man1/')

0 commit comments

Comments
 (0)