Skip to content

Commit

Permalink
lib_libvsprintf.c:add option in Kconfig to control "%p*" special form…
Browse files Browse the repository at this point in the history
…at specifier.

Signed-off-by: likun17 <[email protected]>
  • Loading branch information
Otpvondoiats authored and GUIDINGLI committed Oct 15, 2024
1 parent 83914d5 commit 9de0465
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 19 deletions.
44 changes: 30 additions & 14 deletions libs/libc/misc/lib_err.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = &copy;
#else
# else
vaf.fmt = fmt;
vaf.va = &ap;
#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
}

Expand All @@ -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 = &copy;
#else
# else
vaf.fmt = fmt;
vaf.va = &ap;
#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
}

Expand Down
6 changes: 6 additions & 0 deletions libs/libc/stdio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 7 additions & 5 deletions libs/libc/stdio/lib_libvsprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
Expand All @@ -1173,14 +1174,15 @@ static int vsprintf_internal(FAR struct lib_outstream_s *stream,

continue;
}
#endif
# endif
break;
}

default:
fmt_ungetc(fmt);
break;
}
#endif

flags |= FL_ALT;

Expand Down
1 change: 1 addition & 0 deletions libs/libc/symtab/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9de0465

Please sign in to comment.