4 # Usage: run `command script import -r misc/lldb_yjit.py` on LLDB
7 from __future__
import print_function
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()
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")
23 # Get the global variables we need
24 comments
= target
.FindFirstGlobalVariable("yjit_code_comments")
25 cb
= target
.FindFirstGlobalVariable("cb").Cast(codeblock_t
.GetPointerType())
27 # Get the address of the memory block we're using
28 mem_addr
= cb
.GetChildMemberWithName("mem_block").GetValueAsUnsigned()
30 # Find the size of the darray comment list
31 meta
= comments
.Cast(rb_darray_meta_t
.GetPointerType())
32 size
= meta
.GetChildMemberWithName("size").GetValueAsUnsigned()
34 # Get the address of the block following the metadata header
35 t_offset
= comments
.GetValueAsUnsigned() + rb_darray_meta_t
.GetByteSize()
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
)
46 def __lldb_init_module(debugger
, internal_dict
):
47 debugger
.HandleCommand("command script add -f lldb_yjit.list_comments lc")