diff options
author | Mike Belopuhov <mikeb@cvs.openbsd.org> | 2012-04-10 20:39:38 +0000 |
---|---|---|
committer | Mike Belopuhov <mikeb@cvs.openbsd.org> | 2012-04-10 20:39:38 +0000 |
commit | a23d67445b5df6555fc4da33d769a3e3908dda34 (patch) | |
tree | ba0b32f3b219f9a806f6a47744a322071984ebc3 /usr.bin/kdump | |
parent | e9e89e5ae05bfd8e83cfd22c0ac34bd8eaf0f448 (diff) |
Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.
Diffstat (limited to 'usr.bin/kdump')
-rw-r--r-- | usr.bin/kdump/kdump.1 | 8 | ||||
-rw-r--r-- | usr.bin/kdump/kdump.c | 27 |
2 files changed, 23 insertions, 12 deletions
diff --git a/usr.bin/kdump/kdump.1 b/usr.bin/kdump/kdump.1 index 419ed3ab0ad..fad59ab85bf 100644 --- a/usr.bin/kdump/kdump.1 +++ b/usr.bin/kdump/kdump.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: kdump.1,v 1.21 2011/07/28 10:33:36 otto Exp $ +.\" $OpenBSD: kdump.1,v 1.22 2012/04/10 20:39:37 mikeb Exp $ .\" .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" from: @(#)kdump.1 8.1 (Berkeley) 6/6/93 .\" -.Dd $Mdocdate: July 28 2011 $ +.Dd $Mdocdate: April 10 2012 $ .Dt KDUMP 1 .Os .Sh NAME @@ -38,7 +38,7 @@ .Sh SYNOPSIS .Nm kdump .Bk -words -.Op Fl dlnRrTXx +.Op Fl dHlnRrTXx .Op Fl e Ar emulation .Op Fl f Ar file .Op Fl m Ar maxdata @@ -69,6 +69,8 @@ For example, to view trace output from a Linux binary, use .It Fl f Ar file Display the specified file instead of .Pa ktrace.out . +.It Fl H +Display thread identifiers. .It Fl l Loop reading the trace file, once the end-of-file is reached, waiting for more data. diff --git a/usr.bin/kdump/kdump.c b/usr.bin/kdump/kdump.c index 3ef74ad4f57..57643d0aff2 100644 --- a/usr.bin/kdump/kdump.c +++ b/usr.bin/kdump/kdump.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kdump.c,v 1.66 2012/03/31 18:59:14 deraadt Exp $ */ +/* $OpenBSD: kdump.c,v 1.67 2012/04/10 20:39:37 mikeb Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -73,7 +73,8 @@ #include "kdump_subr.h" #include "extern.h" -int timestamp, decimal, iohex, fancy = 1, tail, maxdata = INT_MAX, resolv; +int timestamp, decimal, iohex, fancy = 1, maxdata = INT_MAX; +int needtid, resolv, tail; char *tracefile = DEF_TRACEFILE; struct ktr_header ktr_header; pid_t pid = -1; @@ -167,7 +168,7 @@ main(int argc, char *argv[]) def_emul = current = &emulations[0]; /* native */ - while ((ch = getopt(argc, argv, "e:f:dlm:nrRp:Tt:xX")) != -1) + while ((ch = getopt(argc, argv, "e:f:dHlm:nrRp:Tt:xX")) != -1) switch (ch) { case 'e': setemul(optarg); @@ -179,6 +180,9 @@ main(int argc, char *argv[]) case 'd': decimal = 1; break; + case 'H': + needtid = 1; + break; case 'l': tail = 1; break; @@ -222,6 +226,9 @@ main(int argc, char *argv[]) err(1, NULL); if (!freopen(tracefile, "r", stdin)) err(1, "%s", tracefile); + if (fread_tail(&ktr_header, sizeof(struct ktr_header), 1) == 0 || + ktr_header.ktr_type != htobe32(KTR_START)) + errx(1, "%s: not a dump", tracefile); while (fread_tail(&ktr_header, sizeof(struct ktr_header), 1)) { silent = 0; if (pe_size == 0) @@ -329,9 +336,9 @@ fread_tail(void *buf, size_t size, size_t num) static void dumpheader(struct ktr_header *kth) { - static struct timeval prevtime; + static struct timespec prevtime; char unknown[64], *type; - struct timeval temp; + struct timespec temp; switch (kth->ktr_type) { case KTR_SYSCALL: @@ -364,15 +371,17 @@ dumpheader(struct ktr_header *kth) type = unknown; } - (void)printf("%6ld %-8.*s ", (long)kth->ktr_pid, MAXCOMLEN, - kth->ktr_comm); + (void)printf("%6ld", (long)kth->ktr_pid); + if (needtid) + (void)printf("/%-5ld", (long)kth->ktr_tid - THREAD_PID_OFFSET); + (void)printf(" %-8.*s ", MAXCOMLEN, kth->ktr_comm); if (timestamp) { if (timestamp == 2) { - timersub(&kth->ktr_time, &prevtime, &temp); + timespecsub(&kth->ktr_time, &prevtime, &temp); prevtime = kth->ktr_time; } else temp = kth->ktr_time; - (void)printf("%ld.%06ld ", temp.tv_sec, temp.tv_usec); + (void)printf("%ld.%06ld ", temp.tv_sec, temp.tv_nsec / 1000); } (void)printf("%s ", type); } |