home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / c / condor40.zip / CONDOR / src / condor_tools / prtsegmap.c < prev    next >
C/C++ Source or Header  |  1989-06-06  |  4KB  |  149 lines

  1. /* 
  2. ** Copyright 1986, 1987, 1988, 1989 University of Wisconsin
  3. ** 
  4. ** Permission to use, copy, modify, and distribute this software and its
  5. ** documentation for any purpose and without fee is hereby granted,
  6. ** provided that the above copyright notice appear in all copies and that
  7. ** both that copyright notice and this permission notice appear in
  8. ** supporting documentation, and that the name of the University of
  9. ** Wisconsin not be used in advertising or publicity pertaining to
  10. ** distribution of the software without specific, written prior
  11. ** permission.  The University of Wisconsin makes no representations about
  12. ** the suitability of this software for any purpose.  It is provided "as
  13. ** is" without express or implied warranty.
  14. ** 
  15. ** THE UNIVERSITY OF WISCONSIN DISCLAIMS ALL WARRANTIES WITH REGARD TO
  16. ** THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. ** FITNESS. IN NO EVENT SHALL THE UNIVERSITY OF WISCONSIN  BE LIABLE FOR
  18. ** ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19. ** WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  20. ** ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  21. ** OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22. ** 
  23. ** Authors:  Allan Bricker and Michael J. Litzkow,
  24. **              University of Wisconsin, Computer Sciences Dept.
  25. ** 
  26. */ 
  27. #include <stdio.h>
  28. #include <sys/signal.h>
  29. #include <sys/types.h>
  30. #include <sys/param.h>
  31.  
  32. #include <sys/file.h>
  33. #include <netinet/in.h>
  34.  
  35. #if defined(ultrix) || defined(ibm032)
  36. #include <sys/dir.h>
  37. #endif defined(ultrix) || defined(ibm032)
  38.  
  39. #include <sys/user.h>
  40.  
  41. #if defined(sun)
  42. #include <sys/core.h>
  43.  
  44. static struct core C;
  45. #if defined(SUNOS40)
  46. int StackOffset;
  47. #endif defined(SUNOS40)
  48. #endif defined(sun)
  49.  
  50. #include "condor_sys.h"
  51. #include "trace.h"
  52. #include "ckpt.h"
  53. #include "machdep.h"
  54. #include "except.h"
  55. #include "debug.h"
  56. #include "clib.h"
  57.  
  58. static char *_FileName_ = __FILE__;        /* Used by EXCEPT (see except.h)     */
  59.  
  60. main( argc, argv )
  61. int argc;
  62. char **argv;
  63. {
  64.     CKPTMAP cm;
  65.     int fd;
  66.  
  67.     printf("sizeof(CKPTMAP) = %d\n", sizeof(CKPTMAP));
  68.  
  69.     if( argc < 2 ) {
  70.         fprintf(stderr, "Usage: %s ckptfile [...]\n", *argv );
  71.         exit( 1 );
  72.     }
  73.  
  74.     while( *++argv ) {
  75.         fd = open( *argv, O_RDONLY, 0 );
  76.         if( fd < 0 ) {
  77.             perror(*argv);
  78.             continue;
  79.         }
  80.  
  81.         if( readsegmap( fd, &cm ) >= 0 ) {
  82.             dumpsegmap( &cm, *argv );
  83.         }
  84.  
  85.         (void) close( fd );
  86.     }
  87. }
  88.  
  89. #define TO_HOST_ORDER(i) (int) ntohl( (u_long)i ) 
  90.  
  91. readsegmap( fd, cmp )
  92. int fd;
  93. register CKPTMAP *cmp;
  94. {
  95.     int i;
  96.  
  97.     if( lseek(fd, -sizeof(CKPTMAP), L_XTND) < 0 ) {
  98.         perror("lseek(fd, -sizeof(CKPTMAP), L_XTND)");
  99.         return( -1 );
  100.     }
  101.  
  102.     if( read(fd, (char *) cmp, sizeof(CKPTMAP)) != sizeof(CKPTMAP) ) {
  103.         perror("read cmp");
  104.         return( -1 );
  105.     }
  106.  
  107.     for( i = 0; i < NCKPTSEGS; i++ ) {
  108.         cmp->cm_segs[i].cs_pos = TO_HOST_ORDER(cmp->cm_segs[i].cs_pos);
  109.         cmp->cm_segs[i].cs_len = TO_HOST_ORDER(cmp->cm_segs[i].cs_len);
  110.     }
  111. }
  112.  
  113. static char *segnames[] = {
  114.     "TEXT:   ",
  115.     "DATA:   ",
  116.     "T_RELOC:",
  117.     "D_RELOC:",
  118.     "SYMS:   ",
  119.     "STRTAB: ",
  120.     "STACK:  ",
  121.     "JOB:    ",
  122.     "SEGMAP: "
  123. };
  124.  
  125. static
  126. dumpsegmap( segmap, name )
  127. CKPTMAP *segmap;
  128. char *name;
  129. {
  130.     int i;
  131.  
  132.     printf("\t\t%s\n", name);
  133.  
  134.     for( i = 0; i < NCKPTSEGS; i++ ) {
  135.         dumpseg( &segmap->cm_segs[i], segnames[i] );
  136.     }
  137. }
  138.  
  139. static
  140. dumpseg( seg, name )
  141. CKPTSEG *seg;
  142. char *name;
  143. {
  144.     printf("Segment %s fd %2d, pos %6d (0x%x),\n",
  145.                 name, seg->cs_fd, seg->cs_pos, seg->cs_pos);
  146.     printf("                        len %6d (0x%x)\n",
  147.                 seg->cs_len, seg->cs_len );
  148. }
  149.