xref: /llvm-project/lldb/test/API/python_api/value/addr_of_void_star/TestValueAPIAddressOfVoidStar.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1import lldb
2from lldbsuite.test.decorators import *
3from lldbsuite.test.lldbtest import *
4from lldbsuite.test import lldbutil
5
6
7class ValueAPIVoidStarTestCase(TestBase):
8    def test(self):
9        self.build()
10
11        target, process, thread, _ = lldbutil.run_to_source_breakpoint(
12            self, "Break at this line", lldb.SBFileSpec("main.c")
13        )
14        frame = thread.GetFrameAtIndex(0)
15
16        # Verify that the expression result for a void * behaves the same way as the
17        # variable value.
18
19        var_val = frame.FindVariable("void_ptr")
20        self.assertSuccess(var_val.GetError(), "Var version made correctly")
21
22        expr_val = frame.EvaluateExpression("void_ptr")
23        self.assertSuccess(expr_val.GetError(), "Expr version succeeds")
24
25        # The pointer values should be equal:
26        self.assertEqual(var_val.unsigned, expr_val.unsigned, "Values are equal")
27
28        # Both versions should have valid AddressOf, and they should be the same.
29
30        val_addr_of = var_val.AddressOf()
31        self.assertNotEqual(val_addr_of, lldb.LLDB_INVALID_ADDRESS, "Var addr of right")
32
33        expr_addr_of = expr_val.AddressOf()
34        self.assertNotEqual(
35            expr_addr_of, lldb.LLDB_INVALID_ADDRESS, "Expr addr of right"
36        )
37
38        # The AddressOf values should also be equal.
39        self.assertEqual(expr_addr_of.unsigned, val_addr_of.unsigned, "Addr of equal")
40