summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorAaron Patterson <tenderlove@ruby-lang.org>2020-09-02 16:42:56 -0700
committerAaron Patterson <tenderlove@ruby-lang.org>2020-09-02 16:45:54 -0700
commit3fb255625bba37cd948751163f620a4b2926c394 (patch)
tree207bb9092c86dd147afcb5893405180163010eed /misc
parent933035d303a154f9b8afea84b99ef99fba21c032 (diff)
add lldb functions for getting the heap page / heap page body
Diffstat (limited to 'misc')
-rwxr-xr-xmisc/lldb_cruby.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/misc/lldb_cruby.py b/misc/lldb_cruby.py
index fe5b98e45e..e44673c971 100755
--- a/misc/lldb_cruby.py
+++ b/misc/lldb_cruby.py
@@ -11,6 +11,9 @@ import lldb
import os
import shlex
+HEAP_PAGE_ALIGN_LOG = 14
+HEAP_PAGE_ALIGN_MASK = (~(~0 << HEAP_PAGE_ALIGN_LOG))
+
def lldb_init(debugger):
target = debugger.GetSelectedTarget()
global SIZEOF_VALUE
@@ -283,6 +286,41 @@ def count_objects(debugger, command, ctx, result, internal_dict):
def stack_dump_raw(debugger, command, ctx, result, internal_dict):
ctx.frame.EvaluateExpression("rb_vmdebug_stack_dump_raw_current()")
+def heap_page(debugger, command, ctx, result, internal_dict):
+ target = debugger.GetSelectedTarget()
+ process = target.GetProcess()
+ thread = process.GetSelectedThread()
+ frame = thread.GetSelectedFrame()
+
+ val = frame.EvaluateExpression(command)
+ page = get_page(lldb, target, val)
+ page_type = target.FindFirstType("struct heap_page").GetPointerType()
+ page.Cast(page_type)
+ append_command_output(debugger, "p (struct heap_page *) %0#x" % page.GetValueAsUnsigned(), result)
+ append_command_output(debugger, "p *(struct heap_page *) %0#x" % page.GetValueAsUnsigned(), result)
+
+def heap_page_body(debugger, command, ctx, result, internal_dict):
+ target = debugger.GetSelectedTarget()
+ process = target.GetProcess()
+ thread = process.GetSelectedThread()
+ frame = thread.GetSelectedFrame()
+
+ val = frame.EvaluateExpression(command)
+ page = get_page_body(lldb, target, val)
+ print("Page body address: ", page.GetAddress(), file=result)
+ print(page, file=result)
+
+def get_page_body(lldb, target, val):
+ tHeapPageBody = target.FindFirstType("struct heap_page_body")
+ addr = val.GetValueAsUnsigned()
+ page_addr = addr & ~(HEAP_PAGE_ALIGN_MASK)
+ address = lldb.SBAddress(page_addr, target)
+ return target.CreateValueFromAddress("page", address, tHeapPageBody)
+
+def get_page(lldb, target, val):
+ body = get_page_body(lldb, target, val)
+ return body.GetValueForExpressionPath("->header.page")
+
def dump_node(debugger, command, ctx, result, internal_dict):
args = shlex.split(command)
if not args:
@@ -297,5 +335,7 @@ def __lldb_init_module(debugger, internal_dict):
debugger.HandleCommand("command script add -f lldb_cruby.count_objects rb_count_objects")
debugger.HandleCommand("command script add -f lldb_cruby.stack_dump_raw SDR")
debugger.HandleCommand("command script add -f lldb_cruby.dump_node dump_node")
+ debugger.HandleCommand("command script add -f lldb_cruby.heap_page heap_page")
+ debugger.HandleCommand("command script add -f lldb_cruby.heap_page_body heap_page_body")
lldb_init(debugger)
print("lldb scripts for ruby has been installed.")