Skip to content

[enhancement] Add string information for error #3186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions components/finsh/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,14 @@ long list_thread(void)
thread->error);
#else
ptr = (rt_uint8_t *)thread->stack_addr;
while (*ptr == '#')ptr ++;

rt_kprintf(" 0x%08x 0x%08x %02d%% 0x%08x %03d\n",
while (*ptr == '#') ptr ++;
rt_kprintf(" 0x%08x 0x%08x %02d%% 0x%08x %s\n",
thread->stack_size + ((rt_ubase_t)thread->stack_addr - (rt_ubase_t)thread->sp),
thread->stack_size,
(thread->stack_size - ((rt_ubase_t) ptr - (rt_ubase_t) thread->stack_addr)) * 100
/ thread->stack_size,
thread->remaining_tick,
thread->error);
rt_strerror(thread->error));
#endif
}
}
Expand Down
1 change: 1 addition & 0 deletions include/rtthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ rt_device_t rt_console_get_device(void);
rt_err_t rt_get_errno(void);
void rt_set_errno(rt_err_t no);
int *_rt_errno(void);
const char *rt_strerror(rt_err_t error);
#if !defined(RT_USING_NEWLIB) && !defined(_WIN32)
#ifndef errno
#define errno *_rt_errno()
Expand Down
34 changes: 34 additions & 0 deletions src/kservice.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,40 @@ RT_WEAK void rt_hw_us_delay(rt_uint32_t us)
"Please consider implementing rt_hw_us_delay() in another file."));
}

static const char* rt_errno_strs[] =
{
"OK",
"ERROR",
"ETIMOUT",
"ERSFULL",
"ERSEPTY",
"ENOMEM",
"ENOSYS",
"EBUSY",
"EIO",
"EINTRPT",
"EINVAL",
"EUNKNOW"
};

/**
* This function return a pointer to a string that contains the
* message of error.
*
* @param error the errorno code
* @return a point to error message string
*/
const char *rt_strerror(rt_err_t error)
{
if (error < 0)
error = -error;

return (error > RT_EINVAL + 1) ?
rt_errno_strs[RT_EINVAL + 1] :
rt_errno_strs[error];
}
RTM_EXPORT(rt_strerror);

/**
* This function gets the global errno for the current thread.
*
Expand Down