File: TestVarPath.py

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (123 lines) | stat: -rw-r--r-- 4,714 bytes parent folder | download | duplicates (8)
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
"""
Make sure the getting a variable path works and doesn't crash.
"""


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


class TestVarPath(TestBase):
    # If your test case doesn't stress debug info, then
    # set this to true.  That way it won't be run once for
    # each debug info format.
    NO_DEBUG_INFO_TESTCASE = True

    def test_frame_var(self):
        self.build()
        self.do_test()

    def verify_point(self, frame, var_name, var_typename, x_value, y_value):
        v = frame.GetValueForVariablePath(var_name)
        self.assertSuccess(v.GetError(), "Make sure we find '%s'" % (var_name))
        self.assertEqual(
            v.GetType().GetName(),
            var_typename,
            "Make sure '%s' has type '%s'" % (var_name, var_typename),
        )

        if "*" in var_typename:
            valid_prefix = var_name + "->"
            invalid_prefix = var_name + "."
        else:
            valid_prefix = var_name + "."
            invalid_prefix = var_name + "->"

        valid_x_path = valid_prefix + "x"
        valid_y_path = valid_prefix + "y"
        invalid_x_path = invalid_prefix + "x"
        invalid_y_path = invalid_prefix + "y"
        invalid_m_path = invalid_prefix + "m"

        v = frame.GetValueForVariablePath(valid_x_path)
        self.assertSuccess(v.GetError(), "Make sure we find '%s'" % (valid_x_path))
        self.assertEqual(
            v.GetValue(),
            str(x_value),
            "Make sure '%s' has a value of %i" % (valid_x_path, x_value),
        )
        self.assertEqual(
            v.GetType().GetName(),
            "int",
            "Make sure '%s' has type 'int'" % (valid_x_path),
        )
        v = frame.GetValueForVariablePath(invalid_x_path)
        self.assertTrue(
            v.GetError().Fail(), "Make sure we don't find '%s'" % (invalid_x_path)
        )

        v = frame.GetValueForVariablePath(valid_y_path)
        self.assertSuccess(v.GetError(), "Make sure we find '%s'" % (valid_y_path))
        self.assertEqual(
            v.GetValue(),
            str(y_value),
            "Make sure '%s' has a value of %i" % (valid_y_path, y_value),
        )
        self.assertEqual(
            v.GetType().GetName(),
            "int",
            "Make sure '%s' has type 'int'" % (valid_y_path),
        )
        v = frame.GetValueForVariablePath(invalid_y_path)
        self.assertTrue(
            v.GetError().Fail(), "Make sure we don't find '%s'" % (invalid_y_path)
        )

        v = frame.GetValueForVariablePath(invalid_m_path)
        self.assertTrue(
            v.GetError().Fail(), "Make sure we don't find '%s'" % (invalid_m_path)
        )

    def do_test(self):
        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
            self, "// Set a breakpoint here", lldb.SBFileSpec("main.cpp")
        )

        frame = thread.GetFrameAtIndex(0)
        v = frame.GetValueForVariablePath("no_such_variable")
        self.assertTrue(
            v.GetError().Fail(), "Make sure we don't find 'no_such_variable'"
        )

        # Test an instance
        self.verify_point(frame, "pt", "Point", 1, 2)
        # Test a pointer
        self.verify_point(frame, "pt_ptr", "Point *", 3030, 4040)
        # Test using a pointer as an array
        self.verify_point(frame, "pt_ptr[-1]", "Point", 1010, 2020)
        self.verify_point(frame, "pt_ptr[0]", "Point", 3030, 4040)
        self.verify_point(frame, "pt_ptr[1]", "Point", 5050, 6060)
        # Test arrays
        v = frame.GetValueForVariablePath("points")
        self.assertSuccess(v.GetError(), "Make sure we find 'points'")
        self.verify_point(frame, "points[0]", "Point", 1010, 2020)
        self.verify_point(frame, "points[1]", "Point", 3030, 4040)
        self.verify_point(frame, "points[2]", "Point", 5050, 6060)
        v = frame.GetValueForVariablePath("points[0]+5")
        self.assertTrue(
            v.GetError().Fail(),
            "Make sure we do not ignore characters between ']' and the end",
        )
        # Test a reference
        self.verify_point(frame, "pt_ref", "Point &", 1, 2)
        v = frame.GetValueForVariablePath("pt_sp")
        self.assertSuccess(v.GetError(), "Make sure we find 'pt_sp'")
        # Make sure we don't crash when looking for non existant child
        # in type with synthetic children. This used to cause a crash.
        if not self.isAArch64Windows():
            v = frame.GetValueForVariablePath("pt_sp->not_valid_child")
            self.assertTrue(
                v.GetError().Fail(), "Make sure we don't find 'pt_sp->not_valid_child'"
            )