def test_stdio_pty(self): target = self._create_target() info = target.GetLaunchInfo() info.SetArguments([ "stdin:stdin", "stdout:STDOUT CONTENT\n", "stderr:STDERR CONTENT\n", "dump:" + self.getBuildArtifact("state.log"), ], False) listener = lldb.SBListener("test_stdio") info.SetListener(listener) self.dbg.SetAsync(True) error = lldb.SBError() process = target.Launch(info, error) self.assertSuccess(error) lldbutil.expect_state_changes(self, listener, process, [lldb.eStateRunning]) process.PutSTDIN("STDIN CONTENT\n") lldbutil.expect_state_changes(self, listener, process, [lldb.eStateExited]) # Echoed stdin, stdout and stderr. With a pty we cannot split standard # output and error. self.assertEqual( process.GetSTDOUT(1000), "STDIN CONTENT\r\nSTDOUT CONTENT\r\nSTDERR CONTENT\r\n") with open(self.getBuildArtifact("state.log")) as s: state = json.load(s) self.assertEqual(state["stdin"], "STDIN CONTENT\n")
def wait_for_running_event(self, process): listener = self.dbg.GetListener() if lldb.remote_platform: lldbutil.expect_state_changes(self, listener, process, [lldb.eStateConnected]) lldbutil.expect_state_changes(self, listener, process, [lldb.eStateRunning])
def wait_for_running_event(self, process): listener = self.dbg.GetListener() if lldb.remote_platform: lldbutil.expect_state_changes( self, listener, process, [ lldb.eStateConnected]) lldbutil.expect_state_changes( self, listener, process, [ lldb.eStateRunning])
def test_breakpoint_set_restart(self): self.build() cwd = self.get_process_working_directory() exe = os.path.join(cwd, "a.out") target = self.dbg.CreateTarget(exe) self.dbg.SetAsync(True) process = target.LaunchSimple(None, None, cwd) lldbutil.expect_state_changes(self, self.dbg.GetListener(), [lldb.eStateRunning]) bp = target.BreakpointCreateBySourceRegex(self.BREAKPOINT_TEXT, lldb.SBFileSpec(os.path.join(cwd, 'main.cpp'))) self.assertTrue(bp.IsValid() and bp.GetNumLocations() == 1, VALID_BREAKPOINT) event = lldb.SBEvent() while self.dbg.GetListener().WaitForEvent(2, event): if lldb.SBProcess.GetStateFromEvent(event) == lldb.eStateStopped and lldb.SBProcess.GetRestartedFromEvent(event): continue if lldb.SBProcess.GetStateFromEvent(event) == lldb.eStateRunning: continue self.fail("Setting a breakpoint generated an unexpected event: %s" % lldb.SBDebugger.StateAsCString(lldb.SBProcess.GetStateFromEvent(event)))
def process_attach_continue_interrupt_detach(self): """Test attach/continue/interrupt/detach""" exe = os.path.join(os.getcwd(), exe_name) popen = self.spawnSubprocess(exe) self.addTearDownHook(self.cleanupSubprocesses) self.runCmd("process attach -p " + str(popen.pid)) self.setAsync(True) listener = self.dbg.GetListener() self.runCmd("c") lldbutil.expect_state_changes(self, listener, [lldb.eStateRunning]) self.runCmd("process interrupt") lldbutil.expect_state_changes(self, listener, [lldb.eStateStopped]) # be sure to continue/interrupt/continue (r204504) self.runCmd("c") lldbutil.expect_state_changes(self, listener, [lldb.eStateRunning]) self.runCmd("process interrupt") lldbutil.expect_state_changes(self, listener, [lldb.eStateStopped]) # check that this breakpoint is auto-cleared on detach (r204752) self.runCmd("br set -f main.cpp -l %u" % (line_number('main.cpp', '// Set breakpoint here'))) self.runCmd("c") lldbutil.expect_state_changes(self, listener, [lldb.eStateRunning, lldb.eStateStopped]) self.expect('br list', 'Breakpoint not hit', substrs=['hit count = 1']) # Make sure the breakpoint is not hit again. self.expect("expr debugger_flag = false", substrs=[" = false"]) self.runCmd("c") lldbutil.expect_state_changes(self, listener, [lldb.eStateRunning]) # make sure to detach while in running state (r204759) self.runCmd("detach") lldbutil.expect_state_changes(self, listener, [lldb.eStateDetached])
def process_attach_continue_interrupt_detach(self): """Test attach/continue/interrupt/detach""" exe = os.path.join(os.getcwd(), exe_name) popen = self.spawnSubprocess(exe) self.addTearDownHook(self.cleanupSubprocesses) self.runCmd("process attach -p " + str(popen.pid)) self.setAsync(True) listener = self.dbg.GetListener() process = self.dbg.GetSelectedTarget().GetProcess() self.runCmd("c") lldbutil.expect_state_changes(self, listener, process, [lldb.eStateRunning]) self.runCmd("process interrupt") lldbutil.expect_state_changes(self, listener, process, [lldb.eStateStopped]) # be sure to continue/interrupt/continue (r204504) self.runCmd("c") lldbutil.expect_state_changes(self, listener, process, [lldb.eStateRunning]) self.runCmd("process interrupt") lldbutil.expect_state_changes(self, listener, process, [lldb.eStateStopped]) # Second interrupt should have no effect. self.expect("process interrupt", patterns=["Process is not running"], error=True) # check that this breakpoint is auto-cleared on detach (r204752) self.runCmd("br set -f main.cpp -l %u" % (line_number('main.cpp', '// Set breakpoint here'))) self.runCmd("c") lldbutil.expect_state_changes(self, listener, process, [lldb.eStateRunning, lldb.eStateStopped]) self.expect('br list', 'Breakpoint not hit', substrs = ['hit count = 1']) # Make sure the breakpoint is not hit again. self.expect("expr debugger_flag = false", substrs=[" = false"]); self.runCmd("c") lldbutil.expect_state_changes(self, listener, process, [lldb.eStateRunning]) # make sure to detach while in running state (r204759) self.runCmd("detach") lldbutil.expect_state_changes(self, listener, process, [lldb.eStateDetached])
def process_attach_continue_interrupt_detach(self): """Test attach/continue/interrupt/detach""" exe = self.getBuildArtifact(exe_name) popen = self.spawnSubprocess(exe) self.runCmd("process attach -p " + str(popen.pid)) self.setAsync(True) listener = self.dbg.GetListener() process = self.dbg.GetSelectedTarget().GetProcess() self.runCmd("c") lldbutil.expect_state_changes( self, listener, process, [ lldb.eStateRunning]) self.runCmd("process interrupt") lldbutil.expect_state_changes( self, listener, process, [ lldb.eStateStopped]) # be sure to continue/interrupt/continue (r204504) self.runCmd("c") lldbutil.expect_state_changes( self, listener, process, [ lldb.eStateRunning]) self.runCmd("process interrupt") lldbutil.expect_state_changes( self, listener, process, [ lldb.eStateStopped]) # Second interrupt should have no effect. self.expect( "process interrupt", patterns=["Process is not running"], error=True) # check that this breakpoint is auto-cleared on detach (r204752) self.runCmd("br set -f main.cpp -l %u" % (line_number('main.cpp', '// Set breakpoint here'))) self.runCmd("c") lldbutil.expect_state_changes( self, listener, process, [ lldb.eStateRunning, lldb.eStateStopped]) self.expect('br list', 'Breakpoint not hit', substrs=['hit count = 1']) # Make sure the breakpoint is not hit again. self.expect("expr debugger_flag = false", substrs=[" = false"]) self.runCmd("c") lldbutil.expect_state_changes( self, listener, process, [ lldb.eStateRunning]) # make sure to detach while in running state (r204759) self.runCmd("detach") lldbutil.expect_state_changes( self, listener, process, [ lldb.eStateDetached])