Subject: bin/8517: kdump patch
To: None <gnats-bugs@gnats.netbsd.org>
From: None <roskens@Elfin.Net>
List: netbsd-bugs
Date: 09/29/1999 14:50:49
>Number:         8517
>Category:       bin
>Synopsis:       patch to kdump to add process id selection.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Wed Sep 29 14:50:01 1999
>Last-Modified:
>Originator:     Ron Roskens
>Organization:
>Release:        NetBSD-current 09/29/1999
>Environment:
	
System: NetBSD mail.elfin.net 1.4 NetBSD 1.4 (GENERIC) #0: Fri May 7 12:27:31 PDT 1999 perry@cynic.cynic.net:/usr/src/sys/arch/i386/compile/GENERIC i386


>Description:
   the following patch to kdump will allow you to select a
   specific process id when converting a ktrace.out file.
>How-To-Repeat:
>Fix:

diff -c kdump.1.orig kdump.1
*** kdump.1.orig	Tue Mar 23 06:16:04 1999
--- kdump.1	Tue Sep 28 15:17:35 1999
***************
*** 45,50 ****
--- 45,51 ----
  .Op Fl e Ar emulation
  .Op Fl f Ar file
  .Op Fl m Ar maxdata
+ .Op Fl p Ar pid
  .Op Fl t Op cenis
  .Sh DESCRIPTION
  .Nm
***************
*** 86,91 ****
--- 87,94 ----
  string.
  Suppressing this feature yields a more consistent output format and is
  easily amenable to further processing.
+ .It Fl p Ar pid
+ Display system calls corresponding to pid.
  .It Fl R
  Display relative timestamps (time since previous entry).
  .It Fl T
diff -c kdump.c.orig kdump.c
*** kdump.c.orig	Fri Aug  6 06:32:02 1999
--- kdump.c	Wed Sep 29 16:06:02 1999
***************
*** 56,61 ****
--- 56,62 ----
  #include <sys/ktrace.h>
  #include <sys/ioctl.h>
  #include <sys/ptrace.h>
+ #include <sys/proc.h>
  
  #include <err.h>
  #include <signal.h>
***************
*** 166,176 ****
  {
  	int ch, ktrlen, size;
  	void *m;
  	int trpoints = ALL_POINTS;
  
  	current = &emulations[0];	/* NetBSD */
  
! 	while ((ch = getopt(argc, argv, "e:f:dlm:nRTt:")) != -1)
  		switch (ch) {
  		case 'e':
  			setemul(optarg);
--- 167,178 ----
  {
  	int ch, ktrlen, size;
  	void *m;
+ 	pid_t ppid = -1;
  	int trpoints = ALL_POINTS;
  
  	current = &emulations[0];	/* NetBSD */
  
! 	while ((ch = getopt(argc, argv, "e:f:dlm:np:RTt:")) != -1)
  		switch (ch) {
  		case 'e':
  			setemul(optarg);
***************
*** 190,195 ****
--- 192,202 ----
  		case 'n':
  			fancy = 0;
  			break;
+ 		case 'p':
+ 			ppid = atoi(optarg);
+ 			if (ppid < 1 || ppid > PID_MAX)
+ 				errx(1, "pid %d is out of bounds", optarg);
+ 			break;
  		case 'R':
  			timestamp = 2;	/* relative timestamp */
  			break;
***************
*** 216,221 ****
--- 223,230 ----
  	if (!freopen(tracefile, "r", stdin))
  		err(1, "%s", tracefile);
  	while (fread_tail((char *)&ktr_header, sizeof(struct ktr_header), 1)) {
+ 		if (ppid != -1 && ktr_header.ktr_pid != ppid)
+ 			continue;
  		if (trpoints & (1<<ktr_header.ktr_type))
  			dumpheader(&ktr_header);
  		if ((ktrlen = ktr_header.ktr_len) < 0)
***************
*** 604,610 ****
  {
  
  	(void)fprintf(stderr,
! "usage: kdump [-dnlRT] [-e emulation] [-f trfile] [-m maxdata] [-t [cnis]]\n");
  	exit(1);
  }
  
--- 613,619 ----
  {
  
  	(void)fprintf(stderr,
! "usage: kdump [-dnlRT] [-e emulation] [-f trfile] [-m maxdata] [-p pid] [-t [cnis]]\n");
  	exit(1);
  }
  
>Audit-Trail:
>Unformatted: