tech-kern archive

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

diff: crash(8) on amd64



Hello, tech-kern@!

As promised, a diff to support crash(8) on amd64.
The second diff (in the bottom) is for sys/arch/amd64/amd64/db_disasm.c to
remove the useless include.

I've been using it for a while, hope you like it too :)

Index: Makefile
===================================================================
RCS file: /cvsroot/src/usr.sbin/crash/Makefile,v
retrieving revision 1.6
diff -u -p -r1.6 Makefile
--- Makefile    21 Mar 2011 05:09:33 -0000      1.6
+++ Makefile    6 Apr 2011 11:51:01 -0000
@@ -1,7 +1,7 @@
 #      $NetBSD: Makefile,v 1.6 2011/03/21 05:09:33 joerg Exp $
 
-PROG=  crash
-MAN=   crash.8
+PROG=          crash
+MAN=           crash.8
 RUMPKERNEL=    yes     # XXX: Avoid -mcmodel=kernel
 
 LDADD+=        -lkvm -ledit -lterminfo -T${.CURDIR}/ldscript.crash
@@ -9,16 +9,15 @@ DPADD+=       ${LIBKVM} ${LIBEDIT} ${LIBTERMIN
 
 # some ddb kernel components need limited modifications.  for now,
 # punt if not noted as implemented here.
-.if (${MACHINE} != "i386")
-
+.if !empty(${MACHINE:C/(amd64|i386)//})
 SRCS+= unsupported.c
-
 .else
 
-S=     ${.CURDIR}/../../sys
+S=             ${.CURDIR}/../../sys
 
 CPPFLAGS+=     -I${.CURDIR} -I${.OBJDIR} -I${S} -fno-strict-aliasing
 CPPFLAGS+=     -DDDB_VERBOSE_HELP -DDB_MAX_LINE=10000000 -D_KMEMUSER
+CPPFLAGS+=     -DDB_AOUT_SYMBOLS -UDB_MACHINE_COMMANDS
 
 # ddb files from kernel
 .PATH: $S/ddb
@@ -27,24 +26,24 @@ SRCS+=      db_access.c db_elf.c db_examine.c
 SRCS+= db_expr.c db_lex.c db_output.c db_print.c
 SRCS+= db_sym.c db_variables.c db_write_cmd.c
 
-# db_trace.c, db_disasm.c
-.PATH: ${S}/arch/${MACHINE_ARCH}/${MACHINE_ARCH}
-.for i in ${i} db_disasm db_trace
-. if (exists(${S}/arch/${MACHINE_ARCH}/${MACHINE_ARCH}/${i}.c))
-SRCS+= ${i}.c
+.PATH: ${S}/arch/${MACHINE}/${MACHINE}
+SRCS+= db_machdep.c db_disasm.c
+
+. if empty(${MACHINE:C/(amd64|i386)//})
+.PATH: ${S}/arch/x86/x86
+SRCS+= db_trace.c
 . endif
-.endfor
 
 # crash main source
 SRCS+= crash.c
 
 # arch.c
 .PATH: ${.CURDIR}/arch
-.if (exists(${.CURDIR}/arch/${MACHINE_ARCH}.c))
+. if (exists(${.CURDIR}/arch/${MACHINE_ARCH}.c))
 SRCS+= ${MACHINE_ARCH}.c
-.else
+. else
 SRCS+= generic.c
-.endif
+. endif
 
 # vers.c
 SRCS+= vers.c
Index: arch/amd64.c
===================================================================
RCS file: arch/amd64.c
diff -N arch/amd64.c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ arch/amd64.c        6 Apr 2011 11:51:01 -0000
@@ -0,0 +1,72 @@
+/*     $NetBSD: i386.c,v 1.1 2009/03/07 22:08:08 ad Exp $      */
+
+/*-
+ * Copyright (c) 2009 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Andrew Doran.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: i386.c,v 1.1 2009/03/07 22:08:08 ad Exp $");
+#endif /* not lint */
+
+#include <ddb/ddb.h>
+
+#include <kvm.h>
+#include <nlist.h>
+#include <err.h>
+#include <stdlib.h>
+
+#include <machine/frame.h>
+#include <machine/pcb.h>
+
+#include "extern.h"
+
+static struct nlist nl[] = {
+       { .n_name = "_dumppcb" },
+       { .n_name = NULL },
+};
+
+struct pcb     pcb;
+
+void
+db_mach_init(kvm_t *kd)
+{
+
+       if (kvm_nlist(kd, nl) == -1) {
+               errx(EXIT_FAILURE, "kvm_nlist: %s", kvm_geterr(kd));
+       }
+       if ((size_t)kvm_read(kd, nl[0].n_value, &pcb, sizeof(pcb)) !=
+           sizeof(pcb)) {
+               errx(EXIT_FAILURE, "cannot read dumppcb: %s", kvm_geterr(kd));
+       }
+        ddb_regs.tf_rsp = pcb.pcb_rsp;
+        ddb_regs.tf_rbp = pcb.pcb_rbp;
+        if (ddb_regs.tf_rbp != 0 && ddb_regs.tf_rsp != 0) {
+               printf("Backtrace from time of crash is available.\n");
+       }
+}

Index: db_disasm.c
===================================================================
RCS file: /cvsroot/src/sys/arch/amd64/amd64/db_disasm.c,v
retrieving revision 1.14
diff -u -p -r1.14 db_disasm.c
--- db_disasm.c 18 Feb 2011 18:00:52 -0000      1.14
+++ db_disasm.c 6 Apr 2011 11:51:53 -0000
@@ -36,7 +36,6 @@
 __KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.14 2011/02/18 18:00:52 drochner 
Exp $");
 
 #ifndef _KERNEL
-#include "stubs.h"
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/ksyms.h>


Home | Main Index | Thread Index | Old Index