Author: Alexandre Perez Date: 2026-06-10T15:49:21-07:00 New Revision: e9fbddf223976da11f40291a310d3308c61ea778
URL: https://github.com/llvm/llvm-project/commit/e9fbddf223976da11f40291a310d3308c61ea778 DIFF: https://github.com/llvm/llvm-project/commit/e9fbddf223976da11f40291a310d3308c61ea778.diff LOG: [lldb] Expose SBProcess::IsLiveDebugSession() (#203111) Expose the existing `Process::IsLiveDebugSession()` through the SB API as `SBProcess::IsLiveDebugSession()`, letting clients distinguish a live debuggee from a post-mortem session such as a core file or minidump. It returns `false` when there is no underlying process, consistent with other `SBProcess` query methods. Added: Modified: lldb/include/lldb/API/SBProcess.h lldb/source/API/SBProcess.cpp lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py lldb/test/API/python_api/process/TestProcessAPI.py Removed: ################################################################################ diff --git a/lldb/include/lldb/API/SBProcess.h b/lldb/include/lldb/API/SBProcess.h index 882b8bd837131..f42b30007a64b 100644 --- a/lldb/include/lldb/API/SBProcess.h +++ b/lldb/include/lldb/API/SBProcess.h @@ -424,6 +424,15 @@ class LLDB_API SBProcess { /// the process isn't loaded from a core file. lldb::SBFileSpec GetCoreFile(); + /// Check whether this process is a live debug session, as opposed to a + /// post-mortem session such as a core file or minidump. + /// + /// \return + /// \b true if the process represents a live debug session, \b false if it + /// is a post-mortem session (e.g. a core file) or there is no underlying + /// process. + bool IsLiveDebugSession() const; + /// \{ /// \group Mask Address Methods /// diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp index 77d82581469fa..79ab659c70581 100644 --- a/lldb/source/API/SBProcess.cpp +++ b/lldb/source/API/SBProcess.cpp @@ -1354,6 +1354,15 @@ lldb::SBFileSpec SBProcess::GetCoreFile() { return SBFileSpec(core_file); } +bool SBProcess::IsLiveDebugSession() const { + LLDB_INSTRUMENT_VA(this); + + ProcessSP process_sp(GetSP()); + if (!process_sp) + return false; + return process_sp->IsLiveDebugSession(); +} + addr_t SBProcess::GetAddressMask(AddressMaskType type, AddressMaskRange addr_range) { LLDB_INSTRUMENT_VA(this, type, addr_range); diff --git a/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py b/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py index 2fe56516d8727..0a5dc6e6a41a2 100644 --- a/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py +++ b/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py @@ -223,6 +223,15 @@ def test_read_memory(self): self.assertEqual(len(bytesread), 16) self.dbg.DeleteTarget(target) + @skipIfLLVMTargetMissing("X86") + def test_is_not_live_debug_session(self): + """Test that a process loaded from a core file is not a live session.""" + target = self.dbg.CreateTarget("linux-x86_64.out") + process = target.LoadCore("linux-x86_64.core") + self.assertTrue(process, PROCESS_IS_VALID) + self.assertFalse(process.IsLiveDebugSession()) + self.dbg.DeleteTarget(target) + @skipIfLLVMTargetMissing("X86") def test_write_register(self): """Test that writing to register results in an error and that error diff --git a/lldb/test/API/python_api/process/TestProcessAPI.py b/lldb/test/API/python_api/process/TestProcessAPI.py index 25f75fe68788a..6fb1c9247b291 100644 --- a/lldb/test/API/python_api/process/TestProcessAPI.py +++ b/lldb/test/API/python_api/process/TestProcessAPI.py @@ -29,6 +29,23 @@ def test_scripted_implementation(self): self.assertTrue(process, PROCESS_IS_VALID) self.assertEqual(process.GetScriptedImplementation(), None) + def test_is_live_debug_session(self): + """Test that a launched process reports as a live debug session.""" + self.build() + + (target, process, _, _) = lldbutil.run_to_source_breakpoint( + self, "Set break point", lldb.SBFileSpec("main.cpp") + ) + + self.assertTrue(process, PROCESS_IS_VALID) + self.assertTrue(process.IsLiveDebugSession()) + + def test_is_live_debug_session_invalid_process(self): + """Test that an invalid process is not reported as a live session.""" + process = lldb.SBProcess() + self.assertFalse(process.IsValid()) + self.assertFalse(process.IsLiveDebugSession()) + def test_read_memory(self): """Test Python SBProcess.ReadMemory() API.""" self.build() _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
