diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h index 17d0935dd00ae..e99b71399d01d 100644 --- a/lldb/include/lldb/Target/Process.h +++ b/lldb/include/lldb/Target/Process.h @@ -2307,6 +2307,9 @@ class Process : public std::enable_shared_from_this, UpdateBreakpointSites(const BreakpointSiteToActionMap &site_to_action); public: + /// Performs `action` on `site`. If `forbid_delay` is true, the action is + /// performed immediately, otherwise the method will delay the breakpoint if + /// it is correct to do so. llvm::Error ExecuteBreakpointSiteAction(BreakpointSite &site, Process::BreakpointAction action, bool forbid_delay); diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 9ccbe9684946b..ef7de8c2018ff 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -1601,6 +1601,9 @@ Status Process::DisableBreakpointSiteByID(lldb::user_id_t break_id) { llvm::Error Process::ExecuteBreakpointSiteAction(BreakpointSite &site, BreakpointAction action, bool forbid_delay) { + // Breakpoints immediately affect running processes, so do not delay them. + forbid_delay |= IsRunning(); + if (forbid_delay) if (llvm::Error E = FlushDelayedBreakpoints()) LLDB_LOG_ERROR( diff --git a/lldb/test/API/functionalities/breakpoint/breakpoint_while_running/Makefile b/lldb/test/API/functionalities/breakpoint/breakpoint_while_running/Makefile new file mode 100644 index 0000000000000..10495940055b6 --- /dev/null +++ b/lldb/test/API/functionalities/breakpoint/breakpoint_while_running/Makefile @@ -0,0 +1,3 @@ +C_SOURCES := main.c + +include Makefile.rules diff --git a/lldb/test/API/functionalities/breakpoint/breakpoint_while_running/TestBreakpointWhileRunning.py b/lldb/test/API/functionalities/breakpoint/breakpoint_while_running/TestBreakpointWhileRunning.py new file mode 100644 index 0000000000000..a5ed71c4f0379 --- /dev/null +++ b/lldb/test/API/functionalities/breakpoint/breakpoint_while_running/TestBreakpointWhileRunning.py @@ -0,0 +1,25 @@ +""" +Test inserting a breakpoint while inferior is executing. +""" + +import lldb +from lldbsuite.test.lldbtest import TestBase +from lldbsuite.test import lldbutil + + +class BreakpointWhileRunning(TestBase): + NO_DEBUG_INFO_TESTCASE = True + + def test_breakpoint_while_running(self): + self.build() + target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( + self, "main", lldb.SBFileSpec("main.c") + ) + + self.dbg.SetAsync(True) + listener = self.dbg.GetListener() + self.runCmd("break delete --force") + self.runCmd("continue") + lldbutil.expect_state_changes(self, listener, process, [lldb.eStateRunning]) + self.runCmd("break set --source-pattern-regexp 'break here'") + lldbutil.expect_state_changes(self, listener, process, [lldb.eStateStopped]) diff --git a/lldb/test/API/functionalities/breakpoint/breakpoint_while_running/main.c b/lldb/test/API/functionalities/breakpoint/breakpoint_while_running/main.c new file mode 100644 index 0000000000000..a813e51de4bae --- /dev/null +++ b/lldb/test/API/functionalities/breakpoint/breakpoint_while_running/main.c @@ -0,0 +1,12 @@ +#ifdef _WIN32 +#include +#define sleep(x) Sleep((x) * 1000) +#else +#include +#endif + +int main() { + int count = 100; + while (count--) + sleep(1); // break here +}