grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
From: Leo Sandoval via Grub-devel <grub-devel@gnu.org>
To: grub-devel@gnu.org
Cc: Leo Sandoval <lsandova@redhat.com>
Subject: [PATCH v2 1/2] Make grub_error() more verbose
Date: Tue, 23 Sep 2025 17:33:31 -0600	[thread overview]
Message-ID: <20250923233332.2748851-1-lsandova@redhat.com> (raw)

From: Peter Jones <pjones@redhat.com>

Signed-off-by: Peter Jones <pjones@redhat.com>
---
 grub-core/kern/err.c | 13 +++++++++++--
 include/grub/err.h   |  8 ++++++--
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/grub-core/kern/err.c b/grub-core/kern/err.c
index 53c734de70..aebfe0cf83 100644
--- a/grub-core/kern/err.c
+++ b/grub-core/kern/err.c
@@ -33,15 +33,24 @@ static struct grub_error_saved grub_error_stack_items[GRUB_ERROR_STACK_SIZE];
 static int grub_error_stack_pos;
 static int grub_error_stack_assert;
 
+#ifdef grub_error
+#undef grub_error
+#endif
+
 grub_err_t
-grub_error (grub_err_t n, const char *fmt, ...)
+grub_error (grub_err_t n, const char *file, 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);
+  if (m < 0)
+    m = 0;
+
   va_start (ap, fmt);
-  grub_vsnprintf (grub_errmsg, sizeof (grub_errmsg), _(fmt), ap);
+  grub_vsnprintf (grub_errmsg + m, sizeof (grub_errmsg) - m, _(fmt), ap);
   va_end (ap);
 
   return n;
diff --git a/include/grub/err.h b/include/grub/err.h
index 202fa8a7ae..7530f58b29 100644
--- a/include/grub/err.h
+++ b/include/grub/err.h
@@ -88,8 +88,12 @@ 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 *fmt, ...)
-    __attribute__ ((format (GNU_PRINTF, 2, 3)));
+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)));
+
+#define grub_error(n, fmt, ...) grub_error (n, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
+
+
 void EXPORT_FUNC(grub_fatal) (const char *fmt, ...) __attribute__ ((noreturn));
 void EXPORT_FUNC(grub_error_push) (void);
 int EXPORT_FUNC(grub_error_pop) (void);
-- 
2.50.1


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

             reply	other threads:[~2025-09-23 23:34 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-23 23:33 Leo Sandoval via Grub-devel [this message]
2025-09-23 23:33 ` [PATCH v2 2/2] Include function name on debug and error print functions Leo Sandoval via Grub-devel
2025-09-24 19:49 ` [PATCH v2 1/2] Make grub_error() more verbose Daniel Kiper
2025-09-24 19:55 ` Vladimir 'phcoder' Serbinenko
2025-09-25 18:04   ` Leo Sandoval via Grub-devel
2025-09-26 15:57     ` Vladimir 'phcoder' Serbinenko
2025-09-26 16:14       ` Leo Sandoval via Grub-devel
2025-09-26 16:51         ` Andrew Hamilton
2025-09-26 22:52           ` Leo Sandoval via Grub-devel
2025-09-29 11:07   ` Daniel Kiper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250923233332.2748851-1-lsandova@redhat.com \
    --to=grub-devel@gnu.org \
    --cc=lsandova@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).