[Lldb-commits] [lldb] [LLDB][SBSaveCore] Implement a selectable threadlist for Core Options. (PR #100443)

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Wed Jul 24 12:31:54 PDT 2024


================
@@ -46,8 +46,59 @@ SaveCoreOptions::GetOutputFile() const {
   return m_file;
 }
 
+void SaveCoreOptions::AddThread(lldb::tid_t tid) {
+  if (m_threads_to_save.count(tid) == 0)
+    m_threads_to_save.emplace(tid);
+}
+
+bool SaveCoreOptions::RemoveThread(lldb::tid_t tid) {
+  if (m_threads_to_save.count(tid) == 0) {
+    m_threads_to_save.erase(tid);
+    return true;
+  }
+
+  return false;
+}
+
+size_t SaveCoreOptions::GetNumThreads() const {
+  return m_threads_to_save.size();
+}
+
+int64_t SaveCoreOptions::GetThreadAtIndex(size_t index) const {
+  auto iter = m_threads_to_save.begin();
+  while (index >= 0 && iter != m_threads_to_save.end()) {
+    if (index == 0)
+      return *iter;
+    index--;
+    iter++;
+  }
+
+  return -1;
+}
+
+bool SaveCoreOptions::ShouldSaveThread(lldb::tid_t tid) const {
+  // If the user specified no threads to save, then we save all threads.
+  if (m_threads_to_save.empty())
+    return true;
+  return m_threads_to_save.count(tid) > 0;
+}
+
+Status SaveCoreOptions::EnsureValidConfiguration() const {
+  Status error;
+  std::string error_str;
+  if (!m_threads_to_save.empty() && GetStyle() == lldb::eSaveCoreFull) {
+    error_str += "Cannot save a full core with a subset of threads\n";
----------------
clayborg wrote:

Should we allow "full" core files to be emitted without some thread stacks? We could allow "full" to mean save all memory regions except the thread stacks for any threads that were not in the list. This would allow core files to be a bit smaller, but still contain all mapped memory except the thread stacks we didn't want. We can emit a warning when saving a core file saying something to this effect like we do for "stacks" and "modified-memory"

The reason I say this is for core files for and Apple systems. If you save a `full` style, all mach-o binaries are fully mapped into memory and you would have everything you need to load the core file as all system libraries are mapped into memory, and it would be nice to be able to not save all thread stacks if you don't need them. So maybe turn this into a warning we can expose to the user

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


More information about the lldb-commits mailing list