From 9de0465a8a5a5a4ad623de785e974fb37b376637 Mon Sep 17 00:00:00 2001 From: likun17 Date: Fri, 20 Sep 2024 14:58:46 +0800 Subject: [PATCH] lib_libvsprintf.c:add option in Kconfig to control "%p*" special format specifier. Signed-off-by: likun17 --- libs/libc/misc/lib_err.c | 44 +++++++++++++++++++++---------- libs/libc/stdio/Kconfig | 6 +++++ libs/libc/stdio/lib_libvsprintf.c | 12 +++++---- libs/libc/symtab/Kconfig | 1 + 4 files changed, 44 insertions(+), 19 deletions(-) diff --git a/libs/libc/misc/lib_err.c b/libs/libc/misc/lib_err.c index a8a27c5f88a6d..53f049c684c5c 100644 --- a/libs/libc/misc/lib_err.c +++ b/libs/libc/misc/lib_err.c @@ -55,30 +55,38 @@ do \ void vwarn(FAR const char *fmt, va_list ap) { +#ifdef CONFIG_LIBC_PRINT_EXTENSION int error = get_errno(); struct va_format vaf; -#ifdef va_copy +# ifdef va_copy va_list copy; va_copy(copy, ap); vaf.fmt = fmt; vaf.va = © -#else +# else vaf.fmt = fmt; vaf.va = ≈ -#endif +# endif -#ifdef CONFIG_FILE_STREAM +# ifdef CONFIG_FILE_STREAM fprintf(stderr, "%d: %pV: %s\n", _SCHED_GETTID(), &vaf, strerror(error)); -#else +# else dprintf(STDERR_FILENO, "%d: %pV: %s\n", _SCHED_GETTID(), &vaf, strerror(error)); -#endif +# endif -#ifdef va_copy +# ifdef va_copy va_end(copy); +# endif +#else +# ifdef CONFIG_FILE_STREAM + vfprintf(stderr, fmt, ap); +# else + vdprintf(STDERR_FILENO, fmt, ap); +# endif #endif } @@ -88,28 +96,36 @@ void vwarn(FAR const char *fmt, va_list ap) void vwarnx(FAR const char *fmt, va_list ap) { +#ifdef CONFIG_LIBC_PRINT_EXTENSION struct va_format vaf; -#ifdef va_copy +# ifdef va_copy va_list copy; va_copy(copy, ap); vaf.fmt = fmt; vaf.va = © -#else +# else vaf.fmt = fmt; vaf.va = ≈ -#endif +# endif -#ifdef CONFIG_FILE_STREAM +# ifdef CONFIG_FILE_STREAM fprintf(stderr, "%d: %pV\n", _SCHED_GETTID(), &vaf); -#else +# else dprintf(STDERR_FILENO, "%d: %pV\n", _SCHED_GETTID(), &vaf); -#endif +# endif -#ifdef va_copy +# ifdef va_copy va_end(copy); +# endif +#else +# ifdef CONFIG_FILE_STREAM + vfprintf(stderr, fmt, ap); +# else + vdprintf(STDERR_FILENO, fmt, ap); +# endif #endif } diff --git a/libs/libc/stdio/Kconfig b/libs/libc/stdio/Kconfig index 3070183c951b1..97ecea67d7c00 100644 --- a/libs/libc/stdio/Kconfig +++ b/libs/libc/stdio/Kconfig @@ -106,4 +106,10 @@ config LIBC_SCANSET ---help--- Add scanset support to sscanf(). +config LIBC_PRINT_EXTENSION + bool + default n + ---help--- + Enables vsprintf supports using "%p*" to print. + endmenu #Standard C I/O diff --git a/libs/libc/stdio/lib_libvsprintf.c b/libs/libc/stdio/lib_libvsprintf.c index 0c4cdd8deb336..610a6a42d99cf 100644 --- a/libs/libc/stdio/lib_libvsprintf.c +++ b/libs/libc/stdio/lib_libvsprintf.c @@ -1119,6 +1119,7 @@ static int vsprintf_internal(FAR struct lib_outstream_s *stream, break; case 'p': +#ifdef CONFIG_LIBC_PRINT_EXTENSION c = fmt_char(fmt); switch (c) { @@ -1133,22 +1134,22 @@ static int vsprintf_internal(FAR struct lib_outstream_s *stream, case 'V': { FAR struct va_format *vaf = (FAR void *)(uintptr_t)x; -#ifdef va_copy +# ifdef va_copy va_list copy; va_copy(copy, *vaf->va); lib_vsprintf(stream, vaf->fmt, copy); va_end(copy); -#else +# else lib_vsprintf(stream, vaf->fmt, *vaf->va); -#endif +# endif continue; } case 'S': case 's': { -#ifdef CONFIG_ALLSYMS +# ifdef CONFIG_ALLSYMS FAR const struct symtab_s *symbol; FAR void *addr = (FAR void *)(uintptr_t)x; size_t symbolsize; @@ -1173,7 +1174,7 @@ static int vsprintf_internal(FAR struct lib_outstream_s *stream, continue; } -#endif +# endif break; } @@ -1181,6 +1182,7 @@ static int vsprintf_internal(FAR struct lib_outstream_s *stream, fmt_ungetc(fmt); break; } +#endif flags |= FL_ALT; diff --git a/libs/libc/symtab/Kconfig b/libs/libc/symtab/Kconfig index 32689da1e8209..38d82adcc414d 100644 --- a/libs/libc/symtab/Kconfig +++ b/libs/libc/symtab/Kconfig @@ -5,6 +5,7 @@ config ALLSYMS bool "Load all symbols for debugging" + select LIBC_PRINT_EXTENSION default n ---help--- Say Y here to let the nuttx print out symbolic crash information and