The branch main has been updated by kib:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=874cdf6af695c42d561647f7165c99c2d3df0faa

commit 874cdf6af695c42d561647f7165c99c2d3df0faa
Author:     Konstantin Belousov <[email protected]>
AuthorDate: 2025-12-28 14:13:49 +0000
Commit:     Konstantin Belousov <[email protected]>
CommitDate: 2025-12-29 01:16:25 +0000

    exterr: in verbose mode, print the source file name
    
    Reviewed by:    emaste, mckusick
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D54380
---
 lib/libc/gen/uexterr_format.c | 21 +++++++++++++++++----
 sys/sys/exterr_cat.h          | 11 +++++++++++
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/lib/libc/gen/uexterr_format.c b/lib/libc/gen/uexterr_format.c
index 3321fd80616d..8d3b458ca9f2 100644
--- a/lib/libc/gen/uexterr_format.c
+++ b/lib/libc/gen/uexterr_format.c
@@ -8,7 +8,7 @@
  * under sponsorship from the FreeBSD Foundation.
  */
 
-#include <sys/types.h>
+#include <sys/param.h>
 #include <sys/exterrvar.h>
 #include <exterr.h>
 #include <stdbool.h>
@@ -17,6 +17,19 @@
 #include <string.h>
 #include <unistd.h>
 
+static const char * const cat_to_filenames[] = {
+#include "exterr_cat_filenames.h"
+};
+
+static const char *
+cat_to_filename(int category)
+{
+       if (category < 0 || category >= nitems(cat_to_filenames) ||
+           cat_to_filenames[category] == NULL)
+               return ("unknown");
+       return (cat_to_filenames[category]);
+}
+
 static const char exterror_verbose_name[] = "EXTERROR_VERBOSE";
 enum exterr_verbose_state {
        EXTERR_VERBOSE_UNKNOWN = 100,
@@ -68,9 +81,9 @@ __uexterr_format(const struct uexterror *ue, char *buf, 
size_t bufsz)
                char lbuf[128];
 
                snprintf(lbuf, sizeof(lbuf),
-                   "errno %d category %u (src line %u) p1 %#jx p2 %#jx",
-                   ue->error, ue->cat, ue->src_line,
-                   (uintmax_t)ue->p1, (uintmax_t)ue->p2);
+                   "errno %d category %u (src sys/%s:%u) p1 %#jx p2 %#jx",
+                   ue->error, ue->cat, cat_to_filename(ue->cat),
+                   ue->src_line, (uintmax_t)ue->p1, (uintmax_t)ue->p2);
                if (has_msg)
                        strlcat(buf, " ", bufsz);
                strlcat(buf, lbuf, bufsz);
diff --git a/sys/sys/exterr_cat.h b/sys/sys/exterr_cat.h
index 7492fc31662a..24f07539fe35 100644
--- a/sys/sys/exterr_cat.h
+++ b/sys/sys/exterr_cat.h
@@ -8,6 +8,17 @@
  * under sponsorship from the FreeBSD Foundation.
  */
 
+/*
+ * The category identifiers for the extended errors.
+ * The ids participate in ABI between kernel and libc, so they must
+ * never be reused or changed.  Only new ids can be added.
+ *
+ * After adding a new category id, run
+ * tools/build/make_libc_exterr_cat_filenames.sh
+ * from the top of the source tree, and commit updated file
+ * lib/libc/gen/exterr_cat_filenames.h
+ */
+
 #ifndef _SYS_EXTERR_CAT_H_
 #define        _SYS_EXTERR_CAT_H_
 

Reply via email to