Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Always provide a meaningful short name for the kobj in t...



details:   https://anonhg.NetBSD.org/src/rev/9e842efe44c2
branches:  trunk
changeset: 768280:9e842efe44c2
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Aug 13 21:04:05 2011 +0000

description:
Always provide a meaningful short name for the kobj in the error message,
as well as the function name and the linenumber, without extra line feeds.

diffstat:

 sys/arch/sandpoint/sandpoint/machdep.c |    6 +-
 sys/arch/x86/x86/x86_machdep.c         |    7 +-
 sys/kern/kern_module.c                 |    8 +-
 sys/kern/subr_kobj.c                   |  146 +++++++++++++++++++++++---------
 sys/kern/subr_kobj_vfs.c               |    5 +-
 sys/sys/kobj.h                         |    4 +-
 sys/sys/kobj_impl.h                    |    3 +-
 sys/sys/module.h                       |    4 +-
 8 files changed, 126 insertions(+), 57 deletions(-)

diffs (truncated from 615 to 300 lines):

diff -r 5c71c15f97e8 -r 9e842efe44c2 sys/arch/sandpoint/sandpoint/machdep.c
--- a/sys/arch/sandpoint/sandpoint/machdep.c    Sat Aug 13 20:24:19 2011 +0000
+++ b/sys/arch/sandpoint/sandpoint/machdep.c    Sat Aug 13 21:04:05 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.57 2011/06/20 07:18:07 matt Exp $        */
+/*     $NetBSD: machdep.c,v 1.58 2011/08/13 21:04:05 christos Exp $    */
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.57 2011/06/20 07:18:07 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.58 2011/08/13 21:04:05 christos Exp $");
 
 #include "opt_compat_netbsd.h"
 #include "opt_ddb.h"
@@ -420,7 +420,7 @@
        while (bi < biend) {
                printf("module %s at 0x%08x size %x\n", 
                    bi->kmod, bi->base, bi->len);
-               /* module_prime((void *)bi->base, bi->len); */
+               /* module_prime(bi->kmod, (void *)bi->base, bi->len); */
                bi += 1;
        }
 }
diff -r 5c71c15f97e8 -r 9e842efe44c2 sys/arch/x86/x86/x86_machdep.c
--- a/sys/arch/x86/x86/x86_machdep.c    Sat Aug 13 20:24:19 2011 +0000
+++ b/sys/arch/x86/x86/x86_machdep.c    Sat Aug 13 21:04:05 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: x86_machdep.c,v 1.55 2011/08/11 18:11:17 cherry Exp $  */
+/*     $NetBSD: x86_machdep.c,v 1.56 2011/08/13 21:04:05 christos Exp $        */
 
 /*-
  * Copyright (c) 2002, 2006, 2007 YAMAMOTO Takashi,
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.55 2011/08/11 18:11:17 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.56 2011/08/13 21:04:05 christos Exp $");
 
 #include "opt_modular.h"
 #include "opt_physmem.h"
@@ -160,7 +160,8 @@
                        aprint_debug("Prep module path=%s len=%d pa=%x\n", 
                            bi->path, bi->len, bi->base);
                        KASSERT(trunc_page(bi->base) == bi->base);
-                       module_prime((void *)((uintptr_t)bi->base + KERNBASE),
+                       module_prime(bi->path,
+                           (void *)((uintptr_t)bi->base + KERNBASE),
                            bi->len);
                        break;
                case BI_MODULE_IMAGE:
diff -r 5c71c15f97e8 -r 9e842efe44c2 sys/kern/kern_module.c
--- a/sys/kern/kern_module.c    Sat Aug 13 20:24:19 2011 +0000
+++ b/sys/kern/kern_module.c    Sat Aug 13 21:04:05 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_module.c,v 1.79 2011/07/17 20:54:52 joerg Exp $   */
+/*     $NetBSD: kern_module.c,v 1.80 2011/08/13 21:04:06 christos Exp $        */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.79 2011/07/17 20:54:52 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.80 2011/08/13 21:04:06 christos Exp $");
 
 #define _MODULE_INTERNAL
 
@@ -1179,7 +1179,7 @@
  *     list.
  */
 int
