[Lldb-commits] [lldb] a339837 - Pass plugin_name in SBProcess::SaveCore

Tobias Hieta via lldb-commits lldb-commits at lists.llvm.org
Thu Jun 9 07:30:09 PDT 2022


Author: Levon
Date: 2022-06-09T16:29:50+02:00
New Revision: a33983729df641559b639a48d1b65e2de55f6e90

URL: https://github.com/llvm/llvm-project/commit/a33983729df641559b639a48d1b65e2de55f6e90
DIFF: https://github.com/llvm/llvm-project/commit/a33983729df641559b639a48d1b65e2de55f6e90.diff

LOG: Pass plugin_name in SBProcess::SaveCore

This CL allows to use minidump save-core functionality (https://reviews.llvm.org/D108233) via SBProcess interface.
After adding a support from gdb-remote client (https://reviews.llvm.org/D101329) if the plugin name is empty the plugin manager will try to save the core directly from the process plugin.
See https://github.com/llvm/llvm-project/blob/main/lldb/source/Core/PluginManager.cpp#L696

To have an ability to save the core with minidump plugin I added plugin name as a parameter in SBProcess::SaveCore.

Reviewed By: clayborg

Differential Revision: https://reviews.llvm.org/D125325

Added: 
    

Modified: 
    lldb/bindings/interface/SBProcess.i
    lldb/include/lldb/API/SBProcess.h
    lldb/source/API/SBProcess.cpp
    lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py

Removed: 
    


################################################################################
diff  --git a/lldb/bindings/interface/SBProcess.i b/lldb/bindings/interface/SBProcess.i
index 14566a2942d04..7a9f8fc5757c1 100644
--- a/lldb/bindings/interface/SBProcess.i
+++ b/lldb/bindings/interface/SBProcess.i
@@ -397,6 +397,9 @@ public:
     bool
     IsInstrumentationRuntimePresent(lldb::InstrumentationRuntimeType type);
 
+    lldb::SBError
+    SaveCore(const char *file_name, const char *flavor, lldb::SaveCoreStyle core_style);
+
     lldb::SBError
     SaveCore(const char *file_name);
 

diff  --git a/lldb/include/lldb/API/SBProcess.h b/lldb/include/lldb/API/SBProcess.h
index 73a8d918f4d65..49b3256869ed6 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -337,7 +337,21 @@ class LLDB_API SBProcess {
 
   bool IsInstrumentationRuntimePresent(InstrumentationRuntimeType type);
 
-  /// Save the state of the process in a core file (or mini dump on Windows).
+  /// Save the state of the process in a core file.
+  ///
+  /// \param[in] file_name - The name of the file to save the core file to.
+  ///
+  /// \param[in] flavor - Specify the flavor of a core file plug-in to save.
+  /// Currently supported flavors include "mach-o" and "minidump"
+  ///
+  /// \param[in] core_style - Specify the style of a core file to save.
+  lldb::SBError SaveCore(const char *file_name, const char *flavor,
+                         SaveCoreStyle core_style);
+
+  /// Save the state of the process with the a flavor that matches the
+  /// current process' main executable (if supported).
+  ///
+  /// \param[in] file_name - The name of the file to save the core file to.
   lldb::SBError SaveCore(const char *file_name);
 
   /// Query the address load_addr and store the details of the memory

diff  --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp
index 2538013412b68..27593559bb3dd 100644
--- a/lldb/source/API/SBProcess.cpp
+++ b/lldb/source/API/SBProcess.cpp
@@ -1138,6 +1138,13 @@ bool SBProcess::IsInstrumentationRuntimePresent(
 
 lldb::SBError SBProcess::SaveCore(const char *file_name) {
   LLDB_INSTRUMENT_VA(this, file_name);
+  return SaveCore(file_name, "", SaveCoreStyle::eSaveCoreFull);
+}
+
+lldb::SBError SBProcess::SaveCore(const char *file_name,
+                                  const char *flavor,
+                                  SaveCoreStyle core_style) {
+  LLDB_INSTRUMENT_VA(this, file_name, flavor, core_style);
 
   lldb::SBError error;
   ProcessSP process_sp(GetSP());
@@ -1155,8 +1162,9 @@ lldb::SBError SBProcess::SaveCore(const char *file_name) {
   }
 
   FileSpec core_file(file_name);
-  SaveCoreStyle core_style = SaveCoreStyle::eSaveCoreFull;
-  error.ref() = PluginManager::SaveCore(process_sp, core_file, core_style, "");
+  error.ref() = PluginManager::SaveCore(process_sp, core_file, core_style,
+                                        flavor);
+
   return error;
 }
 

diff  --git a/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py b/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
index a7d2a05964a4b..4275c93aadd87 100644
--- a/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
+++ b/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
@@ -21,6 +21,7 @@ def test_save_linux_mini_dump(self):
         self.build()
         exe = self.getBuildArtifact("a.out")
         core = self.getBuildArtifact("core.dmp")
+        core_sb = self.getBuildArtifact("core_sb.dmp")
         try:
             target = self.dbg.CreateTarget(exe)
             process = target.LaunchSimple(
@@ -43,6 +44,17 @@ def test_save_linux_mini_dump(self):
             # save core and, kill process and verify corefile existence
             self.runCmd("process save-core --plugin-name=minidump --style=stack " + core)
             self.assertTrue(os.path.isfile(core))
+
+            # validate savinig via SBProcess
+            error = process.SaveCore(core_sb, "minidump", lldb.eSaveCoreStackOnly)
+            self.assertTrue(error.Success())
+            self.assertTrue(os.path.isfile(core_sb))
+
+            error = process.SaveCore(core_sb, "minidump", lldb.eSaveCoreFull)
+            self.assertTrue(error.Fail())
+            error = process.SaveCore(core_sb, "minidump", lldb.eSaveCoreDirtyOnly)
+            self.assertTrue(error.Fail())
+
             self.assertSuccess(process.Kill())
 
             # To verify, we'll launch with the mini dump
@@ -77,3 +89,5 @@ def test_save_linux_mini_dump(self):
             self.assertTrue(self.dbg.DeleteTarget(target))
             if (os.path.isfile(core)):
                 os.unlink(core)
+            if (os.path.isfile(core_sb)):
+                os.unlink(core_sb)


        


More information about the lldb-commits mailing list