1 /* Read dbx symbol tables and convert to internal format, for GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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. */
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
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 */
39 #include <sys/types.h>
46 #include <sys/param.h>
53 #include "breakpoint.h"
56 #include "gdbcore.h" /* for bfd stuff */
57 #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
61 #include "aout/aout64.h"
62 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native, now */
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. */
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 */
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.
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. */
88 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
89 #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
96 /* Macro to determine which symbols to ignore when reading the first symbol
97 of a file. Some machines override this definition. */
99 /* This code is used on Ultrix systems. Ignore it */
100 #define IGNORE_SYMBOL(type) (type == (int)N_NSYMS)
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."
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."
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. */
118 #ifndef BELIEVE_PCC_PROMOTION
119 #define BELIEVE_PCC_PROMOTION 0
122 /* Nonzero means give verbose info on gdb action. From main.c. */
123 extern int info_verbose
;
125 /* The BFD for this file -- implicit parameter to next_symbol_text. */
127 static bfd
*symfile_bfd
;
129 /* The objfile for this file -- only good in process_one_symbol(). */
131 static struct objfile
*our_objfile
;
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. */
137 static char *symfile_string_table
;
138 static int symfile_string_table_size
;
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. */
144 static unsigned symbol_size
;
146 /* Complaints about the symbols we have encountered. */
148 struct complaint lbrac_complaint
=
149 {"bad block start address patched", 0, 0};
151 struct complaint string_table_offset_complaint
=
152 {"bad string table offset in symbol %d", 0, 0};
154 struct complaint unknown_symtype_complaint
=
155 {"unknown symbol type %s", 0, 0};
157 struct complaint lbrac_rbrac_complaint
=
158 {"block start larger than block end", 0, 0};
160 struct complaint lbrac_unmatched_complaint
=
161 {"unmatched N_LBRAC before symtab pos %d", 0, 0};
163 struct complaint lbrac_mismatch_complaint
=
164 {"N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d", 0, 0};
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. */
171 struct header_file_location
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 */
179 /* The actual list and controling variables */
180 static struct header_file_location
*bincl_list
, *next_bincl
;
181 static int bincls_allocated
;
183 /* Local function prototypes */
186 free_and_init_header_files
PARAMS ((void));
188 static struct pending
*
189 copy_pending
PARAMS ((struct pending
*, int, struct pending
*));
191 static struct symtab
*
192 read_ofile_symtab
PARAMS ((struct objfile
*, char *, unsigned int, int, int,
193 CORE_ADDR
, int, int));
196 dbx_psymtab_to_symtab
PARAMS ((struct partial_symtab
*));
199 psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*, char *, int, int));
202 read_dbx_symtab
PARAMS ((CORE_ADDR
, struct objfile
*, char *, long, int,
206 free_bincl_list
PARAMS ((struct objfile
*));
208 static struct partial_symtab
*
209 find_corresponding_bincl_psymtab
PARAMS ((char *, int));
212 add_bincl_to_list
PARAMS ((struct partial_symtab
*, char *, int));
215 init_bincl_list
PARAMS ((int, struct objfile
*));
218 init_psymbol_list
PARAMS ((int, struct objfile
*));
221 dbx_next_symbol_text
PARAMS ((void));
224 fill_symbuf
PARAMS ((bfd
*));
227 dbx_symfile_init
PARAMS ((struct sym_fns
*));
230 dbx_new_init
PARAMS ((void));
233 dbx_symfile_read
PARAMS ((struct sym_fns
*, CORE_ADDR
, int));
236 record_minimal_symbol
PARAMS ((char *, CORE_ADDR
, int, struct objfile
*));
239 add_new_header_file
PARAMS ((char *, int));
242 add_old_header_file
PARAMS ((char *, int));
245 add_this_object_header_file
PARAMS ((int));
247 /* Free up old header file tables, and allocate new ones.
248 We're reading a new symbol file now. */
251 free_and_init_header_files ()
254 for (i
= 0; i
< n_header_files
; i
++)
255 free (header_files
[i
].name
);
256 if (header_files
) /* First time null */
258 if (this_object_header_files
) /* First time null */
259 free (this_object_header_files
);
261 n_allocated_header_files
= 10;
262 header_files
= (struct header_file
*) xmalloc (10 * sizeof (struct header_file
));
265 n_allocated_this_object_header_files
= 10;
266 this_object_header_files
= (int *) xmalloc (10 * sizeof (int));
269 /* Add header file number I for this object file
270 at the next successive FILENUM. */
273 add_this_object_header_file (i
)
276 if (n_this_object_header_files
== n_allocated_this_object_header_files
)
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));
284 this_object_header_files
[n_this_object_header_files
++] = i
;
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. */
293 add_old_header_file (name
, instance
)
297 register struct header_file
*p
= header_files
;
300 for (i
= 0; i
< n_header_files
; i
++)
301 if (!strcmp (p
[i
].name
, name
) && instance
== p
[i
].instance
)
303 add_this_object_header_file (i
);
306 error ("Invalid symbol data: \"repeated\" header file that hasn't been seen before, at symtab pos %d.",
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.
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". */
322 add_new_header_file (name
, instance
)
327 header_file_prev_index
= -1;
329 /* Make sure there is room for one more header file. */
331 if (n_header_files
== n_allocated_header_files
)
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
)));
339 /* Create an entry for this header file. */
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
*));
349 add_this_object_header_file (i
);
353 static struct type
**
354 explicit_lookup_type (real_filenum
, index
)
355 int real_filenum
, index
;
357 register struct header_file
*f
= &header_files
[real_filenum
];
359 if (index
>= f
->length
)
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);
367 return &f
->vector
[index
];
372 record_minimal_symbol (name
, address
, type
, objfile
)
376 struct objfile
*objfile
;
378 enum minimal_symbol_type ms_type
;
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;
386 case N_SETV
: ms_type
= mst_data
; break;
388 default: ms_type
= mst_unknown
; break;
391 prim_record_minimal_symbol (obsavestring (name
, strlen (name
), &objfile
-> symbol_obstack
),
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.
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). */
406 dbx_symfile_read (sf
, addr
, mainline
)
409 int mainline
; /* FIXME comments above */
411 struct dbx_symfile_info
*info
= (struct dbx_symfile_info
*) (sf
->sym_private
);
412 bfd
*sym_bfd
= sf
->objfile
->obfd
;
415 val
= bfd_seek (sf
->objfile
->obfd
, info
->symtab_offset
, L_SET
);
417 perror_with_name (sf
->objfile
->name
);
419 /* If mainline, set global string table pointers, and reinitialize global
420 partial symbol list. */
422 symfile_string_table
= info
->stringtab
;
423 symfile_string_table_size
= info
->stringtab_size
;
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
);
430 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
431 symbol_size
= obj_symbol_entry_size (sym_bfd
);
434 make_cleanup (really_free_pendings
, 0);
436 init_minimal_symbol_collection ();
437 make_cleanup (discard_minimal_symbols
, 0);
439 /* Now that the symbol table data of the executable file are all in core,
440 process them and define symbols accordingly. */
442 read_dbx_symtab (addr
- bfd_section_vma (sym_bfd
, info
->text_sect
), /*offset*/
443 sf
->objfile
, info
->stringtab
, info
->stringtab_size
,
445 bfd_section_vma (sym_bfd
, info
->text_sect
),
446 bfd_section_size (sym_bfd
, info
->text_sect
));
448 /* Install any minimal symbols that have been collected as the current
449 minimal symbols for this objfile. */
451 install_minimal_symbols (sf
-> objfile
);
453 /* Free up any memory we allocated for ourselves. */
456 (*sf
->objfile
->free
) (info
->stringtab
); /* Stringtab is only saved for mainline */
458 (*sf
->objfile
->free
) (info
);
459 sf
->sym_private
= NULL
; /* Zap pointer to our (now gone) info struct */
461 if (!have_partial_symbols ()) {
463 printf_filtered ("(no debugging symbols found)...");
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). */
475 buildsym_new_init ();
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
)
481 free (symfile_string_table
);
482 symfile_string_table
= 0;
483 symfile_string_table_size
= 0;
485 free_and_init_header_files ();
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.
495 We read the string table into malloc'd space and stash a pointer to it.
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. */
503 dbx_symfile_init (sf
)
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];
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
;
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 */
521 info
->text_sect
= bfd_get_section_by_name (sym_bfd
, ".text");
522 if (!info
->text_sect
)
524 info
->symcount
= bfd_get_symcount (sym_bfd
);
526 /* Read the string table size and check it for bogosity. */
527 val
= bfd_seek (sym_bfd
, STRING_TABLE_OFFSET
, L_SET
);
529 perror_with_name (name
);
531 val
= bfd_read (size_temp
, sizeof (long), 1, sym_bfd
);
533 perror_with_name (name
);
534 info
->stringtab_size
= bfd_h_get_32 (sym_bfd
, size_temp
);
536 if (info
->stringtab_size
>= 0)
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. */
543 info
->stringtab
= NULL
;
544 if (info
->stringtab
== NULL
&& info
->stringtab_size
!= 0)
545 error ("ridiculous string table size: %d bytes", info
->stringtab_size
);
547 /* Now read in the string table in one big gulp. */
549 val
= bfd_seek (sym_bfd
, STRING_TABLE_OFFSET
, L_SET
);
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
);
556 /* Record the position of the symbol table for later use. */
558 info
->symtab_offset
= SYMBOL_TABLE_OFFSET
;
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
;
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
;
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. */
580 fill_symbuf (sym_bfd
)
583 int nbytes
= bfd_read (symbuf
, sizeof (symbuf
), 1, sym_bfd
);
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
;
592 #define SWAP_SYMBOL(symp, abfd) \
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); \
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. */
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. */
612 dbx_next_symbol_text ()
614 if (symbuf_idx
== symbuf_end
)
615 fill_symbuf (symfile_bfd
);
617 SWAP_SYMBOL(&symbuf
[symbuf_idx
], symfile_bfd
);
618 return symbuf
[symbuf_idx
++].n_strx
+ stringtab_global
;
621 /* Initializes storage for all of the partial symbols that will be
622 created by read_dbx_symtab and subsidiaries. */
625 init_psymbol_list (total_symbols
, objfile
)
627 struct objfile
*objfile
;
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
);
635 /* Current best guess is that there are approximately a twentieth
636 of the total symbols (in a debugging file) are global or static
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
));
646 /* Initialize the list of bincls to contain none and have some
650 init_bincl_list (number
, objfile
)
652 struct objfile
*objfile
;
654 bincls_allocated
= number
;
655 next_bincl
= bincl_list
= (struct header_file_location
*)
656 (*objfile
-> xmalloc
) (bincls_allocated
* sizeof(struct header_file_location
));
659 /* Add a bincl to the list. */
662 add_bincl_to_list (pst
, name
, instance
)
663 struct partial_symtab
*pst
;
667 if (next_bincl
>= bincl_list
+ bincls_allocated
)
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
;
676 next_bincl
->pst
= pst
;
677 next_bincl
->instance
= instance
;
678 next_bincl
++->name
= name
;
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. */
685 static struct partial_symtab
*
686 find_corresponding_bincl_psymtab (name
, instance
)
690 struct header_file_location
*bincl
;
692 for (bincl
= bincl_list
; bincl
< next_bincl
; bincl
++)
693 if (bincl
->instance
== instance
694 && !strcmp (name
, bincl
->name
))
697 return (struct partial_symtab
*) 0;
700 /* Free the storage allocated for the bincl list. */
703 free_bincl_list (objfile
)
704 struct objfile
*objfile
;
706 (*objfile
-> free
) (bincl_list
);
707 bincls_allocated
= 0;
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). */
719 read_dbx_symtab (addr
, objfile
, stringtab
, stringtab_size
, nlistlen
,
720 text_addr
, text_size
)
722 struct objfile
*objfile
;
723 register char *stringtab
;
724 register long stringtab_size
;
725 register int nlistlen
;
729 register struct internal_nlist
*bufp
;
730 register char *namestring
;
732 int past_first_source_file
= 0;
733 CORE_ADDR last_o_file_start
= 0;
734 struct cleanup
*old_chain
;
737 /* End of the text segment of the executable file. */
738 CORE_ADDR end_of_text_addr
;
740 /* Current partial symtab */
741 struct partial_symtab
*pst
;
743 /* List of current psymtab's include files */
744 char **psymtab_include_list
;
745 int includes_allocated
;
748 /* Index within current psymtab dependency list */
749 struct partial_symtab
**dependency_list
;
750 int dependencies_used
, dependencies_allocated
;
752 stringtab_global
= stringtab
;
754 pst
= (struct partial_symtab
*) 0;
756 includes_allocated
= 30;
758 psymtab_include_list
= (char **) alloca (includes_allocated
*
761 dependencies_allocated
= 30;
762 dependencies_used
= 0;
764 (struct partial_symtab
**) alloca (dependencies_allocated
*
765 sizeof (struct partial_symtab
*));
767 old_chain
= make_cleanup (free_objfile
, objfile
);
769 /* Init bincl list */
770 init_bincl_list (20, objfile
);
771 make_cleanup (free_bincl_list
, objfile
);
773 last_source_file
= 0;
775 #ifdef END_OF_TEXT_DEFAULT
776 end_of_text_addr
= END_OF_TEXT_DEFAULT
;
778 end_of_text_addr
= text_addr
+ addr
+ text_size
; /* Relocate */
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
;
786 for (symnum
= 0; symnum
< nlistlen
; symnum
++)
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
)
792 bufp
= &symbuf
[symbuf_idx
++];
795 * Special case to speed up readin.
797 if (bufp
->n_type
== (unsigned char)N_SLINE
) continue;
799 SWAP_SYMBOL (bufp
, abfd
);
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:
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.
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"; \
821 namestring = bufp->n_strx + stringtab
823 #define CUR_SYMBOL_TYPE bufp->n_type
824 #define CUR_SYMBOL_VALUE bufp->n_value
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)
831 #include "partial-stab.h"
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
)
839 startup_file_start
= last_o_file_start
;
840 startup_file_end
= bufp
->n_value
;
845 end_psymtab (pst
, psymtab_include_list
, includes_used
,
846 symnum
* symbol_size
, end_of_text_addr
,
847 dependency_list
, dependencies_used
);
850 free_bincl_list (objfile
);
851 discard_cleanups (old_chain
);
854 /* Allocate and partially fill a partial symtab. It will be
855 completely filled at the end of the symbol list.
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
862 struct partial_symtab
*
863 start_psymtab (objfile
, addr
,
864 filename
, textlow
, ldsymoff
, global_syms
, static_syms
)
865 struct objfile
*objfile
;
870 struct partial_symbol
*global_syms
;
871 struct partial_symbol
*static_syms
;
873 struct partial_symtab
*result
=
874 start_psymtab_common(objfile
, addr
,
875 filename
, textlow
, global_syms
, static_syms
);
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
;
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
891 The global symbols and static symbols are then seperately sorted.
893 Then the partial symtab is put on the global list.
894 *** List variables and peculiarities of same. ***
898 end_psymtab (pst
, include_list
, num_includes
, capping_symbol_offset
,
899 capping_text
, dependency_list
, number_dependencies
)
900 struct partial_symtab
*pst
;
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;*/
910 struct objfile
*objfile
= pst
-> objfile
;
912 if (capping_symbol_offset
!= -1)
913 LDSYMLEN(pst
) = capping_symbol_offset
- LDSYMOFF(pst
);
914 pst
->texthigh
= capping_text
;
917 objfile
->global_psymbols
.next
- (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
919 objfile
->static_psymbols
.next
- (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
921 pst
->number_of_dependencies
= number_dependencies
;
922 if (number_dependencies
)
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
*));
931 pst
->dependencies
= 0;
933 for (i
= 0; i
< num_includes
; i
++)
935 struct partial_symtab
*subpst
=
936 allocate_psymtab (include_list
[i
], objfile
);
938 subpst
->addr
= pst
->addr
;
939 subpst
->read_symtab_private
=
940 (char *) obstack_alloc (&objfile
->psymbol_obstack
,
941 sizeof (struct symloc
));
945 subpst
->texthigh
= 0;
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;
955 subpst
->globals_offset
=
956 subpst
->n_global_syms
=
957 subpst
->statics_offset
=
958 subpst
->n_static_syms
= 0;
962 subpst
->read_symtab
= dbx_psymtab_to_symtab
;
965 sort_pst_symbols (pst
);
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
);
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. */
983 psymtab_to_symtab_1 (pst
, stringtab
, stringtab_size
, sym_offset
)
984 struct partial_symtab
*pst
;
989 struct cleanup
*old_chain
;
997 fprintf (stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
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
)
1006 /* Inform about additional files that need to be read in. */
1009 fputs_filtered (" ", stdout
);
1011 fputs_filtered ("and ", stdout
);
1013 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
1014 wrap_here (""); /* Flush output */
1017 psymtab_to_symtab_1 (pst
->dependencies
[i
],
1018 stringtab
, stringtab_size
, sym_offset
);
1021 if (LDSYMLEN(pst
)) /* Otherwise it's a dummy */
1023 /* Init stuff necessary for reading in symbols */
1025 old_chain
= make_cleanup (really_free_pendings
, 0);
1027 /* Read in this files symbols */
1028 bfd_seek (pst
->objfile
->obfd
, sym_offset
, L_SET
);
1030 read_ofile_symtab (pst
->objfile
, stringtab
, stringtab_size
,
1032 LDSYMLEN(pst
), pst
->textlow
,
1033 pst
->texthigh
- pst
->textlow
, pst
->addr
);
1034 sort_symtab_syms (pst
->symtab
);
1036 do_cleanups (old_chain
);
1043 * Read in all of the symbols for a given psymtab for real.
1044 * Be verbose about it if the user wants that.
1047 dbx_psymtab_to_symtab (pst
)
1048 struct partial_symtab
*pst
;
1060 fprintf (stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1065 if (LDSYMLEN(pst
) || pst
->number_of_dependencies
)
1067 /* Print the message now, before reading the string table,
1068 to avoid disconcerting pauses. */
1071 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1075 sym_bfd
= pst
->objfile
->obfd
;
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
)
1081 /* Read in the string table */
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
);
1087 val
= bfd_read (&st_temp
, sizeof st_temp
, 1, sym_bfd
);
1089 perror_with_name (pst
->objfile
->name
);
1090 stsize
= bfd_h_get_32 (sym_bfd
, (unsigned char *)&st_temp
);
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
);
1097 if (stsize
>= 0 && stsize
< statbuf
.st_size
)
1102 #ifdef BROKEN_LARGE_ALLOCA
1103 stringtab
= (char *) (*pst
->objfile
->xmalloc
) (stsize
);
1104 make_cleanup (pst
->objfile
->free
, stringtab
);
1106 stringtab
= (char *) alloca (stsize
);
1111 if (stringtab
== NULL
&& stsize
!= 0)
1112 error ("ridiculous string table size: %d bytes", stsize
);
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
);
1118 perror_with_name (pst
->objfile
->name
);
1119 val
= bfd_read (stringtab
, stsize
, 1, sym_bfd
);
1121 perror_with_name (pst
->objfile
->name
);
1125 stringtab
= symfile_string_table
;
1126 stsize
= symfile_string_table_size
;
1129 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
1130 symbol_size
= obj_symbol_entry_size (sym_bfd
);
1132 next_symbol_text_func
= dbx_next_symbol_text
;
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
);
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
);
1143 /* Finish up the debug error message. */
1145 printf_filtered ("done.\n");
1150 * Read in a defined section of a specific object file's symbols.
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
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
;
1172 CORE_ADDR text_offset
;
1176 register char *namestring
;
1177 register struct internal_nlist
*bufp
;
1179 unsigned max_symnum
;
1182 current_objfile
= objfile
;
1185 stringtab_global
= stringtab
;
1186 last_source_file
= 0;
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;
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.
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
)
1201 bfd_seek (symfile_bfd
, sym_offset
- symbol_size
, L_INCR
);
1203 bufp
= &symbuf
[symbuf_idx
++];
1204 SWAP_SYMBOL (bufp
, abfd
);
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));
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;
1222 if (symbuf_idx
== symbuf_end
)
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");
1228 max_symnum
= sym_size
/ symbol_size
;
1231 symnum
< max_symnum
;
1234 QUIT
; /* Allow this to be interruptable */
1235 if (symbuf_idx
== symbuf_end
)
1237 bufp
= &symbuf
[symbuf_idx
++];
1238 SWAP_SYMBOL (bufp
, abfd
);
1240 type
= bufp
->n_type
;
1241 if (type
== (unsigned char)N_CATCH
)
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
;
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. */
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
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
1282 current_objfile
= NULL
;
1283 return (end_symtab (text_offset
+ text_size
, 0, 0, objfile
));
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.
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.
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. */
1302 process_one_symbol (type
, desc
, valu
, name
, offset
)
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
;
1314 register struct context_stack
*new;
1317 /* Something is wrong if we see real data before
1318 seeing a source file name. */
1320 if (last_source_file
== 0 && type
!= (unsigned char)N_SO
)
1322 /* Currently this ignores N_ENTRY on Gould machines, N_NSYM on machines
1323 where that code is defined. */
1324 if (IGNORE_SYMBOL (type
))
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.");
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. */
1345 valu
+= offset
; /* Relocate for dynamic loading */
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. */
1354 colon_pos
= strchr (name
, ':');
1356 || (*colon_pos
!= 'f' && *colon_pos
!= 'F'))
1358 define_symbol (valu
, name
, desc
, type
, our_objfile
);
1362 #ifndef SUN_FIXED_LBRAC_BUG
1363 last_pc_address
= valu
; /* Save for SunOS bug circumcision */
1366 within_function
= 1;
1367 if (context_stack_depth
> 0)
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
);
1374 /* Stack must be empty now. */
1375 if (context_stack_depth
!= 0)
1376 complain (&lbrac_unmatched_complaint
, (char *) symnum
);
1378 new = push_context (0, valu
);
1379 new->name
= define_symbol (valu
, name
, desc
, type
, our_objfile
);
1383 /* Record the address at which this catch takes place. */
1384 define_symbol (valu
+offset
, name
, desc
, type
, our_objfile
);
1388 /* This "symbol" just indicates the start of an inner lexical
1389 context within a function. */
1391 #if defined (BLOCK_ADDRESS_ABSOLUTE)
1392 valu
+= offset
; /* Relocate for dynamic loading */
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
;
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
;
1406 new = push_context (desc
, valu
);
1410 /* This "symbol" just indicates the end of an inner lexical
1411 context that was started with N_LBRAC. */
1413 #if defined (BLOCK_ADDRESS_ABSOLUTE)
1414 valu
+= offset
; /* Relocate for dynamic loading */
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
;
1421 new = pop_context();
1422 if (desc
!= new->depth
)
1423 complain (&lbrac_mismatch_complaint
, (char *) symnum
);
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
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
;
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.
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
1449 && (context_stack_depth
1450 > !VARIABLES_INSIDE_BLOCK(desc
, processing_gcc_compilation
)))
1452 /* FIXME Muzzle a compiler bug that makes end < start. */
1453 if (new->start_addr
> valu
)
1455 complain(&lbrac_rbrac_complaint
, 0);
1456 new->start_addr
= valu
;
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
);
1464 within_function
= 0;
1466 if (VARIABLES_INSIDE_BLOCK(desc
, processing_gcc_compilation
))
1467 /* Now pop locals of block just finished. */
1468 local_symbols
= new->locals
;
1473 /* This kind of symbol indicates the start of an object file. */
1474 valu
+= offset
; /* Relocate for dynamic loading */
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 */
1484 #ifndef SUN_FIXED_LBRAC_BUG
1485 last_pc_address
= valu
; /* Save for SunOS bug circumcision */
1488 #ifdef PCC_SOL_BROKEN
1489 /* pcc bug, occasionally puts out SO for SOL. */
1490 if (context_stack_depth
> 0)
1492 start_subfile (name
, NULL
);
1496 if (last_source_file
)
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.
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] == '/')
1507 current_subfile
->dirname
= current_subfile
->name
;
1508 current_subfile
->name
=
1509 obsavestring (name
, strlen (name
),
1510 &our_objfile
-> symbol_obstack
);
1513 (void) end_symtab (valu
, 0, 0, our_objfile
);
1515 start_symtab (name
, NULL
, valu
);
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
);
1530 add_new_header_file (name
, valu
);
1531 start_subfile (name
, NULL
);
1535 start_subfile (pop_subfile (), NULL
);
1539 add_old_header_file (name
, valu
);
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 */
1550 record_line (current_subfile
, desc
, valu
);
1555 error ("Invalid symbol data: common within common at symtab pos %d",
1557 common_block
= local_symbols
;
1558 common_block_i
= local_symbols
? local_symbols
->nsyms
: 0;
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
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
;
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 */
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 */
1606 define_symbol (valu
, name
, desc
, type
, our_objfile
);
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. */
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??? */
1624 complain (&unknown_symtype_complaint
, local_hex_string(type
));
1626 define_symbol (valu
, name
, desc
, type
, our_objfile
);
1629 previous_stab_code
= type
;
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
;
1638 struct pending
*end
;
1640 struct pending
*new = 0;
1641 struct pending
*next
;
1643 for (next
= beg
; next
!= 0 && (next
!= end
|| begi
< end
->nsyms
);
1644 next
= next
->next
, begi
= 0)
1647 for (j
= begi
; j
< next
->nsyms
; j
++)
1648 add_symbol_to_list (next
->symbol
[j
], &new);
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
};
1658 static struct sym_fns aout_sym_fns
= {"a.out", 5,
1659 dbx_new_init
, dbx_symfile_init
, dbx_symfile_read
};
1661 static struct sym_fns bout_sym_fns
= {"b.out", 5,
1662 dbx_new_init
, dbx_symfile_init
, dbx_symfile_read
};
1665 _initialize_dbxread ()
1667 add_symtab_fns(&sunos_sym_fns
);
1668 add_symtab_fns(&aout_sym_fns
);
1669 add_symtab_fns(&bout_sym_fns
);