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 */
38 #include <sys/types.h>
45 #include <sys/param.h>
52 #include "breakpoint.h"
55 #include "gdbcore.h" /* for bfd stuff */
56 #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
60 #include "aout/aout64.h"
61 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native, now */
63 /* Information is passed among various dbxread routines for accessing
64 symbol files. A pointer to this structure is kept in the sym_private
65 field of the struct sym_fns passed in by symfile.h. */
67 struct dbx_symfile_info
{
68 asection
*text_sect
; /* Text section accessor */
69 int symcount
; /* How many symbols are there in the file */
70 char *stringtab
; /* The actual string table */
71 int stringtab_size
; /* Its size */
72 off_t symtab_offset
; /* Offset in file to symbol table */
76 /* Each partial symbol table entry contains a pointer to private data for the
77 read_symtab() function to use when expanding a partial symbol table entry
78 to a full symbol table entry.
80 For dbxread this structure contains the offset within the file symbol table
81 of first local symbol for this file, and length (in bytes) of the section
82 of the symbol table devoted to this file's symbols (actually, the section
83 bracketed may contain more than just this file's symbols). If ldsymlen is
84 0, the only reason for this thing's existence is the dependency list.
85 Nothing else will happen when it is read in. */
87 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
88 #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
95 /* Macro to determine which symbols to ignore when reading the first symbol
96 of a file. Some machines override this definition. */
98 /* This code is used on Ultrix systems. Ignore it */
99 #define IGNORE_SYMBOL(type) (type == (int)N_NSYMS)
102 /* Macro for name of symbol to indicate a file compiled with gcc. */
103 #ifndef GCC_COMPILED_FLAG_SYMBOL
104 #define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
107 /* Macro for name of symbol to indicate a file compiled with gcc2. */
108 #ifndef GCC2_COMPILED_FLAG_SYMBOL
109 #define GCC2_COMPILED_FLAG_SYMBOL "gcc2_compiled."
112 /* Define this as 1 if a pcc declaration of a char or short argument
113 gives the correct address. Otherwise assume pcc gives the
114 address of the corresponding int, which is not the same on a
115 big-endian machine. */
117 #ifndef BELIEVE_PCC_PROMOTION
118 #define BELIEVE_PCC_PROMOTION 0
121 /* Nonzero means give verbose info on gdb action. From main.c. */
122 extern int info_verbose
;
124 /* The BFD for this file -- implicit parameter to next_symbol_text. */
126 static bfd
*symfile_bfd
;
128 /* The objfile for this file -- only good in process_one_symbol(). */
130 static struct objfile
*our_objfile
;
132 /* String table for the main symbol file. It is kept in memory
133 permanently, to speed up symbol reading. Other files' symbol tables
134 are read in on demand. FIXME, this should be cleaner. */
136 static char *symfile_string_table
;
137 static int symfile_string_table_size
;
139 /* The size of each symbol in the symbol file (in external form).
140 This is set by dbx_symfile_read when building psymtabs, and by
141 dbx_psymtab_to_symtab when building symtabs. */
143 static unsigned symbol_size
;
145 /* Complaints about the symbols we have encountered. */
147 struct complaint lbrac_complaint
=
148 {"bad block start address patched", 0, 0};
150 struct complaint string_table_offset_complaint
=
151 {"bad string table offset in symbol %d", 0, 0};
153 struct complaint unknown_symtype_complaint
=
154 {"unknown symbol type %s", 0, 0};
156 struct complaint lbrac_rbrac_complaint
=
157 {"block start larger than block end", 0, 0};
159 struct complaint lbrac_unmatched_complaint
=
160 {"unmatched N_LBRAC before symtab pos %d", 0, 0};
162 struct complaint lbrac_mismatch_complaint
=
163 {"N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d", 0, 0};
165 /* During initial symbol readin, we need to have a structure to keep
166 track of which psymtabs have which bincls in them. This structure
167 is used during readin to setup the list of dependencies within each
168 partial symbol table. */
170 struct header_file_location
172 char *name
; /* Name of header file */
173 int instance
; /* See above */
174 struct partial_symtab
*pst
; /* Partial symtab that has the
175 BINCL/EINCL defs for this file */
178 /* The actual list and controling variables */
179 static struct header_file_location
*bincl_list
, *next_bincl
;
180 static int bincls_allocated
;
182 /* Local function prototypes */
185 free_and_init_header_files
PARAMS ((void));
187 static struct pending
*
188 copy_pending
PARAMS ((struct pending
*, int, struct pending
*));
190 static struct symtab
*
191 read_ofile_symtab
PARAMS ((struct objfile
*, char *, unsigned int, int, int,
192 CORE_ADDR
, int, int));
195 dbx_psymtab_to_symtab
PARAMS ((struct partial_symtab
*));
198 psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*, char *, int, int));
201 read_dbx_symtab
PARAMS ((CORE_ADDR
, struct objfile
*, char *, long, int,
205 free_bincl_list
PARAMS ((struct objfile
*));
207 static struct partial_symtab
*
208 find_corresponding_bincl_psymtab
PARAMS ((char *, int));
211 add_bincl_to_list
PARAMS ((struct partial_symtab
*, char *, int));
214 init_bincl_list
PARAMS ((int, struct objfile
*));
217 init_psymbol_list
PARAMS ((int, struct objfile
*));
220 dbx_next_symbol_text
PARAMS ((void));
223 fill_symbuf
PARAMS ((bfd
*));
226 dbx_symfile_init
PARAMS ((struct sym_fns
*));
229 dbx_new_init
PARAMS ((void));
232 dbx_symfile_read
PARAMS ((struct sym_fns
*, CORE_ADDR
, int));
235 record_minimal_symbol
PARAMS ((char *, CORE_ADDR
, int, struct objfile
*));
238 add_new_header_file
PARAMS ((char *, int));
241 add_old_header_file
PARAMS ((char *, int));
244 add_this_object_header_file
PARAMS ((int));
246 /* Free up old header file tables, and allocate new ones.
247 We're reading a new symbol file now. */
250 free_and_init_header_files ()
253 for (i
= 0; i
< n_header_files
; i
++)
254 free (header_files
[i
].name
);
255 if (header_files
) /* First time null */
257 if (this_object_header_files
) /* First time null */
258 free (this_object_header_files
);
260 n_allocated_header_files
= 10;
261 header_files
= (struct header_file
*) xmalloc (10 * sizeof (struct header_file
));
264 n_allocated_this_object_header_files
= 10;
265 this_object_header_files
= (int *) xmalloc (10 * sizeof (int));
268 /* Add header file number I for this object file
269 at the next successive FILENUM. */
272 add_this_object_header_file (i
)
275 if (n_this_object_header_files
== n_allocated_this_object_header_files
)
277 n_allocated_this_object_header_files
*= 2;
278 this_object_header_files
279 = (int *) xrealloc ((char *) this_object_header_files
,
280 n_allocated_this_object_header_files
* sizeof (int));
283 this_object_header_files
[n_this_object_header_files
++] = i
;
286 /* Add to this file an "old" header file, one already seen in
287 a previous object file. NAME is the header file's name.
288 INSTANCE is its instance code, to select among multiple
289 symbol tables for the same header file. */
292 add_old_header_file (name
, instance
)
296 register struct header_file
*p
= header_files
;
299 for (i
= 0; i
< n_header_files
; i
++)
300 if (!strcmp (p
[i
].name
, name
) && instance
== p
[i
].instance
)
302 add_this_object_header_file (i
);
305 error ("Invalid symbol data: \"repeated\" header file that hasn't been seen before, at symtab pos %d.",
309 /* Add to this file a "new" header file: definitions for its types follow.
310 NAME is the header file's name.
311 Most often this happens only once for each distinct header file,
312 but not necessarily. If it happens more than once, INSTANCE has
313 a different value each time, and references to the header file
314 use INSTANCE values to select among them.
316 dbx output contains "begin" and "end" markers for each new header file,
317 but at this level we just need to know which files there have been;
318 so we record the file when its "begin" is seen and ignore the "end". */
321 add_new_header_file (name
, instance
)
326 header_file_prev_index
= -1;
328 /* Make sure there is room for one more header file. */
330 if (n_header_files
== n_allocated_header_files
)
332 n_allocated_header_files
*= 2;
333 header_files
= (struct header_file
*)
334 xrealloc ((char *) header_files
,
335 (n_allocated_header_files
* sizeof (struct header_file
)));
338 /* Create an entry for this header file. */
340 i
= n_header_files
++;
341 header_files
[i
].name
= savestring (name
, strlen(name
));
342 header_files
[i
].instance
= instance
;
343 header_files
[i
].length
= 10;
344 header_files
[i
].vector
345 = (struct type
**) xmalloc (10 * sizeof (struct type
*));
346 bzero (header_files
[i
].vector
, 10 * sizeof (struct type
*));
348 add_this_object_header_file (i
);
352 static struct type
**
353 explicit_lookup_type (real_filenum
, index
)
354 int real_filenum
, index
;
356 register struct header_file
*f
= &header_files
[real_filenum
];
358 if (index
>= f
->length
)
361 f
->vector
= (struct type
**)
362 xrealloc (f
->vector
, f
->length
* sizeof (struct type
*));
363 bzero (&f
->vector
[f
->length
/ 2],
364 f
->length
* sizeof (struct type
*) / 2);
366 return &f
->vector
[index
];
371 record_minimal_symbol (name
, address
, type
, objfile
)
375 struct objfile
*objfile
;
377 enum minimal_symbol_type ms_type
;
379 switch (type
&~ N_EXT
) {
380 case N_TEXT
: ms_type
= mst_text
; break;
381 case N_DATA
: ms_type
= mst_data
; break;
382 case N_BSS
: ms_type
= mst_bss
; break;
383 case N_ABS
: ms_type
= mst_abs
; break;
385 case N_SETV
: ms_type
= mst_data
; break;
387 default: ms_type
= mst_unknown
; break;
390 prim_record_minimal_symbol (obsavestring (name
, strlen (name
), &objfile
-> symbol_obstack
),
394 /* Scan and build partial symbols for a symbol file.
395 We have been initialized by a call to dbx_symfile_init, which
396 put all the relevant info into a "struct dbx_symfile_info"
397 hung off the struct sym_fns SF.
399 ADDR is the address relative to which the symbols in it are (e.g.
400 the base address of the text segment).
401 MAINLINE is true if we are reading the main symbol
402 table (as opposed to a shared lib or dynamically loaded file). */
405 dbx_symfile_read (sf
, addr
, mainline
)
408 int mainline
; /* FIXME comments above */
410 struct dbx_symfile_info
*info
= (struct dbx_symfile_info
*) (sf
->sym_private
);
411 bfd
*sym_bfd
= sf
->objfile
->obfd
;
414 val
= bfd_seek (sf
->objfile
->obfd
, info
->symtab_offset
, L_SET
);
416 perror_with_name (sf
->objfile
->name
);
418 /* If mainline, set global string table pointers, and reinitialize global
419 partial symbol list. */
421 symfile_string_table
= info
->stringtab
;
422 symfile_string_table_size
= info
->stringtab_size
;
425 /* If we are reinitializing, or if we have never loaded syms yet, init */
426 if (mainline
|| sf
->objfile
->global_psymbols
.size
== 0 || sf
->objfile
->static_psymbols
.size
== 0)
427 init_psymbol_list (info
->symcount
, sf
->objfile
);
429 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
430 symbol_size
= obj_symbol_entry_size (sym_bfd
);
433 make_cleanup (really_free_pendings
, 0);
435 init_minimal_symbol_collection ();
436 make_cleanup (discard_minimal_symbols
, 0);
438 /* Now that the symbol table data of the executable file are all in core,
439 process them and define symbols accordingly. */
441 read_dbx_symtab (addr
- bfd_section_vma (sym_bfd
, info
->text_sect
), /*offset*/
442 sf
->objfile
, info
->stringtab
, info
->stringtab_size
,
444 bfd_section_vma (sym_bfd
, info
->text_sect
),
445 bfd_section_size (sym_bfd
, info
->text_sect
));
447 /* Install any minimal symbols that have been collected as the current
448 minimal symbols for this objfile. */
450 install_minimal_symbols (sf
-> objfile
);
452 /* Free up any memory we allocated for ourselves. */
455 mfree (sf
->objfile
->md
, info
->stringtab
); /* Stringtab is only saved for mainline */
457 mfree (sf
->objfile
->md
, info
);
458 sf
->sym_private
= NULL
; /* Zap pointer to our (now gone) info struct */
460 if (!have_partial_symbols ()) {
462 printf_filtered ("(no debugging symbols found)...");
467 /* Initialize anything that needs initializing when a completely new
468 symbol file is specified (not just adding some symbols from another
469 file, e.g. a shared library). */
474 buildsym_new_init ();
476 /* Don't put these on the cleanup chain; they need to stick around
477 until the next call to dbx_new_init. *Then* we'll free them. */
478 if (symfile_string_table
)
480 free (symfile_string_table
);
481 symfile_string_table
= 0;
482 symfile_string_table_size
= 0;
484 free_and_init_header_files ();
488 /* dbx_symfile_init ()
489 is the dbx-specific initialization routine for reading symbols.
490 It is passed a struct sym_fns which contains, among other things,
491 the BFD for the file whose symbols are being read, and a slot for a pointer
492 to "private data" which we fill with goodies.
494 We read the string table into malloc'd space and stash a pointer to it.
496 Since BFD doesn't know how to read debug symbols in a format-independent
497 way (and may never do so...), we have to do it ourselves. We will never
498 be called unless this is an a.out (or very similar) file.
499 FIXME, there should be a cleaner peephole into the BFD environment here. */
502 dbx_symfile_init (sf
)
506 bfd
*sym_bfd
= sf
->objfile
->obfd
;
507 char *name
= bfd_get_filename (sym_bfd
);
508 struct dbx_symfile_info
*info
;
509 unsigned char size_temp
[4];
511 /* Allocate struct to keep track of the symfile */
512 sf
->sym_private
= xmmalloc (sf
->objfile
->md
, sizeof (*info
));
513 info
= (struct dbx_symfile_info
*)sf
->sym_private
;
515 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
516 #define STRING_TABLE_OFFSET (sym_bfd->origin + obj_str_filepos (sym_bfd))
517 #define SYMBOL_TABLE_OFFSET (sym_bfd->origin + obj_sym_filepos (sym_bfd))
518 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
520 info
->text_sect
= bfd_get_section_by_name (sym_bfd
, ".text");
521 if (!info
->text_sect
)
523 info
->symcount
= bfd_get_symcount (sym_bfd
);
525 /* Read the string table size and check it for bogosity. */
526 val
= bfd_seek (sym_bfd
, STRING_TABLE_OFFSET
, L_SET
);
528 perror_with_name (name
);
530 val
= bfd_read (size_temp
, sizeof (long), 1, sym_bfd
);
532 perror_with_name (name
);
533 info
->stringtab_size
= bfd_h_get_32 (sym_bfd
, size_temp
);
535 if (info
->stringtab_size
>= 0)
537 /* Yes, this should be malloc, not xmalloc. We check its result. */
538 info
->stringtab
= (char *) mmalloc (sf
->objfile
->md
, info
->stringtab_size
);
539 /* Caller is responsible for freeing the string table. No cleanup. */
542 info
->stringtab
= NULL
;
543 if (info
->stringtab
== NULL
&& info
->stringtab_size
!= 0)
544 error ("ridiculous string table size: %d bytes", info
->stringtab_size
);
546 /* Now read in the string table in one big gulp. */
548 val
= bfd_seek (sym_bfd
, STRING_TABLE_OFFSET
, L_SET
);
550 perror_with_name (name
);
551 val
= bfd_read (info
->stringtab
, info
->stringtab_size
, 1, sym_bfd
);
552 if (val
!= info
->stringtab_size
)
553 perror_with_name (name
);
555 /* Record the position of the symbol table for later use. */
557 info
->symtab_offset
= SYMBOL_TABLE_OFFSET
;
560 /* Buffer for reading the symbol table entries. */
561 static struct internal_nlist symbuf
[4096];
562 static int symbuf_idx
;
563 static int symbuf_end
;
565 /* The address in memory of the string table of the object file we are
566 reading (which might not be the "main" object file, but might be a
567 shared library or some other dynamically loaded thing). This is set
568 by read_dbx_symtab when building psymtabs, and by read_ofile_symtab
569 when building symtabs, and is used only by next_symbol_text. */
570 static char *stringtab_global
;
572 /* Refill the symbol table input buffer
573 and set the variables that control fetching entries from it.
574 Reports an error if no data available.
575 This function can read past the end of the symbol table
576 (into the string table) but this does no harm. */
579 fill_symbuf (sym_bfd
)
582 int nbytes
= bfd_read (symbuf
, sizeof (symbuf
), 1, sym_bfd
);
584 perror_with_name (bfd_get_filename (sym_bfd
));
585 else if (nbytes
== 0)
586 error ("Premature end of file reading symbol table");
587 symbuf_end
= nbytes
/ symbol_size
;
591 #define SWAP_SYMBOL(symp, abfd) \
593 (symp)->n_strx = bfd_h_get_32(abfd, \
594 (unsigned char *)&(symp)->n_strx); \
595 (symp)->n_desc = bfd_h_get_16 (abfd, \
596 (unsigned char *)&(symp)->n_desc); \
597 (symp)->n_value = bfd_h_get_32 (abfd, \
598 (unsigned char *)&(symp)->n_value); \
601 /* Invariant: The symbol pointed to by symbuf_idx is the first one
602 that hasn't been swapped. Swap the symbol at the same time
603 that symbuf_idx is incremented. */
605 /* dbx allows the text of a symbol name to be continued into the
606 next symbol name! When such a continuation is encountered
607 (a \ at the end of the text of a name)
608 call this function to get the continuation. */
611 dbx_next_symbol_text ()
613 if (symbuf_idx
== symbuf_end
)
614 fill_symbuf (symfile_bfd
);
616 SWAP_SYMBOL(&symbuf
[symbuf_idx
], symfile_bfd
);
617 return symbuf
[symbuf_idx
++].n_strx
+ stringtab_global
;
620 /* Initializes storage for all of the partial symbols that will be
621 created by read_dbx_symtab and subsidiaries. */
624 init_psymbol_list (total_symbols
, objfile
)
626 struct objfile
*objfile
;
628 /* Free any previously allocated psymbol lists. */
629 if (objfile
-> global_psymbols
.list
)
630 mfree (objfile
-> md
, objfile
-> global_psymbols
.list
);
631 if (objfile
-> static_psymbols
.list
)
632 mfree (objfile
-> md
, objfile
-> static_psymbols
.list
);
634 /* Current best guess is that there are approximately a twentieth
635 of the total symbols (in a debugging file) are global or static
637 objfile
-> global_psymbols
.size
= total_symbols
/ 10;
638 objfile
-> static_psymbols
.size
= total_symbols
/ 10;
639 objfile
-> global_psymbols
.next
= objfile
-> global_psymbols
.list
= (struct partial_symbol
*)
640 xmmalloc (objfile
-> md
, objfile
-> global_psymbols
.size
* sizeof (struct partial_symbol
));
641 objfile
-> static_psymbols
.next
= objfile
-> static_psymbols
.list
= (struct partial_symbol
*)
642 xmmalloc (objfile
-> md
, objfile
-> static_psymbols
.size
* sizeof (struct partial_symbol
));
645 /* Initialize the list of bincls to contain none and have some
649 init_bincl_list (number
, objfile
)
651 struct objfile
*objfile
;
653 bincls_allocated
= number
;
654 next_bincl
= bincl_list
= (struct header_file_location
*)
655 xmmalloc (objfile
-> md
, bincls_allocated
* sizeof(struct header_file_location
));
658 /* Add a bincl to the list. */
661 add_bincl_to_list (pst
, name
, instance
)
662 struct partial_symtab
*pst
;
666 if (next_bincl
>= bincl_list
+ bincls_allocated
)
668 int offset
= next_bincl
- bincl_list
;
669 bincls_allocated
*= 2;
670 bincl_list
= (struct header_file_location
*)
671 xmrealloc (pst
->objfile
->md
, (char *)bincl_list
,
672 bincls_allocated
* sizeof (struct header_file_location
));
673 next_bincl
= bincl_list
+ offset
;
675 next_bincl
->pst
= pst
;
676 next_bincl
->instance
= instance
;
677 next_bincl
++->name
= name
;
680 /* Given a name, value pair, find the corresponding
681 bincl in the list. Return the partial symtab associated
682 with that header_file_location. */
684 static struct partial_symtab
*
685 find_corresponding_bincl_psymtab (name
, instance
)
689 struct header_file_location
*bincl
;
691 for (bincl
= bincl_list
; bincl
< next_bincl
; bincl
++)
692 if (bincl
->instance
== instance
693 && !strcmp (name
, bincl
->name
))
696 return (struct partial_symtab
*) 0;
699 /* Free the storage allocated for the bincl list. */
702 free_bincl_list (objfile
)
703 struct objfile
*objfile
;
705 mfree (objfile
-> md
, bincl_list
);
706 bincls_allocated
= 0;
709 /* Given pointers to an a.out symbol table in core containing dbx
710 style data, setup partial_symtab's describing each source file for
711 which debugging information is available. NLISTLEN is the number
712 of symbols in the symbol table. All symbol names are given as
713 offsets relative to STRINGTAB. STRINGTAB_SIZE is the size of
714 STRINGTAB. SYMFILE_NAME is the name of the file we are reading from
715 and ADDR is its relocated address (if incremental) or 0 (if not). */
718 read_dbx_symtab (addr
, objfile
, stringtab
, stringtab_size
, nlistlen
,
719 text_addr
, text_size
)
721 struct objfile
*objfile
;
722 register char *stringtab
;
723 register long stringtab_size
;
724 register int nlistlen
;
728 register struct internal_nlist
*bufp
;
729 register char *namestring
;
731 int past_first_source_file
= 0;
732 CORE_ADDR last_o_file_start
= 0;
733 struct cleanup
*old_chain
;
736 /* End of the text segment of the executable file. */
737 CORE_ADDR end_of_text_addr
;
739 /* Current partial symtab */
740 struct partial_symtab
*pst
;
742 /* List of current psymtab's include files */
743 char **psymtab_include_list
;
744 int includes_allocated
;
747 /* Index within current psymtab dependency list */
748 struct partial_symtab
**dependency_list
;
749 int dependencies_used
, dependencies_allocated
;
751 stringtab_global
= stringtab
;
753 pst
= (struct partial_symtab
*) 0;
755 includes_allocated
= 30;
757 psymtab_include_list
= (char **) alloca (includes_allocated
*
760 dependencies_allocated
= 30;
761 dependencies_used
= 0;
763 (struct partial_symtab
**) alloca (dependencies_allocated
*
764 sizeof (struct partial_symtab
*));
766 old_chain
= make_cleanup (free_objfile
, objfile
);
768 /* Init bincl list */
769 init_bincl_list (20, objfile
);
770 make_cleanup (free_bincl_list
, objfile
);
772 last_source_file
= 0;
774 #ifdef END_OF_TEXT_DEFAULT
775 end_of_text_addr
= END_OF_TEXT_DEFAULT
;
777 end_of_text_addr
= text_addr
+ addr
+ text_size
; /* Relocate */
780 symfile_bfd
= objfile
->obfd
; /* For next_text_symbol */
781 abfd
= objfile
->obfd
;
782 symbuf_end
= symbuf_idx
= 0;
783 next_symbol_text_func
= dbx_next_symbol_text
;
785 for (symnum
= 0; symnum
< nlistlen
; symnum
++)
787 /* Get the symbol for this run and pull out some info */
788 QUIT
; /* allow this to be interruptable */
789 if (symbuf_idx
== symbuf_end
)
791 bufp
= &symbuf
[symbuf_idx
++];
794 * Special case to speed up readin.
796 if (bufp
->n_type
== (unsigned char)N_SLINE
) continue;
798 SWAP_SYMBOL (bufp
, abfd
);
800 /* Ok. There is a lot of code duplicated in the rest of this
801 switch statement (for efficiency reasons). Since I don't
802 like duplicating code, I will do my penance here, and
803 describe the code which is duplicated:
805 *) The assignment to namestring.
806 *) The call to strchr.
807 *) The addition of a partial symbol the the two partial
808 symbol lists. This last is a large section of code, so
809 I've imbedded it in the following macro.
812 /* Set namestring based on bufp. If the string table index is invalid,
813 give a fake name, and print a single error message per symbol file read,
814 rather than abort the symbol reading or flood the user with messages. */
815 #define SET_NAMESTRING()\
816 if (((unsigned)bufp->n_strx) >= stringtab_size) { \
817 complain (&string_table_offset_complaint, (char *) symnum); \
818 namestring = "foo"; \
820 namestring = bufp->n_strx + stringtab
822 #define CUR_SYMBOL_TYPE bufp->n_type
823 #define CUR_SYMBOL_VALUE bufp->n_value
825 #define START_PSYMTAB(ofile,addr,fname,low,symoff,global_syms,static_syms)\
826 start_psymtab(ofile, addr, fname, low, symoff, global_syms, static_syms)
827 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps)\
828 end_psymtab(pst,ilist,ninc,c_off,c_text,dep_list,n_deps)
830 #include "partial-stab.h"
833 /* If there's stuff to be cleaned up, clean it up. */
834 if (nlistlen
> 0 /* We have some syms */
835 && entry_point
< bufp
->n_value
836 && entry_point
>= last_o_file_start
)
838 startup_file_start
= last_o_file_start
;
839 startup_file_end
= bufp
->n_value
;
844 end_psymtab (pst
, psymtab_include_list
, includes_used
,
845 symnum
* symbol_size
, end_of_text_addr
,
846 dependency_list
, dependencies_used
);
849 free_bincl_list (objfile
);
850 discard_cleanups (old_chain
);
853 /* Allocate and partially fill a partial symtab. It will be
854 completely filled at the end of the symbol list.
856 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
857 is the address relative to which its symbols are (incremental) or 0
861 struct partial_symtab
*
862 start_psymtab (objfile
, addr
,
863 filename
, textlow
, ldsymoff
, global_syms
, static_syms
)
864 struct objfile
*objfile
;
869 struct partial_symbol
*global_syms
;
870 struct partial_symbol
*static_syms
;
872 struct partial_symtab
*result
=
873 start_psymtab_common(objfile
, addr
,
874 filename
, textlow
, global_syms
, static_syms
);
876 result
->read_symtab_private
= (char *)
877 obstack_alloc (&objfile
-> psymbol_obstack
, sizeof (struct symloc
));
878 LDSYMOFF(result
) = ldsymoff
;
879 result
->read_symtab
= dbx_psymtab_to_symtab
;
884 /* Close off the current usage of a partial_symbol table entry. This
885 involves setting the correct number of includes (with a realloc),
886 setting the high text mark, setting the symbol length in the
887 executable, and setting the length of the global and static lists
890 The global symbols and static symbols are then seperately sorted.
892 Then the partial symtab is put on the global list.
893 *** List variables and peculiarities of same. ***
897 end_psymtab (pst
, include_list
, num_includes
, capping_symbol_offset
,
898 capping_text
, dependency_list
, number_dependencies
)
899 struct partial_symtab
*pst
;
902 int capping_symbol_offset
;
903 CORE_ADDR capping_text
;
904 struct partial_symtab
**dependency_list
;
905 int number_dependencies
;
906 /* struct partial_symbol *capping_global, *capping_static;*/
909 struct objfile
*objfile
= pst
-> objfile
;
911 if (capping_symbol_offset
!= -1)
912 LDSYMLEN(pst
) = capping_symbol_offset
- LDSYMOFF(pst
);
913 pst
->texthigh
= capping_text
;
916 objfile
->global_psymbols
.next
- (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
918 objfile
->static_psymbols
.next
- (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
920 pst
->number_of_dependencies
= number_dependencies
;
921 if (number_dependencies
)
923 pst
->dependencies
= (struct partial_symtab
**)
924 obstack_alloc (&objfile
->psymbol_obstack
,
925 number_dependencies
* sizeof (struct partial_symtab
*));
926 memcpy (pst
->dependencies
, dependency_list
,
927 number_dependencies
* sizeof (struct partial_symtab
*));
930 pst
->dependencies
= 0;
932 for (i
= 0; i
< num_includes
; i
++)
934 struct partial_symtab
*subpst
=
935 allocate_psymtab (include_list
[i
], objfile
);
937 subpst
->addr
= pst
->addr
;
938 subpst
->read_symtab_private
=
939 (char *) obstack_alloc (&objfile
->psymbol_obstack
,
940 sizeof (struct symloc
));
944 subpst
->texthigh
= 0;
946 /* We could save slight bits of space by only making one of these,
947 shared by the entire set of include files. FIXME-someday. */
948 subpst
->dependencies
= (struct partial_symtab
**)
949 obstack_alloc (&objfile
->psymbol_obstack
,
950 sizeof (struct partial_symtab
*));
951 subpst
->dependencies
[0] = pst
;
952 subpst
->number_of_dependencies
= 1;
954 subpst
->globals_offset
=
955 subpst
->n_global_syms
=
956 subpst
->statics_offset
=
957 subpst
->n_static_syms
= 0;
961 subpst
->read_symtab
= dbx_psymtab_to_symtab
;
964 sort_pst_symbols (pst
);
966 /* If there is already a psymtab or symtab for a file of this name, remove it.
967 (If there is a symtab, more drastic things also happen.)
968 This happens in VxWorks. */
969 free_named_symtabs (pst
->filename
);
971 if (num_includes
== 0
972 && number_dependencies
== 0
973 && pst
->n_global_syms
== 0
974 && pst
->n_static_syms
== 0) {
975 /* Throw away this psymtab, it's empty. We can't deallocate it, since
976 it is on the obstack, but we can forget to chain it on the list. */
977 struct partial_symtab
*prev_pst
;
979 /* First, snip it out of the psymtab chain */
981 if (pst
->objfile
->psymtabs
== pst
)
982 pst
->objfile
->psymtabs
= pst
->next
;
984 for (prev_pst
= pst
->objfile
->psymtabs
; prev_pst
; prev_pst
= pst
->next
)
985 if (prev_pst
->next
== pst
)
986 prev_pst
->next
= pst
->next
;
988 /* Next, put it on a free list for recycling */
990 pst
->next
= pst
->objfile
->free_psymtabs
;
991 pst
->objfile
->free_psymtabs
= pst
;
996 psymtab_to_symtab_1 (pst
, stringtab
, stringtab_size
, sym_offset
)
997 struct partial_symtab
*pst
;
1002 struct cleanup
*old_chain
;
1010 fprintf (stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1015 /* Read in all partial symtabs on which this one is dependent */
1016 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
1017 if (!pst
->dependencies
[i
]->readin
)
1019 /* Inform about additional files that need to be read in. */
1022 fputs_filtered (" ", stdout
);
1024 fputs_filtered ("and ", stdout
);
1026 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
1027 wrap_here (""); /* Flush output */
1030 psymtab_to_symtab_1 (pst
->dependencies
[i
],
1031 stringtab
, stringtab_size
, sym_offset
);
1034 if (LDSYMLEN(pst
)) /* Otherwise it's a dummy */
1036 /* Init stuff necessary for reading in symbols */
1038 old_chain
= make_cleanup (really_free_pendings
, 0);
1040 /* Read in this files symbols */
1041 bfd_seek (pst
->objfile
->obfd
, sym_offset
, L_SET
);
1043 read_ofile_symtab (pst
->objfile
, stringtab
, stringtab_size
,
1045 LDSYMLEN(pst
), pst
->textlow
,
1046 pst
->texthigh
- pst
->textlow
, pst
->addr
);
1047 sort_symtab_syms (pst
->symtab
);
1049 do_cleanups (old_chain
);
1056 * Read in all of the symbols for a given psymtab for real.
1057 * Be verbose about it if the user wants that.
1060 dbx_psymtab_to_symtab (pst
)
1061 struct partial_symtab
*pst
;
1073 fprintf (stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1078 if (LDSYMLEN(pst
) || pst
->number_of_dependencies
)
1080 /* Print the message now, before reading the string table,
1081 to avoid disconcerting pauses. */
1084 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1088 sym_bfd
= pst
->objfile
->obfd
;
1090 /* We keep the string table for the main symfile resident in memory, but
1091 not the string table for any other symbol files. */
1092 if (symfile_objfile
!= pst
->objfile
)
1094 /* Read in the string table */
1096 /* FIXME, this uses internal BFD variables. See above in
1097 dbx_symbol_file_open where the macro is defined! */
1098 bfd_seek (sym_bfd
, STRING_TABLE_OFFSET
, L_SET
);
1100 val
= bfd_read (&st_temp
, sizeof st_temp
, 1, sym_bfd
);
1102 perror_with_name (pst
->objfile
->name
);
1103 stsize
= bfd_h_get_32 (sym_bfd
, (unsigned char *)&st_temp
);
1105 /* BFD doesn't provide a way to know the total file size, sigh */
1106 struct stat statbuf
;
1107 if (fstat (desc
, &statbuf
) < 0)
1108 perror_with_name (pst
->objfile
->name
);
1110 if (stsize
>= 0 && stsize
< statbuf
.st_size
)
1115 #ifdef BROKEN_LARGE_ALLOCA
1116 stringtab
= (char *) xmalloc (stsize
);
1117 make_cleanup (free
, stringtab
);
1119 stringtab
= (char *) alloca (stsize
);
1124 if (stringtab
== NULL
&& stsize
!= 0)
1125 error ("ridiculous string table size: %d bytes", stsize
);
1127 /* FIXME, this uses internal BFD variables. See above in
1128 dbx_symbol_file_open where the macro is defined! */
1129 val
= bfd_seek (sym_bfd
, STRING_TABLE_OFFSET
, L_SET
);
1131 perror_with_name (pst
->objfile
->name
);
1132 val
= bfd_read (stringtab
, stsize
, 1, sym_bfd
);
1134 perror_with_name (pst
->objfile
->name
);
1138 stringtab
= symfile_string_table
;
1139 stsize
= symfile_string_table_size
;
1142 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
1143 symbol_size
= obj_symbol_entry_size (sym_bfd
);
1145 next_symbol_text_func
= dbx_next_symbol_text
;
1147 /* FIXME, this uses internal BFD variables. See above in
1148 dbx_symbol_file_open where the macro is defined! */
1149 psymtab_to_symtab_1 (pst
, stringtab
, stsize
,
1150 SYMBOL_TABLE_OFFSET
);
1152 /* Match with global symbols. This only needs to be done once,
1153 after all of the symtabs and dependencies have been read in. */
1154 scan_file_globals (pst
->objfile
);
1156 /* Finish up the debug error message. */
1158 printf_filtered ("done.\n");
1163 * Read in a defined section of a specific object file's symbols.
1165 * DESC is the file descriptor for the file, positioned at the
1166 * beginning of the symtab
1167 * STRINGTAB is a pointer to the files string
1168 * table, already read in
1169 * SYM_OFFSET is the offset within the file of
1170 * the beginning of the symbols we want to read, NUM_SUMBOLS is the
1171 * number of symbols to read
1172 * TEXT_OFFSET is the beginning of the text segment we are reading symbols for
1173 * TEXT_SIZE is the size of the text segment read in.
1174 * OFFSET is a relocation offset which gets added to each symbol
1177 static struct symtab
*
1178 read_ofile_symtab (objfile
, stringtab
, stringtab_size
, sym_offset
,
1179 sym_size
, text_offset
, text_size
, offset
)
1180 struct objfile
*objfile
;
1181 register char *stringtab
;
1182 unsigned int stringtab_size
;
1185 CORE_ADDR text_offset
;
1189 register char *namestring
;
1190 register struct internal_nlist
*bufp
;
1192 unsigned max_symnum
;
1195 current_objfile
= objfile
;
1198 stringtab_global
= stringtab
;
1199 last_source_file
= 0;
1201 abfd
= objfile
->obfd
;
1202 symfile_bfd
= objfile
->obfd
; /* Implicit param to next_text_symbol */
1203 our_objfile
= objfile
; /* For end_symtab calls in process_one_symbol */
1204 symbuf_end
= symbuf_idx
= 0;
1206 /* It is necessary to actually read one symbol *before* the start
1207 of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
1208 occurs before the N_SO symbol.
1210 Detecting this in read_dbx_symtab
1211 would slow down initial readin, so we look for it here instead. */
1212 if (sym_offset
>= (int)symbol_size
)
1214 bfd_seek (symfile_bfd
, sym_offset
- symbol_size
, L_INCR
);
1216 bufp
= &symbuf
[symbuf_idx
++];
1217 SWAP_SYMBOL (bufp
, abfd
);
1221 processing_gcc_compilation
=
1222 (bufp
->n_type
== N_TEXT
1223 && (strcmp (namestring
, GCC_COMPILED_FLAG_SYMBOL
) == 0
1224 || strcmp(namestring
, GCC2_COMPILED_FLAG_SYMBOL
) == 0));
1228 /* The N_SO starting this symtab is the first symbol, so we
1229 better not check the symbol before it. I'm not this can
1230 happen, but it doesn't hurt to check for it. */
1231 bfd_seek (symfile_bfd
, sym_offset
, L_INCR
);
1232 processing_gcc_compilation
= 0;
1235 if (symbuf_idx
== symbuf_end
)
1237 bufp
= &symbuf
[symbuf_idx
];
1238 if (bufp
->n_type
!= (unsigned char)N_SO
)
1239 error("First symbol in segment of executable not a source symbol");
1241 max_symnum
= sym_size
/ symbol_size
;
1244 symnum
< max_symnum
;
1247 QUIT
; /* Allow this to be interruptable */
1248 if (symbuf_idx
== symbuf_end
)
1250 bufp
= &symbuf
[symbuf_idx
++];
1251 SWAP_SYMBOL (bufp
, abfd
);
1253 type
= bufp
->n_type
;
1254 if (type
== (unsigned char)N_CATCH
)
1256 /* N_CATCH is not fixed up by the linker, and unfortunately,
1257 there's no other place to put it in the .stab map. */
1258 bufp
->n_value
+= text_offset
- offset
;
1263 if (type
& N_STAB
) {
1264 process_one_symbol (type
, bufp
->n_desc
, bufp
->n_value
,
1265 namestring
, offset
);
1266 /* our_objfile is an implicit parameter. */
1268 /* We skip checking for a new .o or -l file; that should never
1269 happen in this routine. */
1270 else if (type
== N_TEXT
1271 && (strcmp (namestring
, GCC_COMPILED_FLAG_SYMBOL
) == 0
1272 || strcmp (namestring
, GCC2_COMPILED_FLAG_SYMBOL
) == 0))
1273 /* I don't think this code will ever be executed, because
1274 the GCC_COMPILED_FLAG_SYMBOL usually is right before
1275 the N_SO symbol which starts this source file.
1276 However, there is no reason not to accept
1277 the GCC_COMPILED_FLAG_SYMBOL anywhere. */
1278 processing_gcc_compilation
= 1;
1279 else if (type
& N_EXT
|| type
== (unsigned char)N_TEXT
1280 || type
== (unsigned char)N_NBTEXT
1282 /* Global symbol: see if we came across a dbx defintion for
1283 a corresponding symbol. If so, store the value. Remove
1284 syms from the chain when their values are stored, but
1285 search the whole chain, as there may be several syms from
1286 different files with the same name. */
1287 /* This is probably not true. Since the files will be read
1288 in one at a time, each reference to a global symbol will
1289 be satisfied in each file as it appears. So we skip this
1295 current_objfile
= NULL
;
1296 return (end_symtab (text_offset
+ text_size
, 0, 0, objfile
));
1299 /* This handles a single symbol from the symbol-file, building symbols
1300 into a GDB symtab. It takes these arguments and an implicit argument.
1302 TYPE is the type field of the ".stab" symbol entry.
1303 DESC is the desc field of the ".stab" entry.
1304 VALU is the value field of the ".stab" entry.
1305 NAME is the symbol name, in our address space.
1306 OFFSET is the amount by which this object file was relocated
1307 when it was loaded into memory. All symbols that refer
1308 to memory locations need to be offset by this amount.
1310 The implicit argument is:
1311 OUR_OBJFILE is the object file from which we are reading symbols.
1312 It is used in end_symtab. */
1315 process_one_symbol (type
, desc
, valu
, name
, offset
)
1321 #ifndef SUN_FIXED_LBRAC_BUG
1322 /* This records the last pc address we've seen. We depend on there being
1323 an SLINE or FUN or SO before the first LBRAC, since the variable does
1324 not get reset in between reads of different symbol files. */
1325 static CORE_ADDR last_pc_address
;
1327 register struct context_stack
*new;
1330 /* Something is wrong if we see real data before
1331 seeing a source file name. */
1333 if (last_source_file
== 0 && type
!= (unsigned char)N_SO
)
1335 /* Currently this ignores N_ENTRY on Gould machines, N_NSYM on machines
1336 where that code is defined. */
1337 if (IGNORE_SYMBOL (type
))
1340 /* FIXME, this should not be an error, since it precludes extending
1341 the symbol table information in this way... */
1342 error ("Invalid symbol data: does not start by identifying a source file.");
1350 /* It seems that the Sun ANSI C compiler (acc) replaces N_FUN with N_GSYM and
1351 N_STSYM with a type code of f or F. Can't enable this until we get some
1352 stuff straightened out with psymtabs. */
1358 valu
+= offset
; /* Relocate for dynamic loading */
1360 /* Either of these types of symbols indicates the start of
1361 a new function. We must process its "name" normally for dbx,
1362 but also record the start of a new lexical context, and possibly
1363 also the end of the lexical context for the previous function. */
1364 /* This is not always true. This type of symbol may indicate a
1365 text segment variable. */
1367 colon_pos
= strchr (name
, ':');
1369 || (*colon_pos
!= 'f' && *colon_pos
!= 'F'))
1371 define_symbol (valu
, name
, desc
, type
, our_objfile
);
1375 #ifndef SUN_FIXED_LBRAC_BUG
1376 last_pc_address
= valu
; /* Save for SunOS bug circumcision */
1379 within_function
= 1;
1380 if (context_stack_depth
> 0)
1382 new = pop_context ();
1383 /* Make a block for the local symbols within. */
1384 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1385 new->start_addr
, valu
, our_objfile
);
1387 /* Stack must be empty now. */
1388 if (context_stack_depth
!= 0)
1389 complain (&lbrac_unmatched_complaint
, (char *) symnum
);
1391 new = push_context (0, valu
);
1392 new->name
= define_symbol (valu
, name
, desc
, type
, our_objfile
);
1396 /* Record the address at which this catch takes place. */
1397 define_symbol (valu
+offset
, name
, desc
, type
, our_objfile
);
1401 /* This "symbol" just indicates the start of an inner lexical
1402 context within a function. */
1404 #if defined (BLOCK_ADDRESS_ABSOLUTE)
1405 valu
+= offset
; /* Relocate for dynamic loading */
1407 /* On most machines, the block addresses are relative to the
1408 N_SO, the linker did not relocate them (sigh). */
1409 valu
+= last_source_start_addr
;
1412 #ifndef SUN_FIXED_LBRAC_BUG
1413 if (valu
< last_pc_address
) {
1414 /* Patch current LBRAC pc value to match last handy pc value */
1415 complain (&lbrac_complaint
, 0);
1416 valu
= last_pc_address
;
1419 new = push_context (desc
, valu
);
1423 /* This "symbol" just indicates the end of an inner lexical
1424 context that was started with N_LBRAC. */
1426 #if defined (BLOCK_ADDRESS_ABSOLUTE)
1427 valu
+= offset
; /* Relocate for dynamic loading */
1429 /* On most machines, the block addresses are relative to the
1430 N_SO, the linker did not relocate them (sigh). */
1431 valu
+= last_source_start_addr
;
1434 new = pop_context();
1435 if (desc
!= new->depth
)
1436 complain (&lbrac_mismatch_complaint
, (char *) symnum
);
1438 /* Some compilers put the variable decls inside of an
1439 LBRAC/RBRAC block. This macro should be nonzero if this
1440 is true. DESC is N_DESC from the N_RBRAC symbol.
1441 GCC_P is true if we've detected the GCC_COMPILED_SYMBOL
1442 or the GCC2_COMPILED_SYMBOL. */
1443 #if !defined (VARIABLES_INSIDE_BLOCK)
1444 #define VARIABLES_INSIDE_BLOCK(desc, gcc_p) 0
1447 /* Can only use new->locals as local symbols here if we're in
1448 gcc or on a machine that puts them before the lbrack. */
1449 if (!VARIABLES_INSIDE_BLOCK(desc
, processing_gcc_compilation
))
1450 local_symbols
= new->locals
;
1452 /* If this is not the outermost LBRAC...RBRAC pair in the
1453 function, its local symbols preceded it, and are the ones
1454 just recovered from the context stack. Defined the block for them.
1456 If this is the outermost LBRAC...RBRAC pair, there is no
1457 need to do anything; leave the symbols that preceded it
1458 to be attached to the function's own block. However, if
1459 it is so, we need to indicate that we just moved outside
1462 && (context_stack_depth
1463 > !VARIABLES_INSIDE_BLOCK(desc
, processing_gcc_compilation
)))
1465 /* FIXME Muzzle a compiler bug that makes end < start. */
1466 if (new->start_addr
> valu
)
1468 complain(&lbrac_rbrac_complaint
, 0);
1469 new->start_addr
= valu
;
1471 /* Make a block for the local symbols within. */
1472 finish_block (0, &local_symbols
, new->old_blocks
,
1473 new->start_addr
, valu
, our_objfile
);
1477 within_function
= 0;
1479 if (VARIABLES_INSIDE_BLOCK(desc
, processing_gcc_compilation
))
1480 /* Now pop locals of block just finished. */
1481 local_symbols
= new->locals
;
1486 /* This kind of symbol indicates the start of an object file. */
1487 valu
+= offset
; /* Relocate for dynamic loading */
1491 /* This type of symbol indicates the start of data
1492 for one source file.
1493 Finish the symbol table of the previous source file
1494 (if any) and start accumulating a new symbol table. */
1495 valu
+= offset
; /* Relocate for dynamic loading */
1497 #ifndef SUN_FIXED_LBRAC_BUG
1498 last_pc_address
= valu
; /* Save for SunOS bug circumcision */
1501 #ifdef PCC_SOL_BROKEN
1502 /* pcc bug, occasionally puts out SO for SOL. */
1503 if (context_stack_depth
> 0)
1505 start_subfile (name
, NULL
);
1509 if (last_source_file
)
1511 /* Check if previous symbol was also an N_SO (with some
1512 sanity checks). If so, that one was actually the directory
1513 name, and the current one is the real file name.
1515 if (previous_stab_code
== N_SO
1516 && current_subfile
&& current_subfile
->dirname
== NULL
1517 && current_subfile
->name
!= NULL
1518 && current_subfile
->name
[strlen(current_subfile
->name
)-1] == '/')
1520 current_subfile
->dirname
= current_subfile
->name
;
1521 current_subfile
->name
=
1522 obsavestring (name
, strlen (name
),
1523 &our_objfile
-> symbol_obstack
);
1526 (void) end_symtab (valu
, 0, 0, our_objfile
);
1528 start_symtab (name
, NULL
, valu
);
1533 /* This type of symbol indicates the start of data for
1534 a sub-source-file, one whose contents were copied or
1535 included in the compilation of the main source file
1536 (whose name was given in the N_SO symbol.) */
1537 valu
+= offset
; /* Relocate for dynamic loading */
1538 start_subfile (name
, NULL
);
1543 add_new_header_file (name
, valu
);
1544 start_subfile (name
, NULL
);
1548 start_subfile (pop_subfile (), NULL
);
1552 add_old_header_file (name
, valu
);
1556 /* This type of "symbol" really just records
1557 one line-number -- core-address correspondence.
1558 Enter it in the line list for this symbol table. */
1559 valu
+= offset
; /* Relocate for dynamic loading */
1560 #ifndef SUN_FIXED_LBRAC_BUG
1561 last_pc_address
= valu
; /* Save for SunOS bug circumcision */
1563 record_line (current_subfile
, desc
, valu
);
1568 error ("Invalid symbol data: common within common at symtab pos %d",
1570 common_block
= local_symbols
;
1571 common_block_i
= local_symbols
? local_symbols
->nsyms
: 0;
1575 /* Symbols declared since the BCOMM are to have the common block
1576 start address added in when we know it. common_block points to
1577 the first symbol after the BCOMM in the local_symbols list;
1578 copy the list and hang it off the symbol for the common block name
1582 struct symbol
*sym
=
1583 (struct symbol
*) xmmalloc (our_objfile
-> md
, sizeof (struct symbol
));
1584 bzero (sym
, sizeof *sym
);
1585 SYMBOL_NAME (sym
) = savestring (name
, strlen (name
));
1586 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1587 SYMBOL_NAMESPACE (sym
) = (enum namespace)((long)
1588 copy_pending (local_symbols
, common_block_i
, common_block
));
1589 i
= hashname (SYMBOL_NAME (sym
));
1590 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
1591 global_sym_chain
[i
] = sym
;
1596 /* The following symbol types need to have the offset added to their
1597 value; then we process symbol definitions in the name. */
1598 case N_STSYM
: /* Global symbol */
1599 case N_LCSYM
: /* Local symbol */
1600 case N_DSLINE
: /* Source line number, data seg */
1601 case N_BSLINE
: /* Source line number, bss seg */
1602 /* N_BROWS: overlaps with N_BSLINE */
1603 case N_ENTRY
: /* Alternate entry point */
1604 valu
+= offset
; /* Relocate for dynamic loading */
1607 /* The following symbol types don't need the address field relocated,
1608 since it is either unused, or is absolute. */
1609 case N_GSYM
: /* Global variable */
1610 case N_NSYMS
: /* Number of symbols (ultrix) */
1611 case N_NOMAP
: /* No map? (ultrix) */
1612 case N_RSYM
: /* Register variable */
1613 case N_DEFD
: /* Modula-2 GNU module dependency */
1614 case N_SSYM
: /* Struct or union element */
1615 case N_LSYM
: /* Local symbol in stack */
1616 case N_PSYM
: /* Parameter variable */
1617 case N_LENG
: /* Length of preceding symbol type */
1619 define_symbol (valu
, name
, desc
, type
, our_objfile
);
1622 /* The following symbol types we don't know how to process. Handle
1623 them in a "default" way, but complain to people who care. */
1625 case N_EHDECL
: /* Exception handler name */
1626 case N_MAIN
: /* Name of main routine (not used in C) */
1627 case N_PC
: /* Global symbol in Pascal */
1628 case N_M2C
: /* Modula-2 compilation unit */
1629 /* N_MOD2: overlaps with N_EHDECL */
1630 case N_SCOPE
: /* Modula-2 scope information */
1631 case N_ECOML
: /* End common (local name) */
1632 case N_NBTEXT
: /* Gould Non-Base-Register symbols??? */
1637 complain (&unknown_symtype_complaint
, local_hex_string(type
));
1639 define_symbol (valu
, name
, desc
, type
, our_objfile
);
1642 previous_stab_code
= type
;
1645 /* Copy a pending list, used to record the contents of a common
1646 block for later fixup. */
1647 static struct pending
*
1648 copy_pending (beg
, begi
, end
)
1649 struct pending
*beg
;
1651 struct pending
*end
;
1653 struct pending
*new = 0;
1654 struct pending
*next
;
1656 for (next
= beg
; next
!= 0 && (next
!= end
|| begi
< end
->nsyms
);
1657 next
= next
->next
, begi
= 0)
1660 for (j
= begi
; j
< next
->nsyms
; j
++)
1661 add_symbol_to_list (next
->symbol
[j
], &new);
1666 /* Register our willingness to decode symbols for SunOS and a.out and
1667 b.out files handled by BFD... */
1668 static struct sym_fns sunos_sym_fns
= {"sunOs", 6,
1669 dbx_new_init
, dbx_symfile_init
, dbx_symfile_read
};
1671 static struct sym_fns aout_sym_fns
= {"a.out", 5,
1672 dbx_new_init
, dbx_symfile_init
, dbx_symfile_read
};
1674 static struct sym_fns bout_sym_fns
= {"b.out", 5,
1675 dbx_new_init
, dbx_symfile_init
, dbx_symfile_read
};
1678 _initialize_dbxread ()
1680 add_symtab_fns(&sunos_sym_fns
);
1681 add_symtab_fns(&aout_sym_fns
);
1682 add_symtab_fns(&bout_sym_fns
);