You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ar...@apache.org on 2021/12/29 04:10:03 UTC
[incubator-nuttx] 02/03: libc: Prefix the address with 0 to the specified width in sched_dumpstack
This is an automated email from the ASF dual-hosted git repository.
archer pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 9eecd4c5e23c01f5e1d8ac3fc4beec1582000c1e
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun Dec 26 11:40:32 2021 +0800
libc: Prefix the address with 0 to the specified width in sched_dumpstack
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
libs/libc/sched/sched_dumpstack.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/libs/libc/sched/sched_dumpstack.c b/libs/libc/sched/sched_dumpstack.c
index 3f05af0..a6b871c 100644
--- a/libs/libc/sched/sched_dumpstack.c
+++ b/libs/libc/sched/sched_dumpstack.c
@@ -31,12 +31,14 @@
#include <syslog.h>
#include <execinfo.h>
-#define DUMP_FORMAT "%*p"
-#define DUMP_WIDTH (int)(2 * sizeof(FAR void *) + 3)
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
#define DUMP_DEPTH 16
#define DUMP_NITEM 8
-#define DUMP_LINESIZE (DUMP_NITEM * DUMP_WIDTH)
+#define DUMP_WIDTH (int)(2 * sizeof(FAR void *) + 2)
+#define DUMP_LINESZ (DUMP_NITEM * (DUMP_WIDTH + 1))
/****************************************************************************
* Public Functions
@@ -54,7 +56,8 @@ void sched_dumpstack(pid_t tid)
{
FAR void *address[DUMP_DEPTH];
#ifndef CONFIG_ALLSYMS
- char line[DUMP_LINESIZE + 1];
+ const char *format = " %0*p";
+ char line[DUMP_LINESZ + 1];
int ret = 0;
#endif
int size;
@@ -70,10 +73,10 @@ void sched_dumpstack(pid_t tid)
for (i = 0; i < size; i++)
{
ret += snprintf(line + ret, sizeof(line) - ret,
- DUMP_FORMAT, DUMP_WIDTH, address[i]);
- if (i == size - 1 || ret % DUMP_LINESIZE == 0)
+ format, DUMP_WIDTH, address[i]);
+ if (i == size - 1 || ret % DUMP_LINESZ == 0)
{
- syslog(LOG_EMERG, "backtrace|%2d: %s\n", tid, line);
+ syslog(LOG_EMERG, "backtrace|%2d:%s\n", tid, line);
ret = 0;
}
}