]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
kern: Include function name on debug and error print functions
authorLeo Sandoval <lsandova@redhat.com>
Tue, 23 Sep 2025 23:33:32 +0000 (17:33 -0600)
committerDaniel Kiper <daniel.kiper@oracle.com>
Sat, 11 Oct 2025 13:36:53 +0000 (15:36 +0200)
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 <lsandova@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/kern/err.c
grub-core/kern/misc.c
include/grub/err.h
include/grub/misc.h

index aebfe0cf8394f6a5061af84a7d3ab02452294703..ba04b57fb7ddcb2abbe38e38517e22d8dfa293fa 100644 (file)
@@ -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;
 
index 258f918935cc4f959f98dd31cf7f3fe8ab369969..b9ac86c1866aefa1eb637858cf3b5a0048b05bbe 100644 (file)
@@ -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);
index 4b02d136a7b1785202efd35d0da81a14fb01e743..99e757a808ee8c5fd7d961e1a0dd4634adada8a7 100644 (file)
@@ -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);
index 9522d7305a29260cd5f6768ed399e80b313f9a08..0d2bab7dd7e01a0a39823581b40d3dc7b402ef71 100644 (file)
@@ -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);