pstat.c fixes -- you asked for it!

utzoo!decvax!pur-ee!purdue!cak utzoo!decvax!pur-ee!purdue!cak
Tue Feb 2 21:00:25 AEST 1982


>From cak Tue Feb  2 20:58:48 1982
To: csvax.4bsd-bugs at berkeley
Subject: pstat.c fixes

The following diffs show changes made to allow pstat to operate
properly with post-mortem core dumps. Basically, addresses
were not having the high order bit properly cleared when dealing
with dumps.

It also fixes a recently reported bug about the addresses the -f
option reports.

Please note also that the documentation does not mention the -k
flag which is expected when dealing with core dumps.

Chris Kent

*** /usr/src/cmd/pstat.c	Tue Feb  2 20:51:06 1982
--- /usr/src/cmd/pstat.c.v0	Tue Feb  2 20:20:29 1982
***************
*** 1,8
  static char *sccsid = "@(#)pstat.c	4.9 (Berkeley) 5/7/81";
  /*
   * Print system stuff
-  *
-  *	fixed to handle core dumps properly, 2/2/81 -- cak
   */
  
  #define mask(x) (x&0377)

--- 1,6 -----
  static char *sccsid = "@(#)pstat.c	4.9 (Berkeley) 5/7/81";
  /*
   * Print system stuff
   */
  
  #define mask(x) (x&0377)
***************
*** 203,209
  	nin = 0;
  	ninode = getw(nl[SNINODE].n_value);
  	xinode = (struct inode *)calloc(ninode, sizeof (struct inode));
! 	kseek(fc, (int)(ainode = (struct inode *)getw(nl[SINODE].n_value)), 0);
  	read(fc, xinode, ninode * sizeof(struct inode));
  	for (ip = xinode; ip < &xinode[ninode]; ip++)
  		if (ip->i_count)

--- 201,207 -----
  	nin = 0;
  	ninode = getw(nl[SNINODE].n_value);
  	xinode = (struct inode *)calloc(ninode, sizeof (struct inode));
! 	lseek(fc, (int)(ainode = (struct inode *)getw(nl[SINODE].n_value)), 0);
  	read(fc, xinode, ninode * sizeof(struct inode));
  	for (ip = xinode; ip < &xinode[ninode]; ip++)
  		if (ip->i_count)
***************
*** 246,252
  
  	if (kflg)
  		loc &= 0x7fffffff;
! 	kseek(fc, loc, 0);
  	read(fc, &word, sizeof (word));
  	if (kflg)
  		word &= 0x7fffffff;

--- 244,250 -----
  
  	if (kflg)
  		loc &= 0x7fffffff;
! 	lseek(fc, loc, 0);
  	read(fc, &word, sizeof (word));
  	if (kflg)
  		word &= 0x7fffffff;
***************
*** 271,277
  	ntx = 0;
  	ntext = getw(nl[SNTEXT].n_value);
  	xtext = (struct text *)calloc(ntext, sizeof (struct text));
! 	kseek(fc, (int)(atext = (struct text *)getw(nl[STEXT].n_value)), 0);
  	read(fc, xtext, ntext * sizeof (struct text));
  	for (xp = xtext; xp < &xtext[ntext]; xp++)
  		if (xp->x_iptr!=NULL)

--- 269,275 -----
  	ntx = 0;
  	ntext = getw(nl[SNTEXT].n_value);
  	xtext = (struct text *)calloc(ntext, sizeof (struct text));
! 	lseek(fc, (int)(atext = (struct text *)getw(nl[STEXT].n_value)), 0);
  	read(fc, xtext, ntext * sizeof (struct text));
  	for (xp = xtext; xp < &xtext[ntext]; xp++)
  		if (xp->x_iptr!=NULL)
***************
*** 315,321
  
  	nproc = getw(nl[SNPROC].n_value);
  	xproc = (struct proc *)calloc(nproc, sizeof (struct proc));
! 	kseek(fc, (int)(aproc = (struct proc *)getw(nl[SPROC].n_value)), 0);
  	read(fc, xproc, nproc * sizeof (struct proc));
  	np = 0;
  	for (pp=xproc; pp < &xproc[nproc]; pp++)

--- 313,319 -----
  
  	nproc = getw(nl[SNPROC].n_value);
  	xproc = (struct proc *)calloc(nproc, sizeof (struct proc));
! 	lseek(fc, (int)(aproc = (struct proc *)getw(nl[SPROC].n_value)), 0);
  	read(fc, xproc, nproc * sizeof (struct proc));
  	np = 0;
  	for (pp=xproc; pp < &xproc[nproc]; pp++)
***************
*** 346,352
  		printf(" %6d", pp->p_ppid);
  		if (kflg)
  			pp->p_addr = (struct pte *)clear((int)pp->p_addr);
