[Lldb-commits] [lldb] Add new API in SBTarget for loading core from SBFile (PR #71769)

Alex Langford via lldb-commits lldb-commits at lists.llvm.org
Thu Nov 9 09:37:35 PST 2023


================
@@ -244,9 +245,45 @@ SBProcess SBTarget::LoadCore(const char *core_file, lldb::SBError &error) {
   TargetSP target_sp(GetSP());
   if (target_sp) {
     FileSpec filespec(core_file);
-    FileSystem::Instance().Resolve(filespec);
+    auto file = FileSystem::Instance().Open(
+        filespec, lldb_private::File::eOpenOptionReadOnly);
+    if (!file) {
+      error.SetErrorStringWithFormat("Failed to open the core file: %s",
+                                     llvm::toString(file.takeError()).c_str());
+      return sb_process;
+    }
+    ProcessSP process_sp(
+        target_sp->CreateProcess(target_sp->GetDebugger().GetListener(), "",
+                                 std::move(file.get()), 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");
+  }
----------------
bulbazord wrote:

If you flip the condition that checks target_sp for validity, you can save a level of indentation for readability (if that matters to you).

https://github.com/llvm/llvm-project/pull/71769


More information about the lldb-commits mailing list