|
|
1.1 root 1: /*%cc -o coreid -s -n -O %
2: *
3: * coreid [corefile] - display arguments of program that dumped core
4: *
5: */
6: #include <stdio.h>
7: #include <sys/param.h>
8: #include <sys/dir.h>
9: #include <sys/user.h>
10: #define U(x) (int)(&(((struct user *)0)->x))
11: #define BYTESPERCLICK 512
12: #define HSIZE (UPAGES*512L)
13: #define FPOFFSET (HSIZE-0120)
14: #define APOFFSET (HSIZE-0124)
15: int coref;
16: char *core="core";
17: int value;
18: char cvalue;
19: unsigned enddata, startdata;
20: int nchars;
21: long lseek();
22: main(argc, argv)
23: char *argv[];
24: {
25: register fp, av, ap;
26: if(argc > 1)
27: core=argv[1];
28: coref=open(core, 0);
29: if(coref < 0){
30: fprintf(stderr, "coreid: can't open %s\n", core);
31: exit(1);
32: }
33: Hseek(U(u_tsize));
34: Read();
35: startdata=value*BYTESPERCLICK; /* address after text */
36: Read();
37: enddata=startdata+value*BYTESPERCLICK; /* after data & bss */
38: Hseek(APOFFSET);
39: Read();
40: ap=value;
41: Hseek(FPOFFSET);
42: Read();
43: fp=value;
44: for(;;){
45: Seek(fp+12);
46: Read();
47: if(value<fp)
48: break;
49: Seek(fp+8);
50: fp=value;
51: Read();
52: ap=value;
53: }
54: av=ap+16;
55: for(;;){
56: Seek(av);
57: Read();
58: if(value==0)
59: break;
60: string();
61: av+=sizeof(char *);
62: }
63: if(nchars==0)
64: badcore();
65: putchar('\n');
66: }
67: Hseek(loc)
68: register loc;
69: {
70: if(lseek(coref, (long)loc, 0)==-1L)
71: badcore();
72: }
73: Seek(loc)
74: register loc;
75: {
76: if(loc > enddata){
77: if(lseek(coref, (loc|0x80000000)+HSIZE, 2)==-1L)
78: badcore();
79: }else if(lseek(coref, (unsigned)loc-startdata+HSIZE, 0)==-1L)
80: badcore();
81: }
82: Read()
83: {
84: if(read(coref, &value, sizeof (int))!=sizeof (int))
85: badcore();
86: }
87: Readc()
88: {
89: if(read(coref, &cvalue, 1)!=1)
90: badcore();
91: }
92: string()
93: {
94: Seek(value);
95: do{
96: Readc();
97: if(cvalue){
98: putchar(cvalue);
99: nchars++;
100: }
101: }while(cvalue);
102: putchar(' ');
103: }
104: badcore()
105: {
106: char buf[DIRSIZ+1];
107: if(lseek(coref, U(u_comm[0]), 0)!=-1 && read(coref, buf, DIRSIZ)==DIRSIZ){
108: buf[DIRSIZ+1]=0;
109: printf("(%s)\n", buf);
110: exit(0);
111: }
112: fprintf(stderr, "coreid: bad core file `%s'\n", core);
113: exit(1);
114: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.