Bug 1603645. Make the .lldbinit python scripts compatible with Python 3. r=froydnj
authorJonathan Watt <jwatt@jwatt.org>
Fri, 13 Dec 2019 17:53:13 +0000
changeset 506945 3133625a301b6d5d41ac7ba7f13ea768fca06a31
parent 506944 79ea5e38745689368f6d37f2ae74c2311bdc1914
child 506946 54a720d1b988b2be9952f310b20d37e05d570631
push id103169
push userjwatt@jwatt.org
push dateFri, 13 Dec 2019 17:54:36 +0000
treeherderautoland@3133625a301b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1603645. Make the .lldbinit python scripts compatible with Python 3. r=froydnj Differential Revision: https://phabricator.services.mozilla.com/D57043
--- a/.lldbinit
+++ b/.lldbinit
@@ -4,17 +4,20 @@
 # For documentation on all of the commands and type summaries defined here and
 # in the accompanying Python scripts, see third_party/python/lldbutils/README.txt.
 # -----------------------------------------------------------------------------
 # Import the module that defines complex Gecko debugging commands.  This assumes
 # you are either running lldb from the top level source directory, the objdir,
 # or the dist/bin directory.  (.lldbinit files in the objdir and dist/bin set
 # topsrcdir appropriately.)
-script topsrcdir = topsrcdir if locals().has_key("topsrcdir") else os.getcwd(); sys.path.append(os.path.join(topsrcdir, "third_party/python/lldbutils")); import lldbutils; lldbutils.init()
+script topsrcdir = topsrcdir if "topsrcdir" in locals() else os.getcwd()
+script sys.path.append(os.path.join(topsrcdir, "third_party/python/lldbutils"))
+script import lldbutils
+script lldbutils.init()
 # Mozilla's use of UNIFIED_SOURCES to include multiple source files into a
 # single compiled file breaks lldb breakpoint setting. This works around that.
 # See http://lldb.llvm.org/troubleshooting.html for more info.
 settings set target.inline-breakpoint-strategy always
 # Show the dynamic type of an object when using "expr".  This, for example,
 # will show a variable declared as "nsIFrame *" that points to an nsBlockFrame
--- a/third_party/python/lldbutils/lldbutils/general.py
+++ b/third_party/python/lldbutils/lldbutils/general.py
@@ -1,10 +1,11 @@
 import lldb
 from lldbutils import utils
+from __future__ import print_function
 def summarize_string(valobj, internal_dict):
     data = valobj.GetChildMemberWithName("mData")
     length = valobj.GetChildMemberWithName("mLength").GetValueAsUnsigned(0)
     return utils.format_string(data, length)
 def summarize_atom(valobj, internal_dict):
     target = lldb.debugger.GetSelectedTarget()
@@ -44,56 +45,56 @@ def prefcnt(debugger, command, result, d
     # We handled regular nsISupports-like refcounted objects and cycle collected
     # objects.
     target = debugger.GetSelectedTarget()
     process = target.GetProcess()
     thread = process.GetSelectedThread()
     frame = thread.GetSelectedFrame()
     obj = frame.EvaluateExpression(command)
     if obj.GetError().Fail():
-        print "could not evaluate expression"
+        print("could not evaluate expression")
     obj = utils.dereference(obj)
     field = obj.GetChildMemberWithName("mRefCnt")
     if field.GetError().Fail():
         field = obj.GetChildMemberWithName("refCnt")
     if field.GetError().Fail():
-        print "not a refcounted object"
+        print("not a refcounted object")
     refcnt_type = field.GetType().GetCanonicalType().GetName()
     if refcnt_type == "nsAutoRefCnt":
-        print field.GetChildMemberWithName("mValue").GetValueAsUnsigned(0)
+        print(field.GetChildMemberWithName("mValue").GetValueAsUnsigned(0))
     elif refcnt_type == "nsCycleCollectingAutoRefCnt":
-        print field.GetChildMemberWithName("mRefCntAndFlags").GetValueAsUnsigned(0) >> 2
+        print(field.GetChildMemberWithName("mRefCntAndFlags").GetValueAsUnsigned(0) >> 2)
     elif refcnt_type == "mozilla::ThreadSafeAutoRefCnt":
-        print field.GetChildMemberWithName("mValue").GetChildMemberWithName("mValue").GetValueAsUnsigned(0)
+        print(field.GetChildMemberWithName("mValue").GetChildMemberWithName("mValue").GetValueAsUnsigned(0))
     elif refcnt_type == "int":  # non-atomic mozilla::RefCounted object
-        print field.GetValueAsUnsigned(0)
+        print(field.GetValueAsUnsigned(0))
     elif refcnt_type == "mozilla::Atomic<int>":  # atomic mozilla::RefCounted object
-        print field.GetChildMemberWithName("mValue").GetValueAsUnsigned(0)
+        print(field.GetChildMemberWithName("mValue").GetValueAsUnsigned(0))
-        print "unknown mRefCnt type " + refcnt_type
+        print("unknown mRefCnt type " + refcnt_type)
 # Used to work around http://llvm.org/bugs/show_bug.cgi?id=22211
 def callfunc(debugger, command, result, dict):
     """Calls a function for which debugger information is unavailable by getting its address from the symbol table.
        The function is assumed to return void."""
     if '(' not in command:
-        print 'Usage: callfunc your_function(args)'
+        print('Usage: callfunc your_function(args)')
     command_parts = command.split('(')
     funcname = command_parts[0].strip()
     args = command_parts[1]
     target = debugger.GetSelectedTarget()
     symbols = target.FindFunctions(funcname).symbols
     if not symbols:
-        print 'Could not find a function symbol for a function called "%s"' % funcname
+        print('Could not find a function symbol for a function called "%s"' % funcname)
     sym = symbols[0]
     arg_types = '()'
     if sym.name and sym.name.startswith(funcname + '('):
         arg_types = sym.name[len(funcname):]
     debugger.HandleCommand('print ((void(*)%s)0x%0x)(%s' % (arg_types, sym.addr.GetLoadAddress(target), args))