! 		kseek(fc, (long)(Usrptma+btokmx(pp->p_addr)), 0);
  		read(fc, &apte, sizeof(apte));
  		printf(" %8x", ctob(apte.pg_pfnum+1) - sizeof(struct pte) * UPAGES);
  		printf(" %4x", pp->p_rssize);

--- 344,350 -----
  		printf(" %6d", pp->p_ppid);
  		if (kflg)
  			pp->p_addr = (struct pte *)clear((int)pp->p_addr);
! 		lseek(fc, (long)(Usrptma+btokmx(pp->p_addr)), 0);
  		read(fc, &apte, sizeof(apte));
  		printf(" %8x", ctob(apte.pg_pfnum+1) - sizeof(struct pte) * UPAGES);
  		printf(" %4x", pp->p_rssize);
***************
*** 370,376
  	printf("1 cons\n");
  	if (kflg)
  		nl[SKL].n_value = clear(nl[SKL].n_value);
! 	kseek(fc, (long)nl[SKL].n_value, 0);
  	read(fc, dz_tty, sizeof(dz_tty[0]));
  	mesg = " # RAW CAN OUT   MODE    ADDR   DEL COL  STATE   PGRP DISC\n";
  	printf(mesg);

--- 368,374 -----
  	printf("1 cons\n");
  	if (kflg)
  		nl[SKL].n_value = clear(nl[SKL].n_value);
! 	lseek(fc, (long)nl[SKL].n_value, 0);
  	read(fc, dz_tty, sizeof(dz_tty[0]));
  	mesg = " # RAW CAN OUT   MODE    ADDR   DEL COL  STATE   PGRP DISC\n";
  	printf(mesg);
***************
*** 381,387
  		nl[SNDZ].n_value = clear(nl[SNDZ].n_value);
  		nl[SDZ].n_value = clear(nl[SDZ].n_value);
  	}
! 	kseek(fc, (long)nl[SNDZ].n_value, 0);
  	read(fc, &ndz, sizeof(ndz));
  	printf("%d dz lines\n", ndz);
  	kseek(fc, (long)nl[SDZ].n_value, 0);

--- 379,385 -----
  		nl[SNDZ].n_value = clear(nl[SNDZ].n_value);
  		nl[SDZ].n_value = clear(nl[SDZ].n_value);
  	}
! 	lseek(fc, (long)nl[SNDZ].n_value, 0);
  	read(fc, &ndz, sizeof(ndz));
  	printf("%d dz lines\n", ndz);
  	lseek(fc, (long)nl[SDZ].n_value, 0);
***************
*** 384,390
  	kseek(fc, (long)nl[SNDZ].n_value, 0);
  	read(fc, &ndz, sizeof(ndz));
  	printf("%d dz lines\n", ndz);
! 	kseek(fc, (long)nl[SDZ].n_value, 0);
  	read(fc, dz_tty, sizeof(dz_tty));
  	for (tp = dz_tty; tp < &dz_tty[ndz]; tp++)
  		ttyprt(tp, tp - dz_tty);

--- 382,388 -----
  	lseek(fc, (long)nl[SNDZ].n_value, 0);
  	read(fc, &ndz, sizeof(ndz));
  	printf("%d dz lines\n", ndz);
! 	lseek(fc, (long)nl[SDZ].n_value, 0);
  	read(fc, dz_tty, sizeof(dz_tty));
  	for (tp = dz_tty; tp < &dz_tty[ndz]; tp++)
  		ttyprt(tp, tp - dz_tty);
***************
*** 395,401
  		nl[SNDH].n_value = clear(nl[SNDH].n_value);
  		nl[SDH].n_value = clear(nl[SDH].n_value);
  	}
! 	kseek(fc, (long)nl[SNDH].n_value, 0);
  	read(fc, &ndz, sizeof(ndz));
  	printf("%d dh lines\n", ndz);
  	kseek(fc, (long)nl[SDH].n_value, 0);

--- 393,399 -----
  		nl[SNDH].n_value = clear(nl[SNDH].n_value);
  		nl[SDH].n_value = clear(nl[SDH].n_value);
  	}
! 	lseek(fc, (long)nl[SNDH].n_value, 0);
  	read(fc, &ndz, sizeof(ndz));
  	printf("%d dh lines\n", ndz);
  	lseek(fc, (long)nl[SDH].n_value, 0);
***************
*** 398,404
  	kseek(fc, (long)nl[SNDH].n_value, 0);
  	read(fc, &ndz, sizeof(ndz));
  	printf("%d dh lines\n", ndz);
