diff --git a/lldb/packages/Python/lldbsuite/test/decorators.py b/lldb/packages/Python/lldbsuite/test/decorators.py index d17564ad9ebaf..aadcf264d3279 100644 --- a/lldb/packages/Python/lldbsuite/test/decorators.py +++ b/lldb/packages/Python/lldbsuite/test/decorators.py @@ -960,6 +960,19 @@ def is_compiler_clang_with_call_site_info(): return skipTestIfFn(is_compiler_clang_with_call_site_info)(func) +def skipUnlessCompilerIsClang(func): + """Decorate the item to skip test unless the compiler is clang.""" + + def is_compiler_clang(): + compiler_path = lldbplatformutil.getCompiler() + compiler = os.path.basename(compiler_path) + if not compiler.startswith("clang"): + return "Test requires clang as compiler" + return None + + return skipTestIfFn(is_compiler_clang)(func) + + def skipUnlessThreadSanitizer(func): """Decorate the item to skip test unless Clang -fsanitize=thread is supported.""" diff --git a/lldb/test/API/functionalities/breakpoint/jit_loader_rtdyld_elf/Makefile b/lldb/test/API/functionalities/breakpoint/jit_loader_rtdyld_elf/Makefile new file mode 100644 index 0000000000000..1981a7a3264cb --- /dev/null +++ b/lldb/test/API/functionalities/breakpoint/jit_loader_rtdyld_elf/Makefile @@ -0,0 +1,12 @@ +CXX_SOURCES := jitbp.cpp + +include Makefile.rules + +jitbp.ll: jitbp.cpp + $(CXX) -g -S -emit-llvm --target=x86_64-unknown-unknown-elf \ + -o $@ $< + +all: jitbp.ll + +clean:: + rm -f jitbp.ll diff --git a/lldb/test/API/functionalities/breakpoint/jit_loader_rtdyld_elf/TestJitBreakPoint.py b/lldb/test/API/functionalities/breakpoint/jit_loader_rtdyld_elf/TestJitBreakPoint.py new file mode 100644 index 0000000000000..92f233a7638de --- /dev/null +++ b/lldb/test/API/functionalities/breakpoint/jit_loader_rtdyld_elf/TestJitBreakPoint.py @@ -0,0 +1,46 @@ +""" +Test that pending breakpoints resolve for JITted code with mcjit and rtdyld. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * + + +class TestJitBreakpoint(TestBase): + @skipUnlessArch("x86_64") + @skipUnlessCompilerIsClang + @expectedFailureAll(oslist=["windows"]) + def test_jit_breakpoints(self): + self.build() + self.ll = self.getBuildArtifact("jitbp.ll") + self.do_test("--jit-kind=mcjit") + self.do_test("--jit-linker=rtdyld") + + def do_test(self, jit_flag: str): + self.runCmd("settings set plugin.jit-loader.gdb.enable on") + + clang_path = self.findBuiltClang() + self.assertTrue(clang_path, "built clang could not be found") + lli_path = os.path.join(os.path.dirname(clang_path), "lli") + self.assertTrue(lldbutil.is_exe(lli_path), f"'{lli_path}' is not an executable") + self.runCmd(f"target create {lli_path}", CURRENT_EXECUTABLE_SET) + + line = line_number("jitbp.cpp", "int jitbp()") + lldbutil.run_break_set_by_file_and_line( + self, "jitbp.cpp", line, num_expected_locations=0 + ) + + self.runCmd(f"run {jit_flag} {self.ll}", RUN_SUCCEEDED) + + # The stop reason of the thread should be breakpoint. + # And it should break at jitbp.cpp:1. + self.expect( + "thread list", + STOPPED_DUE_TO_BREAKPOINT, + substrs=[ + "stopped", + "jitbp.cpp:%d" % line, + "stop reason = breakpoint", + ], + ) diff --git a/lldb/test/API/functionalities/breakpoint/jit_loader_rtdyld_elf/jitbp.cpp b/lldb/test/API/functionalities/breakpoint/jit_loader_rtdyld_elf/jitbp.cpp new file mode 100644 index 0000000000000..447d9d66df848 --- /dev/null +++ b/lldb/test/API/functionalities/breakpoint/jit_loader_rtdyld_elf/jitbp.cpp @@ -0,0 +1,2 @@ +int jitbp() { return 0; } +int main() { return jitbp(); } diff --git a/lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test b/lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test deleted file mode 100644 index b34a5673936f5..0000000000000 --- a/lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test +++ /dev/null @@ -1,22 +0,0 @@ -# REQUIRES: target-x86_64 -# XFAIL: system-windows - -# RuntimeDyld can be used to link and load emitted code for both, MCJIT and Orc. -# -# RUN: %clang -g -S -emit-llvm --target=x86_64-unknown-unknown-elf \ -# RUN: -o %t.ll %p/Inputs/jitbp.cpp -# -# RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' \ -# RUN: -o 'run --jit-kind=mcjit %t.ll' lli | FileCheck %s -# -# RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' \ -# RUN: -o 'run --jit-linker=rtdyld %t.ll' lli | FileCheck %s - -# CHECK: Breakpoint 1: no locations (pending). -# CHECK: (lldb) run {{.*}} -# CHECK: Process {{.*}} launched: {{.*}} -# CHECK: Process {{.*}} stopped -# CHECK: JIT(0x{{.*}})`jitbp() at jitbp.cpp:1:15 -# CHECK: -> 1 int jitbp() { return 0; } -# CHECK: ^ -# CHECK: 2 int main() { return jitbp(); }