-module_prime(void *base, size_t size)
+module_prime(const char *name, void *base, size_t size)
 {
        module_t *mod;
        int error;
@@ -1189,7 +1189,7 @@
                return ENOMEM;
        }
 
-       error = kobj_load_mem(&mod->mod_kobj, base, size);
+       error = kobj_load_mem(&mod->mod_kobj, name, base, size);
        if (error != 0) {
                kmem_free(mod, sizeof(*mod));
                module_error("unable to load object pushed by boot loader");
diff -r 5c71c15f97e8 -r 9e842efe44c2 sys/kern/subr_kobj.c
--- a/sys/kern/subr_kobj.c      Sat Aug 13 20:24:19 2011 +0000
+++ b/sys/kern/subr_kobj.c      Sat Aug 13 21:04:05 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_kobj.c,v 1.43 2011/07/17 20:54:52 joerg Exp $     */
+/*     $NetBSD: subr_kobj.c,v 1.44 2011/08/13 21:04:06 christos Exp $  */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.43 2011/07/17 20:54:52 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.44 2011/08/13 21:04:06 christos Exp $");
 
 #include "opt_modular.h"
 
@@ -82,7 +82,8 @@
 
 static int     kobj_relocate(kobj_t, bool);
 static int     kobj_checksyms(kobj_t, bool);
-static void    kobj_error(const char *, ...);
+static void    kobj_error(const char *, int, kobj_t, const char *, ...)
+    __printflike(4, 5);
 static void    kobj_jettison(kobj_t);
 static void    kobj_free(kobj_t, void *, size_t);
 static void    kobj_close(kobj_t);
@@ -98,7 +99,7 @@
  *     the complete size of the object is known.
  */
 int
-kobj_load_mem(kobj_t *kop, void *base, ssize_t size)
+kobj_load_mem(kobj_t *kop, const char *name, void *base, ssize_t size)
 {
        kobj_t ko;
 
@@ -108,6 +109,7 @@
        }
 
        ko->ko_type = KT_MEMORY;
+       kobj_setname(ko, name);
        ko->ko_source = base;
        ko->ko_memsize = size;
        ko->ko_read = kobj_read_mem;
@@ -176,22 +178,26 @@
         * Read the elf header from the file.
         */
        error = ko->ko_read(ko, (void **)&hdr, sizeof(*hdr), 0, true);
-       if (error != 0)
+       if (error != 0) {
+               kobj_error(__func__, __LINE__, ko, "read failed %d", error);
                goto out;
+       }
        if (memcmp(hdr->e_ident, ELFMAG, SELFMAG) != 0) {
-               kobj_error("not an ELF object");
+               kobj_error(__func__, __LINE__, ko, "not an ELF object");
                error = ENOEXEC;
                goto out;
        }
 
        if (hdr->e_ident[EI_VERSION] != EV_CURRENT ||
            hdr->e_version != EV_CURRENT) {
-               kobj_error("unsupported file version");
+               kobj_error(__func__, __LINE__, ko,
+                   "unsupported file version %d", hdr->e_ident[EI_VERSION]);
                error = ENOEXEC;
                goto out;
        }
        if (hdr->e_type != ET_REL) {
-               kobj_error("unsupported file type");
+               kobj_error(__func__, __LINE__, ko, "unsupported file type %d",
+                   hdr->e_type);
                error = ENOEXEC;
                goto out;
        }
@@ -204,7 +210,8 @@
 #error not defined
 #endif
        default:
-               kobj_error("unsupported machine");
+               kobj_error(__func__, __LINE__, ko, "unsupported machine %d",
+                   hdr->e_machine);
                error = ENOEXEC;
                goto out;
        }
@@ -220,12 +227,14 @@
        ko->ko_shdrsz = hdr->e_shnum * hdr->e_shentsize;
        if (ko->ko_shdrsz == 0 || hdr->e_shoff == 0 ||
            hdr->e_shentsize != sizeof(Elf_Shdr)) {
+               kobj_error(__func__, __LINE__, ko, "bad sizes");
                error = ENOEXEC;
                goto out;
        }
        error = ko->ko_read(ko, (void **)&shdr, ko->ko_shdrsz, hdr->e_shoff,
            true);
        if (error != 0) {
+               kobj_error(__func__, __LINE__, ko, "read failed %d", error);
                goto out;
        }
        ko->ko_shdr = shdr;
