Home | History | Annotate | Download | only in issue_11588
      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 import os, time
      8 import unittest2
      9 import lldb
     10 import lldbutil
     11 from lldbtest import *
     12 
     13 class Issue11581TestCase(TestBase):
     14 
     15     mydir = os.path.join("expression_command", "issue_11588")
     16 
     17     def test_11581_commands(self):
     18         # This is the function to remove the custom commands in order to have a
     19         # clean slate for the next test case.
     20         def cleanup():
     21             self.runCmd('type synthetic clear', check=False)
     22 
     23 
     24         # Execute the cleanup function during test case tear down.
     25         self.addTearDownHook(cleanup)
     26 
     27         """valobj.AddressOf() should return correct values."""
     28         self.buildDefault()
     29         
     30         exe = os.path.join(os.getcwd(), "a.out")
     31         
     32         target = self.dbg.CreateTarget(exe)
     33         self.assertTrue(target, VALID_TARGET)
     34 
     35         breakpoint = target.BreakpointCreateBySourceRegex('Set breakpoint here.',lldb.SBFileSpec ("main.cpp", False))
     36         
     37         process = target.LaunchSimple (None, None, os.getcwd())
     38         self.assertTrue (process, "Created a process.")
     39         self.assertTrue (process.GetState() == lldb.eStateStopped, "Stopped it too.")
     40 
     41         thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint)
     42         self.assertTrue (len(thread_list) == 1)
     43         thread = thread_list[0]
     44 
     45         self.runCmd("command script import --allow-reload s11588.py")
     46         self.runCmd("type synthetic add --python-class s11588.Issue11581SyntheticProvider StgClosure")
     47 
     48         self.expect("expr --show-types -- *((StgClosure*)(r14-1))",
     49             substrs = ["(StgClosure) $",
     50             "(StgClosure *) &$","0x",
     51             "addr = ",
     52             "load_address = "])
     53 
     54 
     55         target = lldb.debugger.GetSelectedTarget()
     56         process = target.GetProcess()
     57 # register r14 does not exist on 32-bit architectures, it is an x86_64 extension
     58 # let's skip this part of the test if we are in 32-bit mode
     59         if process.GetAddressByteSize() == 8:
     60                 frame = process.GetSelectedThread().GetSelectedFrame()
     61                 pointer = frame.FindVariable("r14")
     62                 addr = pointer.GetValueAsUnsigned(0)
     63                 self.assertTrue(addr != 0, "could not read pointer to StgClosure")
     64                 addr = addr - 1
     65                 self.runCmd("register write r14 %d" % addr)
     66                 self.expect("register read r14",
     67                     substrs = ["0x",hex(addr)[2:].rstrip("L")])  # Remove trailing 'L' if it exists
     68                 self.expect("expr --show-types -- *(StgClosure*)$r14",
     69                     substrs = ["(StgClosure) $",
     70                     "(StgClosure *) &$","0x",
     71                     "addr = ",
     72                     "load_address = ",
     73                     hex(addr)[2:].rstrip("L"),
     74                     str(addr)])
     75 
     76 
     77 if __name__ == '__main__':
     78     import atexit
     79     lldb.SBDebugger.Initialize()
     80     atexit.register(lambda: lldb.SBDebugger.Terminate())
     81     unittest2.main()
     82