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        target = self.createTestTarget()
29
30        # Create any breakpoints we need
31        breakpoint = target.BreakpointCreateBySourceRegex(
32            'break here', lldb.SBFileSpec("main.cpp", False))
33        self.assertTrue(breakpoint, VALID_BREAKPOINT)
34
35        # Ensure we do the expansion with /bin/sh on POSIX.
36        os.environ["SHELL"] = '/bin/sh'
37
38        self.runCmd(
39            "process launch -X true -w %s -- fi*.tx? () > <" %
40            (self.getSourceDir()))
41
42        process = self.process()
43
44        self.assertEquals(process.GetState(), lldb.eStateStopped,
45                        STOPPED_DUE_TO_BREAKPOINT)
46
47        thread = process.GetThreadAtIndex(0)
48
49        self.assertTrue(thread.IsValid(),
50                        "Process stopped at 'main' should have a valid thread")
51
52        stop_reason = thread.GetStopReason()
53
54        self.assertEqual(
55            stop_reason, lldb.eStopReasonBreakpoint,
56            "Thread in process stopped in 'main' should have a stop reason of eStopReasonBreakpoint")
57
58        self.expect_var_path("argv[1]", summary='"file1.txt"')
59        self.expect_var_path("argv[2]", summary='"file2.txt"')
60        self.expect_var_path("argv[3]", summary='"file3.txt"')
61        self.expect_var_path("argv[4]", summary='"file4.txy"')
62        self.expect_var_path("argv[5]", summary='"()"')
63        self.expect_var_path("argv[6]", summary='">"')
64        self.expect_var_path("argv[7]", summary='"<"')
65        self.expect_var_path("argc", value='8')
66
67        self.runCmd("process kill")
68
69        self.runCmd(
70            'process launch -X true -w %s -- "foo bar"' %
71            (self.getSourceDir()))
72
73        process = self.process()
74
75        self.assertEquals(process.GetState(), lldb.eStateStopped,
76                        STOPPED_DUE_TO_BREAKPOINT)
77
78        thread = process.GetThreadAtIndex(0)
79
80        self.assertTrue(thread.IsValid(),
81                        "Process stopped at 'main' should have a valid thread")
82
83        stop_reason = thread.GetStopReason()
84
85        self.assertEqual(
86            stop_reason, lldb.eStopReasonBreakpoint,
87            "Thread in process stopped in 'main' should have a stop reason of eStopReasonBreakpoint")
88
89        self.expect("frame variable argv[1]", substrs=['foo bar'])
90
91        self.runCmd("process kill")
92
93        self.runCmd('process launch -X true -w %s -- foo\ bar'
94                    % (self.getBuildDir()))
95
96        process = self.process()
97
98        self.assertEquals(process.GetState(), lldb.eStateStopped,
99                        STOPPED_DUE_TO_BREAKPOINT)
100
101        thread = process.GetThreadAtIndex(0)
102
103        self.assertTrue(thread.IsValid(),
104                        "Process stopped at 'main' should have a valid thread")
105
106        stop_reason = thread.GetStopReason()
107
108        self.assertEqual(
109            stop_reason, lldb.eStopReasonBreakpoint,
110            "Thread in process stopped in 'main' should have a stop reason of eStopReasonBreakpoint")
111
112        self.expect("frame variable argv[1]", substrs=['foo bar'])
113