From 1dca33359994271342f81b430f552c3d37de4dba Mon Sep 17 00:00:00 2001 From: Matt Valentine-House Date: Tue, 16 Mar 2021 10:46:07 +0000 Subject: [PATCH] LLDB: Extract a dump_bits function from rp that dumps the heap page bitmaps for a slot --- misc/lldb_cruby.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/misc/lldb_cruby.py b/misc/lldb_cruby.py index 075612735c..7341e0447f 100755 --- a/misc/lldb_cruby.py +++ b/misc/lldb_cruby.py @@ -257,29 +257,16 @@ def lldb_inspect(debugger, target, result, val): else: tRBasic = target.FindFirstType("struct RBasic").GetPointerType() tRValue = target.FindFirstType("struct RVALUE") - tUintPtr = target.FindFirstType("uintptr_t") # bits_t val = val.Cast(tRBasic) flags = val.GetValueForExpressionPath("->flags").GetValueAsUnsigned() flaginfo = "" - num_in_page = (val.GetValueAsUnsigned() & HEAP_PAGE_ALIGN_MASK) // tRValue.GetByteSize(); - bits_bitlength = tUintPtr.GetByteSize() * 8 - bitmap_index = num_in_page // bits_bitlength - bitmap_offset = num_in_page & (bits_bitlength - 1) - bitmap_bit = 1 << bitmap_offset - page = get_page(lldb, target, val) page_type = target.FindFirstType("struct heap_page").GetPointerType() page.Cast(page_type) - print("bits [%s%s%s%s%s]" % ( - check_bits(page, "uncollectible_bits", bitmap_index, bitmap_bit, "L"), - check_bits(page, "mark_bits", bitmap_index, bitmap_bit, "M"), - check_bits(page, "pinned_bits", bitmap_index, bitmap_bit, "P"), - check_bits(page, "marking_bits", bitmap_index, bitmap_bit, "R"), - check_bits(page, "wb_unprotected_bits", bitmap_index, bitmap_bit, "U"), - ), file=result) + dump_bits(target, result, page, val.GetValueAsUnsigned()) if (flags & RUBY_FL_PROMOTED) == RUBY_FL_PROMOTED: flaginfo += "[PROMOTED] " @@ -522,6 +509,23 @@ def rb_backtrace(debugger, command, result, internal_dict): bt.print_bt(val) +def dump_bits(target, result, page, object_address, end = "\n"): + tRValue = target.FindFirstType("struct RVALUE") + tUintPtr = target.FindFirstType("uintptr_t") # bits_t + + num_in_page = (object_address & HEAP_PAGE_ALIGN_MASK) // tRValue.GetByteSize(); + bits_bitlength = tUintPtr.GetByteSize() * 8 + bitmap_index = num_in_page // bits_bitlength + bitmap_offset = num_in_page & (bits_bitlength - 1) + bitmap_bit = 1 << bitmap_offset + + print("bits: [%s%s%s%s%s]" % ( + check_bits(page, "uncollectible_bits", bitmap_index, bitmap_bit, "L"), + check_bits(page, "mark_bits", bitmap_index, bitmap_bit, "M"), + check_bits(page, "pinned_bits", bitmap_index, bitmap_bit, "P"), + check_bits(page, "marking_bits", bitmap_index, bitmap_bit, "R"), + check_bits(page, "wb_unprotected_bits", bitmap_index, bitmap_bit, "U"), + ), end=end, file=result) 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")