summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test/functionalities/type_completion/TestTypeCompletion.py
blob: e08f4be08942144e8cf46462a240dea182dccdc9 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
"""
Check that types only get completed when necessary.
"""

from __future__ import print_function


import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class TypeCompletionTestCase(TestBase):

    mydir = TestBase.compute_mydir(__file__)

    @expectedFailureAll(
        compiler="icc",
        bugnumber="often fails with 'NameAndAddress should be valid.")
    # Fails with gcc 4.8.1 with llvm.org/pr15301 LLDB prints incorrect sizes
    # of STL containers
    def test_with_run_command(self):
        """Check that types only get completed when necessary."""
        self.build()
        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)

        lldbutil.run_break_set_by_source_regexp(
            self, "// Set break point at this line.")

        self.runCmd("run", RUN_SUCCEEDED)

        # The stop reason of the thread should be breakpoint.
        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
                    substrs=['stopped',
                             'stop reason = breakpoint'])

        # This is the function to remove the custom formats in order to have a
        # clean slate for the next test case.
        def cleanup():
            self.runCmd('type category enable -l c++', check=False)

        self.runCmd('type category disable -l c++', check=False)

        # Execute the cleanup function during test case tear down.
        self.addTearDownHook(cleanup)

        p_vector = self.dbg.GetSelectedTarget().GetProcess(
        ).GetSelectedThread().GetSelectedFrame().FindVariable('p')
        p_type = p_vector.GetType()
        self.assertFalse(
            p_type.IsTypeComplete(),
            'vector<T> complete but it should not be')

        self.runCmd("continue")

        p_vector = self.dbg.GetSelectedTarget().GetProcess(
        ).GetSelectedThread().GetSelectedFrame().FindVariable('p')
        p_type = p_vector.GetType()
        self.assertFalse(
            p_type.IsTypeComplete(),
            'vector<T> complete but it should not be')

        self.runCmd("continue")

        self.runCmd("frame variable p --show-types")

        p_vector = self.dbg.GetSelectedTarget().GetProcess(
        ).GetSelectedThread().GetSelectedFrame().FindVariable('p')
        p_type = p_vector.GetType()
        self.assertTrue(
            p_type.IsTypeComplete(),
            'vector<T> should now be complete')
        name_address_type = p_type.GetTemplateArgumentType(0)
        self.assertTrue(
            name_address_type.IsValid(),
            'NameAndAddress should be valid')
        self.assertFalse(
            name_address_type.IsTypeComplete(),
            'NameAndAddress complete but it should not be')

        self.runCmd("continue")

        self.runCmd("frame variable guy --show-types")

        p_vector = self.dbg.GetSelectedTarget().GetProcess(
        ).GetSelectedThread().GetSelectedFrame().FindVariable('p')
        p_type = p_vector.GetType()
        self.assertTrue(
            p_type.IsTypeComplete(),
            'vector<T> should now be complete')
        name_address_type = p_type.GetTemplateArgumentType(0)
        self.assertTrue(
            name_address_type.IsValid(),
            'NameAndAddress should be valid')
        self.assertTrue(
            name_address_type.IsTypeComplete(),
            'NameAndAddress should now be complete')
        field0 = name_address_type.GetFieldAtIndex(0)
        self.assertTrue(
            field0.IsValid(),
            'NameAndAddress::m_name should be valid')
        string = field0.GetType().GetPointeeType()
        self.assertTrue(string.IsValid(), 'CustomString should be valid')
        self.assertFalse(string.IsTypeComplete(),
                         'CustomString complete but it should not be')

        self.runCmd("continue")

        p_vector = self.dbg.GetSelectedTarget().GetProcess(
        ).GetSelectedThread().GetSelectedFrame().FindVariable('p')
        p_type = p_vector.GetType()
        self.assertTrue(
            p_type.IsTypeComplete(),
            'vector<T> should now be complete')
        name_address_type = p_type.GetTemplateArgumentType(0)
        self.assertTrue(
            name_address_type.IsValid(),
            'NameAndAddress should be valid')
        self.assertTrue(
            name_address_type.IsTypeComplete(),
            'NameAndAddress should now be complete')
        field0 = name_address_type.GetFieldAtIndex(0)
        self.assertTrue(
            field0.IsValid(),
            'NameAndAddress::m_name should be valid')
        string = field0.GetType().GetPointeeType()
        self.assertTrue(string.IsValid(), 'CustomString should be valid')
        self.assertFalse(string.IsTypeComplete(),
                         'CustomString complete but it should not be')

        self.runCmd('type category enable -l c++', check=False)
        self.runCmd('frame variable guy --show-types --ptr-depth=1')

        p_vector = self.dbg.GetSelectedTarget().GetProcess(
        ).GetSelectedThread().GetSelectedFrame().FindVariable('p')
        p_type = p_vector.GetType()
        self.assertTrue(
            p_type.IsTypeComplete(),
            'vector<T> should now be complete')
        name_address_type = p_type.GetTemplateArgumentType(0)
        self.assertTrue(
            name_address_type.IsValid(),
            'NameAndAddress should be valid')
        self.assertTrue(
            name_address_type.IsTypeComplete(),
            'NameAndAddress should now be complete')
        field0 = name_address_type.GetFieldAtIndex(0)
        self.assertTrue(
            field0.IsValid(),
            'NameAndAddress::m_name should be valid')
        string = field0.GetType().GetPointeeType()
        self.assertTrue(string.IsValid(), 'CustomString should be valid')
        self.assertTrue(
            string.IsTypeComplete(),
            'CustomString should now be complete')
OpenPOWER on IntegriCloud