kdump_verbose.diff

schmidtm, 12/13/2007 11:12 AM

Download (24.5 KB)

View differences:

kdump/Makefile 2007-12-13 12:34:56.000000000 +0100
1 1
#	@(#)Makefile	8.1 (Berkeley) 6/6/93
2
# $FreeBSD: src/usr.bin/kdump/Makefile,v 1.4.2.2 2002/07/23 09:16:07 ru Exp $
2
# $FreeBSD: src/usr.bin/kdump/Makefile,v 1.12 2006/05/20 14:27:22 netchild Exp $
3 3
# $DragonFly: src/usr.bin/kdump/Makefile,v 1.6 2007/08/27 16:50:54 pavalos Exp $
4 4

  
5 5
.PATH: ${.CURDIR}/../ktrace
6 6

  
7 7
PROG=		kdump
8
SRCS=		kdump.c ioctl.c subr.c
9
CFLAGS+=	-I${.CURDIR}/../ktrace -I${.CURDIR}/../.. -I${.CURDIR}/../../sys
8
SRCS=		kdump.c ioctl.c kdump_subr.c subr.c
9
CFLAGS+=	-I${.CURDIR}/../ktrace -I${.CURDIR} -I${.CURDIR}/../.. 
10 10
WARNS?=	0
11 11

  
12
CLEANFILES=	ioctl.c
12
CLEANFILES=	ioctl.c kdump_subr.c
13 13

  
14 14
ioctl.c: mkioctls
15 15
	sh ${.CURDIR}/mkioctls ${DESTDIR}/usr/include > ${.TARGET}
16 16

  
17
kdump_subr.c: mksubr
18
	sh ${.CURDIR}/mksubr ${DESTDIR}/usr/include > ${.TARGET}
19

  
17 20
.include <bsd.prog.mk>
kdump/kdump.c 2007-12-13 12:34:14.000000000 +0100
32 32
 *
