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