1"""
2Test that argdumper is a viable launching strategy.
3"""
4
5
6import lldb
7from lldbsuite.test.decorators import *
8from lldbsuite.test.lldbtest import *
9from lldbsuite.test import lldbutil
10
11
12class TestRerun(TestBase):
13
14    def test(self):
15        self.build()
16        exe = self.getBuildArtifact("a.out")
17
18        self.runCmd("target create %s" % exe)
19
20        # Create the target
21        target = self.dbg.CreateTarget(exe)
22
23        # Create any breakpoints we need
24        breakpoint = target.BreakpointCreateBySourceRegex(
25            'break here', lldb.SBFileSpec("main.cpp", False))
26        self.assertTrue(breakpoint, VALID_BREAKPOINT)
27
28        self.runCmd("process launch 1 2 3")
29
30        process = self.process()
31        thread = lldbutil.get_one_thread_stopped_at_breakpoint(
32            process, breakpoint)
33        self.assertIsNotNone(
34            thread, "Process should be stopped at a breakpoint in main")
35        self.assertTrue(thread.IsValid(), "Stopped thread is not valid")
36
37        self.expect("frame variable argv[1]", substrs=['1'])
38        self.expect("frame variable argv[2]", substrs=['2'])
39        self.expect("frame variable argv[3]", substrs=['3'])
40
41        # Let program exit
42        self.runCmd("continue")
43
44        # Re-run with no args and make sure we still run with 1 2 3 as arguments as
45        # they should have been stored in "target.run-args"
46        self.runCmd("process launch")
47
48        process = self.process()
49        thread = lldbutil.get_one_thread_stopped_at_breakpoint(
50            process, breakpoint)
51
52        self.assertIsNotNone(
53            thread, "Process should be stopped at a breakpoint in main")
54        self.assertTrue(thread.IsValid(), "Stopped thread is not valid")
55
56        self.expect("frame variable argv[1]", substrs=['1'])
57        self.expect("frame variable argv[2]", substrs=['2'])
58        self.expect("frame variable argv[3]", substrs=['3'])
59