rtos/FreeRTOS: solve some conflicting usage of thread id. (#865)

* rtos/FreeRTOS: solve some conflicting usage of thread id.

1.
There are some RISCV-specific usage of thread_id, which has conflict with upstream.
Some adaptions are made in this patch, to make sure OpenOCD is sending a clear thread list to gdb.

2.
Use freertos_read_struct_value for xSchedulerRunning.

Change-Id: I001a88a0c6d8eac98a389c0217b4897f28124840
Signed-off-by: Chao Du <duchao@eswincomputing.com>

* fix typo.

Change-Id: Id6546cc74de44bbee7e44b7cb29b769a2f35ec4a

* correct the data type.

Change-Id: I28c7e111e569d94ba5f6e1ae21745ddb34d4dd12

* changes as per the review comment.

Change-Id: Ica4c705a8f2657700dc27e24790287ca802480fd

* another macro replacement.

Change-Id: Ia9330fed32d917cf87804051ba1b8d6ac42cfb7b

---------

Signed-off-by: Chao Du <duchao@eswincomputing.com>
This commit is contained in:
Chao Du 2023-06-23 00:05:29 +08:00 committed by GitHub
parent 470c2a402c
commit a45589d60a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 11 deletions

View File

@ -22,6 +22,7 @@
#define FREERTOS_MAX_PRIORITIES 63
#define FREERTOS_THREAD_NAME_STR_SIZE 200
#define FREERTOS_CURRENT_EXECUTION_ID 1
struct freertos_params {
const char *target_name;
@ -511,15 +512,17 @@ static int freertos_update_threads(struct rtos *rtos)
px_current_tcb);
/* read scheduler running */
uint32_t scheduler_running;
retval = target_read_u32(rtos->target,
rtos->symbols[FREERTOS_VAL_X_SCHEDULER_RUNNING].address,
&scheduler_running);
uint64_t scheduler_running;
retval = freertos_read_struct_value(rtos->target,
rtos->symbols[FREERTOS_VAL_X_SCHEDULER_RUNNING].address,
0,
freertos->ubasetype_size,
&scheduler_running);
if (retval != ERROR_OK) {
LOG_ERROR("Error reading FreeRTOS scheduler state");
return retval;
}
LOG_DEBUG("FreeRTOS: Read xSchedulerRunning at 0x%" PRIx64 ", value 0x%" PRIx32,
LOG_DEBUG("FreeRTOS: Read xSchedulerRunning at 0x%" PRIx64 ", value 0x%" PRIx64,
rtos->symbols[FREERTOS_VAL_X_SCHEDULER_RUNNING].address,
scheduler_running);
@ -536,8 +539,8 @@ static int freertos_update_threads(struct rtos *rtos)
LOG_ERROR("Error allocating memory for %" PRIu64 " threads", thread_list_size);
return ERROR_FAIL;
}
rtos->current_thread = 1;
rtos->thread_details->threadid = 1;
rtos->current_thread = FREERTOS_CURRENT_EXECUTION_ID;
rtos->thread_details->threadid = rtos->current_thread;
rtos->thread_details->exists = true;
rtos->thread_details->extra_info_str = NULL;
rtos->thread_details->thread_name_str = malloc(sizeof(tmp_str));
@ -608,7 +611,6 @@ static int freertos_update_threads(struct rtos *rtos)
list_of_lists[num_lists++] = rtos->symbols[FREERTOS_VAL_X_SUSPENDED_TASK_LIST].address;
list_of_lists[num_lists++] = rtos->symbols[FREERTOS_VAL_X_TASKS_WAITING_TERMINATION].address;
rtos->current_thread = 0;
for (unsigned int i = 0; i < num_lists; i++) {
if (list_of_lists[i] == 0)
continue;
@ -670,8 +672,12 @@ static int freertos_update_threads(struct rtos *rtos)
if (!value) {
struct freertos_thread_entry *new_value = calloc(1, sizeof(struct freertos_thread_entry));
new_value->tcb = tcb;
/* threadid can't be 0. */
new_value->threadid = ++freertos->last_threadid;
/* threadid can't be 0.
* plus 1 to avoid duplication with "Current Execution" */
new_value->threadid = ++freertos->last_threadid + FREERTOS_CURRENT_EXECUTION_ID;
LOG_DEBUG("FreeRTOS: new thread created, tcb=0x%" PRIx64 ", threadid=0x%" PRIx64,
new_value->tcb, new_value->threadid);
list_add_tail(&new_value->list, &freertos->thread_entry_list);
value = new_value;
@ -711,7 +717,7 @@ static int freertos_update_threads(struct rtos *rtos)
strcpy(rtos->thread_details[tasks_found].thread_name_str, tmp_str);
rtos->thread_details[tasks_found].exists = true;
if (value->tcb == px_current_tcb) {
if (value->tcb == px_current_tcb && rtos->current_thread != FREERTOS_CURRENT_EXECUTION_ID) {
char running_str[] = "State: Running";
rtos->current_thread = value->threadid;
rtos->thread_details[tasks_found].extra_info_str = malloc(