Skip to content

Commit

Permalink
Bug 1603645. Make the .lldbinit python scripts compatible with Python…
Browse files Browse the repository at this point in the history
… 3. r=froydnj

Differential Revision: https://phabricator.services.mozilla.com/D57043

--HG--
extra : moz-landing-system : lando
  • Loading branch information
jwatt committed Dec 13, 2019
1 parent e210a55 commit 199786a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
5 changes: 4 additions & 1 deletion .lldbinit
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
# 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.
Expand Down
21 changes: 11 additions & 10 deletions third_party/python/lldbutils/lldbutils/general.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import lldb
from lldbutils import utils
from __future__ import print_function

def summarize_string(valobj, internal_dict):
data = valobj.GetChildMemberWithName("mData")
Expand Down Expand Up @@ -49,36 +50,36 @@ def prefcnt(debugger, command, result, dict):
frame = thread.GetSelectedFrame()
obj = frame.EvaluateExpression(command)
if obj.GetError().Fail():
print "could not evaluate expression"
print("could not evaluate expression")
return
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")
return
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))
else:
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)')
return

command_parts = command.split('(')
Expand All @@ -88,7 +89,7 @@ def callfunc(debugger, command, result, dict):
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)
return

sym = symbols[0]
Expand Down

0 comments on commit 199786a

Please sign in to comment.