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

ruby-changes:57881

From: Nobuyoshi <ko1@a...>
Date: Tue, 24 Sep 2019 21:07:36 +0900 (JST)
Subject: [ruby-changes:57881] c5a97d995a (master): misc/lldb_cruby.py: update for python3 [ci skip]

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

From c5a97d995ae06e0ae420d7529085ae94695c7593 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Tue, 24 Sep 2019 21:05:29 +0900
Subject: misc/lldb_cruby.py: update for python3 [ci skip]

lldb module bundled with Xcode is for Python 3 now.

diff --git a/misc/lldb_cruby.py b/misc/lldb_cruby.py
index bafaac4..aacb836 100755
--- a/misc/lldb_cruby.py
+++ b/misc/lldb_cruby.py
@@ -6,6 +6,7 @@ https://github.com/ruby/ruby/blob/trunk/misc/lldb_cruby.py#L6
 # 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): https://github.com/ruby/ruby/blob/trunk/misc/lldb_cruby.py#L21
     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): https://github.com/ruby/ruby/blob/trunk/misc/lldb_cruby.py#L80
         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): https://github.com/ruby/ruby/blob/trunk/misc/lldb_cruby.py#L145
             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): https://github.com/ruby/ruby/blob/trunk/misc/lldb_cruby.py#L167
             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): https://github.com/ruby/ruby/blob/trunk/misc/lldb_cruby.py#L198
             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): https://github.com/ruby/ruby/blob/trunk/misc/lldb_cruby.py#L223
             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): https://github.com/ruby/ruby/blob/trunk/misc/lldb_cruby.py#L236
         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_sl (... truncated)

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

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