@@ -33,7 +33,18 @@ static int hwthread_write_buffer(struct rtos *rtos, target_addr_t address,
33
33
34
34
static inline threadid_t threadid_from_target (const struct target * target )
35
35
{
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 ;
37
48
}
38
49
39
50
const struct rtos_type hwthread_rtos = {
@@ -54,14 +65,13 @@ struct hwthread_params {
54
65
int dummy_param ;
55
66
};
56
67
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 )
58
69
{
59
70
char tmp_str [HW_THREAD_NAME_STR_SIZE ];
60
- threadid_t tid = threadid_from_target (curr );
61
71
62
72
memset (tmp_str , 0 , HW_THREAD_NAME_STR_SIZE );
63
73
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 */
65
75
rtos -> thread_details [thread_num ].threadid = tid ;
66
76
/* create the thread name */
67
77
rtos -> thread_details [thread_num ].exists = true;
@@ -123,9 +133,8 @@ static int hwthread_update_threads(struct rtos *rtos)
123
133
if (!target_was_examined (curr ))
124
134
continue ;
125
135
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 );
129
138
130
139
/* find an interesting thread to set as current */
131
140
switch (current_reason ) {
@@ -182,8 +191,8 @@ static int hwthread_update_threads(struct rtos *rtos)
182
191
threads_found ++ ;
183
192
}
184
193
} 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 );
187
196
threads_found ++ ;
188
197
}
189
198
@@ -206,19 +215,17 @@ static int hwthread_smp_init(struct target *target)
206
215
return hwthread_update_threads (target -> rtos );
207
216
}
208
217
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 )
210
219
{
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 ))
221
222
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 ;
222
229
}
223
230
return NULL ;
224
231
}
@@ -297,7 +304,7 @@ static int hwthread_get_thread_reg(struct rtos *rtos, int64_t thread_id,
297
304
}
298
305
299
306
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." );
301
308
return ERROR_FAIL ;
302
309
}
303
310
@@ -382,9 +389,9 @@ static int hwthread_thread_packet(struct connection *connection, const char *pac
382
389
return ERROR_FAIL ;
383
390
}
384
391
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 ) {
387
393
target -> rtos -> current_thread = threadid_from_target (target );
394
+ }
388
395
389
396
target -> rtos -> current_threadid = current_threadid ;
390
397
0 commit comments