|
|
1.1 root 1: /*
2: * These macros are used to speak ``offsets'' to the outside world,
3: * so that we can use the other source files for sdb essentially
4: * unchanged, even though they believe that we work with symbol
5: * table offsets, and we really have the whole symbol table in
6: * core and would prefer to just work with pointers into it.
7: */
8: #define sptooff(sp) (ststart + (int)(sp) - (int)(symtab))
9: #define offtosp(off) (&symtab[((off) - ststart) / sizeof (struct nlist))
10:
11: /*
12: * Initialize the file and procedure tables.
13: *
14: * This routine rummages through the symbol table and builds tables
15: * of the files and procedures referenced there, sorting the latter
16: * table into address order. These tables are used in the other
17: * routines defined here.
18: *
19: * NB:
20: *
21: * In this version of sdb we could well dispense with most of the
22: * fields of these tables, since we have the symbol table in core,
23: * but for compatibility for the time being we duplicate the information
24: * so older code in other sdb files will work unchanged.
25: */
26: initfp()
27: {
28: register struct nlist *sp;
29: register struct proct *procp;
30: register struct filet *filep;
31: struct stat stb;
32: int nfile, nproc;
33: int class;
34: extern int compar(); /* Sort routine for procedure table */
35:
36: firstdata = MAXPOS;
37: /*
38: * Since the symbol table is in core, we can afford
39: * two passes over it to avoid messy allocation strategies
40: * for these tables, who sizes are as yet unknown.
41: */
42: nfile = 0;
43: nproc = 0;
44: for (sp = symtab; sp < esymtab; sp++) switch (sp->n_type & STABMASK) {
45:
46: case N_SO:
47: case N_SOL:
48: nfile++;
49: continue;
50: case N_TEXT:
51: if (sp->n_name[0] == '_')
52: nfile++;
53: continue;
54: case N_FUN:
55: case N_ENTRY:
56: nfile++;
57: continue;
58: }
59: files = calloc(nfile+1, sizeof (struct filet));
60: procs = calloc(nfile+1, sizeof (struct filet));
61: if (files == 0 || procs == 0) {
62: printf("Couldn't get space for file/procedure tables\n");
63: exit(1);
64: }
65: if (nfiles == 0)
66: printf("Warning: `%s' not compiled with -g\n", symfil);
67: procp = procs;
68: filep = files;
69: for (sp = symtab; sp < esymtab; sp++) {
70: class = sp->n_type & STABMASK;
71: switch (class) {
72:
73: case N_SO:
74: case N_SOL:
75: filep->faddr = sp->n_value;
76: filep->lineflag = (class == N_SOL);
77: filep->stf_offset = sptooff(sp);
78: filep->sfilename = sp->n_name;
79: strcpy(fp, filep->sfilename);
80: if (stat(filework, &stb) == -1)
81: printf("Warning: `%s' not found\n",
82: filep->sfilename);
83: else if (stb.st_mtime > symtime)
84: printf("Warning: `%s' newer than `%s'\n",
85: filep->sfilename, symfil);
86: filep++;
87: break;
88:
89: case N_TEXT:
90: if (stentry.n_name[0] != '_')
91: break;
92: case N_FUN:
93: case N_ENTRY:
94: procp->pname = sp->n_name;
95: procp->paddr = sp->n_value;
96: procp->st_offset = sptooff(sp);
97: if (class != N_TEXT) {
98: procp->sfptr = filep - 1;
99: procp->lineno = so->n_desc;
100: } else {
101: procp->sfptr = badfile;
102: procp->lineno = 0;
103: }
104: procp->entrypt = class == N_ENTRY;
105: procp++;
106: break;
107: }
108: if (sp->n_type & N_EXT) {
109: if (!extstart)
110: extstart = sp;
111: /* THIS LOOKS WRONG !!! SHOULD BE (x || y) && z ??? */
112: if (sp->n_type == (N_DATA+N_EXT) ||
113: sp->n_type == (N_BSS+N_EXT) ||
114: sp->n_value < firstdata)
115: firstdata = sp->n_value;
116: }
117: }
118: if (filep != &files[nfile] || procp != &procs[nproc]) {
119: printf("initfp botch - tell someone\n");
120: exit(1);
121: }
122: /*
123: * Now have the file and procedure tables.
124: * Sort the procedure table, and initialize the boundary
125: * elements of the tables.
126: */
127: qsort(procs, procp-procs, sizeof procs[0], compar);
128: badproc = procp;
129: badfile = filep;
130: badproc->st_offset = esymtab;
131: badproc->sfptr = badfile;
132: badproc->pname = badfile->sfilename = "";
133: setcur(1);
134: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.