XuNeo commented on code in PR #12585:
URL: https://github.com/apache/nuttx/pull/12585#discussion_r1659535368
##########
include/execinfo.h:
##########
@@ -27,15 +27,43 @@
#include <nuttx/sched.h>
+#include <assert.h>
+#include <stdio.h>
#include <sys/types.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
-#define backtrace(buffer, size) sched_backtrace(_SCHED_GETTID(), \
- buffer, size, 0)
-#define dump_stack() sched_dumpstack(_SCHED_GETTID())
+/* 3: ' 0x' prefix */
+
+#define BACKTRACE_PTR_FMT_WIDTH ((int)sizeof(uintptr_t) * 2 + 3)
+
+/* Buffer size needed to hold formatted `depth` backtraces */
+
+#define BACKTRACE_BUFFER_SIZE(d) (BACKTRACE_PTR_FMT_WIDTH * (d) + 1)
+
+#define backtrace(b, s) sched_backtrace(_SCHED_GETTID(), b, s, 0)
+#define dump_stack() sched_dumpstack(_SCHED_GETTID())
+
+/* Format a backtrace into a buffer for dumping. */
+
+#define backtrace_format(buf, buflen, backtrace, depth) \
Review Comment:
Done.
##########
include/execinfo.h:
##########
@@ -27,15 +27,43 @@
#include <nuttx/sched.h>
+#include <assert.h>
+#include <stdio.h>
#include <sys/types.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
-#define backtrace(buffer, size) sched_backtrace(_SCHED_GETTID(), \
- buffer, size, 0)
-#define dump_stack() sched_dumpstack(_SCHED_GETTID())
+/* 3: ' 0x' prefix */
+
+#define BACKTRACE_PTR_FMT_WIDTH ((int)sizeof(uintptr_t) * 2 + 3)
+
+/* Buffer size needed to hold formatted `depth` backtraces */
+
+#define BACKTRACE_BUFFER_SIZE(d) (BACKTRACE_PTR_FMT_WIDTH * (d) + 1)
+
+#define backtrace(b, s) sched_backtrace(_SCHED_GETTID(), b, s, 0)
+#define dump_stack() sched_dumpstack(_SCHED_GETTID())
+
+/* Format a backtrace into a buffer for dumping. */
+
+#define backtrace_format(buf, buflen, backtrace, depth) \
+do \
+ { \
+ FAR const char *format = "%0*p "; \
+ int i; \
+ \
+ DEBUGASSERT(buflen >= BACKTRACE_BUFFER_SIZE(depth)); \
+ buf[0] = '\0'; \
+ for (i = 0; i < depth && backtrace[i]; i++) \
+ { \
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]