"""Create a listener and use SBEvent API to print the events received."""
exe = os.path.join(os.getcwd(), "a.out")
+ self.dbg.SetAsync(True)
+
# Create a target by the debugger.
target = self.dbg.CreateTarget(exe)
self.assertTrue(target, VALID_TARGET)
# Now create a breakpoint on main.c by name 'c'.
breakpoint = target.BreakpointCreateByName('c', 'a.out')
- # Now launch the process, and do not stop at the entry point.
- process = target.LaunchSimple (None, None, self.get_process_working_directory())
- self.assertTrue(process.GetState() == lldb.eStateStopped,
- PROCESS_STOPPED)
+ listener = lldb.SBListener("my listener")
- # Get a handle on the process's broadcaster.
- broadcaster = process.GetBroadcaster()
+ # Now launch the process, and do not stop at the entry point.
+ error = lldb.SBError()
+ process = target.Launch (listener,
+ None, # argv
+ None, # envp
+ None, # stdin_path
+ None, # stdout_path
+ None, # stderr_path
+ None, # working directory
+ 0, # launch flags
+ False, # Stop at entry
+ error) # error
+
+ self.assertTrue(process.GetState() == lldb.eStateStopped, PROCESS_STOPPED)
# Create an empty event object.
event = lldb.SBEvent()
- # Create a listener object and register with the broadcaster.
- listener = lldb.SBListener("my listener")
- rc = broadcaster.AddListener(listener, lldb.SBProcess.eBroadcastBitStateChanged)
- self.assertTrue(rc, "AddListener successfully retruns")
-
traceOn = self.TraceOn()
if traceOn:
lldbutil.print_stacktraces(process)
while not count > 3:
if traceOn:
print "Try wait for event..."
- if listener.WaitForEventForBroadcasterWithType(5,
- broadcaster,
- lldb.SBProcess.eBroadcastBitStateChanged,
- event):
+ if listener.WaitForEvent(5, event):
if traceOn:
desc = lldbutil.get_description(event)
print "Event description:", desc
"""Get the listener associated with the debugger and exercise WaitForEvent API."""
exe = os.path.join(os.getcwd(), "a.out")
+ self.dbg.SetAsync(True)
+
# Create a target by the debugger.
target = self.dbg.CreateTarget(exe)
self.assertTrue(target, VALID_TARGET)
# Now launch the process, and do not stop at entry point.
error = lldb.SBError()
- process = target.Launch (listener, None, None, None, None, None, None, 0, False, error)
+ process = target.Launch (listener,
+ None, # argv
+ None, # envp
+ None, # stdin_path
+ None, # stdout_path
+ None, # stderr_path
+ None, # working directory
+ 0, # launch flags
+ False, # Stop at entry
+ error) # error
self.assertTrue(error.Success() and process, PROCESS_IS_VALID)
- # Get a handle on the process's broadcaster.
- broadcaster = process.GetBroadcaster()
- self.assertTrue(broadcaster, "Process with valid broadcaster")
-
# Create an empty event object.
event = lldb.SBEvent()
self.assertFalse(event, "Event should not be valid initially")
"""Get the broadcaster associated with the process and wait for broadcaster events."""
exe = os.path.join(os.getcwd(), "a.out")
+ self.dbg.SetAsync(True)
+
# Create a target by the debugger.
target = self.dbg.CreateTarget(exe)
self.assertTrue(target, VALID_TARGET)
breakpoint.GetNumLocations() == 1,
VALID_BREAKPOINT)
- # Now launch the process, and do not stop at the entry point.
- process = target.LaunchSimple (None, None, self.get_process_working_directory())
- self.assertTrue(process.GetState() == lldb.eStateStopped,
- PROCESS_STOPPED)
+ listener = lldb.SBListener("my listener")
- # Get a handle on the process's broadcaster.
- broadcaster = process.GetBroadcaster()
- self.assertTrue(broadcaster, "Process with valid broadcaster")
+ # Now launch the process, and do not stop at the entry point.
+ error = lldb.SBError()
+ process = target.Launch (listener,
+ None, # argv
+ None, # envp
+ None, # stdin_path
+ None, # stdout_path
+ None, # stderr_path
+ None, # working directory
+ 0, # launch flags
+ False, # Stop at entry
+ error) # error
# Create an empty event object.
event = lldb.SBEvent()
self.assertFalse(event, "Event should not be valid initially")
- # Create a listener object and register with the broadcaster.
- listener = lldb.SBListener("TestEvents.listener")
- rc = broadcaster.AddListener(listener, lldb.SBProcess.eBroadcastBitStateChanged)
- self.assertTrue(rc, "AddListener successfully retruns")
# The finite state machine for our custom listening thread, with an
# initail state of 0, which means a "running" event is expected.
# Let's only try at most 6 times to retrieve our events.
count = 0
while True:
- if listener.WaitForEventForBroadcasterWithType(5,
- broadcaster,
- lldb.SBProcess.eBroadcastBitStateChanged,
- event):
+ if listener.WaitForEvent(5, event):
desc = lldbutil.get_description(event)
#print "Event description:", desc
match = pattern.search(desc)
# Wait until the 'MyListeningThread' terminates.
my_thread.join()
- # We are no longer interested in receiving state changed events.
- # Remove our custom listener before the inferior is killed.
- broadcaster.RemoveListener(listener, lldb.SBProcess.eBroadcastBitStateChanged)
-
# The final judgement. :-)
self.assertTrue(self.state == 2,
"Both expected state changed events received")