Deleted Added
full compact
ktrdump.c (129558) ktrdump.c (129559)
1/*-
2 * Copyright (c) 2002 Jake Burkholder
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

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

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

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

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

95 int in;
96 int c;
97 int i;
98
99 /*
100 * Parse commandline arguments.
101 */
102 out = stdout;
68static int tflag;
69static int iflag;
70
71static char corefile[PATH_MAX];
72static char execfile[PATH_MAX];
73
74static char desc[SBUFLEN];
75static char errbuf[_POSIX2_LINE_MAX];

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

96 int in;
97 int c;
98 int i;
99
100 /*
101 * Parse commandline arguments.
102 */
103 out = stdout;
103 while ((c = getopt(ac, av, "cfte:i:m:o:")) != -1)
104 while ((c = getopt(ac, av, "cfqte:i:m:o:")) != -1)
104 switch (c) {
105 case 'c':
106 cflag = 1;
107 break;
108 case 'e':
109 if (strlcpy(execfile, optarg, sizeof(execfile))
110 >= sizeof(execfile))
111 errx(1, "%s: File name too long", optarg);

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

124 >= sizeof(corefile))
125 errx(1, "%s: File name too long", optarg);
126 mflag = 1;
127 break;
128 case 'o':
129 if ((out = fopen(optarg, "w")) == NULL)
130 err(1, "%s", optarg);
131 break;
105 switch (c) {
106 case 'c':
107 cflag = 1;
108 break;
109 case 'e':
110 if (strlcpy(execfile, optarg, sizeof(execfile))
111 >= sizeof(execfile))
112 errx(1, "%s: File name too long", optarg);

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

125 >= sizeof(corefile))
126 errx(1, "%s: File name too long", optarg);
127 mflag = 1;
128 break;
129 case 'o':
130 if ((out = fopen(optarg, "w")) == NULL)
131 err(1, "%s", optarg);
132 break;
133 case 'q':
134 qflag++;
135 break;
132 case 't':
133 tflag = 1;
134 break;
135 case '?':
136 default:
137 usage();
138 }
139 ac -= optind;

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

171 kvm_read(kd, nl[3].n_value, buf, sizeof(*buf) * entries)
172 == -1)
173 errx(1, "%s", kvm_geterr(kd));
174 }
175
176 /*
177 * Print a nice header.
178 */
136 case 't':
137 tflag = 1;
138 break;
139 case '?':
140 default:
141 usage();
142 }
143 ac -= optind;

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

175 kvm_read(kd, nl[3].n_value, buf, sizeof(*buf) * entries)
176 == -1)
177 errx(1, "%s", kvm_geterr(kd));
178 }
179
180 /*
181 * Print a nice header.
182 */
179 fprintf(out, "%-6s ", "index");
180 if (cflag)
181 fprintf(out, "%-3s ", "cpu");
182 if (tflag)
183 fprintf(out, "%-16s ", "timestamp");
184 if (fflag)
185 fprintf(out, "%-40s ", "file and line");
186 fprintf(out, "%s", "trace");
187 fprintf(out, "\n");
183 if (!qflag) {
184 fprintf(out, "%-6s ", "index");
185 if (cflag)
186 fprintf(out, "%-3s ", "cpu");
187 if (tflag)
188 fprintf(out, "%-16s ", "timestamp");
189 if (fflag)
190 fprintf(out, "%-40s ", "file and line");
191 fprintf(out, "%s", "trace");
192 fprintf(out, "\n");
188
193
189 fprintf(out, "------ ");
190 if (cflag)
191 fprintf(out, "--- ");
192 if (tflag)
193 fprintf(out, "---------------- ");
194 if (fflag)
195 fprintf(out, "---------------------------------------- ");
196 fprintf(out, "----- ");
197 fprintf(out, "\n");
194 fprintf(out, "------ ");
195 if (cflag)
196 fprintf(out, "--- ");
197 if (tflag)
198 fprintf(out, "---------------- ");
199 if (fflag)
200 fprintf(out,
201 "---------------------------------------- ");
202 fprintf(out, "----- ");
203 fprintf(out, "\n");
204 }
198
199 /*
200 * Now tear through the trace buffer.
201 */
202 if (!iflag)
203 i = (index - 1) & (entries - 1);
204 for (;;) {
205 if (buf[i].ktr_desc == NULL)

--- 63 unchanged lines hidden ---
205
206 /*
207 * Now tear through the trace buffer.
208 */
209 if (!iflag)
210 i = (index - 1) & (entries - 1);
211 for (;;) {
212 if (buf[i].ktr_desc == NULL)

--- 63 unchanged lines hidden ---