* xm-sun3os4.h, xm-sun4os4.h: Enable HAVE_MMAP.
[deliverable/binutils-gdb.git] / gdb / dbxread.c
1 /* Read dbx symbol tables and convert to internal format, for GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 /* This module provides three functions: dbx_symfile_init,
21 which initializes to read a symbol file; dbx_new_init, which
22 discards existing cached information when all symbols are being
23 discarded; and dbx_symfile_read, which reads a symbol table
24 from a file.
25
26 dbx_symfile_read only does the minimum work necessary for letting the
27 user "name" things symbolically; it does not read the entire symtab.
28 Instead, it reads the external and static symbols and puts them in partial
29 symbol tables. When more extensive information is requested of a
30 file, the corresponding partial symbol table is mutated into a full
31 fledged symbol table by going back and reading the symbols
32 for real. dbx_psymtab_to_symtab() is the function that does this */
33
34 #include <stdio.h>
35 #include <string.h>
36 #include "defs.h"
37
38 #ifdef USG
39 #include <sys/types.h>
40 #include <fcntl.h>
41 #define L_SET 0
42 #define L_INCR 1
43 #endif
44
45 #include <obstack.h>
46 #include <sys/param.h>
47 #ifndef NO_SYS_FILE
48 #include <sys/file.h>
49 #endif
50 #include <sys/stat.h>
51 #include <ctype.h>
52 #include "symtab.h"
53 #include "breakpoint.h"
54 #include "command.h"
55 #include "target.h"
56 #include "gdbcore.h" /* for bfd stuff */
57 #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
58 #include "symfile.h"
59 #include "buildsym.h"
60
61 #include "aout/aout64.h"
62 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native, now */
63
64 /* Information is passed among various dbxread routines for accessing
65 symbol files. A pointer to this structure is kept in the sym_private
66 field of the struct sym_fns passed in by symfile.h. */
67
68 struct dbx_symfile_info {
69 asection *text_sect; /* Text section accessor */
70 int symcount; /* How many symbols are there in the file */
71 char *stringtab; /* The actual string table */
72 int stringtab_size; /* Its size */
73 off_t symtab_offset; /* Offset in file to symbol table */
74 };
75
76
77 /* Each partial symbol table entry contains a pointer to private data for the
78 read_symtab() function to use when expanding a partial symbol table entry
79 to a full symbol table entry.
80
81 For dbxread this structure contains the offset within the file symbol table
82 of first local symbol for this file, and length (in bytes) of the section
83 of the symbol table devoted to this file's symbols (actually, the section
84 bracketed may contain more than just this file's symbols). If ldsymlen is
85 0, the only reason for this thing's existence is the dependency list.
86 Nothing else will happen when it is read in. */
87
88 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
89 #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
90
91 struct symloc {
92 int ldsymoff;
93 int ldsymlen;
94 };
95
96 /* Macro to determine which symbols to ignore when reading the first symbol
97 of a file. Some machines override this definition. */
98 #ifndef IGNORE_SYMBOL
99 /* This code is used on Ultrix systems. Ignore it */
100 #define IGNORE_SYMBOL(type) (type == (int)N_NSYMS)
101 #endif
102
103 /* Macro for name of symbol to indicate a file compiled with gcc. */
104 #ifndef GCC_COMPILED_FLAG_SYMBOL
105 #define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
106 #endif
107
108 /* Macro for name of symbol to indicate a file compiled with gcc2. */
109 #ifndef GCC2_COMPILED_FLAG_SYMBOL
110 #define GCC2_COMPILED_FLAG_SYMBOL "gcc2_compiled."
111 #endif
112
113 /* Define this as 1 if a pcc declaration of a char or short argument
114 gives the correct address. Otherwise assume pcc gives the
115 address of the corresponding int, which is not the same on a
116 big-endian machine. */
117
118 #ifndef BELIEVE_PCC_PROMOTION
119 #define BELIEVE_PCC_PROMOTION 0
120 #endif
121
122 /* Nonzero means give verbose info on gdb action. From main.c. */
123 extern int info_verbose;
124
125 /* The BFD for this file -- implicit parameter to next_symbol_text. */
126
127 static bfd *symfile_bfd;
128
129 /* The objfile for this file -- only good in process_one_symbol(). */
130
131 static struct objfile *our_objfile;
132
133 /* String table for the main symbol file. It is kept in memory
134 permanently, to speed up symbol reading. Other files' symbol tables
135 are read in on demand. FIXME, this should be cleaner. */
136
137 static char *symfile_string_table;
138 static int symfile_string_table_size;
139
140 /* The size of each symbol in the symbol file (in external form).
141 This is set by dbx_symfile_read when building psymtabs, and by
142 dbx_psymtab_to_symtab when building symtabs. */
143
144 static unsigned symbol_size;
145
146 /* Complaints about the symbols we have encountered. */
147
148 struct complaint lbrac_complaint =
149 {"bad block start address patched", 0, 0};
150
151 struct complaint string_table_offset_complaint =
152 {"bad string table offset in symbol %d", 0, 0};
153
154 struct complaint unknown_symtype_complaint =
155 {"unknown symbol type %s", 0, 0};
156
157 struct complaint lbrac_rbrac_complaint =
158 {"block start larger than block end", 0, 0};
159
160 struct complaint lbrac_unmatched_complaint =
161 {"unmatched N_LBRAC before symtab pos %d", 0, 0};
162
163 struct complaint lbrac_mismatch_complaint =
164 {"N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d", 0, 0};
165 \f
166 /* During initial symbol readin, we need to have a structure to keep
167 track of which psymtabs have which bincls in them. This structure
168 is used during readin to setup the list of dependencies within each
169 partial symbol table. */
170
171 struct header_file_location
172 {
173 char *name; /* Name of header file */
174 int instance; /* See above */
175 struct partial_symtab *pst; /* Partial symtab that has the
176 BINCL/EINCL defs for this file */
177 };
178
179 /* The actual list and controling variables */
180 static struct header_file_location *bincl_list, *next_bincl;
181 static int bincls_allocated;
182
183 /* Local function prototypes */
184
185 static void
186 free_and_init_header_files PARAMS ((void));
187
188 static struct pending *
189 copy_pending PARAMS ((struct pending *, int, struct pending *));
190
191 static struct symtab *
192 read_ofile_symtab PARAMS ((struct objfile *, char *, unsigned int, int, int,
193 CORE_ADDR, int, int));
194
195 static void
196 dbx_psymtab_to_symtab PARAMS ((struct partial_symtab *));
197
198 static void
199 psymtab_to_symtab_1 PARAMS ((struct partial_symtab *, char *, int, int));
200
201 static void
202 read_dbx_symtab PARAMS ((CORE_ADDR, struct objfile *, char *, long, int,
203 CORE_ADDR, int));
204
205 static void
206 free_bincl_list PARAMS ((struct objfile *));
207
208 static struct partial_symtab *
209 find_corresponding_bincl_psymtab PARAMS ((char *, int));
210
211 static void
212 add_bincl_to_list PARAMS ((struct partial_symtab *, char *, int));
213
214 static void
215 init_bincl_list PARAMS ((int, struct objfile *));
216
217 static void
218 init_psymbol_list PARAMS ((int, struct objfile *));
219
220 static char *
221 dbx_next_symbol_text PARAMS ((void));
222
223 static void
224 fill_symbuf PARAMS ((bfd *));
225
226 static void
227 dbx_symfile_init PARAMS ((struct sym_fns *));
228
229 static void
230 dbx_new_init PARAMS ((void));
231
232 static void
233 dbx_symfile_read PARAMS ((struct sym_fns *, CORE_ADDR, int));
234
235 static void
236 record_minimal_symbol PARAMS ((char *, CORE_ADDR, int, struct objfile *));
237
238 static void
239 add_new_header_file PARAMS ((char *, int));
240
241 static void
242 add_old_header_file PARAMS ((char *, int));
243
244 static void
245 add_this_object_header_file PARAMS ((int));
246
247 /* Free up old header file tables, and allocate new ones.
248 We're reading a new symbol file now. */
249
250 static void
251 free_and_init_header_files ()
252 {
253 register int i;
254 for (i = 0; i < n_header_files; i++)
255 free (header_files[i].name);
256 if (header_files) /* First time null */
257 free (header_files);
258 if (this_object_header_files) /* First time null */
259 free (this_object_header_files);
260
261 n_allocated_header_files = 10;
262 header_files = (struct header_file *) xmalloc (10 * sizeof (struct header_file));
263 n_header_files = 0;
264
265 n_allocated_this_object_header_files = 10;
266 this_object_header_files = (int *) xmalloc (10 * sizeof (int));
267 }
268
269 /* Add header file number I for this object file
270 at the next successive FILENUM. */
271
272 static void
273 add_this_object_header_file (i)
274 int i;
275 {
276 if (n_this_object_header_files == n_allocated_this_object_header_files)
277 {
278 n_allocated_this_object_header_files *= 2;
279 this_object_header_files
280 = (int *) xrealloc ((char *) this_object_header_files,
281 n_allocated_this_object_header_files * sizeof (int));
282 }
283
284 this_object_header_files[n_this_object_header_files++] = i;
285 }
286
287 /* Add to this file an "old" header file, one already seen in
288 a previous object file. NAME is the header file's name.
289 INSTANCE is its instance code, to select among multiple
290 symbol tables for the same header file. */
291
292 static void
293 add_old_header_file (name, instance)
294 char *name;
295 int instance;
296 {
297 register struct header_file *p = header_files;
298 register int i;
299
300 for (i = 0; i < n_header_files; i++)
301 if (!strcmp (p[i].name, name) && instance == p[i].instance)
302 {
303 add_this_object_header_file (i);
304 return;
305 }
306 error ("Invalid symbol data: \"repeated\" header file that hasn't been seen before, at symtab pos %d.",
307 symnum);
308 }
309
310 /* Add to this file a "new" header file: definitions for its types follow.
311 NAME is the header file's name.
312 Most often this happens only once for each distinct header file,
313 but not necessarily. If it happens more than once, INSTANCE has
314 a different value each time, and references to the header file
315 use INSTANCE values to select among them.
316
317 dbx output contains "begin" and "end" markers for each new header file,
318 but at this level we just need to know which files there have been;
319 so we record the file when its "begin" is seen and ignore the "end". */
320
321 static void
322 add_new_header_file (name, instance)
323 char *name;
324 int instance;
325 {
326 register int i;
327 header_file_prev_index = -1;
328
329 /* Make sure there is room for one more header file. */
330
331 if (n_header_files == n_allocated_header_files)
332 {
333 n_allocated_header_files *= 2;
334 header_files = (struct header_file *)
335 xrealloc ((char *) header_files,
336 (n_allocated_header_files * sizeof (struct header_file)));
337 }
338
339 /* Create an entry for this header file. */
340
341 i = n_header_files++;
342 header_files[i].name = savestring (name, strlen(name));
343 header_files[i].instance = instance;
344 header_files[i].length = 10;
345 header_files[i].vector
346 = (struct type **) xmalloc (10 * sizeof (struct type *));
347 bzero (header_files[i].vector, 10 * sizeof (struct type *));
348
349 add_this_object_header_file (i);
350 }
351
352 #if 0
353 static struct type **
354 explicit_lookup_type (real_filenum, index)
355 int real_filenum, index;
356 {
357 register struct header_file *f = &header_files[real_filenum];
358
359 if (index >= f->length)
360 {
361 f->length *= 2;
362 f->vector = (struct type **)
363 xrealloc (f->vector, f->length * sizeof (struct type *));
364 bzero (&f->vector[f->length / 2],
365 f->length * sizeof (struct type *) / 2);
366 }
367 return &f->vector[index];
368 }
369 #endif
370 \f
371 static void
372 record_minimal_symbol (name, address, type, objfile)
373 char *name;
374 CORE_ADDR address;
375 int type;
376 struct objfile *objfile;
377 {
378 enum minimal_symbol_type ms_type;
379
380 switch (type &~ N_EXT) {
381 case N_TEXT: ms_type = mst_text; break;
382 case N_DATA: ms_type = mst_data; break;
383 case N_BSS: ms_type = mst_bss; break;
384 case N_ABS: ms_type = mst_abs; break;
385 #ifdef N_SETV
386 case N_SETV: ms_type = mst_data; break;
387 #endif
388 default: ms_type = mst_unknown; break;
389 }
390
391 prim_record_minimal_symbol (obsavestring (name, strlen (name), &objfile -> symbol_obstack),
392 address, ms_type);
393 }
394 \f
395 /* Scan and build partial symbols for a symbol file.
396 We have been initialized by a call to dbx_symfile_init, which
397 put all the relevant info into a "struct dbx_symfile_info"
398 hung off the struct sym_fns SF.
399
400 ADDR is the address relative to which the symbols in it are (e.g.
401 the base address of the text segment).
402 MAINLINE is true if we are reading the main symbol
403 table (as opposed to a shared lib or dynamically loaded file). */
404
405 static void
406 dbx_symfile_read (sf, addr, mainline)
407 struct sym_fns *sf;
408 CORE_ADDR addr;
409 int mainline; /* FIXME comments above */
410 {
411 struct dbx_symfile_info *info = (struct dbx_symfile_info *) (sf->sym_private);
412 bfd *sym_bfd = sf->objfile->obfd;
413 int val;
414
415 val = bfd_seek (sf->objfile->obfd, info->symtab_offset, L_SET);
416 if (val < 0)
417 perror_with_name (sf->objfile->name);
418
419 /* If mainline, set global string table pointers, and reinitialize global
420 partial symbol list. */
421 if (mainline) {
422 symfile_string_table = info->stringtab;
423 symfile_string_table_size = info->stringtab_size;
424 }
425
426 /* If we are reinitializing, or if we have never loaded syms yet, init */
427 if (mainline || sf->objfile->global_psymbols.size == 0 || sf->objfile->static_psymbols.size == 0)
428 init_psymbol_list (info->symcount, sf->objfile);
429
430 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
431 symbol_size = obj_symbol_entry_size (sym_bfd);
432
433 pending_blocks = 0;
434 make_cleanup (really_free_pendings, 0);
435
436 init_minimal_symbol_collection ();
437 make_cleanup (discard_minimal_symbols, 0);
438
439 /* Now that the symbol table data of the executable file are all in core,
440 process them and define symbols accordingly. */
441
442 read_dbx_symtab (addr - bfd_section_vma (sym_bfd, info->text_sect), /*offset*/
443 sf->objfile, info->stringtab, info->stringtab_size,
444 info->symcount,
445 bfd_section_vma (sym_bfd, info->text_sect),
446 bfd_section_size (sym_bfd, info->text_sect));
447
448 /* Install any minimal symbols that have been collected as the current
449 minimal symbols for this objfile. */
450
451 install_minimal_symbols (sf -> objfile);
452
453 /* Free up any memory we allocated for ourselves. */
454
455 if (!mainline) {
456 (*sf->objfile->free) (info->stringtab); /* Stringtab is only saved for mainline */
457 }
458 (*sf->objfile->free) (info);
459 sf->sym_private = NULL; /* Zap pointer to our (now gone) info struct */
460
461 if (!have_partial_symbols ()) {
462 wrap_here ("");
463 printf_filtered ("(no debugging symbols found)...");
464 wrap_here ("");
465 }
466 }
467
468 /* Initialize anything that needs initializing when a completely new
469 symbol file is specified (not just adding some symbols from another
470 file, e.g. a shared library). */
471
472 static void
473 dbx_new_init ()
474 {
475 buildsym_new_init ();
476
477 /* Don't put these on the cleanup chain; they need to stick around
478 until the next call to dbx_new_init. *Then* we'll free them. */
479 if (symfile_string_table)
480 {
481 free (symfile_string_table);
482 symfile_string_table = 0;
483 symfile_string_table_size = 0;
484 }
485 free_and_init_header_files ();
486 }
487
488
489 /* dbx_symfile_init ()
490 is the dbx-specific initialization routine for reading symbols.
491 It is passed a struct sym_fns which contains, among other things,
492 the BFD for the file whose symbols are being read, and a slot for a pointer
493 to "private data" which we fill with goodies.
494
495 We read the string table into malloc'd space and stash a pointer to it.
496
497 Since BFD doesn't know how to read debug symbols in a format-independent
498 way (and may never do so...), we have to do it ourselves. We will never
499 be called unless this is an a.out (or very similar) file.
500 FIXME, there should be a cleaner peephole into the BFD environment here. */
501
502 static void
503 dbx_symfile_init (sf)
504 struct sym_fns *sf;
505 {
506 int val;
507 bfd *sym_bfd = sf->objfile->obfd;
508 char *name = bfd_get_filename (sym_bfd);
509 struct dbx_symfile_info *info;
510 unsigned char size_temp[4];
511
512 /* Allocate struct to keep track of the symfile */
513 sf->sym_private = (*sf->objfile->xmalloc) (sizeof (*info));
514 info = (struct dbx_symfile_info *)sf->sym_private;
515
516 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
517 #define STRING_TABLE_OFFSET (sym_bfd->origin + obj_str_filepos (sym_bfd))
518 #define SYMBOL_TABLE_OFFSET (sym_bfd->origin + obj_sym_filepos (sym_bfd))
519 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
520
521 info->text_sect = bfd_get_section_by_name (sym_bfd, ".text");
522 if (!info->text_sect)
523 abort();
524 info->symcount = bfd_get_symcount (sym_bfd);
525
526 /* Read the string table size and check it for bogosity. */
527 val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
528 if (val < 0)
529 perror_with_name (name);
530
531 val = bfd_read (size_temp, sizeof (long), 1, sym_bfd);
532 if (val < 0)
533 perror_with_name (name);
534 info->stringtab_size = bfd_h_get_32 (sym_bfd, size_temp);
535
536 if (info->stringtab_size >= 0)
537 {
538 /* Yes, this should be malloc, not xmalloc. We check its result. */
539 info->stringtab = (char *) (*sf->objfile->malloc) (info->stringtab_size);
540 /* Caller is responsible for freeing the string table. No cleanup. */
541 }
542 else
543 info->stringtab = NULL;
544 if (info->stringtab == NULL && info->stringtab_size != 0)
545 error ("ridiculous string table size: %d bytes", info->stringtab_size);
546
547 /* Now read in the string table in one big gulp. */
548
549 val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
550 if (val < 0)
551 perror_with_name (name);
552 val = bfd_read (info->stringtab, info->stringtab_size, 1, sym_bfd);
553 if (val != info->stringtab_size)
554 perror_with_name (name);
555
556 /* Record the position of the symbol table for later use. */
557
558 info->symtab_offset = SYMBOL_TABLE_OFFSET;
559 }
560 \f
561 /* Buffer for reading the symbol table entries. */
562 static struct internal_nlist symbuf[4096];
563 static int symbuf_idx;
564 static int symbuf_end;
565
566 /* The address in memory of the string table of the object file we are
567 reading (which might not be the "main" object file, but might be a
568 shared library or some other dynamically loaded thing). This is set
569 by read_dbx_symtab when building psymtabs, and by read_ofile_symtab
570 when building symtabs, and is used only by next_symbol_text. */
571 static char *stringtab_global;
572
573 /* Refill the symbol table input buffer
574 and set the variables that control fetching entries from it.
575 Reports an error if no data available.
576 This function can read past the end of the symbol table
577 (into the string table) but this does no harm. */
578
579 static void
580 fill_symbuf (sym_bfd)
581 bfd *sym_bfd;
582 {
583 int nbytes = bfd_read (symbuf, sizeof (symbuf), 1, sym_bfd);
584 if (nbytes < 0)
585 perror_with_name (bfd_get_filename (sym_bfd));
586 else if (nbytes == 0)
587 error ("Premature end of file reading symbol table");
588 symbuf_end = nbytes / symbol_size;
589 symbuf_idx = 0;
590 }
591
592 #define SWAP_SYMBOL(symp, abfd) \
593 { \
594 (symp)->n_strx = bfd_h_get_32(abfd, \
595 (unsigned char *)&(symp)->n_strx); \
596 (symp)->n_desc = bfd_h_get_16 (abfd, \
597 (unsigned char *)&(symp)->n_desc); \
598 (symp)->n_value = bfd_h_get_32 (abfd, \
599 (unsigned char *)&(symp)->n_value); \
600 }
601
602 /* Invariant: The symbol pointed to by symbuf_idx is the first one
603 that hasn't been swapped. Swap the symbol at the same time
604 that symbuf_idx is incremented. */
605
606 /* dbx allows the text of a symbol name to be continued into the
607 next symbol name! When such a continuation is encountered
608 (a \ at the end of the text of a name)
609 call this function to get the continuation. */
610
611 static char *
612 dbx_next_symbol_text ()
613 {
614 if (symbuf_idx == symbuf_end)
615 fill_symbuf (symfile_bfd);
616 symnum++;
617 SWAP_SYMBOL(&symbuf[symbuf_idx], symfile_bfd);
618 return symbuf[symbuf_idx++].n_strx + stringtab_global;
619 }
620 \f
621 /* Initializes storage for all of the partial symbols that will be
622 created by read_dbx_symtab and subsidiaries. */
623
624 static void
625 init_psymbol_list (total_symbols, objfile)
626 int total_symbols;
627 struct objfile *objfile;
628 {
629 /* Free any previously allocated psymbol lists. */
630 if (objfile -> global_psymbols.list)
631 (*objfile -> free) (objfile -> global_psymbols.list);
632 if (objfile -> static_psymbols.list)
633 (*objfile -> free) (objfile -> static_psymbols.list);
634
635 /* Current best guess is that there are approximately a twentieth
636 of the total symbols (in a debugging file) are global or static
637 oriented symbols */
638 objfile -> global_psymbols.size = total_symbols / 10;
639 objfile -> static_psymbols.size = total_symbols / 10;
640 objfile -> global_psymbols.next = objfile -> global_psymbols.list = (struct partial_symbol *)
641 (*objfile -> xmalloc) (objfile -> global_psymbols.size * sizeof (struct partial_symbol));
642 objfile -> static_psymbols.next = objfile -> static_psymbols.list = (struct partial_symbol *)
643 (*objfile -> xmalloc) (objfile -> static_psymbols.size * sizeof (struct partial_symbol));
644 }
645
646 /* Initialize the list of bincls to contain none and have some
647 allocated. */
648
649 static void
650 init_bincl_list (number, objfile)
651 int number;
652 struct objfile *objfile;
653 {
654 bincls_allocated = number;
655 next_bincl = bincl_list = (struct header_file_location *)
656 (*objfile -> xmalloc) (bincls_allocated * sizeof(struct header_file_location));
657 }
658
659 /* Add a bincl to the list. */
660
661 static void
662 add_bincl_to_list (pst, name, instance)
663 struct partial_symtab *pst;
664 char *name;
665 int instance;
666 {
667 if (next_bincl >= bincl_list + bincls_allocated)
668 {
669 int offset = next_bincl - bincl_list;
670 bincls_allocated *= 2;
671 bincl_list = (struct header_file_location *)
672 (*pst->objfile->xrealloc) ((char *)bincl_list,
673 bincls_allocated * sizeof (struct header_file_location));
674 next_bincl = bincl_list + offset;
675 }
676 next_bincl->pst = pst;
677 next_bincl->instance = instance;
678 next_bincl++->name = name;
679 }
680
681 /* Given a name, value pair, find the corresponding
682 bincl in the list. Return the partial symtab associated
683 with that header_file_location. */
684
685 static struct partial_symtab *
686 find_corresponding_bincl_psymtab (name, instance)
687 char *name;
688 int instance;
689 {
690 struct header_file_location *bincl;
691
692 for (bincl = bincl_list; bincl < next_bincl; bincl++)
693 if (bincl->instance == instance
694 && !strcmp (name, bincl->name))
695 return bincl->pst;
696
697 return (struct partial_symtab *) 0;
698 }
699
700 /* Free the storage allocated for the bincl list. */
701
702 static void
703 free_bincl_list (objfile)
704 struct objfile *objfile;
705 {
706 (*objfile -> free) (bincl_list);
707 bincls_allocated = 0;
708 }
709
710 /* Given pointers to an a.out symbol table in core containing dbx
711 style data, setup partial_symtab's describing each source file for
712 which debugging information is available. NLISTLEN is the number
713 of symbols in the symbol table. All symbol names are given as
714 offsets relative to STRINGTAB. STRINGTAB_SIZE is the size of
715 STRINGTAB. SYMFILE_NAME is the name of the file we are reading from
716 and ADDR is its relocated address (if incremental) or 0 (if not). */
717
718 static void
719 read_dbx_symtab (addr, objfile, stringtab, stringtab_size, nlistlen,
720 text_addr, text_size)
721 CORE_ADDR addr;
722 struct objfile *objfile;
723 register char *stringtab;
724 register long stringtab_size;
725 register int nlistlen;
726 CORE_ADDR text_addr;
727 int text_size;
728 {
729 register struct internal_nlist *bufp;
730 register char *namestring;
731 int nsl;
732 int past_first_source_file = 0;
733 CORE_ADDR last_o_file_start = 0;
734 struct cleanup *old_chain;
735 bfd *abfd;
736
737 /* End of the text segment of the executable file. */
738 CORE_ADDR end_of_text_addr;
739
740 /* Current partial symtab */
741 struct partial_symtab *pst;
742
743 /* List of current psymtab's include files */
744 char **psymtab_include_list;
745 int includes_allocated;
746 int includes_used;
747
748 /* Index within current psymtab dependency list */
749 struct partial_symtab **dependency_list;
750 int dependencies_used, dependencies_allocated;
751
752 stringtab_global = stringtab;
753
754 pst = (struct partial_symtab *) 0;
755
756 includes_allocated = 30;
757 includes_used = 0;
758 psymtab_include_list = (char **) alloca (includes_allocated *
759 sizeof (char *));
760
761 dependencies_allocated = 30;
762 dependencies_used = 0;
763 dependency_list =
764 (struct partial_symtab **) alloca (dependencies_allocated *
765 sizeof (struct partial_symtab *));
766
767 old_chain = make_cleanup (free_objfile, objfile);
768
769 /* Init bincl list */
770 init_bincl_list (20, objfile);
771 make_cleanup (free_bincl_list, objfile);
772
773 last_source_file = 0;
774
775 #ifdef END_OF_TEXT_DEFAULT
776 end_of_text_addr = END_OF_TEXT_DEFAULT;
777 #else
778 end_of_text_addr = text_addr + addr + text_size; /* Relocate */
779 #endif
780
781 symfile_bfd = objfile->obfd; /* For next_text_symbol */
782 abfd = objfile->obfd;
783 symbuf_end = symbuf_idx = 0;
784 next_symbol_text_func = dbx_next_symbol_text;
785
786 for (symnum = 0; symnum < nlistlen; symnum++)
787 {
788 /* Get the symbol for this run and pull out some info */
789 QUIT; /* allow this to be interruptable */
790 if (symbuf_idx == symbuf_end)
791 fill_symbuf (abfd);
792 bufp = &symbuf[symbuf_idx++];
793
794 /*
795 * Special case to speed up readin.
796 */
797 if (bufp->n_type == (unsigned char)N_SLINE) continue;
798
799 SWAP_SYMBOL (bufp, abfd);
800
801 /* Ok. There is a lot of code duplicated in the rest of this
802 switch statement (for efficiency reasons). Since I don't
803 like duplicating code, I will do my penance here, and
804 describe the code which is duplicated:
805
806 *) The assignment to namestring.
807 *) The call to strchr.
808 *) The addition of a partial symbol the the two partial
809 symbol lists. This last is a large section of code, so
810 I've imbedded it in the following macro.
811 */
812
813 /* Set namestring based on bufp. If the string table index is invalid,
814 give a fake name, and print a single error message per symbol file read,
815 rather than abort the symbol reading or flood the user with messages. */
816 #define SET_NAMESTRING()\
817 if (((unsigned)bufp->n_strx) >= stringtab_size) { \
818 complain (&string_table_offset_complaint, (char *) symnum); \
819 namestring = "foo"; \
820 } else \
821 namestring = bufp->n_strx + stringtab
822
823 #define CUR_SYMBOL_TYPE bufp->n_type
824 #define CUR_SYMBOL_VALUE bufp->n_value
825 #define DBXREAD_ONLY
826 #define START_PSYMTAB(ofile,addr,fname,low,symoff,global_syms,static_syms)\
827 start_psymtab(ofile, addr, fname, low, symoff, global_syms, static_syms)
828 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps)\
829 end_psymtab(pst,ilist,ninc,c_off,c_text,dep_list,n_deps)
830
831 #include "partial-stab.h"
832 }
833
834 /* If there's stuff to be cleaned up, clean it up. */
835 if (nlistlen > 0 /* We have some syms */
836 && entry_point < bufp->n_value
837 && entry_point >= last_o_file_start)
838 {
839 startup_file_start = last_o_file_start;
840 startup_file_end = bufp->n_value;
841 }
842
843 if (pst)
844 {
845 end_psymtab (pst, psymtab_include_list, includes_used,
846 symnum * symbol_size, end_of_text_addr,
847 dependency_list, dependencies_used);
848 }
849
850 free_bincl_list (objfile);
851 discard_cleanups (old_chain);
852 }
853
854 /* Allocate and partially fill a partial symtab. It will be
855 completely filled at the end of the symbol list.
856
857 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
858 is the address relative to which its symbols are (incremental) or 0
859 (normal). */
860
861
862 struct partial_symtab *
863 start_psymtab (objfile, addr,
864 filename, textlow, ldsymoff, global_syms, static_syms)
865 struct objfile *objfile;
866 CORE_ADDR addr;
867 char *filename;
868 CORE_ADDR textlow;
869 int ldsymoff;
870 struct partial_symbol *global_syms;
871 struct partial_symbol *static_syms;
872 {
873 struct partial_symtab *result =
874 start_psymtab_common(objfile, addr,
875 filename, textlow, global_syms, static_syms);
876
877 result->read_symtab_private = (char *)
878 obstack_alloc (&objfile -> psymbol_obstack, sizeof (struct symloc));
879 LDSYMOFF(result) = ldsymoff;
880 result->read_symtab = dbx_psymtab_to_symtab;
881
882 return result;
883 }
884
885 /* Close off the current usage of a partial_symbol table entry. This
886 involves setting the correct number of includes (with a realloc),
887 setting the high text mark, setting the symbol length in the
888 executable, and setting the length of the global and static lists
889 of psymbols.
890
891 The global symbols and static symbols are then seperately sorted.
892
893 Then the partial symtab is put on the global list.
894 *** List variables and peculiarities of same. ***
895 */
896
897 void
898 end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
899 capping_text, dependency_list, number_dependencies)
900 struct partial_symtab *pst;
901 char **include_list;
902 int num_includes;
903 int capping_symbol_offset;
904 CORE_ADDR capping_text;
905 struct partial_symtab **dependency_list;
906 int number_dependencies;
907 /* struct partial_symbol *capping_global, *capping_static;*/
908 {
909 int i;
910 struct objfile *objfile = pst -> objfile;
911
912 if (capping_symbol_offset != -1)
913 LDSYMLEN(pst) = capping_symbol_offset - LDSYMOFF(pst);
914 pst->texthigh = capping_text;
915
916 pst->n_global_syms =
917 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
918 pst->n_static_syms =
919 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
920
921 pst->number_of_dependencies = number_dependencies;
922 if (number_dependencies)
923 {
924 pst->dependencies = (struct partial_symtab **)
925 obstack_alloc (&objfile->psymbol_obstack,
926 number_dependencies * sizeof (struct partial_symtab *));
927 memcpy (pst->dependencies, dependency_list,
928 number_dependencies * sizeof (struct partial_symtab *));
929 }
930 else
931 pst->dependencies = 0;
932
933 for (i = 0; i < num_includes; i++)
934 {
935 struct partial_symtab *subpst =
936 allocate_psymtab (include_list[i], objfile);
937
938 subpst->addr = pst->addr;
939 subpst->read_symtab_private =
940 (char *) obstack_alloc (&objfile->psymbol_obstack,
941 sizeof (struct symloc));
942 LDSYMOFF(subpst) =
943 LDSYMLEN(subpst) =
944 subpst->textlow =
945 subpst->texthigh = 0;
946
947 /* We could save slight bits of space by only making one of these,
948 shared by the entire set of include files. FIXME-someday. */
949 subpst->dependencies = (struct partial_symtab **)
950 obstack_alloc (&objfile->psymbol_obstack,
951 sizeof (struct partial_symtab *));
952 subpst->dependencies[0] = pst;
953 subpst->number_of_dependencies = 1;
954
955 subpst->globals_offset =
956 subpst->n_global_syms =
957 subpst->statics_offset =
958 subpst->n_static_syms = 0;
959
960 subpst->readin = 0;
961 subpst->symtab = 0;
962 subpst->read_symtab = dbx_psymtab_to_symtab;
963 }
964
965 sort_pst_symbols (pst);
966
967 /* If there is already a psymtab or symtab for a file of this name, remove it.
968 (If there is a symtab, more drastic things also happen.)
969 This happens in VxWorks. */
970 free_named_symtabs (pst->filename);
971
972 if (num_includes == 0
973 && number_dependencies == 0
974 && pst->n_global_syms == 0
975 && pst->n_static_syms == 0) {
976 /* Throw away this psymtab, it's empty. We can't deallocate it, since
977 it is on the obstack, but we can forget to chain it on the list. */
978 ;
979 }
980 }
981 \f
982 static void
983 psymtab_to_symtab_1 (pst, stringtab, stringtab_size, sym_offset)
984 struct partial_symtab *pst;
985 char *stringtab;
986 int stringtab_size;
987 int sym_offset;
988 {
989 struct cleanup *old_chain;
990 int i;
991
992 if (!pst)
993 return;
994
995 if (pst->readin)
996 {
997 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
998 pst->filename);
999 return;
1000 }
1001
1002 /* Read in all partial symtabs on which this one is dependent */
1003 for (i = 0; i < pst->number_of_dependencies; i++)
1004 if (!pst->dependencies[i]->readin)
1005 {
1006 /* Inform about additional files that need to be read in. */
1007 if (info_verbose)
1008 {
1009 fputs_filtered (" ", stdout);
1010 wrap_here ("");
1011 fputs_filtered ("and ", stdout);
1012 wrap_here ("");
1013 printf_filtered ("%s...", pst->dependencies[i]->filename);
1014 wrap_here (""); /* Flush output */
1015 fflush (stdout);
1016 }
1017 psymtab_to_symtab_1 (pst->dependencies[i],
1018 stringtab, stringtab_size, sym_offset);
1019 }
1020
1021 if (LDSYMLEN(pst)) /* Otherwise it's a dummy */
1022 {
1023 /* Init stuff necessary for reading in symbols */
1024 buildsym_init ();
1025 old_chain = make_cleanup (really_free_pendings, 0);
1026
1027 /* Read in this files symbols */
1028 bfd_seek (pst->objfile->obfd, sym_offset, L_SET);
1029 pst->symtab =
1030 read_ofile_symtab (pst->objfile, stringtab, stringtab_size,
1031 LDSYMOFF(pst),
1032 LDSYMLEN(pst), pst->textlow,
1033 pst->texthigh - pst->textlow, pst->addr);
1034 sort_symtab_syms (pst->symtab);
1035
1036 do_cleanups (old_chain);
1037 }
1038
1039 pst->readin = 1;
1040 }
1041
1042 /*
1043 * Read in all of the symbols for a given psymtab for real.
1044 * Be verbose about it if the user wants that.
1045 */
1046 static void
1047 dbx_psymtab_to_symtab (pst)
1048 struct partial_symtab *pst;
1049 {
1050 char *stringtab;
1051 int stsize, val;
1052 bfd *sym_bfd;
1053 long st_temp;
1054
1055 if (!pst)
1056 return;
1057
1058 if (pst->readin)
1059 {
1060 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1061 pst->filename);
1062 return;
1063 }
1064
1065 if (LDSYMLEN(pst) || pst->number_of_dependencies)
1066 {
1067 /* Print the message now, before reading the string table,
1068 to avoid disconcerting pauses. */
1069 if (info_verbose)
1070 {
1071 printf_filtered ("Reading in symbols for %s...", pst->filename);
1072 fflush (stdout);
1073 }
1074
1075 sym_bfd = pst->objfile->obfd;
1076
1077 /* We keep the string table for the main symfile resident in memory, but
1078 not the string table for any other symbol files. */
1079 if (symfile_objfile != pst->objfile)
1080 {
1081 /* Read in the string table */
1082
1083 /* FIXME, this uses internal BFD variables. See above in
1084 dbx_symbol_file_open where the macro is defined! */
1085 bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
1086
1087 val = bfd_read (&st_temp, sizeof st_temp, 1, sym_bfd);
1088 if (val < 0)
1089 perror_with_name (pst->objfile->name);
1090 stsize = bfd_h_get_32 (sym_bfd, (unsigned char *)&st_temp);
1091 #if 0
1092 /* BFD doesn't provide a way to know the total file size, sigh */
1093 struct stat statbuf;
1094 if (fstat (desc, &statbuf) < 0)
1095 perror_with_name (pst->objfile->name);
1096
1097 if (stsize >= 0 && stsize < statbuf.st_size)
1098 #else
1099 if (stsize >= 0)
1100 #endif
1101 {
1102 #ifdef BROKEN_LARGE_ALLOCA
1103 stringtab = (char *) (*pst->objfile->xmalloc) (stsize);
1104 make_cleanup (pst->objfile->free, stringtab);
1105 #else
1106 stringtab = (char *) alloca (stsize);
1107 #endif
1108 }
1109 else
1110 stringtab = NULL;
1111 if (stringtab == NULL && stsize != 0)
1112 error ("ridiculous string table size: %d bytes", stsize);
1113
1114 /* FIXME, this uses internal BFD variables. See above in
1115 dbx_symbol_file_open where the macro is defined! */
1116 val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
1117 if (val < 0)
1118 perror_with_name (pst->objfile->name);
1119 val = bfd_read (stringtab, stsize, 1, sym_bfd);
1120 if (val < 0)
1121 perror_with_name (pst->objfile->name);
1122 }
1123 else
1124 {
1125 stringtab = symfile_string_table;
1126 stsize = symfile_string_table_size;
1127 }
1128
1129 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
1130 symbol_size = obj_symbol_entry_size (sym_bfd);
1131
1132 next_symbol_text_func = dbx_next_symbol_text;
1133
1134 /* FIXME, this uses internal BFD variables. See above in
1135 dbx_symbol_file_open where the macro is defined! */
1136 psymtab_to_symtab_1 (pst, stringtab, stsize,
1137 SYMBOL_TABLE_OFFSET);
1138
1139 /* Match with global symbols. This only needs to be done once,
1140 after all of the symtabs and dependencies have been read in. */
1141 scan_file_globals (pst->objfile);
1142
1143 /* Finish up the debug error message. */
1144 if (info_verbose)
1145 printf_filtered ("done.\n");
1146 }
1147 }
1148
1149 /*
1150 * Read in a defined section of a specific object file's symbols.
1151 *
1152 * DESC is the file descriptor for the file, positioned at the
1153 * beginning of the symtab
1154 * STRINGTAB is a pointer to the files string
1155 * table, already read in
1156 * SYM_OFFSET is the offset within the file of
1157 * the beginning of the symbols we want to read, NUM_SUMBOLS is the
1158 * number of symbols to read
1159 * TEXT_OFFSET is the beginning of the text segment we are reading symbols for
1160 * TEXT_SIZE is the size of the text segment read in.
1161 * OFFSET is a relocation offset which gets added to each symbol
1162 */
1163
1164 static struct symtab *
1165 read_ofile_symtab (objfile, stringtab, stringtab_size, sym_offset,
1166 sym_size, text_offset, text_size, offset)
1167 struct objfile *objfile;
1168 register char *stringtab;
1169 unsigned int stringtab_size;
1170 int sym_offset;
1171 int sym_size;
1172 CORE_ADDR text_offset;
1173 int text_size;
1174 int offset;
1175 {
1176 register char *namestring;
1177 register struct internal_nlist *bufp;
1178 unsigned char type;
1179 unsigned max_symnum;
1180 register bfd *abfd;
1181
1182 current_objfile = objfile;
1183 subfile_stack = 0;
1184
1185 stringtab_global = stringtab;
1186 last_source_file = 0;
1187
1188 abfd = objfile->obfd;
1189 symfile_bfd = objfile->obfd; /* Implicit param to next_text_symbol */
1190 our_objfile = objfile; /* For end_symtab calls in process_one_symbol */
1191 symbuf_end = symbuf_idx = 0;
1192
1193 /* It is necessary to actually read one symbol *before* the start
1194 of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
1195 occurs before the N_SO symbol.
1196
1197 Detecting this in read_dbx_symtab
1198 would slow down initial readin, so we look for it here instead. */
1199 if (sym_offset >= (int)symbol_size)
1200 {
1201 bfd_seek (symfile_bfd, sym_offset - symbol_size, L_INCR);
1202 fill_symbuf (abfd);
1203 bufp = &symbuf[symbuf_idx++];
1204 SWAP_SYMBOL (bufp, abfd);
1205
1206 SET_NAMESTRING ();
1207
1208 processing_gcc_compilation =
1209 (bufp->n_type == N_TEXT
1210 && (strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL) == 0
1211 || strcmp(namestring, GCC2_COMPILED_FLAG_SYMBOL) == 0));
1212 }
1213 else
1214 {
1215 /* The N_SO starting this symtab is the first symbol, so we
1216 better not check the symbol before it. I'm not this can
1217 happen, but it doesn't hurt to check for it. */
1218 bfd_seek (symfile_bfd, sym_offset, L_INCR);
1219 processing_gcc_compilation = 0;
1220 }
1221
1222 if (symbuf_idx == symbuf_end)
1223 fill_symbuf (abfd);
1224 bufp = &symbuf[symbuf_idx];
1225 if (bufp->n_type != (unsigned char)N_SO)
1226 error("First symbol in segment of executable not a source symbol");
1227
1228 max_symnum = sym_size / symbol_size;
1229
1230 for (symnum = 0;
1231 symnum < max_symnum;
1232 symnum++)
1233 {
1234 QUIT; /* Allow this to be interruptable */
1235 if (symbuf_idx == symbuf_end)
1236 fill_symbuf(abfd);
1237 bufp = &symbuf[symbuf_idx++];
1238 SWAP_SYMBOL (bufp, abfd);
1239
1240 type = bufp->n_type;
1241 if (type == (unsigned char)N_CATCH)
1242 {
1243 /* N_CATCH is not fixed up by the linker, and unfortunately,
1244 there's no other place to put it in the .stab map. */
1245 bufp->n_value += text_offset - offset;
1246 }
1247
1248 SET_NAMESTRING ();
1249
1250 if (type & N_STAB) {
1251 process_one_symbol (type, bufp->n_desc, bufp->n_value,
1252 namestring, offset);
1253 /* our_objfile is an implicit parameter. */
1254 }
1255 /* We skip checking for a new .o or -l file; that should never
1256 happen in this routine. */
1257 else if (type == N_TEXT
1258 && (strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL) == 0
1259 || strcmp (namestring, GCC2_COMPILED_FLAG_SYMBOL) == 0))
1260 /* I don't think this code will ever be executed, because
1261 the GCC_COMPILED_FLAG_SYMBOL usually is right before
1262 the N_SO symbol which starts this source file.
1263 However, there is no reason not to accept
1264 the GCC_COMPILED_FLAG_SYMBOL anywhere. */
1265 processing_gcc_compilation = 1;
1266 else if (type & N_EXT || type == (unsigned char)N_TEXT
1267 || type == (unsigned char)N_NBTEXT
1268 ) {
1269 /* Global symbol: see if we came across a dbx defintion for
1270 a corresponding symbol. If so, store the value. Remove
1271 syms from the chain when their values are stored, but
1272 search the whole chain, as there may be several syms from
1273 different files with the same name. */
1274 /* This is probably not true. Since the files will be read
1275 in one at a time, each reference to a global symbol will
1276 be satisfied in each file as it appears. So we skip this
1277 section. */
1278 ;
1279 }
1280 }
1281
1282 current_objfile = NULL;
1283 return (end_symtab (text_offset + text_size, 0, 0, objfile));
1284 }
1285 \f
1286 /* This handles a single symbol from the symbol-file, building symbols
1287 into a GDB symtab. It takes these arguments and an implicit argument.
1288
1289 TYPE is the type field of the ".stab" symbol entry.
1290 DESC is the desc field of the ".stab" entry.
1291 VALU is the value field of the ".stab" entry.
1292 NAME is the symbol name, in our address space.
1293 OFFSET is the amount by which this object file was relocated
1294 when it was loaded into memory. All symbols that refer
1295 to memory locations need to be offset by this amount.
1296
1297 The implicit argument is:
1298 OUR_OBJFILE is the object file from which we are reading symbols.
1299 It is used in end_symtab. */
1300
1301 void
1302 process_one_symbol (type, desc, valu, name, offset)
1303 int type, desc;
1304 CORE_ADDR valu;
1305 char *name;
1306 int offset;
1307 {
1308 #ifndef SUN_FIXED_LBRAC_BUG
1309 /* This records the last pc address we've seen. We depend on there being
1310 an SLINE or FUN or SO before the first LBRAC, since the variable does
1311 not get reset in between reads of different symbol files. */
1312 static CORE_ADDR last_pc_address;
1313 #endif
1314 register struct context_stack *new;
1315 char *colon_pos;
1316
1317 /* Something is wrong if we see real data before
1318 seeing a source file name. */
1319
1320 if (last_source_file == 0 && type != (unsigned char)N_SO)
1321 {
1322 /* Currently this ignores N_ENTRY on Gould machines, N_NSYM on machines
1323 where that code is defined. */
1324 if (IGNORE_SYMBOL (type))
1325 return;
1326
1327 /* FIXME, this should not be an error, since it precludes extending
1328 the symbol table information in this way... */
1329 error ("Invalid symbol data: does not start by identifying a source file.");
1330 }
1331
1332 switch (type)
1333 {
1334 case N_FUN:
1335 case N_FNAME:
1336 #if 0
1337 /* It seems that the Sun ANSI C compiler (acc) replaces N_FUN with N_GSYM and
1338 N_STSYM with a type code of f or F. Can't enable this until we get some
1339 stuff straightened out with psymtabs. */
1340
1341 case N_GSYM:
1342 case N_STSYM:
1343 #endif /* 0 */
1344
1345 valu += offset; /* Relocate for dynamic loading */
1346
1347 /* Either of these types of symbols indicates the start of
1348 a new function. We must process its "name" normally for dbx,
1349 but also record the start of a new lexical context, and possibly
1350 also the end of the lexical context for the previous function. */
1351 /* This is not always true. This type of symbol may indicate a
1352 text segment variable. */
1353
1354 colon_pos = strchr (name, ':');
1355 if (!colon_pos++
1356 || (*colon_pos != 'f' && *colon_pos != 'F'))
1357 {
1358 define_symbol (valu, name, desc, type, our_objfile);
1359 break;
1360 }
1361
1362 #ifndef SUN_FIXED_LBRAC_BUG
1363 last_pc_address = valu; /* Save for SunOS bug circumcision */
1364 #endif
1365
1366 within_function = 1;
1367 if (context_stack_depth > 0)
1368 {
1369 new = pop_context ();
1370 /* Make a block for the local symbols within. */
1371 finish_block (new->name, &local_symbols, new->old_blocks,
1372 new->start_addr, valu, our_objfile);
1373 }
1374 /* Stack must be empty now. */
1375 if (context_stack_depth != 0)
1376 complain (&lbrac_unmatched_complaint, (char *) symnum);
1377
1378 new = push_context (0, valu);
1379 new->name = define_symbol (valu, name, desc, type, our_objfile);
1380 break;
1381
1382 case N_CATCH:
1383 /* Record the address at which this catch takes place. */
1384 define_symbol (valu+offset, name, desc, type, our_objfile);
1385 break;
1386
1387 case N_LBRAC:
1388 /* This "symbol" just indicates the start of an inner lexical
1389 context within a function. */
1390
1391 #if defined (BLOCK_ADDRESS_ABSOLUTE)
1392 valu += offset; /* Relocate for dynamic loading */
1393 #else
1394 /* On most machines, the block addresses are relative to the
1395 N_SO, the linker did not relocate them (sigh). */
1396 valu += last_source_start_addr;
1397 #endif
1398
1399 #ifndef SUN_FIXED_LBRAC_BUG
1400 if (valu < last_pc_address) {
1401 /* Patch current LBRAC pc value to match last handy pc value */
1402 complain (&lbrac_complaint, 0);
1403 valu = last_pc_address;
1404 }
1405 #endif
1406 new = push_context (desc, valu);
1407 break;
1408
1409 case N_RBRAC:
1410 /* This "symbol" just indicates the end of an inner lexical
1411 context that was started with N_LBRAC. */
1412
1413 #if defined (BLOCK_ADDRESS_ABSOLUTE)
1414 valu += offset; /* Relocate for dynamic loading */
1415 #else
1416 /* On most machines, the block addresses are relative to the
1417 N_SO, the linker did not relocate them (sigh). */
1418 valu += last_source_start_addr;
1419 #endif
1420
1421 new = pop_context();
1422 if (desc != new->depth)
1423 complain (&lbrac_mismatch_complaint, (char *) symnum);
1424
1425 /* Some compilers put the variable decls inside of an
1426 LBRAC/RBRAC block. This macro should be nonzero if this
1427 is true. DESC is N_DESC from the N_RBRAC symbol.
1428 GCC_P is true if we've detected the GCC_COMPILED_SYMBOL
1429 or the GCC2_COMPILED_SYMBOL. */
1430 #if !defined (VARIABLES_INSIDE_BLOCK)
1431 #define VARIABLES_INSIDE_BLOCK(desc, gcc_p) 0
1432 #endif
1433
1434 /* Can only use new->locals as local symbols here if we're in
1435 gcc or on a machine that puts them before the lbrack. */
1436 if (!VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation))
1437 local_symbols = new->locals;
1438
1439 /* If this is not the outermost LBRAC...RBRAC pair in the
1440 function, its local symbols preceded it, and are the ones
1441 just recovered from the context stack. Defined the block for them.
1442
1443 If this is the outermost LBRAC...RBRAC pair, there is no
1444 need to do anything; leave the symbols that preceded it
1445 to be attached to the function's own block. However, if
1446 it is so, we need to indicate that we just moved outside
1447 of the function. */
1448 if (local_symbols
1449 && (context_stack_depth
1450 > !VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation)))
1451 {
1452 /* FIXME Muzzle a compiler bug that makes end < start. */
1453 if (new->start_addr > valu)
1454 {
1455 complain(&lbrac_rbrac_complaint, 0);
1456 new->start_addr = valu;
1457 }
1458 /* Make a block for the local symbols within. */
1459 finish_block (0, &local_symbols, new->old_blocks,
1460 new->start_addr, valu, our_objfile);
1461 }
1462 else
1463 {
1464 within_function = 0;
1465 }
1466 if (VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation))
1467 /* Now pop locals of block just finished. */
1468 local_symbols = new->locals;
1469 break;
1470
1471 case N_FN:
1472 case N_FN_SEQ:
1473 /* This kind of symbol indicates the start of an object file. */
1474 valu += offset; /* Relocate for dynamic loading */
1475 break;
1476
1477 case N_SO:
1478 /* This type of symbol indicates the start of data
1479 for one source file.
1480 Finish the symbol table of the previous source file
1481 (if any) and start accumulating a new symbol table. */
1482 valu += offset; /* Relocate for dynamic loading */
1483
1484 #ifndef SUN_FIXED_LBRAC_BUG
1485 last_pc_address = valu; /* Save for SunOS bug circumcision */
1486 #endif
1487
1488 #ifdef PCC_SOL_BROKEN
1489 /* pcc bug, occasionally puts out SO for SOL. */
1490 if (context_stack_depth > 0)
1491 {
1492 start_subfile (name, NULL);
1493 break;
1494 }
1495 #endif
1496 if (last_source_file)
1497 {
1498 /* Check if previous symbol was also an N_SO (with some
1499 sanity checks). If so, that one was actually the directory
1500 name, and the current one is the real file name.
1501 Patch things up. */
1502 if (previous_stab_code == N_SO
1503 && current_subfile && current_subfile->dirname == NULL
1504 && current_subfile->name != NULL
1505 && current_subfile->name[strlen(current_subfile->name)-1] == '/')
1506 {
1507 current_subfile->dirname = current_subfile->name;
1508 current_subfile->name =
1509 obsavestring (name, strlen (name),
1510 &our_objfile -> symbol_obstack);
1511 break;
1512 }
1513 (void) end_symtab (valu, 0, 0, our_objfile);
1514 }
1515 start_symtab (name, NULL, valu);
1516 break;
1517
1518
1519 case N_SOL:
1520 /* This type of symbol indicates the start of data for
1521 a sub-source-file, one whose contents were copied or
1522 included in the compilation of the main source file
1523 (whose name was given in the N_SO symbol.) */
1524 valu += offset; /* Relocate for dynamic loading */
1525 start_subfile (name, NULL);
1526 break;
1527
1528 case N_BINCL:
1529 push_subfile ();
1530 add_new_header_file (name, valu);
1531 start_subfile (name, NULL);
1532 break;
1533
1534 case N_EINCL:
1535 start_subfile (pop_subfile (), NULL);
1536 break;
1537
1538 case N_EXCL:
1539 add_old_header_file (name, valu);
1540 break;
1541
1542 case N_SLINE:
1543 /* This type of "symbol" really just records
1544 one line-number -- core-address correspondence.
1545 Enter it in the line list for this symbol table. */
1546 valu += offset; /* Relocate for dynamic loading */
1547 #ifndef SUN_FIXED_LBRAC_BUG
1548 last_pc_address = valu; /* Save for SunOS bug circumcision */
1549 #endif
1550 record_line (current_subfile, desc, valu);
1551 break;
1552
1553 case N_BCOMM:
1554 if (common_block)
1555 error ("Invalid symbol data: common within common at symtab pos %d",
1556 symnum);
1557 common_block = local_symbols;
1558 common_block_i = local_symbols ? local_symbols->nsyms : 0;
1559 break;
1560
1561 case N_ECOMM:
1562 /* Symbols declared since the BCOMM are to have the common block
1563 start address added in when we know it. common_block points to
1564 the first symbol after the BCOMM in the local_symbols list;
1565 copy the list and hang it off the symbol for the common block name
1566 for later fixup. */
1567 {
1568 int i;
1569 struct symbol *sym =
1570 (struct symbol *) (*our_objfile -> xmalloc) (sizeof (struct symbol));
1571 bzero (sym, sizeof *sym);
1572 SYMBOL_NAME (sym) = savestring (name, strlen (name));
1573 SYMBOL_CLASS (sym) = LOC_BLOCK;
1574 SYMBOL_NAMESPACE (sym) = (enum namespace)((long)
1575 copy_pending (local_symbols, common_block_i, common_block));
1576 i = hashname (SYMBOL_NAME (sym));
1577 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
1578 global_sym_chain[i] = sym;
1579 common_block = 0;
1580 break;
1581 }
1582
1583 /* The following symbol types need to have the offset added to their
1584 value; then we process symbol definitions in the name. */
1585 case N_STSYM: /* Global symbol */
1586 case N_LCSYM: /* Local symbol */
1587 case N_DSLINE: /* Source line number, data seg */
1588 case N_BSLINE: /* Source line number, bss seg */
1589 /* N_BROWS: overlaps with N_BSLINE */
1590 case N_ENTRY: /* Alternate entry point */
1591 valu += offset; /* Relocate for dynamic loading */
1592 /* FALL THROUGH */
1593
1594 /* The following symbol types don't need the address field relocated,
1595 since it is either unused, or is absolute. */
1596 case N_GSYM: /* Global variable */
1597 case N_NSYMS: /* Number of symbols (ultrix) */
1598 case N_NOMAP: /* No map? (ultrix) */
1599 case N_RSYM: /* Register variable */
1600 case N_DEFD: /* Modula-2 GNU module dependency */
1601 case N_SSYM: /* Struct or union element */
1602 case N_LSYM: /* Local symbol in stack */
1603 case N_PSYM: /* Parameter variable */
1604 case N_LENG: /* Length of preceding symbol type */
1605 if (name)
1606 define_symbol (valu, name, desc, type, our_objfile);
1607 break;
1608
1609 /* The following symbol types we don't know how to process. Handle
1610 them in a "default" way, but complain to people who care. */
1611 default:
1612 case N_EHDECL: /* Exception handler name */
1613 case N_MAIN: /* Name of main routine (not used in C) */
1614 case N_PC: /* Global symbol in Pascal */
1615 case N_M2C: /* Modula-2 compilation unit */
1616 /* N_MOD2: overlaps with N_EHDECL */
1617 case N_SCOPE: /* Modula-2 scope information */
1618 case N_ECOML: /* End common (local name) */
1619 case N_NBTEXT: /* Gould Non-Base-Register symbols??? */
1620 case N_NBDATA:
1621 case N_NBBSS:
1622 case N_NBSTS:
1623 case N_NBLCS:
1624 complain (&unknown_symtype_complaint, local_hex_string(type));
1625 if (name)
1626 define_symbol (valu, name, desc, type, our_objfile);
1627 }
1628
1629 previous_stab_code = type;
1630 }
1631 \f
1632 /* Copy a pending list, used to record the contents of a common
1633 block for later fixup. */
1634 static struct pending *
1635 copy_pending (beg, begi, end)
1636 struct pending *beg;
1637 int begi;
1638 struct pending *end;
1639 {
1640 struct pending *new = 0;
1641 struct pending *next;
1642
1643 for (next = beg; next != 0 && (next != end || begi < end->nsyms);
1644 next = next->next, begi = 0)
1645 {
1646 register int j;
1647 for (j = begi; j < next->nsyms; j++)
1648 add_symbol_to_list (next->symbol[j], &new);
1649 }
1650 return new;
1651 }
1652 \f
1653 /* Register our willingness to decode symbols for SunOS and a.out and
1654 b.out files handled by BFD... */
1655 static struct sym_fns sunos_sym_fns = {"sunOs", 6,
1656 dbx_new_init, dbx_symfile_init, dbx_symfile_read};
1657
1658 static struct sym_fns aout_sym_fns = {"a.out", 5,
1659 dbx_new_init, dbx_symfile_init, dbx_symfile_read};
1660
1661 static struct sym_fns bout_sym_fns = {"b.out", 5,
1662 dbx_new_init, dbx_symfile_init, dbx_symfile_read};
1663
1664 void
1665 _initialize_dbxread ()
1666 {
1667 add_symtab_fns(&sunos_sym_fns);
1668 add_symtab_fns(&aout_sym_fns);
1669 add_symtab_fns(&bout_sym_fns);
1670 }
This page took 0.365141 seconds and 5 git commands to generate.