1""" 2Test some lldb command abbreviations. 3""" 4from __future__ import print_function 5 6 7import lldb 8from lldbsuite.test.decorators import * 9from lldbsuite.test.lldbtest import * 10from lldbsuite.test import lldbutil 11 12 13class ExecTestCase(TestBase): 14 15 NO_DEBUG_INFO_TESTCASE = True 16 17 mydir = TestBase.compute_mydir(__file__) 18 19 @expectedFailureAll(archs=['i386'], bugnumber="rdar://28656532") 20 @expectedFailureAll(oslist=["ios", "tvos", "watchos", "bridgeos"], bugnumber="rdar://problem/34559552") # this exec test has problems on ios systems 21 @expectedFailureNetBSD 22 @skipIfAsan # rdar://problem/43756823 23 @skipIfWindows 24 def test_hitting_exec (self): 25 self.do_test(False) 26 27 @expectedFailureAll(archs=['i386'], bugnumber="rdar://28656532") 28 @expectedFailureAll(oslist=["ios", "tvos", "watchos", "bridgeos"], bugnumber="rdar://problem/34559552") # this exec test has problems on ios systems 29 @expectedFailureNetBSD 30 @skipIfAsan # rdar://problem/43756823 31 @skipIfWindows 32 def test_skipping_exec (self): 33 self.do_test(True) 34 35 def do_test(self, skip_exec): 36 self.build() 37 exe = self.getBuildArtifact("a.out") 38 secondprog = self.getBuildArtifact("secondprog") 39 40 # Create the target 41 target = self.dbg.CreateTarget(exe) 42 43 # Create any breakpoints we need 44 breakpoint1 = target.BreakpointCreateBySourceRegex( 45 'Set breakpoint 1 here', lldb.SBFileSpec("main.cpp", False)) 46 self.assertTrue(breakpoint1, VALID_BREAKPOINT) 47 breakpoint2 = target.BreakpointCreateBySourceRegex( 48 'Set breakpoint 2 here', lldb.SBFileSpec("secondprog.cpp", False)) 49 self.assertTrue(breakpoint2, VALID_BREAKPOINT) 50 51 # Launch the process 52 process = target.LaunchSimple( 53 None, None, self.get_process_working_directory()) 54 self.assertTrue(process, PROCESS_IS_VALID) 55 56 if self.TraceOn(): 57 self.runCmd("settings show target.process.stop-on-exec", check=False) 58 if skip_exec: 59 self.dbg.HandleCommand("settings set target.process.stop-on-exec false") 60 def cleanup(): 61 self.runCmd("settings set target.process.stop-on-exec false", 62 check=False) 63 64 # Execute the cleanup function during test case tear down. 65 self.addTearDownHook(cleanup) 66 67 # The stop reason of the thread should be breakpoint. 68 self.assertTrue(process.GetState() == lldb.eStateStopped, 69 STOPPED_DUE_TO_BREAKPOINT) 70 71 threads = lldbutil.get_threads_stopped_at_breakpoint( 72 process, breakpoint1) 73 self.assertTrue(len(threads) == 1) 74 75 # We had a deadlock tearing down the TypeSystemMap on exec, but only if some 76 # expression had been evaluated. So make sure we do that here so the teardown 77 # is not trivial. 78 79 thread = threads[0] 80 value = thread.frames[0].EvaluateExpression("1 + 2") 81 self.assertTrue( 82 value.IsValid(), 83 "Expression evaluated successfully") 84 int_value = value.GetValueAsSigned() 85 self.assertTrue(int_value == 3, "Expression got the right result.") 86 87 # Run and we should stop due to exec 88 process.Continue() 89 90 if not skip_exec: 91 self.assertFalse(process.GetState() == lldb.eStateExited, 92 "Process should not have exited!") 93 self.assertTrue(process.GetState() == lldb.eStateStopped, 94 "Process should be stopped at __dyld_start") 95 96 threads = lldbutil.get_stopped_threads( 97 process, lldb.eStopReasonExec) 98 self.assertTrue( 99 len(threads) == 1, 100 "We got a thread stopped for exec.") 101 102 # Run and we should stop at breakpoint in main after exec 103 process.Continue() 104 105 threads = lldbutil.get_threads_stopped_at_breakpoint( 106 process, breakpoint2) 107 if self.TraceOn(): 108 for t in process.threads: 109 print(t) 110 if t.GetStopReason() != lldb.eStopReasonBreakpoint: 111 self.runCmd("bt") 112 self.assertTrue(len(threads) == 1, 113 "Stopped at breakpoint in exec'ed process.") 114