================
@@ -259,12 +257,17 @@ bool
ProcessFreeBSDKernelCore::DoUpdateThreadList(ThreadList &old_thread_list,
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) {
- lldb::addr_t proc = *proc_it;
+ std::sort(process_addrs.begin(), process_addrs.end(),
+ [&](lldb::addr_t a, lldb::addr_t b) {
+ Status err;
+ int32_t pid_a =
+ ReadSignedIntegerFromMemory(a + offset_p_pid, 4, -1, err);
----------------
DavidSpickett wrote:
In theory these can fail. Though we have no way to break out of the std::sort
when that happens. So we could accumulate the status value and check after the
sort, but this means failing a lot if there's some widespread issue.
The other option is to read all the PIDs up front. Have a vector of
pair<address, pid_t> . Then sort that once you know everything read correctly.
Could you read the PID at the point you do process_addrs.push_back(proc); ? So
you're pushing back the address and the read pid, as a pair. If any one of
those fails, return.
Then finally sort the list of pairs by the pid field and iterate over them.
Which is convenient because the first thing that loop does it read the pid,
again! You can reuse the pid value you read before.
https://github.com/llvm/llvm-project/pull/187976
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits