[前][次][番号順一覧][スレッド一覧]

ruby-changes:62814

From: Aaron <ko1@a...>
Date: Thu, 3 Sep 2020 08:46:27 +0900 (JST)
Subject: [ruby-changes:62814] 3fb255625b (master): add lldb functions for getting the heap page / heap page body

https://git.ruby-lang.org/ruby.git/commit/?id=3fb255625b

From 3fb255625bba37cd948751163f620a4b2926c394 Mon Sep 17 00:00:00 2001
From: Aaron Patterson <tenderlove@r...>
Date: Wed, 2 Sep 2020 16:42:56 -0700
Subject: add lldb functions for getting the heap page / heap page body


diff --git a/misc/lldb_cruby.py b/misc/lldb_cruby.py
index fe5b98e..e44673c 100755
--- a/misc/lldb_cruby.py
+++ b/misc/lldb_cruby.py
@@ -11,6 +11,9 @@ import lldb https://github.com/ruby/ruby/blob/trunk/misc/lldb_cruby.py#L11
 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): https://github.com/ruby/ruby/blob/trunk/misc/lldb_cruby.py#L286
 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): https://github.com/ruby/ruby/blob/trunk/misc/lldb_cruby.py#L335
     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.")
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]