Ver Fonte

[enhancement] Add string information for error (#3186)

* [enhancement]Add string information for error

* Update src/kservice.c

* Update src/kservice.c

Co-authored-by: Man, Jianting (Meco) <920369182@qq.com>

* remove %m

Signed-off-by: a1012112796 <1012112796@qq.com>

Co-authored-by: Meco Man <920369182@qq.com>
a1012112796 há 2 anos atrás
pai
commit
697bf139b2
3 ficheiros alterados com 38 adições e 4 exclusões
  1. 3 4
      components/finsh/cmd.c
  2. 1 0
      include/rtthread.h
  3. 34 0
      src/kservice.c

+ 3 - 4
components/finsh/cmd.c

@@ -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
                 }
             }

+ 1 - 0
include/rtthread.h

@@ -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()

+ 34 - 0
src/kservice.c

@@ -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.
  *