1d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen""" 2d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny ChenTest the lldb command line takes a filename with single quote chars. 3d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen""" 4d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen 5d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chenimport os 6d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chenimport unittest2 7d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chenimport lldb 8d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chenimport pexpect 9d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chenfrom lldbtest import * 10d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen 11d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chenclass SingleQuoteInCommandLineTestCase(TestBase): 12d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen 13d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen mydir = os.path.join("functionalities", "single-quote-in-filename-to-lldb") 14d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen myexe = "path with '09/a.out" 15d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen 16d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen @classmethod 17d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen def classCleanup(cls): 18d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen """Cleanup the test byproducts.""" 19ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata try: 20ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata os.remove("child_send.txt") 21ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata os.remove("child_read.txt") 22ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata os.remove(cls.myexe) 23ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata except: 24ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata pass 25d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen 266bc4dcdfbcdfa455299d2123011b82a77351ee72Daniel Malea @skipIfLinux # llvm.org/pr14637: this test case fails sometimes because the input prompt "(lldb)" is missing 27d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen def test_lldb_invocation_with_single_quote_in_filename(self): 28d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen """Test that 'lldb my_file_name' works where my_file_name is a string with a single quote char in it.""" 29d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen self.buildDefault() 30d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen system(["/bin/sh", "-c", "cp a.out \"%s\"" % self.myexe]) 31d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen 32d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen # The default lldb prompt. 33d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen prompt = "(lldb) " 34d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen 35d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen # So that the child gets torn down after the test. 36d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen self.child = pexpect.spawn('%s %s "%s"' % (self.lldbHere, self.lldbOption, self.myexe)) 37d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen child = self.child 38d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen child.setecho(True) 39d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen # Turn on logging for input/output to/from the child. 40d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen with open('child_send.txt', 'w') as f_send: 41d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen with open('child_read.txt', 'w') as f_read: 42d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen child.logfile_send = f_send 43d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen child.logfile_read = f_read 44d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen 45d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen child.expect_exact(prompt) 46d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen 47d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen child.send("help watchpoint") 48d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen child.sendline('') 49d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen child.expect_exact(prompt) 50d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen 51d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen # Now that the necessary logging is done, restore logfile to None to 52d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen # stop further logging. 53d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen child.logfile_send = None 54d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen child.logfile_read = None 55d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen 56d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen with open('child_send.txt', 'r') as fs: 57d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen if self.TraceOn(): 58d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen print "\n\nContents of child_send.txt:" 59d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen print fs.read() 60d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen with open('child_read.txt', 'r') as fr: 61d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen from_child = fr.read() 62d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen if self.TraceOn(): 63d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen print "\n\nContents of child_read.txt:" 64d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen print from_child 65d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen 66d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen self.expect(from_child, exe=False, 67d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen substrs = ["Current executable set to"]) 68d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen 69d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen 70d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chenif __name__ == '__main__': 71d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen import atexit 72d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen lldb.SBDebugger.Initialize() 73d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen atexit.register(lambda: lldb.SBDebugger.Terminate()) 74d1e0829de2ab90cb34d13b2776d3be3977355e5aJohnny Chen unittest2.main() 75