[Lldb-commits] [lldb] e2fb816 - Add new API in SBTarget for loading core from SBFile (#71769)
via lldb-commits
lldb-commits at lists.llvm.org
Fri Nov 17 09:53:16 PST 2023
Author: GeorgeHuyubo
Date: 2023-11-17T09:53:12-08:00
New Revision: e2fb816c4f0286ddf8b1030148a343d5efc14e01
URL: https://github.com/llvm/llvm-project/commit/e2fb816c4f0286ddf8b1030148a343d5efc14e01
DIFF: https://github.com/llvm/llvm-project/commit/e2fb816c4f0286ddf8b1030148a343d5efc14e01.diff
LOG: Add new API in SBTarget for loading core from SBFile (#71769)
Add a new API in SBTarget to Load Core from a SBFile.
This will enable a target to load core from a file descriptor.
So that in coredumper, we don't need to write core file to disk, instead
we can pass the input file descriptor to lldb directly.
Test:
```
(lldb) script
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
>>> file_object = open("/home/hyubo/210hda79ms32sr0h", "r")
>>> fd=file_object.fileno()
>>> file = lldb.SBFile(fd,'r', True)
>>> error = lldb.SBError()
>>> target = lldb.debugger.CreateTarget(None)
>>> target.LoadCore(file,error)
SBProcess: pid = 56415, state = stopped, threads = 1
```
Added:
Modified:
lldb/include/lldb/API/SBTarget.h
lldb/source/API/SBTarget.cpp
lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
Removed:
################################################################################
diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h
index 83087623088c5b4..8e44cd5513c5b20 100644
--- a/lldb/include/lldb/API/SBTarget.h
+++ b/lldb/include/lldb/API/SBTarget.h
@@ -184,6 +184,7 @@ class LLDB_API SBTarget {
SBProcess LoadCore(const char *core_file);
SBProcess LoadCore(const char *core_file, lldb::SBError &error);
+ SBProcess LoadCore(const SBFile &file, lldb::SBError &error);
/// Launch a new process with sensible defaults.
///
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index 2d029554492a05c..9632627e3cefc42 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -16,6 +16,7 @@
#include "lldb/API/SBEnvironment.h"
#include "lldb/API/SBEvent.h"
#include "lldb/API/SBExpressionOptions.h"
+#include "lldb/API/SBFile.h"
#include "lldb/API/SBFileSpec.h"
#include "lldb/API/SBListener.h"
#include "lldb/API/SBModule.h"
@@ -260,6 +261,31 @@ SBProcess SBTarget::LoadCore(const char *core_file, lldb::SBError &error) {
return sb_process;
}
+SBProcess SBTarget::LoadCore(const SBFile &file, lldb::SBError &error) {
+ LLDB_INSTRUMENT_VA(this, file, error);
+
+ SBProcess sb_process;
+ TargetSP target_sp(GetSP());
+ if (target_sp) {
+ FileSP file_sp = file.GetFile();
+ FileSpec filespec;
+ file_sp->GetFileSpec(filespec);
+ FileSystem::Instance().Resolve(filespec);
+ ProcessSP process_sp(target_sp->CreateProcess(
+ target_sp->GetDebugger().GetListener(), "", &filespec, false));
+ if (process_sp) {
+ error.SetError(process_sp->LoadCore());
+ if (error.Success())
+ sb_process.SetSP(process_sp);
+ } else {
+ error.SetErrorString("Failed to create the process");
+ }
+ } else {
+ error.SetErrorString("SBTarget is invalid");
+ }
+ return sb_process;
+}
+
SBProcess SBTarget::LaunchSimple(char const **argv, char const **envp,
const char *working_directory) {
LLDB_INSTRUMENT_VA(this, argv, envp, working_directory);
diff --git a/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py b/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
index 58f104eb49de245..a6a8518f9397da3 100644
--- a/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
+++ b/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
@@ -53,6 +53,11 @@ def test_x86_64(self):
"""Test that lldb can read the process information from an x86_64 linux core file."""
self.do_test("linux-x86_64", self._x86_64_pid, self._x86_64_regions, "a.out")
+ @skipIfLLVMTargetMissing("X86")
+ def test_x86_64_fd(self):
+ """Test that lldb can read the process information from an x86_64 linux core file."""
+ self.do_test_fd("linux-x86_64", self._x86_64_pid, self._x86_64_regions, "a.out")
+
@skipIfLLVMTargetMissing("SystemZ")
def test_s390x(self):
"""Test that lldb can read the process information from an s390x linux core file."""
@@ -757,6 +762,19 @@ def do_test(self, filename, pid, region_count, thread_name):
self.dbg.DeleteTarget(target)
+ def do_test_fd(self, filename, pid, region_count, thread_name):
+ file_object = open(filename + ".core", "r")
+ fd = file_object.fileno()
+ file = lldb.SBFile(fd, "r", True)
+ target = self.dbg.CreateTarget(filename + ".out")
+ error = lldb.SBError()
+ process = target.LoadCore(file, error)
+
+ self.check_all(process, pid, region_count, thread_name)
+
+ self.dbg.DeleteTarget(target)
+
+
def replace_path(binary, replace_from, replace_to):
src = replace_from.encode()
More information about the lldb-commits
mailing list