1"""
2Test process attach/resume.
3"""
4
5
6
7import lldb
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10from lldbsuite.test import lldbutil
11
12exe_name = "AttachResume"  # Must match Makefile
13
14
15class AttachResumeTestCase(TestBase):
16
17    mydir = TestBase.compute_mydir(__file__)
18    NO_DEBUG_INFO_TESTCASE = True
19
20    @skipIfRemote
21    @expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr19310')
22    @expectedFailureNetBSD
23    @skipIfWindows # llvm.org/pr24778, llvm.org/pr21753
24    @skipIfReproducer # Unexpected packet during replay
25    def test_attach_continue_interrupt_detach(self):
26        """Test attach/continue/interrupt/detach"""
27        self.build()
28        self.process_attach_continue_interrupt_detach()
29
30    def process_attach_continue_interrupt_detach(self):
31        """Test attach/continue/interrupt/detach"""
32
33        exe = self.getBuildArtifact(exe_name)
34
35        popen = self.spawnSubprocess(exe)
36        self.addTearDownHook(self.cleanupSubprocesses)
37
38        self.runCmd("process attach -p " + str(popen.pid))
39
40        self.setAsync(True)
41        listener = self.dbg.GetListener()
42        process = self.dbg.GetSelectedTarget().GetProcess()
43
44        self.runCmd("c")
45        lldbutil.expect_state_changes(
46            self, listener, process, [
47                lldb.eStateRunning])
48
49        self.runCmd("process interrupt")
50        lldbutil.expect_state_changes(
51            self, listener, process, [
52                lldb.eStateStopped])
53
54        # be sure to continue/interrupt/continue (r204504)
55        self.runCmd("c")
56        lldbutil.expect_state_changes(
57            self, listener, process, [
58                lldb.eStateRunning])
59
60        self.runCmd("process interrupt")
61        lldbutil.expect_state_changes(
62            self, listener, process, [
63                lldb.eStateStopped])
64
65        # Second interrupt should have no effect.
66        self.expect(
67            "process interrupt",
68            patterns=["Process is not running"],
69            error=True)
70
71        # check that this breakpoint is auto-cleared on detach (r204752)
72        self.runCmd("br set -f main.cpp -l %u" %
73                    (line_number('main.cpp', '// Set breakpoint here')))
74
75        self.runCmd("c")
76        lldbutil.expect_state_changes(
77            self, listener, process, [
78                lldb.eStateRunning, lldb.eStateStopped])
79        self.expect('br list', 'Breakpoint not hit',
80                    substrs=['hit count = 1'])
81
82        # Make sure the breakpoint is not hit again.
83        self.expect("expr debugger_flag = false", substrs=[" = false"])
84
85        self.runCmd("c")
86        lldbutil.expect_state_changes(
87            self, listener, process, [
88                lldb.eStateRunning])
89
90        # make sure to detach while in running state (r204759)
91        self.runCmd("detach")
92        lldbutil.expect_state_changes(
93            self, listener, process, [
94                lldb.eStateDetached])
95