Commit | Line | Data |
---|---|---|
d07734e3 | 1 | /* Support routines for building symbol tables in GDB's internal format. |
93297ea0 JG |
2 | Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992 |
3 | Free Software Foundation, Inc. | |
c0302457 JG |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
20 | ||
21 | /* This module provides subroutines used for creating and adding to | |
22 | the symbol table. These routines are called from various symbol- | |
d07734e3 | 23 | file-reading routines. |
c0302457 | 24 | |
d07734e3 FF |
25 | Routines to support specific debugging information formats (stabs, |
26 | DWARF, etc) belong somewhere else. */ | |
c0302457 JG |
27 | |
28 | #include "defs.h" | |
d07734e3 | 29 | #include "bfd.h" |
c0302457 JG |
30 | #include "obstack.h" |
31 | #include "symtab.h" | |
c0302457 | 32 | #include "symfile.h" /* Needed for "struct complaint" */ |
5e2e79f8 | 33 | #include "objfiles.h" |
c0302457 | 34 | #include <string.h> |
c0302457 JG |
35 | |
36 | /* Ask buildsym.h to define the vars it normally declares `extern'. */ | |
37 | #define EXTERN /**/ | |
38 | #include "buildsym.h" /* Our own declarations */ | |
39 | #undef EXTERN | |
40 | ||
1ab3bf1b JG |
41 | static int |
42 | compare_line_numbers PARAMS ((const void *, const void *)); | |
43 | ||
44 | static struct blockvector * | |
45 | make_blockvector PARAMS ((struct objfile *)); | |
46 | ||
1ab3bf1b | 47 | \f |
4137c5fc JG |
48 | /* Initial sizes of data structures. These are realloc'd larger if needed, |
49 | and realloc'd down to the size actually used, when completed. */ | |
50 | ||
51 | #define INITIAL_CONTEXT_STACK_SIZE 10 | |
4137c5fc | 52 | #define INITIAL_LINE_VECTOR_LENGTH 1000 |
d07734e3 | 53 | |
c0302457 JG |
54 | \f |
55 | /* Complaints about the symbols we have encountered. */ | |
56 | ||
57 | struct complaint innerblock_complaint = | |
58 | {"inner block not inside outer block in %s", 0, 0}; | |
59 | ||
76512886 JG |
60 | struct complaint innerblock_anon_complaint = |
61 | {"inner block not inside outer block", 0, 0}; | |
62 | ||
c0302457 | 63 | struct complaint blockvector_complaint = |
76512886 | 64 | {"block at 0x%x out of order", 0, 0}; |
c0302457 | 65 | |
c0302457 JG |
66 | \f |
67 | /* maintain the lists of symbols and blocks */ | |
68 | ||
69 | /* Add a symbol to one of the lists of symbols. */ | |
d07734e3 | 70 | |
c0302457 JG |
71 | void |
72 | add_symbol_to_list (symbol, listhead) | |
73 | struct symbol *symbol; | |
74 | struct pending **listhead; | |
75 | { | |
d07734e3 FF |
76 | register struct pending *link; |
77 | ||
c0302457 JG |
78 | /* We keep PENDINGSIZE symbols in each link of the list. |
79 | If we don't have a link with room in it, add a new link. */ | |
d07734e3 | 80 | if (*listhead == NULL || (*listhead)->nsyms == PENDINGSIZE) |
c0302457 | 81 | { |
c0302457 JG |
82 | if (free_pendings) |
83 | { | |
84 | link = free_pendings; | |
85 | free_pendings = link->next; | |
86 | } | |
87 | else | |
d07734e3 FF |
88 | { |
89 | link = (struct pending *) xmalloc (sizeof (struct pending)); | |
90 | } | |
c0302457 JG |
91 | |
92 | link->next = *listhead; | |
93 | *listhead = link; | |
94 | link->nsyms = 0; | |
95 | } | |
96 | ||
97 | (*listhead)->symbol[(*listhead)->nsyms++] = symbol; | |
98 | } | |
99 | ||
a048c8f5 | 100 | /* Find a symbol on a pending list. */ |
d07734e3 | 101 | |
a048c8f5 JG |
102 | struct symbol * |
103 | find_symbol_in_list (list, name, length) | |
104 | struct pending *list; | |
105 | char *name; | |
106 | int length; | |
107 | { | |
108 | int j; | |
d07734e3 | 109 | char *pp; |
a048c8f5 | 110 | |
d07734e3 FF |
111 | while (list != NULL) |
112 | { | |
113 | for (j = list->nsyms; --j >= 0; ) | |
114 | { | |
115 | pp = SYMBOL_NAME (list->symbol[j]); | |
116 | if (*pp == *name && strncmp (pp, name, length) == 0 && | |
117 | pp[length] == '\0') | |
118 | { | |
119 | return (list->symbol[j]); | |
120 | } | |
121 | } | |
122 | list = list->next; | |
a048c8f5 | 123 | } |
d07734e3 | 124 | return (NULL); |
a048c8f5 JG |
125 | } |
126 | ||
c0302457 | 127 | /* At end of reading syms, or in case of quit, |
d07734e3 | 128 | really free as many `struct pending's as we can easily find. */ |
c0302457 JG |
129 | |
130 | /* ARGSUSED */ | |
131 | void | |
132 | really_free_pendings (foo) | |
133 | int foo; | |
134 | { | |
135 | struct pending *next, *next1; | |
136 | #if 0 | |
137 | struct pending_block *bnext, *bnext1; | |
138 | #endif | |
139 | ||
140 | for (next = free_pendings; next; next = next1) | |
141 | { | |
142 | next1 = next->next; | |
84ffdec2 | 143 | free ((PTR)next); |
c0302457 | 144 | } |
d07734e3 | 145 | free_pendings = NULL; |
c0302457 JG |
146 | |
147 | #if 0 /* Now we make the links in the symbol_obstack, so don't free them. */ | |
148 | for (bnext = pending_blocks; bnext; bnext = bnext1) | |
149 | { | |
150 | bnext1 = bnext->next; | |
84ffdec2 | 151 | free ((PTR)bnext); |
c0302457 JG |
152 | } |
153 | #endif | |
d07734e3 | 154 | pending_blocks = NULL; |
c0302457 | 155 | |
d07734e3 | 156 | for (next = file_symbols; next != NULL; next = next1) |
c0302457 JG |
157 | { |
158 | next1 = next->next; | |
84ffdec2 | 159 | free ((PTR)next); |
c0302457 | 160 | } |
d07734e3 | 161 | file_symbols = NULL; |
c0302457 | 162 | |
d07734e3 | 163 | for (next = global_symbols; next != NULL; next = next1) |
c0302457 JG |
164 | { |
165 | next1 = next->next; | |
84ffdec2 | 166 | free ((PTR)next); |
c0302457 | 167 | } |
d07734e3 | 168 | global_symbols = NULL; |
c0302457 JG |
169 | } |
170 | ||
171 | /* Take one of the lists of symbols and make a block from it. | |
172 | Keep the order the symbols have in the list (reversed from the input file). | |
173 | Put the block on the list of pending blocks. */ | |
174 | ||
175 | void | |
1ab3bf1b | 176 | finish_block (symbol, listhead, old_blocks, start, end, objfile) |
c0302457 JG |
177 | struct symbol *symbol; |
178 | struct pending **listhead; | |
179 | struct pending_block *old_blocks; | |
180 | CORE_ADDR start, end; | |
1ab3bf1b | 181 | struct objfile *objfile; |
c0302457 JG |
182 | { |
183 | register struct pending *next, *next1; | |
184 | register struct block *block; | |
185 | register struct pending_block *pblock; | |
186 | struct pending_block *opblock; | |
187 | register int i; | |
d07734e3 | 188 | register int j; |
c0302457 JG |
189 | |
190 | /* Count the length of the list of symbols. */ | |
191 | ||
d07734e3 FF |
192 | for (next = *listhead, i = 0; next; i += next->nsyms, next = next->next) |
193 | { | |
194 | /*EMPTY*/; | |
195 | } | |
c0302457 | 196 | |
1ab3bf1b | 197 | block = (struct block *) obstack_alloc (&objfile -> symbol_obstack, |
a048c8f5 | 198 | (sizeof (struct block) + ((i - 1) * sizeof (struct symbol *)))); |
c0302457 JG |
199 | |
200 | /* Copy the symbols into the block. */ | |
201 | ||
202 | BLOCK_NSYMS (block) = i; | |
203 | for (next = *listhead; next; next = next->next) | |
204 | { | |
c0302457 | 205 | for (j = next->nsyms - 1; j >= 0; j--) |
d07734e3 FF |
206 | { |
207 | BLOCK_SYM (block, --i) = next->symbol[j]; | |
208 | } | |
c0302457 JG |
209 | } |
210 | ||
211 | BLOCK_START (block) = start; | |
212 | BLOCK_END (block) = end; | |
d07734e3 FF |
213 | /* Superblock filled in when containing block is made */ |
214 | BLOCK_SUPERBLOCK (block) = NULL; | |
c0302457 JG |
215 | BLOCK_GCC_COMPILED (block) = processing_gcc_compilation; |
216 | ||
217 | /* Put the block in as the value of the symbol that names it. */ | |
218 | ||
219 | if (symbol) | |
220 | { | |
221 | SYMBOL_BLOCK_VALUE (symbol) = block; | |
222 | BLOCK_FUNCTION (block) = symbol; | |
223 | } | |
224 | else | |
d07734e3 FF |
225 | { |
226 | BLOCK_FUNCTION (block) = NULL; | |
227 | } | |
c0302457 JG |
228 | |
229 | /* Now "free" the links of the list, and empty the list. */ | |
230 | ||
231 | for (next = *listhead; next; next = next1) | |
232 | { | |
233 | next1 = next->next; | |
234 | next->next = free_pendings; | |
235 | free_pendings = next; | |
236 | } | |
d07734e3 | 237 | *listhead = NULL; |
c0302457 JG |
238 | |
239 | /* Install this block as the superblock | |
240 | of all blocks made since the start of this scope | |
241 | that don't have superblocks yet. */ | |
242 | ||
d07734e3 | 243 | opblock = NULL; |
c0302457 JG |
244 | for (pblock = pending_blocks; pblock != old_blocks; pblock = pblock->next) |
245 | { | |
d07734e3 FF |
246 | if (BLOCK_SUPERBLOCK (pblock->block) == NULL) |
247 | { | |
c0302457 | 248 | #if 1 |
d07734e3 FF |
249 | /* Check to be sure the blocks are nested as we receive them. |
250 | If the compiler/assembler/linker work, this just burns a small | |
251 | amount of time. */ | |
252 | if (BLOCK_START (pblock->block) < BLOCK_START (block) || | |
253 | BLOCK_END (pblock->block) > BLOCK_END (block)) | |
254 | { | |
255 | if (symbol) | |
256 | { | |
257 | complain (&innerblock_complaint, SYMBOL_NAME (symbol)); | |
258 | } | |
259 | else | |
260 | { | |
261 | complain (&innerblock_anon_complaint, 0); | |
262 | } | |
263 | BLOCK_START (pblock->block) = BLOCK_START (block); | |
264 | BLOCK_END (pblock->block) = BLOCK_END (block); | |
265 | } | |
c0302457 | 266 | #endif |
d07734e3 FF |
267 | BLOCK_SUPERBLOCK (pblock->block) = block; |
268 | } | |
c0302457 JG |
269 | opblock = pblock; |
270 | } | |
271 | ||
272 | /* Record this block on the list of all blocks in the file. | |
273 | Put it after opblock, or at the beginning if opblock is 0. | |
274 | This puts the block in the list after all its subblocks. */ | |
275 | ||
276 | /* Allocate in the symbol_obstack to save time. | |
277 | It wastes a little space. */ | |
278 | pblock = (struct pending_block *) | |
1ab3bf1b | 279 | obstack_alloc (&objfile -> symbol_obstack, |
c0302457 JG |
280 | sizeof (struct pending_block)); |
281 | pblock->block = block; | |
282 | if (opblock) | |
283 | { | |
284 | pblock->next = opblock->next; | |
285 | opblock->next = pblock; | |
286 | } | |
287 | else | |
288 | { | |
289 | pblock->next = pending_blocks; | |
290 | pending_blocks = pblock; | |
291 | } | |
292 | } | |
293 | ||
1ab3bf1b JG |
294 | static struct blockvector * |
295 | make_blockvector (objfile) | |
296 | struct objfile *objfile; | |
c0302457 JG |
297 | { |
298 | register struct pending_block *next; | |
299 | register struct blockvector *blockvector; | |
300 | register int i; | |
301 | ||
302 | /* Count the length of the list of blocks. */ | |
303 | ||
d07734e3 | 304 | for (next = pending_blocks, i = 0; next; next = next->next, i++) {;} |
c0302457 JG |
305 | |
306 | blockvector = (struct blockvector *) | |
1ab3bf1b | 307 | obstack_alloc (&objfile -> symbol_obstack, |
c0302457 JG |
308 | (sizeof (struct blockvector) |
309 | + (i - 1) * sizeof (struct block *))); | |
310 | ||
311 | /* Copy the blocks into the blockvector. | |
312 | This is done in reverse order, which happens to put | |
313 | the blocks into the proper order (ascending starting address). | |
314 | finish_block has hair to insert each block into the list | |
315 | after its subblocks in order to make sure this is true. */ | |
316 | ||
317 | BLOCKVECTOR_NBLOCKS (blockvector) = i; | |
d07734e3 FF |
318 | for (next = pending_blocks; next; next = next->next) |
319 | { | |
320 | BLOCKVECTOR_BLOCK (blockvector, --i) = next->block; | |
321 | } | |
c0302457 JG |
322 | |
323 | #if 0 /* Now we make the links in the obstack, so don't free them. */ | |
324 | /* Now free the links of the list, and empty the list. */ | |
325 | ||
326 | for (next = pending_blocks; next; next = next1) | |
327 | { | |
328 | next1 = next->next; | |
329 | free (next); | |
330 | } | |
331 | #endif | |
d07734e3 | 332 | pending_blocks = NULL; |
c0302457 JG |
333 | |
334 | #if 1 /* FIXME, shut this off after a while to speed up symbol reading. */ | |
335 | /* Some compilers output blocks in the wrong order, but we depend | |
336 | on their being in the right order so we can binary search. | |
337 | Check the order and moan about it. FIXME. */ | |
338 | if (BLOCKVECTOR_NBLOCKS (blockvector) > 1) | |
d07734e3 FF |
339 | { |
340 | for (i = 1; i < BLOCKVECTOR_NBLOCKS (blockvector); i++) | |
341 | { | |
342 | if (BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i-1)) | |
343 | > BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i))) | |
344 | { | |
345 | complain (&blockvector_complaint, | |
346 | (char *) BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i))); | |
347 | } | |
348 | } | |
c0302457 JG |
349 | } |
350 | #endif | |
351 | ||
d07734e3 | 352 | return (blockvector); |
c0302457 | 353 | } |
d07734e3 | 354 | |
c0302457 | 355 | \f |
4137c5fc JG |
356 | /* Start recording information about source code that came from an included |
357 | (or otherwise merged-in) source file with a different name. */ | |
c0302457 JG |
358 | |
359 | void | |
4137c5fc JG |
360 | start_subfile (name, dirname) |
361 | char *name; | |
362 | char *dirname; | |
363 | { | |
364 | register struct subfile *subfile; | |
365 | ||
366 | /* See if this subfile is already known as a subfile of the | |
367 | current main source file. */ | |
368 | ||
369 | for (subfile = subfiles; subfile; subfile = subfile->next) | |
370 | { | |
371 | if (!strcmp (subfile->name, name)) | |
372 | { | |
373 | current_subfile = subfile; | |
374 | return; | |
375 | } | |
376 | } | |
377 | ||
378 | /* This subfile is not known. Add an entry for it. | |
379 | Make an entry for this subfile in the list of all subfiles | |
380 | of the current main source file. */ | |
381 | ||
382 | subfile = (struct subfile *) xmalloc (sizeof (struct subfile)); | |
383 | subfile->next = subfiles; | |
384 | subfiles = subfile; | |
385 | current_subfile = subfile; | |
386 | ||
387 | /* Save its name and compilation directory name */ | |
1ab3bf1b | 388 | subfile->name = strdup (name); |
4137c5fc | 389 | if (dirname == NULL) |
d07734e3 FF |
390 | { |
391 | subfile->dirname = NULL; | |
392 | } | |
4137c5fc | 393 | else |
d07734e3 FF |
394 | { |
395 | subfile->dirname = strdup (dirname); | |
396 | } | |
4137c5fc JG |
397 | |
398 | /* Initialize line-number recording for this subfile. */ | |
d07734e3 | 399 | subfile->line_vector = NULL; |
4137c5fc | 400 | } |
d07734e3 | 401 | |
4137c5fc | 402 | \f |
a048c8f5 JG |
403 | /* Handle the N_BINCL and N_EINCL symbol types |
404 | that act like N_SOL for switching source files | |
405 | (different subfiles, as we call them) within one object file, | |
406 | but using a stack rather than in an arbitrary order. */ | |
407 | ||
408 | void | |
409 | push_subfile () | |
410 | { | |
411 | register struct subfile_stack *tem | |
412 | = (struct subfile_stack *) xmalloc (sizeof (struct subfile_stack)); | |
413 | ||
414 | tem->next = subfile_stack; | |
415 | subfile_stack = tem; | |
d07734e3 FF |
416 | if (current_subfile == NULL || current_subfile->name == NULL) |
417 | { | |
418 | abort (); | |
419 | } | |
a048c8f5 | 420 | tem->name = current_subfile->name; |
a048c8f5 JG |
421 | } |
422 | ||
423 | char * | |
424 | pop_subfile () | |
425 | { | |
426 | register char *name; | |
427 | register struct subfile_stack *link = subfile_stack; | |
428 | ||
d07734e3 FF |
429 | if (link == NULL) |
430 | { | |
431 | abort (); | |
432 | } | |
a048c8f5 JG |
433 | name = link->name; |
434 | subfile_stack = link->next; | |
84ffdec2 | 435 | free ((PTR)link); |
d07734e3 | 436 | return (name); |
a048c8f5 | 437 | } |
d07734e3 | 438 | |
a048c8f5 | 439 | \f |
4137c5fc JG |
440 | /* Manage the vector of line numbers for each subfile. */ |
441 | ||
442 | void | |
443 | record_line (subfile, line, pc) | |
444 | register struct subfile *subfile; | |
c0302457 JG |
445 | int line; |
446 | CORE_ADDR pc; | |
447 | { | |
448 | struct linetable_entry *e; | |
449 | /* Ignore the dummy line number in libg.o */ | |
450 | ||
451 | if (line == 0xffff) | |
d07734e3 FF |
452 | { |
453 | return; | |
454 | } | |
c0302457 | 455 | |
4137c5fc | 456 | /* Make sure line vector exists and is big enough. */ |
d07734e3 FF |
457 | if (!subfile->line_vector) |
458 | { | |
459 | subfile->line_vector_length = INITIAL_LINE_VECTOR_LENGTH; | |
460 | subfile->line_vector = (struct linetable *) | |
4137c5fc JG |
461 | xmalloc (sizeof (struct linetable) |
462 | + subfile->line_vector_length * sizeof (struct linetable_entry)); | |
d07734e3 FF |
463 | subfile->line_vector->nitems = 0; |
464 | } | |
c0302457 | 465 | |
4137c5fc | 466 | if (subfile->line_vector->nitems + 1 >= subfile->line_vector_length) |
c0302457 | 467 | { |
4137c5fc JG |
468 | subfile->line_vector_length *= 2; |
469 | subfile->line_vector = (struct linetable *) | |
1ab3bf1b | 470 | xrealloc ((char *) subfile->line_vector, (sizeof (struct linetable) |
d07734e3 | 471 | + subfile->line_vector_length * sizeof (struct linetable_entry))); |
c0302457 JG |
472 | } |
473 | ||
4137c5fc | 474 | e = subfile->line_vector->item + subfile->line_vector->nitems++; |
c0302457 JG |
475 | e->line = line; e->pc = pc; |
476 | } | |
4137c5fc JG |
477 | |
478 | ||
479 | /* Needed in order to sort line tables from IBM xcoff files. Sigh! */ | |
480 | ||
1ab3bf1b JG |
481 | static int |
482 | compare_line_numbers (ln1p, ln2p) | |
483 | const PTR ln1p; | |
484 | const PTR ln2p; | |
4137c5fc | 485 | { |
1ab3bf1b JG |
486 | return (((struct linetable_entry *) ln1p) -> line - |
487 | ((struct linetable_entry *) ln2p) -> line); | |
4137c5fc | 488 | } |
1ab3bf1b | 489 | |
c0302457 JG |
490 | \f |
491 | /* Start a new symtab for a new source file. | |
d07734e3 FF |
492 | Called, for example, when a stabs symbol of type N_SO is seen, or when |
493 | a DWARF TAG_compile_unit DIE is seen. | |
494 | It indicates the start of data for one original source file. */ | |
c0302457 JG |
495 | |
496 | void | |
497 | start_symtab (name, dirname, start_addr) | |
498 | char *name; | |
499 | char *dirname; | |
500 | CORE_ADDR start_addr; | |
501 | { | |
502 | ||
503 | last_source_file = name; | |
504 | last_source_start_addr = start_addr; | |
d07734e3 FF |
505 | file_symbols = NULL; |
506 | global_symbols = NULL; | |
c0302457 JG |
507 | within_function = 0; |
508 | ||
a048c8f5 JG |
509 | /* Context stack is initially empty. Allocate first one with room for |
510 | 10 levels; reuse it forever afterward. */ | |
d07734e3 FF |
511 | if (context_stack == NULL) |
512 | { | |
513 | context_stack_size = INITIAL_CONTEXT_STACK_SIZE; | |
514 | context_stack = (struct context_stack *) | |
515 | xmalloc (context_stack_size * sizeof (struct context_stack)); | |
516 | } | |
c0302457 JG |
517 | context_stack_depth = 0; |
518 | ||
c0302457 JG |
519 | /* Initialize the list of sub source files with one entry |
520 | for this file (the top-level source file). */ | |
521 | ||
d07734e3 FF |
522 | subfiles = NULL; |
523 | current_subfile = NULL; | |
c0302457 JG |
524 | start_subfile (name, dirname); |
525 | } | |
526 | ||
527 | /* Finish the symbol definitions for one main source file, | |
528 | close off all the lexical contexts for that file | |
529 | (creating struct block's for them), then make the struct symtab | |
530 | for that file and put it in the list of all such. | |
531 | ||
532 | END_ADDR is the address of the end of the file's text. */ | |
533 | ||
534 | struct symtab * | |
a048c8f5 | 535 | end_symtab (end_addr, sort_pending, sort_linevec, objfile) |
c0302457 | 536 | CORE_ADDR end_addr; |
4137c5fc JG |
537 | int sort_pending; |
538 | int sort_linevec; | |
a048c8f5 | 539 | struct objfile *objfile; |
c0302457 JG |
540 | { |
541 | register struct symtab *symtab; | |
542 | register struct blockvector *blockvector; | |
543 | register struct subfile *subfile; | |
d07734e3 | 544 | register struct context_stack *cstk; |
c0302457 JG |
545 | struct subfile *nextsub; |
546 | ||
547 | /* Finish the lexical context of the last function in the file; | |
548 | pop the context stack. */ | |
549 | ||
550 | if (context_stack_depth > 0) | |
551 | { | |
c0302457 JG |
552 | context_stack_depth--; |
553 | cstk = &context_stack[context_stack_depth]; | |
554 | /* Make a block for the local symbols within. */ | |
555 | finish_block (cstk->name, &local_symbols, cstk->old_blocks, | |
1ab3bf1b | 556 | cstk->start_addr, end_addr, objfile); |
a048c8f5 | 557 | |
d07734e3 FF |
558 | /* Debug: if context stack still has something in it, |
559 | we are in trouble. */ | |
a048c8f5 | 560 | if (context_stack_depth > 0) |
d07734e3 FF |
561 | { |
562 | abort (); | |
563 | } | |
c0302457 JG |
564 | } |
565 | ||
4137c5fc JG |
566 | /* It is unfortunate that in aixcoff, pending blocks might not be ordered |
567 | in this stage. Especially, blocks for static functions will show up at | |
568 | the end. We need to sort them, so tools like `find_pc_function' and | |
569 | `find_pc_block' can work reliably. */ | |
d07734e3 FF |
570 | |
571 | if (sort_pending && pending_blocks) | |
572 | { | |
573 | /* FIXME! Remove this horrid bubble sort and use qsort!!! */ | |
574 | int swapped; | |
575 | do | |
576 | { | |
577 | struct pending_block *pb, *pbnext; | |
578 | ||
579 | pb = pending_blocks; | |
580 | pbnext = pb->next; | |
581 | swapped = 0; | |
582 | ||
583 | while (pbnext) | |
584 | { | |
585 | /* swap blocks if unordered! */ | |
586 | ||
587 | if (BLOCK_START(pb->block) < BLOCK_START(pbnext->block)) | |
588 | { | |
589 | struct block *tmp = pb->block; | |
590 | pb->block = pbnext->block; | |
591 | pbnext->block = tmp; | |
592 | swapped = 1; | |
593 | } | |
594 | pb = pbnext; | |
595 | pbnext = pbnext->next; | |
596 | } | |
597 | } while (swapped); | |
598 | } | |
4137c5fc | 599 | |
c0302457 JG |
600 | /* Cleanup any undefined types that have been left hanging around |
601 | (this needs to be done before the finish_blocks so that | |
d07734e3 FF |
602 | file_symbols is still good). |
603 | FIXME: Stabs specific. */ | |
c0302457 | 604 | cleanup_undefined_types (); |
d07734e3 | 605 | finish_global_stabs (objfile); |
c0302457 | 606 | |
d07734e3 FF |
607 | if (pending_blocks == NULL |
608 | && file_symbols == NULL | |
609 | && global_symbols == NULL) | |
610 | { | |
611 | /* Ignore symtabs that have no functions with real debugging info */ | |
612 | blockvector = NULL; | |
613 | } | |
614 | else | |
615 | { | |
616 | /* Define the STATIC_BLOCK & GLOBAL_BLOCK, and build the blockvector. */ | |
617 | finish_block (0, &file_symbols, 0, last_source_start_addr, end_addr, | |
618 | objfile); | |
619 | finish_block (0, &global_symbols, 0, last_source_start_addr, end_addr, | |
620 | objfile); | |
621 | blockvector = make_blockvector (objfile); | |
622 | } | |
c0302457 | 623 | |
818de002 | 624 | #ifdef PROCESS_LINENUMBER_HOOK |
d07734e3 | 625 | PROCESS_LINENUMBER_HOOK (); /* Needed for aixcoff. */ |
818de002 PB |
626 | #endif |
627 | ||
c0302457 JG |
628 | /* Now create the symtab objects proper, one for each subfile. */ |
629 | /* (The main file is the last one on the chain.) */ | |
630 | ||
631 | for (subfile = subfiles; subfile; subfile = nextsub) | |
632 | { | |
1ab3bf1b | 633 | int linetablesize; |
a048c8f5 JG |
634 | /* If we have blocks of symbols, make a symtab. |
635 | Otherwise, just ignore this file and any line number info in it. */ | |
d07734e3 FF |
636 | symtab = NULL; |
637 | if (blockvector) | |
638 | { | |
639 | if (subfile->line_vector) | |
640 | { | |
641 | /* First, shrink the linetable to make more memory. */ | |
642 | linetablesize = sizeof (struct linetable) + | |
643 | subfile->line_vector->nitems * sizeof (struct linetable_entry); | |
644 | subfile->line_vector = (struct linetable *) | |
645 | xrealloc ((char *) subfile->line_vector, linetablesize); | |
646 | ||
647 | if (sort_linevec) | |
648 | qsort (subfile->line_vector->item, | |
649 | subfile->line_vector->nitems, | |
650 | sizeof (struct linetable_entry), compare_line_numbers); | |
651 | } | |
652 | ||
653 | /* Now, allocate a symbol table. */ | |
654 | symtab = allocate_symtab (subfile->name, objfile); | |
4137c5fc | 655 | |
d07734e3 FF |
656 | /* Fill in its components. */ |
657 | symtab->blockvector = blockvector; | |
658 | if (subfile->line_vector) | |
659 | { | |
660 | /* Reallocate the line table on the symbol obstack */ | |
661 | symtab->linetable = (struct linetable *) | |
662 | obstack_alloc (&objfile -> symbol_obstack, linetablesize); | |
663 | memcpy (symtab->linetable, subfile->line_vector, linetablesize); | |
664 | } | |
665 | else | |
666 | { | |
667 | symtab->linetable = NULL; | |
668 | } | |
669 | symtab->dirname = subfile->dirname; | |
670 | symtab->free_code = free_linetable; | |
671 | symtab->free_ptr = NULL; | |
2b5a8d9c | 672 | |
1eeba686 | 673 | #ifdef IBM6000_TARGET |
d07734e3 FF |
674 | /* In case we need to duplicate symbol tables (to represent include |
675 | files), and in case our system needs relocation, we want to | |
676 | relocate the main symbol table node only (for the main file, | |
677 | not for the include files). */ | |
2b5a8d9c | 678 | |
d07734e3 | 679 | symtab->nonreloc = TRUE; |
2b5a8d9c | 680 | #endif |
d07734e3 | 681 | } |
1ab3bf1b | 682 | if (subfile->line_vector) |
d07734e3 FF |
683 | { |
684 | free ((PTR)subfile->line_vector); | |
685 | } | |
4137c5fc | 686 | |
c0302457 | 687 | nextsub = subfile->next; |
84ffdec2 | 688 | free ((PTR)subfile); |
c0302457 JG |
689 | } |
690 | ||
1eeba686 | 691 | #ifdef IBM6000_TARGET |
2b5a8d9c PB |
692 | /* all include symbol tables are non-relocatable, except the main source |
693 | file's. */ | |
1eeba686 | 694 | if (symtab) |
d07734e3 FF |
695 | { |
696 | symtab->nonreloc = FALSE; | |
697 | } | |
2b5a8d9c PB |
698 | #endif |
699 | ||
d07734e3 FF |
700 | last_source_file = NULL; |
701 | current_subfile = NULL; | |
4137c5fc | 702 | |
d07734e3 | 703 | return (symtab); |
c0302457 | 704 | } |
a048c8f5 JG |
705 | |
706 | ||
707 | /* Push a context block. Args are an identifying nesting level (checkable | |
708 | when you pop it), and the starting PC address of this context. */ | |
709 | ||
710 | struct context_stack * | |
711 | push_context (desc, valu) | |
712 | int desc; | |
713 | CORE_ADDR valu; | |
714 | { | |
715 | register struct context_stack *new; | |
716 | ||
717 | if (context_stack_depth == context_stack_size) | |
718 | { | |
719 | context_stack_size *= 2; | |
720 | context_stack = (struct context_stack *) | |
1ab3bf1b JG |
721 | xrealloc ((char *) context_stack, |
722 | (context_stack_size * sizeof (struct context_stack))); | |
a048c8f5 JG |
723 | } |
724 | ||
725 | new = &context_stack[context_stack_depth++]; | |
726 | new->depth = desc; | |
727 | new->locals = local_symbols; | |
728 | new->old_blocks = pending_blocks; | |
729 | new->start_addr = valu; | |
d07734e3 | 730 | new->name = NULL; |
a048c8f5 | 731 | |
d07734e3 | 732 | local_symbols = NULL; |
a048c8f5 | 733 | |
d07734e3 | 734 | return (new); |
a048c8f5 | 735 | } |
d07734e3 | 736 | |
c0302457 JG |
737 | \f |
738 | /* Initialize anything that needs initializing when starting to read | |
739 | a fresh piece of a symbol file, e.g. reading in the stuff corresponding | |
740 | to a psymtab. */ | |
741 | ||
742 | void | |
743 | buildsym_init () | |
744 | { | |
d07734e3 FF |
745 | free_pendings = NULL; |
746 | file_symbols = NULL; | |
747 | global_symbols = NULL; | |
748 | pending_blocks = NULL; | |
c0302457 JG |
749 | } |
750 | ||
751 | /* Initialize anything that needs initializing when a completely new | |
752 | symbol file is specified (not just adding some symbols from another | |
753 | file, e.g. a shared library). */ | |
754 | ||
755 | void | |
756 | buildsym_new_init () | |
757 | { | |
c0302457 JG |
758 | buildsym_init (); |
759 | } | |
760 | ||
d07734e3 | 761 | /* Initializer for this module */ |
095db7ce | 762 | |
c0302457 JG |
763 | void |
764 | _initialize_buildsym () | |
765 | { | |
c0302457 | 766 | } |