1"""
2Test that LLDB can emit JIT objects when the appropriate setting is enabled
3"""
4
5
6import os
7import lldb
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10from lldbsuite.test import lldbutil
11
12class SaveJITObjectsTestCase(TestBase):
13    mydir = TestBase.compute_mydir(__file__)
14
15    def enumerateJITFiles(self):
16        return [f for f in os.listdir(self.getBuildDir()) if f.startswith("jit")]
17
18    def countJITFiles(self):
19        return len(self.enumerateJITFiles())
20
21    def cleanJITFiles(self):
22        for j in self.enumerateJITFiles():
23            os.remove(j)
24        return
25
26    @expectedFailureAll(oslist=["windows"])
27    def test_save_jit_objects(self):
28        self.build()
29        os.chdir(self.getBuildDir())
30        src_file = "main.c"
31        src_file_spec = lldb.SBFileSpec(src_file)
32
33        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
34            self, "break", src_file_spec)
35
36        frame = thread.frames[0]
37
38        self.cleanJITFiles()
39        frame.EvaluateExpression("(void*)malloc(0x1)")
40        self.assertEquals(self.countJITFiles(), 0,
41                        "No files emitted with save-jit-objects=false")
42
43        self.runCmd("settings set target.save-jit-objects true")
44        frame.EvaluateExpression("(void*)malloc(0x1)")
45        jit_files_count = self.countJITFiles()
46        self.cleanJITFiles()
47        self.assertNotEqual(jit_files_count, 0,
48                        "At least one file emitted with save-jit-objects=true")
49
50        process.Kill()
51        os.chdir(self.getSourceDir())
52