From owner-svn-src-all@FreeBSD.ORG Sun Oct 19 11:13:49 2008 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 94C6F106568A; Sun, 19 Oct 2008 11:13:49 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 657A58FC1A; Sun, 19 Oct 2008 11:13:49 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9JBDnTj042467; Sun, 19 Oct 2008 11:13:49 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9JBDnDM042466; Sun, 19 Oct 2008 11:13:49 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <200810191113.m9JBDnDM042466@svn.freebsd.org> From: Konstantin Belousov Date: Sun, 19 Oct 2008 11:13:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r184060 - head/sys/kern X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 19 Oct 2008 11:13:49 -0000 Author: kib Date: Sun Oct 19 11:13:49 2008 New Revision: 184060 URL: http://svn.freebsd.org/changeset/base/184060 Log: Ktr(9) stores format string and arguments in the event circular buffer, not the string formatted at the time of CTRX() call. Stack_ktr(9) uses an on-stack buffer for the symbol name, that is supplied as an argument to ktr. As result, stack_ktr() traces show garbage or cause page faults. Fix stack_ktr() by using pointer to module symbol table that is supposed to have a longer lifetime. Tested by: pho MFC after: 1 week Modified: head/sys/kern/subr_stack.c Modified: head/sys/kern/subr_stack.c ============================================================================== --- head/sys/kern/subr_stack.c Sun Oct 19 10:11:35 2008 (r184059) +++ head/sys/kern/subr_stack.c Sun Oct 19 11:13:49 2008 (r184060) @@ -45,8 +45,7 @@ static MALLOC_DEFINE(M_STACK, "stack", " static void stack_symbol(vm_offset_t pc, char *namebuf, u_int buflen, long *offset); #ifdef DDB -static void stack_symbol_ddb(vm_offset_t pc, char *namebuf, u_int buflen, - long *offset); +static void stack_symbol_ddb(vm_offset_t pc, const char **name, long *offset); #endif struct stack * @@ -109,16 +108,15 @@ stack_print(struct stack *st) void stack_print_ddb(struct stack *st) { - char namebuf[64]; + const char *name; long offset; int i; KASSERT(st->depth <= STACK_MAX, ("bogus stack")); for (i = 0; i < st->depth; i++) { - stack_symbol_ddb(st->pcs[i], namebuf, sizeof(namebuf), - &offset); + stack_symbol_ddb(st->pcs[i], &name, &offset); printf("#%d %p at %s+%#lx\n", i, (void *)st->pcs[i], - namebuf, offset); + name, offset); } } #endif @@ -146,16 +144,15 @@ stack_sbuf_print(struct sbuf *sb, struct void stack_sbuf_print_ddb(struct sbuf *sb, struct stack *st) { - char namebuf[64]; + const char *name; long offset; int i; KASSERT(st->depth <= STACK_MAX, ("bogus stack")); for (i = 0; i < st->depth; i++) { - stack_symbol_ddb(st->pcs[i], namebuf, sizeof(namebuf), - &offset); + stack_symbol_ddb(st->pcs[i], &name, &offset); sbuf_printf(sb, "#%d %p at %s+%#lx\n", i, (void *)st->pcs[i], - namebuf, offset); + name, offset); } } @@ -164,7 +161,7 @@ void stack_ktr(u_int mask, const char *file, int line, struct stack *st, u_int depth, int cheap) { - char namebuf[64]; + const char *name; long offset; int i; @@ -187,10 +184,9 @@ stack_ktr(u_int mask, const char *file, if (depth == 0 || st->depth < depth) depth = st->depth; for (i = 0; i < depth; i++) { - stack_symbol_ddb(st->pcs[i], namebuf, - sizeof(namebuf), &offset); + stack_symbol_ddb(st->pcs[i], &name, &offset); ktr_tracepoint(mask, file, line, "#%d %p at %s+%#lx", - i, st->pcs[i], (u_long)namebuf, offset, 0, 0); + i, st->pcs[i], (u_long)name, offset, 0, 0); } } } @@ -214,13 +210,21 @@ stack_symbol(vm_offset_t pc, char *nameb #ifdef DDB static void -stack_symbol_ddb(vm_offset_t pc, char *namebuf, u_int buflen, long *offset) +stack_symbol_ddb(vm_offset_t pc, const char **name, long *offset) { + linker_symval_t symval; + c_linker_sym_t sym; - if (linker_ddb_search_symbol_name((caddr_t)pc, namebuf, buflen, - offset) != 0) { - *offset = 0; - strlcpy(namebuf, "??", buflen); - }; + if (linker_ddb_search_symbol((caddr_t)pc, &sym, offset) != 0) + goto out; + if (linker_ddb_symbol_values(sym, &symval) != 0) + goto out; + if (symval.name != NULL) { + *name = symval.name; + return; + } + out: + *offset = 0; + *name = "??"; } #endif