https://github.com/charles-zablit updated https://github.com/llvm/llvm-project/pull/170333
>From 07ecfc8d5d143ef0ea6011a91eb5f19c79582957 Mon Sep 17 00:00:00 2001 From: Charles Zablit <[email protected]> Date: Wed, 3 Dec 2025 13:06:20 +0000 Subject: [PATCH 1/2] [lldb] convert TestJitBreakpoint to API test --- .../breakpoint/jit_loader_rtdyld_elf/Makefile | 12 ++++ .../TestJitBreakPoint.py | 55 +++++++++++++++++++ .../jit_loader_rtdyld_elf/jitbp.cpp | 2 + .../Breakpoint/jit-loader_rtdyld_elf.test | 22 -------- 4 files changed, 69 insertions(+), 22 deletions(-) create mode 100644 lldb/test/API/functionalities/breakpoint/jit_loader_rtdyld_elf/Makefile create mode 100644 lldb/test/API/functionalities/breakpoint/jit_loader_rtdyld_elf/TestJitBreakPoint.py create mode 100644 lldb/test/API/functionalities/breakpoint/jit_loader_rtdyld_elf/jitbp.cpp delete mode 100644 lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test 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..78f1d6e9d3c4c --- /dev/null +++ b/lldb/test/API/functionalities/breakpoint/jit_loader_rtdyld_elf/TestJitBreakPoint.py @@ -0,0 +1,55 @@ +""" +Test that pending breakpoints resolve for JITted code with mcjit and rtdyld. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * + +import shutil + + +class TestJitBreakpoint(TestBase): + def setUp(self): + TestBase.setUp(self) + self.ll = self.getBuildArtifact("jitbp.ll") + + @skipUnlessArch("x86_64") + @expectedFailureAll(oslist=["windows"]) + def test_jit_breakpoints(self): + self.build() + self.do_test("--jit-kind=mcjit") + self.do_test("--jit-linker=rtdyld") + + def do_test(self, jit_flag: str): + self.dbg.SetAsync(False) + + self.dbg.HandleCommand("settings set plugin.jit-loader.gdb.enable on") + + lldb_dir = os.path.dirname(lldbtest_config.lldbExec) + lli_path = shutil.which("lli", path=lldb_dir) + self.assertTrue(os.path.exists(lli_path), "lli not found") + target = self.dbg.CreateTarget(lli_path) + self.assertTrue(target.IsValid()) + + bp = target.BreakpointCreateByName("jitbp") + self.assertTrue(bp.IsValid()) + self.assertEqual(bp.GetNumLocations(), 0, "Expected a pending breakpoint") + + launch_info = target.GetLaunchInfo() + launch_info.SetArguments([jit_flag, self.ll], True) + + error = lldb.SBError() + process = target.Launch(launch_info, error) + self.assertTrue(process.IsValid()) + self.assertTrue(error.Success(), error.GetCString()) + + self.assertEqual(process.GetState(), lldb.eStateStopped) + + thread = process.GetSelectedThread() + frame = thread.GetSelectedFrame() + self.assertIn("jitbp", frame.GetFunctionName()) + + self.assertGreaterEqual( + bp.GetNumLocations(), 1, "Breakpoint must be resolved after JIT loads code" + ) 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 ae9402a519494..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: %clangxx -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(); } >From 887a09df4a2786798b8ac19a74569a3ede786ea7 Mon Sep 17 00:00:00 2001 From: Charles Zablit <[email protected]> Date: Tue, 9 Dec 2025 16:39:29 +0000 Subject: [PATCH 2/2] fixup! [lldb] convert TestJitBreakpoint to API test --- .../Python/lldbsuite/test/decorators.py | 11 ++++ .../TestJitBreakPoint.py | 53 ++++++++----------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/decorators.py b/lldb/packages/Python/lldbsuite/test/decorators.py index 7311b17f97e01..af6c9fb1a0624 100644 --- a/lldb/packages/Python/lldbsuite/test/decorators.py +++ b/lldb/packages/Python/lldbsuite/test/decorators.py @@ -952,6 +952,17 @@ 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/TestJitBreakPoint.py b/lldb/test/API/functionalities/breakpoint/jit_loader_rtdyld_elf/TestJitBreakPoint.py index 78f1d6e9d3c4c..7b4dd49d7498e 100644 --- a/lldb/test/API/functionalities/breakpoint/jit_loader_rtdyld_elf/TestJitBreakPoint.py +++ b/lldb/test/API/functionalities/breakpoint/jit_loader_rtdyld_elf/TestJitBreakPoint.py @@ -6,50 +6,39 @@ from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * -import shutil - class TestJitBreakpoint(TestBase): - def setUp(self): - TestBase.setUp(self) - self.ll = self.getBuildArtifact("jitbp.ll") - @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.dbg.SetAsync(False) - - self.dbg.HandleCommand("settings set plugin.jit-loader.gdb.enable on") + import shutil - lldb_dir = os.path.dirname(lldbtest_config.lldbExec) - lli_path = shutil.which("lli", path=lldb_dir) - self.assertTrue(os.path.exists(lli_path), "lli not found") - target = self.dbg.CreateTarget(lli_path) - self.assertTrue(target.IsValid()) + self.runCmd("settings set plugin.jit-loader.gdb.enable on") - bp = target.BreakpointCreateByName("jitbp") - self.assertTrue(bp.IsValid()) - self.assertEqual(bp.GetNumLocations(), 0, "Expected a pending breakpoint") + self.runCmd("target create lli", CURRENT_EXECUTABLE_SET) - launch_info = target.GetLaunchInfo() - launch_info.SetArguments([jit_flag, self.ll], True) - - error = lldb.SBError() - process = target.Launch(launch_info, error) - self.assertTrue(process.IsValid()) - self.assertTrue(error.Success(), error.GetCString()) - - self.assertEqual(process.GetState(), lldb.eStateStopped) - - thread = process.GetSelectedThread() - frame = thread.GetSelectedFrame() - self.assertIn("jitbp", frame.GetFunctionName()) + line = line_number("jitbp.cpp", "int jitbp()") + lldbutil.run_break_set_by_file_and_line( + self, "jitbp.cpp", line, num_expected_locations=0 + ) - self.assertGreaterEqual( - bp.GetNumLocations(), 1, "Breakpoint must be resolved after JIT loads code" + 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", + ], ) _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
