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