libc/execinfo: extract a common backtrace format function

Add a common method to format backtrace to buffer, so it can be used by both mm, fs and other possoble modules.

Signed-off-by: fangpeina <fangpeina@xiaomi.com>
This commit is contained in:
fangpeina
2024-06-18 18:03:15 +08:00
committed by Xiang Xiao
parent ed099f1cea
commit 242b50f921
6 changed files with 91 additions and 73 deletions
+14 -3
View File
@@ -27,15 +27,24 @@
#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())
/****************************************************************************
* Public Function Prototypes
@@ -52,6 +61,8 @@ extern "C"
FAR char **backtrace_symbols(FAR void *const *buffer, int size);
void backtrace_symbols_fd(FAR void *const *buffer, int size, int fd);
int backtrace_format(FAR char *buffer, int size,
FAR void *backtrace[], int depth);
#undef EXTERN
#if defined(__cplusplus)