33 33
 * @(#) Copyright (c) 1988, 1993 The Regents of the University of California.  All rights reserved.
34 34
 * @(#)kdump.c	8.1 (Berkeley) 6/6/93
35
 * $FreeBSD: src/usr.bin/kdump/kdump.c,v 1.17 1999/12/29 05:05:33 peter Exp $
35
 * $FreeBSD: src/usr.bin/kdump/kdump.c,v 1.29 2006/05/20 14:27:22 netchild Exp $
36 36
 * $DragonFly: src/usr.bin/kdump/kdump.c,v 1.8 2007/05/07 15:43:31 dillon Exp $
37 37
 */
38 38

  
......
54 54
#include <unistd.h>
55 55
#include <vis.h>
56 56
#include "ktrace.h"
57
#include "kdump_subr.h"
57 58

  
58 59
int timestamp, decimal, fancy = 1, tail, maxdata = 64;
59 60
int fixedformat;
......
257 258
	if (narg) {
258 259
		char c = '(';
259 260
		if (fancy) {
261

  
262
#define print_number(i,n,c) do {                      \
263
	if (decimal)                                  \
264
		(void)printf("%c%ld", c, (long)*i);   \
265
	else                                          \
266
		(void)printf("%c%#lx", c, (long)*i);  \
267
	i++;                                          \
268
	n--;                                          \
269
	c = ',';                                      \
270
	} while (0);
271

  
260 272
			if (ktr->ktr_code == SYS_ioctl) {
261 273
				char *cp;
262
				if (decimal)
263
					(void)printf("(%ld", (long)*ip);
264
				else
265
					(void)printf("(%#lx", (long)*ip);
266
				ip++;
267
				narg--;
274
				print_number(ip,narg,c);
268 275
				if ((cp = ioctlname(*ip)) != NULL)
269 276
					(void)printf(",%s", cp);
270 277
				else {
......
276 283
				c = ',';
277 284
				ip++;
278 285
				narg--;
286
			} else if (ktr->ktr_code == SYS_access) {
287
				print_number(ip,narg,c);
288
				(void)putchar(',');
289
				accessmodename ((int)*ip);
290
				ip++;
291
				narg--;
292
			} else if (ktr->ktr_code == SYS_open) {
293
				int	flags;
294
				int	mode;
295
				print_number(ip,narg,c);
296
				flags = *ip;
297
				mode = *++ip;
298
				(void)putchar(',');
299
				flagsandmodename (flags, mode, decimal);
300
				ip++;
301
				narg-=2;
302
			} else if (ktr->ktr_code == SYS_wait4) {
303
				print_number(ip,narg,c);
304
				print_number(ip,narg,c);
305
				(void)putchar(',');
306
				wait4optname ((int)*ip);
307
				ip++;
308
				narg--;
309
			} else if (ktr->ktr_code == SYS_chmod ||
310
				   ktr->ktr_code == SYS_fchmod ||
311
				   ktr->ktr_code == SYS_lchmod) {
312
				print_number(ip,narg,c);
313
				(void)putchar(',');
314
				modename ((int)*ip);
315
				ip++;
316
				narg--;
317
			} else if (ktr->ktr_code == SYS_mknod) {
318
				print_number(ip,narg,c);
319
				(void)putchar(',');
320
				modename ((int)*ip);
321
				ip++;
322
				narg--;
323
			} else if (ktr->ktr_code == SYS_getfsstat) {
324
				print_number(ip,narg,c);
325
				print_number(ip,narg,c);
326
				(void)putchar(',');
327
				getfsstatflagsname ((int)*ip);
328
				ip++;
329
				narg--;
330
			} else if (ktr->ktr_code == SYS_mount) {
331
				print_number(ip,narg,c);
332
				print_number(ip,narg,c);
333
				(void)putchar(',');
334
				mountflagsname ((int)*ip);
335
				ip++;
336
				narg--;
337
			} else if (ktr->ktr_code == SYS_unmount) {
338
				print_number(ip,narg,c);
339
				(void)putchar(',');
340
				mountflagsname ((int)*ip);
341
				ip++;
342
				narg--;
343
			} else if (ktr->ktr_code == SYS_recvmsg ||
344
				   ktr->ktr_code == SYS_sendmsg) {
345
				print_number(ip,narg,c);
346
				print_number(ip,narg,c);
347
				(void)putchar(',');
348
				sendrecvflagsname ((int)*ip);
349
				ip++;
350
				narg--;
351
			} else if (ktr->ktr_code == SYS_recvfrom ||
352
				   ktr->ktr_code == SYS_sendto) {
353
				print_number(ip,narg,c);
354
				print_number(ip,narg,c);
355
				print_number(ip,narg,c);
356
				(void)putchar(',');
357
				sendrecvflagsname ((int)*ip);
358
				ip++;
359
				narg--;
360
			} else if (ktr->ktr_code == SYS_chflags ||
361
				   ktr->ktr_code == SYS_fchflags) {
362
				print_number(ip,narg,c);
363
				(void)putchar(',');
364
				modename((int)*ip);
365
				ip++;
366
				narg--;
367
			} else if (ktr->ktr_code == SYS_kill) {
368
				print_number(ip,narg,c);
369
				(void)putchar(',');
370
				signame((int)*ip);
371
				ip++;
372
				narg--;
373
			} else if (ktr->ktr_code == SYS_reboot) {
374
				(void)putchar('(');
375
				rebootoptname((int)*ip);
376
				ip++;
377
				narg--;
378
			} else if (ktr->ktr_code == SYS_umask) {
379
				(void)putchar('(');
380
				modename((int)*ip);
381
				ip++;
382
				narg--;
383
			} else if (ktr->ktr_code == SYS_msync) {
384
				print_number(ip,narg,c);
385
				print_number(ip,narg,c);
386
				(void)putchar(',');
387
				msyncflagsname((int)*ip);
388
				ip++;
389
				narg--;
390
			} else if (ktr->ktr_code == SYS_mmap) {
391
				print_number(ip,narg,c);
392
				print_number(ip,narg,c);
393
				(void)putchar(',');
394
				mmapprotname ((int)*ip);
395
				(void)putchar(',');
396
				ip++;
397
				narg--;
398
				mmapflagsname ((int)*ip);
399
				ip++;
400
				narg--;
401
			} else if (ktr->ktr_code == SYS_mprotect) {
402
				print_number(ip,narg,c);
403
				print_number(ip,narg,c);
404
				(void)putchar(',');
405
				mmapprotname ((int)*ip);
406
				ip++;
407
				narg--;
408
			} else if (ktr->ktr_code == SYS_madvise) {
409
				print_number(ip,narg,c);
410
				print_number(ip,narg,c);
411
				(void)putchar(',');
412
				madvisebehavname((int)*ip);
413
				ip++;
414
				narg--;
415
			} else if (ktr->ktr_code == SYS_setpriority) {
416
				print_number(ip,narg,c);
417
				print_number(ip,narg,c);
418
				(void)putchar(',');
419
				prioname((int)*ip);
420
				ip++;
421
				narg--;
422
			} else if (ktr->ktr_code == SYS_fcntl) {
423
				int cmd;
424
				int arg;
425
				print_number(ip,narg,c);
426
				cmd = *ip;
427
				arg = *++ip;
428
				(void)putchar(',');
429
				fcntlcmdname(cmd, arg, decimal);
430
				ip++;
431
				narg-=2;
432
			} else if (ktr->ktr_code == SYS_socket) {
433
				(void)putchar('(');
434
				sockdomainname((int)*ip);
435
				ip++;
436
				narg--;
437
				(void)putchar(',');
438
				socktypename((int)*ip);
439
				ip++;
440
				narg--;
441
				c = ',';
442
			} else if (ktr->ktr_code == SYS_setsockopt ||
443
				   ktr->ktr_code == SYS_getsockopt) {
444
				print_number(ip,narg,c);
445
				(void)putchar(',');
446
				sockoptlevelname((int)*ip, decimal);
447
				ip++;
448
				narg--;
449
				(void)putchar(',');
450
				sockoptname((int)*ip);
451
				ip++;
452
				narg--;
453
			} else if (ktr->ktr_code == SYS_lseek) {
454
				print_number(ip,narg,c);
455
				/* Hidden 'pad' argument, not in lseek(2) */
456
				print_number(ip,narg,c);
457
				print_number(ip,narg,c);
458
				(void)putchar(',');
459
				whencename ((int)*ip);
460
				ip++;
461
				narg--;
462
			} else if (ktr->ktr_code == SYS_flock) {
463
				print_number(ip,narg,c);
464
				(void)putchar(',');
465
				flockname((int)*ip);
466
				ip++;
467
				narg--;
468
			} else if (ktr->ktr_code == SYS_mkfifo ||
469
				   ktr->ktr_code == SYS_mkdir) {
470
				print_number(ip,narg,c);
471
				(void)putchar(',');
472
				modename((int)*ip);
473
				ip++;
474
				narg--;
475
			} else if (ktr->ktr_code == SYS_shutdown) {
476
				print_number(ip,narg,c);
477
				(void)putchar(',');
478
				shutdownhowname((int)*ip);
479
				ip++;
480
				narg--;
481
			} else if (ktr->ktr_code == SYS_socketpair) {
482
				(void)putchar('(');
483
				sockdomainname((int)*ip);
484
				ip++;
485
				narg--;
486
				(void)putchar(',');
487
				socktypename((int)*ip);
488
				ip++;
489
				narg--;
490
				c = ',';
491
			} else if (ktr->ktr_code == SYS_getrlimit ||
492
				   ktr->ktr_code == SYS_setrlimit) {
493
				(void)putchar('(');
494
				rlimitname((int)*ip);
495
				ip++;
496
				narg--;
497
				c = ',';
498
			} else if (ktr->ktr_code == SYS_quotactl) {
499
				print_number(ip,narg,c);
500
				quotactlname((int)*ip);
501
				ip++;
502
				narg--;
503
				c = ',';
504
			} else if (ktr->ktr_code == SYS_rtprio) {
505
				(void)putchar('(');
506
				rtprioname((int)*ip);
507
				ip++;
508
				narg--;
509
				c = ',';
510
			} else if (ktr->ktr_code == SYS___semctl) {
511
				print_number(ip,narg,c);
512
				print_number(ip,narg,c);
513
				semctlname((int)*ip);
514
				ip++;
515
				narg--;
516
			} else if (ktr->ktr_code == SYS_semget) {
517
				print_number(ip,narg,c);
518
				print_number(ip,narg,c);
519
				semgetname((int)*ip);
520
				ip++;
521
				narg--;
522
			} else if (ktr->ktr_code == SYS_msgctl) {
523
				print_number(ip,narg,c);
524
				shmctlname((int)*ip);
525
				ip++;
526
				narg--;
527
			} else if (ktr->ktr_code == SYS_shmat) {
528
				print_number(ip,narg,c);
529
				print_number(ip,narg,c);
530
				shmatname((int)*ip);
531
				ip++;
532
				narg--;
533
			} else if (ktr->ktr_code == SYS_shmctl) {
534
				print_number(ip,narg,c);
535
				shmctlname((int)*ip);
536
				ip++;
537
				narg--;
538
			} else if (ktr->ktr_code == SYS_minherit) {
539
				print_number(ip,narg,c);
540
				print_number(ip,narg,c);
541
				minheritname((int)*ip);
542
				ip++;
543
				narg--;
544
			} else if (ktr->ktr_code == SYS_rfork) {
545
				(void)putchar('(');
546
				rforkname((int)*ip);
547
				ip++;
548
				narg--;
549
				c = ',';
550
			} else if (ktr->ktr_code == SYS_lio_listio) {
551
				(void)putchar('(');
552
				lio_listioname((int)*ip);
553
				ip++;
554
				narg--;
555
				c = ',';
556
			} else if (ktr->ktr_code == SYS_mlockall) {
557
				(void)putchar('(');
558
				mlockallname((int)*ip);
559
				ip++;
560
				narg--;
561
			} else if (ktr->ktr_code == SYS_sched_setscheduler) {
562
				print_number(ip,narg,c);
563
				schedpolicyname((int)*ip);
564
				ip++;
565
				narg--;
566
			} else if (ktr->ktr_code == SYS_sched_get_priority_max ||
567
				   ktr->ktr_code == SYS_sched_get_priority_min) {
568
				(void)putchar('(');
569
				schedpolicyname((int)*ip);
570
				ip++;
571
				narg--;
572
			} else if (ktr->ktr_code == SYS_sendfile) {
573
				print_number(ip,narg,c);
574
				print_number(ip,narg,c);
575
				print_number(ip,narg,c);
576
				print_number(ip,narg,c);
577
				print_number(ip,narg,c);
578
				print_number(ip,narg,c);
579
				sendfileflagsname((int)*ip);
580
				ip++;
581
				narg--;
582
			} else if (ktr->ktr_code == SYS_kldsym) {
583
				print_number(ip,narg,c);
584
				kldsymcmdname((int)*ip);
585
				ip++;
586
				narg--;
587
			} else if (ktr->ktr_code == SYS_sigprocmask) {
588
				(void)putchar('(');
589
				sigprocmaskhowname((int)*ip);
590
				ip++;
591
				narg--;
592
				c = ',';
593
			} else if (ktr->ktr_code == SYS___acl_get_file ||
594
				   ktr->ktr_code == SYS___acl_set_file ||
595
				   ktr->ktr_code == SYS___acl_get_fd ||
596
				   ktr->ktr_code == SYS___acl_set_fd ||
597
				   ktr->ktr_code == SYS___acl_delete_file ||
598
				   ktr->ktr_code == SYS___acl_delete_fd ||
599
				   ktr->ktr_code == SYS___acl_aclcheck_file ||
600
				   ktr->ktr_code == SYS___acl_aclcheck_fd) {
601
				print_number(ip,narg,c);
602
				acltypename((int)*ip);
603
				ip++;
604
				narg--;
605
			} else if (ktr->ktr_code == SYS_sigaction) {
606
				(void)putchar('(');
607
				signame((int)*ip);
608
				ip++;
609
				narg--;
610
				c = ',';
611
			} else if (ktr->ktr_code == SYS_extattrctl) {
612
				print_number(ip,narg,c);
613
				extattrctlname((int)*ip);
614
				ip++;
615
				narg--;
279 616
			} else if (ktr->ktr_code == SYS_ptrace) {
280 617
				if (*ip < sizeof(ptrace_ops) /
281 618
				    sizeof(ptrace_ops[0]) && *ip >= 0)
......
312 649
			}
313 650
		}
314 651
		while (narg) {
315
			if (decimal)
316
				(void)printf("%c%ld", c, (long)*ip);
317
			else
318
				(void)printf("%c%#lx", c, (long)*ip);
319
			c = ',';
320
			ip++;
321
			narg--;
652
			print_number(ip,narg,c);
322 653
		}
323 654
		(void)putchar(')');
324 655
	}
kdump/kdump_subr.h 2007-12-12 20:25:17.000000000 +0100
1
/* $FreeBSD: src/usr.bin/kdump/kdump_subr.h,v 1.3 2007/04/09 22:04:27 emaste Exp $ */
2

  
3
void signame (int);
4
void semctlname (int);
5
void shmctlname (int);
6
void semgetname (int);
7
void fcntlcmdname (int, int, int);
8
void rtprioname (int);
9
void modename (int);
10
void flagsname (int);
11
void flagsandmodename (int, int, int);
12
void accessmodename (int);
13
void mmapprotname (int);
14
void mmapflagsname (int);
15
void wait4optname (int);
16
void sendrecvflagsname (int);
17
void getfsstatflagsname (int);
18
void mountflagsname (int);
19
void rebootoptname (int);
20
void flockname (int);
21
void sockoptname (int);
22
void sockoptlevelname (int, int);
23
void sockdomainname (int);
24
void sockipprotoname (int);
25
void socktypename (int);
26
void thrcreateflagsname (int);
27
void mlockallname (int);
28
void shmatname (int);
29
void rforkname (int);
30
void nfssvcname (int);
31
void whencename (int);
32
void rlimitname (int);
33
void shutdownhowname (int);
34
void prioname (int);
35
void madvisebehavname (int);
36
void msyncflagsname (int);
37
void schedpolicyname (int);
38
void kldunloadfflagsname (int);
39
void ksethrcmdname (int);
40
void extattrctlname (int);
41
void kldsymcmdname (int);
42
void sendfileflagsname (int);
43
void acltypename (int);
44
void sigprocmaskhowname (int);
45
void lio_listioname (int);
46
void minheritname (int);
47
void quotactlname (int);
48
void ptraceopname (int);
kdump/mksubr 2007-12-13 12:26:05.000000000 +0100
1
set -e
2

  
3
# Generates kdump_subr.c
4
# mkioctls is a special-purpose script, and works fine as it is
5
# now, so it remains independent. The idea behind how it generates
6
# its list was heavily borrowed here.
7
#
8
# Some functions here are automatically generated. This can mean
9
# the user will see unusual kdump output or errors while building
10
# if the underlying .h files are changed significantly.
11
#
12
# Key:
13
# AUTO: Completely auto-generated with either the "or" or the "switch"
14
# method.
15
# AUTO - Special: Generated automatically, but with some extra commands
16
# that the auto_*_type() functions are inappropriate for.
17
# MANUAL: Manually entered and must therefore be manually updated.
18

  
19
# $FreeBSD: src/usr.bin/kdump/mksubr,v 1.9 2007/04/09 19:16:24 emaste Exp $
20

  
21
LC_ALL=C; export LC_ALL
22

  
23
if [ -z "$1" ]
24
then
25
	echo "usage: sh $0 include-dir"
26
	exit 1
27
fi
28
include_dir=$1
29

  
30
#
31
# Automatically generates a C function that will print out the
32
# numeric input as a pipe-delimited string of the appropriate
33
# #define keys. ex:
34
# S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH
35
# The XOR is necessary to prevent including the "0"-value in every
36
# line.
37
#
38
auto_or_type () {
39
	local name grep file
40
	name=$1
41
	grep=$2
42
	file=$3
43

  
44
	cat <<_EOF_
45
/* AUTO */
46
void
47
$name (int arg)
48
{
49
	int	or = 0;
50
_EOF_
51
	egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
52
		$include_dir/$file | \
53
	awk '{ for (i = 1; i <= NF; i++) \
54
		if ($i ~ /define/) \
55
			break; \
56
		++i; \
57
		printf "\tif(!((arg>0)^((%s)>0)))\n\t\tif_print_or(arg, %s, or);\n", $i, $i }'
58
cat <<_EOF_
59
	if (or == 0)
60
		(void)printf("<invalid>%ld", (long)arg);
61
}
62

  
63
_EOF_
64
}
65

  
66
#
67
# Automatically generates a C function used when the argument
68
# maps to a single, specific #definition
69
#
70
auto_switch_type () {
71
	local name grep file
72
	name=$1
73
	grep=$2
74
	file=$3
75

  
76
	cat <<_EOF_
77
/* AUTO */
78
void
79
$name (int arg)
80
{
81
	switch (arg) {
82
_EOF_
83
	egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
84
		$include_dir/$file | \
85
	awk '{ for (i = 1; i <= NF; i++) \
86
		if ($i ~ /define/) \
87
			break; \
88
		++i; \
89
		printf "\tcase %s:\n\t\t(void)printf(\"%s\");\n\t\tbreak;\n", $i, $i }'
90
cat <<_EOF_
91
	default: /* Should not reach */
92
		(void)printf("<invalid=%ld>", (long)arg);
93
	}
94
}
95

  
96
_EOF_
97
}
98

  
99
#
100
# Automatically generates a C function used when the argument
101
# maps to a #definition
102
#
103
auto_if_type () {
104
	local name grep file
105
	name=$1
106
	grep=$2
107
	file=$3
108

  
109
	cat <<_EOF_
110
/* AUTO */
111
void
112
$name (int arg)
113
{
114
_EOF_
115
	egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
116
		$include_dir/$file | \
117
	awk '{ printf "\t"; \
118
		if (NR > 1) \
119
			printf "else " ; \
120
		printf "if (arg == %s) \n\t\tprintf(\"%s\");\n", $2, $2 }'
121
cat <<_EOF_
122
	else /* Should not reach */
123
		(void)printf("<invalid=%ld>", (long)arg);
124
}
125

  
126
_EOF_
127
}
128

  
129
# C start
130

  
131
cat <<_EOF_
132
#define _KERNEL_STRUCTURES
133

  
134
#include <stdio.h>
135
#include <sys/fcntl.h>
136
#include <sys/stat.h>
137
#include <sys/unistd.h>
138
#include <sys/mman.h>
139
#include <sys/wait.h>
140
#include <sys/socket.h>
141
#include <netinet/in.h>
142
#include <sys/param.h>
143
#include <sys/mount.h>
144
#include <sys/ptrace.h>
145
#include <sys/resource.h>
146
#include <sys/reboot.h>
147
#include <sched.h>
148
#include <sys/linker.h>
149
#include <sys/extattr.h>
150
#include <sys/acl.h>
151
#include <aio.h>
152
#include <sys/sem.h>
153
#include <sys/ipc.h>
154
#include <sys/rtprio.h>
155
#include <sys/shm.h>
156
#include <vfs/ufs/quota.h>
157

  
158
#include "kdump_subr.h"
159

  
160
/*
161
 * These are simple support macros. print_or utilizes a variable
162
 * defined in the calling function to track whether or not it should
163
 * print a logical-OR character ('|') before a string. if_print_or
164
 * simply handles the necessary "if" statement used in many lines
165
 * of this file.
166
 */
