home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume3 / sps / part1 / initsymbols.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  2.9 KB  |  90 lines

  1. # include       "sps.h"
  2. # include       "flags.h"
  3. # ifdef BSD42
  4. # include       <sys/file.h>
  5. # endif
  6. # include       <nlist.h>
  7. # include       <stdio.h>
  8.  
  9. /* INITSYMBOLS - Reads kmem values into the Info structure */
  10. /*
  11. ** THIS CODE COPIES KMEM VALUES INTO THE INFO STRUCTURE ASSUMING THAT
  12. ** VALUES READ FROM THE KERNEL HAVE TYPE CADDR_T. THEREFORE, WE ARE
  13. ** MAKING THE DUBIOUS ASSUMPTION THAT INTS, POINTERS AND CADDR_T's
  14. ** HAVE IDENTICAL SIZES.
  15. */
  16. initsymbols ()
  17. {
  18.     register struct nlist   *np ;
  19.     register struct symbol  *s ;
  20.     register struct nlist   *np0 ;
  21.     char                    *filesymbol ;
  22.     extern int              Flkmem ;
  23.     extern struct flags     Flg ;
  24.     extern struct symbol    Symbollist[] ;
  25.     extern struct info      Info ;
  26.     char                    *getcore() ;
  27.     char                    *strncpy() ;
  28.  
  29.     filesymbol = Flg.flg_s ? Flg.flg_s : FILE_SYMBOL ;
  30.     /* Find the length of the symbol table */
  31.     for ( s = Symbollist ; s->s_kname ; s++ )
  32.         ;
  33.     /* Construct an nlist structure by copying names from the symbol table*/
  34.     np0 = (struct nlist*)getcore( (s-Symbollist+1)*sizeof( struct nlist ) );
  35.     for ( s = Symbollist, np = np0 ; s->s_kname ; s++, np++ )
  36.     {                                       
  37.         np->n_name = s->s_kname ;       
  38.         np[1].n_name = (char*)0 ;       
  39.         np->n_value = 0 ;
  40.     }
  41. # ifdef BSD42
  42.     if ( access( filesymbol, R_OK ) < 0 )
  43. # else
  44.     if ( access( filesymbol, 4 ) < 0 )
  45. # endif
  46.     {
  47.         fprintf( stderr, "sps - Can't open symbol file %s", filesymbol);
  48.         sysperror() ;
  49.     }
  50.     /* Get kernel addresses */
  51.     nlist( filesymbol, np0 ) ;              
  52.     if ( np0[0].n_value == -1 )
  53.     {
  54.         fprintf( stderr, "sps - Can't read symbol file %s", filesymbol);
  55.         sysperror() ;
  56.     }
  57.     for ( s = Symbollist, np = np0 ; s->s_kname ; s++, np++ )
  58.     {                                       
  59.         if ( !np->n_value )             
  60.         {
  61.             fprintf( stderr, "sps - Can't find symbol %s in %s",
  62.                 np->n_name, filesymbol ) ;
  63.             /* Assume this error to be unimportant if the address
  64.                is only associated with a process wait state.
  65.                This may happen if the system has been configured
  66.                without a particular device. */
  67.             fprintf( stderr, &Info.i_waitstate[ 0 ] <= s->s_info
  68.                 && s->s_info < &Info.i_waitstate[ NWAITSTATE ]
  69.                 ? " (error is not serious)\n"
  70.                 : " (ERROR MAY BE SERIOUS)\n" ) ;
  71.             *s->s_info = (caddr_t)0 ;
  72.             continue ;
  73.         }
  74.         /* If no indirection is required, just copy the obtained value
  75.            into the `Info' structure. */
  76.         if ( !s->s_indirect )           
  77.         {                               
  78.         /* DUBIOUS ASSUMPTION THAT KMEM VALUE HAS SIZE OF A CADDR_T */
  79.             *s->s_info = (caddr_t)np->n_value ;
  80.             continue ;              
  81.         }                               
  82.         /* Otherwise one level of indirection is required. Using the
  83.            obtained address, look again in the kernel for the value */
  84.         memseek( Flkmem, (long)np->n_value ) ;
  85.         /* DUBIOUS ASSUMPTION THAT KMEM VALUE HAS SIZE OF A CADDR_T */
  86.         (void)read( Flkmem, (char*)s->s_info, sizeof(caddr_t) ) ;
  87.     }
  88.     free( (char*)np0 ) ;
  89. }
  90.