summaryrefslogtreecommitdiffstats
path: root/lldb/examples/python
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/examples/python')
-rwxr-xr-xlldb/examples/python/bsd.py39
-rw-r--r--lldb/examples/python/cmdtemplate.py10
-rwxr-xr-xlldb/examples/python/delta.py14
-rw-r--r--lldb/examples/python/diagnose_nsstring.py32
-rw-r--r--lldb/examples/python/diagnose_unwind.py113
-rwxr-xr-xlldb/examples/python/disasm-stress-test.py20
-rwxr-xr-xlldb/examples/python/disasm.py36
-rwxr-xr-xlldb/examples/python/file_extract.py2
-rwxr-xr-xlldb/examples/python/gdb_disassemble.py6
-rwxr-xr-xlldb/examples/python/gdbremote.py254
-rwxr-xr-xlldb/examples/python/globals.py17
-rw-r--r--lldb/examples/python/jump.py4
-rw-r--r--lldb/examples/python/lldb_module_utils.py23
-rw-r--r--lldb/examples/python/lldbtk.py14
-rwxr-xr-xlldb/examples/python/mach_o.py191
-rwxr-xr-xlldb/examples/python/memory.py36
-rwxr-xr-xlldb/examples/python/performance.py40
-rwxr-xr-xlldb/examples/python/process_events.py82
-rw-r--r--lldb/examples/python/pytracer.py35
-rw-r--r--lldb/examples/python/scripted_step.py10
-rw-r--r--lldb/examples/python/shadow.py13
-rw-r--r--lldb/examples/python/sources.py7
-rwxr-xr-xlldb/examples/python/stacks.py12
-rwxr-xr-xlldb/examples/python/types.py56
24 files changed, 546 insertions, 520 deletions
diff --git a/lldb/examples/python/bsd.py b/lldb/examples/python/bsd.py
index 3e9528c6584..c66226e3710 100755
--- a/lldb/examples/python/bsd.py
+++ b/lldb/examples/python/bsd.py
@@ -1,4 +1,5 @@
#!/usr/bin/python
+from __future__ import print_function
import cmd
import optparse
@@ -391,18 +392,18 @@ if __name__ == '__main__':
def print_mtime_error(result, dmap_mtime, actual_mtime):
- print >>result, ("error: modification time in debug map (%#08.8x) doesn't "
+ print("error: modification time in debug map (%#08.8x) doesn't "
"match the .o file modification time (%#08.8x)" % (
- dmap_mtime, actual_mtime))
+ dmap_mtime, actual_mtime), file=result)
def print_file_missing_error(result, path):
- print >>result, "error: file \"%s\" doesn't exist" % (path)
+ print("error: file \"%s\" doesn't exist" % (path), file=result)
def print_multiple_object_matches(result, object_name, mtime, matches):
- print >>result, ("error: multiple matches for object '%s' with with "
- "modification time %#08.8x:" % (object_name, mtime))
+ print("error: multiple matches for object '%s' with with "
+ "modification time %#08.8x:" % (object_name, mtime), file=result)
Archive.dump_header(f=result)
for match in matches:
match.dump(f=result, flat=True)
@@ -411,15 +412,15 @@ def print_multiple_object_matches(result, object_name, mtime, matches):
def print_archive_object_error(result, object_name, mtime, archive):
matches = archive.find(object_name, f=result)
if len(matches) > 0:
- print >>result, ("error: no objects have a modification time that "
+ print("error: no objects have a modification time that "
"matches %#08.8x for '%s'. Potential matches:" % (
- mtime, object_name))
+ mtime, object_name), file=result)
Archive.dump_header(f=result)
for match in matches:
match.dump(f=result, flat=True)
else:
- print >>result, "error: no object named \"%s\" found in archive:" % (
- object_name)
+ print("error: no object named \"%s\" found in archive:" % (
+ object_name), file=result)
Archive.dump_header(f=result)
for match in archive.objects:
match.dump(f=result, flat=True)
@@ -496,13 +497,13 @@ or whose modification times don't match in the debug map of an executable.'''
dmap_mtime = int(str(symbol).split('value = ')
[1].split(',')[0], 16)
if not options.errors:
- print >>result, '%s' % (path)
+ print('%s' % (path), file=result)
if os.path.exists(path):
actual_mtime = int(os.stat(path).st_mtime)
if dmap_mtime != actual_mtime:
num_errors += 1
if options.errors:
- print >>result, '%s' % (path),
+ print('%s' % (path), end=' ', file=result)
print_mtime_error(result, dmap_mtime,
actual_mtime)
elif path[-1] == ')':
@@ -510,13 +511,13 @@ or whose modification times don't match in the debug map of an executable.'''
if not archive_path and not object_name:
num_errors += 1
if options.errors:
- print >>result, '%s' % (path),
+ print('%s' % (path), end=' ', file=result)
print_file_missing_error(path)
continue
if not os.path.exists(archive_path):
num_errors += 1
if options.errors:
- print >>result, '%s' % (path),
+ print('%s' % (path), end=' ', file=result)
print_file_missing_error(archive_path)
continue
if archive_path in archives:
@@ -527,30 +528,30 @@ or whose modification times don't match in the debug map of an executable.'''
matches = archive.find(object_name, dmap_mtime)
num_matches = len(matches)
if num_matches == 1:
- print >>result, '1 match'
+ print('1 match', file=result)
obj = matches[0]
if obj.date != dmap_mtime:
num_errors += 1
if options.errors:
- print >>result, '%s' % (path),
+ print('%s' % (path), end=' ', file=result)
print_mtime_error(result, dmap_mtime, obj.date)
elif num_matches == 0:
num_errors += 1
if options.errors:
- print >>result, '%s' % (path),
+ print('%s' % (path), end=' ', file=result)
print_archive_object_error(result, object_name,
dmap_mtime, archive)
elif num_matches > 1:
num_errors += 1
if options.errors:
- print >>result, '%s' % (path),
+ print('%s' % (path), end=' ', file=result)
print_multiple_object_matches(result,
object_name,
dmap_mtime, matches)
if num_errors > 0:
- print >>result, "%u errors found" % (num_errors)
+ print("%u errors found" % (num_errors), file=result)
else:
- print >>result, "No errors detected in debug map"
+ print("No errors detected in debug map", file=result)
def __lldb_init_module(debugger, dict):
diff --git a/lldb/examples/python/cmdtemplate.py b/lldb/examples/python/cmdtemplate.py
index 0acb04ef471..97af943e6de 100644
--- a/lldb/examples/python/cmdtemplate.py
+++ b/lldb/examples/python/cmdtemplate.py
@@ -9,6 +9,8 @@
# (lldb) command script import /path/to/cmdtemplate.py
# ---------------------------------------------------------------------
+from __future__ import print_function
+
import inspect
import lldb
import optparse
@@ -124,7 +126,7 @@ class FrameStatCommand:
options.inscope)
variables_count = variables_list.GetSize()
if variables_count == 0:
- print >> result, "no variables here"
+ print("no variables here", file=result)
return
total_size = 0
for i in range(0, variables_count):
@@ -132,9 +134,9 @@ class FrameStatCommand:
variable_type = variable.GetType()
total_size = total_size + variable_type.GetByteSize()
average_size = float(total_size) / variables_count
- print >>result, ("Your frame has %d variables. Their total size "
- "is %d bytes. The average size is %f bytes") % (
- variables_count, total_size, average_size)
+ print("Your frame has %d variables. Their total size "
+ "is %d bytes. The average size is %f bytes" % (
+ variables_count, total_size, average_size), file=result)
# not returning anything is akin to returning success
diff --git a/lldb/examples/python/delta.py b/lldb/examples/python/delta.py
index 1b192aceb9d..bb52cad633f 100755
--- a/lldb/examples/python/delta.py
+++ b/lldb/examples/python/delta.py
@@ -17,6 +17,8 @@
#----------------------------------------------------------------------
import commands
+from __future__ import print_function
+
import optparse
import os
import shlex
@@ -94,9 +96,9 @@ def parse_log_file(file, options):
handy when trying to figure out why some operation in the debugger is taking
a long time during a preset set of debugger commands.'''
- print '#----------------------------------------------------------------------'
- print "# Log file: '%s'" % file
- print '#----------------------------------------------------------------------'
+ print('#----------------------------------------------------------------------')
+ print("# Log file: '%s'" % file)
+ print('#----------------------------------------------------------------------')
timestamp_regex = re.compile('(\s*)([1-9][0-9]+\.[0-9]+)([^0-9].*)$')
@@ -114,10 +116,10 @@ def parse_log_file(file, options):
else:
base_time = curr_time
- print '%s%.6f %+.6f%s' % (match.group(1), curr_time - base_time, delta, match.group(3))
+ print('%s%.6f %+.6f%s' % (match.group(1), curr_time - base_time, delta, match.group(3)))
last_time = curr_time
else:
- print line
+ print(line)
if __name__ == '__main__':
@@ -131,4 +133,4 @@ else:
# Add any commands contained in this module to LLDB
lldb.debugger.HandleCommand(
'command script add -f delta.parse_time_log parse_time_log')
- print 'The "parse_time_log" command is now installed and ready for use, type "parse_time_log --help" for more information'
+ print('The "parse_time_log" command is now installed and ready for use, type "parse_time_log --help" for more information')
diff --git a/lldb/examples/python/diagnose_nsstring.py b/lldb/examples/python/diagnose_nsstring.py
index 0404f714f74..4a8eee3c2dd 100644
--- a/lldb/examples/python/diagnose_nsstring.py
+++ b/lldb/examples/python/diagnose_nsstring.py
@@ -4,6 +4,8 @@
# decisions it did and providing some useful context information that can
# be used for improving the formatter
+from __future__ import print_function
+
import lldb
@@ -32,7 +34,7 @@ def read_memory(process, location, size):
if x < size - 2:
data = data + ":"
except Exception as e:
- print e
+ print(e)
return data
@@ -57,7 +59,7 @@ def diagnose_nsstring_Command_Impl(debugger, command, result, internal_dict):
nsstring = frame.EvaluateExpression(command, options)
else:
nsstring = target.EvaluateExpression(command, options)
- print >>result, str(nsstring)
+ print(str(nsstring), file=result)
nsstring_address = nsstring.GetValueAsUnsigned(0)
if nsstring_address == 0:
return "unable to obtain the string - cannot proceed"
@@ -103,7 +105,7 @@ struct $__lldb__CFString {\
expression = expression + "*(($__lldb__CFString*) %d)" % nsstring_address
# print expression
dumped = target.EvaluateExpression(expression, options)
- print >>result, str(dumped)
+ print(str(dumped), file=result)
little_endian = (target.byte_order == lldb.eByteOrderLittle)
ptr_size = target.addr_size
@@ -119,8 +121,8 @@ struct $__lldb__CFString {\
lldb.eDynamicCanRunTarget).GetTypeName() == "NSPathStore2")
has_null = (info_bits & 8) == 8
- print >>result, "\nInfo=%d\nMutable=%s\nInline=%s\nExplicit=%s\nUnicode=%s\nSpecial=%s\nNull=%s\n" % \
- (info_bits, "yes" if is_mutable else "no", "yes" if is_inline else "no", "yes" if has_explicit_length else "no", "yes" if is_unicode else "no", "yes" if is_special else "no", "yes" if has_null else "no")
+ print("\nInfo=%d\nMutable=%s\nInline=%s\nExplicit=%s\nUnicode=%s\nSpecial=%s\nNull=%s\n" % \
+ (info_bits, "yes" if is_mutable else "no", "yes" if is_inline else "no", "yes" if has_explicit_length else "no", "yes" if is_unicode else "no", "yes" if is_special else "no", "yes" if has_null else "no"), file=result)
explicit_length_offset = 0
if not has_null and has_explicit_length and not is_special:
@@ -135,13 +137,13 @@ struct $__lldb__CFString {\
explicit_length_offset = 0
if explicit_length_offset == 0:
- print >>result, "There is no explicit length marker - skipping this step\n"
+ print("There is no explicit length marker - skipping this step\n", file=result)
else:
explicit_length_offset = nsstring_address + explicit_length_offset
explicit_length = process.ReadUnsignedFromMemory(
explicit_length_offset, 4, error)
- print >>result, "Explicit length location is at 0x%x - read value is %d\n" % (
- explicit_length_offset, explicit_length)
+ print("Explicit length location is at 0x%x - read value is %d\n" % (
+ explicit_length_offset, explicit_length), file=result)
if is_mutable:
location = 2 * ptr_size + nsstring_address
@@ -152,7 +154,7 @@ struct $__lldb__CFString {\
location = 2 * ptr_size + nsstring_address
if is_inline:
if not has_explicit_length:
- print >>result, "Unicode & Inline & !Explicit is a new combo - no formula for it"
+ print("Unicode & Inline & !Explicit is a new combo - no formula for it", file=result)
else:
location += ptr_size
else:
@@ -166,18 +168,18 @@ struct $__lldb__CFString {\
else:
location = 2 * ptr_size + nsstring_address
location = process.ReadPointerFromMemory(location, error)
- print >>result, "Expected data location: 0x%x\n" % (location)
- print >>result, "1K of data around location: %s\n" % read_memory(
- process, location, 1024)
- print >>result, "5K of data around string pointer: %s\n" % read_memory(
- process, nsstring_address, 1024 * 5)
+ print("Expected data location: 0x%x\n" % (location), file=result)
+ print("1K of data around location: %s\n" % read_memory(
+ process, location, 1024), file=result)
+ print("5K of data around string pointer: %s\n" % read_memory(
+ process, nsstring_address, 1024 * 5), file=result)
def __lldb_init_module(debugger, internal_dict):
debugger.HandleCommand(
"command script add -f %s.diagnose_nsstring_Command_Impl diagnose-nsstring" %
__name__)
- print 'The "diagnose-nsstring" command has been installed, type "help diagnose-nsstring" for detailed help.'
+ print('The "diagnose-nsstring" command has been installed, type "help diagnose-nsstring" for detailed help.')
__lldb_init_module(lldb.debugger, None)
__lldb_init_module = None
diff --git a/lldb/examples/python/diagnose_unwind.py b/lldb/examples/python/diagnose_unwind.py
index b90372970e5..db3ff1952f3 100644
--- a/lldb/examples/python/diagnose_unwind.py
+++ b/lldb/examples/python/diagnose_unwind.py
@@ -5,6 +5,7 @@
# information about the stack frames, and tries an alternate unwind
# algorithm, that will help to understand why lldb's unwind algorithm
# did not succeed.
+from __future__ import print_function
import optparse
import lldb
@@ -39,7 +40,7 @@ def backtrace_print_frame(target, frame_num, addr, fp):
module_description = '%s %s' % (
module_filename, module_uuid_str)
except Exception:
- print '%2d: pc==0x%-*x fp==0x%-*x' % (frame_num, addr_width, addr_for_printing, addr_width, fp)
+ print('%2d: pc==0x%-*x fp==0x%-*x' % (frame_num, addr_width, addr_for_printing, addr_width, fp))
return
sym_ctx = target.ResolveSymbolContextForAddress(
@@ -47,9 +48,9 @@ def backtrace_print_frame(target, frame_num, addr, fp):
if sym_ctx.IsValid() and sym_ctx.GetSymbol().IsValid():
function_start = sym_ctx.GetSymbol().GetStartAddress().GetLoadAddress(target)
offset = addr - function_start
- print '%2d: pc==0x%-*x fp==0x%-*x %s %s + %d' % (frame_num, addr_width, addr_for_printing, addr_width, fp, module_description, sym_ctx.GetSymbol().GetName(), offset)
+ print('%2d: pc==0x%-*x fp==0x%-*x %s %s + %d' % (frame_num, addr_width, addr_for_printing, addr_width, fp, module_description, sym_ctx.GetSymbol().GetName(), offset))
else:
- print '%2d: pc==0x%-*x fp==0x%-*x %s' % (frame_num, addr_width, addr_for_printing, addr_width, fp, module_description)
+ print('%2d: pc==0x%-*x fp==0x%-*x %s' % (frame_num, addr_width, addr_for_printing, addr_width, fp, module_description))
return sbaddr.GetModule()
# A simple stack walk algorithm that follows the frame chain.
@@ -78,7 +79,7 @@ def simple_backtrace(debugger):
this_module = backtrace_print_frame(
target, 0, cur_thread.GetFrameAtIndex(0).GetPC(), initial_fp)
print_stack_frame(process, initial_fp)
- print ""
+ print("")
if this_module is not None:
module_list.append(this_module)
if cur_thread.GetNumFrames() < 2:
@@ -94,7 +95,7 @@ def simple_backtrace(debugger):
address_list.append(cur_pc)
this_module = backtrace_print_frame(target, frame_num, cur_pc, cur_fp)
print_stack_frame(process, cur_fp)
- print ""
+ print("")
if this_module is not None:
module_list.append(this_module)
frame_num = frame_num + 1
@@ -119,7 +120,7 @@ def simple_backtrace(debugger):
cur_fp = next_fp
this_module = backtrace_print_frame(target, frame_num, cur_pc, cur_fp)
print_stack_frame(process, cur_fp)
- print ""
+ print("")
if this_module is not None:
module_list.append(this_module)
return [module_list, address_list]
@@ -139,7 +140,7 @@ def print_stack_frame(process, fp):
addr + (i * addr_size), error)
outline += " 0x%x" % address
i += 1
- print outline
+ print(outline)
except Exception:
return
@@ -180,39 +181,39 @@ def diagnose_unwind(debugger, command, result, dict):
modules_seen = []
addresses_seen = []
- print 'LLDB version %s' % debugger.GetVersionString()
- print 'Unwind diagnostics for thread %d' % thread.GetIndexID()
- print ""
- print "============================================================================================="
- print ""
- print "OS plugin setting:"
+ print('LLDB version %s' % debugger.GetVersionString())
+ print('Unwind diagnostics for thread %d' % thread.GetIndexID())
+ print("")
+ print("=============================================================================================")
+ print("")
+ print("OS plugin setting:")
debugger.HandleCommand(
"settings show target.process.python-os-plugin-path")
- print ""
- print "Live register context:"
+ print("")
+ print("Live register context:")
thread.SetSelectedFrame(0)
debugger.HandleCommand("register read")
- print ""
- print "============================================================================================="
- print ""
- print "lldb's unwind algorithm:"
- print ""
+ print("")
+ print("=============================================================================================")
+ print("")
+ print("lldb's unwind algorithm:")
+ print("")
frame_num = 0
for frame in thread.frames:
if not frame.IsInlined():
this_module = backtrace_print_frame(
target, frame_num, frame.GetPC(), frame.GetFP())
print_stack_frame(process, frame.GetFP())
- print ""
+ print("")
if this_module is not None:
modules_seen.append(this_module)
addresses_seen.append(frame.GetPC())
frame_num = frame_num + 1
- print ""
- print "============================================================================================="
- print ""
- print "Simple stack walk algorithm:"
- print ""
+ print("")
+ print("=============================================================================================")
+ print("")
+ print("Simple stack walk algorithm:")
+ print("")
(module_list, address_list) = simple_backtrace(debugger)
if module_list and module_list is not None:
modules_seen += module_list
@@ -220,11 +221,11 @@ def diagnose_unwind(debugger, command, result, dict):
addresses_seen = set(addresses_seen)
addresses_seen.update(set(address_list))
- print ""
- print "============================================================================================="
- print ""
- print "Modules seen in stack walks:"
- print ""
+ print("")
+ print("=============================================================================================")
+ print("")
+ print("Modules seen in stack walks:")
+ print("")
modules_already_seen = set()
for module in modules_seen:
if module is not None and module.GetFileSpec().GetFilename() is not None:
@@ -235,18 +236,18 @@ def diagnose_unwind(debugger, command, result, dict):
modules_already_seen.add(
module.GetFileSpec().GetFilename())
- print ""
- print "============================================================================================="
- print ""
- print "Disassembly ofaddresses seen in stack walks:"
- print ""
+ print("")
+ print("=============================================================================================")
+ print("")
+ print("Disassembly ofaddresses seen in stack walks:")
+ print("")
additional_addresses_to_disassemble = addresses_seen
for frame in thread.frames:
if not frame.IsInlined():
- print "--------------------------------------------------------------------------------------"
- print ""
- print "Disassembly of %s, frame %d, address 0x%x" % (frame.GetFunctionName(), frame.GetFrameID(), frame.GetPC())
- print ""
+ print("--------------------------------------------------------------------------------------")
+ print("")
+ print("Disassembly of %s, frame %d, address 0x%x" % (frame.GetFunctionName(), frame.GetFrameID(), frame.GetPC()))
+ print("")
if target.triple[
0:6] == "x86_64" or target.triple[
0:4] == "i386":
@@ -261,10 +262,10 @@ def diagnose_unwind(debugger, command, result, dict):
frame.GetPC())
for address in list(additional_addresses_to_disassemble):
- print "--------------------------------------------------------------------------------------"
- print ""
- print "Disassembly of 0x%x" % address
- print ""
+ print("--------------------------------------------------------------------------------------")
+ print("")
+ print("Disassembly of 0x%x" % address)
+ print("")
if target.triple[
0:6] == "x86_64" or target.triple[
0:4] == "i386":
@@ -273,16 +274,16 @@ def diagnose_unwind(debugger, command, result, dict):
else:
debugger.HandleCommand('disassemble -a 0x%x' % address)
- print ""
- print "============================================================================================="
- print ""
+ print("")
+ print("=============================================================================================")
+ print("")
additional_addresses_to_show_unwind = addresses_seen
for frame in thread.frames:
if not frame.IsInlined():
- print "--------------------------------------------------------------------------------------"
- print ""
- print "Unwind instructions for %s, frame %d" % (frame.GetFunctionName(), frame.GetFrameID())
- print ""
+ print("--------------------------------------------------------------------------------------")
+ print("")
+ print("Unwind instructions for %s, frame %d" % (frame.GetFunctionName(), frame.GetFrameID()))
+ print("")
debugger.HandleCommand(
'image show-unwind -a "0x%x"' % frame.GetPC())
if frame.GetPC() in additional_addresses_to_show_unwind:
@@ -290,10 +291,10 @@ def diagnose_unwind(debugger, command, result, dict):
frame.GetPC())
for address in list(additional_addresses_to_show_unwind):
- print "--------------------------------------------------------------------------------------"
- print ""
- print "Unwind instructions for 0x%x" % address
- print ""
+ print("--------------------------------------------------------------------------------------")
+ print("")
+ print("Unwind instructions for 0x%x" % address)
+ print("")
debugger.HandleCommand(
'image show-unwind -a "0x%x"' % address)
@@ -310,4 +311,4 @@ def create_diagnose_unwind_options():
lldb.debugger.HandleCommand(
'command script add -f %s.diagnose_unwind diagnose-unwind' %
__name__)
-print 'The "diagnose-unwind" command has been installed, type "help diagnose-unwind" for detailed help.'
+print('The "diagnose-unwind" command has been installed, type "help diagnose-unwind" for detailed help.')
diff --git a/lldb/examples/python/disasm-stress-test.py b/lldb/examples/python/disasm-stress-test.py
index 2c20ffb9236..5d0ce96fbd6 100755
--- a/lldb/examples/python/disasm-stress-test.py
+++ b/lldb/examples/python/disasm-stress-test.py
@@ -71,7 +71,7 @@ def AddLLDBToSysPathOnMacOSX():
lldb_framework_path = GetLLDBFrameworkPath()
if lldb_framework_path is None:
- print "Couldn't find LLDB.framework"
+ print("Couldn't find LLDB.framework")
sys.exit(-1)
sys.path.append(lldb_framework_path + "/Resources/Python")
@@ -86,13 +86,13 @@ import lldb
debugger = lldb.SBDebugger.Create()
if debugger.IsValid() == False:
- print "Couldn't create an SBDebugger"
+ print("Couldn't create an SBDebugger")
sys.exit(-1)
target = debugger.CreateTargetWithFileAndArch(None, arg_ns.arch)
if target.IsValid() == False:
- print "Couldn't create an SBTarget for architecture " + arg_ns.arch
+ print("Couldn't create an SBTarget for architecture " + arg_ns.arch)
sys.exit(-1)
@@ -103,8 +103,8 @@ def ResetLogFile(log_file):
def PrintByteArray(log_file, byte_array):
for byte in byte_array:
- print >>log_file, hex(byte) + " ",
- print >>log_file
+ print(hex(byte) + " ", end=' ', file=log_file)
+ print(file=log_file)
class SequentialInstructionProvider:
@@ -119,7 +119,7 @@ class SequentialInstructionProvider:
def PrintCurrentState(self, ret):
ResetLogFile(self.m_log_file)
- print >>self.m_log_file, self.m_value
+ print(self.m_value, file=self.m_log_file)
PrintByteArray(self.m_log_file, ret)
def GetNextInstruction(self):
@@ -215,16 +215,16 @@ for inst_bytes in instruction_provider:
remaining_time = float(
total_num_instructions - num_instructions_logged) * (
float(elapsed_time) / float(num_instructions_logged))
- print str(datetime.timedelta(seconds=remaining_time))
+ print(str(datetime.timedelta(seconds=remaining_time)))
num_instructions_logged = num_instructions_logged + 1
inst_list = target.GetInstructions(fake_address, inst_bytes)
if not inst_list.IsValid():
- print >>log_file, "Invalid instruction list"
+ print("Invalid instruction list", file=log_file)
continue
inst = inst_list.GetInstructionAtIndex(0)
if not inst.IsValid():
- print >>log_file, "Invalid instruction"
+ print("Invalid instruction", file=log_file)
continue
instr_output_stream = lldb.SBStream()
inst.GetDescription(instr_output_stream)
- print >>log_file, instr_output_stream.GetData()
+ print(instr_output_stream.GetData(), file=log_file)
diff --git a/lldb/examples/python/disasm.py b/lldb/examples/python/disasm.py
index af024a6887d..819a0522388 100755
--- a/lldb/examples/python/disasm.py
+++ b/lldb/examples/python/disasm.py
@@ -15,12 +15,12 @@ import sys
def disassemble_instructions(insts):
for i in insts:
- print i
+ print(i)
def usage():
- print "Usage: disasm.py [-n name] executable-image"
- print " By default, it breaks at and disassembles the 'main' function."
+ print("Usage: disasm.py [-n name] executable-image")
+ print(" By default, it breaks at and disassembles the 'main' function.")
sys.exit(0)
if len(sys.argv) == 2:
@@ -43,7 +43,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)
@@ -52,7 +52,7 @@ if target:
main_bp = target.BreakpointCreateByName(
fname, target.GetExecutable().GetFilename())
- print main_bp
+ print(main_bp)
# Launch the process. Since we specified synchronous mode, we won't return
# from this function until we hit the breakpoint at main
@@ -62,24 +62,24 @@ if target:
if process:
# Print some simple process info
state = process.GetState()
- print process
+ print(process)
if state == lldb.eStateStopped:
# Get the first thread
thread = process.GetThreadAtIndex(0)
if thread:
# Print some simple thread info
- print thread
+ print(thread)
# Get the first frame
frame = thread.GetFrameAtIndex(0)
if frame:
# Print some simple frame info
- print frame
+ print(frame)
function = frame.GetFunction()
# See if we have debug info (a function)
if function:
# We do have a function, print some info for the
# function
- print function
+ print(function)
# Now get all instructions for this function and print
# them
insts = function.GetInstructions(target)
@@ -91,35 +91,35 @@ if target:
if symbol:
# We do have a symbol, print some info for the
# symbol
- print symbol
+ print(symbol)
# Now get all instructions for this symbol and
# print them
insts = symbol.GetInstructions(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
process.Continue()
# When we return from the above function we will hopefully be at the
# program exit. Print out some process info
- print process
+ 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()
diff --git a/lldb/examples/python/file_extract.py b/lldb/examples/python/file_extract.py
index 7a617e91106..decbba0b299 100755
--- a/lldb/examples/python/file_extract.py
+++ b/lldb/examples/python/file_extract.py
@@ -29,7 +29,7 @@ class FileExtract:
elif b == '<' or b == '>' or b == '@' or b == '=':
self.byte_order = b
else:
- print "error: invalid byte order specified: '%s'" % b
+ print("error: invalid byte order specified: '%s'" % b)
def is_in_memory(self):
return False
diff --git a/lldb/examples/python/gdb_disassemble.py b/lldb/examples/python/gdb_disassemble.py
index 2590aba8c85..65983e2e993 100755
--- a/lldb/examples/python/gdb_disassemble.py
+++ b/lldb/examples/python/gdb_disassemble.py
@@ -16,11 +16,11 @@ def disassemble(debugger, command, result, dict):
inst_offset = inst_addr - start_addr
comment = inst.comment
if comment:
- print "<%s + %-4u> 0x%x %8s %s ; %s" % (name, inst_offset, inst_addr, inst.mnemonic, inst.operands, comment)
+ print("<%s + %-4u> 0x%x %8s %s ; %s" % (name, inst_offset, inst_addr, inst.mnemonic, inst.operands, comment))
else:
- print "<%s + %-4u> 0x%x %8s %s" % (name, inst_offset, inst_addr, inst.mnemonic, inst.operands)
+ print("<%s + %-4u> 0x%x %8s %s" % (name, inst_offset, inst_addr, inst.mnemonic, inst.operands))
# Install the command when the module gets imported
lldb.debugger.HandleCommand(
'command script add -f gdb_disassemble.disassemble gdb-disassemble')
-print 'Installed "gdb-disassemble" command for disassembly'
+print('Installed "gdb-disassemble" command for disassembly')
diff --git a/lldb/examples/python/gdbremote.py b/lldb/examples/python/gdbremote.py
index 4ca8a1b82e8..d9647efe276 100755
--- a/lldb/examples/python/gdbremote.py
+++ b/lldb/examples/python/gdbremote.py
@@ -299,7 +299,7 @@ def stop_gdb_log(debugger, command, result, dict):
options.symbolicator = lldb.utils.symbolication.Symbolicator()
options.symbolicator.target = lldb.target
else:
- print "error: can't symbolicate without a target"
+ print("error: can't symbolicate without a target")
if not g_log_file:
result.PutCString(
@@ -314,7 +314,7 @@ def stop_gdb_log(debugger, command, result, dict):
else:
result.PutCString(usage)
else:
- print 'error: the GDB packet log file "%s" does not exist' % g_log_file
+ print('error: the GDB packet log file "%s" does not exist' % g_log_file)
def is_hex_byte(str):
@@ -584,11 +584,11 @@ def get_thread_from_thread_suffix(str):
def cmd_qThreadStopInfo(options, cmd, args):
packet = Packet(args)
tid = packet.get_hex_uint('big')
- print "get_thread_stop_info (tid = 0x%x)" % (tid)
+ print("get_thread_stop_info (tid = 0x%x)" % (tid))
def cmd_stop_reply(options, cmd, args):
- print "get_last_stop_info()"
+ print("get_last_stop_info()")
return False
@@ -611,69 +611,69 @@ def rsp_stop_reply(options, cmd, cmd_args, rsp):
elif key == 'jthreads' or key == 'jstopinfo':
key_value_pair[1] = binascii.unhexlify(key_value_pair[1])
key_value_pairs.insert(0, ['signal', signo])
- print 'stop_reply():'
+ print('stop_reply():')
dump_key_value_pairs(key_value_pairs)
elif stop_type == 'W':
exit_status = packet.get_hex_uint8()
- print 'stop_reply(): exit (status=%i)' % exit_status
+ print('stop_reply(): exit (status=%i)' % exit_status)
elif stop_type == 'O':
- print 'stop_reply(): stdout = "%s"' % packet.str
+ print('stop_reply(): stdout = "%s"' % packet.str)
def cmd_unknown_packet(options, cmd, args):
if args:
- print "cmd: %s, args: %s", cmd, args
+ print("cmd: %s, args: %s", cmd, args)
else:
- print "cmd: %s", cmd
+ print("cmd: %s", cmd)
return False
def cmd_qSymbol(options, cmd, args):
if args == ':':
- print 'ready to serve symbols'
+ print('ready to serve symbols')
else:
packet = Packet(args)
symbol_addr = packet.get_hex_uint('big')
if symbol_addr is None:
if packet.skip_exact_string(':'):
symbol_name = packet.get_hex_ascii_str()
- print 'lookup_symbol("%s") -> symbol not available yet' % (symbol_name)
+ print('lookup_symbol("%s") -> symbol not available yet' % (symbol_name))
else:
- print 'error: bad command format'
+ print('error: bad command format')
else:
if packet.skip_exact_string(':'):
symbol_name = packet.get_hex_ascii_str()
- print 'lookup_symbol("%s") -> 0x%x' % (symbol_name, symbol_addr)
+ print('lookup_symbol("%s") -> 0x%x' % (symbol_name, symbol_addr))
else:
- print 'error: bad command format'
+ print('error: bad command format')
def cmd_QSetWithHexString(options, cmd, args):
- print '%s("%s")' % (cmd[:-1], binascii.unhexlify(args))
+ print('%s("%s")' % (cmd[:-1], binascii.unhexlify(args)))
def cmd_QSetWithString(options, cmd, args):
- print '%s("%s")' % (cmd[:-1], args)
+ print('%s("%s")' % (cmd[:-1], args))
def cmd_QSetWithUnsigned(options, cmd, args):
- print '%s(%i)' % (cmd[:-1], int(args))
+ print('%s(%i)' % (cmd[:-1], int(args)))
def rsp_qSymbol(options, cmd, cmd_args, rsp):
if len(rsp) == 0:
- print "Unsupported"
+ print("Unsupported")
else:
if rsp == "OK":
- print "No more symbols to lookup"
+ print("No more symbols to lookup")
else:
packet = Packet(rsp)
if packet.skip_exact_string("qSymbol:"):
symbol_name = packet.get_hex_ascii_str()
- print 'lookup_symbol("%s")' % (symbol_name)
+ print('lookup_symbol("%s")' % (symbol_name))
else:
- print 'error: response string should start with "qSymbol:": respnse is "%s"' % (rsp)
+ print('error: response string should start with "qSymbol:": respnse is "%s"' % (rsp))
def cmd_qXfer(options, cmd, args):
# $qXfer:features:read:target.xml:0,1ffff#14
- print "read target special data %s" % (args)
+ print("read target special data %s" % (args))
return True
@@ -710,12 +710,12 @@ def rsp_qXfer(options, cmd, cmd_args, rsp):
reg_info.info[
'bitsize'] = reg_element.attrib['bitsize']
g_register_infos.append(reg_info)
- print 'XML for "%s":' % (data[2])
+ print('XML for "%s":' % (data[2]))
ET.dump(xml_root)
def cmd_A(options, cmd, args):
- print 'launch process:'
+ print('launch process:')
packet = Packet(args)
while True:
arg_len = packet.get_number()
@@ -729,50 +729,50 @@ def cmd_A(options, cmd, args):
if not packet.skip_exact_string(','):
break
arg_value = packet.get_hex_ascii_str(arg_len)
- print 'argv[%u] = "%s"' % (arg_idx, arg_value)
+ print('argv[%u] = "%s"' % (arg_idx, arg_value))
def cmd_qC(options, cmd, args):
- print "query_current_thread_id()"
+ print("query_current_thread_id()")
def rsp_qC(options, cmd, cmd_args, rsp):
packet = Packet(rsp)
if packet.skip_exact_string("QC"):
tid = packet.get_thread_id()
- print "current_thread_id = %#x" % (tid)
+ print("current_thread_id = %#x" % (tid))
else:
- print "current_thread_id = old thread ID"
+ print("current_thread_id = old thread ID")
def cmd_query_packet(options, cmd, args):
if args:
- print "%s%s" % (cmd, args)
+ print("%s%s" % (cmd, args))
else:
- print "%s" % (cmd)
+ print("%s" % (cmd))
return False
def rsp_ok_error(rsp):
- print "rsp: ", rsp
+ print("rsp: ", rsp)
def rsp_ok_means_supported(options, cmd, cmd_args, rsp):
if rsp == 'OK':
- print "%s%s is supported" % (cmd, cmd_args)
+ print("%s%s is supported" % (cmd, cmd_args))
elif rsp == '':
- print "%s%s is not supported" % (cmd, cmd_args)
+ print("%s%s is not supported" % (cmd, cmd_args))
else:
- print "%s%s -> %s" % (cmd, cmd_args, rsp)
+ print("%s%s -> %s" % (cmd, cmd_args, rsp))
def rsp_ok_means_success(options, cmd, cmd_args, rsp):
if rsp == 'OK':
- print "success"
+ print("success")
elif rsp == '':
- print "%s%s is not supported" % (cmd, cmd_args)
+ print("%s%s is not supported" % (cmd, cmd_args))
else:
- print "%s%s -> %s" % (cmd, cmd_args, rsp)
+ print("%s%s -> %s" % (cmd, cmd_args, rsp))
def dump_key_value_pairs(key_value_pairs):
@@ -786,42 +786,42 @@ def dump_key_value_pairs(key_value_pairs):
value = key_value_pair[1]
unhex_value = get_hex_string_if_all_printable(value)
if unhex_value:
- print "%*s = %s (%s)" % (max_key_len, key, value, unhex_value)
+ print("%*s = %s (%s)" % (max_key_len, key, value, unhex_value))
else:
- print "%*s = %s" % (max_key_len, key, value)
+ print("%*s = %s" % (max_key_len, key, value))
def rsp_dump_key_value_pairs(options, cmd, cmd_args, rsp):
if rsp:
- print '%s response:' % (cmd)
+ print('%s response:' % (cmd))
packet = Packet(rsp)
key_value_pairs = packet.get_key_value_pairs()
dump_key_value_pairs(key_value_pairs)
else:
- print "not supported"
+ print("not supported")
def cmd_c(options, cmd, args):
- print "continue()"
+ print("continue()")
return False
def cmd_s(options, cmd, args):
- print "step()"
+ print("step()")
return False
def cmd_qSpeedTest(options, cmd, args):
- print("qSpeedTest: cmd='%s', args='%s'" % (cmd, args))
+ print(("qSpeedTest: cmd='%s', args='%s'" % (cmd, args)))
def rsp_qSpeedTest(options, cmd, cmd_args, rsp):
- print("qSpeedTest: rsp='%s' cmd='%s', args='%s'" % (rsp, cmd, args))
+ print(("qSpeedTest: rsp='%s' cmd='%s', args='%s'" % (rsp, cmd, args)))
def cmd_vCont(options, cmd, args):
if args == '?':
- print "%s: get supported extended continue modes" % (cmd)
+ print("%s: get supported extended continue modes" % (cmd))
else:
got_other_threads = 0
s = ''
@@ -846,9 +846,9 @@ def cmd_vCont(options, cmd, args):
else:
s += 'thread 0x%4.4x: %s' % (tid, action)
if got_other_threads:
- print "extended_continue (%s)" % (s)
+ print("extended_continue (%s)" % (s))
else:
- print "extended_continue (%s, other-threads: suspend)" % (s)
+ print("extended_continue (%s, other-threads: suspend)" % (s))
return False
@@ -874,47 +874,47 @@ def rsp_vCont(options, cmd, cmd_args, rsp):
s += 'stop'
# else:
# s += 'unrecognized vCont mode: ', str(mode)
- print s
+ print(s)
elif rsp:
if rsp[0] == 'T' or rsp[0] == 'S' or rsp[0] == 'W' or rsp[0] == 'X':
rsp_stop_reply(options, cmd, cmd_args, rsp)
return
if rsp[0] == 'O':
- print "stdout: %s" % (rsp)
+ print("stdout: %s" % (rsp))
return
else:
- print "not supported (cmd = '%s', args = '%s', rsp = '%s')" % (cmd, cmd_args, rsp)
+ print("not supported (cmd = '%s', args = '%s', rsp = '%s')" % (cmd, cmd_args, rsp))
def cmd_vAttach(options, cmd, args):
(extra_command, args) = string.split(args, ';')
if extra_command:
- print "%s%s(%s)" % (cmd, extra_command, args)
+ print("%s%s(%s)" % (cmd, extra_command, args))
else:
- print "attach(pid = %u)" % int(args, 16)
+ print("attach(pid = %u)" % int(args, 16))
return False
def cmd_qRegisterInfo(options, cmd, args):
- print 'query_register_info(reg_num=%i)' % (int(args, 16))
+ print('query_register_info(reg_num=%i)' % (int(args, 16)))
return False
def rsp_qRegisterInfo(options, cmd, cmd_args, rsp):
global g_max_register_info_name_len
- print 'query_register_info(reg_num=%i):' % (int(cmd_args, 16)),
+ print('query_register_info(reg_num=%i):' % (int(cmd_args, 16)), end=' ')
if len(rsp) == 3 and rsp[0] == 'E':
g_max_register_info_name_len = 0
for reg_info in g_register_infos:
name_len = len(reg_info.name())
if g_max_register_info_name_len < name_len:
g_max_register_info_name_len = name_len
- print' DONE'
+ print(' DONE')
else:
packet = Packet(rsp)
reg_info = RegisterInfo(packet.get_key_value_pairs())
g_register_infos.append(reg_info)
- print reg_info
+ print(reg_info)
return False
@@ -923,7 +923,7 @@ def cmd_qThreadInfo(options, cmd, args):
query_type = 'first'
else:
query_type = 'subsequent'
- print 'get_current_thread_list(type=%s)' % (query_type)
+ print('get_current_thread_list(type=%s)' % (query_type))
return False
@@ -934,20 +934,20 @@ def rsp_qThreadInfo(options, cmd, cmd_args, rsp):
tids = packet.split_hex(';', 'big')
for i, tid in enumerate(tids):
if i:
- print ',',
- print '0x%x' % (tid),
- print
+ print(',', end=' ')
+ print('0x%x' % (tid), end=' ')
+ print()
elif response_type == 'l':
- print 'END'
+ print('END')
def rsp_hex_big_endian(options, cmd, cmd_args, rsp):
if rsp == '':
- print "%s%s is not supported" % (cmd, cmd_args)
+ print("%s%s is not supported" % (cmd, cmd_args))
else:
packet = Packet(rsp)
uval = packet.get_hex_uint('big')
- print '%s: 0x%x' % (cmd, uval)
+ print('%s: 0x%x' % (cmd, uval))
def cmd_read_mem_bin(options, cmd, args):
@@ -956,7 +956,7 @@ def cmd_read_mem_bin(options, cmd, args):
addr = packet.get_hex_uint('big')
comma = packet.get_char()
size = packet.get_hex_uint('big')
- print 'binary_read_memory (addr = 0x%16.16x, size = %u)' % (addr, size)
+ print('binary_read_memory (addr = 0x%16.16x, size = %u)' % (addr, size))
return False
@@ -965,7 +965,7 @@ def rsp_mem_bin_bytes(options, cmd, cmd_args, rsp):
addr = packet.get_hex_uint('big')
comma = packet.get_char()
size = packet.get_hex_uint('big')
- print 'memory:'
+ print('memory:')
if size > 0:
dump_hex_memory_buffer(addr, rsp)
@@ -975,7 +975,7 @@ def cmd_read_memory(options, cmd, args):
addr = packet.get_hex_uint('big')
comma = packet.get_char()
size = packet.get_hex_uint('big')
- print 'read_memory (addr = 0x%16.16x, size = %u)' % (addr, size)
+ print('read_memory (addr = 0x%16.16x, size = %u)' % (addr, size))
return False
@@ -987,10 +987,10 @@ def dump_hex_memory_buffer(addr, hex_byte_str):
while uval is not None:
if ((idx % 16) == 0):
if ascii:
- print ' ', ascii
+ print(' ', ascii)
ascii = ''
- print '0x%x:' % (addr + idx),
- print '%2.2x' % (uval),
+ print('0x%x:' % (addr + idx), end=' ')
+ print('%2.2x' % (uval), end=' ')
if 0x20 <= uval and uval < 0x7f:
ascii += '%c' % uval
else:
@@ -998,7 +998,7 @@ def dump_hex_memory_buffer(addr, hex_byte_str):
uval = packet.get_hex_uint8()
idx = idx + 1
if ascii:
- print ' ', ascii
+ print(' ', ascii)
ascii = ''
@@ -1006,13 +1006,13 @@ def cmd_write_memory(options, cmd, args):
packet = Packet(args)
addr = packet.get_hex_uint('big')
if packet.get_char() != ',':
- print 'error: invalid write memory command (missing comma after address)'
+ print('error: invalid write memory command (missing comma after address)')
return
size = packet.get_hex_uint('big')
if packet.get_char() != ':':
- print 'error: invalid write memory command (missing colon after size)'
+ print('error: invalid write memory command (missing colon after size)')
return
- print 'write_memory (addr = 0x%16.16x, size = %u, data:' % (addr, size)
+ print('write_memory (addr = 0x%16.16x, size = %u, data:' % (addr, size))
dump_hex_memory_buffer(addr, packet.str)
return False
@@ -1021,25 +1021,25 @@ def cmd_alloc_memory(options, cmd, args):
packet = Packet(args)
byte_size = packet.get_hex_uint('big')
if packet.get_char() != ',':
- print 'error: invalid allocate memory command (missing comma after address)'
+ print('error: invalid allocate memory command (missing comma after address)')
return
- print 'allocate_memory (byte-size = %u (0x%x), permissions = %s)' % (byte_size, byte_size, packet.str)
+ print('allocate_memory (byte-size = %u (0x%x), permissions = %s)' % (byte_size, byte_size, packet.str))
return False
def rsp_alloc_memory(options, cmd, cmd_args, rsp):
packet = Packet(rsp)
addr = packet.get_hex_uint('big')
- print 'addr = 0x%x' % addr
+ print('addr = 0x%x' % addr)
def cmd_dealloc_memory(options, cmd, args):
packet = Packet(args)
addr = packet.get_hex_uint('big')
if packet.get_char() != ',':
- print 'error: invalid allocate memory command (missing comma after address)'
+ print('error: invalid allocate memory command (missing comma after address)')
else:
- print 'deallocate_memory (addr = 0x%x, permissions = %s)' % (addr, packet.str)
+ print('deallocate_memory (addr = 0x%x, permissions = %s)' % (addr, packet.str))
return False
@@ -1085,21 +1085,21 @@ def cmd_read_one_reg(options, cmd, args):
if tid is not None:
s += ', tid = 0x%4.4x' % (tid)
s += ')'
- print s
+ print(s)
return False
def rsp_read_one_reg(options, cmd, cmd_args, rsp):
packet = Packet(cmd_args)
reg_num = packet.get_hex_uint('big')
- print get_register_name_equal_value(options, reg_num, rsp)
+ print(get_register_name_equal_value(options, reg_num, rsp))
def cmd_write_one_reg(options, cmd, args):
packet = Packet(args)
reg_num = packet.get_hex_uint('big')
if packet.get_char() != '=':
- print 'error: invalid register write packet'
+ print('error: invalid register write packet')
else:
name = None
hex_value_str = packet.get_hex_chars()
@@ -1112,7 +1112,7 @@ def cmd_write_one_reg(options, cmd, args):
if tid is not None:
s += ', tid = 0x%4.4x' % (tid)
s += ')'
- print s
+ print(s)
return False
@@ -1122,7 +1122,7 @@ def dump_all_regs(packet):
hex_value_str = packet.get_hex_chars(nibble_size)
if hex_value_str is not None:
value = reg_info.get_value_from_hex_string(hex_value_str)
- print '%*s = %s' % (g_max_register_info_name_len, reg_info.name(), value)
+ print('%*s = %s' % (g_max_register_info_name_len, reg_info.name(), value))
else:
return
@@ -1132,9 +1132,9 @@ def cmd_read_all_regs(cmd, cmd_args):
packet.get_char() # toss the 'g' command character
tid = get_thread_from_thread_suffix(packet.str)
if tid is not None:
- print 'read_all_register(thread = 0x%4.4x)' % tid
+ print('read_all_register(thread = 0x%4.4x)' % tid)
else:
- print 'read_all_register()'
+ print('read_all_register()')
return False
@@ -1145,7 +1145,7 @@ def rsp_read_all_regs(options, cmd, cmd_args, rsp):
def cmd_write_all_regs(options, cmd, args):
packet = Packet(args)
- print 'write_all_registers()'
+ print('write_all_registers()')
dump_all_regs(packet)
return False
@@ -1165,7 +1165,7 @@ def cmd_bp(options, cmd, args):
bp_size = packet.get_hex_uint('big')
s += g_bp_types[bp_type]
s += " (addr = 0x%x, size = %u)" % (bp_addr, bp_size)
- print s
+ print(s)
return False
@@ -1173,22 +1173,22 @@ def cmd_mem_rgn_info(options, cmd, args):
packet = Packet(args)
packet.get_char() # skip ':' character
addr = packet.get_hex_uint('big')
- print 'get_memory_region_info (addr=0x%x)' % (addr)
+ print('get_memory_region_info (addr=0x%x)' % (addr))
return False
def cmd_kill(options, cmd, args):
- print 'kill_process()'
+ print('kill_process()')
return False
def cmd_jThreadsInfo(options, cmd, args):
- print 'jThreadsInfo()'
+ print('jThreadsInfo()')
return False
def cmd_jGetLoadedDynamicLibrariesInfos(options, cmd, args):
- print 'jGetLoadedDynamicLibrariesInfos()'
+ print('jGetLoadedDynamicLibrariesInfos()')
return False
@@ -1210,9 +1210,9 @@ def decode_packet(s, start_index=0):
def rsp_json(options, cmd, cmd_args, rsp):
- print '%s() reply:' % (cmd)
+ print('%s() reply:' % (cmd))
json_tree = json.loads(rsp)
- print json.dumps(json_tree, indent=4, separators=(',', ': '))
+ print(json.dumps(json_tree, indent=4, separators=(',', ': ')))
def rsp_jGetLoadedDynamicLibrariesInfos(options, cmd, cmd_args, rsp):
@@ -1387,26 +1387,26 @@ def parse_gdb_log(file, options):
packet = m.group('packet')
sys.stdout.write(options.colors.green())
if not options.quiet and not hide_next_response:
- print '# ', line
+ print('# ', line)
sys.stdout.write(options.colors.reset())
# print 'direction = "%s", packet = "%s"' % (direction, packet)
if packet[0] == '+':
if is_command:
- print '-->',
+ print('-->', end=' ')
else:
- print '<--',
+ print('<--', end=' ')
if not options.quiet:
- print 'ACK'
+ print('ACK')
continue
elif packet[0] == '-':
if is_command:
- print '-->',
+ print('-->', end=' ')
else:
- print '<--',
+ print('<--', end=' ')
if not options.quiet:
- print 'NACK'
+ print('NACK')
continue
elif packet[0] == '$':
m = packet_contents_name_regex.match(packet)
@@ -1415,7 +1415,7 @@ def parse_gdb_log(file, options):
idx = line_index + 1
while idx < num_lines:
if not options.quiet and not hide_next_response:
- print '# ', lines[idx]
+ print('# ', lines[idx])
multiline_packet += lines[idx]
m = packet_contents_name_regex.match(multiline_packet)
if m:
@@ -1426,9 +1426,9 @@ def parse_gdb_log(file, options):
idx += 1
if m:
if is_command:
- print '-->',
+ print('-->', end=' ')
else:
- print '<--',
+ print('<--', end=' ')
contents = decode_packet(m.group(1))
if is_command:
hide_next_response = False
@@ -1458,11 +1458,11 @@ def parse_gdb_log(file, options):
gdb_remote_commands[last_command]['rsp'](
options, last_command, last_command_args, contents)
else:
- print 'error: invalid packet: "', packet, '"'
+ print('error: invalid packet: "', packet, '"')
else:
- print '???'
+ print('???')
else:
- print '## ', line
+ print('## ', line)
match = timestamp_regex.match(line)
if match:
curr_time = float(match.group(2))
@@ -1491,16 +1491,16 @@ def parse_gdb_log(file, options):
min_time = delta
if not options or not options.quiet:
- print '%s%.6f %+.6f%s' % (match.group(1),
+ print('%s%.6f %+.6f%s' % (match.group(1),
curr_time - base_time,
delta,
- match.group(3))
+ match.group(3)))
last_time = curr_time
# else:
# print line
(average, std_dev) = calculate_mean_and_standard_deviation(all_packet_times)
if average and std_dev:
- print '%u packets with average packet time of %f and standard deviation of %f' % (len(all_packet_times), average, std_dev)
+ print('%u packets with average packet time of %f and standard deviation of %f' % (len(all_packet_times), average, std_dev))
if packet_total_times:
total_packet_time = 0.0
total_packet_count = 0
@@ -1512,14 +1512,14 @@ def parse_gdb_log(file, options):
for key, vvv in packet_counts.items():
total_packet_count += vvv
- print '#------------------------------------------------------------'
- print '# Packet timing summary:'
- print '# Totals: time = %6f, count = %6d' % (total_packet_time,
- total_packet_count)
- print '# Min packet time: time = %6f' % (min_time)
- print '#------------------------------------------------------------'
- print '# Packet Time (sec) Percent Count Latency'
- print '#------------------------- ----------- ------- ------ -------'
+ print('#------------------------------------------------------------')
+ print('# Packet timing summary:')
+ print('# Totals: time = %6f, count = %6d' % (total_packet_time,
+ total_packet_count))
+ print('# Min packet time: time = %6f' % (min_time))
+ print('#------------------------------------------------------------')
+ print('# Packet Time (sec) Percent Count Latency')
+ print('#------------------------- ----------- ------- ------ -------')
if options and options.sort_count:
res = sorted(
packet_counts,
@@ -1537,9 +1537,9 @@ def parse_gdb_log(file, options):
packet_percent = (
packet_total_time / total_packet_time) * 100.0
packet_count = packet_counts[item]
- print " %24s %11.6f %5.2f%% %6d %9.6f" % (
+ print(" %24s %11.6f %5.2f%% %6d %9.6f" % (
item, packet_total_time, packet_percent, packet_count,
- float(packet_total_time) / float(packet_count))
+ float(packet_total_time) / float(packet_count)))
if options.plot:
plot_latencies(packet_times)
@@ -1593,7 +1593,7 @@ if __name__ == '__main__':
try:
(options, args) = parser.parse_args(sys.argv[1:])
except:
- print 'error: argument error'
+ print('error: argument error')
sys.exit(1)
options.colors = TerminalColors(options.color)
@@ -1603,18 +1603,18 @@ if __name__ == '__main__':
lldb.debugger = lldb.SBDebugger.Create()
import lldb.macosx.crashlog
options.symbolicator = lldb.macosx.crashlog.CrashLog(options.crashlog)
- print '%s' % (options.symbolicator)
+ print('%s' % (options.symbolicator))
# This script is being run from the command line, create a debugger in case we are
# going to use any debugger functions in our function.
if len(args):
for file in args:
- print '#----------------------------------------------------------------------'
- print "# GDB remote log file: '%s'" % file
- print '#----------------------------------------------------------------------'
+ print('#----------------------------------------------------------------------')
+ print("# GDB remote log file: '%s'" % file)
+ print('#----------------------------------------------------------------------')
parse_gdb_log_file(file, options)
if options.symbolicator:
- print '%s' % (options.symbolicator)
+ print('%s' % (options.symbolicator))
else:
parse_gdb_log(sys.stdin, options)
@@ -1627,4 +1627,4 @@ else:
'command script add -f gdbremote.start_gdb_log start_gdb_log')
lldb.debugger.HandleCommand(
'command script add -f gdbremote.stop_gdb_log stop_gdb_log')
- print 'The "start_gdb_log" and "stop_gdb_log" commands are now installed and ready for use, type "start_gdb_log --help" or "stop_gdb_log --help" for more information'
+ print('The "start_gdb_log" and "stop_gdb_log" commands are now installed and ready for use, type "start_gdb_log --help" or "stop_gdb_log --help" for more information')
diff --git a/lldb/examples/python/globals.py b/lldb/examples/python/globals.py
index 43bd915b393..1b18ed42dcb 100755
--- a/lldb/examples/python/globals.py
+++ b/lldb/examples/python/globals.py
@@ -7,6 +7,7 @@
# For the shells sh, bash:
# PYTHONPATH=/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Resources/Python ./globals.py <path> [<path> ...]
#----------------------------------------------------------------------
+from __future__ import print_function
import lldb
import commands
@@ -46,22 +47,22 @@ def get_globals(raw_path, options):
# Print results for anything that matched
for global_variable in global_variable_list:
# returns the global variable name as a string
- print 'name = %s' % global_variable.name
+ print('name = %s' % global_variable.name)
# Returns the variable value as a string
- print 'value = %s' % global_variable.value
- print 'type = %s' % global_variable.type # Returns an lldb.SBType object
+ print('value = %s' % global_variable.value)
+ print('type = %s' % global_variable.type) # Returns an lldb.SBType object
# Returns an lldb.SBAddress (section offset
# address) for this global
- print 'addr = %s' % global_variable.addr
+ print('addr = %s' % global_variable.addr)
# Returns the file virtual address for this
# global
- print 'file_addr = 0x%x' % global_variable.addr.file_addr
+ print('file_addr = 0x%x' % global_variable.addr.file_addr)
# returns the global variable value as a string
- print 'location = %s' % global_variable.location
+ print('location = %s' % global_variable.location)
# Returns the size in bytes of this global
# variable
- print 'size = %s' % global_variable.size
- print
+ print('size = %s' % global_variable.size)
+ print()
def globals(command_args):
diff --git a/lldb/examples/python/jump.py b/lldb/examples/python/jump.py
index e33a6a6f369..dc4cc48b144 100644
--- a/lldb/examples/python/jump.py
+++ b/lldb/examples/python/jump.py
@@ -1,3 +1,5 @@
+from __future__ import print_function
+
import lldb
import re
@@ -193,4 +195,4 @@ if lldb.debugger:
# Module is being run inside the LLDB interpreter
jump.__doc__ = usage_string()
lldb.debugger.HandleCommand('command script add -f jump.jump jump')
- print 'The "jump" command has been installed, type "help jump" or "jump <ENTER>" for detailed help.'
+ print('The "jump" command has been installed, type "help jump" or "jump <ENTER>" for detailed help.')
diff --git a/lldb/examples/python/lldb_module_utils.py b/lldb/examples/python/lldb_module_utils.py
index 006f232681f..2b2fea9d4f1 100644
--- a/lldb/examples/python/lldb_module_utils.py
+++ b/lldb/examples/python/lldb_module_utils.py
@@ -1,4 +1,5 @@
#!/usr/bin/python
+from __future__ import print_function
import lldb
import optparse
@@ -61,14 +62,14 @@ class DumpLineTables:
result.SetError('no module found that matches "%s".' % (module_path))
return
num_cus = module.GetNumCompileUnits()
- print >>result, 'Module: "%s"' % (module.file.fullpath),
+ print('Module: "%s"' % (module.file.fullpath), end=' ', file=result)
if num_cus == 0:
- print >>result, 'no debug info.'
+ print('no debug info.', file=result)
continue
- print >>result, 'has %u compile units:' % (num_cus)
+ print('has %u compile units:' % (num_cus), file=result)
for cu_idx in range(num_cus):
cu = module.GetCompileUnitAtIndex(cu_idx)
- print >>result, ' Compile Unit: %s' % (cu.file.fullpath)
+ print(' Compile Unit: %s' % (cu.file.fullpath), file=result)
for line_idx in range(cu.GetNumLineEntries()):
line_entry = cu.GetLineEntryAtIndex(line_idx)
start_file_addr = line_entry.addr.file_addr
@@ -163,19 +164,19 @@ path when setting breakpoints.
result.SetError('no module found that matches "%s".' % (module_path))
return
num_cus = module.GetNumCompileUnits()
- print >>result, 'Module: "%s"' % (module.file.fullpath),
+ print('Module: "%s"' % (module.file.fullpath), end=' ', file=result)
if num_cus == 0:
- print >>result, 'no debug info.'
+ print('no debug info.', file=result)
continue
- print >>result, 'has %u compile units:' % (num_cus)
+ print('has %u compile units:' % (num_cus), file=result)
for i in range(num_cus):
cu = module.GetCompileUnitAtIndex(i)
- print >>result, ' Compile Unit: %s' % (cu.file.fullpath)
+ print(' Compile Unit: %s' % (cu.file.fullpath), file=result)
if options.support_files:
num_support_files = cu.GetNumSupportFiles()
for j in range(num_support_files):
path = cu.GetSupportFileAtIndex(j).fullpath
- print >>result, ' file[%u]: %s' % (j, path)
+ print(' file[%u]: %s' % (j, path), file=result)
def __lldb_init_module(debugger, dict):
@@ -187,5 +188,5 @@ def __lldb_init_module(debugger, dict):
DumpLineTables.command_name))
debugger.HandleCommand(
'command script add -c %s.DumpFiles %s' % (__name__, DumpFiles.command_name))
- print 'The "%s" and "%s" commands have been installed.' % (DumpLineTables.command_name,
- DumpFiles.command_name)
+ print('The "%s" and "%s" commands have been installed.' % (DumpLineTables.command_name,
+ DumpFiles.command_name))
diff --git a/lldb/examples/python/lldbtk.py b/lldb/examples/python/lldbtk.py
index a978b9e0703..cac969e665e 100644
--- a/lldb/examples/python/lldbtk.py
+++ b/lldb/examples/python/lldbtk.py
@@ -539,19 +539,19 @@ def tk_variable_display(debugger, command, result, dict):
sys.argv = ['tk-variables']
target = debugger.GetSelectedTarget()
if not target:
- print >>result, "invalid target"
+ print("invalid target", file=result)
return
process = target.GetProcess()
if not process:
- print >>result, "invalid process"
+ print("invalid process", file=result)
return
thread = process.GetSelectedThread()
if not thread:
- print >>result, "invalid thread"
+ print("invalid thread", file=result)
return
frame = thread.GetSelectedFrame()
if not frame:
- print >>result, "invalid frame"
+ print("invalid frame", file=result)
return
# Parse command line args
command_args = shlex.split(command)
@@ -573,11 +573,11 @@ def tk_process_display(debugger, command, result, dict):
sys.argv = ['tk-process']
target = debugger.GetSelectedTarget()
if not target:
- print >>result, "invalid target"
+ print("invalid target", file=result)
return
process = target.GetProcess()
if not process:
- print >>result, "invalid process"
+ print("invalid process", file=result)
return
# Parse command line args
columnd_dicts = [{'id': '#0', 'text': 'Name', 'anchor': W, 'stretch': 0},
@@ -598,7 +598,7 @@ def tk_target_display(debugger, command, result, dict):
sys.argv = ['tk-target']
target = debugger.GetSelectedTarget()
if not target:
- print >>result, "invalid target"
+ print("invalid target", file=result)
return
# Parse command line args
columnd_dicts = [{'id': '#0', 'text': 'Name', 'anchor': W, 'stretch': 0},
diff --git a/lldb/examples/python/mach_o.py b/lldb/examples/python/mach_o.py
index faa05ac8307..0f36a8bc330 100755
--- a/lldb/examples/python/mach_o.py
+++ b/lldb/examples/python/mach_o.py
@@ -1,4 +1,5 @@
#!/usr/bin/python
+from __future__ import print_function
import cmd
import dict_utils
@@ -187,11 +188,11 @@ def dump_memory(base_addr, data, hex_bytes_len, num_per_line):
while i < hex_bytes_len:
if ((i / 2) % num_per_line) == 0:
if i > 0:
- print ' %s' % (ascii_str)
+ print(' %s' % (ascii_str))
ascii_str = ''
- print '0x%8.8x:' % (addr + i),
+ print('0x%8.8x:' % (addr + i), end=' ')
hex_byte = hex_bytes[i:i + 2]
- print hex_byte,
+ print(hex_byte, end=' ')
int_byte = int(hex_byte, 16)
ascii_char = '%c' % (int_byte)
if int_byte >= 32 and int_byte < 127:
@@ -204,8 +205,8 @@ def dump_memory(base_addr, data, hex_bytes_len, num_per_line):
padding = num_per_line - ((i / 2) % num_per_line)
else:
padding = 0
- print '%*s%s' % (padding * 3 + 1, '', ascii_str)
- print
+ print('%*s%s' % (padding * 3 + 1, '', ascii_str))
+ print()
class TerminalColors:
@@ -371,11 +372,11 @@ def dump_hex_bytes(addr, s, bytes_per_line=16):
for ch in s:
if (i % bytes_per_line) == 0:
if line:
- print line
+ print(line)
line = '%#8.8x: ' % (addr + i)
line += "%02X " % ord(ch)
i += 1
- print line
+ print(line)
def dump_hex_byte_string_diff(addr, a, b, bytes_per_line=16):
@@ -404,7 +405,7 @@ def dump_hex_byte_string_diff(addr, a, b, bytes_per_line=16):
mismatch = ch_a != ch_b
if (i % bytes_per_line) == 0:
if line:
- print line
+ print(line)
line = '%#8.8x: ' % (addr + i)
if mismatch:
line += tty_colors.red()
@@ -413,7 +414,7 @@ def dump_hex_byte_string_diff(addr, a, b, bytes_per_line=16):
line += tty_colors.default()
i += 1
- print line
+ print(line)
class Mach:
@@ -533,11 +534,11 @@ class Mach:
# f.close()
except IOError as xxx_todo_changeme:
(errno, strerror) = xxx_todo_changeme.args
- print "I/O error({0}): {1}".format(errno, strerror)
+ print("I/O error({0}): {1}".format(errno, strerror))
except ValueError:
- print "Could not convert data to an integer."
+ print("Could not convert data to an integer.")
except:
- print "Unexpected error:", sys.exc_info()[0]
+ print("Unexpected error:", sys.exc_info()[0])
raise
def compare(self, rhs):
@@ -625,56 +626,56 @@ class Mach:
self.archs[i].mach.unpack(data, skinny_magic)
def compare(self, rhs):
- print 'error: comparing two universal files is not supported yet'
+ print('error: comparing two universal files is not supported yet')
return False
def dump(self, options):
if options.dump_header:
- print
- print "Universal Mach File: magic = %s, nfat_arch = %u" % (self.magic, self.nfat_arch)
- print
+ print()
+ print("Universal Mach File: magic = %s, nfat_arch = %u" % (self.magic, self.nfat_arch))
+ print()
if self.nfat_arch > 0:
if options.dump_header:
self.archs[0].dump_header(True, options)
for i in range(self.nfat_arch):
self.archs[i].dump_flat(options)
if options.dump_header:
- print
+ print()
for i in range(self.nfat_arch):
self.archs[i].mach.dump(options)
def dump_header(self, dump_description=True, options=None):
if dump_description:
- print self.description()
+ print(self.description())
for i in range(self.nfat_arch):
self.archs[i].mach.dump_header(True, options)
- print
+ print()
def dump_load_commands(self, dump_description=True, options=None):
if dump_description:
- print self.description()
+ print(self.description())
for i in range(self.nfat_arch):
self.archs[i].mach.dump_load_commands(True, options)
- print
+ print()
def dump_sections(self, dump_description=True, options=None):
if dump_description:
- print self.description()
+ print(self.description())
for i in range(self.nfat_arch):
self.archs[i].mach.dump_sections(True, options)
- print
+ print()
def dump_section_contents(self, options):
for i in range(self.nfat_arch):
self.archs[i].mach.dump_section_contents(options)
- print
+ print()
def dump_symtab(self, dump_description=True, options=None):
if dump_description:
- print self.description()
+ print(self.description())
for i in range(self.nfat_arch):
self.archs[i].mach.dump_symtab(True, options)
- print
+ print()
def dump_symbol_names_matching_regex(self, regex, file=None):
for i in range(self.nfat_arch):
@@ -698,24 +699,24 @@ class Mach:
def dump_header(self, dump_description=True, options=None):
if options.verbose:
- print "CPU SUBTYPE OFFSET SIZE ALIGN"
- print "---------- ---------- ---------- ---------- ----------"
+ print("CPU SUBTYPE OFFSET SIZE ALIGN")
+ print("---------- ---------- ---------- ---------- ----------")
else:
- print "ARCH FILEOFFSET FILESIZE ALIGN"
- print "---------- ---------- ---------- ----------"
+ print("ARCH FILEOFFSET FILESIZE ALIGN")
+ print("---------- ---------- ---------- ----------")
def dump_flat(self, options):
if options.verbose:
- print "%#8.8x %#8.8x %#8.8x %#8.8x %#8.8x" % (self.arch.cpu, self.arch.sub, self.offset, self.size, self.align)
+ print("%#8.8x %#8.8x %#8.8x %#8.8x %#8.8x" % (self.arch.cpu, self.arch.sub, self.offset, self.size, self.align))
else:
- print "%-10s %#8.8x %#8.8x %#8.8x" % (self.arch, self.offset, self.size, self.align)
+ print("%-10s %#8.8x %#8.8x %#8.8x" % (self.arch, self.offset, self.size, self.align))
def dump(self):
- print " cputype: %#8.8x" % self.arch.cpu
- print "cpusubtype: %#8.8x" % self.arch.sub
- print " offset: %#8.8x" % self.offset
- print " size: %#8.8x" % self.size
- print " align: %#8.8x" % self.align
+ print(" cputype: %#8.8x" % self.arch.cpu)
+ print("cpusubtype: %#8.8x" % self.arch.sub)
+ print(" offset: %#8.8x" % self.offset)
+ print(" size: %#8.8x" % self.size)
+ print(" align: %#8.8x" % self.align)
def __str__(self):
return "Mach.Universal.ArchInfo: %#8.8x %#8.8x %#8.8x %#8.8x %#8.8x" % (
@@ -906,21 +907,21 @@ class Mach:
return lc
def compare(self, rhs):
- print "\nComparing:"
- print "a) %s %s" % (self.arch, self.path)
- print "b) %s %s" % (rhs.arch, rhs.path)
+ print("\nComparing:")
+ print("a) %s %s" % (self.arch, self.path))
+ print("b) %s %s" % (rhs.arch, rhs.path))
result = True
if self.type == rhs.type:
for lhs_section in self.sections[1:]:
rhs_section = rhs.get_section_by_section(lhs_section)
if rhs_section:
- print 'comparing %s.%s...' % (lhs_section.segname, lhs_section.sectname),
+ print('comparing %s.%s...' % (lhs_section.segname, lhs_section.sectname), end=' ')
sys.stdout.flush()
lhs_data = lhs_section.get_contents(self)
rhs_data = rhs_section.get_contents(rhs)
if lhs_data and rhs_data:
if lhs_data == rhs_data:
- print 'ok'
+ print('ok')
else:
lhs_data_len = len(lhs_data)
rhs_data_len = len(rhs_data)
@@ -938,51 +939,51 @@ class Mach:
# result = False
# else:
result = False
- print 'error: sections differ'
+ print('error: sections differ')
# print 'a) %s' % (lhs_section)
# dump_hex_byte_string_diff(0, lhs_data, rhs_data)
# print 'b) %s' % (rhs_section)
# dump_hex_byte_string_diff(0, rhs_data, lhs_data)
elif lhs_data and not rhs_data:
- print 'error: section data missing from b:'
- print 'a) %s' % (lhs_section)
- print 'b) %s' % (rhs_section)
+ print('error: section data missing from b:')
+ print('a) %s' % (lhs_section))
+ print('b) %s' % (rhs_section))
result = False
elif not lhs_data and rhs_data:
- print 'error: section data missing from a:'
- print 'a) %s' % (lhs_section)
- print 'b) %s' % (rhs_section)
+ print('error: section data missing from a:')
+ print('a) %s' % (lhs_section))
+ print('b) %s' % (rhs_section))
result = False
elif lhs_section.offset or rhs_section.offset:
- print 'error: section data missing for both a and b:'
- print 'a) %s' % (lhs_section)
- print 'b) %s' % (rhs_section)
+ print('error: section data missing for both a and b:')
+ print('a) %s' % (lhs_section))
+ print('b) %s' % (rhs_section))
result = False
else:
- print 'ok'
+ print('ok')
else:
result = False
- print 'error: section %s is missing in %s' % (lhs_section.sectname, rhs.path)
+ print('error: section %s is missing in %s' % (lhs_section.sectname, rhs.path))
else:
- print 'error: comaparing a %s mach-o file with a %s mach-o file is not supported' % (self.type, rhs.type)
+ print('error: comaparing a %s mach-o file with a %s mach-o file is not supported' % (self.type, rhs.type))
result = False
if not result:
- print 'error: mach files differ'
+ print('error: mach files differ')
return result
def dump_header(self, dump_description=True, options=None):
if options.verbose:
- print "MAGIC CPU SUBTYPE FILETYPE NUM CMDS SIZE CMDS FLAGS"
- print "---------- ---------- ---------- ---------- -------- ---------- ----------"
+ print("MAGIC CPU SUBTYPE FILETYPE NUM CMDS SIZE CMDS FLAGS")
+ print("---------- ---------- ---------- ---------- -------- ---------- ----------")
else:
- print "MAGIC ARCH FILETYPE NUM CMDS SIZE CMDS FLAGS"
- print "------------ ---------- -------------- -------- ---------- ----------"
+ print("MAGIC ARCH FILETYPE NUM CMDS SIZE CMDS FLAGS")
+ print("------------ ---------- -------------- -------- ---------- ----------")
def dump_flat(self, options):
if options.verbose:
- print "%#8.8x %#8.8x %#8.8x %#8.8x %#8u %#8.8x %#8.8x" % (self.magic, self.arch.cpu, self.arch.sub, self.filetype.value, self.ncmds, self.sizeofcmds, self.flags.bits)
+ print("%#8.8x %#8.8x %#8.8x %#8.8x %#8u %#8.8x %#8.8x" % (self.magic, self.arch.cpu, self.arch.sub, self.filetype.value, self.ncmds, self.sizeofcmds, self.flags.bits))
else:
- print "%-12s %-10s %-14s %#8u %#8.8x %s" % (self.magic, self.arch, self.filetype, self.ncmds, self.sizeofcmds, self.flags)
+ print("%-12s %-10s %-14s %#8u %#8.8x %s" % (self.magic, self.arch, self.filetype, self.ncmds, self.sizeofcmds, self.flags))
def dump(self, options):
if options.dump_header:
@@ -998,27 +999,27 @@ class Mach:
if len(self.symbols):
self.dump_sections(False, options)
else:
- print "No symbols"
+ print("No symbols")
if options.find_mangled:
self.dump_symbol_names_matching_regex(re.compile('^_?_Z'))
def dump_header(self, dump_description=True, options=None):
if dump_description:
- print self.description()
- print "Mach Header"
- print " magic: %#8.8x %s" % (self.magic.value, self.magic)
- print " cputype: %#8.8x %s" % (self.arch.cpu, self.arch)
- print " cpusubtype: %#8.8x" % self.arch.sub
- print " filetype: %#8.8x %s" % (self.filetype.get_enum_value(), self.filetype.get_enum_name())
- print " ncmds: %#8.8x %u" % (self.ncmds, self.ncmds)
- print " sizeofcmds: %#8.8x" % self.sizeofcmds
- print " flags: %#8.8x %s" % (self.flags.bits, self.flags)
+ print(self.description())
+ print("Mach Header")
+ print(" magic: %#8.8x %s" % (self.magic.value, self.magic))
+ print(" cputype: %#8.8x %s" % (self.arch.cpu, self.arch))
+ print(" cpusubtype: %#8.8x" % self.arch.sub)
+ print(" filetype: %#8.8x %s" % (self.filetype.get_enum_value(), self.filetype.get_enum_name()))
+ print(" ncmds: %#8.8x %u" % (self.ncmds, self.ncmds))
+ print(" sizeofcmds: %#8.8x" % self.sizeofcmds)
+ print(" flags: %#8.8x %s" % (self.flags.bits, self.flags))
def dump_load_commands(self, dump_description=True, options=None):
if dump_description:
- print self.description()
+ print(self.description())
for lc in self.commands:
- print lc
+ print(lc)
def get_section_by_name(self, name):
for section in self.sections:
@@ -1034,12 +1035,12 @@ class Mach:
def dump_sections(self, dump_description=True, options=None):
if dump_description:
- print self.description()
+ print(self.description())
num_sections = len(self.sections)
if num_sections > 1:
self.sections[1].dump_header()
for sect_idx in range(1, num_sections):
- print "%s" % self.sections[sect_idx]
+ print("%s" % self.sections[sect_idx])
def dump_section_contents(self, options):
saved_section_to_disk = False
@@ -1075,19 +1076,19 @@ class Mach:
data.seek(data_offset)
outfile.write(data.read_size(data_size))
else:
- print "Saving section %s to '%s'" % (sectname, options.outfile)
+ print("Saving section %s to '%s'" % (sectname, options.outfile))
outfile.write(sect_bytes)
outfile.close()
saved_section_to_disk = True
else:
- print "error: you can only save a single section to disk at a time, skipping section '%s'" % (sectname)
+ print("error: you can only save a single section to disk at a time, skipping section '%s'" % (sectname))
else:
- print 'section %s:\n' % (sectname)
+ print('section %s:\n' % (sectname))
section.dump_header()
- print '%s\n' % (section)
+ print('%s\n' % (section))
dump_memory(0, sect_bytes, options.max_count, 16)
else:
- print 'error: no section named "%s" was found' % (sectname)
+ print('error: no section named "%s" was found' % (sectname))
def get_segment(self, segname):
if len(self.segments) == 1 and self.segments[0].segname == '':
@@ -1125,20 +1126,20 @@ class Mach:
nlist.unpack(self, self.data, lc_symtab)
self.symbols.append(nlist)
else:
- print "no LC_SYMTAB"
+ print("no LC_SYMTAB")
def dump_symtab(self, dump_description=True, options=None):
self.get_symtab()
if dump_description:
- print self.description()
+ print(self.description())
for i, symbol in enumerate(self.symbols):
- print '[%5u] %s' % (i, symbol)
+ print('[%5u] %s' % (i, symbol))
def dump_symbol_names_matching_regex(self, regex, file=None):
self.get_symtab()
for symbol in self.symbols:
if symbol.name and regex.search(symbol.name):
- print symbol.name
+ print(symbol.name)
if file:
file.write('%s\n' % (symbol.name))
@@ -1247,11 +1248,11 @@ class Mach:
def dump_header(self):
if self.is_64:
- print "INDEX ADDRESS SIZE OFFSET ALIGN RELOFF NRELOC FLAGS RESERVED1 RESERVED2 RESERVED3 NAME"
- print "===== ------------------ ------------------ ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------------------"
+ print("INDEX ADDRESS SIZE OFFSET ALIGN RELOFF NRELOC FLAGS RESERVED1 RESERVED2 RESERVED3 NAME")
+ print("===== ------------------ ------------------ ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------------------")
else:
- print "INDEX ADDRESS SIZE OFFSET ALIGN RELOFF NRELOC FLAGS RESERVED1 RESERVED2 NAME"
- print "===== ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------------------"
+ print("INDEX ADDRESS SIZE OFFSET ALIGN RELOFF NRELOC FLAGS RESERVED1 RESERVED2 NAME")
+ print("===== ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------------------")
def __str__(self):
if self.is_64:
@@ -1682,7 +1683,7 @@ class Mach:
def default(self, line):
'''Catch all for unknown command, which will exit the interpreter.'''
- print "uknown command: %s" % line
+ print("uknown command: %s" % line)
return True
def do_q(self, line):
@@ -1813,10 +1814,10 @@ if __name__ == '__main__':
(options, mach_files) = parser.parse_args()
if options.extract_modules:
if options.section_names:
- print "error: can't use --section option with the --extract-modules option"
+ print("error: can't use --section option with the --extract-modules option")
exit(1)
if not options.outfile:
- print "error: the --output=FILE option must be specified with the --extract-modules option"
+ print("error: the --output=FILE option must be specified with the --extract-modules option")
exit(1)
options.section_names.append("__apple_ast")
if options.compare:
@@ -1827,14 +1828,14 @@ if __name__ == '__main__':
mach_b.parse(mach_files[1])
mach_a.compare(mach_b)
else:
- print 'error: --compare takes two mach files as arguments'
+ print('error: --compare takes two mach files as arguments')
else:
if not (options.dump_header or options.dump_load_commands or options.dump_symtab or options.dump_sections or options.find_mangled or options.section_names):
options.dump_header = True
options.dump_load_commands = True
if options.verbose:
- print 'options', options
- print 'mach_files', mach_files
+ print('options', options)
+ print('mach_files', mach_files)
for path in mach_files:
mach = Mach()
mach.parse(path)
diff --git a/lldb/examples/python/memory.py b/lldb/examples/python/memory.py
index 5e2f636dc3e..cdc89fc811d 100755
--- a/lldb/examples/python/memory.py
+++ b/lldb/examples/python/memory.py
@@ -10,6 +10,8 @@
#----------------------------------------------------------------------
import commands
+from __future__ import print_function
+
import platform
import os
import re
@@ -44,11 +46,11 @@ except ImportError:
except ImportError:
pass
else:
- print 'imported lldb from: "%s"' % (lldb_python_dir)
+ print('imported lldb from: "%s"' % (lldb_python_dir))
success = True
break
if not success:
- print "error: couldn't locate the 'lldb' module, please set PYTHONPATH correctly"
+ print("error: couldn't locate the 'lldb' module, please set PYTHONPATH correctly")
sys.exit(1)
import commands
@@ -197,9 +199,9 @@ def memfind_command(debugger, command, result, dict):
def print_error(str, show_usage, result):
- print >>result, str
+ print(str, file=result)
if show_usage:
- print >>result, create_memfind_options().format_help()
+ print(create_memfind_options().format_help(), file=result)
def memfind(target, options, args, result):
@@ -233,44 +235,44 @@ def memfind(target, options, args, result):
return
if not options.data:
- print >>result, 'error: no data specified to search for'
+ print('error: no data specified to search for', file=result)
return
if not target:
- print >>result, 'error: invalid target'
+ print('error: invalid target', file=result)
return
process = target.process
if not process:
- print >>result, 'error: invalid process'
+ print('error: invalid process', file=result)
return
error = lldb.SBError()
bytes = process.ReadMemory(start_addr, options.size, error)
if error.Success():
num_matches = 0
- print >>result, "Searching memory range [%#x - %#x) for" % (
- start_addr, end_addr),
+ print("Searching memory range [%#x - %#x) for" % (
+ start_addr, end_addr), end=' ', file=result)
for byte in options.data:
- print >>result, '%2.2x' % ord(byte),
- print >>result
+ print('%2.2x' % ord(byte), end=' ', file=result)
+ print(file=result)
match_index = string.find(bytes, options.data)
while match_index != -1:
num_matches = num_matches + 1
- print >>result, '%#x: %#x + %u' % (start_addr +
- match_index, start_addr, match_index)
+ print('%#x: %#x + %u' % (start_addr +
+ match_index, start_addr, match_index), file=result)
match_index = string.find(bytes, options.data, match_index + 1)
if num_matches == 0:
- print >>result, "error: no matches found"
+ print("error: no matches found", file=result)
else:
- print >>result, 'error: %s' % (error.GetCString())
+ print('error: %s' % (error.GetCString()), file=result)
if __name__ == '__main__':
- print 'error: this script is designed to be used within the embedded script interpreter in LLDB'
+ print('error: this script is designed to be used within the embedded script interpreter in LLDB')
elif getattr(lldb, 'debugger', None):
memfind_command.__doc__ = create_memfind_options().format_help()
lldb.debugger.HandleCommand(
'command script add -f memory.memfind_command memfind')
- print '"memfind" command installed, use the "--help" option for detailed help'
+ print('"memfind" command installed, use the "--help" option for detailed help')
diff --git a/lldb/examples/python/performance.py b/lldb/examples/python/performance.py
index f1bc94f4b43..5412be80293 100755
--- a/lldb/examples/python/performance.py
+++ b/lldb/examples/python/performance.py
@@ -9,6 +9,8 @@
#----------------------------------------------------------------------
import commands
+from __future__ import print_function
+
import optparse
import os
import platform
@@ -50,11 +52,11 @@ except ImportError:
except ImportError:
pass
else:
- print 'imported lldb from: "%s"' % (lldb_python_dir)
+ print('imported lldb from: "%s"' % (lldb_python_dir))
success = True
break
if not success:
- print "error: couldn't locate the 'lldb' module, please set PYTHONPATH correctly"
+ print("error: couldn't locate the 'lldb' module, please set PYTHONPATH correctly")
sys.exit(1)
@@ -179,7 +181,7 @@ class TestCase:
error = lldb.SBError()
self.process = self.target.Launch(self.launch_info, error)
if not error.Success():
- print "error: %s" % error.GetCString()
+ print("error: %s" % error.GetCString())
if self.process:
self.process.GetBroadcaster().AddListener(self.listener,
lldb.SBProcess.eBroadcastBitStateChanged | lldb.SBProcess.eBroadcastBitInterrupt)
@@ -194,7 +196,7 @@ class TestCase:
if self.listener.WaitForEvent(lldb.UINT32_MAX, process_event):
state = lldb.SBProcess.GetStateFromEvent(process_event)
if self.verbose:
- print "event = %s" % (lldb.SBDebugger.StateAsCString(state))
+ print("event = %s" % (lldb.SBDebugger.StateAsCString(state)))
if lldb.SBProcess.GetRestartedFromEvent(process_event):
continue
if state == lldb.eStateInvalid or state == lldb.eStateDetached or state == lldb.eStateCrashed or state == lldb.eStateUnloaded or state == lldb.eStateExited:
@@ -213,46 +215,46 @@ class TestCase:
stop_reason = thread.GetStopReason()
if self.verbose:
- print "tid = %#x pc = %#x " % (thread.GetThreadID(), frame.GetPC()),
+ print("tid = %#x pc = %#x " % (thread.GetThreadID(), frame.GetPC()), end=' ')
if stop_reason == lldb.eStopReasonNone:
if self.verbose:
- print "none"
+ print("none")
elif stop_reason == lldb.eStopReasonTrace:
select_thread = True
if self.verbose:
- print "trace"
+ print("trace")
elif stop_reason == lldb.eStopReasonPlanComplete:
select_thread = True
if self.verbose:
- print "plan complete"
+ print("plan complete")
elif stop_reason == lldb.eStopReasonThreadExiting:
if self.verbose:
- print "thread exiting"
+ print("thread exiting")
elif stop_reason == lldb.eStopReasonExec:
if self.verbose:
- print "exec"
+ print("exec")
elif stop_reason == lldb.eStopReasonInvalid:
if self.verbose:
- print "invalid"
+ print("invalid")
elif stop_reason == lldb.eStopReasonException:
select_thread = True
if self.verbose:
- print "exception"
+ print("exception")
fatal = True
elif stop_reason == lldb.eStopReasonBreakpoint:
select_thread = True
bp_id = thread.GetStopReasonDataAtIndex(0)
bp_loc_id = thread.GetStopReasonDataAtIndex(1)
if self.verbose:
- print "breakpoint id = %d.%d" % (bp_id, bp_loc_id)
+ print("breakpoint id = %d.%d" % (bp_id, bp_loc_id))
elif stop_reason == lldb.eStopReasonWatchpoint:
select_thread = True
if self.verbose:
- print "watchpoint id = %d" % (thread.GetStopReasonDataAtIndex(0))
+ print("watchpoint id = %d" % (thread.GetStopReasonDataAtIndex(0)))
elif stop_reason == lldb.eStopReasonSignal:
select_thread = True
if self.verbose:
- print "signal %d" % (thread.GetStopReasonDataAtIndex(0))
+ print("signal %d" % (thread.GetStopReasonDataAtIndex(0)))
if select_thread and not selected_thread:
self.thread = thread
@@ -339,7 +341,7 @@ class TesterTestCase(TestCase):
def BreakpointHit(self, thread):
bp_id = thread.GetStopReasonDataAtIndex(0)
loc_id = thread.GetStopReasonDataAtIndex(1)
- print "Breakpoint %i.%i hit: %s" % (bp_id, loc_id, thread.process.target.FindBreakpointByID(bp_id))
+ print("Breakpoint %i.%i hit: %s" % (bp_id, loc_id, thread.process.target.FindBreakpointByID(bp_id)))
thread.StepOver()
def PlanComplete(self, thread):
@@ -374,9 +376,9 @@ class TesterTestCase(TestCase):
while not self.done:
self.WaitForNextProcessEvent()
else:
- print "error: failed to launch process"
+ print("error: failed to launch process")
else:
- print "error: failed to create target with '%s'" % (args[0])
+ print("error: failed to create target with '%s'" % (args[0]))
print('Total time = %.03f sec.' % total_time.interval)
@@ -386,7 +388,7 @@ if __name__ == '__main__':
test.Run(sys.argv[1:])
mem = MemoryMeasurement(os.getpid())
mem.Measure()
- print str(mem)
+ print(str(mem))
lldb.SBDebugger.Terminate()
# print "sleeeping for 100 seconds"
# time.sleep(100)
diff --git a/lldb/examples/python/process_events.py b/lldb/examples/python/process_events.py
index c93020a979f..a00217b70c8 100755
--- a/lldb/examples/python/process_events.py
+++ b/lldb/examples/python/process_events.py
@@ -9,6 +9,8 @@
#----------------------------------------------------------------------
import commands
+from __future__ import print_function
+
import optparse
import os
import platform
@@ -46,18 +48,18 @@ except ImportError:
except ImportError:
pass
else:
- print 'imported lldb from: "%s"' % (lldb_python_dir)
+ print('imported lldb from: "%s"' % (lldb_python_dir))
success = True
break
if not success:
- print "error: couldn't locate the 'lldb' module, please set PYTHONPATH correctly"
+ print("error: couldn't locate the 'lldb' module, please set PYTHONPATH correctly")
sys.exit(1)
def print_threads(process, options):
if options.show_threads:
for thread in process:
- print '%s %s' % (thread, thread.GetFrameAtIndex(0))
+ print('%s %s' % (thread, thread.GetFrameAtIndex(0)))
def run_commands(command_interpreter, commands):
@@ -65,9 +67,9 @@ def run_commands(command_interpreter, commands):
for command in commands:
command_interpreter.HandleCommand(command, return_obj)
if return_obj.Succeeded():
- print return_obj.GetOutput()
+ print(return_obj.GetOutput())
else:
- print return_obj
+ print(return_obj)
if options.stop_on_error:
break
@@ -241,17 +243,17 @@ def main(argv):
if options.run_count == 1:
attach_info = lldb.SBAttachInfo(options.attach_pid)
else:
- print "error: --run-count can't be used with the --attach-pid option"
+ print("error: --run-count can't be used with the --attach-pid option")
sys.exit(1)
elif not options.attach_name is None:
if options.run_count == 1:
attach_info = lldb.SBAttachInfo(
options.attach_name, options.attach_wait)
else:
- print "error: --run-count can't be used with the --attach-name option"
+ print("error: --run-count can't be used with the --attach-name option")
sys.exit(1)
else:
- print 'error: a program path for a program to debug and its arguments are required'
+ print('error: a program path for a program to debug and its arguments are required')
sys.exit(1)
# Create a new debugger instance
@@ -261,7 +263,7 @@ def main(argv):
# Create a target from a file and arch
if exe:
- print "Creating a target for '%s'" % exe
+ print("Creating a target for '%s'" % exe)
error = lldb.SBError()
target = debugger.CreateTarget(
exe, options.arch, options.platform, True, error)
@@ -283,26 +285,26 @@ def main(argv):
if launch_info:
if options.run_count == 1:
- print 'Launching "%s"...' % (exe)
+ print('Launching "%s"...' % (exe))
else:
- print 'Launching "%s"... (launch %u of %u)' % (exe, run_idx + 1, options.run_count)
+ print('Launching "%s"... (launch %u of %u)' % (exe, run_idx + 1, options.run_count))
process = target.Launch(launch_info, error)
else:
if options.attach_pid != -1:
- print 'Attaching to process %i...' % (options.attach_pid)
+ print('Attaching to process %i...' % (options.attach_pid))
else:
if options.attach_wait:
- print 'Waiting for next to process named "%s" to launch...' % (options.attach_name)
+ print('Waiting for next to process named "%s" to launch...' % (options.attach_name))
else:
- print 'Attaching to existing process named "%s"...' % (options.attach_name)
+ print('Attaching to existing process named "%s"...' % (options.attach_name))
process = target.Attach(attach_info, error)
# Make sure the launch went ok
if process and process.GetProcessID() != lldb.LLDB_INVALID_PROCESS_ID:
pid = process.GetProcessID()
- print 'Process is %i' % (pid)
+ print('Process is %i' % (pid))
if attach_info:
# continue process if we attached as we won't get an
# initial event
@@ -319,19 +321,19 @@ def main(argv):
state = lldb.SBProcess.GetStateFromEvent(event)
if state == lldb.eStateInvalid:
# Not a state event
- print 'process event = %s' % (event)
+ print('process event = %s' % (event))
else:
- print "process state changed event: %s" % (lldb.SBDebugger.StateAsCString(state))
+ print("process state changed event: %s" % (lldb.SBDebugger.StateAsCString(state)))
if state == lldb.eStateStopped:
if stop_idx == 0:
if launch_info:
- print "process %u launched" % (pid)
+ print("process %u launched" % (pid))
run_commands(
command_interpreter, ['breakpoint list'])
else:
- print "attached to process %u" % (pid)
+ print("attached to process %u" % (pid))
for m in target.modules:
- print m
+ print(m)
if options.breakpoints:
for bp in options.breakpoints:
debugger.HandleCommand(
@@ -342,74 +344,74 @@ def main(argv):
command_interpreter, options.launch_commands)
else:
if options.verbose:
- print "process %u stopped" % (pid)
+ print("process %u stopped" % (pid))
run_commands(
command_interpreter, options.stop_commands)
stop_idx += 1
print_threads(process, options)
- print "continuing process %u" % (pid)
+ print("continuing process %u" % (pid))
process.Continue()
elif state == lldb.eStateExited:
exit_desc = process.GetExitDescription()
if exit_desc:
- print "process %u exited with status %u: %s" % (pid, process.GetExitStatus(), exit_desc)
+ print("process %u exited with status %u: %s" % (pid, process.GetExitStatus(), exit_desc))
else:
- print "process %u exited with status %u" % (pid, process.GetExitStatus())
+ print("process %u exited with status %u" % (pid, process.GetExitStatus()))
run_commands(
command_interpreter, options.exit_commands)
done = True
elif state == lldb.eStateCrashed:
- print "process %u crashed" % (pid)
+ print("process %u crashed" % (pid))
print_threads(process, options)
run_commands(
command_interpreter, options.crash_commands)
done = True
elif state == lldb.eStateDetached:
- print "process %u detached" % (pid)
+ print("process %u detached" % (pid))
done = True
elif state == lldb.eStateRunning:
# process is running, don't say anything,
# we will always get one of these after
# resuming
if options.verbose:
- print "process %u resumed" % (pid)
+ print("process %u resumed" % (pid))
elif state == lldb.eStateUnloaded:
- print "process %u unloaded, this shouldn't happen" % (pid)
+ print("process %u unloaded, this shouldn't happen" % (pid))
done = True
elif state == lldb.eStateConnected:
- print "process connected"
+ print("process connected")
elif state == lldb.eStateAttaching:
- print "process attaching"
+ print("process attaching")
elif state == lldb.eStateLaunching:
- print "process launching"
+ print("process launching")
else:
- print 'event = %s' % (event)
+ print('event = %s' % (event))
else:
# timeout waiting for an event
- print "no process event for %u seconds, killing the process..." % (options.event_timeout)
+ print("no process event for %u seconds, killing the process..." % (options.event_timeout))
done = True
# Now that we are done dump the stdout and stderr
process_stdout = process.GetSTDOUT(1024)
if process_stdout:
- print "Process STDOUT:\n%s" % (process_stdout)
+ print("Process STDOUT:\n%s" % (process_stdout))
while process_stdout:
process_stdout = process.GetSTDOUT(1024)
- print process_stdout
+ print(process_stdout)
process_stderr = process.GetSTDERR(1024)
if process_stderr:
- print "Process STDERR:\n%s" % (process_stderr)
+ print("Process STDERR:\n%s" % (process_stderr))
while process_stderr:
process_stderr = process.GetSTDERR(1024)
- print process_stderr
+ print(process_stderr)
process.Kill() # kill the process
else:
if error:
- print error
+ print(error)
else:
if launch_info:
- print 'error: launch failed'
+ print('error: launch failed')
else:
- print 'error: attach failed'
+ print('error: attach failed')
lldb.SBDebugger.Terminate()
diff --git a/lldb/examples/python/pytracer.py b/lldb/examples/python/pytracer.py
index 4d0d7b0d827..27f88d7a3ee 100644
--- a/lldb/examples/python/pytracer.py
+++ b/lldb/examples/python/pytracer.py
@@ -1,3 +1,4 @@
+from __future__ import print_function
import sys
import inspect
from collections import OrderedDict
@@ -229,17 +230,17 @@ def disable():
class LoggingTracer:
def callEvent(self, frame):
- print "call " + frame.getName() + " from " + frame.getCaller().getName() + " @ " + str(frame.getCaller().getLineNumber()) + " args are " + str(frame.getArgumentInfo())
+ print("call " + frame.getName() + " from " + frame.getCaller().getName() + " @ " + str(frame.getCaller().getLineNumber()) + " args are " + str(frame.getArgumentInfo()))
def lineEvent(self, frame):
- print "running " + frame.getName() + " @ " + str(frame.getLineNumber()) + " locals are " + str(frame.getLocals()) + " in " + frame.getFileName()
+ print("running " + frame.getName() + " @ " + str(frame.getLineNumber()) + " locals are " + str(frame.getLocals()) + " in " + frame.getFileName())
def returnEvent(self, frame, retval):
- print "return from " + frame.getName() + " value is " + str(retval) + " locals are " + str(frame.getLocals())
+ print("return from " + frame.getName() + " value is " + str(retval) + " locals are " + str(frame.getLocals()))
def exceptionEvent(self, frame, exception):
- print "exception %s %s raised from %s @ %s" % (exception.getType(), str(exception.getValue()), frame.getName(), frame.getLineNumber())
- print "tb: " + str(exception.getTraceback())
+ print("exception %s %s raised from %s @ %s" % (exception.getType(), str(exception.getValue()), frame.getName(), frame.getLineNumber()))
+ print("tb: " + str(exception.getTraceback()))
# the same functionality as LoggingTracer, but with a little more
# lldb-specific smarts
@@ -251,10 +252,10 @@ class LLDBAwareTracer:
if frame.getName() == "<module>":
return
if frame.getName() == "run_one_line":
- print "call run_one_line(%s)" % (frame.getArgumentInfo().getArgs()["input_string"])
+ print("call run_one_line(%s)" % (frame.getArgumentInfo().getArgs()["input_string"]))
return
if "Python.framework" in frame.getFileName():
- print "call into Python at " + frame.getName()
+ print("call into Python at " + frame.getName())
return
if frame.getName() == "__init__" and frame.getCaller().getName(
) == "run_one_line" and frame.getCaller().getLineNumber() == 101:
@@ -270,16 +271,16 @@ class LLDBAwareTracer:
else:
strout += " from " + frame.getCaller().getName() + " @ " + \
str(frame.getCaller().getLineNumber()) + " args are " + str(frame.getArgumentInfo())
- print strout
+ print(strout)
def lineEvent(self, frame):
if frame.getName() == "<module>":
return
if frame.getName() == "run_one_line":
- print "running run_one_line(%s) @ %s" % (frame.getArgumentInfo().getArgs()["input_string"], frame.getLineNumber())
+ print("running run_one_line(%s) @ %s" % (frame.getArgumentInfo().getArgs()["input_string"], frame.getLineNumber()))
return
if "Python.framework" in frame.getFileName():
- print "running into Python at " + frame.getName() + " @ " + str(frame.getLineNumber())
+ print("running into Python at " + frame.getName() + " @ " + str(frame.getLineNumber()))
return
strout = "running " + frame.getName() + " @ " + str(frame.getLineNumber()) + \
" locals are "
@@ -292,16 +293,16 @@ class LLDBAwareTracer:
else:
strout = strout + str(frame.getLocals())
strout = strout + " in " + frame.getFileName()
- print strout
+ print(strout)
def returnEvent(self, frame, retval):
if frame.getName() == "<module>":
return
if frame.getName() == "run_one_line":
- print "return from run_one_line(%s) return value is %s" % (frame.getArgumentInfo().getArgs()["input_string"], retval)
+ print("return from run_one_line(%s) return value is %s" % (frame.getArgumentInfo().getArgs()["input_string"], retval))
return
if "Python.framework" in frame.getFileName():
- print "return from Python at " + frame.getName() + " return value is " + str(retval)
+ print("return from Python at " + frame.getName() + " return value is " + str(retval))
return
strout = "return from " + frame.getName() + " return value is " + \
str(retval) + " locals are "
@@ -314,13 +315,13 @@ class LLDBAwareTracer:
else:
strout = strout + str(frame.getLocals())
strout = strout + " in " + frame.getFileName()
- print strout
+ print(strout)
def exceptionEvent(self, frame, exception):
if frame.getName() == "<module>":
return
- print "exception %s %s raised from %s @ %s" % (exception.getType(), str(exception.getValue()), frame.getName(), frame.getLineNumber())
- print "tb: " + str(exception.getTraceback())
+ print("exception %s %s raised from %s @ %s" % (exception.getType(), str(exception.getValue()), frame.getName(), frame.getLineNumber()))
+ print("tb: " + str(exception.getTraceback()))
def f(x, y=None):
@@ -336,7 +337,7 @@ def g(x):
def print_keyword_args(**kwargs):
# kwargs is a dict of the keyword args passed to the function
for key, value in kwargs.items():
- print "%s = %s" % (key, value)
+ print("%s = %s" % (key, value))
def total(initial=5, *numbers, **keywords):
diff --git a/lldb/examples/python/scripted_step.py b/lldb/examples/python/scripted_step.py
index 453b5e229fb..3c1d5d7a6c4 100644
--- a/lldb/examples/python/scripted_step.py
+++ b/lldb/examples/python/scripted_step.py
@@ -93,6 +93,8 @@
#
# (lldb) thread step-scripted -C scripted_step.StepWithPlan
+from __future__ import print_function
+
import lldb
@@ -186,13 +188,13 @@ class StepCheckingCondition:
a_var = frame.FindVariable("a")
if not a_var.IsValid():
- print "A was not valid."
+ print("A was not valid.")
return True
error = lldb.SBError()
a_value = a_var.GetValueAsSigned(error)
if not error.Success():
- print "A value was not good."
+ print("A value was not good.")
return True
if a_value == 20:
@@ -239,6 +241,6 @@ class FinishPrintAndContinue:
frame_0 = self.thread.frames[0]
rax_value = frame_0.FindRegister("rax")
if rax_value.GetError().Success():
- print "RAX on exit: ", rax_value.GetValue()
+ print("RAX on exit: ", rax_value.GetValue())
else:
- print "Couldn't get rax value:", rax_value.GetError().GetCString()
+ print("Couldn't get rax value:", rax_value.GetError().GetCString())
diff --git a/lldb/examples/python/shadow.py b/lldb/examples/python/shadow.py
index 0556cfc553c..b14467c52c9 100644
--- a/lldb/examples/python/shadow.py
+++ b/lldb/examples/python/shadow.py
@@ -1,4 +1,5 @@
#!/usr/bin/python
+from __future__ import print_function
import lldb
import shlex
@@ -10,12 +11,12 @@ def check_shadow_command(debugger, command, exe_ctx, result, dict):
process = exe_ctx.GetProcess()
state = process.GetState()
if state != lldb.eStateStopped:
- print >>result, "process must be stopped, state is %s" % lldb.SBDebugger.StateAsCString(
- state)
+ print("process must be stopped, state is %s" % lldb.SBDebugger.StateAsCString(
+ state), file=result)
return
frame = exe_ctx.GetFrame()
if not frame:
- print >>result, "invalid frame"
+ print("invalid frame", file=result)
return
# Parse command line args
command_args = shlex.split(command)
@@ -50,9 +51,9 @@ def check_shadow_command(debugger, command, exe_ctx, result, dict):
for name in shadow_dict.keys():
shadow_vars = shadow_dict[name]
if len(shadow_vars) > 1:
- print '"%s" is shadowed by the following declarations:' % (name)
+ print('"%s" is shadowed by the following declarations:' % (name))
num_shadowed_variables += 1
for shadow_var in shadow_vars:
- print >>result, str(shadow_var.GetDeclaration())
+ print(str(shadow_var.GetDeclaration()), file=result)
if num_shadowed_variables == 0:
- print >>result, 'no variables are shadowed'
+ print('no variables are shadowed', file=result)
diff --git a/lldb/examples/python/sources.py b/lldb/examples/python/sources.py
index b912f43f72c..9684f7f6e78 100644
--- a/lldb/examples/python/sources.py
+++ b/lldb/examples/python/sources.py
@@ -1,4 +1,5 @@
#!/usr/bin/python
+from __future__ import print_function
import lldb
import shlex
@@ -6,10 +7,10 @@ import shlex
def dump_module_sources(module, result):
if module:
- print >> result, "Module: %s" % (module.file)
+ print("Module: %s" % (module.file), file=result)
for compile_unit in module.compile_units:
if compile_unit.file:
- print >> result, " %s" % (compile_unit.file)
+ print(" %s" % (compile_unit.file), file=result)
def info_sources(debugger, command, result, dict):
@@ -28,4 +29,4 @@ def __lldb_init_module(debugger, dict):
# Add any commands contained in this module to LLDB
debugger.HandleCommand(
'command script add -f sources.info_sources info_sources')
- print 'The "info_sources" command has been installed, type "help info_sources" or "info_sources --help" for detailed help.'
+ print('The "info_sources" command has been installed, type "help info_sources" or "info_sources --help" for detailed help.')
diff --git a/lldb/examples/python/stacks.py b/lldb/examples/python/stacks.py
index fec879993d9..63c46ad046e 100755
--- a/lldb/examples/python/stacks.py
+++ b/lldb/examples/python/stacks.py
@@ -1,5 +1,5 @@
#!/usr/bin/python
-
+from __future__ import print_function
import lldb
import commands
import optparse
@@ -30,7 +30,7 @@ def stack_frames(debugger, command, result, dict):
frame_info = {}
for thread in process:
last_frame = None
- print "thread %u" % (thread.id)
+ print("thread %u" % (thread.id))
for frame in thread.frames:
if last_frame:
frame_size = 0
@@ -43,7 +43,7 @@ def stack_frames(debugger, command, result, dict):
else:
# First frame that has a valid size
first_frame_size = last_frame.fp - last_frame.sp
- print "<%#7x> %s" % (first_frame_size, last_frame)
+ print("<%#7x> %s" % (first_frame_size, last_frame))
if first_frame_size:
name = last_frame.name
if name not in frame_info:
@@ -53,7 +53,7 @@ def stack_frames(debugger, command, result, dict):
else:
# Second or higher frame
frame_size = frame.fp - last_frame.fp
- print "<%#7x> %s" % (frame_size, frame)
+ print("<%#7x> %s" % (frame_size, frame))
if frame_size > 0:
name = frame.name
if name not in frame_info:
@@ -61,9 +61,9 @@ def stack_frames(debugger, command, result, dict):
else:
frame_info[name] += frame_size
last_frame = frame
- print frame_info
+ print(frame_info)
lldb.debugger.HandleCommand(
"command script add -f stacks.stack_frames stack_frames")
-print "A new command called 'stack_frames' was added, type 'stack_frames --help' for more information."
+print("A new command called 'stack_frames' was added, type 'stack_frames --help' for more information.")
diff --git a/lldb/examples/python/types.py b/lldb/examples/python/types.py
index a8aac24f4a0..a4cc91ba5dc 100755
--- a/lldb/examples/python/types.py
+++ b/lldb/examples/python/types.py
@@ -10,6 +10,8 @@
#----------------------------------------------------------------------
import commands
+from __future__ import print_function
+
import platform
import os
import re
@@ -45,11 +47,11 @@ except ImportError:
except ImportError:
pass
else:
- print 'imported lldb from: "%s"' % (lldb_python_dir)
+ print('imported lldb from: "%s"' % (lldb_python_dir))
success = True
break
if not success:
- print "error: couldn't locate the 'lldb' module, please set PYTHONPATH correctly"
+ print("error: couldn't locate the 'lldb' module, please set PYTHONPATH correctly")
sys.exit(1)
import commands
@@ -157,7 +159,7 @@ be verified in all specified modules.
def verify_type(target, options, type):
- print type
+ print(type)
typename = type.GetName()
# print 'type: %s' % (typename)
(end_offset, padding) = verify_type_recursive(
@@ -167,11 +169,11 @@ def verify_type(target, options, type):
# last_member_padding = byte_size - end_offset
# print '%+4u <%u> padding' % (end_offset, last_member_padding)
# padding += last_member_padding
- print 'Total byte size: %u' % (byte_size)
- print 'Total pad bytes: %u' % (padding)
+ print('Total byte size: %u' % (byte_size))
+ print('Total pad bytes: %u' % (padding))
if padding > 0:
- print 'Padding percentage: %2.2f %%' % ((float(padding) / float(byte_size)) * 100.0)
- print
+ print('Padding percentage: %2.2f %%' % ((float(padding) / float(byte_size)) * 100.0))
+ print()
def verify_type_recursive(
@@ -186,9 +188,9 @@ def verify_type_recursive(
typename = type.GetName()
byte_size = type.GetByteSize()
if member_name and member_name != typename:
- print '%+4u <%3u> %s%s %s;' % (base_offset, byte_size, ' ' * depth, typename, member_name)
+ print('%+4u <%3u> %s%s %s;' % (base_offset, byte_size, ' ' * depth, typename, member_name))
else:
- print '%+4u {%3u} %s%s' % (base_offset, byte_size, ' ' * depth, typename)
+ print('%+4u {%3u} %s%s' % (base_offset, byte_size, ' ' * depth, typename))
for type_regex in options.skip_type_regexes:
match = type_regex.match(typename)
@@ -211,13 +213,13 @@ def verify_type_recursive(
if member_idx == 0 and member_offset == target.GetAddressByteSize(
) and type.IsPolymorphicClass():
ptr_size = target.GetAddressByteSize()
- print '%+4u <%3u> %s__vtbl_ptr_type * _vptr;' % (prev_end_offset, ptr_size, ' ' * (depth + 1))
+ print('%+4u <%3u> %s__vtbl_ptr_type * _vptr;' % (prev_end_offset, ptr_size, ' ' * (depth + 1)))
prev_end_offset = ptr_size
else:
if prev_end_offset < member_total_offset:
member_padding = member_total_offset - prev_end_offset
padding = padding + member_padding
- print '%+4u <%3u> %s<PADDING>' % (prev_end_offset, member_padding, ' ' * (depth + 1))
+ print('%+4u <%3u> %s<PADDING>' % (prev_end_offset, member_padding, ' ' * (depth + 1)))
if member_is_class_or_struct:
(prev_end_offset,
@@ -232,18 +234,18 @@ def verify_type_recursive(
prev_end_offset = member_total_offset + member_byte_size
member_typename = member_type.GetName()
if member.IsBitfield():
- print '%+4u <%3u> %s%s:%u %s;' % (member_total_offset, member_byte_size, ' ' * (depth + 1), member_typename, member.GetBitfieldSizeInBits(), member_name)
+ print('%+4u <%3u> %s%s:%u %s;' % (member_total_offset, member_byte_size, ' ' * (depth + 1), member_typename, member.GetBitfieldSizeInBits(), member_name))
else:
- print '%+4u <%3u> %s%s %s;' % (member_total_offset, member_byte_size, ' ' * (depth + 1), member_typename, member_name)
+ print('%+4u <%3u> %s%s %s;' % (member_total_offset, member_byte_size, ' ' * (depth + 1), member_typename, member_name))
if prev_end_offset < byte_size:
last_member_padding = byte_size - prev_end_offset
- print '%+4u <%3u> %s<PADDING>' % (prev_end_offset, last_member_padding, ' ' * (depth + 1))
+ print('%+4u <%3u> %s<PADDING>' % (prev_end_offset, last_member_padding, ' ' * (depth + 1)))
padding += last_member_padding
else:
if type.IsPolymorphicClass():
ptr_size = target.GetAddressByteSize()
- print '%+4u <%3u> %s__vtbl_ptr_type * _vptr;' % (prev_end_offset, ptr_size, ' ' * (depth + 1))
+ print('%+4u <%3u> %s__vtbl_ptr_type * _vptr;' % (prev_end_offset, ptr_size, ' ' * (depth + 1)))
prev_end_offset = ptr_size
prev_end_offset = base_offset + byte_size
@@ -274,17 +276,17 @@ def parse_all_struct_class_types(debugger, command, result, dict):
error = lldb.SBError()
target = debugger.CreateTarget(f, None, None, False, error)
module = target.GetModuleAtIndex(0)
- print "Parsing all types in '%s'" % (module)
+ print("Parsing all types in '%s'" % (module))
types = module.GetTypes(lldb.eTypeClassClass | lldb.eTypeClassStruct)
for t in types:
- print t
- print ""
+ print(t)
+ print("")
def verify_types(target, options):
if not target:
- print 'error: invalid target'
+ print('error: invalid target')
return
modules = list()
@@ -301,24 +303,24 @@ def verify_types(target, options):
if modules:
for module in modules:
- print 'module: %s' % (module.file)
+ print('module: %s' % (module.file))
if options.typenames:
for typename in options.typenames:
types = module.FindTypes(typename)
if types.GetSize():
- print 'Found %u types matching "%s" in "%s"' % (len(types), typename, module.file)
+ print('Found %u types matching "%s" in "%s"' % (len(types), typename, module.file))
for type in types:
verify_type(target, options, type)
else:
- print 'error: no type matches "%s" in "%s"' % (typename, module.file)
+ print('error: no type matches "%s" in "%s"' % (typename, module.file))
else:
types = module.GetTypes(
lldb.eTypeClassClass | lldb.eTypeClassStruct)
- print 'Found %u types in "%s"' % (len(types), module.file)
+ print('Found %u types in "%s"' % (len(types), module.file))
for type in types:
verify_type(target, options, type)
else:
- print 'error: no modules'
+ print('error: no modules')
if __name__ == '__main__':
debugger = lldb.SBDebugger.Create()
@@ -331,7 +333,7 @@ if __name__ == '__main__':
# sys.exit(1)
if options.debug:
- print "Waiting for debugger to attach to process %d" % os.getpid()
+ print("Waiting for debugger to attach to process %d" % os.getpid())
os.kill(os.getpid(), signal.SIGSTOP)
for path in args:
@@ -346,11 +348,11 @@ if __name__ == '__main__':
True,
error)
if error.Fail():
- print error.GetCString()
+ print(error.GetCString())
continue
verify_types(target, options)
elif getattr(lldb, 'debugger', None):
lldb.debugger.HandleCommand(
'command script add -f types.check_padding_command check_padding')
- print '"check_padding" command installed, use the "--help" option for detailed help'
+ print('"check_padding" command installed, use the "--help" option for detailed help')
OpenPOWER on IntegriCloud