167
#define print_or(str,orflag) do {                  \\
168
	if (orflag) putchar('|'); else orflag = 1; \\
169
	printf (str); }                            \\
170
	while (0)
171
#define if_print_or(i,flag,orflag) do {            \\
172
	if ((i & flag) == flag)                    \\
173
	print_or(#flag,orflag); }                  \\
174
	while (0)
175

  
176
/* MANUAL */
177
extern char *signames[]; /* from kdump.c */
178
void
179
signame (int sig)
180
{
181
	if (sig > 0 && sig < NSIG)
182
		(void)printf("SIG%s",signames[sig]);
183
	else
184
		(void)printf("SIG %d", sig);
185
}
186

  
187
/* MANUAL */
188
void
189
semctlname (int cmd)
190
{
191
	switch (cmd) {
192
	case GETNCNT:
193
		(void)printf("GETNCNT");
194
		break;
195
	case GETPID:
196
		(void)printf("GETPID");
197
		break;
198
	case GETVAL:
199
		(void)printf("GETVAL");
200
		break;
201
	case GETALL:
202
		(void)printf("GETALL");
203
		break;
204
	case GETZCNT:
205
		(void)printf("GETZCNT");
206
		break;
207
	case SETVAL:
208
		(void)printf("SETVAL");
209
		break;
210
	case SETALL:
211
		(void)printf("SETALL");
212
		break;
213
	case IPC_RMID:
214
		(void)printf("IPC_RMID");
215
		break;
216
	case IPC_SET:
217
		(void)printf("IPC_SET");
218
		break;
219
	case IPC_STAT:
220
		(void)printf("IPC_STAT");
221
		break;
222
	default: /* Should not reach */
223
		(void)printf("<invalid=%ld>", (long)cmd);
224
	}
225
}
226

  
227
/* MANUAL */
228
void
229
shmctlname (int cmd) {
230
	switch (cmd) {
231
	case IPC_RMID:
232
		(void)printf("IPC_RMID");
233
		break;
234
	case IPC_SET:
235
		(void)printf("IPC_SET");
236
		break;
237
	case IPC_STAT:
238
		(void)printf("IPC_STAT");
239
		break;
240
	default: /* Should not reach */
241
		(void)printf("<invalid=%ld>", (long)cmd);
242
	}
243
}
244

  
245
/* MANUAL */
246
void
247
semgetname (int flag) {
248
	int	or = 0;
249
	if_print_or(flag, SEM_R, or);
250
	if_print_or(flag, SEM_A, or);
251
	if_print_or(flag, (SEM_R>>3), or);
252
	if_print_or(flag, (SEM_A>>3), or);
253
	if_print_or(flag, (SEM_R>>6), or);
254
	if_print_or(flag, (SEM_A>>6), or);
255
}
256

  
257
/*
258
 * MANUAL
259
 *
260
 * Only used by SYS_open. Unless O_CREAT is set in flags, the
261
 * mode argument is unused (and often bogus and misleading).
262
 */
263
void
264
flagsandmodename (int flags, int mode, int decimal) {
265
	flagsname (flags);
266
	(void)putchar(',');
267
	if ((flags & O_CREAT) == O_CREAT) {
268
		modename (mode);
269
	} else {
270
		if (decimal) {
271
			(void)printf("<unused>%ld", (long)mode);
272
		} else {
273
			(void)printf("<unused>%#lx", (long)mode);
274
		}
275
	}
276
}
277

  
278
/*
279
 * MANUAL
280
 *
281
 * [g|s]etsockopt's level argument can either be SOL_SOCKET or a value
282
 * referring to a line in /etc/protocols . It might be appropriate
283
 * to use getprotoent(3) here.
284
 */
285
void
286
sockoptlevelname (int level, int decimal)
287
{
288
	if (level == SOL_SOCKET) {
289
		(void)printf("SOL_SOCKET");
290
	} else {
291
		if (decimal) {
292
			(void)printf("%ld", (long)level);
293
		} else {
294
			(void)printf("%#lx", (long)level);
295
		}
296
	}
297
}
298

  
299
_EOF_
300

  
301
auto_or_type "modename" "S_[A-Z]+[[:space:]]+[0-6]{7}" "sys/stat.h"
302
auto_or_type "flagsname" "O_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/fcntl.h"
303
auto_or_type "accessmodename" "[A-Z]_OK[[:space:]]+0?x?[0-9A-Fa-f]+" "sys/unistd.h"
304
auto_or_type "mmapprotname" "PROT_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/mman.h"
305
auto_or_type "mmapflagsname" "MAP_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/mman.h"
306
auto_or_type "wait4optname" "W[A-Z]+[[:space:]]+[0-9]+" "sys/wait.h"
307
auto_or_type "getfsstatflagsname" "MNT_[A-Z]+[[:space:]]+[1-9][0-9]*" "sys/mount.h"
308
auto_or_type "mountflagsname" "MNT_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mount.h"
309
auto_or_type "rebootoptname" "RB_[A-Z]+[[:space:]]+0x[0-9]+" "sys/reboot.h"
310
auto_or_type "flockname" "LOCK_[A-Z]+[[:space:]]+0x[0-9]+" "sys/fcntl.h"
311
auto_or_type "mlockallname" "MCL_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mman.h"
312
auto_or_type "shmatname" "SHM_[A-Z]+[[:space:]]+[0-9]{6}+" "sys/shm.h"
313
auto_or_type "rforkname" "RF[A-Z]+[[:space:]]+\([0-9]+<<[0-9]+\)" "sys/unistd.h"
314

  
315
auto_switch_type "whencename" "SEEK_[A-Z]+[[:space:]]+[0-9]+" "sys/unistd.h"
316
auto_switch_type "rlimitname" "RLIMIT_[A-Z]+[[:space:]]+[0-9]+" "sys/resource.h"
317
auto_switch_type "shutdownhowname" "SHUT_[A-Z]+[[:space:]]+0x[0-9]+" "sys/socket.h"
318
auto_switch_type "prioname" "PRIO_[A-Z]+[[:space:]]+[0-9]" "sys/resource.h"
319
auto_switch_type "madvisebehavname" "_?MADV_[A-Z]+[[:space:]]+[0-9]+" "sys/mman.h"
320
auto_switch_type "msyncflagsname" "MS_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mman.h"
321
auto_switch_type "schedpolicyname" "SCHED_[A-Z]+[[:space:]]+[0-9]+" "sched.h"
322
auto_switch_type "kldunloadfflagsname" "LINKER_UNLOAD_[A-Z]+[[:space:]]+[0-9]+" "sys/linker.h"
323
auto_switch_type "extattrctlname" "EXTATTR_NAMESPACE_[A-Z]+[[:space:]]+0x[0-9]+" "sys/extattr.h"
324
auto_switch_type "kldsymcmdname" "KLDSYM_[A-Z]+[[:space:]]+[0-9]+" "sys/linker.h"
325
auto_switch_type "sendfileflagsname" "SF_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h"
326
auto_switch_type "acltypename" "ACL_TYPE_[A-Z]+[[:space:]]+0x[0-9]+" "sys/acl.h"
327
auto_switch_type "sigprocmaskhowname" "SIG_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
328
auto_switch_type "lio_listioname" "LIO_(NO)?WAIT[[:space:]]+[0-9]+" "aio.h"
329
auto_switch_type "minheritname" "INHERIT_[A-Z]+[[:space:]]+[0-9]+" "sys/mman.h"
330
auto_switch_type "quotactlname" "Q_[A-Z]+[[:space:]]+0x[0-9]+" "ufs/ufs/quota.h"
331
auto_if_type "sockdomainname" "PF_[[:alnum:]]+[[:space:]]+" "sys/socket.h"
332
auto_if_type "sockipprotoname" "IPPROTO_[[:alnum:]]+[[:space:]]+" "netinet/in.h"
333
auto_switch_type "sockoptname" "SO_[A-Z]+[[:space:]]+0x[0-9]+" "sys/socket.h"
334
auto_switch_type "socktypename" "SOCK_[A-Z]+[[:space:]]+[1-9]+[0-9]*" "sys/socket.h"
335
auto_switch_type "ptraceopname" "PT_[[:alnum:]]+[[:space:]]+[0-9]+" "sys/ptrace.h"
336

  
337
cat <<_EOF_
338
/*
339
 * AUTO - Special
340
 * F_ is used to specify fcntl commands as well as arguments. Both sets are
341
 * grouped in fcntl.h, and this awk script grabs the first group.
342
 */
343
void
344
fcntlcmdname (int cmd, int arg, int decimal)
345
{
346
	switch (cmd) {
347
_EOF_
348
egrep "^#[[:space:]]*define[[:space:]]+F_[A-Z]+[[:space:]]+[0-9]+[[:space:]]*" \
349
	$include_dir/sys/fcntl.h | \
350
	awk 'BEGIN { o=0 } { for (i = 1; i <= NF; i++) \
351
		if ($i ~ /define/) \
352
			break; \
353
		++i; \
354
		if (o <= $(i+1)) \
355
			printf "\tcase %s:\n\t\t(void)printf(\"%s\");\n\t\tbreak;\n", $i, $i; \
356
		else \
357
			exit; \
358
		o = $(i+1) }'
359
cat <<_EOF_
360
	default: /* Should not reach */
361
		(void)printf("<invalid=%ld>", (long)cmd);
362
	}
363
	(void)putchar(',');
364
	if (cmd == F_GETFD || cmd == F_SETFD) {
365
		if (arg == FD_CLOEXEC)
366
			(void)printf("FD_CLOEXEC");
367
		else if (arg == 0)
368
			(void)printf("0");
369
		else {
370
			if (decimal)
371
				(void)printf("<invalid>%ld", (long)arg);
372
			else
373
				(void)printf("<invalid>%#lx", (long)arg);
374
		}
375
	} else if (cmd == F_SETFL) {
376
		flagsname(arg);
377
	} else {
378
		if (decimal)
379
			(void)printf("%ld", (long)arg);
380
		else
381
			(void)printf("%#lx", (long)arg);
382
	}
383
}
384

  
385
/*
386
 * AUTO - Special
387
 *
388
 * The only reason this is not fully automated is due to the
389
 * grep -v RTP_PRIO statement. A better egrep line should
390
 * make this capable of being a auto_switch_type() function.
391
 */
