1""" 2Test that we read the function starts section. 3""" 4 5 6 7import lldb 8from lldbsuite.test.decorators import * 9from lldbsuite.test.lldbtest import * 10from lldbsuite.test import lldbutil 11 12exe_name = "StripMe" # Must match Makefile 13 14class FunctionStartsTestCase(TestBase): 15 16 mydir = TestBase.compute_mydir(__file__) 17 18 NO_DEBUG_INFO_TESTCASE = True 19 20 @skipIfRemote 21 @skipUnlessDarwin 22 def test_function_starts_binary(self): 23 """Test that we make synthetic symbols when we have the binary.""" 24 self.build(dictionary={'CODESIGN': ''}) # Binary is getting stripped later. 25 self.do_function_starts(False) 26 27 @skipIfRemote 28 @skipUnlessDarwin 29 def test_function_starts_no_binary(self): 30 """Test that we make synthetic symbols when we don't have the binary""" 31 self.build(dictionary={'CODESIGN': ''}) # Binary is getting stripped later. 32 self.do_function_starts(True) 33 34 def do_function_starts(self, in_memory): 35 """Run the binary, stop at our unstripped function, 36 make sure the caller has synthetic symbols""" 37 38 exe = os.path.realpath(self.getBuildArtifact(exe_name)) 39 # Now strip the binary, but leave externals so we can break on dont_strip_me. 40 self.runBuildCommand(["strip", "-u", "-x", "-S", exe]) 41 42 # Use a file as a synchronization point between test and inferior. 43 pid_file_path = lldbutil.append_to_process_working_directory(self, 44 "token_pid_%d" % (int(os.getpid()))) 45 self.addTearDownHook( 46 lambda: self.run_platform_command( 47 "rm %s" % 48 (pid_file_path))) 49 50 popen = self.spawnSubprocess(exe, [pid_file_path]) 51 52 # Wait until process has fully started up. 53 pid = lldbutil.wait_for_file_on_target(self, pid_file_path) 54 55 if in_memory: 56 remove_file(exe) 57 58 target = self.dbg.CreateTarget(None) 59 self.assertTrue(target.IsValid(), "Got a vaid empty target.") 60 error = lldb.SBError() 61 attach_info = lldb.SBAttachInfo() 62 attach_info.SetProcessID(popen.pid) 63 attach_info.SetIgnoreExisting(False) 64 process = target.Attach(attach_info, error) 65 self.assertSuccess(error, "Didn't attach successfully to %d"%(popen.pid)) 66 67 bkpt = target.BreakpointCreateByName("dont_strip_me", exe) 68 self.assertTrue(bkpt.GetNumLocations() > 0, "Didn't set the dont_strip_me bkpt.") 69 70 threads = lldbutil.continue_to_breakpoint(process, bkpt) 71 self.assertEqual(len(threads), 1, "Didn't hit my breakpoint.") 72 73 # Our caller frame should have been stripped. Make sure we made a synthetic symbol 74 # for it: 75 thread = threads[0] 76 self.assertTrue(thread.num_frames > 1, "Couldn't backtrace.") 77 name = thread.frame[1].GetFunctionName() 78 self.assertTrue(name.startswith("___lldb_unnamed_symbol")) 79 80 81 82