misc/lldb_cruby.py: update for python3 [ci skip]

lldb module bundled with Xcode is for Python 3 now.
This commit is contained in:
Nobuyoshi Nakada 2019-09-24 21:05:29 +09:00
Родитель 0526366033
Коммит c5a97d995a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4BC7D6DF58D8DF60
1 изменённых файлов: 36 добавлений и 35 удалений

Просмотреть файл

@ -6,6 +6,7 @@
# Test: misc/test_lldb_cruby.rb
#
from __future__ import print_function
import lldb
import os
import shlex
@ -20,7 +21,7 @@ def lldb_init(debugger):
for enum in target.FindFirstGlobalVariable('ruby_dummy_gdb_enums'):
enum = enum.GetType()
members = enum.GetEnumMembers()
for i in xrange(0, members.GetSize()):
for i in range(0, members.GetSize()):
member = members.GetTypeEnumMemberAtIndex(i)
name = member.GetName()
value = member.GetValueAsUnsigned()
@ -79,62 +80,62 @@ def lldb_rp(debugger, command, result, internal_dict):
val = target.EvaluateExpression(command)
error = val.GetError()
if error.Fail():
print >> result, error
print(error, file=result)
return
lldb_inspect(debugger, target, result, val)
def lldb_inspect(debugger, target, result, val):
num = val.GetValueAsSigned()
if num == RUBY_Qfalse:
print >> result, 'false'
print('false', file=result)
elif num == RUBY_Qtrue:
print >> result, 'true'
print('true', file=result)
elif num == RUBY_Qnil:
print >> result, 'nil'
print('nil', file=result)
elif num == RUBY_Qundef:
print >> result, 'undef'
print('undef', file=result)
elif fixnum_p(num):
print >> result, num >> 1
print(num >> 1, file=result)
elif flonum_p(num):
append_command_output(debugger, "print rb_float_value(%0#x)" % val.GetValueAsUnsigned(), result)
elif static_sym_p(num):
if num < 128:
print >> result, "T_SYMBOL: %c" % num
print("T_SYMBOL: %c" % num, file=result)
else:
print >> result, "T_SYMBOL: (%x)" % num
print("T_SYMBOL: (%x)" % num, file=result)
elif num & RUBY_IMMEDIATE_MASK:
print >> result, 'immediate(%x)' % num
print('immediate(%x)' % num, file=result)
else:
tRBasic = target.FindFirstType("struct RBasic").GetPointerType()
val = val.Cast(tRBasic)
flags = val.GetValueForExpressionPath("->flags").GetValueAsUnsigned()
if (flags & RUBY_FL_PROMOTED) == RUBY_FL_PROMOTED:
print >> result, "[PROMOTED] "
print("[PROMOTED] ", file=result)
if (flags & RUBY_FL_FREEZE) == RUBY_FL_FREEZE:
print >> result, "[FROZEN] "
print("[FROZEN] ", file=result)
flType = flags & RUBY_T_MASK
if flType == RUBY_T_NONE:
print >> result, 'T_NONE: %s' % val.Dereference()
print('T_NONE: %s' % val.Dereference(), file=result)
elif flType == RUBY_T_NIL:
print >> result, 'T_NIL: %s' % val.Dereference()
print('T_NIL: %s' % val.Dereference(), file=result)
elif flType == RUBY_T_OBJECT:
tRObject = target.FindFirstType("struct RObject").GetPointerType()
val = val.Cast(tRObject)
print >> result, 'T_OBJECT: %s' % val.Dereference()
print('T_OBJECT: %s' % val.Dereference(), file=result)
elif flType == RUBY_T_CLASS or flType == RUBY_T_MODULE or flType == RUBY_T_ICLASS:
tRClass = target.FindFirstType("struct RClass").GetPointerType()
val = val.Cast(tRClass)
print >> result, 'T_%s: %s' % ('CLASS' if flType == RUBY_T_CLASS else 'MODULE' if flType == RUBY_T_MODULE else 'ICLASS', val.Dereference())
print('T_%s: %s' % ('CLASS' if flType == RUBY_T_CLASS else 'MODULE' if flType == RUBY_T_MODULE else 'ICLASS', val.Dereference()), file=result)
elif flType == RUBY_T_STRING:
tRString = target.FindFirstType("struct RString").GetPointerType()
val = val.Cast(tRString)
if flags & RSTRING_NOEMBED:
print >> result, val.GetValueForExpressionPath("->as.heap")
print(val.GetValueForExpressionPath("->as.heap"), file=result)
else:
print >> result, val.GetValueForExpressionPath("->as.ary")
print(val.GetValueForExpressionPath("->as.ary"), file=result)
elif flType == RUBY_T_SYMBOL:
tRSymbol = target.FindFirstType("struct RSymbol").GetPointerType()
print >> result, val.Cast(tRSymbol).Dereference()
print(val.Cast(tRSymbol).Dereference(), file=result)
elif flType == RUBY_T_ARRAY:
tRArray = target.FindFirstType("struct RArray").GetPointerType()
val = val.Cast(tRArray)
@ -144,7 +145,7 @@ def lldb_inspect(debugger, target, result, val):
else:
len = val.GetValueForExpressionPath("->as.heap.len").GetValueAsSigned()
ptr = val.GetValueForExpressionPath("->as.heap.ptr")
#print >> result, val.GetValueForExpressionPath("->as.heap")
#print(val.GetValueForExpressionPath("->as.heap"), file=result)
result.write("T_ARRAY: len=%d" % len)
if flags & RUBY_FL_USER1:
result.write(" (embed)")
@ -166,12 +167,12 @@ def lldb_inspect(debugger, target, result, val):
val = val.Cast(tRBignum)
if flags & RUBY_FL_USER2:
len = ((flags & (RUBY_FL_USER3|RUBY_FL_USER4|RUBY_FL_USER5)) >> (RUBY_FL_USHIFT+3))
print >> result, "T_BIGNUM: len=%d (embed)" % len
print("T_BIGNUM: len=%d (embed)" % len, file=result)
append_command_output(debugger, "print ((struct RBignum *) %0#x)->as.ary" % val.GetValueAsUnsigned(), result)
else:
len = val.GetValueForExpressionPath("->as.heap.len").GetValueAsSigned()
print >> result, "T_BIGNUM: len=%d" % len
print >> result, val.Dereference()
print("T_BIGNUM: len=%d" % len, file=result)
print(val.Dereference(), file=result)
append_command_output(debugger, "expression -Z %x -fx -- (const BDIGIT*)((struct RBignum*)%d)->as.heap.digits" % (len, val.GetValueAsUnsigned()), result)
# append_command_output(debugger, "x ((struct RBignum *) %0#x)->as.heap.digits / %d" % (val.GetValueAsUnsigned(), len), result)
elif flType == RUBY_T_FLOAT:
@ -197,23 +198,23 @@ def lldb_inspect(debugger, target, result, val):
result.Clear()
if not imag.startswith("-"):
imag = "+" + imag
print >> result, "(Complex) " + real + imag + "i"
print("(Complex) " + real + imag + "i", file=result)
elif flType == RUBY_T_REGEXP:
tRRegex = target.FindFirstType("struct RRegexp").GetPointerType()
val = val.Cast(tRRegex)
print >> result, "(Regex)"
print >> result, "->src {",
print("(Regex)", file=result)
print("->src {", file=result)
lldb_inspect(debugger, target, result, val.GetValueForExpressionPath("->src"))
print >> result, "}"
print("}", file=result)
elif flType == RUBY_T_DATA:
tRTypedData = target.FindFirstType("struct RTypedData").GetPointerType()
val = val.Cast(tRTypedData)
flag = val.GetValueForExpressionPath("->typed_flag")
if flag.GetValueAsUnsigned() == 1:
print >> result, "T_DATA: %s" % val.GetValueForExpressionPath("->type->wrap_struct_name")
print("T_DATA: %s" % val.GetValueForExpressionPath("->type->wrap_struct_name"), file=result)
append_command_output(debugger, "p *(struct RTypedData *) %0#x" % val.GetValueAsUnsigned(), result)
else:
print >> result, "T_DATA:"
print("T_DATA:", file=result)
append_command_output(debugger, "p *(struct RData *) %0#x" % val.GetValueAsUnsigned(), result)
elif flType == RUBY_T_NODE:
tRTypedData = target.FindFirstType("struct RNode").GetPointerType()
@ -222,8 +223,8 @@ def lldb_inspect(debugger, target, result, val):
val = val.Cast(tRTypedData)
append_command_output(debugger, "p *(struct RNode *) %0#x" % val.GetValueAsUnsigned(), result)
else:
print >> result, "Not-handled type %0#x" % flType
print >> result, val
print("Not-handled type %0#x" % flType, file=result)
print(val, file=result)
def count_objects(debugger, command, ctx, result, internal_dict):
objspace = ctx.frame.EvaluateExpression("ruby_current_vm->objspace")
@ -235,7 +236,7 @@ def count_objects(debugger, command, ctx, result, internal_dict):
counts[t] = 0
for i in range(0, num_pages):
print "\rcounting... %d/%d" % (i, num_pages),
print("\rcounting... %d/%d" % (i, num_pages), end="")
page = objspace.GetValueForExpressionPath('.heap_pages.sorted[%d]' % i)
p = page.GetChildMemberWithName('start')
num_slots = page.GetChildMemberWithName('total_slots').unsigned
@ -246,9 +247,9 @@ def count_objects(debugger, command, ctx, result, internal_dict):
counts[obj_type] += 1
total += num_slots
print "\rTOTAL: %d, FREE: %d" % (total, counts[0x00])
print("\rTOTAL: %d, FREE: %d" % (total, counts[0x00]), end="")
for sym in value_types:
print "%s: %d" % (sym, counts[globals()[sym]])
print("%s: %d" % (sym, counts[globals()[sym]]))
def stack_dump_raw(debugger, command, ctx, result, internal_dict):
ctx.frame.EvaluateExpression("rb_vmdebug_stack_dump_raw_current()")
@ -268,4 +269,4 @@ def __lldb_init_module(debugger, internal_dict):
debugger.HandleCommand("command script add -f lldb_cruby.stack_dump_raw SDR")
debugger.HandleCommand("command script add -f lldb_cruby.dump_node dump_node")
lldb_init(debugger)
print "lldb scripts for ruby has been installed."
print("lldb scripts for ruby has been installed.")