! 	kseek(fc, (long)nl[SDH].n_value, 0);
  	read(fc, dz_tty, sizeof(dz_tty));
  	for (tp = dz_tty; tp < &dz_tty[ndz]; tp++)
  		ttyprt(tp, tp - dz_tty);

--- 396,402 -----
  	lseek(fc, (long)nl[SNDH].n_value, 0);
  	read(fc, &ndz, sizeof(ndz));
  	printf("%d dh lines\n", ndz);
! 	lseek(fc, (long)nl[SDH].n_value, 0);
  	read(fc, dz_tty, sizeof(dz_tty));
  	for (tp = dz_tty; tp < &dz_tty[ndz]; tp++)
  		ttyprt(tp, tp - dz_tty);
***************
*** 459,465
  	register i, j, *ip;
  
  	/* This wins only if PAGSIZ > sizeof (struct user) */
! 	kseek(fc, ubase * NBPG, 0);
  	read(fc, &U, sizeof(U));
  	printf("pcb");
  	ip = (int *)&U.u_pcb;

--- 457,463 -----
  	register i, j, *ip;
  
  	/* This wins only if PAGSIZ > sizeof (struct user) */
! 	lseek(fc, ubase * NBPG, 0);
  	read(fc, &U, sizeof(U));
  	printf("pcb");
  	ip = (int *)&U.u_pcb;
***************
*** 589,595
  	nf = 0;
  	nfile = getw(nl[SNFILE].n_value);
  	xfile = (struct file *)calloc(nfile, sizeof (struct file));
! 	kseek(fc, (int)(afile = (struct file *)getw(nl[SFIL].n_value)), 0);
  	read(fc, xfile, nfile * sizeof (struct file));
  	for (fp=xfile; fp < &xfile[nfile]; fp++)
  		if (fp->f_count)

--- 587,593 -----
  	nf = 0;
  	nfile = getw(nl[SNFILE].n_value);
  	xfile = (struct file *)calloc(nfile, sizeof (struct file));
! 	lseek(fc, (int)(afile = (struct file *)getw(nl[SFIL].n_value)), 0);
  	read(fc, xfile, nfile * sizeof (struct file));
  	for (fp=xfile; fp < &xfile[nfile]; fp++)
  		if (fp->f_count)
***************
*** 600,608
  	}
  	printf("%d/%d open files\n", nf, nfile);
  	printf("   LOC   FLG  CNT   INO    OFFS\n");
! 	if(kflg)
! 		afile = (struct file *)clear((int)afile);
! 	for (fp=xfile,loc=(int)afile; fp < &xfile[nfile]; fp++,loc+=sizeof(xfile[0])) {
  		if (fp->f_count==0)
  			continue;
  		printf("%8x ", loc);

--- 598,604 -----
  	}
  	printf("%d/%d open files\n", nf, nfile);
  	printf("   LOC   FLG  CNT   INO    OFFS\n");
