1ee11ef6dSJason Molenda"""Test that we don't read objc class tables early in process startup.""" 2ee11ef6dSJason Molenda 3ee11ef6dSJason Molendaimport time 4ee11ef6dSJason Molendaimport lldb 5ee11ef6dSJason Molendafrom lldbsuite.test.decorators import * 6ee11ef6dSJason Molendafrom lldbsuite.test.lldbtest import * 7ee11ef6dSJason Molendafrom lldbsuite.test import lldbutil 8ee11ef6dSJason Molenda 9ee11ef6dSJason Molenda 10ee11ef6dSJason Molendaclass TestEarlyProcessLaunch(TestBase): 11ee11ef6dSJason Molenda NO_DEBUG_INFO_TESTCASE = True 12ee11ef6dSJason Molenda 13ee11ef6dSJason Molenda @skipUnlessDarwin 1427249c06SAdrian Prantl @skipIfAsan # rdar://103359354 15ad10b3dcSJason Molenda @skipIfOutOfTreeDebugserver # 2022-12-13 FIXME: skipping system debugserver 16ad10b3dcSJason Molenda # until this feature is included in the system 17ad10b3dcSJason Molenda # debugserver. 182238dcc3SJonas Devlieghere @add_test_categories(["pyapi"]) 19ee11ef6dSJason Molenda def test_early_process_launch(self): 20ee11ef6dSJason Molenda """Test that we don't read objc class tables early in proc startup""" 21ee11ef6dSJason Molenda self.build() 22ee11ef6dSJason Molenda 23ee11ef6dSJason Molenda ### 24ee11ef6dSJason Molenda ### Hit a breakpoint on the first malloc() call, which 25ee11ef6dSJason Molenda ### is before libSystem has finished initializing. At 26ee11ef6dSJason Molenda ### this point, we should not read the objc class tables. 27ee11ef6dSJason Molenda ### Then continue to main(), which is past libSystem 28ee11ef6dSJason Molenda ### initializing. Try again, and they should be read. 29ee11ef6dSJason Molenda ### 30ee11ef6dSJason Molenda ### Use the types logging to detect the difference. 31ee11ef6dSJason Molenda 32*1988c27eSJason Molenda exe = self.getBuildArtifact("a.out") 33*1988c27eSJason Molenda target = self.dbg.CreateTarget(exe) 34*1988c27eSJason Molenda self.assertTrue(target.IsValid()) 35*1988c27eSJason Molenda bkpt = target.BreakpointCreateByRegex("alloc", None) 36*1988c27eSJason Molenda self.assertTrue(bkpt.IsValid()) 37*1988c27eSJason Molenda (target, process, thread, bkpt) = lldbutil.run_to_breakpoint_do_run( 38*1988c27eSJason Molenda self, target, bkpt 39*1988c27eSJason Molenda ) 40ee11ef6dSJason Molenda 41ee11ef6dSJason Molenda target.DisableAllBreakpoints() 42ee11ef6dSJason Molenda target.BreakpointCreateByName("main") 43ee11ef6dSJason Molenda 44ee11ef6dSJason Molenda logfile_early = os.path.join(self.getBuildDir(), "types-log-early.txt") 45ee11ef6dSJason Molenda self.addTearDownHook(lambda: self.runCmd("log disable lldb types")) 46ee11ef6dSJason Molenda self.runCmd("log enable -f %s lldb types" % logfile_early) 479e6ea387SMichael Buch self.runCmd("expression --language objc -- global = 15") 48ee11ef6dSJason Molenda 49ee11ef6dSJason Molenda err = process.Continue() 50ee11ef6dSJason Molenda self.assertTrue(err.Success()) 51ee11ef6dSJason Molenda 52ee11ef6dSJason Molenda logfile_later = os.path.join(self.getBuildDir(), "types-log-later.txt") 53ee11ef6dSJason Molenda self.runCmd("log enable -f %s lldb types" % logfile_later) 549e6ea387SMichael Buch self.runCmd("expression --language objc -- global = 25") 55ee11ef6dSJason Molenda 56ee11ef6dSJason Molenda self.assertTrue(os.path.exists(logfile_early)) 57ee11ef6dSJason Molenda self.assertTrue(os.path.exists(logfile_later)) 58ee11ef6dSJason Molenda early_text = open(logfile_early).read() 59ee11ef6dSJason Molenda later_text = open(logfile_later).read() 60ee11ef6dSJason Molenda 61ee11ef6dSJason Molenda self.assertIn("ran: no, retry: yes", early_text) 62ee11ef6dSJason Molenda self.assertNotIn("ran: no, retry: yes", later_text) 63ee11ef6dSJason Molenda 64ee11ef6dSJason Molenda self.assertNotIn("ran: yes, retry: no", early_text) 65ee11ef6dSJason Molenda self.assertIn("ran: yes, retry: no", later_text) 66