summaryrefslogtreecommitdiffstats
path: root/lldb/examples/python/process_events.py
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/examples/python/process_events.py')
-rwxr-xr-xlldb/examples/python/process_events.py82
1 files changed, 42 insertions, 40 deletions
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()
OpenPOWER on IntegriCloud