1""" 2Test that argdumper is a viable launching strategy. 3""" 4import os 5 6 7import lldb 8from lldbsuite.test.decorators import * 9from lldbsuite.test.lldbtest import * 10from lldbsuite.test import lldbutil 11 12 13class LaunchWithShellExpandTestCase(TestBase): 14 15 mydir = TestBase.compute_mydir(__file__) 16 NO_DEBUG_INFO_TESTCASE = True 17 18 @expectedFailureAll( 19 oslist=[ 20 "windows", 21 "linux", 22 "freebsd"], 23 bugnumber="llvm.org/pr24778 llvm.org/pr22627") 24 @skipIfDarwinEmbedded # iOS etc don't launch the binary via a shell, so arg expansion won't happen 25 @expectedFailureNetBSD 26 def test(self): 27 self.build() 28 exe = self.getBuildArtifact("a.out") 29 30 self.runCmd("target create %s" % exe) 31 32 # Create the target 33 target = self.dbg.CreateTarget(exe) 34 35 # Create any breakpoints we need 36 breakpoint = target.BreakpointCreateBySourceRegex( 37 'break here', lldb.SBFileSpec("main.cpp", False)) 38 self.assertTrue(breakpoint, VALID_BREAKPOINT) 39 40 # Ensure we do the expansion with /bin/sh on POSIX. 41 os.environ["SHELL"] = '/bin/sh' 42 43 self.runCmd( 44 "process launch -X true -w %s -- fi*.tx? () > <" % 45 (self.getSourceDir())) 46 47 process = self.process() 48 49 self.assertEquals(process.GetState(), lldb.eStateStopped, 50 STOPPED_DUE_TO_BREAKPOINT) 51 52 thread = process.GetThreadAtIndex(0) 53 54 self.assertTrue(thread.IsValid(), 55 "Process stopped at 'main' should have a valid thread") 56 57 stop_reason = thread.GetStopReason() 58 59 self.assertTrue( 60 stop_reason == lldb.eStopReasonBreakpoint, 61 "Thread in process stopped in 'main' should have a stop reason of eStopReasonBreakpoint") 62 63 self.expect("frame variable argv[1]", substrs=['file1.txt']) 64 self.expect("frame variable argv[2]", substrs=['file2.txt']) 65 self.expect("frame variable argv[3]", substrs=['file3.txt']) 66 self.expect("frame variable argv[4]", substrs=['file4.txy']) 67 self.expect("frame variable argv[5]", substrs=['()']) 68 self.expect("frame variable argv[6]", substrs=['>']) 69 self.expect("frame variable argv[7]", substrs=['<']) 70 self.expect( 71 "frame variable argv[5]", 72 substrs=['file5.tyx'], 73 matching=False) 74 self.expect( 75 "frame variable argv[8]", 76 substrs=['file5.tyx'], 77 matching=False) 78 79 self.runCmd("process kill") 80 81 self.runCmd( 82 'process launch -X true -w %s -- "foo bar"' % 83 (self.getSourceDir())) 84 85 process = self.process() 86 87 self.assertEquals(process.GetState(), lldb.eStateStopped, 88 STOPPED_DUE_TO_BREAKPOINT) 89 90 thread = process.GetThreadAtIndex(0) 91 92 self.assertTrue(thread.IsValid(), 93 "Process stopped at 'main' should have a valid thread") 94 95 stop_reason = thread.GetStopReason() 96 97 self.assertTrue( 98 stop_reason == lldb.eStopReasonBreakpoint, 99 "Thread in process stopped in 'main' should have a stop reason of eStopReasonBreakpoint") 100 101 self.expect("frame variable argv[1]", substrs=['foo bar']) 102 103 self.runCmd("process kill") 104 105 self.runCmd('process launch -X true -w %s -- foo\ bar' 106 % (self.getBuildDir())) 107 108 process = self.process() 109 110 self.assertEquals(process.GetState(), lldb.eStateStopped, 111 STOPPED_DUE_TO_BREAKPOINT) 112 113 thread = process.GetThreadAtIndex(0) 114 115 self.assertTrue(thread.IsValid(), 116 "Process stopped at 'main' should have a valid thread") 117 118 stop_reason = thread.GetStopReason() 119 120 self.assertTrue( 121 stop_reason == lldb.eStopReasonBreakpoint, 122 "Thread in process stopped in 'main' should have a stop reason of eStopReasonBreakpoint") 123 124 self.expect("frame variable argv[1]", substrs=['foo bar']) 125