================
@@ -46,8 +48,79 @@ SaveCoreOptions::GetOutputFile() const {
   return m_file;
 }
 
+Status SaveCoreOptions::SetProcess(lldb::ProcessSP process_sp) {
+  Status error;
+  if (!process_sp) {
+    ClearProcessSpecificData();
+    m_process_sp = std::nullopt;
+    return error;
+  }
+
+  if (!process_sp->IsValid()) {
+    error.SetErrorString("Cannot assign an invalid process.");
+    return error;
+  }
+
+  if (m_process_sp.has_value())
+    ClearProcessSpecificData();
+
+  m_process_sp = process_sp;
+  return error;
+}
+
+Status SaveCoreOptions::AddThread(lldb_private::Thread *thread) {
+  Status error;
+  if (!thread) {
+    error.SetErrorString("Thread is null");
+  }
+
+  if (!m_process_sp.has_value())
+    m_process_sp = thread->GetProcess();
+
+  if (m_process_sp.value() != thread->GetProcess()) {
+    error.SetErrorString("Cannot add thread from a different process.");
+    return error;
+  }
+
+  std::pair<lldb::tid_t, lldb::ThreadSP> tid_pair(thread->GetID(),
+                                                  thread->GetBackingThread());
----------------
clayborg wrote:

We should switch the parameter to a `ThreadSP`. But FYI: `lldb_private::Thread` 
inherits from `std::enable_shared_from_this<Thread>` which means you can call 
`thread->shared_from_this()` to get a shared pointer. All of our objects that 
are held in shared pointers inherit from `std::enable_shared_from_this<T>` to 
allow them to do this.

you can change this code to:
```
m_threads_to_save[thread_sp->GetID()] = thread_sp;
```
and remove the `insert` call below.

https://github.com/llvm/llvm-project/pull/100443
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to