Skip to contentSkip to conversation

Include function name on debug traces

PATCH In review Leo Sandoval via Grub-devel 3 participants 8 messages Apr 11, 2025 – Apr 23, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Include function name on debug traces

Together with the line number, the debug trace with the function name provides a bit more context and could be useful when inspecting log.

---
 grub-core/kern/misc.c | 4 ++--
 include/grub/misc.h   | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)
grub-core/kern/misc.c +2 -2
index 2b79223935..90c71d7cea 100644
@@ -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);
include/grub/misc.h +3 -2
index e087e7b3e8..881af5ca98 100644
@@ -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);
@@ -410,9 +410,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 int 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);
Signature · 7 lines
2.48.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#1 lore raw

PATCH 2/2 Prepend debug traces with absolute and relative timestamps

From: Renaud Métrich <[email protected]>

Debug traces with timestamps are useful to detect performance issues. To enable it, include '--with-debug-timestamps' argument on the configure step.

---
 config.h.in           |  1 +
 configure.ac          | 18 ++++++++++++++++++
 grub-core/kern/misc.c | 21 +++++++++++++++++++++
 3 files changed, 40 insertions(+)
config.h.in +1 -0
index 9b1d399718..e0e27a8a6a 100644
@@ -16,6 +16,7 @@
 /* Define to 1 to enable disk cache statistics.  */
 #define DISK_CACHE_STATS @DISK_CACHE_STATS@
 #define BOOT_TIME_STATS @BOOT_TIME_STATS@
+#define DEBUG_WITH_TIMESTAMPS @DEBUG_WITH_TIMESTAMPS@
 
 /* We don't need those.  */
 #define MINILZO_CFG_SKIP_LZO_PTR 1
configure.ac +18 -0
index 83e3ddf908..34fb9a01ad 100644
@@ -1657,6 +1657,17 @@ else
 fi
 AC_SUBST([BOOT_TIME_STATS])
 
