New file describing how stabs for live range splitting work. Should be
[deliverable/binutils-gdb.git] / gdb / dbxread.c
1 /* Read dbx symbol tables and convert to internal format, for GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
3 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21 /* This module provides three functions: dbx_symfile_init,
22 which initializes to read a symbol file; dbx_new_init, which
23 discards existing cached information when all symbols are being
24 discarded; and dbx_symfile_read, which reads a symbol table
25 from a file.
26
27 dbx_symfile_read only does the minimum work necessary for letting the
28 user "name" things symbolically; it does not read the entire symtab.
29 Instead, it reads the external and static symbols and puts them in partial
30 symbol tables. When more extensive information is requested of a
31 file, the corresponding partial symbol table is mutated into a full
32 fledged symbol table by going back and reading the symbols
33 for real. dbx_psymtab_to_symtab() is the function that does this */
34
35 #include "defs.h"
36 #include "gdb_string.h"
37
38 #if defined(USG) || defined(__CYGNUSCLIB__)
39 #include <sys/types.h>
40 #include <fcntl.h>
41 #endif
42
43 #include "obstack.h"
44 #include "gdb_stat.h"
45 #include <ctype.h>
46 #include "symtab.h"
47 #include "breakpoint.h"
48 #include "command.h"
49 #include "target.h"
50 #include "gdbcore.h" /* for bfd stuff */
51 #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
52 #include "symfile.h"
53 #include "objfiles.h"
54 #include "buildsym.h"
55 #include "stabsread.h"
56 #include "gdb-stabs.h"
57 #include "demangle.h"
58 #include "language.h" /* Needed inside partial-stab.h */
59 #include "complaints.h"
60
61 #include "aout/aout64.h"
62 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native, now */
63
64 \f
65 /* This macro returns the size field of a minimal symbol, which is normally
66 stored in the "info" field. The macro can be overridden for specific
67 targets (e.g. MIPS16) that use the info field for other purposes. */
68 #ifndef MSYMBOL_SIZE
69 #define MSYMBOL_SIZE(msym) ((long) MSYMBOL_INFO (msym))
70 #endif
71
72
73 /* We put a pointer to this structure in the read_symtab_private field
74 of the psymtab. */
75
76 struct symloc {
77
78 /* Offset within the file symbol table of first local symbol for this
79 file. */
80
81 int ldsymoff;
82
83 /* Length (in bytes) of the section of the symbol table devoted to
84 this file's symbols (actually, the section bracketed may contain
85 more than just this file's symbols). If ldsymlen is 0, the only
86 reason for this thing's existence is the dependency list. Nothing
87 else will happen when it is read in. */
88
89 int ldsymlen;
90
91 /* The size of each symbol in the symbol file (in external form). */
92
93 int symbol_size;
94
95 /* Further information needed to locate the symbols if they are in
96 an ELF file. */
97
98 int symbol_offset;
99 int string_offset;
100 int file_string_offset;
101 };
102
103 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
104 #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
105 #define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private))
106 #define SYMBOL_SIZE(p) (SYMLOC(p)->symbol_size)
107 #define SYMBOL_OFFSET(p) (SYMLOC(p)->symbol_offset)
108 #define STRING_OFFSET(p) (SYMLOC(p)->string_offset)
109 #define FILE_STRING_OFFSET(p) (SYMLOC(p)->file_string_offset)
110
111 \f
112 /* Macro to determine which symbols to ignore when reading the first symbol
113 of a file. Some machines override this definition. */
114 #ifndef IGNORE_SYMBOL
115 /* This code is used on Ultrix systems. Ignore it */
116 #define IGNORE_SYMBOL(type) (type == (int)N_NSYMS)
117 #endif
118
119 /* Remember what we deduced to be the source language of this psymtab. */
120
121 static enum language psymtab_language = language_unknown;
122
123 /* Nonzero means give verbose info on gdb action. From main.c. */
124 extern int info_verbose;
125
126 /* The BFD for this file -- implicit parameter to next_symbol_text. */
127
128 static bfd *symfile_bfd;
129
130 /* The size of each symbol in the symbol file (in external form).
131 This is set by dbx_symfile_read when building psymtabs, and by
132 dbx_psymtab_to_symtab when building symtabs. */
133
134 static unsigned symbol_size;
135
136 /* This is the offset of the symbol table in the executable file */
137 static unsigned symbol_table_offset;
138
139 /* This is the offset of the string table in the executable file */
140 static unsigned string_table_offset;
141
142 /* For elf+stab executables, the n_strx field is not a simple index
143 into the string table. Instead, each .o file has a base offset
144 in the string table, and the associated symbols contain offsets
145 from this base. The following two variables contain the base
146 offset for the current and next .o files. */
147 static unsigned int file_string_table_offset;
148 static unsigned int next_file_string_table_offset;
149
150 /* .o and NLM files contain unrelocated addresses which are based at 0. When
151 non-zero, this flag disables some of the special cases for Solaris elf+stab
152 text addresses at location 0. */
153
154 static int symfile_relocatable = 0;
155
156 /* If this is nonzero, N_LBRAC, N_RBRAC, and N_SLINE entries are relative
157 to the function start address. */
158
159 static int block_address_function_relative = 0;
160 \f
161 /* The lowest text address we have yet encountered. This is needed
162 because in an a.out file, there is no header field which tells us
163 what address the program is actually going to be loaded at, so we
164 need to make guesses based on the symbols (which *are* relocated to
165 reflect the address it will be loaded at). */
166 static CORE_ADDR lowest_text_address;
167
168 /* Complaints about the symbols we have encountered. */
169
170 struct complaint lbrac_complaint =
171 {"bad block start address patched", 0, 0};
172
173 struct complaint string_table_offset_complaint =
174 {"bad string table offset in symbol %d", 0, 0};
175
176 struct complaint unknown_symtype_complaint =
177 {"unknown symbol type %s", 0, 0};
178
179 struct complaint unknown_symchar_complaint =
180 {"unknown symbol descriptor `%c'", 0, 0};
181
182 struct complaint lbrac_rbrac_complaint =
183 {"block start larger than block end", 0, 0};
184
185 struct complaint lbrac_unmatched_complaint =
186 {"unmatched N_LBRAC before symtab pos %d", 0, 0};
187
188 struct complaint lbrac_mismatch_complaint =
189 {"N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d", 0, 0};
190
191 struct complaint repeated_header_complaint =
192 {"\"repeated\" header file %s not previously seen, at symtab pos %d", 0, 0};
193
194 struct complaint unclaimed_bincl_complaint =
195 {"N_BINCL %s not in entries for any file, at symtab pos %d", 0, 0};
196 \f
197 /* During initial symbol readin, we need to have a structure to keep
198 track of which psymtabs have which bincls in them. This structure
199 is used during readin to setup the list of dependencies within each
200 partial symbol table. */
201
202 struct header_file_location
203 {
204 char *name; /* Name of header file */
205 int instance; /* See above */
206 struct partial_symtab *pst; /* Partial symtab that has the
207 BINCL/EINCL defs for this file */
208 };
209
210 /* The actual list and controling variables */
211 static struct header_file_location *bincl_list, *next_bincl;
212 static int bincls_allocated;
213
214 /* Local function prototypes */
215
216 static void
217 process_now PARAMS ((struct objfile *));
218
219 static void
220 free_header_files PARAMS ((void));
221
222 static void
223 init_header_files PARAMS ((void));
224
225 static void
226 read_ofile_symtab PARAMS ((struct partial_symtab *));
227
228 static void
229 dbx_psymtab_to_symtab PARAMS ((struct partial_symtab *));
230
231 static void
232 dbx_psymtab_to_symtab_1 PARAMS ((struct partial_symtab *));
233
234 static void
235 read_dbx_dynamic_symtab PARAMS ((struct section_offsets *,
236 struct objfile *objfile));
237
238 static void
239 read_dbx_symtab PARAMS ((struct section_offsets *, struct objfile *,
240 CORE_ADDR, int));
241
242 static void
243 free_bincl_list PARAMS ((struct objfile *));
244
245 static struct partial_symtab *
246 find_corresponding_bincl_psymtab PARAMS ((char *, int));
247
248 static void
249 add_bincl_to_list PARAMS ((struct partial_symtab *, char *, int));
250
251 static void
252 init_bincl_list PARAMS ((int, struct objfile *));
253
254 static char *
255 dbx_next_symbol_text PARAMS ((struct objfile *));
256
257 static void
258 fill_symbuf PARAMS ((bfd *));
259
260 static void
261 dbx_symfile_init PARAMS ((struct objfile *));
262
263 static void
264 dbx_new_init PARAMS ((struct objfile *));
265
266 static void
267 dbx_symfile_read PARAMS ((struct objfile *, struct section_offsets *, int));
268
269 static void
270 dbx_symfile_finish PARAMS ((struct objfile *));
271
272 static void
273 record_minimal_symbol PARAMS ((char *, CORE_ADDR, int, struct objfile *));
274
275 static void
276 add_new_header_file PARAMS ((char *, int));
277
278 static void
279 add_old_header_file PARAMS ((char *, int));
280
281 static void
282 add_this_object_header_file PARAMS ((int));
283
284 /* Free up old header file tables */
285
286 static void
287 free_header_files ()
288 {
289 if (this_object_header_files)
290 {
291 free ((PTR)this_object_header_files);
292 this_object_header_files = NULL;
293 }
294 n_allocated_this_object_header_files = 0;
295 }
296
297 /* Allocate new header file tables */
298
299 static void
300 init_header_files ()
301 {
302 n_allocated_this_object_header_files = 10;
303 this_object_header_files = (int *) xmalloc (10 * sizeof (int));
304 }
305
306 /* Add header file number I for this object file
307 at the next successive FILENUM. */
308
309 static void
310 add_this_object_header_file (i)
311 int i;
312 {
313 if (n_this_object_header_files == n_allocated_this_object_header_files)
314 {
315 n_allocated_this_object_header_files *= 2;
316 this_object_header_files
317 = (int *) xrealloc ((char *) this_object_header_files,
318 n_allocated_this_object_header_files * sizeof (int));
319 }
320
321 this_object_header_files[n_this_object_header_files++] = i;
322 }
323
324 /* Add to this file an "old" header file, one already seen in
325 a previous object file. NAME is the header file's name.
326 INSTANCE is its instance code, to select among multiple
327 symbol tables for the same header file. */
328
329 static void
330 add_old_header_file (name, instance)
331 char *name;
332 int instance;
333 {
334 register struct header_file *p = HEADER_FILES (current_objfile);
335 register int i;
336
337 for (i = 0; i < N_HEADER_FILES (current_objfile); i++)
338 if (STREQ (p[i].name, name) && instance == p[i].instance)
339 {
340 add_this_object_header_file (i);
341 return;
342 }
343 complain (&repeated_header_complaint, name, symnum);
344 }
345
346 /* Add to this file a "new" header file: definitions for its types follow.
347 NAME is the header file's name.
348 Most often this happens only once for each distinct header file,
349 but not necessarily. If it happens more than once, INSTANCE has
350 a different value each time, and references to the header file
351 use INSTANCE values to select among them.
352
353 dbx output contains "begin" and "end" markers for each new header file,
354 but at this level we just need to know which files there have been;
355 so we record the file when its "begin" is seen and ignore the "end". */
356
357 static void
358 add_new_header_file (name, instance)
359 char *name;
360 int instance;
361 {
362 register int i;
363 register struct header_file *hfile;
364
365 /* Make sure there is room for one more header file. */
366
367 i = N_ALLOCATED_HEADER_FILES (current_objfile);
368
369 if (N_HEADER_FILES (current_objfile) == i)
370 {
371 if (i == 0)
372 {
373 N_ALLOCATED_HEADER_FILES (current_objfile) = 10;
374 HEADER_FILES (current_objfile) = (struct header_file *)
375 xmalloc (10 * sizeof (struct header_file));
376 }
377 else
378 {
379 i *= 2;
380 N_ALLOCATED_HEADER_FILES (current_objfile) = i;
381 HEADER_FILES (current_objfile) = (struct header_file *)
382 xrealloc ((char *) HEADER_FILES (current_objfile),
383 (i * sizeof (struct header_file)));
384 }
385 }
386
387 /* Create an entry for this header file. */
388
389 i = N_HEADER_FILES (current_objfile)++;
390 hfile = HEADER_FILES (current_objfile) + i;
391 hfile->name = savestring (name, strlen(name));
392 hfile->instance = instance;
393 hfile->length = 10;
394 hfile->vector
395 = (struct type **) xmalloc (10 * sizeof (struct type *));
396 memset (hfile->vector, 0, 10 * sizeof (struct type *));
397
398 add_this_object_header_file (i);
399 }
400
401 #if 0
402 static struct type **
403 explicit_lookup_type (real_filenum, index)
404 int real_filenum, index;
405 {
406 register struct header_file *f = &HEADER_FILES (current_objfile)[real_filenum];
407
408 if (index >= f->length)
409 {
410 f->length *= 2;
411 f->vector = (struct type **)
412 xrealloc (f->vector, f->length * sizeof (struct type *));
413 memset (&f->vector[f->length / 2],
414 '\0', f->length * sizeof (struct type *) / 2);
415 }
416 return &f->vector[index];
417 }
418 #endif
419 \f
420 static void
421 record_minimal_symbol (name, address, type, objfile)
422 char *name;
423 CORE_ADDR address;
424 int type;
425 struct objfile *objfile;
426 {
427 enum minimal_symbol_type ms_type;
428 int section;
429 asection *bfd_section;
430
431 switch (type)
432 {
433 case N_TEXT | N_EXT:
434 ms_type = mst_text;
435 section = SECT_OFF_TEXT;
436 bfd_section = DBX_TEXT_SECTION (objfile);
437 break;
438 case N_DATA | N_EXT:
439 ms_type = mst_data;
440 section = SECT_OFF_DATA;
441 bfd_section = DBX_DATA_SECTION (objfile);
442 break;
443 case N_BSS | N_EXT:
444 ms_type = mst_bss;
445 section = SECT_OFF_BSS;
446 bfd_section = DBX_BSS_SECTION (objfile);
447 break;
448 case N_ABS | N_EXT:
449 ms_type = mst_abs;
450 section = -1;
451 bfd_section = NULL;
452 break;
453 #ifdef N_SETV
454 case N_SETV | N_EXT:
455 ms_type = mst_data;
456 section = SECT_OFF_DATA;
457 bfd_section = DBX_DATA_SECTION (objfile);
458 break;
459 case N_SETV:
460 /* I don't think this type actually exists; since a N_SETV is the result
461 of going over many .o files, it doesn't make sense to have one
462 file local. */
463 ms_type = mst_file_data;
464 section = SECT_OFF_DATA;
465 bfd_section = DBX_DATA_SECTION (objfile);
466 break;
467 #endif
468 case N_TEXT:
469 case N_NBTEXT:
470 case N_FN:
471 case N_FN_SEQ:
472 ms_type = mst_file_text;
473 section = SECT_OFF_TEXT;
474 bfd_section = DBX_TEXT_SECTION (objfile);
475 break;
476 case N_DATA:
477 ms_type = mst_file_data;
478
479 /* Check for __DYNAMIC, which is used by Sun shared libraries.
480 Record it as global even if it's local, not global, so
481 lookup_minimal_symbol can find it. We don't check symbol_leading_char
482 because for SunOS4 it always is '_'. */
483 if (name[8] == 'C' && STREQ ("__DYNAMIC", name))
484 ms_type = mst_data;
485
486 /* Same with virtual function tables, both global and static. */
487 {
488 char *tempstring = name;
489 if (tempstring[0] == bfd_get_symbol_leading_char (objfile->obfd))
490 ++tempstring;
491 if (VTBL_PREFIX_P ((tempstring)))
492 ms_type = mst_data;
493 }
494 section = SECT_OFF_DATA;
495 bfd_section = DBX_DATA_SECTION (objfile);
496 break;
497 case N_BSS:
498 ms_type = mst_file_bss;
499 section = SECT_OFF_BSS;
500 bfd_section = DBX_BSS_SECTION (objfile);
501 break;
502 default:
503 ms_type = mst_unknown;
504 section = -1;
505 bfd_section = NULL;
506 break;
507 }
508
509 if ((ms_type == mst_file_text || ms_type == mst_text)
510 && address < lowest_text_address)
511 lowest_text_address = address;
512
513 prim_record_minimal_symbol_and_info
514 (name, address, ms_type, NULL, section, bfd_section, objfile);
515 }
516 \f
517 /* Scan and build partial symbols for a symbol file.
518 We have been initialized by a call to dbx_symfile_init, which
519 put all the relevant info into a "struct dbx_symfile_info",
520 hung off the objfile structure.
521
522 SECTION_OFFSETS contains offsets relative to which the symbols in the
523 various sections are (depending where the sections were actually loaded).
524 MAINLINE is true if we are reading the main symbol
525 table (as opposed to a shared lib or dynamically loaded file). */
526
527 static void
528 dbx_symfile_read (objfile, section_offsets, mainline)
529 struct objfile *objfile;
530 struct section_offsets *section_offsets;
531 int mainline; /* FIXME comments above */
532 {
533 bfd *sym_bfd;
534 int val;
535 struct cleanup *back_to;
536
537 val = strlen (objfile->name);
538
539 sym_bfd = objfile->obfd;
540
541 /* .o and .nlm files are relocatables with text, data and bss segs based at
542 0. This flag disables special (Solaris stabs-in-elf only) fixups for
543 symbols with a value of 0. */
544
545 symfile_relocatable = bfd_get_file_flags (sym_bfd) & HAS_RELOC;
546
547 /* This is true for Solaris (and all other systems which put stabs
548 in sections, hopefully, since it would be silly to do things
549 differently from Solaris), and false for SunOS4 and other a.out
550 file formats. */
551 block_address_function_relative =
552 ((0 == strncmp (bfd_get_target (sym_bfd), "elf", 3))
553 || (0 == strncmp (bfd_get_target (sym_bfd), "som", 3))
554 || (0 == strncmp (bfd_get_target (sym_bfd), "coff", 4))
555 || (0 == strncmp (bfd_get_target (sym_bfd), "pe", 2))
556 || (0 == strncmp (bfd_get_target (sym_bfd), "nlm", 3)));
557
558 val = bfd_seek (sym_bfd, DBX_SYMTAB_OFFSET (objfile), SEEK_SET);
559 if (val < 0)
560 perror_with_name (objfile->name);
561
562 /* If we are reinitializing, or if we have never loaded syms yet, init */
563 if (mainline
564 || objfile->global_psymbols.size == 0
565 || objfile->static_psymbols.size == 0)
566 init_psymbol_list (objfile, DBX_SYMCOUNT (objfile));
567
568 symbol_size = DBX_SYMBOL_SIZE (objfile);
569 symbol_table_offset = DBX_SYMTAB_OFFSET (objfile);
570
571 free_pending_blocks ();
572 back_to = make_cleanup (really_free_pendings, 0);
573
574 init_minimal_symbol_collection ();
575 make_cleanup (discard_minimal_symbols, 0);
576
577 /* Now that the symbol table data of the executable file are all in core,
578 process them and define symbols accordingly. */
579
580 read_dbx_symtab (section_offsets, objfile,
581 DBX_TEXT_ADDR (objfile),
582 DBX_TEXT_SIZE (objfile));
583
584 /* Add the dynamic symbols. */
585
586 read_dbx_dynamic_symtab (section_offsets, objfile);
587
588 /* Install any minimal symbols that have been collected as the current
589 minimal symbols for this objfile. */
590
591 install_minimal_symbols (objfile);
592
593 do_cleanups (back_to);
594 }
595
596 /* Initialize anything that needs initializing when a completely new
597 symbol file is specified (not just adding some symbols from another
598 file, e.g. a shared library). */
599
600 static void
601 dbx_new_init (ignore)
602 struct objfile *ignore;
603 {
604 stabsread_new_init ();
605 buildsym_new_init ();
606 init_header_files ();
607 }
608
609
610 /* dbx_symfile_init ()
611 is the dbx-specific initialization routine for reading symbols.
612 It is passed a struct objfile which contains, among other things,
613 the BFD for the file whose symbols are being read, and a slot for a pointer
614 to "private data" which we fill with goodies.
615
616 We read the string table into malloc'd space and stash a pointer to it.
617
618 Since BFD doesn't know how to read debug symbols in a format-independent
619 way (and may never do so...), we have to do it ourselves. We will never
620 be called unless this is an a.out (or very similar) file.
621 FIXME, there should be a cleaner peephole into the BFD environment here. */
622
623 #define DBX_STRINGTAB_SIZE_SIZE sizeof(long) /* FIXME */
624
625 static void
626 dbx_symfile_init (objfile)
627 struct objfile *objfile;
628 {
629 int val;
630 bfd *sym_bfd = objfile->obfd;
631 char *name = bfd_get_filename (sym_bfd);
632 asection *text_sect;
633 unsigned char size_temp[DBX_STRINGTAB_SIZE_SIZE];
634
635 /* Allocate struct to keep track of the symfile */
636 objfile->sym_stab_info = (PTR)
637 xmmalloc (objfile -> md, sizeof (struct dbx_symfile_info));
638 memset ((PTR) objfile->sym_stab_info, 0, sizeof (struct dbx_symfile_info));
639
640 DBX_TEXT_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".text");
641 DBX_DATA_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".data");
642 DBX_BSS_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".bss");
643
644 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
645 #define STRING_TABLE_OFFSET (sym_bfd->origin + obj_str_filepos (sym_bfd))
646 #define SYMBOL_TABLE_OFFSET (sym_bfd->origin + obj_sym_filepos (sym_bfd))
647
648 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
649
650 DBX_SYMFILE_INFO (objfile)->stab_section_info = NULL;
651
652 text_sect = bfd_get_section_by_name (sym_bfd, ".text");
653 if (!text_sect)
654 error ("Can't find .text section in symbol file");
655 DBX_TEXT_ADDR (objfile) = bfd_section_vma (sym_bfd, text_sect);
656 DBX_TEXT_SIZE (objfile) = bfd_section_size (sym_bfd, text_sect);
657
658 DBX_SYMBOL_SIZE (objfile) = obj_symbol_entry_size (sym_bfd);
659 DBX_SYMCOUNT (objfile) = bfd_get_symcount (sym_bfd);
660 DBX_SYMTAB_OFFSET (objfile) = SYMBOL_TABLE_OFFSET;
661
662 /* Read the string table and stash it away in the psymbol_obstack. It is
663 only needed as long as we need to expand psymbols into full symbols,
664 so when we blow away the psymbol the string table goes away as well.
665 Note that gdb used to use the results of attempting to malloc the
666 string table, based on the size it read, as a form of sanity check
667 for botched byte swapping, on the theory that a byte swapped string
668 table size would be so totally bogus that the malloc would fail. Now
669 that we put in on the psymbol_obstack, we can't do this since gdb gets
670 a fatal error (out of virtual memory) if the size is bogus. We can
671 however at least check to see if the size is less than the size of
672 the size field itself, or larger than the size of the entire file.
673 Note that all valid string tables have a size greater than zero, since
674 the bytes used to hold the size are included in the count. */
675
676 if (STRING_TABLE_OFFSET == 0)
677 {
678 /* It appears that with the existing bfd code, STRING_TABLE_OFFSET
679 will never be zero, even when there is no string table. This
680 would appear to be a bug in bfd. */
681 DBX_STRINGTAB_SIZE (objfile) = 0;
682 DBX_STRINGTAB (objfile) = NULL;
683 }
684 else
685 {
686 val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, SEEK_SET);
687 if (val < 0)
688 perror_with_name (name);
689
690 memset ((PTR) size_temp, 0, sizeof (size_temp));
691 val = bfd_read ((PTR) size_temp, sizeof (size_temp), 1, sym_bfd);
692 if (val < 0)
693 {
694 perror_with_name (name);
695 }
696 else if (val == 0)
697 {
698 /* With the existing bfd code, STRING_TABLE_OFFSET will be set to
699 EOF if there is no string table, and attempting to read the size
700 from EOF will read zero bytes. */
701 DBX_STRINGTAB_SIZE (objfile) = 0;
702 DBX_STRINGTAB (objfile) = NULL;
703 }
704 else
705 {
706 /* Read some data that would appear to be the string table size.
707 If there really is a string table, then it is probably the right
708 size. Byteswap if necessary and validate the size. Note that
709 the minimum is DBX_STRINGTAB_SIZE_SIZE. If we just read some
710 random data that happened to be at STRING_TABLE_OFFSET, because
711 bfd can't tell us there is no string table, the sanity checks may
712 or may not catch this. */
713 DBX_STRINGTAB_SIZE (objfile) = bfd_h_get_32 (sym_bfd, size_temp);
714
715 if (DBX_STRINGTAB_SIZE (objfile) < sizeof (size_temp)
716 || DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd))
717 error ("ridiculous string table size (%d bytes).",
718 DBX_STRINGTAB_SIZE (objfile));
719
720 DBX_STRINGTAB (objfile) =
721 (char *) obstack_alloc (&objfile -> psymbol_obstack,
722 DBX_STRINGTAB_SIZE (objfile));
723 OBJSTAT (objfile, sz_strtab += DBX_STRINGTAB_SIZE (objfile));
724
725 /* Now read in the string table in one big gulp. */
726
727 val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, SEEK_SET);
728 if (val < 0)
729 perror_with_name (name);
730 val = bfd_read (DBX_STRINGTAB (objfile), DBX_STRINGTAB_SIZE (objfile), 1,
731 sym_bfd);
732 if (val != DBX_STRINGTAB_SIZE (objfile))
733 perror_with_name (name);
734 }
735 }
736 }
737
738 /* Perform any local cleanups required when we are done with a particular
739 objfile. I.E, we are in the process of discarding all symbol information
740 for an objfile, freeing up all memory held for it, and unlinking the
741 objfile struct from the global list of known objfiles. */
742
743 static void
744 dbx_symfile_finish (objfile)
745 struct objfile *objfile;
746 {
747 if (objfile->sym_stab_info != NULL)
748 {
749 if (HEADER_FILES (objfile) != NULL)
750 {
751 register int i = N_HEADER_FILES (objfile);
752 register struct header_file *hfiles = HEADER_FILES (objfile);
753
754 while (--i >= 0)
755 {
756 free (hfiles [i].name);
757 free (hfiles [i].vector);
758 }
759 free ((PTR) hfiles);
760 }
761 mfree (objfile -> md, objfile->sym_stab_info);
762 }
763 free_header_files ();
764 }
765
766 \f
767 /* Buffer for reading the symbol table entries. */
768 static struct external_nlist symbuf[4096];
769 static int symbuf_idx;
770 static int symbuf_end;
771
772 /* cont_elem is used for continuing information in cfront.
773 It saves information about which types need to be fixed up and
774 completed after all the stabs are read. */
775 struct cont_elem
776 {
777 /* sym and stabsstring for continuing information in cfront */
778 struct symbol * sym;
779 char * stabs;
780 /* state dependancies (statics that must be preserved) */
781 int sym_idx;
782 int sym_end;
783 int symnum;
784 int (*func) PARAMS ((struct objfile *, struct symbol *, char *));
785 /* other state dependancies include:
786 (assumption is that these will not change since process_now FIXME!!)
787 stringtab_global
788 n_stabs
789 objfile
790 symfile_bfd */
791 };
792
793 static struct cont_elem *cont_list = 0;
794 static int cont_limit = 0;
795 static int cont_count = 0;
796
797 void
798 process_later (sym, p, f)
799 struct symbol * sym;
800 char * p;
801 int (*f) PARAMS ((struct objfile *, struct symbol *, char *));
802 {
803 if (cont_count >= cont_limit - 1)
804 {
805 cont_limit += 32; /* chunk size */
806 cont_list = (struct cont_elem *) realloc (cont_list,
807 cont_limit * sizeof (struct cont_elem));
808 if (!cont_list)
809 error ("Virtual memory exhausted\n");
810 }
811 /* save state so we can process these stabs later */
812 cont_list[cont_count].sym_idx = symbuf_idx;
813 cont_list[cont_count].sym_end = symbuf_end;
814 cont_list[cont_count].symnum = symnum;
815 cont_list[cont_count].sym = sym;
816 cont_list[cont_count].stabs = p;
817 cont_list[cont_count].func = f;
818 cont_count++;
819 }
820
821 static void
822 process_now (objfile)
823 struct objfile * objfile;
824 {
825 int i;
826 /* save original state */
827 int save_symbuf_idx = symbuf_idx;
828 int save_symbuf_end = symbuf_end;
829 int save_symnum = symnum;
830 struct symbol *sym;
831 char *stabs;
832 int err;
833 int (*func) PARAMS ((struct objfile *, struct symbol *, char *));
834
835 for (i=0; i<cont_count; i++)
836 {
837 /* Set state as if we were parsing stabs strings
838 for this symbol */
839 symbuf_idx = cont_list[i].sym_idx; /* statics used by gdb */
840 symbuf_end = cont_list[i].sym_end;
841 symnum = cont_list[i].symnum;
842 sym = cont_list[i].sym;
843 stabs = cont_list[i].stabs;
844 func = cont_list[i].func;
845
846 err = (*func) (objfile, sym, stabs);
847 if (err)
848 error ("Internal error: unable to resolve stab.\n");
849 }
850 /* restore original state */
851 symbuf_idx = save_symbuf_idx;
852 symbuf_end = save_symbuf_end;
853 symnum = save_symnum;
854 cont_count=0; /* reset for next run */
855 }
856
857
858 /* Name of last function encountered. Used in Solaris to approximate
859 object file boundaries. */
860 static char *last_function_name;
861
862 /* The address in memory of the string table of the object file we are
863 reading (which might not be the "main" object file, but might be a
864 shared library or some other dynamically loaded thing). This is
865 set by read_dbx_symtab when building psymtabs, and by
866 read_ofile_symtab when building symtabs, and is used only by
867 next_symbol_text. FIXME: If that is true, we don't need it when
868 building psymtabs, right? */
869 static char *stringtab_global;
870
871 /* These variables are used to control fill_symbuf when the stabs
872 symbols are not contiguous (as may be the case when a COFF file is
873 linked using --split-by-reloc). */
874 static struct stab_section_list *symbuf_sections;
875 static unsigned int symbuf_left;
876 static unsigned int symbuf_read;
877
878 /* Refill the symbol table input buffer
879 and set the variables that control fetching entries from it.
880 Reports an error if no data available.
881 This function can read past the end of the symbol table
882 (into the string table) but this does no harm. */
883
884 static void
885 fill_symbuf (sym_bfd)
886 bfd *sym_bfd;
887 {
888 unsigned int count;
889 int nbytes;
890
891 if (symbuf_sections == NULL)
892 count = sizeof (symbuf);
893 else
894 {
895 if (symbuf_left <= 0)
896 {
897 file_ptr filepos = symbuf_sections->section->filepos;
898 if (bfd_seek (sym_bfd, filepos, SEEK_SET) != 0)
899 perror_with_name (bfd_get_filename (sym_bfd));
900 symbuf_left = bfd_section_size (sym_bfd, symbuf_sections->section);
901 symbol_table_offset = filepos - symbuf_read;
902 symbuf_sections = symbuf_sections->next;
903 }
904
905 count = symbuf_left;
906 if (count > sizeof (symbuf))
907 count = sizeof (symbuf);
908 }
909
910 nbytes = bfd_read ((PTR)symbuf, count, 1, sym_bfd);
911 if (nbytes < 0)
912 perror_with_name (bfd_get_filename (sym_bfd));
913 else if (nbytes == 0)
914 error ("Premature end of file reading symbol table");
915 symbuf_end = nbytes / symbol_size;
916 symbuf_idx = 0;
917 symbuf_left -= nbytes;
918 symbuf_read += nbytes;
919 }
920
921 #define SWAP_SYMBOL(symp, abfd) \
922 { \
923 (symp)->n_strx = bfd_h_get_32(abfd, \
924 (unsigned char *)&(symp)->n_strx); \
925 (symp)->n_desc = bfd_h_get_16 (abfd, \
926 (unsigned char *)&(symp)->n_desc); \
927 (symp)->n_value = bfd_h_get_32 (abfd, \
928 (unsigned char *)&(symp)->n_value); \
929 }
930
931 #define INTERNALIZE_SYMBOL(intern, extern, abfd) \
932 { \
933 (intern).n_type = bfd_h_get_8 (abfd, (extern)->e_type); \
934 (intern).n_strx = bfd_h_get_32 (abfd, (extern)->e_strx); \
935 (intern).n_desc = bfd_h_get_16 (abfd, (extern)->e_desc); \
936 (intern).n_value = bfd_h_get_32 (abfd, (extern)->e_value); \
937 }
938
939 /* Invariant: The symbol pointed to by symbuf_idx is the first one
940 that hasn't been swapped. Swap the symbol at the same time
941 that symbuf_idx is incremented. */
942
943 /* dbx allows the text of a symbol name to be continued into the
944 next symbol name! When such a continuation is encountered
945 (a \ at the end of the text of a name)
946 call this function to get the continuation. */
947
948 static char *
949 dbx_next_symbol_text (objfile)
950 struct objfile *objfile;
951 {
952 struct internal_nlist nlist;
953
954 if (symbuf_idx == symbuf_end)
955 fill_symbuf (symfile_bfd);
956
957 symnum++;
958 INTERNALIZE_SYMBOL(nlist, &symbuf[symbuf_idx], symfile_bfd);
959 OBJSTAT (objfile, n_stabs++);
960
961 symbuf_idx++;
962
963 return nlist.n_strx + stringtab_global + file_string_table_offset;
964 }
965 \f
966 /* Initialize the list of bincls to contain none and have some
967 allocated. */
968
969 static void
970 init_bincl_list (number, objfile)
971 int number;
972 struct objfile *objfile;
973 {
974 bincls_allocated = number;
975 next_bincl = bincl_list = (struct header_file_location *)
976 xmmalloc (objfile -> md, bincls_allocated * sizeof(struct header_file_location));
977 }
978
979 /* Add a bincl to the list. */
980
981 static void
982 add_bincl_to_list (pst, name, instance)
983 struct partial_symtab *pst;
984 char *name;
985 int instance;
986 {
987 if (next_bincl >= bincl_list + bincls_allocated)
988 {
989 int offset = next_bincl - bincl_list;
990 bincls_allocated *= 2;
991 bincl_list = (struct header_file_location *)
992 xmrealloc (pst->objfile->md, (char *)bincl_list,
993 bincls_allocated * sizeof (struct header_file_location));
994 next_bincl = bincl_list + offset;
995 }
996 next_bincl->pst = pst;
997 next_bincl->instance = instance;
998 next_bincl++->name = name;
999 }
1000
1001 /* Given a name, value pair, find the corresponding
1002 bincl in the list. Return the partial symtab associated
1003 with that header_file_location. */
1004
1005 static struct partial_symtab *
1006 find_corresponding_bincl_psymtab (name, instance)
1007 char *name;
1008 int instance;
1009 {
1010 struct header_file_location *bincl;
1011
1012 for (bincl = bincl_list; bincl < next_bincl; bincl++)
1013 if (bincl->instance == instance
1014 && STREQ (name, bincl->name))
1015 return bincl->pst;
1016
1017 complain (&repeated_header_complaint, name, symnum);
1018 return (struct partial_symtab *) 0;
1019 }
1020
1021 /* Free the storage allocated for the bincl list. */
1022
1023 static void
1024 free_bincl_list (objfile)
1025 struct objfile *objfile;
1026 {
1027 mfree (objfile -> md, (PTR)bincl_list);
1028 bincls_allocated = 0;
1029 }
1030
1031 /* Scan a SunOs dynamic symbol table for symbols of interest and
1032 add them to the minimal symbol table. */
1033
1034 static void
1035 read_dbx_dynamic_symtab (section_offsets, objfile)
1036 struct section_offsets *section_offsets;
1037 struct objfile *objfile;
1038 {
1039 bfd *abfd = objfile->obfd;
1040 struct cleanup *back_to;
1041 int counter;
1042 long dynsym_size;
1043 long dynsym_count;
1044 asymbol **dynsyms;
1045 asymbol **symptr;
1046 arelent **relptr;
1047 long dynrel_size;
1048 long dynrel_count;
1049 arelent **dynrels;
1050 CORE_ADDR sym_value;
1051 char *name;
1052
1053 /* Check that the symbol file has dynamic symbols that we know about.
1054 bfd_arch_unknown can happen if we are reading a sun3 symbol file
1055 on a sun4 host (and vice versa) and bfd is not configured
1056 --with-target=all. This would trigger an assertion in bfd/sunos.c,
1057 so we ignore the dynamic symbols in this case. */
1058 if (bfd_get_flavour (abfd) != bfd_target_aout_flavour
1059 || (bfd_get_file_flags (abfd) & DYNAMIC) == 0
1060 || bfd_get_arch (abfd) == bfd_arch_unknown)
1061 return;
1062
1063 dynsym_size = bfd_get_dynamic_symtab_upper_bound (abfd);
1064 if (dynsym_size < 0)
1065 return;
1066
1067 dynsyms = (asymbol **) xmalloc (dynsym_size);
1068 back_to = make_cleanup (free, dynsyms);
1069
1070 dynsym_count = bfd_canonicalize_dynamic_symtab (abfd, dynsyms);
1071 if (dynsym_count < 0)
1072 {
1073 do_cleanups (back_to);
1074 return;
1075 }
1076
1077 /* Enter dynamic symbols into the minimal symbol table
1078 if this is a stripped executable. */
1079 if (bfd_get_symcount (abfd) <= 0)
1080 {
1081 symptr = dynsyms;
1082 for (counter = 0; counter < dynsym_count; counter++, symptr++)
1083 {
1084 asymbol *sym = *symptr;
1085 asection *sec;
1086 int type;
1087
1088 sec = bfd_get_section (sym);
1089
1090 /* BFD symbols are section relative. */
1091 sym_value = sym->value + sec->vma;
1092
1093 if (bfd_get_section_flags (abfd, sec) & SEC_CODE)
1094 {
1095 sym_value += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1096 type = N_TEXT;
1097 }
1098 else if (bfd_get_section_flags (abfd, sec) & SEC_DATA)
1099 {
1100 sym_value += ANOFFSET (section_offsets, SECT_OFF_DATA);
1101 type = N_DATA;
1102 }
1103 else if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
1104 {
1105 sym_value += ANOFFSET (section_offsets, SECT_OFF_BSS);
1106 type = N_BSS;
1107 }
1108 else
1109 continue;
1110
1111 if (sym->flags & BSF_GLOBAL)
1112 type |= N_EXT;
1113
1114 record_minimal_symbol ((char *) bfd_asymbol_name (sym), sym_value,
1115 type, objfile);
1116 }
1117 }
1118
1119 /* Symbols from shared libraries have a dynamic relocation entry
1120 that points to the associated slot in the procedure linkage table.
1121 We make a mininal symbol table entry with type mst_solib_trampoline
1122 at the address in the procedure linkage table. */
1123 dynrel_size = bfd_get_dynamic_reloc_upper_bound (abfd);
1124 if (dynrel_size < 0)
1125 {
1126 do_cleanups (back_to);
1127 return;
1128 }
1129
1130 dynrels = (arelent **) xmalloc (dynrel_size);
1131 make_cleanup (free, dynrels);
1132
1133 dynrel_count = bfd_canonicalize_dynamic_reloc (abfd, dynrels, dynsyms);
1134 if (dynrel_count < 0)
1135 {
1136 do_cleanups (back_to);
1137 return;
1138 }
1139
1140 for (counter = 0, relptr = dynrels;
1141 counter < dynrel_count;
1142 counter++, relptr++)
1143 {
1144 arelent *rel = *relptr;
1145 CORE_ADDR address =
1146 rel->address + ANOFFSET (section_offsets, SECT_OFF_DATA);
1147
1148 switch (bfd_get_arch (abfd))
1149 {
1150 case bfd_arch_sparc:
1151 if (rel->howto->type != RELOC_JMP_SLOT)
1152 continue;
1153 break;
1154 case bfd_arch_m68k:
1155 /* `16' is the type BFD produces for a jump table relocation. */
1156 if (rel->howto->type != 16)
1157 continue;
1158
1159 /* Adjust address in the jump table to point to
1160 the start of the bsr instruction. */
1161 address -= 2;
1162 break;
1163 default:
1164 continue;
1165 }
1166
1167 name = (char *) bfd_asymbol_name (*rel->sym_ptr_ptr);
1168 prim_record_minimal_symbol (name, address, mst_solib_trampoline,
1169 objfile);
1170 }
1171
1172 do_cleanups (back_to);
1173 }
1174
1175 /* Given pointers to an a.out symbol table in core containing dbx
1176 style data, setup partial_symtab's describing each source file for
1177 which debugging information is available.
1178 SYMFILE_NAME is the name of the file we are reading from
1179 and SECTION_OFFSETS is the set of offsets for the various sections
1180 of the file (a set of zeros if the mainline program). */
1181
1182 static void
1183 read_dbx_symtab (section_offsets, objfile, text_addr, text_size)
1184 struct section_offsets *section_offsets;
1185 struct objfile *objfile;
1186 CORE_ADDR text_addr;
1187 int text_size;
1188 {
1189 register struct external_nlist *bufp = 0; /* =0 avoids gcc -Wall glitch */
1190 struct internal_nlist nlist;
1191
1192 register char *namestring;
1193 int nsl;
1194 int past_first_source_file = 0;
1195 CORE_ADDR last_o_file_start = 0;
1196 CORE_ADDR last_function_start = 0;
1197 struct cleanup *back_to;
1198 bfd *abfd;
1199 int textlow_not_set;
1200
1201 /* Current partial symtab */
1202 struct partial_symtab *pst;
1203
1204 /* List of current psymtab's include files */
1205 char **psymtab_include_list;
1206 int includes_allocated;
1207 int includes_used;
1208
1209 /* Index within current psymtab dependency list */
1210 struct partial_symtab **dependency_list;
1211 int dependencies_used, dependencies_allocated;
1212
1213 /* FIXME. We probably want to change stringtab_global rather than add this
1214 while processing every symbol entry. FIXME. */
1215 file_string_table_offset = 0;
1216 next_file_string_table_offset = 0;
1217
1218 stringtab_global = DBX_STRINGTAB (objfile);
1219
1220 pst = (struct partial_symtab *) 0;
1221
1222 includes_allocated = 30;
1223 includes_used = 0;
1224 psymtab_include_list = (char **) alloca (includes_allocated *
1225 sizeof (char *));
1226
1227 dependencies_allocated = 30;
1228 dependencies_used = 0;
1229 dependency_list =
1230 (struct partial_symtab **) alloca (dependencies_allocated *
1231 sizeof (struct partial_symtab *));
1232
1233 /* Init bincl list */
1234 init_bincl_list (20, objfile);
1235 back_to = make_cleanup (free_bincl_list, objfile);
1236
1237 last_source_file = NULL;
1238
1239 lowest_text_address = (CORE_ADDR)-1;
1240
1241 symfile_bfd = objfile->obfd; /* For next_text_symbol */
1242 abfd = objfile->obfd;
1243 symbuf_end = symbuf_idx = 0;
1244 next_symbol_text_func = dbx_next_symbol_text;
1245 textlow_not_set = 1;
1246
1247 for (symnum = 0; symnum < DBX_SYMCOUNT (objfile); symnum++)
1248 {
1249 /* Get the symbol for this run and pull out some info */
1250 QUIT; /* allow this to be interruptable */
1251 if (symbuf_idx == symbuf_end)
1252 fill_symbuf (abfd);
1253 bufp = &symbuf[symbuf_idx++];
1254
1255 /*
1256 * Special case to speed up readin.
1257 */
1258 if (bfd_h_get_8 (abfd, bufp->e_type) == N_SLINE)
1259 continue;
1260
1261 INTERNALIZE_SYMBOL (nlist, bufp, abfd);
1262 OBJSTAT (objfile, n_stabs++);
1263
1264 /* Ok. There is a lot of code duplicated in the rest of this
1265 switch statement (for efficiency reasons). Since I don't
1266 like duplicating code, I will do my penance here, and
1267 describe the code which is duplicated:
1268
1269 *) The assignment to namestring.
1270 *) The call to strchr.
1271 *) The addition of a partial symbol the the two partial
1272 symbol lists. This last is a large section of code, so
1273 I've imbedded it in the following macro.
1274 */
1275
1276 /* Set namestring based on nlist. If the string table index is invalid,
1277 give a fake name, and print a single error message per symbol file read,
1278 rather than abort the symbol reading or flood the user with messages. */
1279
1280 /*FIXME: Too many adds and indirections in here for the inner loop. */
1281 #define SET_NAMESTRING()\
1282 if (((unsigned)CUR_SYMBOL_STRX + file_string_table_offset) >= \
1283 DBX_STRINGTAB_SIZE (objfile)) { \
1284 complain (&string_table_offset_complaint, symnum); \
1285 namestring = "<bad string table offset>"; \
1286 } else \
1287 namestring = CUR_SYMBOL_STRX + file_string_table_offset + \
1288 DBX_STRINGTAB (objfile)
1289
1290 #define CUR_SYMBOL_TYPE nlist.n_type
1291 #define CUR_SYMBOL_VALUE nlist.n_value
1292 #define CUR_SYMBOL_STRX nlist.n_strx
1293 #define DBXREAD_ONLY
1294 #define START_PSYMTAB(ofile,secoff,fname,low,symoff,global_syms,static_syms)\
1295 start_psymtab(ofile, secoff, fname, low, symoff, global_syms, static_syms)
1296 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps,textlow_not_set)\
1297 end_psymtab(pst,ilist,ninc,c_off,c_text,dep_list,n_deps,textlow_not_set)
1298
1299 #include "partial-stab.h"
1300 }
1301
1302 /* If there's stuff to be cleaned up, clean it up. */
1303 if (DBX_SYMCOUNT (objfile) > 0 /* We have some syms */
1304 /*FIXME, does this have a bug at start address 0? */
1305 && last_o_file_start
1306 && objfile -> ei.entry_point < nlist.n_value
1307 && objfile -> ei.entry_point >= last_o_file_start)
1308 {
1309 objfile -> ei.entry_file_lowpc = last_o_file_start;
1310 objfile -> ei.entry_file_highpc = nlist.n_value;
1311 }
1312
1313 if (pst)
1314 {
1315 end_psymtab (pst, psymtab_include_list, includes_used,
1316 symnum * symbol_size,
1317 (lowest_text_address == (CORE_ADDR)-1
1318 ? (text_addr + section_offsets->offsets[SECT_OFF_TEXT])
1319 : lowest_text_address)
1320 + text_size,
1321 dependency_list, dependencies_used, textlow_not_set);
1322 }
1323
1324 do_cleanups (back_to);
1325 }
1326
1327 /* Allocate and partially fill a partial symtab. It will be
1328 completely filled at the end of the symbol list.
1329
1330 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
1331 is the address relative to which its symbols are (incremental) or 0
1332 (normal). */
1333
1334
1335 struct partial_symtab *
1336 start_psymtab (objfile, section_offsets,
1337 filename, textlow, ldsymoff, global_syms, static_syms)
1338 struct objfile *objfile;
1339 struct section_offsets *section_offsets;
1340 char *filename;
1341 CORE_ADDR textlow;
1342 int ldsymoff;
1343 struct partial_symbol **global_syms;
1344 struct partial_symbol **static_syms;
1345 {
1346 struct partial_symtab *result =
1347 start_psymtab_common(objfile, section_offsets,
1348 filename, textlow, global_syms, static_syms);
1349
1350 result->read_symtab_private = (char *)
1351 obstack_alloc (&objfile -> psymbol_obstack, sizeof (struct symloc));
1352 LDSYMOFF(result) = ldsymoff;
1353 result->read_symtab = dbx_psymtab_to_symtab;
1354 SYMBOL_SIZE(result) = symbol_size;
1355 SYMBOL_OFFSET(result) = symbol_table_offset;
1356 STRING_OFFSET(result) = string_table_offset;
1357 FILE_STRING_OFFSET(result) = file_string_table_offset;
1358
1359 /* If we're handling an ELF file, drag some section-relocation info
1360 for this source file out of the ELF symbol table, to compensate for
1361 Sun brain death. This replaces the section_offsets in this psymtab,
1362 if successful. */
1363 elfstab_offset_sections (objfile, result);
1364
1365 /* Deduce the source language from the filename for this psymtab. */
1366 psymtab_language = deduce_language_from_filename (filename);
1367
1368 return result;
1369 }
1370
1371 /* Close off the current usage of PST.
1372 Returns PST or NULL if the partial symtab was empty and thrown away.
1373
1374 FIXME: List variables and peculiarities of same. */
1375
1376 struct partial_symtab *
1377 end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
1378 capping_text, dependency_list, number_dependencies, textlow_not_set)
1379 struct partial_symtab *pst;
1380 char **include_list;
1381 int num_includes;
1382 int capping_symbol_offset;
1383 CORE_ADDR capping_text;
1384 struct partial_symtab **dependency_list;
1385 int number_dependencies;
1386 int textlow_not_set;
1387 {
1388 int i;
1389 struct objfile *objfile = pst -> objfile;
1390
1391 if (capping_symbol_offset != -1)
1392 LDSYMLEN(pst) = capping_symbol_offset - LDSYMOFF(pst);
1393 pst->texthigh = capping_text;
1394
1395 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
1396 /* Under Solaris, the N_SO symbols always have a value of 0,
1397 instead of the usual address of the .o file. Therefore,
1398 we have to do some tricks to fill in texthigh and textlow.
1399 The first trick is in partial-stab.h: if we see a static
1400 or global function, and the textlow for the current pst
1401 is not set (ie: textlow_not_set), then we use that function's
1402 address for the textlow of the pst. */
1403
1404 /* Now, to fill in texthigh, we remember the last function seen
1405 in the .o file (also in partial-stab.h). Also, there's a hack in
1406 bfd/elf.c and gdb/elfread.c to pass the ELF st_size field
1407 to here via the misc_info field. Therefore, we can fill in
1408 a reliable texthigh by taking the address plus size of the
1409 last function in the file. */
1410
1411 if (pst->texthigh == 0 && last_function_name)
1412 {
1413 char *p;
1414 int n;
1415 struct minimal_symbol *minsym;
1416
1417 p = strchr (last_function_name, ':');
1418 if (p == NULL)
1419 p = last_function_name;
1420 n = p - last_function_name;
1421 p = alloca (n + 1);
1422 strncpy (p, last_function_name, n);
1423 p[n] = 0;
1424
1425 minsym = lookup_minimal_symbol (p, pst->filename, objfile);
1426
1427 if (minsym)
1428 pst->texthigh = SYMBOL_VALUE_ADDRESS (minsym) + MSYMBOL_SIZE (minsym);
1429
1430 last_function_name = NULL;
1431 }
1432
1433 /* this test will be true if the last .o file is only data */
1434 if (textlow_not_set)
1435 pst->textlow = pst->texthigh;
1436 else
1437 {
1438 struct partial_symtab *p1;
1439
1440 /* If we know our own starting text address, then walk through all other
1441 psymtabs for this objfile, and if any didn't know their ending text
1442 address, set it to our starting address. Take care to not set our
1443 own ending address to our starting address, nor to set addresses on
1444 `dependency' files that have both textlow and texthigh zero. */
1445
1446 ALL_OBJFILE_PSYMTABS (objfile, p1)
1447 {
1448 if (p1->texthigh == 0 && p1->textlow != 0 && p1 != pst)
1449 {
1450 p1->texthigh = pst->textlow;
1451 /* if this file has only data, then make textlow match texthigh */
1452 if (p1->textlow == 0)
1453 p1->textlow = p1->texthigh;
1454 }
1455 }
1456 }
1457
1458 /* End of kludge for patching Solaris textlow and texthigh. */
1459 #endif /* SOFUN_ADDRESS_MAYBE_MISSING. */
1460
1461 pst->n_global_syms =
1462 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
1463 pst->n_static_syms =
1464 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
1465
1466 pst->number_of_dependencies = number_dependencies;
1467 if (number_dependencies)
1468 {
1469 pst->dependencies = (struct partial_symtab **)
1470 obstack_alloc (&objfile->psymbol_obstack,
1471 number_dependencies * sizeof (struct partial_symtab *));
1472 memcpy (pst->dependencies, dependency_list,
1473 number_dependencies * sizeof (struct partial_symtab *));
1474 }
1475 else
1476 pst->dependencies = 0;
1477
1478 for (i = 0; i < num_includes; i++)
1479 {
1480 struct partial_symtab *subpst =
1481 allocate_psymtab (include_list[i], objfile);
1482
1483 subpst->section_offsets = pst->section_offsets;
1484 subpst->read_symtab_private =
1485 (char *) obstack_alloc (&objfile->psymbol_obstack,
1486 sizeof (struct symloc));
1487 LDSYMOFF(subpst) =
1488 LDSYMLEN(subpst) =
1489 subpst->textlow =
1490 subpst->texthigh = 0;
1491
1492 /* We could save slight bits of space by only making one of these,
1493 shared by the entire set of include files. FIXME-someday. */
1494 subpst->dependencies = (struct partial_symtab **)
1495 obstack_alloc (&objfile->psymbol_obstack,
1496 sizeof (struct partial_symtab *));
1497 subpst->dependencies[0] = pst;
1498 subpst->number_of_dependencies = 1;
1499
1500 subpst->globals_offset =
1501 subpst->n_global_syms =
1502 subpst->statics_offset =
1503 subpst->n_static_syms = 0;
1504
1505 subpst->readin = 0;
1506 subpst->symtab = 0;
1507 subpst->read_symtab = pst->read_symtab;
1508 }
1509
1510 sort_pst_symbols (pst);
1511
1512 /* If there is already a psymtab or symtab for a file of this name, remove it.
1513 (If there is a symtab, more drastic things also happen.)
1514 This happens in VxWorks. */
1515 free_named_symtabs (pst->filename);
1516
1517 if (num_includes == 0
1518 && number_dependencies == 0
1519 && pst->n_global_syms == 0
1520 && pst->n_static_syms == 0)
1521 {
1522 /* Throw away this psymtab, it's empty. We can't deallocate it, since
1523 it is on the obstack, but we can forget to chain it on the list. */
1524 /* Empty psymtabs happen as a result of header files which don't have
1525 any symbols in them. There can be a lot of them. But this check
1526 is wrong, in that a psymtab with N_SLINE entries but nothing else
1527 is not empty, but we don't realize that. Fixing that without slowing
1528 things down might be tricky. */
1529 struct partial_symtab *prev_pst;
1530
1531 /* First, snip it out of the psymtab chain */
1532
1533 if (pst->objfile->psymtabs == pst)
1534 pst->objfile->psymtabs = pst->next;
1535 else
1536 for (prev_pst = pst->objfile->psymtabs; prev_pst; prev_pst = pst->next)
1537 if (prev_pst->next == pst)
1538 prev_pst->next = pst->next;
1539
1540 /* Next, put it on a free list for recycling */
1541
1542 pst->next = pst->objfile->free_psymtabs;
1543 pst->objfile->free_psymtabs = pst;
1544
1545 /* Indicate that psymtab was thrown away. */
1546 pst = (struct partial_symtab *)NULL;
1547 }
1548 return pst;
1549 }
1550 \f
1551 static void
1552 dbx_psymtab_to_symtab_1 (pst)
1553 struct partial_symtab *pst;
1554 {
1555 struct cleanup *old_chain;
1556 int i;
1557
1558 if (!pst)
1559 return;
1560
1561 if (pst->readin)
1562 {
1563 fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1564 pst->filename);
1565 return;
1566 }
1567
1568 /* Read in all partial symtabs on which this one is dependent */
1569 for (i = 0; i < pst->number_of_dependencies; i++)
1570 if (!pst->dependencies[i]->readin)
1571 {
1572 /* Inform about additional files that need to be read in. */
1573 if (info_verbose)
1574 {
1575 fputs_filtered (" ", gdb_stdout);
1576 wrap_here ("");
1577 fputs_filtered ("and ", gdb_stdout);
1578 wrap_here ("");
1579 printf_filtered ("%s...", pst->dependencies[i]->filename);
1580 wrap_here (""); /* Flush output */
1581 gdb_flush (gdb_stdout);
1582 }
1583 dbx_psymtab_to_symtab_1 (pst->dependencies[i]);
1584 }
1585
1586 if (LDSYMLEN(pst)) /* Otherwise it's a dummy */
1587 {
1588 /* Init stuff necessary for reading in symbols */
1589 stabsread_init ();
1590 buildsym_init ();
1591 old_chain = make_cleanup (really_free_pendings, 0);
1592 file_string_table_offset = FILE_STRING_OFFSET (pst);
1593 symbol_size = SYMBOL_SIZE (pst);
1594
1595 /* Read in this file's symbols */
1596 bfd_seek (pst->objfile->obfd, SYMBOL_OFFSET (pst), SEEK_SET);
1597 read_ofile_symtab (pst);
1598 sort_symtab_syms (pst->symtab);
1599
1600 do_cleanups (old_chain);
1601 }
1602
1603 pst->readin = 1;
1604 }
1605
1606 /* Read in all of the symbols for a given psymtab for real.
1607 Be verbose about it if the user wants that. */
1608
1609 static void
1610 dbx_psymtab_to_symtab (pst)
1611 struct partial_symtab *pst;
1612 {
1613 bfd *sym_bfd;
1614
1615 if (!pst)
1616 return;
1617
1618 if (pst->readin)
1619 {
1620 fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1621 pst->filename);
1622 return;
1623 }
1624
1625 if (LDSYMLEN(pst) || pst->number_of_dependencies)
1626 {
1627 /* Print the message now, before reading the string table,
1628 to avoid disconcerting pauses. */
1629 if (info_verbose)
1630 {
1631 printf_filtered ("Reading in symbols for %s...", pst->filename);
1632 gdb_flush (gdb_stdout);
1633 }
1634
1635 sym_bfd = pst->objfile->obfd;
1636
1637 next_symbol_text_func = dbx_next_symbol_text;
1638
1639 dbx_psymtab_to_symtab_1 (pst);
1640
1641 /* Match with global symbols. This only needs to be done once,
1642 after all of the symtabs and dependencies have been read in. */
1643 scan_file_globals (pst->objfile);
1644
1645 /* Finish up the debug error message. */
1646 if (info_verbose)
1647 printf_filtered ("done.\n");
1648 }
1649 }
1650
1651 /* Read in a defined section of a specific object file's symbols. */
1652
1653 static void
1654 read_ofile_symtab (pst)
1655 struct partial_symtab *pst;
1656 {
1657 register char *namestring;
1658 register struct external_nlist *bufp;
1659 struct internal_nlist nlist;
1660 unsigned char type;
1661 unsigned max_symnum;
1662 register bfd *abfd;
1663 struct objfile *objfile;
1664 int sym_offset; /* Offset to start of symbols to read */
1665 int sym_size; /* Size of symbols to read */
1666 CORE_ADDR text_offset; /* Start of text segment for symbols */
1667 int text_size; /* Size of text segment for symbols */
1668 struct section_offsets *section_offsets;
1669
1670 objfile = pst->objfile;
1671 sym_offset = LDSYMOFF(pst);
1672 sym_size = LDSYMLEN(pst);
1673 text_offset = pst->textlow;
1674 text_size = pst->texthigh - pst->textlow;
1675 section_offsets = pst->section_offsets;
1676
1677 current_objfile = objfile;
1678 subfile_stack = NULL;
1679
1680 stringtab_global = DBX_STRINGTAB (objfile);
1681 last_source_file = NULL;
1682
1683 abfd = objfile->obfd;
1684 symfile_bfd = objfile->obfd; /* Implicit param to next_text_symbol */
1685 symbuf_end = symbuf_idx = 0;
1686
1687 /* It is necessary to actually read one symbol *before* the start
1688 of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
1689 occurs before the N_SO symbol.
1690
1691 Detecting this in read_dbx_symtab
1692 would slow down initial readin, so we look for it here instead. */
1693 if (!processing_acc_compilation && sym_offset >= (int)symbol_size)
1694 {
1695 bfd_seek (symfile_bfd, sym_offset - symbol_size, SEEK_CUR);
1696 fill_symbuf (abfd);
1697 bufp = &symbuf[symbuf_idx++];
1698 INTERNALIZE_SYMBOL (nlist, bufp, abfd);
1699 OBJSTAT (objfile, n_stabs++);
1700
1701 SET_NAMESTRING ();
1702
1703 processing_gcc_compilation = 0;
1704 if (nlist.n_type == N_TEXT)
1705 {
1706 const char *tempstring = namestring;
1707
1708 if (STREQ (namestring, GCC_COMPILED_FLAG_SYMBOL))
1709 processing_gcc_compilation = 1;
1710 else if (STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL))
1711 processing_gcc_compilation = 2;
1712 if (tempstring[0] == bfd_get_symbol_leading_char (symfile_bfd))
1713 ++tempstring;
1714 if (STREQN (tempstring, "__gnu_compiled", 14))
1715 processing_gcc_compilation = 2;
1716 }
1717
1718 /* Try to select a C++ demangling based on the compilation unit
1719 producer. */
1720
1721 if (processing_gcc_compilation)
1722 {
1723 if (AUTO_DEMANGLING)
1724 {
1725 set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
1726 }
1727 }
1728 }
1729 else
1730 {
1731 /* The N_SO starting this symtab is the first symbol, so we
1732 better not check the symbol before it. I'm not this can
1733 happen, but it doesn't hurt to check for it. */
1734 bfd_seek (symfile_bfd, sym_offset, SEEK_CUR);
1735 processing_gcc_compilation = 0;
1736 }
1737
1738 if (symbuf_idx == symbuf_end)
1739 fill_symbuf (abfd);
1740 bufp = &symbuf[symbuf_idx];
1741 if (bfd_h_get_8 (abfd, bufp->e_type) != N_SO)
1742 error("First symbol in segment of executable not a source symbol");
1743
1744 max_symnum = sym_size / symbol_size;
1745
1746 for (symnum = 0;
1747 symnum < max_symnum;
1748 symnum++)
1749 {
1750 QUIT; /* Allow this to be interruptable */
1751 if (symbuf_idx == symbuf_end)
1752 fill_symbuf(abfd);
1753 bufp = &symbuf[symbuf_idx++];
1754 INTERNALIZE_SYMBOL (nlist, bufp, abfd);
1755 OBJSTAT (objfile, n_stabs++);
1756
1757 type = bfd_h_get_8 (abfd, bufp->e_type);
1758
1759 SET_NAMESTRING ();
1760
1761 if (type & N_STAB) {
1762 process_one_symbol (type, nlist.n_desc, nlist.n_value,
1763 namestring, section_offsets, objfile);
1764 }
1765 /* We skip checking for a new .o or -l file; that should never
1766 happen in this routine. */
1767 else if (type == N_TEXT)
1768 {
1769 /* I don't think this code will ever be executed, because
1770 the GCC_COMPILED_FLAG_SYMBOL usually is right before
1771 the N_SO symbol which starts this source file.
1772 However, there is no reason not to accept
1773 the GCC_COMPILED_FLAG_SYMBOL anywhere. */
1774
1775 if (STREQ (namestring, GCC_COMPILED_FLAG_SYMBOL))
1776 processing_gcc_compilation = 1;
1777 else if (STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL))
1778 processing_gcc_compilation = 2;
1779
1780 if (AUTO_DEMANGLING)
1781 {
1782 set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
1783 }
1784 }
1785 else if (type & N_EXT || type == (unsigned char)N_TEXT
1786 || type == (unsigned char)N_NBTEXT
1787 ) {
1788 /* Global symbol: see if we came across a dbx defintion for
1789 a corresponding symbol. If so, store the value. Remove
1790 syms from the chain when their values are stored, but
1791 search the whole chain, as there may be several syms from
1792 different files with the same name. */
1793 /* This is probably not true. Since the files will be read
1794 in one at a time, each reference to a global symbol will
1795 be satisfied in each file as it appears. So we skip this
1796 section. */
1797 ;
1798 }
1799 }
1800
1801 current_objfile = NULL;
1802
1803 /* In a Solaris elf file, this variable, which comes from the
1804 value of the N_SO symbol, will still be 0. Luckily, text_offset,
1805 which comes from pst->textlow is correct. */
1806 if (last_source_start_addr == 0)
1807 last_source_start_addr = text_offset;
1808
1809 /* In reordered executables last_source_start_addr may not be the
1810 lower bound for this symtab, instead use text_offset which comes
1811 from pst->textlow which is correct. */
1812 if (last_source_start_addr > text_offset)
1813 last_source_start_addr = text_offset;
1814
1815 pst->symtab = end_symtab (text_offset + text_size, objfile, SECT_OFF_TEXT);
1816
1817 /* Process items which we had to "process_later" due to dependancies
1818 on other stabs. */
1819 process_now (objfile);
1820
1821 end_stabs ();
1822 }
1823
1824 \f
1825 /* This handles a single symbol from the symbol-file, building symbols
1826 into a GDB symtab. It takes these arguments and an implicit argument.
1827
1828 TYPE is the type field of the ".stab" symbol entry.
1829 DESC is the desc field of the ".stab" entry.
1830 VALU is the value field of the ".stab" entry.
1831 NAME is the symbol name, in our address space.
1832 SECTION_OFFSETS is a set of amounts by which the sections of this object
1833 file were relocated when it was loaded into memory.
1834 All symbols that refer
1835 to memory locations need to be offset by these amounts.
1836 OBJFILE is the object file from which we are reading symbols.
1837 It is used in end_symtab. */
1838
1839 void
1840 process_one_symbol (type, desc, valu, name, section_offsets, objfile)
1841 int type, desc;
1842 CORE_ADDR valu;
1843 char *name;
1844 struct section_offsets *section_offsets;
1845 struct objfile *objfile;
1846 {
1847 #ifdef SUN_FIXED_LBRAC_BUG
1848 /* If SUN_FIXED_LBRAC_BUG is defined, then it tells us whether we need
1849 to correct the address of N_LBRAC's. If it is not defined, then
1850 we never need to correct the addresses. */
1851
1852 /* This records the last pc address we've seen. We depend on there being
1853 an SLINE or FUN or SO before the first LBRAC, since the variable does
1854 not get reset in between reads of different symbol files. */
1855 static CORE_ADDR last_pc_address;
1856 #endif
1857
1858 register struct context_stack *new;
1859 /* This remembers the address of the start of a function. It is used
1860 because in Solaris 2, N_LBRAC, N_RBRAC, and N_SLINE entries are
1861 relative to the current function's start address. On systems
1862 other than Solaris 2, this just holds the SECT_OFF_TEXT value, and is
1863 used to relocate these symbol types rather than SECTION_OFFSETS. */
1864 static CORE_ADDR function_start_offset;
1865
1866 /* If this is nonzero, we've seen a non-gcc N_OPT symbol for this source
1867 file. Used to detect the SunPRO solaris compiler. */
1868 static int n_opt_found;
1869
1870 /* The stab type used for the definition of the last function.
1871 N_STSYM or N_GSYM for SunOS4 acc; N_FUN for other compilers. */
1872 static int function_stab_type = 0;
1873
1874 if (!block_address_function_relative)
1875 /* N_LBRAC, N_RBRAC and N_SLINE entries are not relative to the
1876 function start address, so just use the text offset. */
1877 function_start_offset = ANOFFSET (section_offsets, SECT_OFF_TEXT);
1878
1879 /* Something is wrong if we see real data before
1880 seeing a source file name. */
1881
1882 if (last_source_file == NULL && type != (unsigned char)N_SO)
1883 {
1884 /* Ignore any symbols which appear before an N_SO symbol. Currently
1885 no one puts symbols there, but we should deal gracefully with the
1886 case. A complain()t might be in order (if !IGNORE_SYMBOL (type)),
1887 but this should not be an error (). */
1888 return;
1889 }
1890
1891 switch (type)
1892 {
1893 case N_FUN:
1894 case N_FNAME:
1895
1896 if (*name == '\000')
1897 {
1898 /* This N_FUN marks the end of a function. This closes off the
1899 current block. */
1900 within_function = 0;
1901 new = pop_context ();
1902
1903 /* Make a block for the local symbols within. */
1904 finish_block (new->name, &local_symbols, new->old_blocks,
1905 new->start_addr, new->start_addr + valu,
1906 objfile);
1907 break;
1908 }
1909
1910 /* Relocate for dynamic loading */
1911 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1912 goto define_a_symbol;
1913
1914 case N_LBRAC:
1915 /* This "symbol" just indicates the start of an inner lexical
1916 context within a function. */
1917
1918 /* Ignore extra outermost context from SunPRO cc and acc. */
1919 if (n_opt_found && desc == 1)
1920 break;
1921
1922 #if defined(BLOCK_ADDRESS_ABSOLUTE)
1923 /* Relocate for dynamic loading (?). */
1924 valu += function_start_offset;
1925 #else
1926 if (block_address_function_relative)
1927 /* Relocate for Sun ELF acc fn-relative syms. */
1928 valu += function_start_offset;
1929 else
1930 /* On most machines, the block addresses are relative to the
1931 N_SO, the linker did not relocate them (sigh). */
1932 valu += last_source_start_addr;
1933 #endif
1934
1935 #ifdef SUN_FIXED_LBRAC_BUG
1936 if (!SUN_FIXED_LBRAC_BUG && valu < last_pc_address) {
1937 /* Patch current LBRAC pc value to match last handy pc value */
1938 complain (&lbrac_complaint);
1939 valu = last_pc_address;
1940 }
1941 #endif
1942 new = push_context (desc, valu);
1943 break;
1944
1945 case N_RBRAC:
1946 /* This "symbol" just indicates the end of an inner lexical
1947 context that was started with N_LBRAC. */
1948
1949 /* Ignore extra outermost context from SunPRO cc and acc. */
1950 if (n_opt_found && desc == 1)
1951 break;
1952
1953 #if defined(BLOCK_ADDRESS_ABSOLUTE)
1954 /* Relocate for dynamic loading (?). */
1955 valu += function_start_offset;
1956 #else
1957 if (block_address_function_relative)
1958 /* Relocate for Sun ELF acc fn-relative syms. */
1959 valu += function_start_offset;
1960 else
1961 /* On most machines, the block addresses are relative to the
1962 N_SO, the linker did not relocate them (sigh). */
1963 valu += last_source_start_addr;
1964 #endif
1965
1966 new = pop_context();
1967 if (desc != new->depth)
1968 complain (&lbrac_mismatch_complaint, symnum);
1969
1970 /* Some compilers put the variable decls inside of an
1971 LBRAC/RBRAC block. This macro should be nonzero if this
1972 is true. DESC is N_DESC from the N_RBRAC symbol.
1973 GCC_P is true if we've detected the GCC_COMPILED_SYMBOL
1974 or the GCC2_COMPILED_SYMBOL. */
1975 #if !defined (VARIABLES_INSIDE_BLOCK)
1976 #define VARIABLES_INSIDE_BLOCK(desc, gcc_p) 0
1977 #endif
1978
1979 /* Can only use new->locals as local symbols here if we're in
1980 gcc or on a machine that puts them before the lbrack. */
1981 if (!VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation))
1982 local_symbols = new->locals;
1983
1984 if (context_stack_depth
1985 > !VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation))
1986 {
1987 /* This is not the outermost LBRAC...RBRAC pair in the function,
1988 its local symbols preceded it, and are the ones just recovered
1989 from the context stack. Define the block for them (but don't
1990 bother if the block contains no symbols. Should we complain
1991 on blocks without symbols? I can't think of any useful purpose
1992 for them). */
1993 if (local_symbols != NULL)
1994 {
1995 /* Muzzle a compiler bug that makes end < start. (which
1996 compilers? Is this ever harmful?). */
1997 if (new->start_addr > valu)
1998 {
1999 complain (&lbrac_rbrac_complaint);
2000 new->start_addr = valu;
2001 }
2002 /* Make a block for the local symbols within. */
2003 finish_block (0, &local_symbols, new->old_blocks,
2004 new->start_addr, valu, objfile);
2005 }
2006 }
2007 else
2008 {
2009 /* This is the outermost LBRAC...RBRAC pair. There is no
2010 need to do anything; leave the symbols that preceded it
2011 to be attached to the function's own block. We need to
2012 indicate that we just moved outside of the function. */
2013 within_function = 0;
2014 }
2015
2016 if (VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation))
2017 /* Now pop locals of block just finished. */
2018 local_symbols = new->locals;
2019 break;
2020
2021 case N_FN:
2022 case N_FN_SEQ:
2023 /* This kind of symbol indicates the start of an object file. */
2024 /* Relocate for dynamic loading */
2025 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
2026 break;
2027
2028 case N_SO:
2029 /* This type of symbol indicates the start of data
2030 for one source file.
2031 Finish the symbol table of the previous source file
2032 (if any) and start accumulating a new symbol table. */
2033 /* Relocate for dynamic loading */
2034 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
2035
2036 n_opt_found = 0;
2037
2038 #ifdef SUN_FIXED_LBRAC_BUG
2039 last_pc_address = valu; /* Save for SunOS bug circumcision */
2040 #endif
2041
2042 #ifdef PCC_SOL_BROKEN
2043 /* pcc bug, occasionally puts out SO for SOL. */
2044 if (context_stack_depth > 0)
2045 {
2046 start_subfile (name, NULL);
2047 break;
2048 }
2049 #endif
2050 if (last_source_file)
2051 {
2052 /* Check if previous symbol was also an N_SO (with some
2053 sanity checks). If so, that one was actually the directory
2054 name, and the current one is the real file name.
2055 Patch things up. */
2056 if (previous_stab_code == (unsigned char) N_SO)
2057 {
2058 patch_subfile_names (current_subfile, name);
2059 break; /* Ignore repeated SOs */
2060 }
2061 end_symtab (valu, objfile, SECT_OFF_TEXT);
2062 end_stabs ();
2063 }
2064
2065 /* Null name means this just marks the end of text for this .o file.
2066 Don't start a new symtab in this case. */
2067 if (*name == '\000')
2068 break;
2069
2070 start_stabs ();
2071 start_symtab (name, NULL, valu);
2072 record_debugformat ("stabs");
2073 break;
2074
2075 case N_SOL:
2076 /* This type of symbol indicates the start of data for
2077 a sub-source-file, one whose contents were copied or
2078 included in the compilation of the main source file
2079 (whose name was given in the N_SO symbol.) */
2080 /* Relocate for dynamic loading */
2081 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
2082 start_subfile (name, current_subfile->dirname);
2083 break;
2084
2085 case N_BINCL:
2086 push_subfile ();
2087 add_new_header_file (name, valu);
2088 start_subfile (name, current_subfile->dirname);
2089 break;
2090
2091 case N_EINCL:
2092 start_subfile (pop_subfile (), current_subfile->dirname);
2093 break;
2094
2095 case N_EXCL:
2096 add_old_header_file (name, valu);
2097 break;
2098
2099 case N_SLINE:
2100 /* This type of "symbol" really just records
2101 one line-number -- core-address correspondence.
2102 Enter it in the line list for this symbol table. */
2103 /* Relocate for dynamic loading and for ELF acc fn-relative syms. */
2104 valu += function_start_offset;
2105 #ifdef SUN_FIXED_LBRAC_BUG
2106 last_pc_address = valu; /* Save for SunOS bug circumcision */
2107 #endif
2108 record_line (current_subfile, desc, valu);
2109 break;
2110
2111 case N_BCOMM:
2112 common_block_start (name, objfile);
2113 break;
2114
2115 case N_ECOMM:
2116 common_block_end (objfile);
2117 break;
2118
2119 /* The following symbol types need to have the appropriate offset added
2120 to their value; then we process symbol definitions in the name. */
2121
2122 case N_STSYM: /* Static symbol in data seg */
2123 case N_LCSYM: /* Static symbol in BSS seg */
2124 case N_ROSYM: /* Static symbol in Read-only data seg */
2125 /* HORRID HACK DEPT. However, it's Sun's furgin' fault.
2126 Solaris2's stabs-in-elf makes *most* symbols relative
2127 but leaves a few absolute (at least for Solaris 2.1 and version
2128 2.0.1 of the SunPRO compiler). N_STSYM and friends sit on the fence.
2129 .stab "foo:S...",N_STSYM is absolute (ld relocates it)
2130 .stab "foo:V...",N_STSYM is relative (section base subtracted).
2131 This leaves us no choice but to search for the 'S' or 'V'...
2132 (or pass the whole section_offsets stuff down ONE MORE function
2133 call level, which we really don't want to do). */
2134 {
2135 char *p;
2136
2137 /* .o files and NLMs have non-zero text seg offsets, but don't need
2138 their static syms offset in this fashion. XXX - This is really a
2139 crock that should be fixed in the solib handling code so that I
2140 don't have to work around it here. */
2141
2142 if (!symfile_relocatable)
2143 {
2144 p = strchr (name, ':');
2145 if (p != 0 && p[1] == 'S')
2146 {
2147 /* The linker relocated it. We don't want to add an
2148 elfstab_offset_sections-type offset, but we *do* want
2149 to add whatever solib.c passed to symbol_file_add as
2150 addr (this is known to affect SunOS4, and I suspect ELF
2151 too). Since elfstab_offset_sections currently does not
2152 muck with the text offset (there is no Ttext.text
2153 symbol), we can get addr from the text offset. If
2154 elfstab_offset_sections ever starts dealing with the
2155 text offset, and we still need to do this, we need to
2156 invent a SECT_OFF_ADDR_KLUDGE or something. */
2157 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
2158 goto define_a_symbol;
2159 }
2160 }
2161 /* Since it's not the kludge case, re-dispatch to the right handler. */
2162 switch (type) {
2163 case N_STSYM: goto case_N_STSYM;
2164 case N_LCSYM: goto case_N_LCSYM;
2165 case N_ROSYM: goto case_N_ROSYM;
2166 default: abort();
2167 }
2168 }
2169
2170 case_N_STSYM: /* Static symbol in data seg */
2171 case N_DSLINE: /* Source line number, data seg */
2172 valu += ANOFFSET (section_offsets, SECT_OFF_DATA);
2173 goto define_a_symbol;
2174
2175 case_N_LCSYM: /* Static symbol in BSS seg */
2176 case N_BSLINE: /* Source line number, bss seg */
2177 /* N_BROWS: overlaps with N_BSLINE */
2178 valu += ANOFFSET (section_offsets, SECT_OFF_BSS);
2179 goto define_a_symbol;
2180
2181 case_N_ROSYM: /* Static symbol in Read-only data seg */
2182 valu += ANOFFSET (section_offsets, SECT_OFF_RODATA);
2183 goto define_a_symbol;
2184
2185 case N_ENTRY: /* Alternate entry point */
2186 /* Relocate for dynamic loading */
2187 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
2188 goto define_a_symbol;
2189
2190 /* The following symbol types we don't know how to process. Handle
2191 them in a "default" way, but complain to people who care. */
2192 default:
2193 case N_CATCH: /* Exception handler catcher */
2194 case N_EHDECL: /* Exception handler name */
2195 case N_PC: /* Global symbol in Pascal */
2196 case N_M2C: /* Modula-2 compilation unit */
2197 /* N_MOD2: overlaps with N_EHDECL */
2198 case N_SCOPE: /* Modula-2 scope information */
2199 case N_ECOML: /* End common (local name) */
2200 case N_NBTEXT: /* Gould Non-Base-Register symbols??? */
2201 case N_NBDATA:
2202 case N_NBBSS:
2203 case N_NBSTS:
2204 case N_NBLCS:
2205 complain (&unknown_symtype_complaint, local_hex_string (type));
2206 /* FALLTHROUGH */
2207
2208 /* The following symbol types don't need the address field relocated,
2209 since it is either unused, or is absolute. */
2210 define_a_symbol:
2211 case N_GSYM: /* Global variable */
2212 case N_NSYMS: /* Number of symbols (ultrix) */
2213 case N_NOMAP: /* No map? (ultrix) */
2214 case N_RSYM: /* Register variable */
2215 case N_DEFD: /* Modula-2 GNU module dependency */
2216 case N_SSYM: /* Struct or union element */
2217 case N_LSYM: /* Local symbol in stack */
2218 case N_PSYM: /* Parameter variable */
2219 case N_LENG: /* Length of preceding symbol type */
2220 if (name)
2221 {
2222 int deftype;
2223 char *colon_pos = strchr (name, ':');
2224 if (colon_pos == NULL)
2225 deftype = '\0';
2226 else
2227 deftype = colon_pos[1];
2228
2229 switch (deftype)
2230 {
2231 case 'f':
2232 case 'F':
2233 function_stab_type = type;
2234
2235 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
2236 /* Deal with the SunPRO 3.0 compiler which omits the address
2237 from N_FUN symbols. */
2238 if (type == N_FUN
2239 && valu == ANOFFSET (section_offsets, SECT_OFF_TEXT))
2240 {
2241 struct minimal_symbol *msym;
2242 char *p;
2243 int n;
2244
2245 p = strchr (name, ':');
2246 if (p == NULL)
2247 p = name;
2248 n = p - name;
2249 p = alloca (n + 1);
2250 strncpy (p, name, n);
2251 p[n] = 0;
2252
2253 msym = lookup_minimal_symbol (p, last_source_file,
2254 objfile);
2255 if (msym)
2256 valu = SYMBOL_VALUE_ADDRESS (msym);
2257 }
2258 #endif
2259
2260 #ifdef SUN_FIXED_LBRAC_BUG
2261 /* The Sun acc compiler, under SunOS4, puts out
2262 functions with N_GSYM or N_STSYM. The problem is
2263 that the address of the symbol is no good (for N_GSYM
2264 it doesn't even attept an address; for N_STSYM it
2265 puts out an address but then it gets relocated
2266 relative to the data segment, not the text segment).
2267 Currently we can't fix this up later as we do for
2268 some types of symbol in scan_file_globals.
2269 Fortunately we do have a way of finding the address -
2270 we know that the value in last_pc_address is either
2271 the one we want (if we're dealing with the first
2272 function in an object file), or somewhere in the
2273 previous function. This means that we can use the
2274 minimal symbol table to get the address. */
2275
2276 /* Starting with release 3.0, the Sun acc compiler,
2277 under SunOS4, puts out functions with N_FUN and a value
2278 of zero. This gets relocated to the start of the text
2279 segment of the module, which is no good either.
2280 Under SunOS4 we can deal with this as N_SLINE and N_SO
2281 entries contain valid absolute addresses.
2282 Release 3.0 acc also puts out N_OPT entries, which makes
2283 it possible to discern acc from cc or gcc. */
2284
2285 if (type == N_GSYM || type == N_STSYM
2286 || (type == N_FUN
2287 && n_opt_found && !block_address_function_relative))
2288 {
2289 struct minimal_symbol *m;
2290 int l = colon_pos - name;
2291
2292 m = lookup_minimal_symbol_by_pc (last_pc_address);
2293 if (m && STREQN (SYMBOL_NAME (m), name, l)
2294 && SYMBOL_NAME (m) [l] == '\0')
2295 /* last_pc_address was in this function */
2296 valu = SYMBOL_VALUE (m);
2297 else if (m && SYMBOL_NAME (m+1)
2298 && STREQN (SYMBOL_NAME (m+1), name, l)
2299 && SYMBOL_NAME (m+1) [l] == '\0')
2300 /* last_pc_address was in last function */
2301 valu = SYMBOL_VALUE (m+1);
2302 else
2303 /* Not found - use last_pc_address (for finish_block) */
2304 valu = last_pc_address;
2305 }
2306
2307 last_pc_address = valu; /* Save for SunOS bug circumcision */
2308 #endif
2309
2310 if (block_address_function_relative)
2311 /* For Solaris 2.0 compilers, the block addresses and
2312 N_SLINE's are relative to the start of the
2313 function. On normal systems, and when using gcc on
2314 Solaris 2.0, these addresses are just absolute, or
2315 relative to the N_SO, depending on
2316 BLOCK_ADDRESS_ABSOLUTE. */
2317 function_start_offset = valu;
2318
2319 within_function = 1;
2320 if (context_stack_depth > 0)
2321 {
2322 new = pop_context ();
2323 /* Make a block for the local symbols within. */
2324 finish_block (new->name, &local_symbols, new->old_blocks,
2325 new->start_addr, valu, objfile);
2326 }
2327 /* Stack must be empty now. */
2328 if (context_stack_depth != 0)
2329 complain (&lbrac_unmatched_complaint, symnum);
2330
2331 new = push_context (0, valu);
2332 new->name = define_symbol (valu, name, desc, type, objfile);
2333 break;
2334
2335 default:
2336 define_symbol (valu, name, desc, type, objfile);
2337 break;
2338 }
2339 }
2340 break;
2341
2342 /* We use N_OPT to carry the gcc2_compiled flag. Sun uses it
2343 for a bunch of other flags, too. Someday we may parse their
2344 flags; for now we ignore theirs and hope they'll ignore ours. */
2345 case N_OPT: /* Solaris 2: Compiler options */
2346 if (name)
2347 {
2348 if (STREQ (name, GCC2_COMPILED_FLAG_SYMBOL))
2349 {
2350 processing_gcc_compilation = 2;
2351 #if 1 /* Works, but is experimental. -fnf */
2352 if (AUTO_DEMANGLING)
2353 {
2354 set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
2355 }
2356 #endif
2357 }
2358 else
2359 n_opt_found = 1;
2360 }
2361 break;
2362
2363 /* The following symbol types can be ignored. */
2364 case N_OBJ: /* Solaris 2: Object file dir and name */
2365 /* N_UNDF: Solaris 2: file separator mark */
2366 /* N_UNDF: -- we will never encounter it, since we only process one
2367 file's symbols at once. */
2368 case N_ENDM: /* Solaris 2: End of module */
2369 case N_MAIN: /* Name of main routine. */
2370 break;
2371 }
2372
2373 /* Special GNU C extension for referencing names. */
2374 if (name[0] == '#')
2375 {
2376 /* Initialize symbol reference names and determine if this is
2377 a definition. If symbol reference is being defined, go
2378 ahead and add it. Otherwise, just return sym. */
2379 char *s;
2380 int refnum;
2381 /* If defined, store away a pointer to the symbol;
2382 we'll use it later when we resolve references in
2383 "resolve_symbol_reference". */
2384
2385 s = name;
2386 if (refnum = symbol_reference_defined (&s), refnum)
2387 if (!ref_search (refnum))
2388 ref_add (refnum, 0, name, valu);
2389 name = s; /* Advance past refid. */
2390 }
2391
2392
2393 previous_stab_code = type;
2394 }
2395 \f
2396 /* FIXME: The only difference between this and elfstab_build_psymtabs
2397 is the call to install_minimal_symbols for elf, and the support for
2398 split sections. If the differences are really that small, the code
2399 should be shared. */
2400
2401 /* Scan and build partial symbols for an coff symbol file.
2402 The coff file has already been processed to get its minimal symbols.
2403
2404 This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
2405 rolled into one.
2406
2407 OBJFILE is the object file we are reading symbols from.
2408 ADDR is the address relative to which the symbols are (e.g.
2409 the base address of the text segment).
2410 MAINLINE is true if we are reading the main symbol
2411 table (as opposed to a shared lib or dynamically loaded file).
2412 TEXTADDR is the address of the text section.
2413 TEXTSIZE is the size of the text section.
2414 STABSECTS is the list of .stab sections in OBJFILE.
2415 STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the
2416 .stabstr section exists.
2417
2418 This routine is mostly copied from dbx_symfile_init and dbx_symfile_read,
2419 adjusted for coff details. */
2420
2421 void
2422 coffstab_build_psymtabs (objfile, section_offsets, mainline,
2423 textaddr, textsize, stabsects,
2424 stabstroffset, stabstrsize)
2425 struct objfile *objfile;
2426 struct section_offsets *section_offsets;
2427 int mainline;
2428 CORE_ADDR textaddr;
2429 unsigned int textsize;
2430 struct stab_section_list *stabsects;
2431 file_ptr stabstroffset;
2432 unsigned int stabstrsize;
2433 {
2434 int val;
2435 bfd *sym_bfd = objfile->obfd;
2436 char *name = bfd_get_filename (sym_bfd);
2437 struct dbx_symfile_info *info;
2438 unsigned int stabsize;
2439
2440 /* There is already a dbx_symfile_info allocated by our caller.
2441 It might even contain some info from the coff symtab to help us. */
2442 info = objfile->sym_stab_info;
2443
2444 DBX_TEXT_ADDR (objfile) = textaddr;
2445 DBX_TEXT_SIZE (objfile) = textsize;
2446
2447 #define COFF_STABS_SYMBOL_SIZE 12 /* XXX FIXME XXX */
2448 DBX_SYMBOL_SIZE (objfile) = COFF_STABS_SYMBOL_SIZE;
2449 DBX_STRINGTAB_SIZE (objfile) = stabstrsize;
2450
2451 if (stabstrsize > bfd_get_size (sym_bfd))
2452 error ("ridiculous string table size: %d bytes", stabstrsize);
2453 DBX_STRINGTAB (objfile) = (char *)
2454 obstack_alloc (&objfile->psymbol_obstack, stabstrsize+1);
2455 OBJSTAT (objfile, sz_strtab += stabstrsize+1);
2456
2457 /* Now read in the string table in one big gulp. */
2458
2459 val = bfd_seek (sym_bfd, stabstroffset, SEEK_SET);
2460 if (val < 0)
2461 perror_with_name (name);
2462 val = bfd_read (DBX_STRINGTAB (objfile), stabstrsize, 1, sym_bfd);
2463 if (val != stabstrsize)
2464 perror_with_name (name);
2465
2466 stabsread_new_init ();
2467 buildsym_new_init ();
2468 free_header_files ();
2469 init_header_files ();
2470
2471 processing_acc_compilation = 1;
2472
2473 /* In a coff file, we've already installed the minimal symbols that came
2474 from the coff (non-stab) symbol table, so always act like an
2475 incremental load here. */
2476 if (stabsects->next == NULL)
2477 {
2478 stabsize = bfd_section_size (sym_bfd, stabsects->section);
2479 DBX_SYMCOUNT (objfile) = stabsize / DBX_SYMBOL_SIZE (objfile);
2480 DBX_SYMTAB_OFFSET (objfile) = stabsects->section->filepos;
2481 }
2482 else
2483 {
2484 struct stab_section_list *stabsect;
2485
2486 DBX_SYMCOUNT (objfile) = 0;
2487 for (stabsect = stabsects; stabsect != NULL; stabsect = stabsect->next)
2488 {
2489 stabsize = bfd_section_size (sym_bfd, stabsect->section);
2490 DBX_SYMCOUNT (objfile) += stabsize / DBX_SYMBOL_SIZE (objfile);
2491 }
2492
2493 DBX_SYMTAB_OFFSET (objfile) = stabsects->section->filepos;
2494
2495 symbuf_sections = stabsects->next;
2496 symbuf_left = bfd_section_size (sym_bfd, stabsects->section);
2497 symbuf_read = 0;
2498 }
2499
2500 dbx_symfile_read (objfile, section_offsets, 0);
2501 }
2502 \f
2503 /* Scan and build partial symbols for an ELF symbol file.
2504 This ELF file has already been processed to get its minimal symbols,
2505 and any DWARF symbols that were in it.
2506
2507 This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
2508 rolled into one.
2509
2510 OBJFILE is the object file we are reading symbols from.
2511 ADDR is the address relative to which the symbols are (e.g.
2512 the base address of the text segment).
2513 MAINLINE is true if we are reading the main symbol
2514 table (as opposed to a shared lib or dynamically loaded file).
2515 STABOFFSET and STABSIZE define the location in OBJFILE where the .stab
2516 section exists.
2517 STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the
2518 .stabstr section exists.
2519
2520 This routine is mostly copied from dbx_symfile_init and dbx_symfile_read,
2521 adjusted for elf details. */
2522
2523 void
2524 elfstab_build_psymtabs (objfile, section_offsets, mainline,
2525 staboffset, stabsize,
2526 stabstroffset, stabstrsize)
2527 struct objfile *objfile;
2528 struct section_offsets *section_offsets;
2529 int mainline;
2530 file_ptr staboffset;
2531 unsigned int stabsize;
2532 file_ptr stabstroffset;
2533 unsigned int stabstrsize;
2534 {
2535 int val;
2536 bfd *sym_bfd = objfile->obfd;
2537 char *name = bfd_get_filename (sym_bfd);
2538 struct dbx_symfile_info *info;
2539 asection *text_sect;
2540
2541 /* There is already a dbx_symfile_info allocated by our caller.
2542 It might even contain some info from the ELF symtab to help us. */
2543 info = objfile->sym_stab_info;
2544
2545 text_sect = bfd_get_section_by_name (sym_bfd, ".text");
2546 if (!text_sect)
2547 error ("Can't find .text section in symbol file");
2548 DBX_TEXT_ADDR (objfile) = bfd_section_vma (sym_bfd, text_sect);
2549 DBX_TEXT_SIZE (objfile) = bfd_section_size (sym_bfd, text_sect);
2550
2551 #define ELF_STABS_SYMBOL_SIZE 12 /* XXX FIXME XXX */
2552 DBX_SYMBOL_SIZE (objfile) = ELF_STABS_SYMBOL_SIZE;
2553 DBX_SYMCOUNT (objfile) = stabsize / DBX_SYMBOL_SIZE (objfile);
2554 DBX_STRINGTAB_SIZE (objfile) = stabstrsize;
2555 DBX_SYMTAB_OFFSET (objfile) = staboffset;
2556
2557 if (stabstrsize > bfd_get_size (sym_bfd))
2558 error ("ridiculous string table size: %d bytes", stabstrsize);
2559 DBX_STRINGTAB (objfile) = (char *)
2560 obstack_alloc (&objfile->psymbol_obstack, stabstrsize+1);
2561 OBJSTAT (objfile, sz_strtab += stabstrsize+1);
2562
2563 /* Now read in the string table in one big gulp. */
2564
2565 val = bfd_seek (sym_bfd, stabstroffset, SEEK_SET);
2566 if (val < 0)
2567 perror_with_name (name);
2568 val = bfd_read (DBX_STRINGTAB (objfile), stabstrsize, 1, sym_bfd);
2569 if (val != stabstrsize)
2570 perror_with_name (name);
2571
2572 stabsread_new_init ();
2573 buildsym_new_init ();
2574 free_header_files ();
2575 init_header_files ();
2576 install_minimal_symbols (objfile);
2577
2578 processing_acc_compilation = 1;
2579
2580 /* In an elf file, we've already installed the minimal symbols that came
2581 from the elf (non-stab) symbol table, so always act like an
2582 incremental load here. */
2583 dbx_symfile_read (objfile, section_offsets, 0);
2584 }
2585 \f
2586 /* Scan and build partial symbols for a file with special sections for stabs
2587 and stabstrings. The file has already been processed to get its minimal
2588 symbols, and any other symbols that might be necessary to resolve GSYMs.
2589
2590 This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
2591 rolled into one.
2592
2593 OBJFILE is the object file we are reading symbols from.
2594 ADDR is the address relative to which the symbols are (e.g. the base address
2595 of the text segment).
2596 MAINLINE is true if we are reading the main symbol table (as opposed to a
2597 shared lib or dynamically loaded file).
2598 STAB_NAME is the name of the section that contains the stabs.
2599 STABSTR_NAME is the name of the section that contains the stab strings.
2600
2601 This routine is mostly copied from dbx_symfile_init and dbx_symfile_read. */
2602
2603 void
2604 stabsect_build_psymtabs (objfile, section_offsets, mainline, stab_name,
2605 stabstr_name, text_name)
2606 struct objfile *objfile;
2607 struct section_offsets *section_offsets;
2608 int mainline;
2609 char *stab_name;
2610 char *stabstr_name;
2611 char *text_name;
2612 {
2613 int val;
2614 bfd *sym_bfd = objfile->obfd;
2615 char *name = bfd_get_filename (sym_bfd);
2616 asection *stabsect;
2617 asection *stabstrsect;
2618 asection *text_sect;
2619
2620 stabsect = bfd_get_section_by_name (sym_bfd, stab_name);
2621 stabstrsect = bfd_get_section_by_name (sym_bfd, stabstr_name);
2622
2623 if (!stabsect)
2624 return;
2625
2626 if (!stabstrsect)
2627 error ("stabsect_build_psymtabs: Found stabs (%s), but not string section (%s)",
2628 stab_name, stabstr_name);
2629
2630 objfile->sym_stab_info = (PTR) xmalloc (sizeof (struct dbx_symfile_info));
2631 memset (objfile->sym_stab_info, 0, sizeof (struct dbx_symfile_info));
2632
2633 text_sect = bfd_get_section_by_name (sym_bfd, text_name);
2634 if (!text_sect)
2635 error ("Can't find %s section in symbol file", text_name);
2636 DBX_TEXT_ADDR (objfile) = bfd_section_vma (sym_bfd, text_sect);
2637 DBX_TEXT_SIZE (objfile) = bfd_section_size (sym_bfd, text_sect);
2638
2639 DBX_SYMBOL_SIZE (objfile) = sizeof (struct external_nlist);
2640 DBX_SYMCOUNT (objfile) = bfd_section_size (sym_bfd, stabsect)
2641 / DBX_SYMBOL_SIZE (objfile);
2642 DBX_STRINGTAB_SIZE (objfile) = bfd_section_size (sym_bfd, stabstrsect);
2643 DBX_SYMTAB_OFFSET (objfile) = stabsect->filepos; /* XXX - FIXME: POKING INSIDE BFD DATA STRUCTURES */
2644
2645 if (DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd))
2646 error ("ridiculous string table size: %d bytes", DBX_STRINGTAB_SIZE (objfile));
2647 DBX_STRINGTAB (objfile) = (char *)
2648 obstack_alloc (&objfile->psymbol_obstack, DBX_STRINGTAB_SIZE (objfile) + 1);
2649 OBJSTAT (objfile, sz_strtab += DBX_STRINGTAB_SIZE (objfile) + 1);
2650
2651 /* Now read in the string table in one big gulp. */
2652
2653 val = bfd_get_section_contents (sym_bfd, /* bfd */
2654 stabstrsect, /* bfd section */
2655 DBX_STRINGTAB (objfile), /* input buffer */
2656 0, /* offset into section */
2657 DBX_STRINGTAB_SIZE (objfile)); /* amount to read */
2658
2659 if (!val)
2660 perror_with_name (name);
2661
2662 stabsread_new_init ();
2663 buildsym_new_init ();
2664 free_header_files ();
2665 init_header_files ();
2666 install_minimal_symbols (objfile);
2667
2668 /* Now, do an incremental load */
2669
2670 processing_acc_compilation = 1;
2671 dbx_symfile_read (objfile, section_offsets, 0);
2672 }
2673 \f
2674 static struct sym_fns aout_sym_fns =
2675 {
2676 bfd_target_aout_flavour,
2677 dbx_new_init, /* sym_new_init: init anything gbl to entire symtab */
2678 dbx_symfile_init, /* sym_init: read initial info, setup for sym_read() */
2679 dbx_symfile_read, /* sym_read: read a symbol file into symtab */
2680 dbx_symfile_finish, /* sym_finish: finished with file, cleanup */
2681 default_symfile_offsets,
2682 /* sym_offsets: parse user's offsets to internal form */
2683 NULL /* next: pointer to next struct sym_fns */
2684 };
2685
2686 void
2687 _initialize_dbxread ()
2688 {
2689 add_symtab_fns(&aout_sym_fns);
2690 }
This page took 0.083701 seconds and 4 git commands to generate.