[Lldb-commits] [lldb] [lldb] [Process/FreeBSDKernel] List threads in correct order (PR #178306)
Alex Langford via lldb-commits
lldb-commits at lists.llvm.org
Thu Jan 29 11:01:20 PST 2026
================
@@ -174,29 +174,39 @@ bool ProcessFreeBSDKernel::DoUpdateThreadList(ThreadList &old_thread_list,
ReadSignedIntegerFromMemory(FindSymbol("dumptid"), 4, -1, error);
lldb::addr_t dumppcb = FindSymbol("dumppcb");
- // stoppcbs is an array of PCBs on all CPUs
- // each element is of size pcb_size
+ // stoppcbs is an array of PCBs on all CPUs.
+ // Each element is of size pcb_size.
int32_t pcbsize =
ReadSignedIntegerFromMemory(FindSymbol("pcb_size"), 4, -1, error);
lldb::addr_t stoppcbs = FindSymbol("stoppcbs");
// from FreeBSD sys/param.h
constexpr size_t fbsd_maxcomlen = 19;
- // iterate through a linked list of all processes
- // allproc is a pointer to the first list element, p_list field
- // (found at offset_p_list) specifies the next element
+ // Iterate through a linked list of all processes. New processes are added
+ // to the head of this list. Which means that earlier PIDs are actually at
+ // the end of the list, so we have to walk it backwards. First collect all
+ // the processes in the list order.
+ std::vector<lldb::addr_t> process_addrs;
for (lldb::addr_t proc =
ReadPointerFromMemory(FindSymbol("allproc"), error);
proc != 0 && proc != LLDB_INVALID_ADDRESS;
proc = ReadPointerFromMemory(proc + offset_p_list, error)) {
+ process_addrs.push_back(proc);
+ }
+
+ // Processes are in the linked list in descending PID order, so we must walk
+ // them in reverse to get ascending PID order.
+ for (auto proc_it = process_addrs.rbegin(); proc_it != process_addrs.rend();
+ ++proc_it) {
----------------
bulbazord wrote:
Are the curly braces balanced? I see you adding an opening brace but I don't see an added closing brace or a removed opening brace.
https://github.com/llvm/llvm-project/pull/178306
More information about the lldb-commits
mailing list