@@ -724,17 +724,12 @@ GetJSONThreadsInfo(NativeProcessProtocol &process, bool abridged) {
724724 json::Array threads_array;
725725
726726 // Ensure we can get info on the given thread.
727- uint32_t thread_idx = 0 ;
728- for (NativeThreadProtocol *thread;
729- (thread = process.GetThreadAtIndex (thread_idx)) != nullptr ;
730- ++thread_idx) {
731-
732- lldb::tid_t tid = thread->GetID ();
733-
727+ for (NativeThreadProtocol &thread : process.Threads ()) {
728+ lldb::tid_t tid = thread.GetID ();
734729 // Grab the reason this thread stopped.
735730 struct ThreadStopInfo tid_stop_info;
736731 std::string description;
737- if (!thread-> GetStopReason (tid_stop_info, description))
732+ if (!thread. GetStopReason (tid_stop_info, description))
738733 return llvm::make_error<llvm::StringError>(
739734 " failed to get stop reason" , llvm::inconvertibleErrorCode ());
740735
@@ -751,7 +746,7 @@ GetJSONThreadsInfo(NativeProcessProtocol &process, bool abridged) {
751746 json::Object thread_obj;
752747
753748 if (!abridged) {
754- if (llvm::Optional<json::Object> registers = GetRegistersAsJSON (* thread))
749+ if (llvm::Optional<json::Object> registers = GetRegistersAsJSON (thread))
755750 thread_obj.try_emplace (" registers" , std::move (*registers));
756751 }
757752
@@ -760,7 +755,7 @@ GetJSONThreadsInfo(NativeProcessProtocol &process, bool abridged) {
760755 if (signum != 0 )
761756 thread_obj.try_emplace (" signal" , signum);
762757
763- const std::string thread_name = thread-> GetName ();
758+ const std::string thread_name = thread. GetName ();
764759 if (!thread_name.empty ())
765760 thread_obj.try_emplace (" name" , thread_name);
766761
@@ -856,14 +851,12 @@ GDBRemoteCommunicationServerLLGS::PrepareStopReplyPacketForThread(
856851 if (m_list_threads_in_stop_reply) {
857852 response.PutCString (" threads:" );
858853
859- uint32_t thread_index = 0 ;
860- NativeThreadProtocol *listed_thread;
861- for (listed_thread = process.GetThreadAtIndex (thread_index); listed_thread;
862- ++thread_index,
863- listed_thread = process.GetThreadAtIndex (thread_index)) {
864- if (thread_index > 0 )
854+ uint32_t thread_num = 0 ;
855+ for (NativeThreadProtocol &listed_thread : process.Threads ()) {
856+ if (thread_num > 0 )
865857 response.PutChar (' ,' );
866- response.Printf (" %" PRIx64, listed_thread->GetID ());
858+ response.Printf (" %" PRIx64, listed_thread.GetID ());
859+ ++thread_num;
867860 }
868861 response.PutChar (' ;' );
869862
@@ -872,7 +865,7 @@ GDBRemoteCommunicationServerLLGS::PrepareStopReplyPacketForThread(
872865 // is hex ascii JSON that contains the thread IDs thread stop info only for
873866 // threads that have stop reasons. Only send this if we have more than one
874867 // thread otherwise this packet has all the info it needs.
875- if (thread_index > 1 ) {
868+ if (thread_num > 1 ) {
876869 const bool threads_with_valid_stop_info_only = true ;
877870 llvm::Expected<json::Array> threads_info = GetJSONThreadsInfo (
878871 *m_current_process, threads_with_valid_stop_info_only);
@@ -889,12 +882,10 @@ GDBRemoteCommunicationServerLLGS::PrepareStopReplyPacketForThread(
889882 }
890883 }
891884
892- uint32_t i = 0 ;
893885 response.PutCString (" thread-pcs" );
894886 char delimiter = ' :' ;
895- for (NativeThreadProtocol *thread;
896- (thread = process.GetThreadAtIndex (i)) != nullptr ; ++i) {
897- NativeRegisterContext ®_ctx = thread->GetRegisterContext ();
887+ for (NativeThreadProtocol &thread : process.Threads ()) {
888+ NativeRegisterContext ®_ctx = thread.GetRegisterContext ();
898889
899890 uint32_t reg_to_read = reg_ctx.ConvertRegisterKindToRegisterNumber (
900891 eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC );
@@ -1024,12 +1015,10 @@ void GDBRemoteCommunicationServerLLGS::EnqueueStopReplyPackets(
10241015 if (!m_non_stop)
10251016 return ;
10261017
1027- uint32_t thread_index = 0 ;
1028- while (NativeThreadProtocol *listed_thread =
1029- m_current_process->GetThreadAtIndex (thread_index++)) {
1030- if (listed_thread->GetID () != thread_to_skip)
1018+ for (NativeThreadProtocol &listed_thread : m_current_process->Threads ()) {
1019+ if (listed_thread.GetID () != thread_to_skip)
10311020 m_stop_notification_queue.push_back (
1032- PrepareStopReplyPacketForThread (* listed_thread).GetString ().str ());
1021+ PrepareStopReplyPacketForThread (listed_thread).GetString ().str ());
10331022 }
10341023}
10351024
@@ -1990,15 +1979,10 @@ void GDBRemoteCommunicationServerLLGS::AddProcessThreads(
19901979 return ;
19911980
19921981 LLDB_LOG (log, " iterating over threads of process {0}" , process.GetID ());
1993- NativeThreadProtocol *thread;
1994- uint32_t thread_index;
1995- for (thread_index = 0 , thread = process.GetThreadAtIndex (thread_index);
1996- thread;
1997- ++thread_index, thread = process.GetThreadAtIndex (thread_index)) {
1998- LLDB_LOG (log, " iterated thread {0} (tid={1})" , thread_index,
1999- thread->GetID ());
1982+ for (NativeThreadProtocol &thread : process.Threads ()) {
1983+ LLDB_LOG (log, " iterated thread tid={0}" , thread.GetID ());
20001984 response.PutChar (had_any ? ' ,' : ' m' );
2001- AppendThreadIDToResponse (response, pid, thread-> GetID ());
1985+ AppendThreadIDToResponse (response, pid, thread. GetID ());
20021986 had_any = true ;
20031987 }
20041988}
0 commit comments