dbxread.c revision 1.1 1 /* Read dbx symbol tables and convert to internal format, for GDB.
2 Copyright (C) 1986-2014 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19 /* This module provides three functions: dbx_symfile_init,
20 which initializes to read a symbol file; dbx_new_init, which
21 discards existing cached information when all symbols are being
22 discarded; and dbx_symfile_read, which reads a symbol table
23 from a file.
24
25 dbx_symfile_read only does the minimum work necessary for letting the
26 user "name" things symbolically; it does not read the entire symtab.
27 Instead, it reads the external and static symbols and puts them in partial
28 symbol tables. When more extensive information is requested of a
29 file, the corresponding partial symbol table is mutated into a full
30 fledged symbol table by going back and reading the symbols
31 for real. dbx_psymtab_to_symtab() is the function that does this */
32
33 #include "defs.h"
34 #include <string.h>
35
36 #if defined(__CYGNUSCLIB__)
37 #include <sys/types.h>
38 #include <fcntl.h>
39 #endif
40
41 #include "gdb_obstack.h"
42 #include <sys/stat.h>
43 #include "symtab.h"
44 #include "breakpoint.h"
45 #include "target.h"
46 #include "gdbcore.h" /* for bfd stuff */
47 #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
48 #include "filenames.h"
49 #include "objfiles.h"
50 #include "buildsym.h"
51 #include "stabsread.h"
52 #include "gdb-stabs.h"
53 #include "demangle.h"
54 #include "complaints.h"
55 #include "cp-abi.h"
56 #include "cp-support.h"
57 #include "psympriv.h"
58 #include "block.h"
59
60 #include "gdb_assert.h"
61
62 #include "aout/aout64.h"
63 #include "aout/stab_gnu.h" /* We always use GNU stabs, not
64 native, now. */
65
66
68 /* Key for dbx-associated data. */
69
70 const struct objfile_data *dbx_objfile_data_key;
71
72 /* We put a pointer to this structure in the read_symtab_private field
73 of the psymtab. */
74
75 struct symloc
76 {
77 /* Offset within the file symbol table of first local symbol for this
78 file. */
79
80 int ldsymoff;
81
82 /* Length (in bytes) of the section of the symbol table devoted to
83 this file's symbols (actually, the section bracketed may contain
84 more than just this file's symbols). If ldsymlen is 0, the only
85 reason for this thing's existence is the dependency list. Nothing
86 else will happen when it is read in. */
87
88 int ldsymlen;
89
90 /* The size of each symbol in the symbol file (in external form). */
91
92 int symbol_size;
93
94 /* Further information needed to locate the symbols if they are in
95 an ELF file. */
96
97 int symbol_offset;
98 int string_offset;
99 int file_string_offset;
100 };
101
102 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
103 #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
104 #define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private))
105 #define SYMBOL_SIZE(p) (SYMLOC(p)->symbol_size)
106 #define SYMBOL_OFFSET(p) (SYMLOC(p)->symbol_offset)
107 #define STRING_OFFSET(p) (SYMLOC(p)->string_offset)
108 #define FILE_STRING_OFFSET(p) (SYMLOC(p)->file_string_offset)
109
110
112 /* The objfile we are currently reading. */
113
114 static struct objfile *dbxread_objfile;
115
116 /* Remember what we deduced to be the source language of this psymtab. */
117
118 static enum language psymtab_language = language_unknown;
119
120 /* The BFD for this file -- implicit parameter to next_symbol_text. */
121
122 static bfd *symfile_bfd;
123
124 /* The size of each symbol in the symbol file (in external form).
125 This is set by dbx_symfile_read when building psymtabs, and by
126 dbx_psymtab_to_symtab when building symtabs. */
127
128 static unsigned symbol_size;
129
130 /* This is the offset of the symbol table in the executable file. */
131
132 static unsigned symbol_table_offset;
133
134 /* This is the offset of the string table in the executable file. */
135
136 static unsigned string_table_offset;
137
138 /* For elf+stab executables, the n_strx field is not a simple index
139 into the string table. Instead, each .o file has a base offset in
140 the string table, and the associated symbols contain offsets from
141 this base. The following two variables contain the base offset for
142 the current and next .o files. */
143
144 static unsigned int file_string_table_offset;
145 static unsigned int next_file_string_table_offset;
146
147 /* .o and NLM files contain unrelocated addresses which are based at
148 0. When non-zero, this flag disables some of the special cases for
149 Solaris elf+stab text addresses at location 0. */
150
151 static int symfile_relocatable = 0;
152
153 /* If this is nonzero, N_LBRAC, N_RBRAC, and N_SLINE entries are
154 relative to the function start address. */
155
156 static int block_address_function_relative = 0;
157
158 /* The lowest text address we have yet encountered. This is needed
160 because in an a.out file, there is no header field which tells us
161 what address the program is actually going to be loaded at, so we
162 need to make guesses based on the symbols (which *are* relocated to
163 reflect the address it will be loaded at). */
164
165 static CORE_ADDR lowest_text_address;
166
167 /* Non-zero if there is any line number info in the objfile. Prevents
168 end_psymtab from discarding an otherwise empty psymtab. */
169
170 static int has_line_numbers;
171
172 /* Complaints about the symbols we have encountered. */
173
174 static void
175 unknown_symtype_complaint (const char *arg1)
176 {
177 complaint (&symfile_complaints, _("unknown symbol type %s"), arg1);
178 }
179
180 static void
181 lbrac_mismatch_complaint (int arg1)
182 {
183 complaint (&symfile_complaints,
184 _("N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d"), arg1);
185 }
186
187 static void
188 repeated_header_complaint (const char *arg1, int arg2)
189 {
190 complaint (&symfile_complaints,
191 _("\"repeated\" header file %s not "
192 "previously seen, at symtab pos %d"),
193 arg1, arg2);
194 }
195
196 /* find_text_range --- find start and end of loadable code sections
197
198 The find_text_range function finds the shortest address range that
199 encloses all sections containing executable code, and stores it in
200 objfile's text_addr and text_size members.
201
202 dbx_symfile_read will use this to finish off the partial symbol
203 table, in some cases. */
204
205 static void
206 find_text_range (bfd * sym_bfd, struct objfile *objfile)
207 {
208 asection *sec;
209 int found_any = 0;
210 CORE_ADDR start = 0;
211 CORE_ADDR end = 0;
212
213 for (sec = sym_bfd->sections; sec; sec = sec->next)
214 if (bfd_get_section_flags (sym_bfd, sec) & SEC_CODE)
215 {
216 CORE_ADDR sec_start = bfd_section_vma (sym_bfd, sec);
217 CORE_ADDR sec_end = sec_start + bfd_section_size (sym_bfd, sec);
218
219 if (found_any)
220 {
221 if (sec_start < start)
222 start = sec_start;
223 if (sec_end > end)
224 end = sec_end;
225 }
226 else
227 {
228 start = sec_start;
229 end = sec_end;
230 }
231
232 found_any = 1;
233 }
234
235 if (!found_any)
236 error (_("Can't find any code sections in symbol file"));
237
238 DBX_TEXT_ADDR (objfile) = start;
239 DBX_TEXT_SIZE (objfile) = end - start;
240 }
241
242
244
245 /* During initial symbol readin, we need to have a structure to keep
246 track of which psymtabs have which bincls in them. This structure
247 is used during readin to setup the list of dependencies within each
248 partial symbol table. */
249
250 struct header_file_location
251 {
252 char *name; /* Name of header file */
253 int instance; /* See above */
254 struct partial_symtab *pst; /* Partial symtab that has the
255 BINCL/EINCL defs for this file. */
256 };
257
258 /* The actual list and controling variables. */
259 static struct header_file_location *bincl_list, *next_bincl;
260 static int bincls_allocated;
261
262 /* Local function prototypes. */
263
264 extern void _initialize_dbxread (void);
265
266 static void read_ofile_symtab (struct objfile *, struct partial_symtab *);
267
268 static void dbx_read_symtab (struct partial_symtab *self,
269 struct objfile *objfile);
270
271 static void dbx_psymtab_to_symtab_1 (struct objfile *, struct partial_symtab *);
272
273 static void read_dbx_dynamic_symtab (struct objfile *objfile);
274
275 static void read_dbx_symtab (struct objfile *);
276
277 static void free_bincl_list (struct objfile *);
278
279 static struct partial_symtab *find_corresponding_bincl_psymtab (char *, int);
280
281 static void add_bincl_to_list (struct partial_symtab *, char *, int);
282
283 static void init_bincl_list (int, struct objfile *);
284
285 static char *dbx_next_symbol_text (struct objfile *);
286
287 static void fill_symbuf (bfd *);
288
289 static void dbx_symfile_init (struct objfile *);
290
291 static void dbx_new_init (struct objfile *);
292
293 static void dbx_symfile_read (struct objfile *, int);
294
295 static void dbx_symfile_finish (struct objfile *);
296
297 static void record_minimal_symbol (const char *, CORE_ADDR, int,
298 struct objfile *);
299
300 static void add_new_header_file (char *, int);
301
302 static void add_old_header_file (char *, int);
303
304 static void add_this_object_header_file (int);
305
306 static struct partial_symtab *start_psymtab (struct objfile *, char *,
307 CORE_ADDR, int,
308 struct partial_symbol **,
309 struct partial_symbol **);
310
311 /* Free up old header file tables. */
312
313 void
314 free_header_files (void)
315 {
316 if (this_object_header_files)
317 {
318 xfree (this_object_header_files);
319 this_object_header_files = NULL;
320 }
321 n_allocated_this_object_header_files = 0;
322 }
323
324 /* Allocate new header file tables. */
325
326 void
327 init_header_files (void)
328 {
329 n_allocated_this_object_header_files = 10;
330 this_object_header_files = (int *) xmalloc (10 * sizeof (int));
331 }
332
333 /* Add header file number I for this object file
334 at the next successive FILENUM. */
335
336 static void
337 add_this_object_header_file (int i)
338 {
339 if (n_this_object_header_files == n_allocated_this_object_header_files)
340 {
341 n_allocated_this_object_header_files *= 2;
342 this_object_header_files
343 = (int *) xrealloc ((char *) this_object_header_files,
344 n_allocated_this_object_header_files * sizeof (int));
345 }
346
347 this_object_header_files[n_this_object_header_files++] = i;
348 }
349
350 /* Add to this file an "old" header file, one already seen in
351 a previous object file. NAME is the header file's name.
352 INSTANCE is its instance code, to select among multiple
353 symbol tables for the same header file. */
354
355 static void
356 add_old_header_file (char *name, int instance)
357 {
358 struct header_file *p = HEADER_FILES (dbxread_objfile);
359 int i;
360
361 for (i = 0; i < N_HEADER_FILES (dbxread_objfile); i++)
362 if (filename_cmp (p[i].name, name) == 0 && instance == p[i].instance)
363 {
364 add_this_object_header_file (i);
365 return;
366 }
367 repeated_header_complaint (name, symnum);
368 }
369
370 /* Add to this file a "new" header file: definitions for its types follow.
371 NAME is the header file's name.
372 Most often this happens only once for each distinct header file,
373 but not necessarily. If it happens more than once, INSTANCE has
374 a different value each time, and references to the header file
375 use INSTANCE values to select among them.
376
377 dbx output contains "begin" and "end" markers for each new header file,
378 but at this level we just need to know which files there have been;
379 so we record the file when its "begin" is seen and ignore the "end". */
380
381 static void
382 add_new_header_file (char *name, int instance)
383 {
384 int i;
385 struct header_file *hfile;
386
387 /* Make sure there is room for one more header file. */
388
389 i = N_ALLOCATED_HEADER_FILES (dbxread_objfile);
390
391 if (N_HEADER_FILES (dbxread_objfile) == i)
392 {
393 if (i == 0)
394 {
395 N_ALLOCATED_HEADER_FILES (dbxread_objfile) = 10;
396 HEADER_FILES (dbxread_objfile) = (struct header_file *)
397 xmalloc (10 * sizeof (struct header_file));
398 }
399 else
400 {
401 i *= 2;
402 N_ALLOCATED_HEADER_FILES (dbxread_objfile) = i;
403 HEADER_FILES (dbxread_objfile) = (struct header_file *)
404 xrealloc ((char *) HEADER_FILES (dbxread_objfile),
405 (i * sizeof (struct header_file)));
406 }
407 }
408
409 /* Create an entry for this header file. */
410
411 i = N_HEADER_FILES (dbxread_objfile)++;
412 hfile = HEADER_FILES (dbxread_objfile) + i;
413 hfile->name = xstrdup (name);
414 hfile->instance = instance;
415 hfile->length = 10;
416 hfile->vector
417 = (struct type **) xmalloc (10 * sizeof (struct type *));
418 memset (hfile->vector, 0, 10 * sizeof (struct type *));
419
420 add_this_object_header_file (i);
421 }
422
423 #if 0
424 static struct type **
425 explicit_lookup_type (int real_filenum, int index)
426 {
427 struct header_file *f = &HEADER_FILES (dbxread_objfile)[real_filenum];
428
429 if (index >= f->length)
430 {
431 f->length *= 2;
432 f->vector = (struct type **)
433 xrealloc (f->vector, f->length * sizeof (struct type *));
434 memset (&f->vector[f->length / 2],
435 '\0', f->length * sizeof (struct type *) / 2);
436 }
437 return &f->vector[index];
438 }
439 #endif
440
441 static void
443 record_minimal_symbol (const char *name, CORE_ADDR address, int type,
444 struct objfile *objfile)
445 {
446 enum minimal_symbol_type ms_type;
447 int section;
448
449 switch (type)
450 {
451 case N_TEXT | N_EXT:
452 ms_type = mst_text;
453 section = SECT_OFF_TEXT (objfile);
454 break;
455 case N_DATA | N_EXT:
456 ms_type = mst_data;
457 section = SECT_OFF_DATA (objfile);
458 break;
459 case N_BSS | N_EXT:
460 ms_type = mst_bss;
461 section = SECT_OFF_BSS (objfile);
462 break;
463 case N_ABS | N_EXT:
464 ms_type = mst_abs;
465 section = -1;
466 break;
467 #ifdef N_SETV
468 case N_SETV | N_EXT:
469 ms_type = mst_data;
470 section = SECT_OFF_DATA (objfile);
471 break;
472 case N_SETV:
473 /* I don't think this type actually exists; since a N_SETV is the result
474 of going over many .o files, it doesn't make sense to have one
475 file local. */
476 ms_type = mst_file_data;
477 section = SECT_OFF_DATA (objfile);
478 break;
479 #endif
480 case N_TEXT:
481 case N_NBTEXT:
482 case N_FN:
483 case N_FN_SEQ:
484 ms_type = mst_file_text;
485 section = SECT_OFF_TEXT (objfile);
486 break;
487 case N_DATA:
488 ms_type = mst_file_data;
489
490 /* Check for __DYNAMIC, which is used by Sun shared libraries.
491 Record it as global even if it's local, not global, so
492 lookup_minimal_symbol can find it. We don't check symbol_leading_char
493 because for SunOS4 it always is '_'. */
494 if (name[8] == 'C' && strcmp ("__DYNAMIC", name) == 0)
495 ms_type = mst_data;
496
497 /* Same with virtual function tables, both global and static. */
498 {
499 const char *tempstring = name;
500
501 if (tempstring[0] == bfd_get_symbol_leading_char (objfile->obfd))
502 ++tempstring;
503 if (is_vtable_name (tempstring))
504 ms_type = mst_data;
505 }
506 section = SECT_OFF_DATA (objfile);
507 break;
508 case N_BSS:
509 ms_type = mst_file_bss;
510 section = SECT_OFF_BSS (objfile);
511 break;
512 default:
513 ms_type = mst_unknown;
514 section = -1;
515 break;
516 }
517
518 if ((ms_type == mst_file_text || ms_type == mst_text)
519 && address < lowest_text_address)
520 lowest_text_address = address;
521
522 prim_record_minimal_symbol_and_info
523 (name, address, ms_type, section, objfile);
524 }
525
526 /* Scan and build partial symbols for a symbol file.
528 We have been initialized by a call to dbx_symfile_init, which
529 put all the relevant info into a "struct dbx_symfile_info",
530 hung off the objfile structure. */
531
532 static void
533 dbx_symfile_read (struct objfile *objfile, int symfile_flags)
534 {
535 bfd *sym_bfd;
536 int val;
537 struct cleanup *back_to;
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), "epoc-pe", 7))
557 || (0 == strncmp (bfd_get_target (sym_bfd), "nlm", 3)));
558
559 val = bfd_seek (sym_bfd, DBX_SYMTAB_OFFSET (objfile), SEEK_SET);
560 if (val < 0)
561 perror_with_name (objfile_name (objfile));
562
563 /* Size the symbol table. */
564 if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0)
565 init_psymbol_list (objfile, DBX_SYMCOUNT (objfile));
566
567 symbol_size = DBX_SYMBOL_SIZE (objfile);
568 symbol_table_offset = DBX_SYMTAB_OFFSET (objfile);
569
570 free_pending_blocks ();
571 back_to = make_cleanup (really_free_pendings, 0);
572
573 init_minimal_symbol_collection ();
574 make_cleanup_discard_minimal_symbols ();
575
576 /* Read stabs data from executable file and define symbols. */
577
578 read_dbx_symtab (objfile);
579
580 /* Add the dynamic symbols. */
581
582 read_dbx_dynamic_symtab (objfile);
583
584 /* Install any minimal symbols that have been collected as the current
585 minimal symbols for this objfile. */
586
587 install_minimal_symbols (objfile);
588
589 do_cleanups (back_to);
590 }
591
592 /* Initialize anything that needs initializing when a completely new
593 symbol file is specified (not just adding some symbols from another
594 file, e.g. a shared library). */
595
596 static void
597 dbx_new_init (struct objfile *ignore)
598 {
599 stabsread_new_init ();
600 buildsym_new_init ();
601 init_header_files ();
602 }
603
604
605 /* dbx_symfile_init ()
606 is the dbx-specific initialization routine for reading symbols.
607 It is passed a struct objfile which contains, among other things,
608 the BFD for the file whose symbols are being read, and a slot for a pointer
609 to "private data" which we fill with goodies.
610
611 We read the string table into malloc'd space and stash a pointer to it.
612
613 Since BFD doesn't know how to read debug symbols in a format-independent
614 way (and may never do so...), we have to do it ourselves. We will never
615 be called unless this is an a.out (or very similar) file.
616 FIXME, there should be a cleaner peephole into the BFD environment here. */
617
618 #define DBX_STRINGTAB_SIZE_SIZE sizeof(long) /* FIXME */
619
620 static void
621 dbx_symfile_init (struct objfile *objfile)
622 {
623 int val;
624 bfd *sym_bfd = objfile->obfd;
625 char *name = bfd_get_filename (sym_bfd);
626 asection *text_sect;
627 unsigned char size_temp[DBX_STRINGTAB_SIZE_SIZE];
628 struct dbx_symfile_info *dbx;
629
630 /* Allocate struct to keep track of the symfile. */
631 dbx = XCNEW (struct dbx_symfile_info);
632 set_objfile_data (objfile, dbx_objfile_data_key, dbx);
633
634 DBX_TEXT_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".text");
635 DBX_DATA_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".data");
636 DBX_BSS_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".bss");
637
638 /* FIXME POKING INSIDE BFD DATA STRUCTURES. */
639 #define STRING_TABLE_OFFSET (sym_bfd->origin + obj_str_filepos (sym_bfd))
640 #define SYMBOL_TABLE_OFFSET (sym_bfd->origin + obj_sym_filepos (sym_bfd))
641
642 /* FIXME POKING INSIDE BFD DATA STRUCTURES. */
643
644 DBX_SYMFILE_INFO (objfile)->stab_section_info = NULL;
645
646 text_sect = bfd_get_section_by_name (sym_bfd, ".text");
647 if (!text_sect)
648 error (_("Can't find .text section in symbol file"));
649 DBX_TEXT_ADDR (objfile) = bfd_section_vma (sym_bfd, text_sect);
650 DBX_TEXT_SIZE (objfile) = bfd_section_size (sym_bfd, text_sect);
651
652 DBX_SYMBOL_SIZE (objfile) = obj_symbol_entry_size (sym_bfd);
653 DBX_SYMCOUNT (objfile) = bfd_get_symcount (sym_bfd);
654 DBX_SYMTAB_OFFSET (objfile) = SYMBOL_TABLE_OFFSET;
655
656 /* Read the string table and stash it away in the objfile_obstack.
657 When we blow away the objfile the string table goes away as well.
658 Note that gdb used to use the results of attempting to malloc the
659 string table, based on the size it read, as a form of sanity check
660 for botched byte swapping, on the theory that a byte swapped string
661 table size would be so totally bogus that the malloc would fail. Now
662 that we put in on the objfile_obstack, we can't do this since gdb gets
663 a fatal error (out of virtual memory) if the size is bogus. We can
664 however at least check to see if the size is less than the size of
665 the size field itself, or larger than the size of the entire file.
666 Note that all valid string tables have a size greater than zero, since
667 the bytes used to hold the size are included in the count. */
668
669 if (STRING_TABLE_OFFSET == 0)
670 {
671 /* It appears that with the existing bfd code, STRING_TABLE_OFFSET
672 will never be zero, even when there is no string table. This
673 would appear to be a bug in bfd. */
674 DBX_STRINGTAB_SIZE (objfile) = 0;
675 DBX_STRINGTAB (objfile) = NULL;
676 }
677 else
678 {
679 val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, SEEK_SET);
680 if (val < 0)
681 perror_with_name (name);
682
683 memset (size_temp, 0, sizeof (size_temp));
684 val = bfd_bread (size_temp, sizeof (size_temp), sym_bfd);
685 if (val < 0)
686 {
687 perror_with_name (name);
688 }
689 else if (val == 0)
690 {
691 /* With the existing bfd code, STRING_TABLE_OFFSET will be set to
692 EOF if there is no string table, and attempting to read the size
693 from EOF will read zero bytes. */
694 DBX_STRINGTAB_SIZE (objfile) = 0;
695 DBX_STRINGTAB (objfile) = NULL;
696 }
697 else
698 {
699 /* Read some data that would appear to be the string table size.
700 If there really is a string table, then it is probably the right
701 size. Byteswap if necessary and validate the size. Note that
702 the minimum is DBX_STRINGTAB_SIZE_SIZE. If we just read some
703 random data that happened to be at STRING_TABLE_OFFSET, because
704 bfd can't tell us there is no string table, the sanity checks may
705 or may not catch this. */
706 DBX_STRINGTAB_SIZE (objfile) = bfd_h_get_32 (sym_bfd, size_temp);
707
708 if (DBX_STRINGTAB_SIZE (objfile) < sizeof (size_temp)
709 || DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd))
710 error (_("ridiculous string table size (%d bytes)."),
711 DBX_STRINGTAB_SIZE (objfile));
712
713 DBX_STRINGTAB (objfile) =
714 (char *) obstack_alloc (&objfile->objfile_obstack,
715 DBX_STRINGTAB_SIZE (objfile));
716 OBJSTAT (objfile, sz_strtab += DBX_STRINGTAB_SIZE (objfile));
717
718 /* Now read in the string table in one big gulp. */
719
720 val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, SEEK_SET);
721 if (val < 0)
722 perror_with_name (name);
723 val = bfd_bread (DBX_STRINGTAB (objfile),
724 DBX_STRINGTAB_SIZE (objfile),
725 sym_bfd);
726 if (val != DBX_STRINGTAB_SIZE (objfile))
727 perror_with_name (name);
728 }
729 }
730 }
731
732 /* Perform any local cleanups required when we are done with a particular
733 objfile. I.E, we are in the process of discarding all symbol information
734 for an objfile, freeing up all memory held for it, and unlinking the
735 objfile struct from the global list of known objfiles. */
736
737 static void
738 dbx_symfile_finish (struct objfile *objfile)
739 {
740 free_header_files ();
741 }
742
743 static void
744 dbx_free_symfile_info (struct objfile *objfile, void *arg)
745 {
746 struct dbx_symfile_info *dbx = arg;
747
748 if (dbx->header_files != NULL)
749 {
750 int i = dbx->n_header_files;
751 struct header_file *hfiles = dbx->header_files;
752
753 while (--i >= 0)
754 {
755 xfree (hfiles[i].name);
756 xfree (hfiles[i].vector);
757 }
758 xfree (hfiles);
759 }
760
761 xfree (dbx);
762 }
763
764
765
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 /* Name of last function encountered. Used in Solaris to approximate
773 object file boundaries. */
774 static char *last_function_name;
775
776 /* The address in memory of the string table of the object file we are
777 reading (which might not be the "main" object file, but might be a
778 shared library or some other dynamically loaded thing). This is
779 set by read_dbx_symtab when building psymtabs, and by
780 read_ofile_symtab when building symtabs, and is used only by
781 next_symbol_text. FIXME: If that is true, we don't need it when
782 building psymtabs, right? */
783 static char *stringtab_global;
784
785 /* These variables are used to control fill_symbuf when the stabs
786 symbols are not contiguous (as may be the case when a COFF file is
787 linked using --split-by-reloc). */
788 static struct stab_section_list *symbuf_sections;
789 static unsigned int symbuf_left;
790 static unsigned int symbuf_read;
791
792 /* This variable stores a global stabs buffer, if we read stabs into
793 memory in one chunk in order to process relocations. */
794 static bfd_byte *stabs_data;
795
796 /* Refill the symbol table input buffer
797 and set the variables that control fetching entries from it.
798 Reports an error if no data available.
799 This function can read past the end of the symbol table
800 (into the string table) but this does no harm. */
801
802 static void
803 fill_symbuf (bfd *sym_bfd)
804 {
805 unsigned int count;
806 int nbytes;
807
808 if (stabs_data)
809 {
810 nbytes = sizeof (symbuf);
811 if (nbytes > symbuf_left)
812 nbytes = symbuf_left;
813 memcpy (symbuf, stabs_data + symbuf_read, nbytes);
814 }
815 else if (symbuf_sections == NULL)
816 {
817 count = sizeof (symbuf);
818 nbytes = bfd_bread (symbuf, count, sym_bfd);
819 }
820 else
821 {
822 if (symbuf_left <= 0)
823 {
824 file_ptr filepos = symbuf_sections->section->filepos;
825
826 if (bfd_seek (sym_bfd, filepos, SEEK_SET) != 0)
827 perror_with_name (bfd_get_filename (sym_bfd));
828 symbuf_left = bfd_section_size (sym_bfd, symbuf_sections->section);
829 symbol_table_offset = filepos - symbuf_read;
830 symbuf_sections = symbuf_sections->next;
831 }
832
833 count = symbuf_left;
834 if (count > sizeof (symbuf))
835 count = sizeof (symbuf);
836 nbytes = bfd_bread (symbuf, count, sym_bfd);
837 }
838
839 if (nbytes < 0)
840 perror_with_name (bfd_get_filename (sym_bfd));
841 else if (nbytes == 0)
842 error (_("Premature end of file reading symbol table"));
843 symbuf_end = nbytes / symbol_size;
844 symbuf_idx = 0;
845 symbuf_left -= nbytes;
846 symbuf_read += nbytes;
847 }
848
849 static void
850 stabs_seek (int sym_offset)
851 {
852 if (stabs_data)
853 {
854 symbuf_read += sym_offset;
855 symbuf_left -= sym_offset;
856 }
857 else
858 bfd_seek (symfile_bfd, sym_offset, SEEK_CUR);
859 }
860
861 #define INTERNALIZE_SYMBOL(intern, extern, abfd) \
862 { \
863 (intern).n_strx = bfd_h_get_32 (abfd, (extern)->e_strx); \
864 (intern).n_type = bfd_h_get_8 (abfd, (extern)->e_type); \
865 (intern).n_other = 0; \
866 (intern).n_desc = bfd_h_get_16 (abfd, (extern)->e_desc); \
867 if (bfd_get_sign_extend_vma (abfd)) \
868 (intern).n_value = bfd_h_get_signed_32 (abfd, (extern)->e_value); \
869 else \
870 (intern).n_value = bfd_h_get_32 (abfd, (extern)->e_value); \
871 }
872
873 /* Invariant: The symbol pointed to by symbuf_idx is the first one
874 that hasn't been swapped. Swap the symbol at the same time
875 that symbuf_idx is incremented. */
876
877 /* dbx allows the text of a symbol name to be continued into the
878 next symbol name! When such a continuation is encountered
879 (a \ at the end of the text of a name)
880 call this function to get the continuation. */
881
882 static char *
883 dbx_next_symbol_text (struct objfile *objfile)
884 {
885 struct internal_nlist nlist;
886
887 if (symbuf_idx == symbuf_end)
888 fill_symbuf (symfile_bfd);
889
890 symnum++;
891 INTERNALIZE_SYMBOL (nlist, &symbuf[symbuf_idx], symfile_bfd);
892 OBJSTAT (objfile, n_stabs++);
893
894 symbuf_idx++;
895
896 return nlist.n_strx + stringtab_global + file_string_table_offset;
897 }
898
899 /* Initialize the list of bincls to contain none and have some
901 allocated. */
902
903 static void
904 init_bincl_list (int number, struct objfile *objfile)
905 {
906 bincls_allocated = number;
907 next_bincl = bincl_list = (struct header_file_location *)
908 xmalloc (bincls_allocated * sizeof (struct header_file_location));
909 }
910
911 /* Add a bincl to the list. */
912
913 static void
914 add_bincl_to_list (struct partial_symtab *pst, char *name, int instance)
915 {
916 if (next_bincl >= bincl_list + bincls_allocated)
917 {
918 int offset = next_bincl - bincl_list;
919
920 bincls_allocated *= 2;
921 bincl_list = (struct header_file_location *)
922 xrealloc ((char *) bincl_list,
923 bincls_allocated * sizeof (struct header_file_location));
924 next_bincl = bincl_list + offset;
925 }
926 next_bincl->pst = pst;
927 next_bincl->instance = instance;
928 next_bincl++->name = name;
929 }
930
931 /* Given a name, value pair, find the corresponding
932 bincl in the list. Return the partial symtab associated
933 with that header_file_location. */
934
935 static struct partial_symtab *
936 find_corresponding_bincl_psymtab (char *name, int instance)
937 {
938 struct header_file_location *bincl;
939
940 for (bincl = bincl_list; bincl < next_bincl; bincl++)
941 if (bincl->instance == instance
942 && strcmp (name, bincl->name) == 0)
943 return bincl->pst;
944
945 repeated_header_complaint (name, symnum);
946 return (struct partial_symtab *) 0;
947 }
948
949 /* Free the storage allocated for the bincl list. */
950
951 static void
952 free_bincl_list (struct objfile *objfile)
953 {
954 xfree (bincl_list);
955 bincls_allocated = 0;
956 }
957
958 static void
959 do_free_bincl_list_cleanup (void *objfile)
960 {
961 free_bincl_list (objfile);
962 }
963
964 static struct cleanup *
965 make_cleanup_free_bincl_list (struct objfile *objfile)
966 {
967 return make_cleanup (do_free_bincl_list_cleanup, objfile);
968 }
969
970 /* Set namestring based on nlist. If the string table index is invalid,
971 give a fake name, and print a single error message per symbol file read,
972 rather than abort the symbol reading or flood the user with messages. */
973
974 static char *
975 set_namestring (struct objfile *objfile, const struct internal_nlist *nlist)
976 {
977 char *namestring;
978
979 if (nlist->n_strx + file_string_table_offset
980 >= DBX_STRINGTAB_SIZE (objfile)
981 || nlist->n_strx + file_string_table_offset < nlist->n_strx)
982 {
983 complaint (&symfile_complaints,
984 _("bad string table offset in symbol %d"),
985 symnum);
986 namestring = "<bad string table offset>";
987 }
988 else
989 namestring = (nlist->n_strx + file_string_table_offset
990 + DBX_STRINGTAB (objfile));
991 return namestring;
992 }
993
994 /* Scan a SunOs dynamic symbol table for symbols of interest and
995 add them to the minimal symbol table. */
996
997 static void
998 read_dbx_dynamic_symtab (struct objfile *objfile)
999 {
1000 bfd *abfd = objfile->obfd;
1001 struct cleanup *back_to;
1002 int counter;
1003 long dynsym_size;
1004 long dynsym_count;
1005 asymbol **dynsyms;
1006 asymbol **symptr;
1007 arelent **relptr;
1008 long dynrel_size;
1009 long dynrel_count;
1010 arelent **dynrels;
1011 CORE_ADDR sym_value;
1012 const char *name;
1013
1014 /* Check that the symbol file has dynamic symbols that we know about.
1015 bfd_arch_unknown can happen if we are reading a sun3 symbol file
1016 on a sun4 host (and vice versa) and bfd is not configured
1017 --with-target=all. This would trigger an assertion in bfd/sunos.c,
1018 so we ignore the dynamic symbols in this case. */
1019 if (bfd_get_flavour (abfd) != bfd_target_aout_flavour
1020 || (bfd_get_file_flags (abfd) & DYNAMIC) == 0
1021 || bfd_get_arch (abfd) == bfd_arch_unknown)
1022 return;
1023
1024 dynsym_size = bfd_get_dynamic_symtab_upper_bound (abfd);
1025 if (dynsym_size < 0)
1026 return;
1027
1028 dynsyms = (asymbol **) xmalloc (dynsym_size);
1029 back_to = make_cleanup (xfree, dynsyms);
1030
1031 dynsym_count = bfd_canonicalize_dynamic_symtab (abfd, dynsyms);
1032 if (dynsym_count < 0)
1033 {
1034 do_cleanups (back_to);
1035 return;
1036 }
1037
1038 /* Enter dynamic symbols into the minimal symbol table
1039 if this is a stripped executable. */
1040 if (bfd_get_symcount (abfd) <= 0)
1041 {
1042 symptr = dynsyms;
1043 for (counter = 0; counter < dynsym_count; counter++, symptr++)
1044 {
1045 asymbol *sym = *symptr;
1046 asection *sec;
1047 int type;
1048
1049 sec = bfd_get_section (sym);
1050
1051 /* BFD symbols are section relative. */
1052 sym_value = sym->value + sec->vma;
1053
1054 if (bfd_get_section_flags (abfd, sec) & SEC_CODE)
1055 {
1056 sym_value += ANOFFSET (objfile->section_offsets,
1057 SECT_OFF_TEXT (objfile));
1058 type = N_TEXT;
1059 }
1060 else if (bfd_get_section_flags (abfd, sec) & SEC_DATA)
1061 {
1062 sym_value += ANOFFSET (objfile->section_offsets,
1063 SECT_OFF_DATA (objfile));
1064 type = N_DATA;
1065 }
1066 else if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
1067 {
1068 sym_value += ANOFFSET (objfile->section_offsets,
1069 SECT_OFF_BSS (objfile));
1070 type = N_BSS;
1071 }
1072 else
1073 continue;
1074
1075 if (sym->flags & BSF_GLOBAL)
1076 type |= N_EXT;
1077
1078 record_minimal_symbol (bfd_asymbol_name (sym), sym_value,
1079 type, objfile);
1080 }
1081 }
1082
1083 /* Symbols from shared libraries have a dynamic relocation entry
1084 that points to the associated slot in the procedure linkage table.
1085 We make a mininal symbol table entry with type mst_solib_trampoline
1086 at the address in the procedure linkage table. */
1087 dynrel_size = bfd_get_dynamic_reloc_upper_bound (abfd);
1088 if (dynrel_size < 0)
1089 {
1090 do_cleanups (back_to);
1091 return;
1092 }
1093
1094 dynrels = (arelent **) xmalloc (dynrel_size);
1095 make_cleanup (xfree, dynrels);
1096
1097 dynrel_count = bfd_canonicalize_dynamic_reloc (abfd, dynrels, dynsyms);
1098 if (dynrel_count < 0)
1099 {
1100 do_cleanups (back_to);
1101 return;
1102 }
1103
1104 for (counter = 0, relptr = dynrels;
1105 counter < dynrel_count;
1106 counter++, relptr++)
1107 {
1108 arelent *rel = *relptr;
1109 CORE_ADDR address =
1110 rel->address + ANOFFSET (objfile->section_offsets,
1111 SECT_OFF_DATA (objfile));
1112
1113 switch (bfd_get_arch (abfd))
1114 {
1115 case bfd_arch_sparc:
1116 if (rel->howto->type != RELOC_JMP_SLOT)
1117 continue;
1118 break;
1119 case bfd_arch_m68k:
1120 /* `16' is the type BFD produces for a jump table relocation. */
1121 if (rel->howto->type != 16)
1122 continue;
1123
1124 /* Adjust address in the jump table to point to
1125 the start of the bsr instruction. */
1126 address -= 2;
1127 break;
1128 default:
1129 continue;
1130 }
1131
1132 name = bfd_asymbol_name (*rel->sym_ptr_ptr);
1133 prim_record_minimal_symbol (name, address, mst_solib_trampoline,
1134 objfile);
1135 }
1136
1137 do_cleanups (back_to);
1138 }
1139
1140 static CORE_ADDR
1141 find_stab_function_addr (char *namestring, const char *filename,
1142 struct objfile *objfile)
1143 {
1144 struct minimal_symbol *msym;
1145 char *p;
1146 int n;
1147
1148 p = strchr (namestring, ':');
1149 if (p == NULL)
1150 p = namestring;
1151 n = p - namestring;
1152 p = alloca (n + 2);
1153 strncpy (p, namestring, n);
1154 p[n] = 0;
1155
1156 msym = lookup_minimal_symbol (p, filename, objfile);
1157 if (msym == NULL)
1158 {
1159 /* Sun Fortran appends an underscore to the minimal symbol name,
1160 try again with an appended underscore if the minimal symbol
1161 was not found. */
1162 p[n] = '_';
1163 p[n + 1] = 0;
1164 msym = lookup_minimal_symbol (p, filename, objfile);
1165 }
1166
1167 if (msym == NULL && filename != NULL)
1168 {
1169 /* Try again without the filename. */
1170 p[n] = 0;
1171 msym = lookup_minimal_symbol (p, NULL, objfile);
1172 }
1173 if (msym == NULL && filename != NULL)
1174 {
1175 /* And try again for Sun Fortran, but without the filename. */
1176 p[n] = '_';
1177 p[n + 1] = 0;
1178 msym = lookup_minimal_symbol (p, NULL, objfile);
1179 }
1180
1181 return msym == NULL ? 0 : SYMBOL_VALUE_ADDRESS (msym);
1182 }
1183
1184 static void
1185 function_outside_compilation_unit_complaint (const char *arg1)
1186 {
1187 complaint (&symfile_complaints,
1188 _("function `%s' appears to be defined "
1189 "outside of all compilation units"),
1190 arg1);
1191 }
1192
1193 /* Setup partial_symtab's describing each source file for which
1194 debugging information is available. */
1195
1196 static void
1197 read_dbx_symtab (struct objfile *objfile)
1198 {
1199 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1200 struct external_nlist *bufp = 0; /* =0 avoids gcc -Wall glitch. */
1201 struct internal_nlist nlist;
1202 CORE_ADDR text_addr;
1203 int text_size;
1204 char *sym_name;
1205 int sym_len;
1206
1207 char *namestring;
1208 int nsl;
1209 int past_first_source_file = 0;
1210 CORE_ADDR last_o_file_start = 0;
1211 CORE_ADDR last_function_start = 0;
1212 struct cleanup *back_to;
1213 bfd *abfd;
1214 int textlow_not_set;
1215 int data_sect_index;
1216
1217 /* Current partial symtab. */
1218 struct partial_symtab *pst;
1219
1220 /* List of current psymtab's include files. */
1221 const char **psymtab_include_list;
1222 int includes_allocated;
1223 int includes_used;
1224
1225 /* Index within current psymtab dependency list. */
1226 struct partial_symtab **dependency_list;
1227 int dependencies_used, dependencies_allocated;
1228
1229 text_addr = DBX_TEXT_ADDR (objfile);
1230 text_size = DBX_TEXT_SIZE (objfile);
1231
1232 /* FIXME. We probably want to change stringtab_global rather than add this
1233 while processing every symbol entry. FIXME. */
1234 file_string_table_offset = 0;
1235 next_file_string_table_offset = 0;
1236
1237 stringtab_global = DBX_STRINGTAB (objfile);
1238
1239 pst = (struct partial_symtab *) 0;
1240
1241 includes_allocated = 30;
1242 includes_used = 0;
1243 psymtab_include_list = (const char **) alloca (includes_allocated *
1244 sizeof (const char *));
1245
1246 dependencies_allocated = 30;
1247 dependencies_used = 0;
1248 dependency_list =
1249 (struct partial_symtab **) alloca (dependencies_allocated *
1250 sizeof (struct partial_symtab *));
1251
1252 /* Init bincl list */
1253 init_bincl_list (20, objfile);
1254 back_to = make_cleanup_free_bincl_list (objfile);
1255
1256 set_last_source_file (NULL);
1257
1258 lowest_text_address = (CORE_ADDR) -1;
1259
1260 symfile_bfd = objfile->obfd; /* For next_text_symbol. */
1261 abfd = objfile->obfd;
1262 symbuf_end = symbuf_idx = 0;
1263 next_symbol_text_func = dbx_next_symbol_text;
1264 textlow_not_set = 1;
1265 has_line_numbers = 0;
1266
1267 /* FIXME: jimb/2003-09-12: We don't apply the right section's offset
1268 to global and static variables. The stab for a global or static
1269 variable doesn't give us any indication of which section it's in,
1270 so we can't tell immediately which offset in
1271 objfile->section_offsets we should apply to the variable's
1272 address.
1273
1274 We could certainly find out which section contains the variable
1275 by looking up the variable's unrelocated address with
1276 find_pc_section, but that would be expensive; this is the
1277 function that constructs the partial symbol tables by examining
1278 every symbol in the entire executable, and it's
1279 performance-critical. So that expense would not be welcome. I'm
1280 not sure what to do about this at the moment.
1281
1282 What we have done for years is to simply assume that the .data
1283 section's offset is appropriate for all global and static
1284 variables. Recently, this was expanded to fall back to the .bss
1285 section's offset if there is no .data section, and then to the
1286 .rodata section's offset. */
1287 data_sect_index = objfile->sect_index_data;
1288 if (data_sect_index == -1)
1289 data_sect_index = SECT_OFF_BSS (objfile);
1290 if (data_sect_index == -1)
1291 data_sect_index = SECT_OFF_RODATA (objfile);
1292
1293 /* If data_sect_index is still -1, that's okay. It's perfectly fine
1294 for the file to have no .data, no .bss, and no .text at all, if
1295 it also has no global or static variables. If it does, we will
1296 get an internal error from an ANOFFSET macro below when we try to
1297 use data_sect_index. */
1298
1299 for (symnum = 0; symnum < DBX_SYMCOUNT (objfile); symnum++)
1300 {
1301 /* Get the symbol for this run and pull out some info. */
1302 QUIT; /* Allow this to be interruptable. */
1303 if (symbuf_idx == symbuf_end)
1304 fill_symbuf (abfd);
1305 bufp = &symbuf[symbuf_idx++];
1306
1307 /*
1308 * Special case to speed up readin.
1309 */
1310 if (bfd_h_get_8 (abfd, bufp->e_type) == N_SLINE)
1311 {
1312 has_line_numbers = 1;
1313 continue;
1314 }
1315
1316 INTERNALIZE_SYMBOL (nlist, bufp, abfd);
1317 OBJSTAT (objfile, n_stabs++);
1318
1319 /* Ok. There is a lot of code duplicated in the rest of this
1320 switch statement (for efficiency reasons). Since I don't
1321 like duplicating code, I will do my penance here, and
1322 describe the code which is duplicated:
1323
1324 *) The assignment to namestring.
1325 *) The call to strchr.
1326 *) The addition of a partial symbol the two partial
1327 symbol lists. This last is a large section of code, so
1328 I've imbedded it in the following macro. */
1329
1330 switch (nlist.n_type)
1331 {
1332 /*
1333 * Standard, external, non-debugger, symbols
1334 */
1335
1336 case N_TEXT | N_EXT:
1337 case N_NBTEXT | N_EXT:
1338 nlist.n_value += ANOFFSET (objfile->section_offsets,
1339 SECT_OFF_TEXT (objfile));
1340 goto record_it;
1341
1342 case N_DATA | N_EXT:
1343 case N_NBDATA | N_EXT:
1344 nlist.n_value += ANOFFSET (objfile->section_offsets,
1345 SECT_OFF_DATA (objfile));
1346 goto record_it;
1347
1348 case N_BSS:
1349 case N_BSS | N_EXT:
1350 case N_NBBSS | N_EXT:
1351 case N_SETV | N_EXT: /* FIXME, is this in BSS? */
1352 nlist.n_value += ANOFFSET (objfile->section_offsets,
1353 SECT_OFF_BSS (objfile));
1354 goto record_it;
1355
1356 case N_ABS | N_EXT:
1357 record_it:
1358 namestring = set_namestring (objfile, &nlist);
1359
1360 record_minimal_symbol (namestring, nlist.n_value,
1361 nlist.n_type, objfile); /* Always */
1362 continue;
1363
1364 /* Standard, local, non-debugger, symbols. */
1365
1366 case N_NBTEXT:
1367
1368 /* We need to be able to deal with both N_FN or N_TEXT,
1369 because we have no way of knowing whether the sys-supplied ld
1370 or GNU ld was used to make the executable. Sequents throw
1371 in another wrinkle -- they renumbered N_FN. */
1372
1373 case N_FN:
1374 case N_FN_SEQ:
1375 case N_TEXT:
1376 nlist.n_value += ANOFFSET (objfile->section_offsets,
1377 SECT_OFF_TEXT (objfile));
1378 namestring = set_namestring (objfile, &nlist);
1379
1380 if ((namestring[0] == '-' && namestring[1] == 'l')
1381 || (namestring[(nsl = strlen (namestring)) - 1] == 'o'
1382 && namestring[nsl - 2] == '.'))
1383 {
1384 if (past_first_source_file && pst
1385 /* The gould NP1 uses low values for .o and -l symbols
1386 which are not the address. */
1387 && nlist.n_value >= pst->textlow)
1388 {
1389 end_psymtab (objfile, pst, psymtab_include_list,
1390 includes_used, symnum * symbol_size,
1391 nlist.n_value > pst->texthigh
1392 ? nlist.n_value : pst->texthigh,
1393 dependency_list, dependencies_used,
1394 textlow_not_set);
1395 pst = (struct partial_symtab *) 0;
1396 includes_used = 0;
1397 dependencies_used = 0;
1398 has_line_numbers = 0;
1399 }
1400 else
1401 past_first_source_file = 1;
1402 last_o_file_start = nlist.n_value;
1403 }
1404 else
1405 goto record_it;
1406 continue;
1407
1408 case N_DATA:
1409 nlist.n_value += ANOFFSET (objfile->section_offsets,
1410 SECT_OFF_DATA (objfile));
1411 goto record_it;
1412
1413 case N_UNDF | N_EXT:
1414 /* The case (nlist.n_value != 0) is a "Fortran COMMON" symbol.
1415 We used to rely on the target to tell us whether it knows
1416 where the symbol has been relocated to, but none of the
1417 target implementations actually provided that operation.
1418 So we just ignore the symbol, the same way we would do if
1419 we had a target-side symbol lookup which returned no match.
1420
1421 All other symbols (with nlist.n_value == 0), are really
1422 undefined, and so we ignore them too. */
1423 continue;
1424
1425 case N_UNDF:
1426 if (processing_acc_compilation && nlist.n_strx == 1)
1427 {
1428 /* Deal with relative offsets in the string table
1429 used in ELF+STAB under Solaris. If we want to use the
1430 n_strx field, which contains the name of the file,
1431 we must adjust file_string_table_offset *before* calling
1432 set_namestring(). */
1433 past_first_source_file = 1;
1434 file_string_table_offset = next_file_string_table_offset;
1435 next_file_string_table_offset =
1436 file_string_table_offset + nlist.n_value;
1437 if (next_file_string_table_offset < file_string_table_offset)
1438 error (_("string table offset backs up at %d"), symnum);
1439 /* FIXME -- replace error() with complaint. */
1440 continue;
1441 }
1442 continue;
1443
1444 /* Lots of symbol types we can just ignore. */
1445
1446 case N_ABS:
1447 case N_NBDATA:
1448 case N_NBBSS:
1449 continue;
1450
1451 /* Keep going . . . */
1452
1453 /*
1454 * Special symbol types for GNU
1455 */
1456 case N_INDR:
1457 case N_INDR | N_EXT:
1458 case N_SETA:
1459 case N_SETA | N_EXT:
1460 case N_SETT:
1461 case N_SETT | N_EXT:
1462 case N_SETD:
1463 case N_SETD | N_EXT:
1464 case N_SETB:
1465 case N_SETB | N_EXT:
1466 case N_SETV:
1467 continue;
1468
1469 /*
1470 * Debugger symbols
1471 */
1472
1473 case N_SO:
1474 {
1475 CORE_ADDR valu;
1476 static int prev_so_symnum = -10;
1477 static int first_so_symnum;
1478 const char *p;
1479 static char *dirname_nso;
1480 int prev_textlow_not_set;
1481
1482 valu = nlist.n_value + ANOFFSET (objfile->section_offsets,
1483 SECT_OFF_TEXT (objfile));
1484
1485 prev_textlow_not_set = textlow_not_set;
1486
1487 /* A zero value is probably an indication for the SunPRO 3.0
1488 compiler. end_psymtab explicitly tests for zero, so
1489 don't relocate it. */
1490
1491 if (nlist.n_value == 0
1492 && gdbarch_sofun_address_maybe_missing (gdbarch))
1493 {
1494 textlow_not_set = 1;
1495 valu = 0;
1496 }
1497 else
1498 textlow_not_set = 0;
1499
1500 past_first_source_file = 1;
1501
1502 if (prev_so_symnum != symnum - 1)
1503 { /* Here if prev stab wasn't N_SO. */
1504 first_so_symnum = symnum;
1505
1506 if (pst)
1507 {
1508 end_psymtab (objfile, pst, psymtab_include_list,
1509 includes_used, symnum * symbol_size,
1510 valu > pst->texthigh ? valu : pst->texthigh,
1511 dependency_list, dependencies_used,
1512 prev_textlow_not_set);
1513 pst = (struct partial_symtab *) 0;
1514 includes_used = 0;
1515 dependencies_used = 0;
1516 has_line_numbers = 0;
1517 }
1518 }
1519
1520 prev_so_symnum = symnum;
1521
1522 /* End the current partial symtab and start a new one. */
1523
1524 namestring = set_namestring (objfile, &nlist);
1525
1526 /* Null name means end of .o file. Don't start a new one. */
1527 if (*namestring == '\000')
1528 continue;
1529
1530 /* Some compilers (including gcc) emit a pair of initial N_SOs.
1531 The first one is a directory name; the second the file name.
1532 If pst exists, is empty, and has a filename ending in '/',
1533 we assume the previous N_SO was a directory name. */
1534
1535 p = lbasename (namestring);
1536 if (p != namestring && *p == '\000')
1537 {
1538 /* Save the directory name SOs locally, then save it into
1539 the psymtab when it's created below. */
1540 dirname_nso = namestring;
1541 continue;
1542 }
1543
1544 /* Some other compilers (C++ ones in particular) emit useless
1545 SOs for non-existant .c files. We ignore all subsequent SOs
1546 that immediately follow the first. */
1547
1548 if (!pst)
1549 {
1550 pst = start_psymtab (objfile,
1551 namestring, valu,
1552 first_so_symnum * symbol_size,
1553 objfile->global_psymbols.next,
1554 objfile->static_psymbols.next);
1555 pst->dirname = dirname_nso;
1556 dirname_nso = NULL;
1557 }
1558 continue;
1559 }
1560
1561 case N_BINCL:
1562 {
1563 enum language tmp_language;
1564
1565 /* Add this bincl to the bincl_list for future EXCLs. No
1566 need to save the string; it'll be around until
1567 read_dbx_symtab function returns. */
1568
1569 namestring = set_namestring (objfile, &nlist);
1570 tmp_language = deduce_language_from_filename (namestring);
1571
1572 /* Only change the psymtab's language if we've learned
1573 something useful (eg. tmp_language is not language_unknown).
1574 In addition, to match what start_subfile does, never change
1575 from C++ to C. */
1576 if (tmp_language != language_unknown
1577 && (tmp_language != language_c
1578 || psymtab_language != language_cplus))
1579 psymtab_language = tmp_language;
1580
1581 if (pst == NULL)
1582 {
1583 /* FIXME: we should not get here without a PST to work on.
1584 Attempt to recover. */
1585 complaint (&symfile_complaints,
1586 _("N_BINCL %s not in entries for "
1587 "any file, at symtab pos %d"),
1588 namestring, symnum);
1589 continue;
1590 }
1591 add_bincl_to_list (pst, namestring, nlist.n_value);
1592
1593 /* Mark down an include file in the current psymtab. */
1594
1595 goto record_include_file;
1596 }
1597
1598 case N_SOL:
1599 {
1600 enum language tmp_language;
1601
1602 /* Mark down an include file in the current psymtab. */
1603 namestring = set_namestring (objfile, &nlist);
1604 tmp_language = deduce_language_from_filename (namestring);
1605
1606 /* Only change the psymtab's language if we've learned
1607 something useful (eg. tmp_language is not language_unknown).
1608 In addition, to match what start_subfile does, never change
1609 from C++ to C. */
1610 if (tmp_language != language_unknown
1611 && (tmp_language != language_c
1612 || psymtab_language != language_cplus))
1613 psymtab_language = tmp_language;
1614
1615 /* In C++, one may expect the same filename to come round many
1616 times, when code is coming alternately from the main file
1617 and from inline functions in other files. So I check to see
1618 if this is a file we've seen before -- either the main
1619 source file, or a previously included file.
1620
1621 This seems to be a lot of time to be spending on N_SOL, but
1622 things like "break c-exp.y:435" need to work (I
1623 suppose the psymtab_include_list could be hashed or put
1624 in a binary tree, if profiling shows this is a major hog). */
1625 if (pst && filename_cmp (namestring, pst->filename) == 0)
1626 continue;
1627 {
1628 int i;
1629
1630 for (i = 0; i < includes_used; i++)
1631 if (filename_cmp (namestring, psymtab_include_list[i]) == 0)
1632 {
1633 i = -1;
1634 break;
1635 }
1636 if (i == -1)
1637 continue;
1638 }
1639
1640 record_include_file:
1641
1642 psymtab_include_list[includes_used++] = namestring;
1643 if (includes_used >= includes_allocated)
1644 {
1645 const char **orig = psymtab_include_list;
1646
1647 psymtab_include_list = (const char **)
1648 alloca ((includes_allocated *= 2) * sizeof (const char *));
1649 memcpy (psymtab_include_list, orig,
1650 includes_used * sizeof (const char *));
1651 }
1652 continue;
1653 }
1654 case N_LSYM: /* Typedef or automatic variable. */
1655 case N_STSYM: /* Data seg var -- static. */
1656 case N_LCSYM: /* BSS " */
1657 case N_ROSYM: /* Read-only data seg var -- static. */
1658 case N_NBSTS: /* Gould nobase. */
1659 case N_NBLCS: /* symbols. */
1660 case N_FUN:
1661 case N_GSYM: /* Global (extern) variable; can be
1662 data or bss (sigh FIXME). */
1663
1664 /* Following may probably be ignored; I'll leave them here
1665 for now (until I do Pascal and Modula 2 extensions). */
1666
1667 case N_PC: /* I may or may not need this; I
1668 suspect not. */
1669 case N_M2C: /* I suspect that I can ignore this here. */
1670 case N_SCOPE: /* Same. */
1671 {
1672 char *p;
1673
1674 namestring = set_namestring (objfile, &nlist);
1675
1676 /* See if this is an end of function stab. */
1677 if (pst && nlist.n_type == N_FUN && *namestring == '\000')
1678 {
1679 CORE_ADDR valu;
1680
1681 /* It's value is the size (in bytes) of the function for
1682 function relative stabs, or the address of the function's
1683 end for old style stabs. */
1684 valu = nlist.n_value + last_function_start;
1685 if (pst->texthigh == 0 || valu > pst->texthigh)
1686 pst->texthigh = valu;
1687 break;
1688 }
1689
1690 p = (char *) strchr (namestring, ':');
1691 if (!p)
1692 continue; /* Not a debugging symbol. */
1693
1694 sym_len = 0;
1695 sym_name = NULL; /* pacify "gcc -Werror" */
1696 if (psymtab_language == language_cplus)
1697 {
1698 char *new_name, *name = xmalloc (p - namestring + 1);
1699 memcpy (name, namestring, p - namestring);
1700
1701 name[p - namestring] = '\0';
1702 new_name = cp_canonicalize_string (name);
1703 if (new_name != NULL)
1704 {
1705 sym_len = strlen (new_name);
1706 sym_name = obstack_copy0 (&objfile->objfile_obstack,
1707 new_name, sym_len);
1708 xfree (new_name);
1709 }
1710 xfree (name);
1711 }
1712
1713 if (sym_len == 0)
1714 {
1715 sym_name = namestring;
1716 sym_len = p - namestring;
1717 }
1718
1719 /* Main processing section for debugging symbols which
1720 the initial read through the symbol tables needs to worry
1721 about. If we reach this point, the symbol which we are
1722 considering is definitely one we are interested in.
1723 p must also contain the (valid) index into the namestring
1724 which indicates the debugging type symbol. */
1725
1726 switch (p[1])
1727 {
1728 case 'S':
1729 nlist.n_value += ANOFFSET (objfile->section_offsets,
1730 data_sect_index);
1731
1732 if (gdbarch_static_transform_name_p (gdbarch))
1733 gdbarch_static_transform_name (gdbarch, namestring);
1734
1735 add_psymbol_to_list (sym_name, sym_len, 1,
1736 VAR_DOMAIN, LOC_STATIC,
1737 &objfile->static_psymbols,
1738 0, nlist.n_value,
1739 psymtab_language, objfile);
1740 continue;
1741
1742 case 'G':
1743 nlist.n_value += ANOFFSET (objfile->section_offsets,
1744 data_sect_index);
1745 /* The addresses in these entries are reported to be
1746 wrong. See the code that reads 'G's for symtabs. */
1747 add_psymbol_to_list (sym_name, sym_len, 1,
1748 VAR_DOMAIN, LOC_STATIC,
1749 &objfile->global_psymbols,
1750 0, nlist.n_value,
1751 psymtab_language, objfile);
1752 continue;
1753
1754 case 'T':
1755 /* When a 'T' entry is defining an anonymous enum, it
1756 may have a name which is the empty string, or a
1757 single space. Since they're not really defining a
1758 symbol, those shouldn't go in the partial symbol
1759 table. We do pick up the elements of such enums at
1760 'check_enum:', below. */
1761 if (p >= namestring + 2
1762 || (p == namestring + 1
1763 && namestring[0] != ' '))
1764 {
1765 add_psymbol_to_list (sym_name, sym_len, 1,
1766 STRUCT_DOMAIN, LOC_TYPEDEF,
1767 &objfile->static_psymbols,
1768 nlist.n_value, 0,
1769 psymtab_language, objfile);
1770 if (p[2] == 't')
1771 {
1772 /* Also a typedef with the same name. */
1773 add_psymbol_to_list (sym_name, sym_len, 1,
1774 VAR_DOMAIN, LOC_TYPEDEF,
1775 &objfile->static_psymbols,
1776 nlist.n_value, 0,
1777 psymtab_language, objfile);
1778 p += 1;
1779 }
1780 }
1781 goto check_enum;
1782
1783 case 't':
1784 if (p != namestring) /* a name is there, not just :T... */
1785 {
1786 add_psymbol_to_list (sym_name, sym_len, 1,
1787 VAR_DOMAIN, LOC_TYPEDEF,
1788 &objfile->static_psymbols,
1789 nlist.n_value, 0,
1790 psymtab_language, objfile);
1791 }
1792 check_enum:
1793 /* If this is an enumerated type, we need to
1794 add all the enum constants to the partial symbol
1795 table. This does not cover enums without names, e.g.
1796 "enum {a, b} c;" in C, but fortunately those are
1797 rare. There is no way for GDB to find those from the
1798 enum type without spending too much time on it. Thus
1799 to solve this problem, the compiler needs to put out the
1800 enum in a nameless type. GCC2 does this. */
1801
1802 /* We are looking for something of the form
1803 <name> ":" ("t" | "T") [<number> "="] "e"
1804 {<constant> ":" <value> ","} ";". */
1805
1806 /* Skip over the colon and the 't' or 'T'. */
1807 p += 2;
1808 /* This type may be given a number. Also, numbers can come
1809 in pairs like (0,26). Skip over it. */
1810 while ((*p >= '0' && *p <= '9')
1811 || *p == '(' || *p == ',' || *p == ')'
1812 || *p == '=')
1813 p++;
1814
1815 if (*p++ == 'e')
1816 {
1817 /* The aix4 compiler emits extra crud before the members. */
1818 if (*p == '-')
1819 {
1820 /* Skip over the type (?). */
1821 while (*p != ':')
1822 p++;
1823
1824 /* Skip over the colon. */
1825 p++;
1826 }
1827
1828 /* We have found an enumerated type. */
1829 /* According to comments in read_enum_type
1830 a comma could end it instead of a semicolon.
1831 I don't know where that happens.
1832 Accept either. */
1833 while (*p && *p != ';' && *p != ',')
1834 {
1835 char *q;
1836
1837 /* Check for and handle cretinous dbx symbol name
1838 continuation! */
1839 if (*p == '\\' || (*p == '?' && p[1] == '\0'))
1840 p = next_symbol_text (objfile);
1841
1842 /* Point to the character after the name
1843 of the enum constant. */
1844 for (q = p; *q && *q != ':'; q++)
1845 ;
1846 /* Note that the value doesn't matter for
1847 enum constants in psymtabs, just in symtabs. */
1848 add_psymbol_to_list (p, q - p, 1,
1849 VAR_DOMAIN, LOC_CONST,
1850 &objfile->static_psymbols, 0,
1851 0, psymtab_language, objfile);
1852 /* Point past the name. */
1853 p = q;
1854 /* Skip over the value. */
1855 while (*p && *p != ',')
1856 p++;
1857 /* Advance past the comma. */
1858 if (*p)
1859 p++;
1860 }
1861 }
1862 continue;
1863
1864 case 'c':
1865 /* Constant, e.g. from "const" in Pascal. */
1866 add_psymbol_to_list (sym_name, sym_len, 1,
1867 VAR_DOMAIN, LOC_CONST,
1868 &objfile->static_psymbols, nlist.n_value,
1869 0, psymtab_language, objfile);
1870 continue;
1871
1872 case 'f':
1873 if (! pst)
1874 {
1875 int name_len = p - namestring;
1876 char *name = xmalloc (name_len + 1);
1877
1878 memcpy (name, namestring, name_len);
1879 name[name_len] = '\0';
1880 function_outside_compilation_unit_complaint (name);
1881 xfree (name);
1882 }
1883 nlist.n_value += ANOFFSET (objfile->section_offsets,
1884 SECT_OFF_TEXT (objfile));
1885 /* Kludges for ELF/STABS with Sun ACC. */
1886 last_function_name = namestring;
1887 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
1888 value for the bottom of the text seg in those cases. */
1889 if (nlist.n_value == ANOFFSET (objfile->section_offsets,
1890 SECT_OFF_TEXT (objfile))
1891 && gdbarch_sofun_address_maybe_missing (gdbarch))
1892 {
1893 CORE_ADDR minsym_valu =
1894 find_stab_function_addr (namestring,
1895 pst ? pst->filename : NULL,
1896 objfile);
1897
1898 /* find_stab_function_addr will return 0 if the minimal
1899 symbol wasn't found. (Unfortunately, this might also
1900 be a valid address.) Anyway, if it *does* return 0,
1901 it is likely that the value was set correctly to begin
1902 with... */
1903 if (minsym_valu != 0)
1904 nlist.n_value = minsym_valu;
1905 }
1906 if (pst && textlow_not_set
1907 && gdbarch_sofun_address_maybe_missing (gdbarch))
1908 {
1909 pst->textlow = nlist.n_value;
1910 textlow_not_set = 0;
1911 }
1912 /* End kludge. */
1913
1914 /* Keep track of the start of the last function so we
1915 can handle end of function symbols. */
1916 last_function_start = nlist.n_value;
1917
1918 /* In reordered executables this function may lie outside
1919 the bounds created by N_SO symbols. If that's the case
1920 use the address of this function as the low bound for
1921 the partial symbol table. */
1922 if (pst
1923 && (textlow_not_set
1924 || (nlist.n_value < pst->textlow
1925 && (nlist.n_value
1926 != ANOFFSET (objfile->section_offsets,
1927 SECT_OFF_TEXT (objfile))))))
1928 {
1929 pst->textlow = nlist.n_value;
1930 textlow_not_set = 0;
1931 }
1932 add_psymbol_to_list (sym_name, sym_len, 1,
1933 VAR_DOMAIN, LOC_BLOCK,
1934 &objfile->static_psymbols,
1935 0, nlist.n_value,
1936 psymtab_language, objfile);
1937 continue;
1938
1939 /* Global functions were ignored here, but now they
1940 are put into the global psymtab like one would expect.
1941 They're also in the minimal symbol table. */
1942 case 'F':
1943 if (! pst)
1944 {
1945 int name_len = p - namestring;
1946 char *name = xmalloc (name_len + 1);
1947
1948 memcpy (name, namestring, name_len);
1949 name[name_len] = '\0';
1950 function_outside_compilation_unit_complaint (name);
1951 xfree (name);
1952 }
1953 nlist.n_value += ANOFFSET (objfile->section_offsets,
1954 SECT_OFF_TEXT (objfile));
1955 /* Kludges for ELF/STABS with Sun ACC. */
1956 last_function_name = namestring;
1957 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
1958 value for the bottom of the text seg in those cases. */
1959 if (nlist.n_value == ANOFFSET (objfile->section_offsets,
1960 SECT_OFF_TEXT (objfile))
1961 && gdbarch_sofun_address_maybe_missing (gdbarch))
1962 {
1963 CORE_ADDR minsym_valu =
1964 find_stab_function_addr (namestring,
1965 pst ? pst->filename : NULL,
1966 objfile);
1967
1968 /* find_stab_function_addr will return 0 if the minimal
1969 symbol wasn't found. (Unfortunately, this might also
1970 be a valid address.) Anyway, if it *does* return 0,
1971 it is likely that the value was set correctly to begin
1972 with... */
1973 if (minsym_valu != 0)
1974 nlist.n_value = minsym_valu;
1975 }
1976 if (pst && textlow_not_set
1977 && gdbarch_sofun_address_maybe_missing (gdbarch))
1978 {
1979 pst->textlow = nlist.n_value;
1980 textlow_not_set = 0;
1981 }
1982 /* End kludge. */
1983
1984 /* Keep track of the start of the last function so we
1985 can handle end of function symbols. */
1986 last_function_start = nlist.n_value;
1987
1988 /* In reordered executables this function may lie outside
1989 the bounds created by N_SO symbols. If that's the case
1990 use the address of this function as the low bound for
1991 the partial symbol table. */
1992 if (pst
1993 && (textlow_not_set
1994 || (nlist.n_value < pst->textlow
1995 && (nlist.n_value
1996 != ANOFFSET (objfile->section_offsets,
1997 SECT_OFF_TEXT (objfile))))))
1998 {
1999 pst->textlow = nlist.n_value;
2000 textlow_not_set = 0;
2001 }
2002 add_psymbol_to_list (sym_name, sym_len, 1,
2003 VAR_DOMAIN, LOC_BLOCK,
2004 &objfile->global_psymbols,
2005 0, nlist.n_value,
2006 psymtab_language, objfile);
2007 continue;
2008
2009 /* Two things show up here (hopefully); static symbols of
2010 local scope (static used inside braces) or extensions
2011 of structure symbols. We can ignore both. */
2012 case 'V':
2013 case '(':
2014 case '0':
2015 case '1':
2016 case '2':
2017 case '3':
2018 case '4':
2019 case '5':
2020 case '6':
2021 case '7':
2022 case '8':
2023 case '9':
2024 case '-':
2025 case '#': /* For symbol identification (used in live ranges). */
2026 continue;
2027
2028 case ':':
2029 /* It is a C++ nested symbol. We don't need to record it
2030 (I don't think); if we try to look up foo::bar::baz,
2031 then symbols for the symtab containing foo should get
2032 read in, I think. */
2033 /* Someone says sun cc puts out symbols like
2034 /foo/baz/maclib::/usr/local/bin/maclib,
2035 which would get here with a symbol type of ':'. */
2036 continue;
2037
2038 default:
2039 /* Unexpected symbol descriptor. The second and subsequent stabs
2040 of a continued stab can show up here. The question is
2041 whether they ever can mimic a normal stab--it would be
2042 nice if not, since we certainly don't want to spend the
2043 time searching to the end of every string looking for
2044 a backslash. */
2045
2046 complaint (&symfile_complaints,
2047 _("unknown symbol descriptor `%c'"),
2048 p[1]);
2049
2050 /* Ignore it; perhaps it is an extension that we don't
2051 know about. */
2052 continue;
2053 }
2054 }
2055
2056 case N_EXCL:
2057
2058 namestring = set_namestring (objfile, &nlist);
2059
2060 /* Find the corresponding bincl and mark that psymtab on the
2061 psymtab dependency list. */
2062 {
2063 struct partial_symtab *needed_pst =
2064 find_corresponding_bincl_psymtab (namestring, nlist.n_value);
2065
2066 /* If this include file was defined earlier in this file,
2067 leave it alone. */
2068 if (needed_pst == pst)
2069 continue;
2070
2071 if (needed_pst)
2072 {
2073 int i;
2074 int found = 0;
2075
2076 for (i = 0; i < dependencies_used; i++)
2077 if (dependency_list[i] == needed_pst)
2078 {
2079 found = 1;
2080 break;
2081 }
2082
2083 /* If it's already in the list, skip the rest. */
2084 if (found)
2085 continue;
2086
2087 dependency_list[dependencies_used++] = needed_pst;
2088 if (dependencies_used >= dependencies_allocated)
2089 {
2090 struct partial_symtab **orig = dependency_list;
2091
2092 dependency_list =
2093 (struct partial_symtab **)
2094 alloca ((dependencies_allocated *= 2)
2095 * sizeof (struct partial_symtab *));
2096 memcpy (dependency_list, orig,
2097 (dependencies_used
2098 * sizeof (struct partial_symtab *)));
2099 #ifdef DEBUG_INFO
2100 fprintf_unfiltered (gdb_stderr,
2101 "Had to reallocate "
2102 "dependency list.\n");
2103 fprintf_unfiltered (gdb_stderr,
2104 "New dependencies allocated: %d\n",
2105 dependencies_allocated);
2106 #endif
2107 }
2108 }
2109 }
2110 continue;
2111
2112 case N_ENDM:
2113 /* Solaris 2 end of module, finish current partial symbol table.
2114 end_psymtab will set pst->texthigh to the proper value, which
2115 is necessary if a module compiled without debugging info
2116 follows this module. */
2117 if (pst && gdbarch_sofun_address_maybe_missing (gdbarch))
2118 {
2119 end_psymtab (objfile, pst, psymtab_include_list, includes_used,
2120 symnum * symbol_size,
2121 (CORE_ADDR) 0, dependency_list,
2122 dependencies_used, textlow_not_set);
2123 pst = (struct partial_symtab *) 0;
2124 includes_used = 0;
2125 dependencies_used = 0;
2126 has_line_numbers = 0;
2127 }
2128 continue;
2129
2130 case N_RBRAC:
2131 #ifdef HANDLE_RBRAC
2132 HANDLE_RBRAC (nlist.n_value);
2133 continue;
2134 #endif
2135 case N_EINCL:
2136 case N_DSLINE:
2137 case N_BSLINE:
2138 case N_SSYM: /* Claim: Structure or union element.
2139 Hopefully, I can ignore this. */
2140 case N_ENTRY: /* Alternate entry point; can ignore. */
2141 case N_MAIN: /* Can definitely ignore this. */
2142 case N_CATCH: /* These are GNU C++ extensions */
2143 case N_EHDECL: /* that can safely be ignored here. */
2144 case N_LENG:
2145 case N_BCOMM:
2146 case N_ECOMM:
2147 case N_ECOML:
2148 case N_FNAME:
2149 case N_SLINE:
2150 case N_RSYM:
2151 case N_PSYM:
2152 case N_LBRAC:
2153 case N_NSYMS: /* Ultrix 4.0: symbol count */
2154 case N_DEFD: /* GNU Modula-2 */
2155 case N_ALIAS: /* SunPro F77: alias name, ignore for now. */
2156
2157 case N_OBJ: /* Useless types from Solaris. */
2158 case N_OPT:
2159 case N_PATCH:
2160 /* These symbols aren't interesting; don't worry about them. */
2161 continue;
2162
2163 default:
2164 /* If we haven't found it yet, ignore it. It's probably some
2165 new type we don't know about yet. */
2166 unknown_symtype_complaint (hex_string (nlist.n_type));
2167 continue;
2168 }
2169 }
2170
2171 /* If there's stuff to be cleaned up, clean it up. */
2172 if (pst)
2173 {
2174 /* Don't set pst->texthigh lower than it already is. */
2175 CORE_ADDR text_end =
2176 (lowest_text_address == (CORE_ADDR) -1
2177 ? (text_addr + ANOFFSET (objfile->section_offsets,
2178 SECT_OFF_TEXT (objfile)))
2179 : lowest_text_address)
2180 + text_size;
2181
2182 end_psymtab (objfile, pst, psymtab_include_list, includes_used,
2183 symnum * symbol_size,
2184 text_end > pst->texthigh ? text_end : pst->texthigh,
2185 dependency_list, dependencies_used, textlow_not_set);
2186 }
2187
2188 do_cleanups (back_to);
2189 }
2190
2191 /* Allocate and partially fill a partial symtab. It will be
2192 completely filled at the end of the symbol list.
2193
2194 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
2195 is the address relative to which its symbols are (incremental) or 0
2196 (normal). */
2197
2198 static struct partial_symtab *
2199 start_psymtab (struct objfile *objfile, char *filename, CORE_ADDR textlow,
2200 int ldsymoff, struct partial_symbol **global_syms,
2201 struct partial_symbol **static_syms)
2202 {
2203 struct partial_symtab *result =
2204 start_psymtab_common (objfile, objfile->section_offsets,
2205 filename, textlow, global_syms, static_syms);
2206
2207 result->read_symtab_private = obstack_alloc (&objfile->objfile_obstack,
2208 sizeof (struct symloc));
2209 LDSYMOFF (result) = ldsymoff;
2210 result->read_symtab = dbx_read_symtab;
2211 SYMBOL_SIZE (result) = symbol_size;
2212 SYMBOL_OFFSET (result) = symbol_table_offset;
2213 STRING_OFFSET (result) = string_table_offset;
2214 FILE_STRING_OFFSET (result) = file_string_table_offset;
2215
2216 #ifdef HAVE_ELF
2217 /* If we're handling an ELF file, drag some section-relocation info
2218 for this source file out of the ELF symbol table, to compensate for
2219 Sun brain death. This replaces the section_offsets in this psymtab,
2220 if successful. */
2221 elfstab_offset_sections (objfile, result);
2222 #endif
2223
2224 /* Deduce the source language from the filename for this psymtab. */
2225 psymtab_language = deduce_language_from_filename (filename);
2226
2227 return result;
2228 }
2229
2230 /* Close off the current usage of PST.
2231 Returns PST or NULL if the partial symtab was empty and thrown away.
2232
2233 FIXME: List variables and peculiarities of same. */
2234
2235 struct partial_symtab *
2236 end_psymtab (struct objfile *objfile, struct partial_symtab *pst,
2237 const char **include_list, int num_includes,
2238 int capping_symbol_offset, CORE_ADDR capping_text,
2239 struct partial_symtab **dependency_list, int number_dependencies,
2240 int textlow_not_set)
2241 {
2242 int i;
2243 struct gdbarch *gdbarch = get_objfile_arch (objfile);
2244
2245 if (capping_symbol_offset != -1)
2246 LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
2247 pst->texthigh = capping_text;
2248
2249 /* Under Solaris, the N_SO symbols always have a value of 0,
2250 instead of the usual address of the .o file. Therefore,
2251 we have to do some tricks to fill in texthigh and textlow.
2252 The first trick is: if we see a static
2253 or global function, and the textlow for the current pst
2254 is not set (ie: textlow_not_set), then we use that function's
2255 address for the textlow of the pst. */
2256
2257 /* Now, to fill in texthigh, we remember the last function seen
2258 in the .o file. Also, there's a hack in
2259 bfd/elf.c and gdb/elfread.c to pass the ELF st_size field
2260 to here via the misc_info field. Therefore, we can fill in
2261 a reliable texthigh by taking the address plus size of the
2262 last function in the file. */
2263
2264 if (pst->texthigh == 0 && last_function_name
2265 && gdbarch_sofun_address_maybe_missing (gdbarch))
2266 {
2267 char *p;
2268 int n;
2269 struct minimal_symbol *minsym;
2270
2271 p = strchr (last_function_name, ':');
2272 if (p == NULL)
2273 p = last_function_name;
2274 n = p - last_function_name;
2275 p = alloca (n + 2);
2276 strncpy (p, last_function_name, n);
2277 p[n] = 0;
2278
2279 minsym = lookup_minimal_symbol (p, pst->filename, objfile);
2280 if (minsym == NULL)
2281 {
2282 /* Sun Fortran appends an underscore to the minimal symbol name,
2283 try again with an appended underscore if the minimal symbol
2284 was not found. */
2285 p[n] = '_';
2286 p[n + 1] = 0;
2287 minsym = lookup_minimal_symbol (p, pst->filename, objfile);
2288 }
2289
2290 if (minsym)
2291 pst->texthigh = SYMBOL_VALUE_ADDRESS (minsym) + MSYMBOL_SIZE (minsym);
2292
2293 last_function_name = NULL;
2294 }
2295
2296 if (!gdbarch_sofun_address_maybe_missing (gdbarch))
2297 ;
2298 /* This test will be true if the last .o file is only data. */
2299 else if (textlow_not_set)
2300 pst->textlow = pst->texthigh;
2301 else
2302 {
2303 struct partial_symtab *p1;
2304
2305 /* If we know our own starting text address, then walk through all other
2306 psymtabs for this objfile, and if any didn't know their ending text
2307 address, set it to our starting address. Take care to not set our
2308 own ending address to our starting address, nor to set addresses on
2309 `dependency' files that have both textlow and texthigh zero. */
2310
2311 ALL_OBJFILE_PSYMTABS (objfile, p1)
2312 {
2313 if (p1->texthigh == 0 && p1->textlow != 0 && p1 != pst)
2314 {
2315 p1->texthigh = pst->textlow;
2316 /* If this file has only data, then make textlow match
2317 texthigh. */
2318 if (p1->textlow == 0)
2319 p1->textlow = p1->texthigh;
2320 }
2321 }
2322 }
2323
2324 /* End of kludge for patching Solaris textlow and texthigh. */
2325
2326 pst->n_global_syms =
2327 objfile->global_psymbols.next - (objfile->global_psymbols.list
2328 + pst->globals_offset);
2329 pst->n_static_syms =
2330 objfile->static_psymbols.next - (objfile->static_psymbols.list
2331 + pst->statics_offset);
2332
2333 pst->number_of_dependencies = number_dependencies;
2334 if (number_dependencies)
2335 {
2336 pst->dependencies = (struct partial_symtab **)
2337 obstack_alloc (&objfile->objfile_obstack,
2338 number_dependencies * sizeof (struct partial_symtab *));
2339 memcpy (pst->dependencies, dependency_list,
2340 number_dependencies * sizeof (struct partial_symtab *));
2341 }
2342 else
2343 pst->dependencies = 0;
2344
2345 for (i = 0; i < num_includes; i++)
2346 {
2347 struct partial_symtab *subpst =
2348 allocate_psymtab (include_list[i], objfile);
2349
2350 /* Copy the sesction_offsets array from the main psymtab. */
2351 subpst->section_offsets = pst->section_offsets;
2352 subpst->read_symtab_private =
2353 obstack_alloc (&objfile->objfile_obstack, sizeof (struct symloc));
2354 LDSYMOFF (subpst) =
2355 LDSYMLEN (subpst) =
2356 subpst->textlow =
2357 subpst->texthigh = 0;
2358
2359 /* We could save slight bits of space by only making one of these,
2360 shared by the entire set of include files. FIXME-someday. */
2361 subpst->dependencies = (struct partial_symtab **)
2362 obstack_alloc (&objfile->objfile_obstack,
2363 sizeof (struct partial_symtab *));
2364 subpst->dependencies[0] = pst;
2365 subpst->number_of_dependencies = 1;
2366
2367 subpst->globals_offset =
2368 subpst->n_global_syms =
2369 subpst->statics_offset =
2370 subpst->n_static_syms = 0;
2371
2372 subpst->readin = 0;
2373 subpst->symtab = 0;
2374 subpst->read_symtab = pst->read_symtab;
2375 }
2376
2377 sort_pst_symbols (objfile, pst);
2378
2379 if (num_includes == 0
2380 && number_dependencies == 0
2381 && pst->n_global_syms == 0
2382 && pst->n_static_syms == 0
2383 && has_line_numbers == 0)
2384 {
2385 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2386 it is on the obstack, but we can forget to chain it on the list. */
2387 /* Empty psymtabs happen as a result of header files which don't have
2388 any symbols in them. There can be a lot of them. But this check
2389 is wrong, in that a psymtab with N_SLINE entries but nothing else
2390 is not empty, but we don't realize that. Fixing that without slowing
2391 things down might be tricky. */
2392
2393 discard_psymtab (objfile, pst);
2394
2395 /* Indicate that psymtab was thrown away. */
2396 pst = (struct partial_symtab *) NULL;
2397 }
2398 return pst;
2399 }
2400
2401 static void
2403 dbx_psymtab_to_symtab_1 (struct objfile *objfile, struct partial_symtab *pst)
2404 {
2405 struct cleanup *old_chain;
2406 int i;
2407
2408 if (pst->readin)
2409 {
2410 fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in. "
2411 "Shouldn't happen.\n",
2412 pst->filename);
2413 return;
2414 }
2415
2416 /* Read in all partial symtabs on which this one is dependent. */
2417 for (i = 0; i < pst->number_of_dependencies; i++)
2418 if (!pst->dependencies[i]->readin)
2419 {
2420 /* Inform about additional files that need to be read in. */
2421 if (info_verbose)
2422 {
2423 fputs_filtered (" ", gdb_stdout);
2424 wrap_here ("");
2425 fputs_filtered ("and ", gdb_stdout);
2426 wrap_here ("");
2427 printf_filtered ("%s...", pst->dependencies[i]->filename);
2428 wrap_here (""); /* Flush output. */
2429 gdb_flush (gdb_stdout);
2430 }
2431 dbx_psymtab_to_symtab_1 (objfile, pst->dependencies[i]);
2432 }
2433
2434 if (LDSYMLEN (pst)) /* Otherwise it's a dummy. */
2435 {
2436 /* Init stuff necessary for reading in symbols */
2437 stabsread_init ();
2438 buildsym_init ();
2439 old_chain = make_cleanup (really_free_pendings, 0);
2440 file_string_table_offset = FILE_STRING_OFFSET (pst);
2441 symbol_size = SYMBOL_SIZE (pst);
2442
2443 /* Read in this file's symbols. */
2444 bfd_seek (objfile->obfd, SYMBOL_OFFSET (pst), SEEK_SET);
2445 read_ofile_symtab (objfile, pst);
2446
2447 do_cleanups (old_chain);
2448 }
2449
2450 pst->readin = 1;
2451 }
2452
2453 /* Read in all of the symbols for a given psymtab for real.
2454 Be verbose about it if the user wants that. SELF is not NULL. */
2455
2456 static void
2457 dbx_read_symtab (struct partial_symtab *self, struct objfile *objfile)
2458 {
2459 bfd *sym_bfd;
2460
2461 if (self->readin)
2462 {
2463 fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in. "
2464 "Shouldn't happen.\n",
2465 self->filename);
2466 return;
2467 }
2468
2469 if (LDSYMLEN (self) || self->number_of_dependencies)
2470 {
2471 struct cleanup *back_to;
2472
2473 /* Print the message now, before reading the string table,
2474 to avoid disconcerting pauses. */
2475 if (info_verbose)
2476 {
2477 printf_filtered ("Reading in symbols for %s...", self->filename);
2478 gdb_flush (gdb_stdout);
2479 }
2480
2481 sym_bfd = objfile->obfd;
2482
2483 next_symbol_text_func = dbx_next_symbol_text;
2484
2485 back_to = make_cleanup (null_cleanup, NULL);
2486
2487 if (DBX_STAB_SECTION (objfile))
2488 {
2489 stabs_data
2490 = symfile_relocate_debug_section (objfile,
2491 DBX_STAB_SECTION (objfile),
2492 NULL);
2493
2494 if (stabs_data)
2495 make_cleanup (free_current_contents, (void *) &stabs_data);
2496 }
2497
2498 dbx_psymtab_to_symtab_1 (objfile, self);
2499
2500 do_cleanups (back_to);
2501
2502 /* Match with global symbols. This only needs to be done once,
2503 after all of the symtabs and dependencies have been read in. */
2504 scan_file_globals (objfile);
2505
2506 /* Finish up the debug error message. */
2507 if (info_verbose)
2508 printf_filtered ("done.\n");
2509 }
2510 }
2511
2512 /* Read in a defined section of a specific object file's symbols. */
2513
2514 static void
2515 read_ofile_symtab (struct objfile *objfile, struct partial_symtab *pst)
2516 {
2517 char *namestring;
2518 struct external_nlist *bufp;
2519 struct internal_nlist nlist;
2520 unsigned char type;
2521 unsigned max_symnum;
2522 bfd *abfd;
2523 int sym_offset; /* Offset to start of symbols to read */
2524 int sym_size; /* Size of symbols to read */
2525 CORE_ADDR text_offset; /* Start of text segment for symbols */
2526 int text_size; /* Size of text segment for symbols */
2527 struct section_offsets *section_offsets;
2528
2529 sym_offset = LDSYMOFF (pst);
2530 sym_size = LDSYMLEN (pst);
2531 text_offset = pst->textlow;
2532 text_size = pst->texthigh - pst->textlow;
2533 /* This cannot be simply objfile->section_offsets because of
2534 elfstab_offset_sections() which initializes the psymtab section
2535 offsets information in a special way, and that is different from
2536 objfile->section_offsets. */
2537 section_offsets = pst->section_offsets;
2538
2539 dbxread_objfile = objfile;
2540
2541 stringtab_global = DBX_STRINGTAB (objfile);
2542 set_last_source_file (NULL);
2543
2544 abfd = objfile->obfd;
2545 symfile_bfd = objfile->obfd; /* Implicit param to next_text_symbol. */
2546 symbuf_end = symbuf_idx = 0;
2547 symbuf_read = 0;
2548 symbuf_left = sym_offset + sym_size;
2549
2550 /* It is necessary to actually read one symbol *before* the start
2551 of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
2552 occurs before the N_SO symbol.
2553
2554 Detecting this in read_dbx_symtab
2555 would slow down initial readin, so we look for it here instead. */
2556 if (!processing_acc_compilation && sym_offset >= (int) symbol_size)
2557 {
2558 stabs_seek (sym_offset - symbol_size);
2559 fill_symbuf (abfd);
2560 bufp = &symbuf[symbuf_idx++];
2561 INTERNALIZE_SYMBOL (nlist, bufp, abfd);
2562 OBJSTAT (objfile, n_stabs++);
2563
2564 namestring = set_namestring (objfile, &nlist);
2565
2566 processing_gcc_compilation = 0;
2567 if (nlist.n_type == N_TEXT)
2568 {
2569 const char *tempstring = namestring;
2570
2571 if (strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL) == 0)
2572 processing_gcc_compilation = 1;
2573 else if (strcmp (namestring, GCC2_COMPILED_FLAG_SYMBOL) == 0)
2574 processing_gcc_compilation = 2;
2575 if (tempstring[0] == bfd_get_symbol_leading_char (symfile_bfd))
2576 ++tempstring;
2577 if (strncmp (tempstring, "__gnu_compiled", 14) == 0)
2578 processing_gcc_compilation = 2;
2579 }
2580 }
2581 else
2582 {
2583 /* The N_SO starting this symtab is the first symbol, so we
2584 better not check the symbol before it. I'm not this can
2585 happen, but it doesn't hurt to check for it. */
2586 stabs_seek (sym_offset);
2587 processing_gcc_compilation = 0;
2588 }
2589
2590 if (symbuf_idx == symbuf_end)
2591 fill_symbuf (abfd);
2592 bufp = &symbuf[symbuf_idx];
2593 if (bfd_h_get_8 (abfd, bufp->e_type) != N_SO)
2594 error (_("First symbol in segment of executable not a source symbol"));
2595
2596 max_symnum = sym_size / symbol_size;
2597
2598 for (symnum = 0;
2599 symnum < max_symnum;
2600 symnum++)
2601 {
2602 QUIT; /* Allow this to be interruptable. */
2603 if (symbuf_idx == symbuf_end)
2604 fill_symbuf (abfd);
2605 bufp = &symbuf[symbuf_idx++];
2606 INTERNALIZE_SYMBOL (nlist, bufp, abfd);
2607 OBJSTAT (objfile, n_stabs++);
2608
2609 type = bfd_h_get_8 (abfd, bufp->e_type);
2610
2611 namestring = set_namestring (objfile, &nlist);
2612
2613 if (type & N_STAB)
2614 {
2615 if (sizeof (nlist.n_value) > 4
2616 /* We are a 64-bit debugger debugging a 32-bit program. */
2617 && (type == N_LSYM || type == N_PSYM))
2618 /* We have to be careful with the n_value in the case of N_LSYM
2619 and N_PSYM entries, because they are signed offsets from frame
2620 pointer, but we actually read them as unsigned 32-bit values.
2621 This is not a problem for 32-bit debuggers, for which negative
2622 values end up being interpreted correctly (as negative
2623 offsets) due to integer overflow.
2624 But we need to sign-extend the value for 64-bit debuggers,
2625 or we'll end up interpreting negative values as very large
2626 positive offsets. */
2627 nlist.n_value = (nlist.n_value ^ 0x80000000) - 0x80000000;
2628 process_one_symbol (type, nlist.n_desc, nlist.n_value,
2629 namestring, section_offsets, objfile);
2630 }
2631 /* We skip checking for a new .o or -l file; that should never
2632 happen in this routine. */
2633 else if (type == N_TEXT)
2634 {
2635 /* I don't think this code will ever be executed, because
2636 the GCC_COMPILED_FLAG_SYMBOL usually is right before
2637 the N_SO symbol which starts this source file.
2638 However, there is no reason not to accept
2639 the GCC_COMPILED_FLAG_SYMBOL anywhere. */
2640
2641 if (strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL) == 0)
2642 processing_gcc_compilation = 1;
2643 else if (strcmp (namestring, GCC2_COMPILED_FLAG_SYMBOL) == 0)
2644 processing_gcc_compilation = 2;
2645 }
2646 else if (type & N_EXT || type == (unsigned char) N_TEXT
2647 || type == (unsigned char) N_NBTEXT)
2648 {
2649 /* Global symbol: see if we came across a dbx defintion for
2650 a corresponding symbol. If so, store the value. Remove
2651 syms from the chain when their values are stored, but
2652 search the whole chain, as there may be several syms from
2653 different files with the same name. */
2654 /* This is probably not true. Since the files will be read
2655 in one at a time, each reference to a global symbol will
2656 be satisfied in each file as it appears. So we skip this
2657 section. */
2658 ;
2659 }
2660 }
2661
2662 /* In a Solaris elf file, this variable, which comes from the
2663 value of the N_SO symbol, will still be 0. Luckily, text_offset,
2664 which comes from pst->textlow is correct. */
2665 if (last_source_start_addr == 0)
2666 last_source_start_addr = text_offset;
2667
2668 /* In reordered executables last_source_start_addr may not be the
2669 lower bound for this symtab, instead use text_offset which comes
2670 from pst->textlow which is correct. */
2671 if (last_source_start_addr > text_offset)
2672 last_source_start_addr = text_offset;
2673
2674 pst->symtab = end_symtab (text_offset + text_size, objfile,
2675 SECT_OFF_TEXT (objfile));
2676
2677 end_stabs ();
2678
2679 dbxread_objfile = NULL;
2680 }
2681
2682
2684 /* Record the namespace that the function defined by SYMBOL was
2685 defined in, if necessary. BLOCK is the associated block; use
2686 OBSTACK for allocation. */
2687
2688 static void
2689 cp_set_block_scope (const struct symbol *symbol,
2690 struct block *block,
2691 struct obstack *obstack)
2692 {
2693 if (SYMBOL_DEMANGLED_NAME (symbol) != NULL)
2694 {
2695 /* Try to figure out the appropriate namespace from the
2696 demangled name. */
2697
2698 /* FIXME: carlton/2003-04-15: If the function in question is
2699 a method of a class, the name will actually include the
2700 name of the class as well. This should be harmless, but
2701 is a little unfortunate. */
2702
2703 const char *name = SYMBOL_DEMANGLED_NAME (symbol);
2704 unsigned int prefix_len = cp_entire_prefix_len (name);
2705
2706 block_set_scope (block,
2707 obstack_copy0 (obstack, name, prefix_len),
2708 obstack);
2709 }
2710 }
2711
2712 /* This handles a single symbol from the symbol-file, building symbols
2713 into a GDB symtab. It takes these arguments and an implicit argument.
2714
2715 TYPE is the type field of the ".stab" symbol entry.
2716 DESC is the desc field of the ".stab" entry.
2717 VALU is the value field of the ".stab" entry.
2718 NAME is the symbol name, in our address space.
2719 SECTION_OFFSETS is a set of amounts by which the sections of this
2720 object file were relocated when it was loaded into memory. Note
2721 that these section_offsets are not the objfile->section_offsets but
2722 the pst->section_offsets. All symbols that refer to memory
2723 locations need to be offset by these amounts.
2724 OBJFILE is the object file from which we are reading symbols. It
2725 is used in end_symtab. */
2726
2727 void
2728 process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
2729 const struct section_offsets *section_offsets,
2730 struct objfile *objfile)
2731 {
2732 struct gdbarch *gdbarch = get_objfile_arch (objfile);
2733 struct context_stack *new;
2734 /* This remembers the address of the start of a function. It is
2735 used because in Solaris 2, N_LBRAC, N_RBRAC, and N_SLINE entries
2736 are relative to the current function's start address. On systems
2737 other than Solaris 2, this just holds the SECT_OFF_TEXT value,
2738 and is used to relocate these symbol types rather than
2739 SECTION_OFFSETS. */
2740 static CORE_ADDR function_start_offset;
2741
2742 /* This holds the address of the start of a function, without the
2743 system peculiarities of function_start_offset. */
2744 static CORE_ADDR last_function_start;
2745
2746 /* If this is nonzero, we've seen an N_SLINE since the start of the
2747 current function. We use this to tell us to move the first sline
2748 to the beginning of the function regardless of what its given
2749 value is. */
2750 static int sline_found_in_function = 1;
2751
2752 /* If this is nonzero, we've seen a non-gcc N_OPT symbol for this
2753 source file. Used to detect the SunPRO solaris compiler. */
2754 static int n_opt_found;
2755
2756 /* The stab type used for the definition of the last function.
2757 N_STSYM or N_GSYM for SunOS4 acc; N_FUN for other compilers. */
2758 static int function_stab_type = 0;
2759
2760 if (!block_address_function_relative)
2761 {
2762 /* N_LBRAC, N_RBRAC and N_SLINE entries are not relative to the
2763 function start address, so just use the text offset. */
2764 function_start_offset =
2765 ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
2766 }
2767
2768 /* Something is wrong if we see real data before seeing a source
2769 file name. */
2770
2771 if (get_last_source_file () == NULL && type != (unsigned char) N_SO)
2772 {
2773 /* Ignore any symbols which appear before an N_SO symbol.
2774 Currently no one puts symbols there, but we should deal
2775 gracefully with the case. A complain()t might be in order,
2776 but this should not be an error (). */
2777 return;
2778 }
2779
2780 switch (type)
2781 {
2782 case N_FUN:
2783 case N_FNAME:
2784
2785 if (*name == '\000')
2786 {
2787 /* This N_FUN marks the end of a function. This closes off
2788 the current block. */
2789 struct block *block;
2790
2791 if (context_stack_depth <= 0)
2792 {
2793 lbrac_mismatch_complaint (symnum);
2794 break;
2795 }
2796
2797 /* The following check is added before recording line 0 at
2798 end of function so as to handle hand-generated stabs
2799 which may have an N_FUN stabs at the end of the function,
2800 but no N_SLINE stabs. */
2801 if (sline_found_in_function)
2802 {
2803 CORE_ADDR addr = last_function_start + valu;
2804
2805 record_line (current_subfile, 0,
2806 gdbarch_addr_bits_remove (gdbarch, addr));
2807 }
2808
2809 within_function = 0;
2810 new = pop_context ();
2811
2812 /* Make a block for the local symbols within. */
2813 block = finish_block (new->name, &local_symbols, new->old_blocks,
2814 new->start_addr, new->start_addr + valu,
2815 objfile);
2816
2817 /* For C++, set the block's scope. */
2818 if (SYMBOL_LANGUAGE (new->name) == language_cplus)
2819 cp_set_block_scope (new->name, block, &objfile->objfile_obstack);
2820
2821 /* May be switching to an assembler file which may not be using
2822 block relative stabs, so reset the offset. */
2823 if (block_address_function_relative)
2824 function_start_offset = 0;
2825
2826 break;
2827 }
2828
2829 sline_found_in_function = 0;
2830
2831 /* Relocate for dynamic loading. */
2832 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
2833 valu = gdbarch_addr_bits_remove (gdbarch, valu);
2834 last_function_start = valu;
2835
2836 goto define_a_symbol;
2837
2838 case N_LBRAC:
2839 /* This "symbol" just indicates the start of an inner lexical
2840 context within a function. */
2841
2842 /* Ignore extra outermost context from SunPRO cc and acc. */
2843 if (n_opt_found && desc == 1)
2844 break;
2845
2846 if (block_address_function_relative)
2847 /* Relocate for Sun ELF acc fn-relative syms. */
2848 valu += function_start_offset;
2849 else
2850 /* On most machines, the block addresses are relative to the
2851 N_SO, the linker did not relocate them (sigh). */
2852 valu += last_source_start_addr;
2853
2854 push_context (desc, valu);
2855 break;
2856
2857 case N_RBRAC:
2858 /* This "symbol" just indicates the end of an inner lexical
2859 context that was started with N_LBRAC. */
2860
2861 /* Ignore extra outermost context from SunPRO cc and acc. */
2862 if (n_opt_found && desc == 1)
2863 break;
2864
2865 if (block_address_function_relative)
2866 /* Relocate for Sun ELF acc fn-relative syms. */
2867 valu += function_start_offset;
2868 else
2869 /* On most machines, the block addresses are relative to the
2870 N_SO, the linker did not relocate them (sigh). */
2871 valu += last_source_start_addr;
2872
2873 if (context_stack_depth <= 0)
2874 {
2875 lbrac_mismatch_complaint (symnum);
2876 break;
2877 }
2878
2879 new = pop_context ();
2880 if (desc != new->depth)
2881 lbrac_mismatch_complaint (symnum);
2882
2883 if (local_symbols != NULL)
2884 {
2885 /* GCC development snapshots from March to December of
2886 2000 would output N_LSYM entries after N_LBRAC
2887 entries. As a consequence, these symbols are simply
2888 discarded. Complain if this is the case. */
2889 complaint (&symfile_complaints,
2890 _("misplaced N_LBRAC entry; discarding local "
2891 "symbols which have no enclosing block"));
2892 }
2893 local_symbols = new->locals;
2894
2895 if (context_stack_depth > 1)
2896 {
2897 /* This is not the outermost LBRAC...RBRAC pair in the
2898 function, its local symbols preceded it, and are the ones
2899 just recovered from the context stack. Define the block
2900 for them (but don't bother if the block contains no
2901 symbols. Should we complain on blocks without symbols?
2902 I can't think of any useful purpose for them). */
2903 if (local_symbols != NULL)
2904 {
2905 /* Muzzle a compiler bug that makes end < start.
2906
2907 ??? Which compilers? Is this ever harmful?. */
2908 if (new->start_addr > valu)
2909 {
2910 complaint (&symfile_complaints,
2911 _("block start larger than block end"));
2912 new->start_addr = valu;
2913 }
2914 /* Make a block for the local symbols within. */
2915 finish_block (0, &local_symbols, new->old_blocks,
2916 new->start_addr, valu, objfile);
2917 }
2918 }
2919 else
2920 {
2921 /* This is the outermost LBRAC...RBRAC pair. There is no
2922 need to do anything; leave the symbols that preceded it
2923 to be attached to the function's own block. We need to
2924 indicate that we just moved outside of the function. */
2925 within_function = 0;
2926 }
2927
2928 break;
2929
2930 case N_FN:
2931 case N_FN_SEQ:
2932 /* This kind of symbol indicates the start of an object file.
2933 Relocate for dynamic loading. */
2934 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
2935 break;
2936
2937 case N_SO:
2938 /* This type of symbol indicates the start of data for one
2939 source file. Finish the symbol table of the previous source
2940 file (if any) and start accumulating a new symbol table.
2941 Relocate for dynamic loading. */
2942 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
2943
2944 n_opt_found = 0;
2945
2946 if (get_last_source_file ())
2947 {
2948 /* Check if previous symbol was also an N_SO (with some
2949 sanity checks). If so, that one was actually the
2950 directory name, and the current one is the real file
2951 name. Patch things up. */
2952 if (previous_stab_code == (unsigned char) N_SO)
2953 {
2954 patch_subfile_names (current_subfile, name);
2955 break; /* Ignore repeated SOs. */
2956 }
2957 end_symtab (valu, objfile, SECT_OFF_TEXT (objfile));
2958 end_stabs ();
2959 }
2960
2961 /* Null name means this just marks the end of text for this .o
2962 file. Don't start a new symtab in this case. */
2963 if (*name == '\000')
2964 break;
2965
2966 if (block_address_function_relative)
2967 function_start_offset = 0;
2968
2969 start_stabs ();
2970 start_symtab (name, NULL, valu);
2971 record_debugformat ("stabs");
2972 break;
2973
2974 case N_SOL:
2975 /* This type of symbol indicates the start of data for a
2976 sub-source-file, one whose contents were copied or included
2977 in the compilation of the main source file (whose name was
2978 given in the N_SO symbol). Relocate for dynamic loading. */
2979 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
2980 start_subfile (name, current_subfile->dirname);
2981 break;
2982
2983 case N_BINCL:
2984 push_subfile ();
2985 add_new_header_file (name, valu);
2986 start_subfile (name, current_subfile->dirname);
2987 break;
2988
2989 case N_EINCL:
2990 start_subfile (pop_subfile (), current_subfile->dirname);
2991 break;
2992
2993 case N_EXCL:
2994 add_old_header_file (name, valu);
2995 break;
2996
2997 case N_SLINE:
2998 /* This type of "symbol" really just records one line-number --
2999 core-address correspondence. Enter it in the line list for
3000 this symbol table. */
3001
3002 /* Relocate for dynamic loading and for ELF acc
3003 function-relative symbols. */
3004 valu += function_start_offset;
3005
3006 /* GCC 2.95.3 emits the first N_SLINE stab somwehere in the
3007 middle of the prologue instead of right at the start of the
3008 function. To deal with this we record the address for the
3009 first N_SLINE stab to be the start of the function instead of
3010 the listed location. We really shouldn't to this. When
3011 compiling with optimization, this first N_SLINE stab might be
3012 optimized away. Other (non-GCC) compilers don't emit this
3013 stab at all. There is no real harm in having an extra
3014 numbered line, although it can be a bit annoying for the
3015 user. However, it totally screws up our testsuite.
3016
3017 So for now, keep adjusting the address of the first N_SLINE
3018 stab, but only for code compiled with GCC. */
3019
3020 if (within_function && sline_found_in_function == 0)
3021 {
3022 CORE_ADDR addr = processing_gcc_compilation == 2 ?
3023 last_function_start : valu;
3024
3025 record_line (current_subfile, desc,
3026 gdbarch_addr_bits_remove (gdbarch, addr));
3027 sline_found_in_function = 1;
3028 }
3029 else
3030 record_line (current_subfile, desc,
3031 gdbarch_addr_bits_remove (gdbarch, valu));
3032 break;
3033
3034 case N_BCOMM:
3035 common_block_start (name, objfile);
3036 break;
3037
3038 case N_ECOMM:
3039 common_block_end (objfile);
3040 break;
3041
3042 /* The following symbol types need to have the appropriate
3043 offset added to their value; then we process symbol
3044 definitions in the name. */
3045
3046 case N_STSYM: /* Static symbol in data segment. */
3047 case N_LCSYM: /* Static symbol in BSS segment. */
3048 case N_ROSYM: /* Static symbol in read-only data segment. */
3049 /* HORRID HACK DEPT. However, it's Sun's furgin' fault.
3050 Solaris 2's stabs-in-elf makes *most* symbols relative but
3051 leaves a few absolute (at least for Solaris 2.1 and version
3052 2.0.1 of the SunPRO compiler). N_STSYM and friends sit on
3053 the fence. .stab "foo:S...",N_STSYM is absolute (ld
3054 relocates it) .stab "foo:V...",N_STSYM is relative (section
3055 base subtracted). This leaves us no choice but to search for
3056 the 'S' or 'V'... (or pass the whole section_offsets stuff
3057 down ONE MORE function call level, which we really don't want
3058 to do). */
3059 {
3060 char *p;
3061
3062 /* Normal object file and NLMs have non-zero text seg offsets,
3063 but don't need their static syms offset in this fashion.
3064 XXX - This is really a crock that should be fixed in the
3065 solib handling code so that I don't have to work around it
3066 here. */
3067
3068 if (!symfile_relocatable)
3069 {
3070 p = strchr (name, ':');
3071 if (p != 0 && p[1] == 'S')
3072 {
3073 /* The linker relocated it. We don't want to add an
3074 elfstab_offset_sections-type offset, but we *do*
3075 want to add whatever solib.c passed to
3076 symbol_file_add as addr (this is known to affect
3077 SunOS 4, and I suspect ELF too). Since
3078 elfstab_offset_sections currently does not muck
3079 with the text offset (there is no Ttext.text
3080 symbol), we can get addr from the text offset. If
3081 elfstab_offset_sections ever starts dealing with
3082 the text offset, and we still need to do this, we
3083 need to invent a SECT_OFF_ADDR_KLUDGE or something. */
3084 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
3085 goto define_a_symbol;
3086 }
3087 }
3088 /* Since it's not the kludge case, re-dispatch to the right
3089 handler. */
3090 switch (type)
3091 {
3092 case N_STSYM:
3093 goto case_N_STSYM;
3094 case N_LCSYM:
3095 goto case_N_LCSYM;
3096 case N_ROSYM:
3097 goto case_N_ROSYM;
3098 default:
3099 internal_error (__FILE__, __LINE__,
3100 _("failed internal consistency check"));
3101 }
3102 }
3103
3104 case_N_STSYM: /* Static symbol in data segment. */
3105 case N_DSLINE: /* Source line number, data segment. */
3106 valu += ANOFFSET (section_offsets, SECT_OFF_DATA (objfile));
3107 goto define_a_symbol;
3108
3109 case_N_LCSYM: /* Static symbol in BSS segment. */
3110 case N_BSLINE: /* Source line number, BSS segment. */
3111 /* N_BROWS: overlaps with N_BSLINE. */
3112 valu += ANOFFSET (section_offsets, SECT_OFF_BSS (objfile));
3113 goto define_a_symbol;
3114
3115 case_N_ROSYM: /* Static symbol in read-only data segment. */
3116 valu += ANOFFSET (section_offsets, SECT_OFF_RODATA (objfile));
3117 goto define_a_symbol;
3118
3119 case N_ENTRY: /* Alternate entry point. */
3120 /* Relocate for dynamic loading. */
3121 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
3122 goto define_a_symbol;
3123
3124 /* The following symbol types we don't know how to process.
3125 Handle them in a "default" way, but complain to people who
3126 care. */
3127 default:
3128 case N_CATCH: /* Exception handler catcher. */
3129 case N_EHDECL: /* Exception handler name. */
3130 case N_PC: /* Global symbol in Pascal. */
3131 case N_M2C: /* Modula-2 compilation unit. */
3132 /* N_MOD2: overlaps with N_EHDECL. */
3133 case N_SCOPE: /* Modula-2 scope information. */
3134 case N_ECOML: /* End common (local name). */
3135 case N_NBTEXT: /* Gould Non-Base-Register symbols??? */
3136 case N_NBDATA:
3137 case N_NBBSS:
3138 case N_NBSTS:
3139 case N_NBLCS:
3140 unknown_symtype_complaint (hex_string (type));
3141 /* FALLTHROUGH */
3142
3143 /* The following symbol types don't need the address field
3144 relocated, since it is either unused, or is absolute. */
3145 define_a_symbol:
3146 case N_GSYM: /* Global variable. */
3147 case N_NSYMS: /* Number of symbols (Ultrix). */
3148 case N_NOMAP: /* No map? (Ultrix). */
3149 case N_RSYM: /* Register variable. */
3150 case N_DEFD: /* Modula-2 GNU module dependency. */
3151 case N_SSYM: /* Struct or union element. */
3152 case N_LSYM: /* Local symbol in stack. */
3153 case N_PSYM: /* Parameter variable. */
3154 case N_LENG: /* Length of preceding symbol type. */
3155 if (name)
3156 {
3157 int deftype;
3158 char *colon_pos = strchr (name, ':');
3159
3160 if (colon_pos == NULL)
3161 deftype = '\0';
3162 else
3163 deftype = colon_pos[1];
3164
3165 switch (deftype)
3166 {
3167 case 'f':
3168 case 'F':
3169 function_stab_type = type;
3170
3171 /* Deal with the SunPRO 3.0 compiler which omits the
3172 address from N_FUN symbols. */
3173 if (type == N_FUN
3174 && valu == ANOFFSET (section_offsets,
3175 SECT_OFF_TEXT (objfile))
3176 && gdbarch_sofun_address_maybe_missing (gdbarch))
3177 {
3178 CORE_ADDR minsym_valu =
3179 find_stab_function_addr (name, get_last_source_file (),
3180 objfile);
3181
3182 /* The function find_stab_function_addr will return
3183 0 if the minimal symbol wasn't found.
3184 (Unfortunately, this might also be a valid
3185 address.) Anyway, if it *does* return 0, it is
3186 likely that the value was set correctly to begin
3187 with... */
3188 if (minsym_valu != 0)
3189 valu = minsym_valu;
3190 }
3191
3192 if (block_address_function_relative)
3193 /* For Solaris 2 compilers, the block addresses and
3194 N_SLINE's are relative to the start of the
3195 function. On normal systems, and when using GCC on
3196 Solaris 2, these addresses are just absolute, or
3197 relative to the N_SO, depending on
3198 BLOCK_ADDRESS_ABSOLUTE. */
3199 function_start_offset = valu;
3200
3201 within_function = 1;
3202
3203 if (context_stack_depth > 1)
3204 {
3205 complaint (&symfile_complaints,
3206 _("unmatched N_LBRAC before symtab pos %d"),
3207 symnum);
3208 break;
3209 }
3210
3211 if (context_stack_depth > 0)
3212 {
3213 struct block *block;
3214
3215 new = pop_context ();
3216 /* Make a block for the local symbols within. */
3217 block = finish_block (new->name, &local_symbols,
3218 new->old_blocks, new->start_addr,
3219 valu, objfile);
3220
3221 /* For C++, set the block's scope. */
3222 if (SYMBOL_LANGUAGE (new->name) == language_cplus)
3223 cp_set_block_scope (new->name, block,
3224 &objfile->objfile_obstack);
3225 }
3226
3227 new = push_context (0, valu);
3228 new->name = define_symbol (valu, name, desc, type, objfile);
3229 break;
3230
3231 default:
3232 define_symbol (valu, name, desc, type, objfile);
3233 break;
3234 }
3235 }
3236 break;
3237
3238 /* We use N_OPT to carry the gcc2_compiled flag. Sun uses it
3239 for a bunch of other flags, too. Someday we may parse their
3240 flags; for now we ignore theirs and hope they'll ignore ours. */
3241 case N_OPT: /* Solaris 2: Compiler options. */
3242 if (name)
3243 {
3244 if (strcmp (name, GCC2_COMPILED_FLAG_SYMBOL) == 0)
3245 {
3246 processing_gcc_compilation = 2;
3247 }
3248 else
3249 n_opt_found = 1;
3250 }
3251 break;
3252
3253 case N_MAIN: /* Name of main routine. */
3254 /* FIXME: If one has a symbol file with N_MAIN and then replaces
3255 it with a symbol file with "main" and without N_MAIN. I'm
3256 not sure exactly what rule to follow but probably something
3257 like: N_MAIN takes precedence over "main" no matter what
3258 objfile it is in; If there is more than one N_MAIN, choose
3259 the one in the symfile_objfile; If there is more than one
3260 N_MAIN within a given objfile, complain() and choose
3261 arbitrarily. (kingdon) */
3262 if (name != NULL)
3263 set_main_name (name);
3264 break;
3265
3266 /* The following symbol types can be ignored. */
3267 case N_OBJ: /* Solaris 2: Object file dir and name. */
3268 case N_PATCH: /* Solaris 2: Patch Run Time Checker. */
3269 /* N_UNDF: Solaris 2: File separator mark. */
3270 /* N_UNDF: -- we will never encounter it, since we only process
3271 one file's symbols at once. */
3272 case N_ENDM: /* Solaris 2: End of module. */
3273 case N_ALIAS: /* SunPro F77: alias name, ignore for now. */
3274 break;
3275 }
3276
3277 /* '#' is a GNU C extension to allow one symbol to refer to another
3278 related symbol.
3279
3280 Generally this is used so that an alias can refer to its main
3281 symbol. */
3282 gdb_assert (name);
3283 if (name[0] == '#')
3284 {
3285 /* Initialize symbol reference names and determine if this is a
3286 definition. If a symbol reference is being defined, go ahead
3287 and add it. Otherwise, just return. */
3288
3289 char *s = name;
3290 int refnum;
3291
3292 /* If this stab defines a new reference ID that is not on the
3293 reference list, then put it on the reference list.
3294
3295 We go ahead and advance NAME past the reference, even though
3296 it is not strictly necessary at this time. */
3297 refnum = symbol_reference_defined (&s);
3298 if (refnum >= 0)
3299 if (!ref_search (refnum))
3300 ref_add (refnum, 0, name, valu);
3301 name = s;
3302 }
3303
3304 previous_stab_code = type;
3305 }
3306
3307 /* FIXME: The only difference between this and elfstab_build_psymtabs
3309 is the call to install_minimal_symbols for elf, and the support for
3310 split sections. If the differences are really that small, the code
3311 should be shared. */
3312
3313 /* Scan and build partial symbols for an coff symbol file.
3314 The coff file has already been processed to get its minimal symbols.
3315
3316 This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
3317 rolled into one.
3318
3319 OBJFILE is the object file we are reading symbols from.
3320 ADDR is the address relative to which the symbols are (e.g.
3321 the base address of the text segment).
3322 TEXTADDR is the address of the text section.
3323 TEXTSIZE is the size of the text section.
3324 STABSECTS is the list of .stab sections in OBJFILE.
3325 STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the
3326 .stabstr section exists.
3327
3328 This routine is mostly copied from dbx_symfile_init and dbx_symfile_read,
3329 adjusted for coff details. */
3330
3331 void
3332 coffstab_build_psymtabs (struct objfile *objfile,
3333 CORE_ADDR textaddr, unsigned int textsize,
3334 struct stab_section_list *stabsects,
3335 file_ptr stabstroffset, unsigned int stabstrsize)
3336 {
3337 int val;
3338 bfd *sym_bfd = objfile->obfd;
3339 char *name = bfd_get_filename (sym_bfd);
3340 struct dbx_symfile_info *info;
3341 unsigned int stabsize;
3342
3343 /* There is already a dbx_symfile_info allocated by our caller.
3344 It might even contain some info from the coff symtab to help us. */
3345 info = DBX_SYMFILE_INFO (objfile);
3346
3347 DBX_TEXT_ADDR (objfile) = textaddr;
3348 DBX_TEXT_SIZE (objfile) = textsize;
3349
3350 #define COFF_STABS_SYMBOL_SIZE 12 /* XXX FIXME XXX */
3351 DBX_SYMBOL_SIZE (objfile) = COFF_STABS_SYMBOL_SIZE;
3352 DBX_STRINGTAB_SIZE (objfile) = stabstrsize;
3353
3354 if (stabstrsize > bfd_get_size (sym_bfd))
3355 error (_("ridiculous string table size: %d bytes"), stabstrsize);
3356 DBX_STRINGTAB (objfile) = (char *)
3357 obstack_alloc (&objfile->objfile_obstack, stabstrsize + 1);
3358 OBJSTAT (objfile, sz_strtab += stabstrsize + 1);
3359
3360 /* Now read in the string table in one big gulp. */
3361
3362 val = bfd_seek (sym_bfd, stabstroffset, SEEK_SET);
3363 if (val < 0)
3364 perror_with_name (name);
3365 val = bfd_bread (DBX_STRINGTAB (objfile), stabstrsize, sym_bfd);
3366 if (val != stabstrsize)
3367 perror_with_name (name);
3368
3369 stabsread_new_init ();
3370 buildsym_new_init ();
3371 free_header_files ();
3372 init_header_files ();
3373
3374 processing_acc_compilation = 1;
3375
3376 /* In a coff file, we've already installed the minimal symbols that came
3377 from the coff (non-stab) symbol table, so always act like an
3378 incremental load here. */
3379 if (stabsects->next == NULL)
3380 {
3381 stabsize = bfd_section_size (sym_bfd, stabsects->section);
3382 DBX_SYMCOUNT (objfile) = stabsize / DBX_SYMBOL_SIZE (objfile);
3383 DBX_SYMTAB_OFFSET (objfile) = stabsects->section->filepos;
3384 }
3385 else
3386 {
3387 struct stab_section_list *stabsect;
3388
3389 DBX_SYMCOUNT (objfile) = 0;
3390 for (stabsect = stabsects; stabsect != NULL; stabsect = stabsect->next)
3391 {
3392 stabsize = bfd_section_size (sym_bfd, stabsect->section);
3393 DBX_SYMCOUNT (objfile) += stabsize / DBX_SYMBOL_SIZE (objfile);
3394 }
3395
3396 DBX_SYMTAB_OFFSET (objfile) = stabsects->section->filepos;
3397
3398 symbuf_sections = stabsects->next;
3399 symbuf_left = bfd_section_size (sym_bfd, stabsects->section);
3400 symbuf_read = 0;
3401 }
3402
3403 dbx_symfile_read (objfile, 0);
3404 }
3405
3406 /* Scan and build partial symbols for an ELF symbol file.
3408 This ELF file has already been processed to get its minimal symbols.
3409
3410 This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
3411 rolled into one.
3412
3413 OBJFILE is the object file we are reading symbols from.
3414 ADDR is the address relative to which the symbols are (e.g.
3415 the base address of the text segment).
3416 STABSECT is the BFD section information for the .stab section.
3417 STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the
3418 .stabstr section exists.
3419
3420 This routine is mostly copied from dbx_symfile_init and dbx_symfile_read,
3421 adjusted for elf details. */
3422
3423 void
3424 elfstab_build_psymtabs (struct objfile *objfile, asection *stabsect,
3425 file_ptr stabstroffset, unsigned int stabstrsize)
3426 {
3427 int val;
3428 bfd *sym_bfd = objfile->obfd;
3429 char *name = bfd_get_filename (sym_bfd);
3430 struct dbx_symfile_info *info;
3431 struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
3432
3433 /* There is already a dbx_symfile_info allocated by our caller.
3434 It might even contain some info from the ELF symtab to help us. */
3435 info = DBX_SYMFILE_INFO (objfile);
3436
3437 /* Find the first and last text address. dbx_symfile_read seems to
3438 want this. */
3439 find_text_range (sym_bfd, objfile);
3440
3441 #define ELF_STABS_SYMBOL_SIZE 12 /* XXX FIXME XXX */
3442 DBX_SYMBOL_SIZE (objfile) = ELF_STABS_SYMBOL_SIZE;
3443 DBX_SYMCOUNT (objfile)
3444 = bfd_section_size (objfile->obfd, stabsect) / DBX_SYMBOL_SIZE (objfile);
3445 DBX_STRINGTAB_SIZE (objfile) = stabstrsize;
3446 DBX_SYMTAB_OFFSET (objfile) = stabsect->filepos;
3447 DBX_STAB_SECTION (objfile) = stabsect;
3448
3449 if (stabstrsize > bfd_get_size (sym_bfd))
3450 error (_("ridiculous string table size: %d bytes"), stabstrsize);
3451 DBX_STRINGTAB (objfile) = (char *)
3452 obstack_alloc (&objfile->objfile_obstack, stabstrsize + 1);
3453 OBJSTAT (objfile, sz_strtab += stabstrsize + 1);
3454
3455 /* Now read in the string table in one big gulp. */
3456
3457 val = bfd_seek (sym_bfd, stabstroffset, SEEK_SET);
3458 if (val < 0)
3459 perror_with_name (name);
3460 val = bfd_bread (DBX_STRINGTAB (objfile), stabstrsize, sym_bfd);
3461 if (val != stabstrsize)
3462 perror_with_name (name);
3463
3464 stabsread_new_init ();
3465 buildsym_new_init ();
3466 free_header_files ();
3467 init_header_files ();
3468
3469 processing_acc_compilation = 1;
3470
3471 symbuf_read = 0;
3472 symbuf_left = bfd_section_size (objfile->obfd, stabsect);
3473 stabs_data = symfile_relocate_debug_section (objfile, stabsect, NULL);
3474 if (stabs_data)
3475 make_cleanup (free_current_contents, (void *) &stabs_data);
3476
3477 /* In an elf file, we've already installed the minimal symbols that came
3478 from the elf (non-stab) symbol table, so always act like an
3479 incremental load here. dbx_symfile_read should not generate any new
3480 minimal symbols, since we will have already read the ELF dynamic symbol
3481 table and normal symbol entries won't be in the ".stab" section; but in
3482 case it does, it will install them itself. */
3483 dbx_symfile_read (objfile, 0);
3484
3485 do_cleanups (back_to);
3486 }
3487
3488 /* Scan and build partial symbols for a file with special sections for stabs
3490 and stabstrings. The file has already been processed to get its minimal
3491 symbols, and any other symbols that might be necessary to resolve GSYMs.
3492
3493 This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
3494 rolled into one.
3495
3496 OBJFILE is the object file we are reading symbols from.
3497 ADDR is the address relative to which the symbols are (e.g. the base address
3498 of the text segment).
3499 STAB_NAME is the name of the section that contains the stabs.
3500 STABSTR_NAME is the name of the section that contains the stab strings.
3501
3502 This routine is mostly copied from dbx_symfile_init and
3503 dbx_symfile_read. */
3504
3505 void
3506 stabsect_build_psymtabs (struct objfile *objfile, char *stab_name,
3507 char *stabstr_name, char *text_name)
3508 {
3509 int val;
3510 bfd *sym_bfd = objfile->obfd;
3511 char *name = bfd_get_filename (sym_bfd);
3512 asection *stabsect;
3513 asection *stabstrsect;
3514 asection *text_sect;
3515 struct dbx_symfile_info *dbx;
3516
3517 stabsect = bfd_get_section_by_name (sym_bfd, stab_name);
3518 stabstrsect = bfd_get_section_by_name (sym_bfd, stabstr_name);
3519
3520 if (!stabsect)
3521 return;
3522
3523 if (!stabstrsect)
3524 error (_("stabsect_build_psymtabs: Found stabs (%s), "
3525 "but not string section (%s)"),
3526 stab_name, stabstr_name);
3527
3528 dbx = XCNEW (struct dbx_symfile_info);
3529 set_objfile_data (objfile, dbx_objfile_data_key, dbx);
3530
3531 text_sect = bfd_get_section_by_name (sym_bfd, text_name);
3532 if (!text_sect)
3533 error (_("Can't find %s section in symbol file"), text_name);
3534 DBX_TEXT_ADDR (objfile) = bfd_section_vma (sym_bfd, text_sect);
3535 DBX_TEXT_SIZE (objfile) = bfd_section_size (sym_bfd, text_sect);
3536
3537 DBX_SYMBOL_SIZE (objfile) = sizeof (struct external_nlist);
3538 DBX_SYMCOUNT (objfile) = bfd_section_size (sym_bfd, stabsect)
3539 / DBX_SYMBOL_SIZE (objfile);
3540 DBX_STRINGTAB_SIZE (objfile) = bfd_section_size (sym_bfd, stabstrsect);
3541 DBX_SYMTAB_OFFSET (objfile) = stabsect->filepos; /* XXX - FIXME: POKING
3542 INSIDE BFD DATA
3543 STRUCTURES */
3544
3545 if (DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd))
3546 error (_("ridiculous string table size: %d bytes"),
3547 DBX_STRINGTAB_SIZE (objfile));
3548 DBX_STRINGTAB (objfile) = (char *)
3549 obstack_alloc (&objfile->objfile_obstack,
3550 DBX_STRINGTAB_SIZE (objfile) + 1);
3551 OBJSTAT (objfile, sz_strtab += DBX_STRINGTAB_SIZE (objfile) + 1);
3552
3553 /* Now read in the string table in one big gulp. */
3554
3555 val = bfd_get_section_contents (sym_bfd, /* bfd */
3556 stabstrsect, /* bfd section */
3557 DBX_STRINGTAB (objfile), /* input buffer */
3558 0, /* offset into section */
3559 DBX_STRINGTAB_SIZE (objfile)); /* amount to
3560 read */
3561
3562 if (!val)
3563 perror_with_name (name);
3564
3565 stabsread_new_init ();
3566 buildsym_new_init ();
3567 free_header_files ();
3568 init_header_files ();
3569
3570 /* Now, do an incremental load. */
3571
3572 processing_acc_compilation = 1;
3573 dbx_symfile_read (objfile, 0);
3574 }
3575
3576 static const struct sym_fns aout_sym_fns =
3578 {
3579 dbx_new_init, /* init anything gbl to entire symtab */
3580 dbx_symfile_init, /* read initial info, setup for sym_read() */
3581 dbx_symfile_read, /* read a symbol file into symtab */
3582 NULL, /* sym_read_psymbols */
3583 dbx_symfile_finish, /* finished with file, cleanup */
3584 default_symfile_offsets, /* parse user's offsets to internal form */
3585 default_symfile_segments, /* Get segment information from a file. */
3586 NULL,
3587 default_symfile_relocate, /* Relocate a debug section. */
3588 NULL, /* sym_probe_fns */
3589 &psym_functions
3590 };
3591
3592 void
3593 _initialize_dbxread (void)
3594 {
3595 add_symtab_fns (bfd_target_aout_flavour, &aout_sym_fns);
3596
3597 dbx_objfile_data_key
3598 = register_objfile_data_with_cleanup (NULL, dbx_free_symfile_info);
3599 }
3600