summaryrefslogtreecommitdiffstats
path: root/lldb/test/functionalities/attach_resume/TestAttachResume.py
blob: b79633ddb2b5627a68e9b6c88201925757c9eb4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"""
Test process attach/resume.
"""

import os, time
import unittest2
import lldb
from lldbtest import *
import lldbutil

exe_name = "AttachResume"  # Must match Makefile

class AttachResumeTestCase(TestBase):

    mydir = TestBase.compute_mydir(__file__)

    @dwarf_test
    def test_attach_continue_interrupt_detach(self):
        """Test attach/continue/interrupt/detach"""
        self.buildDwarf()
        self.process_attach_continue_interrupt_detach()

    def process_attach_continue_interrupt_detach(self):
        """Test attach/continue/interrupt/detach"""

        exe = os.path.join(os.getcwd(), exe_name)

        popen = self.spawnSubprocess(exe)
        self.addTearDownHook(self.cleanupSubprocesses)

        self.runCmd("process attach -p " + str(popen.pid))

        self._state = 0
        def process_events():
            event = lldb.SBEvent()
            while self.dbg.GetListener().GetNextEvent(event):
                self._state = lldb.SBProcess.GetStateFromEvent(event)

        # using process.GetState() does not work: llvm.org/pr16172
        def wait_for_state(s, timeout=5):
            t = 0
            period = 0.1
            while self._state != s:
                process_events()
                time.sleep(period)
                t += period
                if t > timeout:
                    return False
            return True

        self.setAsync(True)

        self.runCmd("c")
        self.assertTrue(wait_for_state(lldb.eStateRunning),
            'Process not running after continue')

        self.runCmd("process interrupt")
        self.assertTrue(wait_for_state(lldb.eStateStopped),
            'Process not stopped after interrupt')

        # be sure to continue/interrupt/continue (r204504)
        self.runCmd("c")
        self.assertTrue(wait_for_state(lldb.eStateRunning),
            'Process not running after continue')

        self.runCmd("process interrupt")
        self.assertTrue(wait_for_state(lldb.eStateStopped),
            'Process not stopped after interrupt')

        # check that this breakpoint is auto-cleared on detach (r204752)
        self.runCmd("br set -f main.c -l 12")

        self.runCmd("c")
        self.assertTrue(wait_for_state(lldb.eStateRunning),
            'Process not running after continue')

        self.assertTrue(wait_for_state(lldb.eStateStopped),
            'Process not stopped after breakpoint')
        self.expect('br list', 'Breakpoint not hit',
            patterns = ['hit count = 1'])

        self.runCmd("c")
        self.assertTrue(wait_for_state(lldb.eStateRunning),
            'Process not running after continue')

        # make sure to detach while in running state (r204759)
        self.runCmd("detach")
        self.assertTrue(wait_for_state(lldb.eStateDetached),
            'Process not detached after detach')

if __name__ == '__main__':
    import atexit
    lldb.SBDebugger.Initialize()
    atexit.register(lambda: lldb.SBDebugger.Terminate())
    unittest2.main()
OpenPOWER on IntegriCloud