summaryrefslogtreecommitdiffstats
path: root/lldb/test/global_variables/TestGlobalVariables.py
blob: ceb7c4dfc34eee6137d1e17c36a1d7e232e276c2 (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
"""Show global variables and check that they do indeed have global scopes."""

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

class TestGlobalVariables(TestBase):

    mydir = "global_variables"

    def test_global_variables(self):
        """Test 'variable list -s -a' which omits args and shows scopes."""
        res = self.res
        exe = os.path.join(os.getcwd(), "a.out")
        self.ci.HandleCommand("file " + exe, res)
        self.assertTrue(res.Succeeded(), CURRENT_EXECUTABLE_SET)

        # Break inside the main.
        self.ci.HandleCommand("breakpoint set -f main.c -l 20", res)
        self.assertTrue(res.Succeeded())
        self.assertTrue(res.GetOutput().startswith(
            "Breakpoint created: 1: file ='main.c', line = 20, locations = 1"),
                        BREAKPOINT_CREATED)

        self.ci.HandleCommand("run", res)
        self.runStarted = True
        self.assertTrue(res.Succeeded(), RUN_STOPPED)

        # The stop reason of the thread should be breakpoint.
        self.ci.HandleCommand("thread list", res)
        #print "thread list ->", res.GetOutput()
        self.assertTrue(res.Succeeded(), CMD_MSG('thread list'))
        self.assertTrue(res.GetOutput().find('state is Stopped') > 0 and
                        res.GetOutput().find('stop reason = breakpoint') > 0,
                        STOPPED_DUE_TO_BREAKPOINT)

        # The breakpoint should have a hit count of 1.
        self.ci.HandleCommand("breakpoint list", res)
        self.assertTrue(res.Succeeded())
        self.assertTrue(res.GetOutput().find(' resolved, hit count = 1') > 0,
                        BREAKPOINT_HIT_ONCE)

        # Check that GLOBAL scopes are indicated for the variables.
        self.ci.HandleCommand("variable list -s -a", res);
        self.assertTrue(res.Succeeded())
        output = res.GetOutput()
        self.assertTrue(output.find('GLOBAL: g_file_static_cstr') > 0 and
                        output.find('g_file_static_cstr') > 0 and
                        output.find('GLOBAL: g_file_global_int') > 0 and
                        output.find('(int) 42') > 0 and
                        output.find('GLOBAL: g_file_global_cstr') > 0 and
                        output.find('g_file_global_cstr') > 0,
                        VARIABLES_DISPLAYED_CORRECTLY)


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