xref: /llvm-project/lldb/test/API/commands/expression/save_jit_objects/TestSaveJITObjects.py (revision 80fcecb13c388ff087a27a4b0e7ca3dd8c98eaa4)
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
12
13class SaveJITObjectsTestCase(TestBase):
14    def enumerateJITFiles(self):
15        return [f for f in os.listdir(self.getBuildDir()) if f.startswith("jit")]
16
17    def countJITFiles(self):
18        return len(self.enumerateJITFiles())
19
20    def cleanJITFiles(self):
21        for j in self.enumerateJITFiles():
22            os.remove(j)
23        return
24
25    @expectedFailureAll(oslist=["windows"])
26    def test_save_jit_objects(self):
27        self.build()
28        os.chdir(self.getBuildDir())
29        src_file = "main.c"
30        src_file_spec = lldb.SBFileSpec(src_file)
31
32        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
33            self, "break", src_file_spec
34        )
35
36        frame = thread.frames[0]
37
38        self.cleanJITFiles()
39        frame.EvaluateExpression("(void*)malloc(0x1)")
40        self.assertEqual(
41            self.countJITFiles(), 0, "No files emitted with save-jit-objects-dir empty"
42        )
43
44        self.runCmd(
45            "settings set target.save-jit-objects-dir {0}".format(self.getBuildDir())
46        )
47        frame.EvaluateExpression("(void*)malloc(0x1)")
48        jit_files_count = self.countJITFiles()
49        self.cleanJITFiles()
50        self.assertNotEqual(
51            jit_files_count,
52            0,
53            "At least one file emitted with save-jit-objects-dir set to the build dir",
54        )
55
56        process.Kill()
57        os.chdir(self.getSourceDir())
58