From 894241c8543eb0dd27b16962a640f38e9b0c6e19 Mon Sep 17 00:00:00 2001 From: Leo Sandoval Date: Tue, 23 Sep 2025 17:33:32 -0600 Subject: [PATCH] kern: Include function name on debug and error print functions With the following change, we see standard (grub_dprintf) and error (grub_error) logs with the function name embedded (see below) into the log which is particular useful when debugging: commands/efi/tpm.c:grub_tpm_measure:281:tpm: log_event, pcr = 8, size = 0xb, Including one more field on the print log impacts the binary sizes and in turn their respective distro packages. For Fedora rpm packages the increase is 20k approximately. Signed-off-by: Leo Sandoval Reviewed-by: Daniel Kiper --- grub-core/kern/err.c | 4 ++-- grub-core/kern/misc.c | 4 ++-- include/grub/err.h | 6 +++--- include/grub/misc.h | 5 +++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/grub-core/kern/err.c b/grub-core/kern/err.c index aebfe0cf8..ba04b57fb 100644 --- a/grub-core/kern/err.c +++ b/grub-core/kern/err.c @@ -38,14 +38,14 @@ static int grub_error_stack_assert; #endif grub_err_t -grub_error (grub_err_t n, const char *file, const int line, const char *fmt, ...) +grub_error (grub_err_t n, const char *file, const char *function, const int line, const char *fmt, ...) { va_list ap; int m; grub_errno = n; - m = grub_snprintf (grub_errmsg, sizeof (grub_errmsg), "%s:%d:", file, line); + m = grub_snprintf (grub_errmsg, sizeof (grub_errmsg), "%s:%s:%d:", file, function, line); if (m < 0) m = 0; diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c index 258f91893..b9ac86c18 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c @@ -231,14 +231,14 @@ grub_debug_enabled (const char * condition) } void -grub_real_dprintf (const char *file, const int line, const char *condition, +grub_real_dprintf (const char *file, const char *function, const int line, const char *condition, const char *fmt, ...) { va_list args; if (grub_debug_enabled (condition)) { - grub_printf ("%s:%d:%s: ", file, line, condition); + grub_printf ("%s:%s:%d:%s: ", file, function, line, condition); va_start (args, fmt); grub_vprintf (fmt, args); va_end (args); diff --git a/include/grub/err.h b/include/grub/err.h index 4b02d136a..99e757a80 100644 --- a/include/grub/err.h +++ b/include/grub/err.h @@ -89,10 +89,10 @@ struct grub_error_saved extern grub_err_t EXPORT_VAR(grub_errno); extern char EXPORT_VAR(grub_errmsg)[GRUB_MAX_ERRMSG]; -grub_err_t EXPORT_FUNC(grub_error) (grub_err_t n, const char *file, const int line, const char *fmt, ...) - __attribute__ ((format (GNU_PRINTF, 4, 5))); +grub_err_t EXPORT_FUNC(grub_error) (grub_err_t n, const char *file, const char *function, const int line, const char *fmt, ...) + __attribute__ ((format (GNU_PRINTF, 5, 6))); -#define grub_error(n, fmt, ...) grub_error (n, __FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define grub_error(n, fmt, ...) grub_error (n, __FILE__, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__) void EXPORT_FUNC(grub_fatal) (const char *fmt, ...) __attribute__ ((noreturn)); void EXPORT_FUNC(grub_error_push) (void); diff --git a/include/grub/misc.h b/include/grub/misc.h index 9522d7305..0d2bab7dd 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h @@ -35,7 +35,7 @@ #define ARRAY_SIZE(array) (sizeof (array) / sizeof (array[0])) #define COMPILE_TIME_ASSERT(cond) switch (0) { case 1: case !(cond): ; } -#define grub_dprintf(condition, ...) grub_real_dprintf(GRUB_FILE, __LINE__, condition, __VA_ARGS__) +#define grub_dprintf(condition, ...) grub_real_dprintf(GRUB_FILE, __FUNCTION__, __LINE__, condition, __VA_ARGS__) void *EXPORT_FUNC(grub_memmove) (void *dest, const void *src, grub_size_t n); char *EXPORT_FUNC(grub_strcpy) (char *dest, const char *src); @@ -413,9 +413,10 @@ grub_puts (const char *s) int EXPORT_FUNC(grub_puts_) (const char *s); int EXPORT_FUNC(grub_debug_enabled) (const char *condition); void EXPORT_FUNC(grub_real_dprintf) (const char *file, + const char *function, const int line, const char *condition, - const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 4, 5))); + const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 5, 6))); int EXPORT_FUNC(grub_printf) (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 1, 2))); int EXPORT_FUNC(grub_printf_) (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 1, 2))); int EXPORT_FUNC(grub_vprintf) (const char *fmt, va_list args);