Apurdue.154
net.bugs.4bsd
utcsrgv!utzoo!decvax!pur-ee!purdue!cak
Fri Jan 15 19:14:52 1982
ps -k bugs

We experienced crashes upon converting to 4.1 and wanted to use
ps k to analyze the dumps -- only to find it doesn't work at all.
After much digging through, I determined that ps k ignores the
fact that the addresses found in the namelist, etc. all begin
at 0x80000000, which is way beyond the end of the core dump. The
changes follow:

*** /usr/src/cmd/ps.c   Fri Jan 15 18:48:52 1982
--- /usr/src/cmd/ps.c.v0        Wed Jan 13 13:24:48 1982
***************
*** 223,229
       hz = getw(nl[X_HZ].n_value);
       savcom = (struct savcom *)calloc(nproc, sizeof (*savcom));
       for (i=0; i<NPROC; ! +="8)" - I J="nproc" { (CHAR *)PROCP, (J I; IF 0); KSEEK(KMEM,> 8)
                       j = 8;

--- 223,229 -----
       hz = getw(nl[X_HZ].n_value);
       savcom = (struct savcom *)calloc(nproc, sizeof (*savcom));
       for (i=0; i<NPROC; ! +="8)" - I J="nproc" { (CHAR *)PROCP, LSEEK(KMEM, (J I; IF 0);> 8)
                       j = 8;
***************
*** 228,234
               if (j > 8)
                       j = 8;
               j *= sizeof (struct proc);
!               if ( read(kmem, (char *)proc, j) != j){
                       cantread("proc table", kmemf);
                       exit(1);
               }

--- 228,234 -----
               if (j > 8)
                       j = 8;
               j *= sizeof (struct proc);
!               if (read(kmem, (char *)proc, j) != j)
                       cantread("proc table", kmemf);
               procp += j;
               for (j = j / sizeof (struct proc) - 1; j >= 0; j--) {
***************
*** 230,237
               j *= sizeof (struct proc);
               if ( read(kmem, (char *)proc, j) != j){
                       cantread("proc table", kmemf);
-                       exit(1);
-               }
               procp += j;
               for (j = j / sizeof (struct proc) - 1; j >= 0; j--) {
                       mproc = &proc[j];

--- 230,235 -----
               j *= sizeof (struct proc);
               if (read(kmem, (char *)proc, j) != j)
                       cantread("proc table", kmemf);
               procp += j;
               for (j = j / sizeof (struct proc) - 1; j >= 0; j--) {
                       mproc = &proc[j];
***************
*** 289,295
 {
       long word;

!       kseek(kmem, loc, 0);
       if (read(kmem, &word, sizeof (word)) != sizeof (word))
               printf("error reading kmem at %x\n", loc);
       return (word);

--- 287,293 -----
 {
       long word;

!       lseek(kmem, loc, 0);
       if (read(kmem, &word, sizeof (word)) != sizeof (word))
               printf("error reading kmem at %x\n", loc);
       return (word);
***************
*** 330,336
       char **argv;
 {
       register struct nlist *nlp;
- int i;

       nlistf = argc > 3 ? argv[3] : "/vmunix";
       nlist(nlistf, nl);

--- 328,333 -----
       char **argv;
 {
       register struct nlist *nlp;

       nlistf = argc > 3 ? argv[3] : "/vmunix";
       nlist(nlistf, nl);
***************
*** 343,349
                       nlp->n_value = clear(nlp->n_value);
       Usrptma = (struct pte *)nl[X_USRPTMA].n_value;
       usrpt = (struct pte *)nl[X_USRPT].n_value;
!       kseek(kmem, (long)nl[X_NSWAP].n_value, 0);
       if (read(kmem, &nswap, sizeof (nswap)) != sizeof (nswap)) {
               cantread("nswap", kmemf);
               exit(1);

--- 340,346 -----
                       nlp->n_value = clear(nlp->n_value);
       Usrptma = (struct pte *)nl[X_USRPTMA].n_value;
       usrpt = (struct pte *)nl[X_USRPT].n_value;
!       lseek(kmem, (long)nl[X_NSWAP].n_value, 0);
       if (read(kmem, &nswap, sizeof (nswap)) != sizeof (nswap)) {
               cantread("nswap", kmemf);
               exit(1);
***************
*** 348,354
               cantread("nswap", kmemf);
               exit(1);
       }
!       kseek(kmem, (long)nl[X_MAXSLP].n_value, 0);
       if (read(kmem, &maxslp, sizeof (maxslp)) != sizeof (maxslp)) {
               cantread("maxslp", kmemf);
               exit(1);

--- 345,351 -----
               cantread("nswap", kmemf);
               exit(1);
       }
!       lseek(kmem, (long)nl[X_MAXSLP].n_value, 0);
       if (read(kmem, &maxslp, sizeof (maxslp)) != sizeof (maxslp)) {
               cantread("maxslp", kmemf);
               exit(1);
***************
*** 353,359
               cantread("maxslp", kmemf);
               exit(1);
       }
!       kseek(kmem, (long)nl[X_CCPU].n_value, 0);
       if (read(kmem, &ccpu, sizeof (ccpu)) != sizeof (ccpu)) {
               cantread("ccpu", kmemf);
               exit(1);

--- 350,356 -----
               cantread("maxslp", kmemf);
               exit(1);
       }
!       lseek(kmem, (long)nl[X_CCPU].n_value, 0);
       if (read(kmem, &ccpu, sizeof (ccpu)) != sizeof (ccpu)) {
               cantread("ccpu", kmemf);
               exit(1);
***************
*** 358,364
               cantread("ccpu", kmemf);
               exit(1);
       }
!       kseek(kmem, (long)nl[X_ECMX].n_value, 0);
       if (read(kmem, &ecmx, sizeof (ecmx)) != sizeof (ecmx)) {
               cantread("ecmx", kmemf);
               exit(1);

--- 355,361 -----
               cantread("ccpu", kmemf);
               exit(1);
       }
!       lseek(kmem, (long)nl[X_ECMX].n_value, 0);
       if (read(kmem, &ecmx, sizeof (ecmx)) != sizeof (ecmx)) {
               cantread("ecmx", kmemf);
               exit(1);
***************
*** 371,377
                       exit(1);
               }
               atext = (struct text *)getw(nl[X_TEXT].n_value);
!               kseek(kmem, (int)atext, 0);
               if (read(kmem, (char *)text, ntext * sizeof (struct text))
                   != ntext * sizeof (struct text)) {
                       cantread("text table", kmemf);

--- 368,374 -----
                       exit(1);
               }
               atext = (struct text *)getw(nl[X_TEXT].n_value);
!               lseek(kmem, (int)atext, 0);
               if (read(kmem, (char *)text, ntext * sizeof (struct text))
                   != ntext * sizeof (struct text)) {
                       cantread("text table", kmemf);
***************
*** 400,406
       char *what, *fromwhat;
 {

!       fprintf(stderr, "ps: error reading %s from %s\n", what, fromwhat);
 }

 struct        direct dbuf;

--- 397,403 -----
       char *what, *fromwhat;
 {

!       fprintf(stderr, "ps: error reading %s from %s", what, fromwhat);
 }

 struct        direct dbuf;
***************
*** 701,707

       size = sflg ? ctob(UPAGES) : sizeof (struct user);
       if ((mproc->p_flag & SLOAD) == 0) {
!               kseek(swap, ctob(mproc->p_swaddr), 0);
               if (read(swap, (char *)&user.user, size) != size) {
                       fprintf(stderr, "ps: cant read u for pid %d from %s\n",
                           mproc->p_pid, swapf);

--- 698,704 -----

       size = sflg ? ctob(UPAGES) : sizeof (struct user);
       if ((mproc->p_flag & SLOAD) == 0) {
!               lseek(swap, ctob(mproc->p_swaddr), 0);
               if (read(swap, (char *)&user.user, size) != size) {
                       fprintf(stderr, "ps: cant read u for pid %d from %s\n",
                           mproc->p_pid, swapf);
***************
*** 711,719
               argaddr = 0;
               return (1);
       }
!       pteaddr = &Usrptma[btokmx(kflg?(struct pte *)clear(mproc->p_p0br):
!                                       mproc->p_p0br) + mproc->p_szpt - 1];
!       kseek(kmem, (long)pteaddr, 0);
       if (read(kmem, (char *)&apte, sizeof(apte)) != sizeof(apte)) {
               printf("ps: cant read indir pte to get u for pid %d from %s\n",
                   mproc->p_pid, swapf);

--- 708,715 -----
               argaddr = 0;
               return (1);
       }
!       pteaddr = &Usrptma[btokmx(mproc->p_p0br) + mproc->p_szpt - 1];
!       lseek(kmem, kflg ? clear(pteaddr) : (int)pteaddr, 0);
       if (read(kmem, (char *)&apte, sizeof(apte)) != sizeof(apte)) {
               printf("ps: cant read indir pte to get u for pid %d from %s\n",
                   mproc->p_pid, swapf);
***************
*** 719,725
                   mproc->p_pid, swapf);
               return (0);
       }
!       kseek(mem,
           ctob(apte.pg_pfnum+1) - (UPAGES+CLSIZE) * sizeof (struct pte), 0);
       if (read(mem, (char *)arguutl, sizeof(arguutl)) != sizeof(arguutl)) {
               printf("ps: cant read page table for u of pid %d from %s\n",

--- 715,721 -----
                   mproc->p_pid, swapf);
               return (0);
       }
!       lseek(mem,
           ctob(apte.pg_pfnum+1) - (UPAGES+CLSIZE) * sizeof (struct pte), 0);
       if (read(mem, (char *)arguutl, sizeof(arguutl)) != sizeof(arguutl)) {
               printf("ps: cant read page table for u of pid %d from %s\n",
***************
*** 734,740
       ncl = (size + NBPG*CLSIZE - 1) / (NBPG*CLSIZE);
       while (--ncl >= 0) {
               i = ncl * CLSIZE;
!               kseek(mem, ctob(arguutl[CLSIZE+i].pg_pfnum), 0);
               if (read(mem, user.upages[i], CLSIZE*NBPG) != CLSIZE*NBPG) {
                       printf("ps: cant read page %d of u of pid %d from %s\n",
                           arguutl[CLSIZE+i].pg_pfnum, mproc->p_pid, memf);

--- 730,736 -----
       ncl = (size + NBPG*CLSIZE - 1) / (NBPG*CLSIZE);
       while (--ncl >= 0) {
               i = ncl * CLSIZE;
!               lseek(mem, ctob(arguutl[CLSIZE+i].pg_pfnum), 0);
               if (read(mem, user.upages[i], CLSIZE*NBPG) != CLSIZE*NBPG) {
                       printf("ps: cant read page %d of u of pid %d from %s\n",
                           arguutl[CLSIZE+i].pg_pfnum, mproc->p_pid, memf);
***************
*** 768,774
       }
       if ((mproc->p_flag & SLOAD) == 0 || argaddr == 0) {
               vstodb(0, CLSIZE, &u.u_smap, &db, 1);
!               kseek(swap, ctob(db.db_base), 0);
               if (read(swap, (char *)&argspac, sizeof(argspac))
                   != sizeof(argspac))
                       goto bad;

--- 764,770 -----
       }
       if ((mproc->p_flag & SLOAD) == 0 || argaddr == 0) {
               vstodb(0, CLSIZE, &u.u_smap, &db, 1);
!               lseek(swap, ctob(db.db_base), 0);
               if (read(swap, (char *)&argspac, sizeof(argspac))
                   != sizeof(argspac))
                       goto bad;
***************
*** 773,779
                   != sizeof(argspac))
                       goto bad;
       } else {
!               kseek(mem, argaddr, 0);
               if (read(mem, (char *)&argspac, sizeof (argspac))
                   != sizeof (argspac))
                       goto bad;

--- 769,775 -----
                   != sizeof(argspac))
                       goto bad;
       } else {
!               lseek(mem, argaddr, 0);
               if (read(mem, (char *)&argspac, sizeof (argspac))
                   != sizeof (argspac))
                       goto bad;
***************
*** 1115,1134
       dp = (char *)alloc(len+1);
       strcpy(dp, cp);
       return (dp);
- }
-
- /*
-  *    make sure the addresses are reasonable when using the
-  *    k flag for post mortem debugging.  cak 1/14/82
-  */
-
- kseek(fd, offset, whence)
- int   fd;
- long  offset;
- int   whence;
- {
-       if(kflg && (fd == kmem))
-               offset = (long)clear(offset);
-
-       lseek(fd, offset, whence);
 }

--- 1111,1114 -----
       dp = (char *)alloc(len+1);
       strcpy(dp, cp);
       return (dp);
 }

 Chris Kent

-----------------------------------------------------------------
gopher://quux.org/ conversion by John Goerzen <[email protected]>
of http://communication.ucsd.edu/A-News/


This Usenet Oldnews Archive
article may be copied and distributed freely, provided:

1. There is no money collected for the text(s) of the articles.

2. The following notice remains appended to each copy:

The Usenet Oldnews Archive: Compilation Copyright (C) 1981, 1996
Bruce Jones, Henry Spencer, David Wiseman.