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

ruby-changes:66339

From: Aaron <ko1@a...>
Date: Tue, 25 May 2021 08:03:08 +0900 (JST)
Subject: [ruby-changes:66339] 45ddefb14a (master): add rb_id2str to lldb debugging scripts

https://git.ruby-lang.org/ruby.git/commit/?id=45ddefb14a

From 45ddefb14a0b88a70d91e29236bc7d6827e15a54 Mon Sep 17 00:00:00 2001
From: Aaron Patterson <tenderlove@r...>
Date: Mon, 24 May 2021 16:02:17 -0700
Subject: add rb_id2str to lldb debugging scripts

---
 misc/lldb_cruby.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/misc/lldb_cruby.py b/misc/lldb_cruby.py
index fa69a9b..898cb2f 100755
--- a/misc/lldb_cruby.py
+++ b/misc/lldb_cruby.py
@@ -655,6 +655,51 @@ def ruby_types(debugger): https://github.com/ruby/ruby/blob/trunk/misc/lldb_cruby.py#L655
 
     return types
 
+def rb_ary_entry(target, ary, idx, result):
+    tRArray = target.FindFirstType("struct RArray").GetPointerType()
+    ary = ary.Cast(tRArray)
+    flags = ary.GetValueForExpressionPath("->flags").GetValueAsUnsigned()
+
+    if flags & RUBY_FL_USER1:
+        ptr = ary.GetValueForExpressionPath("->as.ary")
+    else:
+        ptr = ary.GetValueForExpressionPath("->as.heap.ptr")
+
+    ptr_addr = ptr.GetValueAsUnsigned() + (idx * ptr.GetType().GetByteSize())
+    return target.CreateValueFromAddress("ary_entry[%d]" % idx, lldb.SBAddress(ptr_addr, target), ptr.GetType().GetPointeeType())
+
+def rb_id_to_serial(id_val):
+    if id_val > tLAST_OP_ID:
+        return id_val >> RUBY_ID_SCOPE_SHIFT
+    else:
+        return id_val
+
+def rb_id2str(debugger, command, result, internal_dict):
+    if not ('RUBY_Qfalse' in globals()):
+        lldb_init(debugger)
+
+    target = debugger.GetSelectedTarget()
+    process = target.GetProcess()
+    thread = process.GetSelectedThread()
+    frame = thread.GetSelectedFrame()
+    global_symbols = target.FindFirstGlobalVariable("ruby_global_symbols")
+
+    id_val = frame.EvaluateExpression(command).GetValueAsUnsigned()
+    num = rb_id_to_serial(id_val)
+
+    last_id = global_symbols.GetChildMemberWithName("last_id").GetValueAsUnsigned()
+    ID_ENTRY_SIZE = 2
+    ID_ENTRY_UNIT = int(target.FindFirstGlobalVariable("ID_ENTRY_UNIT").GetValue())
+
+    ids = global_symbols.GetChildMemberWithName("ids")
+
+    if (num <= last_id):
+        idx = num // ID_ENTRY_UNIT
+        ary = rb_ary_entry(target, ids, idx, result)
+        pos = (num % ID_ENTRY_UNIT) * ID_ENTRY_SIZE
+        id_str = rb_ary_entry(target, ary, pos, result)
+        lldb_inspect(debugger, target, result, id_str)
+
 def __lldb_init_module(debugger, internal_dict):
     debugger.HandleCommand("command script add -f lldb_cruby.lldb_rp rp")
     debugger.HandleCommand("command script add -f lldb_cruby.count_objects rb_count_objects")
@@ -665,6 +710,7 @@ def __lldb_init_module(debugger, internal_dict): https://github.com/ruby/ruby/blob/trunk/misc/lldb_cruby.py#L710
     debugger.HandleCommand("command script add -f lldb_cruby.rb_backtrace rbbt")
     debugger.HandleCommand("command script add -f lldb_cruby.dump_page dump_page")
     debugger.HandleCommand("command script add -f lldb_cruby.dump_page_rvalue dump_page_rvalue")
+    debugger.HandleCommand("command script add -f lldb_cruby.rb_id2str rb_id2str")
 
     lldb_init(debugger)
     print("lldb scripts for ruby has been installed.")
-- 
cgit v1.1


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

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