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    NO_DEBUG_INFO_TESTCASE = True
17
18    @skipIfRemote
19    @expectedFailureNetBSD
20    @skipIfWindows # llvm.org/pr24778, llvm.org/pr21753
21    def test_attach_continue_interrupt_detach(self):
22        """Test attach/continue/interrupt/detach"""
23        self.build()
24        self.process_attach_continue_interrupt_detach()
25
26    def process_attach_continue_interrupt_detach(self):
27        """Test attach/continue/interrupt/detach"""
28
29        exe = self.getBuildArtifact(exe_name)
30
31        popen = self.spawnSubprocess(exe)
32
33        self.runCmd("process attach -p " + str(popen.pid))
34
35        self.setAsync(True)
36        listener = self.dbg.GetListener()
37        process = self.dbg.GetSelectedTarget().GetProcess()
38
39        self.runCmd("c")
40        lldbutil.expect_state_changes(
41            self, listener, process, [
42                lldb.eStateRunning])
43
44        self.runCmd("process interrupt")
45        lldbutil.expect_state_changes(
46            self, listener, process, [
47                lldb.eStateStopped])
48
49        # be sure to continue/interrupt/continue (r204504)
50        self.runCmd("c")
51        lldbutil.expect_state_changes(
52            self, listener, process, [
53                lldb.eStateRunning])
54
55        self.runCmd("process interrupt")
56        lldbutil.expect_state_changes(
57            self, listener, process, [
58                lldb.eStateStopped])
59
60        # Second interrupt should have no effect.
61        self.expect(
62            "process interrupt",
63            patterns=["Process is not running"],
64            error=True)
65
66        # check that this breakpoint is auto-cleared on detach (r204752)
67        self.runCmd("br set -f main.cpp -l %u" %
68                    (line_number('main.cpp', '// Set breakpoint here')))
69
70        self.runCmd("c")
71        lldbutil.expect_state_changes(
72            self, listener, process, [
73                lldb.eStateRunning, lldb.eStateStopped])
74        self.expect('br list', 'Breakpoint not hit',
75                    substrs=['hit count = 1'])
76
77        # Make sure the breakpoint is not hit again.
78        self.expect("expr debugger_flag = false", substrs=[" = false"])
79
80        self.runCmd("c")
81        lldbutil.expect_state_changes(
82            self, listener, process, [
83                lldb.eStateRunning])
84
85        # make sure to detach while in running state (r204759)
86        self.runCmd("detach")
87        lldbutil.expect_state_changes(
88            self, listener, process, [
89                lldb.eStateDetached])
90