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