Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/crash - amd64 support
details: https://anonhg.NetBSD.org/src/rev/29331052b353
branches: trunk
changeset: 764037:29331052b353
user: christos <christos%NetBSD.org@localhost>
date: Sun Apr 10 20:39:42 2011 +0000
description:
- amd64 support
- fix end of file handling
From: Vladimir Kirillov proger at wilab dot org dot ua
diffstat:
usr.sbin/crash/Makefile | 35 ++++++++++-----------
usr.sbin/crash/crash.c | 76 +++++++++++++++++++++++++++---------------------
2 files changed, 59 insertions(+), 52 deletions(-)
diffs (249 lines):
diff -r 733db477c3e6 -r 29331052b353 usr.sbin/crash/Makefile
--- a/usr.sbin/crash/Makefile Sun Apr 10 20:38:37 2011 +0000
+++ b/usr.sbin/crash/Makefile Sun Apr 10 20:39:42 2011 +0000
@@ -1,24 +1,23 @@
-# $NetBSD: Makefile,v 1.6 2011/03/21 05:09:33 joerg Exp $
+# $NetBSD: Makefile,v 1.7 2011/04/10 20:39:42 christos 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
-DPADD+= ${LIBKVM} ${LIBEDIT} ${LIBTERMINFO}
+LDADD+= -lutil -lkvm -ledit -lterminfo -T${.CURDIR}/ldscript.crash
+DPADD+= ${LIBUTIL} ${LIBKVM} ${LIBEDIT} ${LIBTERMINFO}
# 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_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
diff -r 733db477c3e6 -r 29331052b353 usr.sbin/crash/crash.c
--- a/usr.sbin/crash/crash.c Sun Apr 10 20:38:37 2011 +0000
+++ b/usr.sbin/crash/crash.c Sun Apr 10 20:39:42 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: crash.c,v 1.2 2009/04/16 06:52:08 lukem Exp $ */
+/* $NetBSD: crash.c,v 1.3 2011/04/10 20:39:42 christos Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: crash.c,v 1.2 2009/04/16 06:52:08 lukem Exp $");
+__RCSID("$NetBSD: crash.c,v 1.3 2011/04/10 20:39:42 christos Exp $");
#endif /* not lint */
#include <ddb/ddb.h>
@@ -52,18 +52,20 @@
#include <kvm.h>
#include <err.h>
#include <ctype.h>
+#include <util.h>
#include "extern.h"
#define MAXSTAB (16 * 1024 * 1024)
-static kvm_t *kd;
db_regs_t ddb_regs;
-History *hist;
-HistEvent he;
-EditLine *elptr;
-char imgrelease[16];
-FILE *ofp;
+
+static kvm_t *kd;
+static History *hist;
+static HistEvent he;
+static EditLine *elptr;
+static char imgrelease[16];
+static FILE *ofp;
static struct nlist nl[] = {
#define X_OSRELEASE 0
@@ -73,6 +75,18 @@
{ .n_name = NULL },
};
+static void
+cleanup(void)
+{
+ if (ofp != stdout) {
+ (void)fflush(ofp);
+ (void)pclose(ofp);
+ ofp = stdout;
+ }
+ el_end(elptr);
+ history_end(hist);
+}
+
void
db_vprintf(const char *fmt, va_list ap)
{
@@ -121,14 +135,14 @@
db_alloc(size_t sz)
{
- return malloc(sz);
+ return emalloc(sz);
}
void *
db_zalloc(size_t sz)
{
- return calloc(1, sz);
+ return ecalloc(1, sz);
}
void
@@ -231,9 +245,8 @@
/* Read next command. */
el = el_gets(elptr, &cnt);
- if (el == NULL) {
- *lstart = '\0';
- return 0;
+ if (el == NULL) { /* EOF */
+ exit(EXIT_SUCCESS);
}
/* Save to history, and copy to caller's buffer. */
@@ -255,7 +268,7 @@
/* Open a pipe to specified command, redirect output. */
assert(ofp == stdout);
- for (*pcmd++ = '\0'; isspace((int)*pcmd); pcmd++) {
+ for (*pcmd++ = '\0'; isspace((unsigned char)*pcmd); pcmd++) {
/* nothing */
}
errno = 0;
@@ -323,6 +336,8 @@
memf = _PATH_MEM;
ofp = stdout;
+ setprogname(argv[0]);
+
/*
* Parse options.
*/
@@ -354,31 +369,30 @@
return EXIT_FAILURE;
}
fd = open(nlistf, O_RDONLY);
- if (fd < 0) {
- err(EXIT_FAILURE, "open(%s)", nlistf);
+ if (fd == -1) {
+ err(EXIT_FAILURE, "open `%s'", nlistf);
}
- if (fstat(fd, &sb) < 0) {
- err(EXIT_FAILURE, "stat(%s)", nlistf);
+ if (fstat(fd, &sb) == -1) {
+ err(EXIT_FAILURE, "stat `%s'", nlistf);
}
if ((sb.st_mode & S_IFMT) != S_IFREG) { /* XXX ksyms */
sz = MAXSTAB;
elf = malloc(sz);
if (elf == NULL) {
- err(EXIT_FAILURE, "malloc(%zd)", sz);
+ err(EXIT_FAILURE, "malloc(%zu)", sz);
}
sz = read(fd, elf, sz);
- if ((ssize_t)sz < 0) {
- err(EXIT_FAILURE, "read(%s)", nlistf);
+ if ((ssize_t)sz == -1) {
+ err(EXIT_FAILURE, "read `%s'", nlistf);
}
if (sz == MAXSTAB) {
- errx(EXIT_FAILURE, "symbol table > %d bytes",
- MAXSTAB);
+ errx(EXIT_FAILURE, "symbol table > %d bytes", MAXSTAB);
}
} else {
sz = sb.st_size;
elf = mmap(NULL, sz, PROT_READ, MAP_FILE, fd, 0);
if (elf == MAP_FAILED) {
- err(EXIT_FAILURE, "mmap(%s)", nlistf);
+ err(EXIT_FAILURE, "mmap `%s'", nlistf);
}
}
@@ -440,6 +454,8 @@
el_set(elptr, EL_PROMPT, prompt);
el_source(elptr, NULL);
+ atexit(cleanup);
+
/*
* Initialize ddb.
*/
@@ -455,15 +471,7 @@
db_command_loop();
/*
- * Clean up and exit.
+ * Finish.
*/
- if (ofp != stdout) {
- (void)fflush(ofp);
- (void)pclose(ofp);
- ofp = stdout;
- }
- el_end(elptr);
- history_end(hist);
- exit(EXIT_SUCCESS);
- /* NOTREACHED */
+ return EXIT_SUCCESS;
}
Home |
Main Index |
Thread Index |
Old Index