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 llvm.org/pr48349") 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_var_path("argv[1]", summary='"file1.txt"') 64 self.expect_var_path("argv[2]", summary='"file2.txt"') 65 self.expect_var_path("argv[3]", summary='"file3.txt"') 66 self.expect_var_path("argv[4]", summary='"file4.txy"') 67 self.expect_var_path("argv[5]", summary='"()"') 68 self.expect_var_path("argv[6]", summary='">"') 69 self.expect_var_path("argv[7]", summary='"<"') 70 self.expect_var_path("argc", value='8') 71 72 self.runCmd("process kill") 73 74 self.runCmd( 75 'process launch -X true -w %s -- "foo bar"' % 76 (self.getSourceDir())) 77 78 process = self.process() 79 80 self.assertEquals(process.GetState(), lldb.eStateStopped, 81 STOPPED_DUE_TO_BREAKPOINT) 82 83 thread = process.GetThreadAtIndex(0) 84 85 self.assertTrue(thread.IsValid(), 86 "Process stopped at 'main' should have a valid thread") 87 88 stop_reason = thread.GetStopReason() 89 90 self.assertTrue( 91 stop_reason == lldb.eStopReasonBreakpoint, 92 "Thread in process stopped in 'main' should have a stop reason of eStopReasonBreakpoint") 93 94 self.expect("frame variable argv[1]", substrs=['foo bar']) 95 96 self.runCmd("process kill") 97 98 self.runCmd('process launch -X true -w %s -- foo\ bar' 99 % (self.getBuildDir())) 100 101 process = self.process() 102 103 self.assertEquals(process.GetState(), lldb.eStateStopped, 104 STOPPED_DUE_TO_BREAKPOINT) 105 106 thread = process.GetThreadAtIndex(0) 107 108 self.assertTrue(thread.IsValid(), 109 "Process stopped at 'main' should have a valid thread") 110 111 stop_reason = thread.GetStopReason() 112 113 self.assertTrue( 114 stop_reason == lldb.eStopReasonBreakpoint, 115 "Thread in process stopped in 'main' should have a stop reason of eStopReasonBreakpoint") 116 117 self.expect("frame variable argv[1]", substrs=['foo bar']) 118