392
void
393
rtprioname (int func)
394
{
395
	switch (func) {
396
_EOF_
397
egrep "^#[[:space:]]*define[[:space:]]+RTP_[A-Z]+[[:space:]]+0x[0-9]+[[:space:]]*" \
398
	$include_dir/sys/rtprio.h | grep -v RTP_PRIO | \
399
	awk '{ for (i = 1; i <= NF; i++) \
400
		if ($i ~ /define/) \
401
			break; \
402
		++i; \
403
		printf "\tcase %s:\n\t\t(void)printf(\"%s\");\n\t\tbreak;\n", $i, $i }'
404
cat <<_EOF_
405
	default: /* Should not reach */
406
		(void)printf("<invalid=%ld>", (long)func);
407
	}
408
}
409

  
410
/*
411
 * AUTO - Special
412
 *
413
 * The send and recv functions have a flags argument which can be
414
 * set to 0. There is no corresponding #define. The auto_ functions
415
 * detect this as "invalid", which is incorrect here.
416
 */
417
void
418
sendrecvflagsname (int flags)
419
{
420
	int	or = 0;
421
	
422
	if (flags == 0) {
423
		(void)printf("0");
424
		return;
425
	}
426
_EOF_
427
egrep "^#[[:space:]]*define[[:space:]]+MSG_[A-Z]+[[:space:]]+0x[0-9]+[[:space:]]*" $include_dir/sys/socket.h | \
428
	awk '{ for (i = 1; i <= NF; i++) \
429
		if ($i ~ /define/) \
430
			break; \
431
		++i; \
432
		printf "\tif(!((flags>0)^((%s)>0)))\n\t\tif_print_or(flags, %s, or);\n", $i, $i }'
433
cat <<_EOF_
434
}
435

  
436
_EOF_