[Lldb-commits] [lldb] r250533 - Make some more of the LLDB/SWIG/Python glue Python 3 aware.
Zachary Turner via lldb-commits
lldb-commits at lists.llvm.org
Fri Oct 16 10:52:32 PDT 2015
Author: zturner
Date: Fri Oct 16 12:52:32 2015
New Revision: 250533
URL: http://llvm.org/viewvc/llvm-project?rev=250533&view=rev
Log:
Make some more of the LLDB/SWIG/Python glue Python 3 aware.
Mostly this is just converting some print statements to print
functions.
Modified:
lldb/trunk/scripts/interface/SBBlock.i
lldb/trunk/scripts/interface/SBBreakpoint.i
lldb/trunk/scripts/interface/SBCompileUnit.i
lldb/trunk/scripts/interface/SBDebugger.i
lldb/trunk/scripts/interface/SBEvent.i
lldb/trunk/scripts/interface/SBLineEntry.i
lldb/trunk/scripts/interface/SBModule.i
lldb/trunk/scripts/interface/SBProcess.i
lldb/trunk/scripts/interface/SBTarget.i
lldb/trunk/scripts/interface/SBTypeCategory.i
lldb/trunk/scripts/interface/SBValue.i
lldb/trunk/scripts/interface/SBValueList.i
lldb/trunk/source/Interpreter/embedded_interpreter.py
Modified: lldb/trunk/scripts/interface/SBBlock.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBBlock.i?rev=250533&r1=250532&r2=250533&view=diff
==============================================================================
--- lldb/trunk/scripts/interface/SBBlock.i (original)
+++ lldb/trunk/scripts/interface/SBBlock.i Fri Oct 16 12:52:32 2015
@@ -128,7 +128,7 @@ public:
if range_idx < len(self):
return [self.sbblock.GetRangeStartAddress(range_idx), self.sbblock.GetRangeEndAddress(range_idx)]
else:
- print "error: unsupported item type: %s" % type(key)
+ print("error: unsupported item type: %s" % type(key))
return None
def get_ranges_access_object(self):
Modified: lldb/trunk/scripts/interface/SBBreakpoint.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBBreakpoint.i?rev=250533&r1=250532&r2=250533&view=diff
==============================================================================
--- lldb/trunk/scripts/interface/SBBreakpoint.i (original)
+++ lldb/trunk/scripts/interface/SBBreakpoint.i Fri Oct 16 12:52:32 2015
@@ -67,8 +67,8 @@ TestBreakpointIgnoreCount.py),
SBBreakpoint supports breakpoint location iteration, for example,
for bl in breakpoint:
- print 'breakpoint location load addr: %s' % hex(bl.GetLoadAddress())
- print 'breakpoint location condition: %s' % hex(bl.GetCondition())
+ print('breakpoint location load addr: %s' % hex(bl.GetLoadAddress()))
+ print('breakpoint location condition: %s' % hex(bl.GetCondition()))
and rich comparion methods which allow the API program to use,
Modified: lldb/trunk/scripts/interface/SBCompileUnit.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBCompileUnit.i?rev=250533&r1=250532&r2=250533&view=diff
==============================================================================
--- lldb/trunk/scripts/interface/SBCompileUnit.i (original)
+++ lldb/trunk/scripts/interface/SBCompileUnit.i Fri Oct 16 12:52:32 2015
@@ -21,10 +21,10 @@ SBCompileUnit supports line entry iterat
compileUnit = context.GetCompileUnit()
for lineEntry in compileUnit:
- print 'line entry: %s:%d' % (str(lineEntry.GetFileSpec()),
- lineEntry.GetLine())
- print 'start addr: %s' % str(lineEntry.GetStartAddress())
- print 'end addr: %s' % str(lineEntry.GetEndAddress())
+ print('line entry: %s:%d' % (str(lineEntry.GetFileSpec()),
+ lineEntry.GetLine()))
+ print('start addr: %s' % str(lineEntry.GetStartAddress()))
+ print('end addr: %s' % str(lineEntry.GetEndAddress()))
produces:
Modified: lldb/trunk/scripts/interface/SBDebugger.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBDebugger.i?rev=250533&r1=250532&r2=250533&view=diff
==============================================================================
--- lldb/trunk/scripts/interface/SBDebugger.i (original)
+++ lldb/trunk/scripts/interface/SBDebugger.i Fri Oct 16 12:52:32 2015
@@ -33,7 +33,7 @@ debugger = lldb.SBDebugger.Create()
debugger.SetAsync (False)
# Create a target from a file and arch
-print 'Creating a target for \'%s\'' % exe
+print('Creating a target for \'%s\'' % exe)
target = debugger.CreateTargetWithFileAndArch (exe, lldb.LLDB_ARCH_DEFAULT)
@@ -82,17 +82,17 @@ if target:
disassemble_instructions (insts)
registerList = frame.GetRegisters()
- print 'Frame registers (size of register set = %d):' % registerList.GetSize()
+ print('Frame registers (size of register set = %d):' % registerList.GetSize())
for value in registerList:
#print value
- print '%s (number of children = %d):' % (value.GetName(), value.GetNumChildren())
+ print('%s (number of children = %d):' % (value.GetName(), value.GetNumChildren()))
for child in value:
- print 'Name: ', child.GetName(), ' Value: ', child.GetValue()
+ print('Name: ', child.GetName(), ' Value: ', child.GetValue())
- print 'Hit the breakpoint at main, enter to continue and wait for program to exit or \'Ctrl-D\'/\'quit\' to terminate the program'
+ print('Hit the breakpoint at main, enter to continue and wait for program to exit or \'Ctrl-D\'/\'quit\' to terminate the program')
next = sys.stdin.readline()
if not next or next.rstrip('\n') == 'quit':
- print 'Terminating the inferior process...'
+ print('Terminating the inferior process...')
process.Kill()
else:
# Now continue to the program exit
@@ -101,9 +101,9 @@ if target:
# program exit. Print out some process info
print process
elif state == lldb.eStateExited:
- print 'Didn\'t hit the breakpoint at main, program has exited...'
+ print('Didn\'t hit the breakpoint at main, program has exited...')
else:
- print 'Unexpected process state: %s, killing process...' % debugger.StateAsCString (state)
+ print('Unexpected process state: %s, killing process...' % debugger.StateAsCString (state))
process.Kill()
") SBDebugger;
class SBDebugger
Modified: lldb/trunk/scripts/interface/SBEvent.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBEvent.i?rev=250533&r1=250532&r2=250533&view=diff
==============================================================================
--- lldb/trunk/scripts/interface/SBEvent.i (original)
+++ lldb/trunk/scripts/interface/SBEvent.i Fri Oct 16 12:52:32 2015
@@ -76,17 +76,17 @@ from test/python_api/event/TestEventspy:
# After that, the thread exits.
while not count > 3:
if traceOn:
- print 'Try wait for event...'
+ print('Try wait for event...')
if listener.WaitForEventForBroadcasterWithType(5,
broadcaster,
lldb.SBProcess.eBroadcastBitStateChanged,
event):
if traceOn:
- desc = lldbutil.get_description(event)
- print 'Event description:', desc
- print 'Event data flavor:', event.GetDataFlavor()
- print 'Process state:', lldbutil.state_type_to_str(process.GetState())
- print
+ desc = lldbutil.get_description(event))
+ print('Event description:', desc)
+ print('Event data flavor:', event.GetDataFlavor())
+ print('Process state:', lldbutil.state_type_to_str(process.GetState()))
+ print()
else:
if traceOn:
print 'timeout occurred waiting for event...'
Modified: lldb/trunk/scripts/interface/SBLineEntry.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBLineEntry.i?rev=250533&r1=250532&r2=250533&view=diff
==============================================================================
--- lldb/trunk/scripts/interface/SBLineEntry.i (original)
+++ lldb/trunk/scripts/interface/SBLineEntry.i Fri Oct 16 12:52:32 2015
@@ -14,10 +14,10 @@ namespace lldb {
a source file location. SBCompileUnit contains SBLineEntry(s). For example,
for lineEntry in compileUnit:
- print 'line entry: %s:%d' % (str(lineEntry.GetFileSpec()),
- lineEntry.GetLine())
- print 'start addr: %s' % str(lineEntry.GetStartAddress())
- print 'end addr: %s' % str(lineEntry.GetEndAddress())
+ print('line entry: %s:%d' % (str(lineEntry.GetFileSpec()),
+ lineEntry.GetLine()))
+ print('start addr: %s' % str(lineEntry.GetStartAddress()))
+ print('end addr: %s' % str(lineEntry.GetEndAddress()))
produces:
Modified: lldb/trunk/scripts/interface/SBModule.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBModule.i?rev=250533&r1=250532&r2=250533&view=diff
==============================================================================
--- lldb/trunk/scripts/interface/SBModule.i (original)
+++ lldb/trunk/scripts/interface/SBModule.i Fri Oct 16 12:52:32 2015
@@ -29,24 +29,24 @@ SBModule supports symbol iteration, for
and rich comparion methods which allow the API program to use,
if thisModule == thatModule:
- print 'This module is the same as that module'
+ print('This module is the same as that module')
to test module equality. A module also contains object file sections, namely
SBSection. SBModule supports section iteration through section_iter(), for
example,
- print 'Number of sections: %d' % module.GetNumSections()
+ print('Number of sections: %d' % module.GetNumSections())
for sec in module.section_iter():
- print sec
+ print(sec)
And to iterate the symbols within a SBSection, use symbol_in_section_iter(),
# Iterates the text section and prints each symbols within each sub-section.
for subsec in text_sec:
- print INDENT + repr(subsec)
+ print(INDENT + repr(subsec))
for sym in exe_module.symbol_in_section_iter(subsec):
- print INDENT2 + repr(sym)
- print INDENT2 + 'symbol type: %s' % symbol_type_to_str(sym.GetType())
+ print(INDENT2 + repr(sym))
+ print(INDENT2 + 'symbol type: %s' % symbol_type_to_str(sym.GetType()))
produces this following output:
@@ -365,7 +365,7 @@ public:
matches.append(symbol)
return matches
else:
- print "error: unsupported item type: %s" % type(key)
+ print("error: unsupported item type: %s" % type(key))
return None
def get_symbols_access_object(self):
@@ -415,7 +415,7 @@ public:
matches.append(section)
return matches
else:
- print "error: unsupported item type: %s" % type(key)
+ print("error: unsupported item type: %s" % type(key))
return None
class compile_units_access(object):
@@ -455,7 +455,7 @@ public:
matches.append(comp_unit)
return matches
else:
- print "error: unsupported item type: %s" % type(key)
+ print("error: unsupported item type: %s" % type(key))
return None
def get_sections_access_object(self):
Modified: lldb/trunk/scripts/interface/SBProcess.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBProcess.i?rev=250533&r1=250532&r2=250533&view=diff
==============================================================================
--- lldb/trunk/scripts/interface/SBProcess.i (original)
+++ lldb/trunk/scripts/interface/SBProcess.i Fri Oct 16 12:52:32 2015
@@ -276,7 +276,7 @@ public:
new_value = str(bytes)
result = process.WriteMemory(addr, new_value, error)
if not error.Success() or result != len(bytes):
- print 'SBProcess.WriteMemory() failed!'
+ print('SBProcess.WriteMemory() failed!')
") WriteMemory;
size_t
WriteMemory (addr_t addr, const void *buf, size_t size, lldb::SBError &error);
@@ -290,9 +290,9 @@ public:
error = lldb.SBError()
cstring = process.ReadCStringFromMemory(0x1000, 256, error)
if error.Success():
- print 'cstring: ', cstring
+ print('cstring: ', cstring)
else
- print 'error: ', error
+ print('error: ', error)
") ReadCStringFromMemory;
size_t
@@ -306,9 +306,9 @@ public:
error = lldb.SBError()
uint = ReadUnsignedFromMemory(0x1000, 4, error)
if error.Success():
- print 'integer: %u' % uint
+ print('integer: %u' % uint)
else
- print 'error: ', error
+ print('error: ', error)
") ReadUnsignedFromMemory;
@@ -322,9 +322,9 @@ public:
error = lldb.SBError()
ptr = ReadPointerFromMemory(0x1000, error)
if error.Success():
- print 'pointer: 0x%x' % ptr
+ print('pointer: 0x%x' % ptr)
else
- print 'error: ', error
+ print('error: ', error)
") ReadPointerFromMemory;
Modified: lldb/trunk/scripts/interface/SBTarget.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBTarget.i?rev=250533&r1=250532&r2=250533&view=diff
==============================================================================
--- lldb/trunk/scripts/interface/SBTarget.i (original)
+++ lldb/trunk/scripts/interface/SBTarget.i Fri Oct 16 12:52:32 2015
@@ -795,7 +795,7 @@ public:
matching_modules.append(module)
return matching_modules
else:
- print "error: unsupported item type: %s" % type(key)
+ print("error: unsupported item type: %s" % type(key))
return None
def get_modules_access_object(self):
Modified: lldb/trunk/scripts/interface/SBTypeCategory.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBTypeCategory.i?rev=250533&r1=250532&r2=250533&view=diff
==============================================================================
--- lldb/trunk/scripts/interface/SBTypeCategory.i (original)
+++ lldb/trunk/scripts/interface/SBTypeCategory.i Fri Oct 16 12:52:32 2015
@@ -142,7 +142,7 @@ namespace lldb {
elif isinstance(key,self.regex_type):
return self.get_by_name_function(self.sbcategory,SBTypeNameSpecifier(key.pattern,True))
else:
- print "error: unsupported item type: %s" % type(key)
+ print("error: unsupported item type: %s" % type(key))
return None
def get_formats_access_object(self):
Modified: lldb/trunk/scripts/interface/SBValue.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBValue.i?rev=250533&r1=250532&r2=250533&view=diff
==============================================================================
--- lldb/trunk/scripts/interface/SBValue.i (original)
+++ lldb/trunk/scripts/interface/SBValue.i Fri Oct 16 12:52:32 2015
@@ -22,9 +22,9 @@ frame as an SBValue, and iterate through
GPRs = regs
break
- print '%s (number of children = %d):' % (GPRs.GetName(), GPRs.GetNumChildren())
+ print('%s (number of children = %d):' % (GPRs.GetName(), GPRs.GetNumChildren()))
for reg in GPRs:
- print 'Name: ', reg.GetName(), ' Value: ', reg.GetValue()
+ print('Name: ', reg.GetName(), ' Value: ', reg.GetValue())
produces the output:
Modified: lldb/trunk/scripts/interface/SBValueList.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBValueList.i?rev=250533&r1=250532&r2=250533&view=diff
==============================================================================
--- lldb/trunk/scripts/interface/SBValueList.i (original)
+++ lldb/trunk/scripts/interface/SBValueList.i Fri Oct 16 12:52:32 2015
@@ -35,7 +35,7 @@ def get_GPRs(frame):
from lldbutil import get_GPRs
regs = get_GPRs(frame)
for reg in regs:
- print '%s => %s' % (reg.GetName(), reg.GetValue())
+ print('%s => %s' % (reg.GetName(), reg.GetValue()))
...
'''
return get_registers(frame, 'general purpose')
@@ -48,7 +48,7 @@ def get_FPRs(frame):
from lldbutil import get_FPRs
regs = get_FPRs(frame)
for reg in regs:
- print '%s => %s' % (reg.GetName(), reg.GetValue())
+ print('%s => %s' % (reg.GetName(), reg.GetValue()))
...
'''
return get_registers(frame, 'floating point')
@@ -61,7 +61,7 @@ def get_ESRs(frame):
from lldbutil import get_ESRs
regs = get_ESRs(frame)
for reg in regs:
- print '%s => %s' % (reg.GetName(), reg.GetValue())
+ print('%s => %s' % (reg.GetName(), reg.GetValue()))
...
'''
return get_registers(frame, 'exception state')"
Modified: lldb/trunk/source/Interpreter/embedded_interpreter.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/embedded_interpreter.py?rev=250533&r1=250532&r2=250533&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/embedded_interpreter.py (original)
+++ lldb/trunk/source/Interpreter/embedded_interpreter.py Fri Oct 16 12:52:32 2015
@@ -1,7 +1,10 @@
-import __builtin__
+import sys
+if sys.version_info[0] < 3:
+ import __builtin__ as builtins
+else:
+ import builtins
import code
import lldb
-import sys
import traceback
try:
@@ -42,8 +45,8 @@ def setquit():
# "sys.exit(123)"
global g_builtin_override_called
g_builtin_override_called = False
- __builtin__.quit = LLDBQuitter('quit')
- __builtin__.exit = LLDBQuitter('exit')
+ builtins.quit = LLDBQuitter('quit')
+ builtins.exit = LLDBQuitter('exit')
# When running one line, we might place the string to run in this string
# in case it would be hard to correctly escape a string's contents
@@ -94,7 +97,7 @@ def run_python_interpreter (local_dict):
except SystemExit as e:
global g_builtin_override_called
if not g_builtin_override_called:
- print 'Script exited with %s' %(e)
+ print('Script exited with %s' %(e))
def run_one_line (local_dict, input_string):
global g_run_one_line_str
@@ -109,4 +112,4 @@ def run_one_line (local_dict, input_stri
except SystemExit as e:
global g_builtin_override_called
if not g_builtin_override_called:
- print 'Script exited with %s' %(e)
+ print('Script exited with %s' %(e))
More information about the lldb-commits
mailing list