kernel: Update k_thread_state_str()

Updates k_thread_state_str() to interpret the halting bits
correctly.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
This commit is contained in:
Peter Mitsis 2023-08-15 10:43:59 -04:00 committed by Anas Nashif
commit 9364ba4353

View file

@ -311,15 +311,33 @@ static size_t copy_bytes(char *dest, size_t dest_size, const char *src, size_t s
return bytes_to_copy;
}
#define Z_STATE_STR_DUMMY "dummy"
#define Z_STATE_STR_PENDING "pending"
#define Z_STATE_STR_PRESTART "prestart"
#define Z_STATE_STR_DEAD "dead"
#define Z_STATE_STR_SUSPENDED "suspended"
#define Z_STATE_STR_ABORTING "aborting"
#define Z_STATE_STR_SUSPENDING "suspending"
#define Z_STATE_STR_QUEUED "queued"
const char *k_thread_state_str(k_tid_t thread_id, char *buf, size_t buf_size)
{
size_t off = 0;
uint8_t bit;
uint8_t thread_state = thread_id->base.thread_state;
static const char *states_str[8] = {"dummy", "pending", "prestart",
"dead", "suspended", "aborting",
"", "queued"};
static const size_t states_sz[8] = {5, 7, 8, 4, 9, 8, 0, 6};
static const struct {
const char *str;
size_t len;
} state_string[] = {
{ Z_STATE_STR_DUMMY, sizeof(Z_STATE_STR_DUMMY) - 1},
{ Z_STATE_STR_PENDING, sizeof(Z_STATE_STR_PENDING) - 1},
{ Z_STATE_STR_PRESTART, sizeof(Z_STATE_STR_PRESTART) - 1},
{ Z_STATE_STR_DEAD, sizeof(Z_STATE_STR_DEAD) - 1},
{ Z_STATE_STR_SUSPENDED, sizeof(Z_STATE_STR_SUSPENDED) - 1},
{ Z_STATE_STR_ABORTING, sizeof(Z_STATE_STR_ABORTING) - 1},
{ Z_STATE_STR_SUSPENDING, sizeof(Z_STATE_STR_SUSPENDING) - 1},
{ Z_STATE_STR_QUEUED, sizeof(Z_STATE_STR_QUEUED) - 1},
};
if ((buf == NULL) || (buf_size == 0)) {
return "";
@ -333,14 +351,16 @@ const char *k_thread_state_str(k_tid_t thread_id, char *buf, size_t buf_size)
* separate the descriptive strings with a '+'.
*/
for (uint8_t index = 0; thread_state != 0; index++) {
for (unsigned int index = 0; thread_state != 0; index++) {
bit = BIT(index);
if ((thread_state & bit) == 0) {
continue;
}
off += copy_bytes(buf + off, buf_size - off,
states_str[index], states_sz[index]);
state_string[index].str,
state_string[index].len);
thread_state &= ~bit;