Deleted Added
full compact
ktrdump.c (263196) ktrdump.c (278327)
1/*-
2 * Copyright (c) 2002 Jake Burkholder
3 * Copyright (c) 2004 Robert Watson
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 12 unchanged lines hidden (view full) ---

21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2002 Jake Burkholder
3 * Copyright (c) 2004 Robert Watson
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 12 unchanged lines hidden (view full) ---

21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: head/usr.bin/ktrdump/ktrdump.c 263196 2014-03-14 22:07:08Z neel $");
29__FBSDID("$FreeBSD: head/usr.bin/ktrdump/ktrdump.c 278327 2015-02-06 19:41:23Z jhb $");
30
31#include <sys/types.h>
32#include <sys/ktr.h>
33#include <sys/mman.h>
34#include <sys/stat.h>
35
36#include <err.h>
37#include <fcntl.h>
38#include <kvm.h>
39#include <limits.h>
40#include <nlist.h>
41#include <stdint.h>
42#include <stdio.h>
43#include <stdlib.h>
44#include <string.h>
45#include <unistd.h>
46
47#define SBUFLEN 128
48#define USAGE \
30
31#include <sys/types.h>
32#include <sys/ktr.h>
33#include <sys/mman.h>
34#include <sys/stat.h>
35
36#include <err.h>
37#include <fcntl.h>
38#include <kvm.h>
39#include <limits.h>
40#include <nlist.h>
41#include <stdint.h>
42#include <stdio.h>
43#include <stdlib.h>
44#include <string.h>
45#include <unistd.h>
46
47#define SBUFLEN 128
48#define USAGE \
49 "usage: ktrdump [-cfqrtH] [-e execfile] [-i ktrfile] [-m corefile] [-o outfile]\n"
49 "usage: ktrdump [-cfqrtH] [-i ktrfile] [-M core] [-N system] [-o outfile]\n"
50
51static void usage(void);
52
53static struct nlist nl[] = {
54 { "_ktr_version" },
55 { "_ktr_entries" },
56 { "_ktr_idx" },
57 { "_ktr_buf" },
58 { NULL }
59};
60
61static int cflag;
50
51static void usage(void);
52
53static struct nlist nl[] = {
54 { "_ktr_version" },
55 { "_ktr_entries" },
56 { "_ktr_idx" },
57 { "_ktr_buf" },
58 { NULL }
59};
60
61static int cflag;
62static int eflag;
63static int fflag;
62static int fflag;
64static int mflag;
63static int Mflag;
64static int Nflag;
65static int qflag;
66static int rflag;
67static int tflag;
68static int iflag;
69static int hflag;
70
71static char corefile[PATH_MAX];
72static char execfile[PATH_MAX];

--- 25 unchanged lines hidden (view full) ---

98 int in;
99 int c;
100 int i = 0;
101
102 /*
103 * Parse commandline arguments.
104 */
105 out = stdout;
65static int qflag;
66static int rflag;
67static int tflag;
68static int iflag;
69static int hflag;
70
71static char corefile[PATH_MAX];
72static char execfile[PATH_MAX];

--- 25 unchanged lines hidden (view full) ---

98 int in;
99 int c;
100 int i = 0;
101
102 /*
103 * Parse commandline arguments.
104 */
105 out = stdout;
106 while ((c = getopt(ac, av, "cfqrtHe:i:m:o:")) != -1)
106 while ((c = getopt(ac, av, "cfqrtHe:i:m:M:N:o:")) != -1)
107 switch (c) {
108 case 'c':
109 cflag = 1;
110 break;
107 switch (c) {
108 case 'c':
109 cflag = 1;
110 break;
111 case 'N':
111 case 'e':
112 if (strlcpy(execfile, optarg, sizeof(execfile))
113 >= sizeof(execfile))
114 errx(1, "%s: File name too long", optarg);
112 case 'e':
113 if (strlcpy(execfile, optarg, sizeof(execfile))
114 >= sizeof(execfile))
115 errx(1, "%s: File name too long", optarg);
115 eflag = 1;
116 Nflag = 1;
116 break;
117 case 'f':
118 fflag = 1;
119 break;
120 case 'i':
121 iflag = 1;
122 if ((in = open(optarg, O_RDONLY)) == -1)
123 err(1, "%s", optarg);
124 break;
117 break;
118 case 'f':
119 fflag = 1;
120 break;
121 case 'i':
122 iflag = 1;
123 if ((in = open(optarg, O_RDONLY)) == -1)
124 err(1, "%s", optarg);
125 break;
126 case 'M':
125 case 'm':
126 if (strlcpy(corefile, optarg, sizeof(corefile))
127 >= sizeof(corefile))
128 errx(1, "%s: File name too long", optarg);
127 case 'm':
128 if (strlcpy(corefile, optarg, sizeof(corefile))
129 >= sizeof(corefile))
130 errx(1, "%s: File name too long", optarg);
129 mflag = 1;
131 Mflag = 1;
130 break;
131 case 'o':
132 if ((out = fopen(optarg, "w")) == NULL)
133 err(1, "%s", optarg);
134 break;
135 case 'q':
136 qflag++;
137 break;

--- 14 unchanged lines hidden (view full) ---

152 av += optind;
153 if (ac != 0)
154 usage();
155
156 /*
157 * Open our execfile and corefile, resolve needed symbols and read in
158 * the trace buffer.
159 */
132 break;
133 case 'o':
134 if ((out = fopen(optarg, "w")) == NULL)
135 err(1, "%s", optarg);
136 break;
137 case 'q':
138 qflag++;
139 break;

--- 14 unchanged lines hidden (view full) ---

154 av += optind;
155 if (ac != 0)
156 usage();
157
158 /*
159 * Open our execfile and corefile, resolve needed symbols and read in
160 * the trace buffer.
161 */
160 if ((kd = kvm_openfiles(eflag ? execfile : NULL,
161 mflag ? corefile : NULL, NULL, O_RDONLY, errbuf)) == NULL)
162 if ((kd = kvm_openfiles(Nflag ? execfile : NULL,
163 Mflag ? corefile : NULL, NULL, O_RDONLY, errbuf)) == NULL)
162 errx(1, "%s", errbuf);
163 if (kvm_nlist(kd, nl) != 0 ||
164 kvm_read(kd, nl[0].n_value, &version, sizeof(version)) == -1)
165 errx(1, "%s", kvm_geterr(kd));
166 if (version != KTR_VERSION)
167 errx(1, "ktr version mismatch");
168 if (iflag) {
169 if (fstat(in, &sb) == -1)

--- 150 unchanged lines hidden ---
164 errx(1, "%s", errbuf);
165 if (kvm_nlist(kd, nl) != 0 ||
166 kvm_read(kd, nl[0].n_value, &version, sizeof(version)) == -1)
167 errx(1, "%s", kvm_geterr(kd));
168 if (version != KTR_VERSION)
169 errx(1, "ktr version mismatch");
170 if (iflag) {
171 if (fstat(in, &sb) == -1)

--- 150 unchanged lines hidden ---