Skip to content

Commit ae567d6

Browse files
tenderloveXrXr
authored andcommitted
Add an lldb script to print YJIT comments
This script is an lldb helper that just loops through all the comments stored and prints out the comment along with the address corresponding to the comment. For example, I'm crashing in JIT code at address 0x0000000110000168. Using the `lc` helper I can see that it's probably crashing inside the exit back to the interpreter ``` (lldb) bt 5 * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x22220021) frame #0: 0x0000000110000168 * frame #1: 0x00000001002b5ff5 miniruby`invoke_block_from_c_bh [inlined] invoke_block(ec=0x0000000100e05350, iseq=0x0000000100c1ff10, self=0x0000000100c76cc0, captured=<unavailable>, cref=0x0000000000000000, type=<unavailable>, opt_pc=<unavailable>) at vm.c:1268:12 frame #2: 0x00000001002b5f7d miniruby`invoke_block_from_c_bh [inlined] invoke_iseq_block_from_c(ec=<unavailable>, captured=<unavailable>, self=0x0000000100c76cc0, argc=2, argv=<unavailable>, kw_splat=0, passed_block_handler=0x0000000000000000, cref=0x0000000000000000, is_lambda=<unavailable>, me=0x0000000000000000) at vm.c:1340 frame #3: 0x00000001002b5e14 miniruby`invoke_block_from_c_bh(ec=<unavailable>, block_handler=<unavailable>, argc=<unavailable>, argv=<unavailable>, kw_splat=0, passed_block_handler=0x0000000000000000, cref=0x0000000000000000, is_lambda=<unavailable>, force_blockarg=0) at vm.c:1358 frame #4: 0x000000010029860b miniruby`rb_yield_values(n=<unavailable>) at vm_eval.c:0 (lldb) lc 0x11000006d "putobject_INT2FIX_1_" 0x110000083 "leave" 0x110000087 "check for interrupts" 0x110000087 "RUBY_VM_CHECK_INTS(ec)" 0x110000098 "check for finish frame" 0x1100000ed "getlocal_WC_0" 0x110000107 "getlocal_WC_1" 0x11000012a "opt_send_without_block" 0x110000139 "opt_send_without_block" 0x11000013c "exit to interpreter" ```
1 parent 39f8dc7 commit ae567d6

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

misc/lldb_yjit.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python
2+
#coding: utf-8
3+
#
4+
# Usage: run `command script import -r misc/lldb_yjit.py` on LLDB
5+
#
6+
7+
from __future__ import print_function
8+
import lldb
9+
import os
10+
import shlex
11+
12+
def list_comments(debugger, command, result, internal_dict):
13+
target = debugger.GetSelectedTarget()
14+
process = target.GetProcess()
15+
thread = process.GetSelectedThread()
16+
frame = thread.GetSelectedFrame()
17+
18+
# Get the different types we need
19+
rb_darray_meta_t = target.FindFirstType("rb_darray_meta_t")
20+
codeblock_t = target.FindFirstType("codeblock_t")
21+
yjit_comment = target.FindFirstType("yjit_comment")
22+
23+
# Get the global variables we need
24+
comments = target.FindFirstGlobalVariable("yjit_code_comments")
25+
cb = target.FindFirstGlobalVariable("cb").Cast(codeblock_t.GetPointerType())
26+
27+
# Get the address of the memory block we're using
28+
mem_addr = cb.GetChildMemberWithName("mem_block").GetValueAsUnsigned()
29+
30+
# Find the size of the darray comment list
31+
meta = comments.Cast(rb_darray_meta_t.GetPointerType())
32+
size = meta.GetChildMemberWithName("size").GetValueAsUnsigned()
33+
34+
# Get the address of the block following the metadata header
35+
t_offset = comments.GetValueAsUnsigned() + rb_darray_meta_t.GetByteSize()
36+
37+
# Loop through each comment and print
38+
for t in range(0, size):
39+
addr = lldb.SBAddress(t_offset + (t * yjit_comment.GetByteSize()), target)
40+
comment = target.CreateValueFromAddress("yjit_comment", addr, yjit_comment)
41+
string = comment.GetChildMemberWithName("comment")
42+
comment_offset = mem_addr + comment.GetChildMemberWithName("offset").GetValueAsUnsigned()
43+
print("%0#x %s" % (comment_offset, string.GetSummary()), file = result)
44+
45+
46+
def __lldb_init_module(debugger, internal_dict):
47+
debugger.HandleCommand("command script add -f lldb_yjit.list_comments lc")

0 commit comments

Comments
 (0)