+AC_ARG_WITH([debug-timestamps],
+	   AS_HELP_STRING([--with-debug-timestamps],
+                          [prepend debug traces with absolute and relative timestamps]))
+
+if test x$with_debug_timestamps = xyes; then
+  DEBUG_WITH_TIMESTAMPS=1
+else
+  DEBUG_WITH_TIMESTAMPS=0
+fi
+AC_SUBST([DEBUG_WITH_TIMESTAMPS])
+
 AC_ARG_ENABLE([grub-emu-sdl2],
 	      [AS_HELP_STRING([--enable-grub-emu-sdl2],
                              [build and install the `grub-emu' debugging utility with SDL2 support (default=guessed)])])
@@ -2245,6 +2256,7 @@ AM_CONDITIONAL([COND_APPLE_LINKER], [test x$TARGET_APPLE_LINKER = x1])
 AM_CONDITIONAL([COND_ENABLE_EFIEMU], [test x$enable_efiemu = xyes])
 AM_CONDITIONAL([COND_ENABLE_CACHE_STATS], [test x$DISK_CACHE_STATS = x1])
 AM_CONDITIONAL([COND_ENABLE_BOOT_TIME_STATS], [test x$BOOT_TIME_STATS = x1])
+AM_CONDITIONAL([COND_DEBUG_WITH_TIMESTAMPS], [test x$DEBUG_WITH_TIMESTAMPS = x1])
 
 AM_CONDITIONAL([COND_HAVE_CXX], [test x$HAVE_CXX = xyes])
 
@@ -2346,6 +2358,12 @@ else
 echo With boot time statistics: No
 fi
 
+if [ x"$with_debug_timestamps" = xyes ]; then
+echo Debug traces with timestamps: Yes
+else
+echo Debug traces with timestamps: No
+fi
+
 if [ x"$efiemu_excuse" = x ]; then
 echo efiemu runtime: Yes
 else
grub-core/kern/misc.c +21 -0
index 90c71d7cea..967c01588d 100644
@@ -26,6 +26,9 @@
 #include <grub/i18n.h>
 #include <grub/types.h>
 #include <grub/charset.h>
+#if DEBUG_WITH_TIMESTAMPS
+#include <grub/time.h>
+#endif
 
 union printf_arg
 {
@@ -235,9 +238,27 @@ grub_real_dprintf (const char *file, const char *function, const int line, const
 		   const char *fmt, ...)
 {
   va_list args;
+#if DEBUG_WITH_TIMESTAMPS
+  static long unsigned int last_time = 0;
+  static int last_had_cr = 1;
+#endif
 
   if (grub_debug_enabled (condition))
     {
+#if DEBUG_WITH_TIMESTAMPS
+      /* Don't print timestamp if last printed message isn't terminated yet */
+      if (last_had_cr) {
+        long unsigned int tmabs = (long unsigned int) grub_get_time_ms();
+        long unsigned int tmrel = tmabs - last_time;
+        last_time = tmabs;
+        grub_printf ("%3lu.%03lus:%2lu.%03lus:", tmabs / 1000, tmabs % 1000, tmrel / 1000, tmrel % 1000);
+      }
+      if (fmt[grub_strlen(fmt)-1] == '\n')
+        last_had_cr = 1;
+      else
+        last_had_cr = 0;
+#endif
+
       grub_printf ("%s:%s:%d:%s: ", file, function, line, condition);
       va_start (args, fmt);
       grub_vprintf (fmt, args);
Signature · 7 lines
2.48.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#2 lore raw

Re: [PATCH 2/2] Prepend debug traces with absolute and relative timestamps

Quoted 84 lines · Leo Sandoval via Grub-devel

From: Renaud Métrich <[email protected]>

Debug traces with timestamps are useful to detect performance issues. To enable it, include '--with-debug-timestamps' argument on the configure step.

---
 config.h.in           |  1 +
 configure.ac          | 18 ++++++++++++++++++
 grub-core/kern/misc.c | 21 +++++++++++++++++++++
 3 files changed, 40 insertions(+)
config.h.in +1 -0
index 9b1d399718..e0e27a8a6a 100644
@@ -16,6 +16,7 @@
 /* Define to 1 to enable disk cache statistics.  */
 #define DISK_CACHE_STATS @DISK_CACHE_STATS@
 #define BOOT_TIME_STATS @BOOT_TIME_STATS@
+#define DEBUG_WITH_TIMESTAMPS @DEBUG_WITH_TIMESTAMPS@
 
 /* We don't need those.  */
 #define MINILZO_CFG_SKIP_LZO_PTR 1
configure.ac +18 -0
index 83e3ddf908..34fb9a01ad 100644
@@ -1657,6 +1657,17 @@ else
 fi
 AC_SUBST([BOOT_TIME_STATS])
 
+AC_ARG_WITH([debug-timestamps],
+	   AS_HELP_STRING([--with-debug-timestamps],
+                          [prepend debug traces with absolute and relative timestamps]))
+
+if test x$with_debug_timestamps = xyes; then
+  DEBUG_WITH_TIMESTAMPS=1
+else
+  DEBUG_WITH_TIMESTAMPS=0
+fi
+AC_SUBST([DEBUG_WITH_TIMESTAMPS])
+
 AC_ARG_ENABLE([grub-emu-sdl2],
 	      [AS_HELP_STRING([--enable-grub-emu-sdl2],
                              [build and install the `grub-emu' debugging utility with SDL2 support (default=guessed)])])
@@ -2245,6 +2256,7 @@ AM_CONDITIONAL([COND_APPLE_LINKER], [test x$TARGET_APPLE_LINKER = x1])
 AM_CONDITIONAL([COND_ENABLE_EFIEMU], [test x$enable_efiemu = xyes])
 AM_CONDITIONAL([COND_ENABLE_CACHE_STATS], [test x$DISK_CACHE_STATS = x1])
 AM_CONDITIONAL([COND_ENABLE_BOOT_TIME_STATS], [test x$BOOT_TIME_STATS = x1])
+AM_CONDITIONAL([COND_DEBUG_WITH_TIMESTAMPS], [test x$DEBUG_WITH_TIMESTAMPS = x1])
 
 AM_CONDITIONAL([COND_HAVE_CXX], [test x$HAVE_CXX = xyes])
 
@@ -2346,6 +2358,12 @@ else
 echo With boot time statistics: No
 fi
 
+if [ x"$with_debug_timestamps" = xyes ]; then
+echo Debug traces with timestamps: Yes
+else
+echo Debug traces with timestamps: No
+fi
+
 if [ x"$efiemu_excuse" = x ]; then
 echo efiemu runtime: Yes
 else
grub-core/kern/misc.c +3 -0
index 90c71d7cea..967c01588d 100644
@@ -26,6 +26,9 @@
 #include <grub/i18n.h>
 #include <grub/types.h>
 #include <grub/charset.h>
+#if DEBUG_WITH_TIMESTAMPS
+#include <grub/time.h>
+#endif
 
 union printf_arg
 {

grub-core/kern/misc.c grub_real_dprintf (const char *file, const char *function, const int line, const · line 242

Quoted 5 lines
grub-core/kern/misc.c +2 -0
@@ -235,9 +238,27 @@ grub_real_dprintf (const char *file, const char *function, const int line, const
 		   const char *fmt, ...)
 {
   va_list args;
+#if DEBUG_WITH_TIMESTAMPS
+  static long unsigned int last_time = 0;

Please use grub_uint64_t everywhere...

grub-core/kern/misc.c grub_real_dprintf (const char *file, const char *function, const int line, const · line 243

Quoted 1 line
grub-core/kern/misc.c +1 -0
+  static int last_had_cr = 1;

s/_cr/_lf/
s/int/bool/ and true/false please...

grub-core/kern/misc.c grub_real_dprintf (const char *file, const char *function, const int line, const · line 250

Quoted 7 lines
grub-core/kern/misc.c +4 -0
+#endif
 
   if (grub_debug_enabled (condition))
     {
+#if DEBUG_WITH_TIMESTAMPS
+      /* Don't print timestamp if last printed message isn't terminated yet */
+      if (last_had_cr) {

What about multiline strings, e.g. "ABC\nDEF\n"?

grub-core/kern/misc.c grub_real_dprintf (const char *file, const char *function, const int line, const · line 253

Quoted 3 lines
grub-core/kern/misc.c +3 -0
+        long unsigned int tmabs = (long unsigned int) grub_get_time_ms();
+        long unsigned int tmrel = tmabs - last_time;
+        last_time = tmabs;

s/last_time/time_last/
s/tmabs/time_abs/
s/tmrel/time_rel/

grub-core/kern/misc.c grub_real_dprintf (const char *file, const char *function, const int line, const · line 254

Quoted 1 line
grub-core/kern/misc.c +1 -0
+        grub_printf ("%3lu.%03lus:%2lu.%03lus:", tmabs / 1000, tmabs % 1000, tmrel / 1000, tmrel % 1000);

If you use grub_uint64_t everywhere then PRIdGRUB_INT64_T macro is your friend...

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Reviewed-by on v1 1/2
#3 lore raw
In reply to Leo Sandoval via Grub-devel
Quoted 4 lines · Leo Sandoval via Grub-devel

Together with the line number, the debug trace with the function name provides a bit more context and could be useful when inspecting log.

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#4 lore raw
In reply to Leo Sandoval via Grub-devel

What is the code size increase on i386-pc? Did you test it? This is likely to result in a big one

Regards
Vladimir 'phcoder' Serbinenko

Quoted 68 lines · Leo Sandoval via Grub-devel

Together with the line number, the debug trace with the function name provides a bit more context and could be useful when inspecting log.

---
 grub-core/kern/misc.c | 4 ++--
 include/grub/misc.h   | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)
grub-core/kern/misc.c +2 -2
index 2b79223935..90c71d7cea 100644
@@ -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);
include/grub/misc.h +1 -1
index e087e7b3e8..881af5ca98 100644
@@ -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);

include/grub/misc.h +2 -1
@@ -410,9 +410,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 int 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);
--
2.48.1

Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#5 lore raw
Quoted 3 lines · Vladimir 'phcoder' Serbinenko

What is the code size increase on i386-pc? Did you test it? This is likely to result in a big one

I did not test the binary size impact but du'ing does not show much degradation (around 24kb increase) on my fedora box

before patch

# du  /boot/grub2/
3404 /boot/grub2/i386-pc
5484 /boot/grub2/locale
2344 /boot/grub2/fonts
11252 /boot/grub2/

with patch

# du  /boot/grub2/
3428 /boot/grub2/i386-pc
5484 /boot/grub2/locale
2344 /boot/grub2/fonts
11276 /boot/grub2/
Quoted 75 lines

Regards
Vladimir 'phcoder' Serbinenko

Quoted 68 lines · Leo Sandoval via Grub-devel

Together with the line number, the debug trace with the function name provides a bit more context and could be useful when inspecting log.

---
 grub-core/kern/misc.c | 4 ++--
 include/grub/misc.h   | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)
grub-core/kern/misc.c +2 -2
index 2b79223935..90c71d7cea 100644
@@ -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);
include/grub/misc.h +1 -1
index e087e7b3e8..881af5ca98 100644
@@ -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);

include/grub/misc.h +2 -1
@@ -410,9 +410,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 int 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);
--
2.48.1

Quoted 6 lines
Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#6 lore raw
Quoted 5 lines · Leo Sandoval

On Tue, Apr 15, 2025 at 9:28 AM Vladimir 'phcoder' Serbinenko < [email protected]> wrote:

Quoted 7 lines
Quoted 3 lines

What is the code size increase on i386-pc? Did you test it? This is likely to result in a big one

I did not test the binary size impact but du'ing does not show much degradation (around 24kb increase) on my fedora box

The size of modules is mostly irrelevant. What matters are the core sizes. ./grub-mkimage -O i386-pc -p /boot/grub -o core.img biosdisk part_msdos ext2
Resulting core has to be under 31K for all the filesystems (replace ext2 with different FS) except btrfs and zfs

Quoted 9 lines

before patch

# du  /boot/grub2/
3404 /boot/grub2/i386-pc
5484 /boot/grub2/locale
2344 /boot/grub2/fonts
11252 /boot/grub2/
Quoted 92 lines

with patch

# du  /boot/grub2/
3428 /boot/grub2/i386-pc
5484 /boot/grub2/locale
2344 /boot/grub2/fonts
11276 /boot/grub2/
Quoted 81 lines

Regards
Vladimir 'phcoder' Serbinenko

Quoted 73 lines · Leo Sandoval via Grub-devel

Together with the line number, the debug trace with the function name provides a bit more context and could be useful when inspecting log.

---
 grub-core/kern/misc.c | 4 ++--
 include/grub/misc.h   | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)
grub-core/kern/misc.c +2 -2
index 2b79223935..90c71d7cea 100644
@@ -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);
include/grub/misc.h +1 -1
index e087e7b3e8..881af5ca98 100644
@@ -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);

include/grub/misc.h +2 -1
@@ -410,9 +410,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 int 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);
--
2.48.1

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#7 lore raw
Quoted 17 lines · Vladimir 'phcoder' Serbinenko
Quoted 5 lines · Leo Sandoval

On Tue, Apr 15, 2025 at 9:28 AM Vladimir 'phcoder' Serbinenko < [email protected]> wrote:

Quoted 7 lines
Quoted 3 lines

What is the code size increase on i386-pc? Did you test it? This is likely to result in a big one

I did not test the binary size impact but du'ing does not show much degradation (around 24kb increase) on my fedora box

Quoted 6 lines

The size of modules is mostly irrelevant. What matters are the core sizes. ./grub-mkimage -O i386-pc -p /boot/grub -o core.img biosdisk part_msdos ext2
Resulting core has to be under 31K for all the filesystems (replace ext2 with different FS) except btrfs and zfs

Thanks for the pointers. These are the sizes then

-rw-r--r--. 1 root root 34K Apr 23 20:19 core-no-function-name.img -rw-r--r--. 1 root root 35K Apr 23 20:20 core-with-function-name.img <---

(or in bytes

-rw-r--r--. 1 root root 34524 Apr 23 20:19 core-no-function-name.img -rw-r--r--. 1 root root 34870 Apr 23 20:20 core-with-function-name.img )

so, in both cases img files are both > 31K, so is there something am I missing?

I used the command you suggested, same params.

Quoted 95 lines
Quoted 95 lines

before patch

# du  /boot/grub2/
3404 /boot/grub2/i386-pc
5484 /boot/grub2/locale
2344 /boot/grub2/fonts
11252 /boot/grub2/

with patch

# du  /boot/grub2/
3428 /boot/grub2/i386-pc
5484 /boot/grub2/locale
2344 /boot/grub2/fonts
11276 /boot/grub2/
Quoted 76 lines

Regards
Vladimir 'phcoder' Serbinenko

Quoted 69 lines · Leo Sandoval via Grub-devel

Together with the line number, the debug trace with the function name provides a bit more context and could be useful when inspecting log.

---
 grub-core/kern/misc.c | 4 ++--
 include/grub/misc.h   | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)
grub-core/kern/misc.c +2 -2
index 2b79223935..90c71d7cea 100644
@@ -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);
include/grub/misc.h +1 -1
index e087e7b3e8..881af5ca98 100644
@@ -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);

include/grub/misc.h +2 -1
@@ -410,9 +410,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 int 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);
--
2.48.1

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel