forked from danbev/learning-v8
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlldb_commands.py
64 lines (59 loc) · 2.43 KB
/
lldb_commands.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import lldb
import re
def jst(debugger, command, result, dict):
"""Print the current JavaScript stack trace"""
target = debugger.GetSelectedTarget()
process = target.GetProcess()
thread = process.GetSelectedThread()
frame = thread.GetSelectedFrame()
frame.EvaluateExpression("_v8_internal_Print_StackTrace();")
print("")
def jss(debugger, command, result, dict):
"""Skip the jitted stack on x64 to where we entered JS last"""
target = debugger.GetSelectedTarget()
process = target.GetProcess()
thread = process.GetSelectedThread()
frame = thread.GetSelectedFrame()
js_entry_sp = frame.EvaluateExpression("v8::internal::Isolate::Current()->thread_local_top()->js_entry_sp_;").GetValue()
sizeof_void = frame.EvaluateExpression("sizeof(void*)").GetValue()
rbp = frame.FindRegister("rbp")
rsp = frame.FindRegister("rsp")
pc = frame.FindRegister("pc")
rbp = js_entry_sp
rsp = js_entry_sp + 2 *sizeof_void
pc.value = js_entry_sp + sizeof_void
def bta(debugger, command, result, dict):
"""Print stack trace with assertion scopes"""
func_name_re = re.compile("([^(<]+)(?:\(.+\))?")
assert_re = re.compile("^v8::internal::Per\w+AssertType::(\w+)_ASSERT, (false|true)>")
target = debugger.GetSelectedTarget()
process = target.GetProcess()
thread = process.GetSelectedThread()
frame = thread.GetSelectedFrame()
for frame in thread:
functionSignature = frame.GetDisplayFunctionName()
if functionSignature is None:
continue
functionName = func_name_re.match(functionSignature)
line = frame.GetLineEntry().GetLine()
sourceFile = frame.GetLineEntry().GetFileSpec().GetFilename()
if line:
sourceFile = sourceFile + ":" + str(line)
if sourceFile is None:
sourceFile = ""
print("[%-2s] %-60s %-40s" % (frame.GetFrameID(),
functionName.group(1),
sourceFile))
match = assert_re.match(str(functionSignature))
if match:
if match.group(3) == "false":
prefix = "Disallow"
color = "\033[91m"
else:
prefix = "Allow"
color = "\033[92m"
print("%s -> %s %s (%s)\033[0m" % (color, prefix, match.group(2), match.group(1)))
def __lldb_init_module (debugger, dict):
debugger.HandleCommand('command script add -f lldb_commands.jst jst')
debugger.HandleCommand('command script add -f lldb_commands.jss jss')
debugger.HandleCommand('command script add -f lldb_commands.bta bta')