! 	for (fp=xfile,loc=nl[SFIL].n_value; fp < &xfile[nfile]; fp++,loc+=sizeof(xfile[0])) {
  		if (fp->f_count==0)
  			continue;
  		printf("%8x ", loc);
***************
*** 630,636
  
  	nproc = getw(nl[SNPROC].n_value);
  	proc = (struct proc *)calloc(nproc, sizeof (struct proc));
! 	kseek(fc, getw(nl[SPROC].n_value), 0);
  	read(fc, proc, nproc * sizeof (struct proc));
  	nswapmap = getw(nl[SNSWAPMAP].n_value);
  	swapmap = (struct map *)calloc(nswapmap, sizeof (struct map));

--- 626,632 -----
  
  	nproc = getw(nl[SNPROC].n_value);
  	proc = (struct proc *)calloc(nproc, sizeof (struct proc));
! 	lseek(fc, getw(nl[SPROC].n_value), 0);
  	read(fc, proc, nproc * sizeof (struct proc));
  	nswapmap = getw(nl[SNSWAPMAP].n_value);
  	swapmap = (struct map *)calloc(nswapmap, sizeof (struct map));
***************
*** 634,640
  	read(fc, proc, nproc * sizeof (struct proc));
  	nswapmap = getw(nl[SNSWAPMAP].n_value);
  	swapmap = (struct map *)calloc(nswapmap, sizeof (struct map));
! 	kseek(fc, getw(nl[SWAPMAP].n_value), 0);
  	read(fc, swapmap, nswapmap * sizeof (struct map));
  	nswap = getw(nl[SNSWAP].n_value);
  	free = 0;

--- 630,636 -----
  	read(fc, proc, nproc * sizeof (struct proc));
  	nswapmap = getw(nl[SNSWAPMAP].n_value);
  	swapmap = (struct map *)calloc(nswapmap, sizeof (struct map));
! 	lseek(fc, getw(nl[SWAPMAP].n_value), 0);
  	read(fc, swapmap, nswapmap * sizeof (struct map));
  	nswap = getw(nl[SNSWAP].n_value);
  	free = 0;
***************
*** 643,649
  		free += me->m_size;
  	ntext = getw(nl[SNTEXT].n_value);
  	xtext = (struct text *)calloc(ntext, sizeof (struct text));
! 	kseek(fc, getw(nl[STEXT].n_value), 0);
  	read(fc, xtext, ntext * sizeof (struct text));
  	tused = 0;
  	for (xp = xtext; xp < &xtext[ntext]; xp++)

--- 639,645 -----
  		free += me->m_size;
  	ntext = getw(nl[SNTEXT].n_value);
  	xtext = (struct text *)calloc(ntext, sizeof (struct text));
! 	lseek(fc, getw(nl[STEXT].n_value), 0);
  	read(fc, xtext, ntext * sizeof (struct text));
  	tused = 0;
  	for (xp = xtext; xp < &xtext[ntext]; xp++)
***************
*** 706,712
  	struct chan chans[NCHANS];
  	struct schan schans[NPORTS];
  
! 	kseek(fc, (long)nl[SCHANS].n_value, 0);
  	read(fc, chans, sizeof chans);
  	kseek(fc, (long)nl[SSCHANS].n_value, 0);
  	read(fc, schans, sizeof schans);

--- 702,708 -----
  	struct chan chans[NCHANS];
  	struct schan schans[NPORTS];
  
! 	lseek(fc, (long)nl[SCHANS].n_value, 0);
  	read(fc, chans, sizeof chans);
  	lseek(fc, (long)nl[SSCHANS].n_value, 0);
  	read(fc, schans, sizeof schans);
***************
*** 708,714
  
  	kseek(fc, (long)nl[SCHANS].n_value, 0);
  	read(fc, chans, sizeof chans);
! 	kseek(fc, (long)nl[SSCHANS].n_value, 0);
  	read(fc, schans, sizeof schans);
  
  	printf("CHAN  FLAGS            INDEX     LINE  GROUP     FILE      TTYP      CTLX      PGRP    OTTYP     OLINE  DATQ      CTLY\n");

--- 704,710 -----
  
  	lseek(fc, (long)nl[SCHANS].n_value, 0);
  	read(fc, chans, sizeof chans);
! 	lseek(fc, (long)nl[SSCHANS].n_value, 0);
  	read(fc, schans, sizeof schans);
  
  	printf("CHAN  FLAGS            INDEX     LINE  GROUP     FILE      TTYP      CTLX      PGRP    OTTYP     OLINE  DATQ      CTLY\n");
***************
*** 778,784
  	struct group *groups[NGROUPS];
  	struct group g;
  
! 	kseek(fc, (long)nl[SGROUP].n_value, 0);
  	read(fc, groups, sizeof groups);
  	printf("GROUP STATE      INDEX     ROT  *GROUP    *INODE    *FILE     ROTM  DATQ\n");
  	for (i = 0; i < NGROUPS; i++) {

--- 774,780 -----
  	struct group *groups[NGROUPS];
  	struct group g;
  
! 	lseek(fc, (long)nl[SGROUP].n_value, 0);
  	read(fc, groups, sizeof groups);
  	printf("GROUP STATE      INDEX     ROT  *GROUP    *INODE    *FILE     ROTM  DATQ\n");
  	for (i = 0; i < NGROUPS; i++) {
***************
*** 784,790
  	for (i = 0; i < NGROUPS; i++) {
  		if (groups[i] == 0)
  			continue;
! 		kseek(fc, (long) groups[i], 0);
  		read(fc, &g, sizeof g);
  		printf("%3d   ", i);
  		printf("%8x  ", g.g_state);

--- 780,786 -----
  	for (i = 0; i < NGROUPS; i++) {
  		if (groups[i] == 0)
  			continue;
! 		lseek(fc, (long) groups[i], 0);
  		read(fc, &g, sizeof g);
  		printf("%3d   ", i);
  		printf("%8x  ", g.g_state);
***************
*** 796,814
  		printf("%3d   ", g.g_rotmask);
  		printf("%3d\n", g.g_datq);
  	}
- }
- 
- /*
-  *	map kernel segment addresses to core dump addresses
-  */
- 
- kseek(fd, offset, whence)
- long	offset;
- {
- 	register long	off;
- 
- 	off = offset;
- 	if(kflg && fd == fc)
- 		off &= 0x7fffffff;
- 	lseek(fd, off, whence);
  }

--- 792,795 -----
  		printf("%3d   ", g.g_rotmask);
  		printf("%3d\n", g.g_datq);
  	}
  }



More information about the Comp.bugs.4bsd.ucb-fixes mailing list