]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/expression_command/issue_11588/Test11588.py
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / expression_command / issue_11588 / Test11588.py
1 """
2 Test the solution to issue 11581.
3 valobj.AddressOf() returns None when an address is
4 expected in a SyntheticChildrenProvider
5 """
6
7 from __future__ import print_function
8
9
10
11 import os, time
12 import lldb
13 import lldbsuite.test.lldbutil as lldbutil
14 from lldbsuite.test.lldbtest import *
15
16 class Issue11581TestCase(TestBase):
17
18     mydir = TestBase.compute_mydir(__file__)
19
20     @expectedFailureWindows("llvm.org/pr24778")
21     def test_11581_commands(self):
22         # This is the function to remove the custom commands in order to have a
23         # clean slate for the next test case.
24         def cleanup():
25             self.runCmd('type synthetic clear', check=False)
26
27
28         # Execute the cleanup function during test case tear down.
29         self.addTearDownHook(cleanup)
30
31         """valobj.AddressOf() should return correct values."""
32         self.build()
33         
34         exe = os.path.join(os.getcwd(), "a.out")
35         
36         target = self.dbg.CreateTarget(exe)
37         self.assertTrue(target, VALID_TARGET)
38
39         breakpoint = target.BreakpointCreateBySourceRegex('Set breakpoint here.',lldb.SBFileSpec ("main.cpp", False))
40         
41         process = target.LaunchSimple (None, None, self.get_process_working_directory())
42         self.assertTrue (process, "Created a process.")
43         self.assertTrue (process.GetState() == lldb.eStateStopped, "Stopped it too.")
44
45         thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint)
46         self.assertTrue (len(thread_list) == 1)
47         thread = thread_list[0]
48
49         self.runCmd("command script import --allow-reload s11588.py")
50         self.runCmd("type synthetic add --python-class s11588.Issue11581SyntheticProvider StgClosure")
51
52         self.expect("expr --show-types -- *((StgClosure*)(r14-1))",
53             substrs = ["(StgClosure) $",
54             "(StgClosure *) &$","0x",
55             "addr = ",
56             "load_address = "])
57
58         # register r14 is an x86_64 extension let's skip this part of the test
59         # if we are on a different architecture
60         if self.getArchitecture() == 'x86_64':
61                 target = lldb.debugger.GetSelectedTarget()
62                 process = target.GetProcess()
63                 frame = process.GetSelectedThread().GetSelectedFrame()
64                 pointer = frame.FindVariable("r14")
65                 addr = pointer.GetValueAsUnsigned(0)
66                 self.assertTrue(addr != 0, "could not read pointer to StgClosure")
67                 addr = addr - 1
68                 self.runCmd("register write r14 %d" % addr)
69                 self.expect("register read r14",
70                     substrs = ["0x",hex(addr)[2:].rstrip("L")])  # Remove trailing 'L' if it exists
71                 self.expect("expr --show-types -- *(StgClosure*)$r14",
72                     substrs = ["(StgClosure) $",
73                     "(StgClosure *) &$","0x",
74                     "addr = ",
75                     "load_address = ",
76                     hex(addr)[2:].rstrip("L"),
77                     str(addr)])