@@ -258,19 +267,21 @@
                }
        }
        if (ko->ko_nprogtab == 0) {
-               kobj_error("file has no contents");
+               kobj_error(__func__, __LINE__, ko, "file has no contents");
                error = ENOEXEC;
                goto out;
        }
        if (nsym != 1) {
                /* Only allow one symbol table for now */
-               kobj_error("file has no valid symbol table");
+               kobj_error(__func__, __LINE__, ko,
+                   "file has no valid symbol table");
                error = ENOEXEC;
                goto out;
        }
        if (symstrindex < 0 || symstrindex > hdr->e_shnum ||
            shdr[symstrindex].sh_type != SHT_STRTAB) {
-               kobj_error("file has invalid symbol strings");
+               kobj_error(__func__, __LINE__, ko,
+                   "file has invalid symbol strings");
                error = ENOEXEC;
                goto out;
        }
@@ -283,6 +294,7 @@
                    sizeof(*ko->ko_progtab), KM_SLEEP);
                if (ko->ko_progtab == NULL) {
                        error = ENOMEM;
+                       kobj_error(__func__, __LINE__, ko, "out of memory");
                        goto out;
                }
        }
@@ -291,6 +303,7 @@
                    sizeof(*ko->ko_reltab), KM_SLEEP);
                if (ko->ko_reltab == NULL) {
                        error = ENOMEM;
+                       kobj_error(__func__, __LINE__, ko, "out of memory");
                        goto out;
                }
        }
@@ -299,11 +312,12 @@
                    sizeof(*ko->ko_relatab), KM_SLEEP);
                if (ko->ko_relatab == NULL) {
                        error = ENOMEM;
+                       kobj_error(__func__, __LINE__, ko, "out of memory");
                        goto out;
                }
        }
        if (symtabindex == -1) {
-               kobj_error("lost symbol table index");
+               kobj_error(__func__, __LINE__, ko, "lost symbol table index");
                goto out;
        }
 
@@ -312,13 +326,14 @@
         */
        ko->ko_symcnt = shdr[symtabindex].sh_size / sizeof(Elf_Sym);
        if (ko->ko_symcnt == 0) {
-               kobj_error("no symbol table");
+               kobj_error(__func__, __LINE__, ko, "no symbol table");
                goto out;
        }
        error = ko->ko_read(ko, (void **)&ko->ko_symtab,
            ko->ko_symcnt * sizeof(Elf_Sym),
            shdr[symtabindex].sh_offset, true);
        if (error != 0) {
+               kobj_error(__func__, __LINE__, ko, "read failed %d", error);
                goto out;
        }
 
@@ -327,12 +342,13 @@
         */
        ko->ko_strtabsz = shdr[symstrindex].sh_size;
        if (ko->ko_strtabsz == 0) {
-               kobj_error("no symbol strings");
+               kobj_error(__func__, __LINE__, ko, "no symbol strings");
                goto out;
        }
        error = ko->ko_read(ko, (void *)&ko->ko_strtab, ko->ko_strtabsz,
            shdr[symstrindex].sh_offset, true);
        if (error != 0) {
+               kobj_error(__func__, __LINE__, ko, "read failed %d", error);
                goto out;
        }
 
@@ -342,6 +358,8 @@
        error = kobj_renamespace(ko->ko_symtab, ko->ko_symcnt,
            &ko->ko_strtab, &ko->ko_strtabsz);
        if (error != 0) {
+               kobj_error(__func__, __LINE__, ko, "renamespace failed %d",
+                   error);
                goto out;
        }
 
@@ -355,6 +373,8 @@
                    shdr[hdr->e_shstrndx].sh_size,
                    shdr[hdr->e_shstrndx].sh_offset, true);
                if (error != 0) {
+                       kobj_error(__func__, __LINE__, ko, "read failed %d",
+                           error);
                        goto out;
                }
        }
@@ -384,7 +404,7 @@
         * can get the bounds and gdb can associate offsets with modules.
         */
        if (mapsize == 0) {



Home | Main Index | Thread Index | Old Index