def test_lldbmi_stopped_when_stopatentry_remote(self): """Test that 'lldb-mi --interpreter' notifies after it was stopped on entry (remote).""" # Prepare debugserver import lldbgdbserverutils debugserver_exe = lldbgdbserverutils.get_debugserver_exe() if not debugserver_exe: self.skipTest("debugserver exe not found") hostname = "localhost" import random port = 12000 + random.randint(0,3999) # the same as GdbRemoteTestCaseBase.get_next_port import pexpect debugserver_child = pexpect.spawn("%s %s:%d" % (debugserver_exe, hostname, port)) self.addTearDownHook(lambda: debugserver_child.terminate(force = True)) self.spawnLldbMi(args = None) # Connect to debugserver self.runCmd("-interpreter-exec command \"platform select remote-macosx --sysroot /\"") self.expect("\^done") self.runCmd("-file-exec-and-symbols %s" % self.myexe) self.expect("\^done") self.runCmd("-interpreter-exec command \"process connect connect://%s:%d\"" % (hostname, port)) self.expect("\^done") # Run with stop-at-entry flag self.runCmd("-interpreter-exec command \"process launch -s\"") self.expect("\^done") # Test that *stopped is printed self.expect("\*stopped,reason=\"signal-received\",signal-name=\"SIGSTOP\",signal-meaning=\"Stop\",.+?thread-id=\"1\",stopped-threads=\"all\"") # Exit self.runCmd("-gdb-exit") self.expect("\^exit")
def setup_remote_platform(self): return self.build() exe = self.getBuildArtifact('a.out') # Launch our test binary. # Attach to it with debugserver. debugserver = get_debugserver_exe() debugserver_args = ['localhost:{}'.format(self.PORT)] self.spawnSubprocess(debugserver, debugserver_args) # Select the platform. self.expect('platform select remote-macosx', substrs=[sdk_dir]) # Connect to debugserver interpreter = self.dbg.GetCommandInterpreter() connected = False for i in range(self.ATTEMPTS): result = lldb.SBCommandReturnObject() interpreter.HandleCommand('gdb-remote {}'.format(self.PORT), result) connected = result.Succeeded() if connected: break time.sleep(self.TIMEOUT) self.assertTrue(connected, "could not connect to debugserver")
def test_lldbmi_stopped_when_segfault_remote(self): """Test that 'lldb-mi --interpreter' notifies after it was stopped when segfault occurred (remote).""" # Prepare debugserver import lldbgdbserverutils debugserver_exe = lldbgdbserverutils.get_debugserver_exe() if not debugserver_exe: raise Exception("debugserver not found") hostname = "localhost" import random port = 12000 + random.randint( 0, 3999) # the same as GdbRemoteTestCaseBase.get_next_port import pexpect debugserver_child = pexpect.spawn("%s %s:%d" % (debugserver_exe, hostname, port)) self.spawnLldbMi(args=None) # Connect to debugserver self.runCmd( "-interpreter-exec command \"platform select remote-macosx --sysroot /\"" ) self.expect("\^done") self.runCmd("-file-exec-and-symbols %s" % self.myexe) self.expect("\^done") self.runCmd( "-interpreter-exec command \"process connect connect://%s:%d\"" % (hostname, port)) self.expect("\^done") try: # Run to main self.runCmd("-break-insert -f main") self.expect("\^done,bkpt={number=\"1\"") #FIXME -exec-run doesn't work self.runCmd("-interpreter-exec command \"process launch\"" ) #FIXME: self.runCmd("-exec-run") self.expect("\^done") #FIXME: self.expect("\^running") self.expect("\*stopped,reason=\"breakpoint-hit\"") # Set do_segfault=1 and run (to cause a segfault error) self.runCmd("-data-evaluate-expression \"do_segfault=1\"") self.expect("\^done,value=\"1\"") self.runCmd("-exec-continue") self.expect("\^running") # Test that *stopped is printed self.expect( "\*stopped,reason=\"exception-received\",exception=\"EXC_BAD_ACCESS \(code=1, address=0x0\)\",thread-id=\"1\",stopped-threads=\"all\"" ) # Exit self.runCmd("-gdb-exit") self.expect("\^exit") finally: # Clean up debugserver_child.terminate(force=True)
def test_lldbmi_stopped_when_segfault_remote(self): """Test that 'lldb-mi --interpreter' notifies after it was stopped when segfault occurred (remote).""" # Prepare debugserver import lldbgdbserverutils debugserver_exe = lldbgdbserverutils.get_debugserver_exe() if not debugserver_exe: self.skipTest("debugserver exe not found") hostname = "localhost" import random # the same as GdbRemoteTestCaseBase.get_next_port port = 12000 + random.randint(0, 3999) import pexpect debugserver_child = pexpect.spawn( "%s %s:%d" % (debugserver_exe, hostname, port)) self.addTearDownHook(lambda: debugserver_child.terminate(force=True)) self.spawnLldbMi(args=None) # Connect to debugserver self.runCmd( "-interpreter-exec command \"platform select remote-macosx --sysroot /\"") self.expect("\^done") self.runCmd("-file-exec-and-symbols %s" % self.myexe) self.expect("\^done") self.runCmd( "-interpreter-exec command \"process connect connect://%s:%d\"" % (hostname, port)) self.expect("\^done") # Run to main self.runCmd("-break-insert -f main") self.expect("\^done,bkpt={number=\"1\"") # FIXME -exec-run doesn't work # FIXME: self.runCmd("-exec-run") self.runCmd("-interpreter-exec command \"process launch\"") self.expect("\^done") # FIXME: self.expect("\^running") self.expect("\*stopped,reason=\"breakpoint-hit\"") # Set do_segfault=1 and run (to cause a segfault error) self.runCmd("-data-evaluate-expression \"do_segfault=1\"") self.expect("\^done,value=\"1\"") self.runCmd("-exec-continue") self.expect("\^running") # Test that *stopped is printed self.expect( "\*stopped,reason=\"exception-received\",exception=\"EXC_BAD_ACCESS \(code=1, address=0x0\)\",thread-id=\"1\",stopped-threads=\"all\"") # Exit self.runCmd("-gdb-exit") self.expect("\^exit")
def test_lldbmi_stopped_when_stopatentry_remote(self): """Test that 'lldb-mi --interpreter' notifies after it was stopped on entry (remote).""" # Prepare debugserver sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "lldb-server"))) import lldbgdbserverutils debugserver_exe = lldbgdbserverutils.get_debugserver_exe() if not debugserver_exe: raise Exception("debugserver not found") hostname = "localhost" import random port = 12000 + random.randint(0,3999) # the same as GdbRemoteTestCaseBase.get_next_port import pexpect debugserver_child = pexpect.spawn("%s %s:%d" % (debugserver_exe, hostname, port)) self.spawnLldbMi(args = None) # Connect to debugserver self.runCmd("-interpreter-exec command \"platform select remote-macosx --sysroot /\"") self.expect("\^done") self.runCmd("-file-exec-and-symbols %s" % self.myexe) self.expect("\^done") self.runCmd("-interpreter-exec command \"process connect connect://%s:%d\"" % (hostname, port)) self.expect("\^done") try: # Run with stop-at-entry flag self.runCmd("-interpreter-exec command \"process launch -s\"") self.expect("\^done") # Test that *stopped is printed self.expect("\*stopped,reason=\"signal-received\",signal-name=\"SIGINT\",signal-meaning=\"Interrupt\",.*thread-id=\"1\",stopped-threads=\"all\"") # Exit self.runCmd("-gdb-exit") self.expect("\^exit") finally: # Clean up debugserver_child.terminate(force = True)
def test_macos_sdk(self): self.build() exe = self.getBuildArtifact('a.out') token = self.getBuildArtifact('token') # Remove the old token. try: os.remove(token) except: pass # Create a fake 'SDK' directory. test_home = os.path.join(self.getBuildDir(), 'fake_home.noindex') macos_version = platform.mac_ver()[0] sdk_dir = os.path.join(test_home, 'Library', 'Developer', 'Xcode', 'macOS DeviceSupport', macos_version) symbols_dir = os.path.join(sdk_dir, 'Symbols') lldbutil.mkdir_p(symbols_dir) # Save the current home directory and restore it afterwards. old_home = os.getenv('HOME') def cleanup(): if not old_home: del os.environ['HOME'] else: os.environ['HOME'] = old_home self.addTearDownHook(cleanup) os.environ['HOME'] = test_home # Launch our test binary. inferior = self.spawnSubprocess(exe, [token]) pid = inferior.pid # Wait for the binary to launch. lldbutil.wait_for_file_on_target(self, token) # Move the binary into the 'SDK'. rel_exe_path = os.path.relpath(exe, '/') exe_sdk_path = os.path.join(symbols_dir, rel_exe_path) lldbutil.mkdir_p(os.path.dirname(exe_sdk_path)) shutil.move(exe, exe_sdk_path) # Attach to it with debugserver. debugserver = get_debugserver_exe() debugserver_args = [ 'localhost:{}'.format(self.PORT), '--attach={}'.format(pid) ] self.spawnSubprocess(debugserver, debugserver_args) # Select the platform. self.expect('platform select remote-macosx', substrs=[sdk_dir]) # Connect to debugserver interpreter = self.dbg.GetCommandInterpreter() connected = False for i in range(self.ATTEMPTS): result = lldb.SBCommandReturnObject() interpreter.HandleCommand('gdb-remote {}'.format(self.PORT), result) connected = result.Succeeded() if connected: break time.sleep(self.TIMEOUT) self.assertTrue(connected, "could not connect to debugserver") # Make sure the image was loaded from the 'SDK'. self.expect('image list', substrs=[exe_sdk_path])
def no_debugserver(self): if get_debugserver_exe() is None: return 'no debugserver' return None