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
This commit is contained in:
Konstantin Belousov
2025-12-28 16:13:49 +02:00
parent 5685c07b5a
commit 874cdf6af6
2 changed files with 28 additions and 4 deletions
+17 -4
View File
@@ -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);
+11
View File
@@ -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_