74 lines · python
1"""2Test the solution to issue 11581.3valobj.AddressOf() returns None when an address is4expected in a SyntheticChildrenProvider5"""6 7 8import lldb9from lldbsuite.test.decorators import *10from lldbsuite.test.lldbtest import *11from lldbsuite.test import lldbutil12 13 14class Issue11581TestCase(TestBase):15 @skipIfWindows # This test is now flaky on windows, see llvm.org/pr2477816 def test_11581_commands(self):17 # This is the function to remove the custom commands in order to have a18 # clean slate for the next test case.19 def cleanup():20 self.runCmd("type synthetic clear", check=False)21 22 # Execute the cleanup function during test case tear down.23 self.addTearDownHook(cleanup)24 25 """valobj.AddressOf() should return correct values."""26 self.build()27 28 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(29 self, "Set breakpoint here.", lldb.SBFileSpec("main.cpp", False)30 )31 self.runCmd("command script import --allow-reload s11588.py")32 self.runCmd(33 "type synthetic add --python-class s11588.Issue11581SyntheticProvider StgClosure"34 )35 36 self.expect(37 "expr --show-types -- *((StgClosure*)(r14-1))",38 substrs=[39 "(StgClosure) $",40 "(StgClosure *) &$",41 "0x",42 "addr = ",43 "load_address = ",44 ],45 )46 47 # register r14 is an x86_64 extension let's skip this part of the test48 # if we are on a different architecture49 if self.getArchitecture() == "x86_64":50 target = self.dbg.GetSelectedTarget()51 process = target.GetProcess()52 frame = process.GetSelectedThread().GetSelectedFrame()53 pointer = frame.FindVariable("r14")54 addr = pointer.GetValueAsUnsigned(0)55 self.assertNotEqual(addr, 0, "could not read pointer to StgClosure")56 addr = addr - 157 self.runCmd("register write r14 %d" % addr)58 self.expect(59 "register read r14", substrs=["0x", hex(addr)[2:].rstrip("L")]60 ) # Remove trailing 'L' if it exists61 self.expect(62 "expr --show-types -- *(StgClosure*)$r14",63 substrs=[64 "(StgClosure) $",65 "(StgClosure *) &$",66 "0x",67 hex(addr)[2:].rstrip("L"),68 "addr = ",69 str(addr),70 "load_address = ",71 str(addr),72 ],73 )74