@@ -33,7 +33,18 @@ static int hwthread_write_buffer(struct rtos *rtos, target_addr_t address,
3333
3434static inline threadid_t threadid_from_target (const struct target * target )
3535{
36- return target -> coreid + 1 ;
36+ if (!target -> smp )
37+ return 1 ;
38+
39+ threadid_t threadid = 1 ;
40+ struct target_list * head ;
41+ foreach_smp_target (head , target -> smp_targets ) {
42+ if (target == head -> target )
43+ return threadid ;
44+ ++ threadid ;
45+ }
46+ assert (0 && "Target is not found in it's own SMP group!" );
47+ return -1 ;
3748}
3849
3950const struct rtos_type hwthread_rtos = {
@@ -54,14 +65,13 @@ struct hwthread_params {
5465 int dummy_param ;
5566};
5667
57- static int hwthread_fill_thread (struct rtos * rtos , struct target * curr , int thread_num )
68+ static int hwthread_fill_thread (struct rtos * rtos , struct target * curr , int thread_num , threadid_t tid )
5869{
5970 char tmp_str [HW_THREAD_NAME_STR_SIZE ];
60- threadid_t tid = threadid_from_target (curr );
6171
6272 memset (tmp_str , 0 , HW_THREAD_NAME_STR_SIZE );
6373
64- /* thread-id is the core-id of this core inside the SMP group plus 1 */
74+ /* thread-id is the index of this core inside the SMP group plus 1 */
6575 rtos -> thread_details [thread_num ].threadid = tid ;
6676 /* create the thread name */
6777 rtos -> thread_details [thread_num ].exists = true;
@@ -123,9 +133,8 @@ static int hwthread_update_threads(struct rtos *rtos)
123133 if (!target_was_examined (curr ))
124134 continue ;
125135
126- threadid_t tid = threadid_from_target (curr );
127-
128- hwthread_fill_thread (rtos , curr , threads_found );
136+ threadid_t tid = threads_found + 1 ;
137+ hwthread_fill_thread (rtos , curr , threads_found , tid );
129138
130139 /* find an interesting thread to set as current */
131140 switch (current_reason ) {
@@ -182,8 +191,8 @@ static int hwthread_update_threads(struct rtos *rtos)
182191 threads_found ++ ;
183192 }
184193 } else {
185- hwthread_fill_thread ( rtos , target , threads_found ) ;
186- current_thread = threadid_from_target ( target );
194+ current_thread = 1 ;
195+ hwthread_fill_thread ( rtos , target , threads_found , current_thread );
187196 threads_found ++ ;
188197 }
189198
@@ -206,19 +215,17 @@ static int hwthread_smp_init(struct target *target)
206215 return hwthread_update_threads (target -> rtos );
207216}
208217
209- static struct target * hwthread_find_thread (struct target * target , int64_t thread_id )
218+ static struct target * hwthread_find_thread (struct target * target , threadid_t thread_id )
210219{
211- /* Find the thread with that thread_id */
212- if (!target )
213- return NULL ;
214- if (target -> smp ) {
215- struct target_list * head ;
216- foreach_smp_target (head , target -> smp_targets ) {
217- if (thread_id == threadid_from_target (head -> target ))
218- return head -> target ;
219- }
220- } else if (thread_id == threadid_from_target (target )) {
220+ /* Find the thread with that thread_id (index in SMP group plus 1)*/
221+ if (!(target && target -> smp ))
221222 return target ;
223+ struct target_list * head ;
224+ threadid_t tid = 1 ;
225+ foreach_smp_target (head , target -> smp_targets ) {
226+ if (thread_id == tid )
227+ return head -> target ;
228+ ++ tid ;
222229 }
223230 return NULL ;
224231}
@@ -297,7 +304,7 @@ static int hwthread_get_thread_reg(struct rtos *rtos, int64_t thread_id,
297304 }
298305
299306 if (!target_was_examined (curr )) {
300- LOG_ERROR ( "Target %d hasn't been examined yet." , curr -> coreid );
307+ LOG_TARGET_ERROR ( curr , "Target hasn't been examined yet." );
301308 return ERROR_FAIL ;
302309 }
303310
@@ -382,9 +389,9 @@ static int hwthread_thread_packet(struct connection *connection, const char *pac
382389 return ERROR_FAIL ;
383390 }
384391 target -> rtos -> current_thread = current_threadid ;
385- } else
386- if (current_threadid == 0 || current_threadid == -1 )
392+ } else if (current_threadid == 0 || current_threadid == -1 ) {
387393 target -> rtos -> current_thread = threadid_from_target (target );
394+ }
388395
389396 target -> rtos -> current_threadid = current_threadid ;
390397
0 commit comments