[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
Fri Jul 26 11:27:19 PDT 2024


================
@@ -6621,29 +6624,28 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
           LC_THREAD_data.SetAddressByteSize(addr_byte_size);
           LC_THREAD_data.SetByteOrder(byte_order);
         }
-        for (uint32_t thread_idx = 0; thread_idx < num_threads; ++thread_idx) {
-          ThreadSP thread_sp(thread_list.GetThreadAtIndex(thread_idx));
+        for (const ThreadSP &thread_sp : thread_list) {
           if (thread_sp) {
             switch (mach_header.cputype) {
             case llvm::MachO::CPU_TYPE_ARM64:
             case llvm::MachO::CPU_TYPE_ARM64_32:
               RegisterContextDarwin_arm64_Mach::Create_LC_THREAD(
-                  thread_sp.get(), LC_THREAD_datas[thread_idx]);
+                  thread_sp.get(), LC_THREAD_datas[thread_sp->GetIndexID()]);
----------------
clayborg wrote:

We can't use `thread_sp->GetIndexID()` here, as before this was the index of the thread from `thread_list`, not the thread's index ID. Why? Because thread index IDs are unique for a process. If you have a process which starts with one thread, its index ID is 1. If this process creates a thread and we stop when this thread is created, we will create a new thread for it and its index ID will be 2. Then this thread exits and a new thread is created and we stop. We will now have two threads whose index IDs are 1 and 3. So we can't use this index as a zero based index into the LC_THREAD_datas array.


So we might need to still use a `thread_idx` in this for loop. See above.

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


More information about the lldb-commits mailing list