From 5c19eac1c8c95fa0e40fa71da664326d29dcaf18 Mon Sep 17 00:00:00 2001 From: Sean Callanan Date: Wed, 6 Nov 2013 19:28:40 +0000 Subject: Added Iterable, a class that vends standard C++ iterators for LLDB's container data structures. Iterable abstracts over the backing data structure, ignoring keys for maps for example. It also provides locking as a service so that the code for (ThreadSP thread_sp : process->Threads()) { // ... use thread_sp } takes the appropriate locks once, without having to do anything else. The salient advantages of this system are: - Much simpler and idiomatic loop code - Lock once instead of each time an element is fetched - Less boilerplate to produce the iterators The intent is that Iterable will replace Get...AtIndex in most places, and that ForEach(), which solves the same problem in a less-idiomatic way, be phased out in favor of this approach. I've added Iterables to ThreadList, TypeList, and Process (which is really just forwarding to ThreadList). llvm-svn: 194159 --- lldb/source/Commands/CommandObjectThread.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'lldb/source/Commands/CommandObjectThread.cpp') diff --git a/lldb/source/Commands/CommandObjectThread.cpp b/lldb/source/Commands/CommandObjectThread.cpp index f46a221..3dce83c 100644 --- a/lldb/source/Commands/CommandObjectThread.cpp +++ b/lldb/source/Commands/CommandObjectThread.cpp @@ -183,24 +183,23 @@ protected: else if (command.GetArgumentCount() == 1 && ::strcmp (command.GetArgumentAtIndex(0), "all") == 0) { Process *process = m_exe_ctx.GetProcessPtr(); - Mutex::Locker locker (process->GetThreadList().GetMutex()); - uint32_t num_threads = process->GetThreadList().GetSize(); - for (uint32_t i = 0; i < num_threads; i++) + uint32_t idx = 0; + for (ThreadSP thread_sp : process->Threads()) { - ThreadSP thread_sp = process->GetThreadList().GetThreadAtIndex(i); + if (idx != 0) + result.AppendMessage(""); + if (!thread_sp->GetStatus (strm, m_options.m_start, m_options.m_count, num_frames_with_source)) { - result.AppendErrorWithFormat ("error displaying backtrace for thread: \"0x%4.4x\"\n", i); + result.AppendErrorWithFormat ("error displaying backtrace for thread: \"0x%4.4x\"\n", idx); result.SetStatus (eReturnStatusFailed); return false; } - if (i < num_threads - 1) - result.AppendMessage(""); - + ++idx; } } else -- cgit v1.1