A bit more cleanup on the process_events.py to use best practices for event handling.

llvm-svn: 185089
This commit is contained in:
Greg Clayton 2013-06-27 18:08:32 +00:00
parent 7dcbe3d356
commit 96eb9ab047
1 changed files with 72 additions and 54 deletions

View File

@ -174,7 +174,6 @@ def main(argv):
pid = process.GetProcessID() pid = process.GetProcessID()
listener = debugger.GetListener() listener = debugger.GetListener()
# sign up for process state change events # sign up for process state change events
#process.GetBroadcaster().AddListener(listener, lldb.SBProcess.eBroadcastBitStateChanged)
stop_idx = 0 stop_idx = 0
done = False done = False
while not done: while not done:
@ -182,62 +181,81 @@ def main(argv):
if listener.WaitForEvent (options.event_timeout, event): if listener.WaitForEvent (options.event_timeout, event):
if lldb.SBProcess.EventIsProcessEvent(event): if lldb.SBProcess.EventIsProcessEvent(event):
state = lldb.SBProcess.GetStateFromEvent (event) state = lldb.SBProcess.GetStateFromEvent (event)
print "event %s" % (lldb.SBDebugger.StateAsCString(state)) if state == lldb.eStateInvalid:
if state == lldb.eStateStopped: # Not a state event
if stop_idx == 0: print 'process event = %s' % (event)
if launch_info: else:
print "process %u launched" % (pid) print "process state changed event: %s" % (lldb.SBDebugger.StateAsCString(state))
run_commands(command_interpreter, ['breakpoint list']) if state == lldb.eStateStopped:
else: if stop_idx == 0:
print "attached to process %u" % (pid) if launch_info:
for m in target.modules: print "process %u launched" % (pid)
print m
if options.breakpoints:
for bp in options.breakpoints:
debugger.HandleCommand( "_regexp-break %s" % (bp))
run_commands(command_interpreter, ['breakpoint list']) run_commands(command_interpreter, ['breakpoint list'])
run_commands (command_interpreter, options.launch_commands) else:
else: print "attached to process %u" % (pid)
for m in target.modules:
print m
if options.breakpoints:
for bp in options.breakpoints:
debugger.HandleCommand( "_regexp-break %s" % (bp))
run_commands(command_interpreter, ['breakpoint list'])
run_commands (command_interpreter, options.launch_commands)
else:
if options.verbose:
print "process %u stopped" % (pid)
run_commands (command_interpreter, options.stop_commands)
stop_idx += 1
print_threads (process, options)
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)
else:
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_threads (process, options)
run_commands (command_interpreter, options.crash_commands)
done = True
elif state == lldb.eStateDetached:
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: if options.verbose:
print "process %u stopped" % (pid) print "process %u resumed" % (pid)
run_commands (command_interpreter, options.stop_commands) elif state == lldb.eStateUnloaded:
stop_idx += 1 print "process %u unloaded, this shouldn't happen" % (pid)
print_threads (process, options) done = True
print "continuing process %u" % (pid) elif state == lldb.eStateConnected:
process.Continue() print "process connected"
elif state == lldb.eStateExited: elif state == lldb.eStateAttaching:
exit_desc = process.GetExitDescription() print "process attaching"
if exit_desc: elif state == lldb.eStateLaunching:
print "process %u exited with status %u: %s" % (pid, process.GetExitStatus (), exit_desc) print "process launching"
else:
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_threads (process, options)
run_commands (command_interpreter, options.crash_commands)
done = True
elif state == lldb.eStateDetached:
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)
elif state == lldb.eStateUnloaded:
print "process %u unloaded, this shouldn't happen" % (pid)
done = True
elif state == lldb.eStateConnected:
print "process connected"
elif state == lldb.eStateAttaching:
print "process attaching"
elif state == lldb.eStateLaunching:
print "process launching"
else: else:
# timeout waiting for an event print 'event = %s' % (event)
print "no process event for %u seconds, killing the process..." % (options.event_timeout) else:
done = True # timeout waiting for an event
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)
while process_stdout:
process_stdout = process.GetSTDOUT(1024)
print process_stdout
process_stderr = process.GetSTDERR(1024)
if process_stderr:
print "Process STDERR:\n%s" % (process_stderr)
while process_stderr:
process_stderr = process.GetSTDERR(1024)
print process_stderr
process.Kill() # kill the process process.Kill() # kill the process
else: else:
if error: if error: