64 lines · python
1"""2Test that we read in the Python module from a dSYM, and run the3init in debugger and the init in target routines.4"""5 6import os, shutil7 8import lldb9import lldbsuite.test.lldbutil as lldbutil10from lldbsuite.test.lldbtest import *11from lldbsuite.test.decorators import *12 13 14@skipUnlessDarwin15class TestdSYMModuleInit(TestBase):16 @no_debug_info_test17 def test_add_module(self):18 """This loads a file into a target and ensures that the python module was19 correctly added and the two intialization functions are called."""20 self.exe_name = "has_dsym"21 self.py_name = self.exe_name + ".py"22 23 # Now load the target the first time into the debugger:24 self.runCmd("settings set target.load-script-from-symbol-file true")25 self.interp = self.dbg.GetCommandInterpreter()26 27 executable = self.build_dsym(self.exe_name + "_1")28 target = self.createTestTarget(file_path=executable)29 self.check_answers(executable, ["1", "1", "has_dsym_1"])30 31 # Now make a second target and make sure both get called:32 executable_2 = self.build_dsym(self.exe_name + "_2")33 target_2 = self.createTestTarget(file_path=executable_2)34 self.check_answers(executable_2, ["2", "2", "has_dsym_2"])35 36 def check_answers(self, name, answers):37 result = lldb.SBCommandReturnObject()38 self.interp.HandleCommand("report_command", result)39 self.assertTrue(40 result.Succeeded(), f"report_command succeeded {result.GetError()}"41 )42 43 cmd_results = result.GetOutput().split()44 self.assertEqual(answers[0], cmd_results[0], "Right number of module imports")45 self.assertEqual(answers[1], cmd_results[1], "Right number of target notices")46 self.assertIn(answers[2], name, "Right target name")47 48 def build_dsym(self, name):49 self.build(debug_info="dsym", dictionary={"EXE": name})50 executable = self.getBuildArtifact(name)51 dsym_path = self.getBuildArtifact(name + ".dSYM")52 python_dir_path = dsym_path53 python_dir_path = os.path.join(dsym_path, "Contents", "Resources", "Python")54 if not os.path.exists(python_dir_path):55 os.mkdir(python_dir_path)56 57 python_file_name = name + ".py"58 59 module_dest_path = os.path.join(python_dir_path, python_file_name)60 module_origin_path = os.path.join(self.getSourceDir(), self.py_name)61 shutil.copy(module_origin_path, module_dest_path)62 63 return executable64