File: TestJITLoaderGDB.py

package info (click to toggle)
llvm-toolchain-11 1%3A11.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 995,808 kB
  • sloc: cpp: 4,767,656; ansic: 760,916; asm: 477,436; python: 170,940; objc: 69,804; lisp: 29,914; sh: 23,855; f90: 18,173; pascal: 7,551; perl: 7,471; ml: 5,603; awk: 3,489; makefile: 2,573; xml: 915; cs: 573; fortran: 503; javascript: 452
file content (107 lines) | stat: -rw-r--r-- 4,055 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"""Test for the JITLoaderGDB interface"""


import unittest2
import os
import lldb
from lldbsuite.test import lldbutil
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *


class JITLoaderGDBTestCase(TestBase):

    mydir = TestBase.compute_mydir(__file__)

    @skipTestIfFn(
        lambda: "Skipped because the test crashes the test runner",
        bugnumber="llvm.org/pr24702")
    @unittest2.expectedFailure("llvm.org/pr24702")
    def test_bogus_values(self):
        """Test that we handle inferior misusing the GDB JIT interface"""
        self.build()
        exe = self.getBuildArtifact("a.out")

        # Create a target by the debugger.
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        # Launch the process, do not stop at entry point.
        process = target.LaunchSimple(
            None, None, self.get_process_working_directory())
        self.assertTrue(process, PROCESS_IS_VALID)

        # The inferior will now pass bogus values over the interface. Make sure
        # we don't crash.
        self.assertEqual(process.GetState(), lldb.eStateExited)
        self.assertEqual(process.GetExitStatus(), 0)

    def gen_log_file(self):
        logfile = self.getBuildArtifact("jitintgdb-{}.txt".format(self.getArchitecture()))
        def cleanup():
            if os.path.exists(logfile):
                os.unlink(logfile)
        self.addTearDownHook(cleanup)
        return logfile

    def test_jit_int_default(self):
        self.expect("settings show plugin.jit-loader.gdb.enable",
                    substrs=["plugin.jit-loader.gdb.enable (enum) = default"])

    @skipIfWindows # This test fails on Windows during C code build
    def test_jit_int_on(self):
        """Tests interface with 'enable' settings 'on'"""
        self.build()
        exe = self.getBuildArtifact("simple")

        logfile = self.gen_log_file()
        self.runCmd("log enable -f %s lldb jit" % (logfile))
        self.runCmd("settings set plugin.jit-loader.gdb.enable on")
        def cleanup():
            self.runCmd("log disable lldb")
            self.runCmd("settings set plugin.jit-loader.gdb.enable default")
        self.addTearDownHook(cleanup)

        # Launch the process.
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)
        process = target.LaunchSimple(
            None, None, self.get_process_working_directory())
        self.assertTrue(process, PROCESS_IS_VALID)

        self.assertEqual(process.GetState(), lldb.eStateExited)
        self.assertEqual(process.GetExitStatus(), 0)

        if not configuration.is_reproducer():
            self.assertTrue(os.path.exists(logfile))
            logcontent = open(logfile).read()
            self.assertIn("SetJITBreakpoint setting JIT breakpoint", logcontent)

    @skipIfWindows # This test fails on Windows during C code build
    def test_jit_int_off(self):
        """Tests interface with 'enable' settings 'off'"""
        self.build()
        exe = self.getBuildArtifact("simple")

        logfile = self.gen_log_file()
        self.runCmd("log enable -f %s lldb jit" % (logfile))
        self.runCmd("settings set plugin.jit-loader.gdb.enable off")
        def cleanup():
            self.runCmd("log disable lldb")
            self.runCmd("settings set plugin.jit-loader.gdb.enable default")
        self.addTearDownHook(cleanup)

        # Launch the process.
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)
        process = target.LaunchSimple(
            None, None, self.get_process_working_directory())
        self.assertTrue(process, PROCESS_IS_VALID)

        self.assertEqual(process.GetState(), lldb.eStateExited)
        self.assertEqual(process.GetExitStatus(), 0)

        if not configuration.is_reproducer():
            self.assertTrue(os.path.exists(logfile))
            logcontent = open(logfile).read()
            self.assertNotIn("SetJITBreakpoint setting JIT breakpoint", logcontent)