OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [gdb-5.3/] [gdb/] [dbxread.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.