dde_linux: fully enable printk format specifiers

The new Lx_kit::Console::print_string() method skips leading
log-level markers in strings if detected.

Issue #4542
This commit is contained in:
Christian Helmuth 2022-05-24 11:47:20 +02:00
parent 7d2f019681
commit ea8df22dbb
5 changed files with 36 additions and 3 deletions

View File

@ -1,6 +1,7 @@
/*
* \brief Lx_emul support to log messages from the kernel code
* \author Stefan Kalkowski
* \author Christian Helmuth
* \date 2021-03-24
*/
@ -19,6 +20,7 @@ extern "C" {
#endif
void lx_emul_vprintf(char const *, va_list);
void lx_emul_print_string(char const *);
#ifdef __cplusplus
}

View File

@ -2,6 +2,7 @@
* \brief Lx_kit format string backend
* \author Stefan Kalkowski
* \author Sebastian Sumpf
* \author Christian Helmuth
* \date 2021-03-17
*
* Greatly inspired by the former DDE Linux Lx_kit implementation.
@ -127,6 +128,7 @@ class Lx_kit::Console
public:
void vprintf(const char *format, va_list list);
void print_string(const char *str);
};
#endif /* _LX_KIT__CONSOLE_H_ */

View File

@ -1,6 +1,7 @@
/*
* \brief Linux Kernel log messages
* \author Stefan Kalkowski
* \author Christian Helmuth
* \date 2021-03-22
*/
@ -16,3 +17,6 @@
extern "C" void lx_emul_vprintf(char const *fmt, va_list va) {
Lx_kit::env().console.vprintf(fmt, va); }
extern "C" void lx_emul_print_string(char const *str) {
Lx_kit::env().console.print_string(str); }

View File

@ -1,6 +1,7 @@
/*
* \brief Replaces kernel/printk/printk.c
* \author Stefan Kalkowski
* \author Christian Helmuth
* \date 2021-03-16
*/
@ -12,22 +13,29 @@
*/
#include <linux/printk.h>
#include <linux/kernel.h>
#include <lx_emul/log.h>
#include <lx_emul/debug.h>
static char print_string[2048];
asmlinkage __visible int printk(const char * fmt,...)
{
va_list args;
va_start(args, fmt);
lx_emul_vprintf(fmt, args);
vsnprintf(print_string, sizeof(print_string), fmt, args);
va_end(args);
lx_emul_print_string(print_string);
return 0;
}
asmlinkage int vprintk(const char * fmt, va_list args)
{
lx_emul_vprintf(fmt, args);
vsnprintf(print_string, sizeof(print_string), fmt, args);
lx_emul_print_string(print_string);
return 0;
}
@ -36,7 +44,8 @@ asmlinkage int vprintk_emit(int facility, int level,
const struct dev_printk_info *dev_info,
const char * fmt, va_list args)
{
lx_emul_vprintf(fmt, args);
vsnprintf(print_string, sizeof(print_string), fmt, args);
lx_emul_print_string(print_string);
return 0;
}

View File

@ -2,6 +2,7 @@
* \brief Lx_kit format string backend
* \author Stefan Kalkowski
* \author Sebastian Sumpf
* \author Christian Helmuth
* \date 2021-03-17
*
* Greatly inspired by the former DDE Linux Lx_kit implementation.
@ -208,6 +209,21 @@ void Lx_kit::Console::_out_string(const char *str)
}
void Lx_kit::Console::print_string(const char *str)
{
if (!str) {
_out_string("<null string>");
return;
}
/* strip potential control characters for log level */
if (*str == 1)
str += 2;
_out_string(str);
}
void Lx_kit::Console::vprintf(const char *format, va_list list)
{
while (*format) {