Various fixes to improve g++ debugging. See ChangeLog.
[deliverable/binutils-gdb.git] / gdb / dbxread.c
CommitLineData
bd5635a1
RP
1/* Read dbx symbol tables and convert to internal format, for GDB.
2 Copyright (C) 1986-1991 Free Software Foundation, Inc.
3
4This file is part of GDB.
5
c3a21801 6This program is free software; you can redistribute it and/or modify
bd5635a1 7it under the terms of the GNU General Public License as published by
c3a21801
JG
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
bd5635a1 10
c3a21801 11This program is distributed in the hope that it will be useful,
bd5635a1
RP
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
c3a21801
JG
17along with this program; if not, write to the Free Software
18Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
9404978d
MT
19
20/* This module provides three functions: dbx_symfile_init,
21 which initializes to read a symbol file; dbx_new_init, which
22 discards existing cached information when all symbols are being
23 discarded; and dbx_symfile_read, which reads a symbol table
24 from a file.
25
26 dbx_symfile_read only does the minimum work necessary for letting the
27 user "name" things symbolically; it does not read the entire symtab.
28 Instead, it reads the external and static symbols and puts them in partial
29 symbol tables. When more extensive information is requested of a
30 file, the corresponding partial symbol table is mutated into a full
31 fledged symbol table by going back and reading the symbols
32 for real. dbx_psymtab_to_symtab() is the function that does this */
bd5635a1 33
bd5635a1
RP
34#include <stdio.h>
35#include <string.h>
36#include "defs.h"
37#include "param.h"
38
39#ifdef USG
40#include <sys/types.h>
41#include <fcntl.h>
42#define L_SET 0
43#define L_INCR 1
44#endif
45
afe4ca15
JG
46#include <obstack.h>
47#include <sys/param.h>
48#include <sys/file.h>
49#include <sys/stat.h>
bd5635a1 50#include <ctype.h>
afe4ca15
JG
51#include "symtab.h"
52#include "breakpoint.h"
53#include "command.h"
54#include "target.h"
55#include "gdbcore.h" /* for bfd stuff */
56#include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
57#include "symfile.h"
58
59#include "aout64.h"
60#include "stab.gnu.h" /* We always use GNU stabs, not native, now */
bd5635a1
RP
61
62#ifndef NO_GNU_STABS
63/*
64 * Define specifically gnu symbols here.
65 */
66
67/* The following type indicates the definition of a symbol as being
68 an indirect reference to another symbol. The other symbol
69 appears as an undefined reference, immediately following this symbol.
70
71 Indirection is asymmetrical. The other symbol's value will be used
72 to satisfy requests for the indirect symbol, but not vice versa.
73 If the other symbol does not have a definition, libraries will
74 be searched to find a definition. */
75#ifndef N_INDR
76#define N_INDR 0xa
77#endif
78
79/* The following symbols refer to set elements.
80 All the N_SET[ATDB] symbols with the same name form one set.
81 Space is allocated for the set in the text section, and each set
82 element's value is stored into one word of the space.
83 The first word of the space is the length of the set (number of elements).
84
85 The address of the set is made into an N_SETV symbol
86 whose name is the same as the name of the set.
87 This symbol acts like a N_DATA global symbol
88 in that it can satisfy undefined external references. */
89
90#ifndef N_SETA
91#define N_SETA 0x14 /* Absolute set element symbol */
92#endif /* This is input to LD, in a .o file. */
93
94#ifndef N_SETT
95#define N_SETT 0x16 /* Text set element symbol */
96#endif /* This is input to LD, in a .o file. */
97
98#ifndef N_SETD
99#define N_SETD 0x18 /* Data set element symbol */
100#endif /* This is input to LD, in a .o file. */
101
102#ifndef N_SETB
103#define N_SETB 0x1A /* Bss set element symbol */
104#endif /* This is input to LD, in a .o file. */
105
106/* Macros dealing with the set element symbols defined in a.out.h */
107#define SET_ELEMENT_P(x) ((x)>=N_SETA&&(x)<=(N_SETB|N_EXT))
108#define TYPE_OF_SET_ELEMENT(x) ((x)-N_SETA+N_ABS)
109
110#ifndef N_SETV
111#define N_SETV 0x1C /* Pointer to set vector in data area. */
112#endif /* This is output from LD. */
113
114#ifndef N_WARNING
115#define N_WARNING 0x1E /* Warning message to print if file included */
116#endif /* This is input to ld */
117
118#endif /* NO_GNU_STABS */
119
bd5635a1
RP
120struct dbx_symfile_info {
121 asection *text_sect; /* Text section accessor */
122 int symcount; /* How many symbols are there in the file */
123 char *stringtab; /* The actual string table */
124 int stringtab_size; /* Its size */
125 off_t symtab_offset; /* Offset in file to symbol table */
126 int desc; /* File descriptor of symbol file */
127};
128
4a35d6e9
FF
129/* Each partial symbol table entry contains a pointer to private data for the
130 read_symtab() function to use when expanding a partial symbol table entry
131 to a full symbol table entry.
132
133 For dbxread this structure contains the offset within the file symbol table
134 of first local symbol for this file, and length (in bytes) of the section
135 of the symbol table devoted to this file's symbols (actually, the section
136 bracketed may contain more than just this file's symbols). If ldsymlen is
137 0, the only reason for this thing's existence is the dependency list.
138 Nothing else will happen when it is read in. */
139
140#define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
141#define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
142
143struct symloc {
144 int ldsymoff;
145 int ldsymlen;
146};
147
bd5635a1
RP
148extern void qsort ();
149extern double atof ();
150extern struct cmd_list_element *cmdlist;
151
152extern void symbol_file_command ();
153
154/* Forward declarations */
155
156static void add_symbol_to_list ();
157static void read_dbx_symtab ();
158static void init_psymbol_list ();
159static void process_one_symbol ();
160static struct type *read_type ();
161static struct type *read_range_type ();
162static struct type *read_enum_type ();
163static struct type *read_struct_type ();
164static struct type *read_array_type ();
165static long read_number ();
166static void finish_block ();
167static struct blockvector *make_blockvector ();
168static struct symbol *define_symbol ();
169static void start_subfile ();
170static int hashname ();
171static struct pending *copy_pending ();
172static void fix_common_block ();
173static void add_undefined_type ();
174static void cleanup_undefined_types ();
175static void scan_file_globals ();
9404978d 176static struct symtab *read_ofile_symtab ();
bd5635a1
RP
177static void dbx_psymtab_to_symtab ();
178
179/* C++ */
180static struct type **read_args ();
181
9404978d
MT
182static const char vptr_name[] = { '_','v','p','t','r',CPLUS_MARKER,'\0' };
183static const char vb_name[] = { '_','v','b',CPLUS_MARKER,'\0' };
bd5635a1
RP
184
185/* Macro to determine which symbols to ignore when reading the first symbol
186 of a file. Some machines override this definition. */
187#ifndef IGNORE_SYMBOL
188/* This code is used on Ultrix systems. Ignore it */
189#define IGNORE_SYMBOL(type) (type == (int)N_NSYMS)
190#endif
191
192/* Macro for name of symbol to indicate a file compiled with gcc. */
193#ifndef GCC_COMPILED_FLAG_SYMBOL
194#define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
195#endif
196
197/* Convert stab register number (from `r' declaration) to a gdb REGNUM. */
198
199#ifndef STAB_REG_TO_REGNUM
200#define STAB_REG_TO_REGNUM(VALUE) (VALUE)
201#endif
202
203/* Define this as 1 if a pcc declaration of a char or short argument
204 gives the correct address. Otherwise assume pcc gives the
205 address of the corresponding int, which is not the same on a
206 big-endian machine. */
207
208#ifndef BELIEVE_PCC_PROMOTION
209#define BELIEVE_PCC_PROMOTION 0
210#endif
211\f
212/* Nonzero means give verbose info on gdb action. From main.c. */
213extern int info_verbose;
214
215/* Name of source file whose symbol data we are now processing.
216 This comes from a symbol of type N_SO. */
217
218static char *last_source_file;
219
220/* Core address of start of text of current source file.
221 This too comes from the N_SO symbol. */
222
223static CORE_ADDR last_source_start_addr;
224
225/* The entry point of a file we are reading. */
226CORE_ADDR entry_point;
227
228/* The list of sub-source-files within the current individual compilation.
229 Each file gets its own symtab with its own linetable and associated info,
230 but they all share one blockvector. */
231
232struct subfile
233{
234 struct subfile *next;
235 char *name;
236 char *dirname;
237 struct linetable *line_vector;
238 int line_vector_length;
239 int line_vector_index;
240 int prev_line_number;
241};
242
243static struct subfile *subfiles;
244
245static struct subfile *current_subfile;
246
247/* Count symbols as they are processed, for error messages. */
248
249static unsigned int symnum;
250
251/* Vector of types defined so far, indexed by their dbx type numbers.
252 (In newer sun systems, dbx uses a pair of numbers in parens,
253 as in "(SUBFILENUM,NUMWITHINSUBFILE)". Then these numbers must be
254 translated through the type_translations hash table to get
255 the index into the type vector.) */
256
7cefc05e 257static struct type **type_vector;
bd5635a1
RP
258
259/* Number of elements allocated for type_vector currently. */
260
261static int type_vector_length;
262
263/* Vector of line number information. */
264
265static struct linetable *line_vector;
266
267/* Index of next entry to go in line_vector_index. */
268
269static int line_vector_index;
270
271/* Last line number recorded in the line vector. */
272
273static int prev_line_number;
274
275/* Number of elements allocated for line_vector currently. */
276
277static int line_vector_length;
278
279/* Hash table of global symbols whose values are not known yet.
280 They are chained thru the SYMBOL_VALUE_CHAIN, since we don't
281 have the correct data for that slot yet. */
282/* The use of the LOC_BLOCK code in this chain is nonstandard--
283 it refers to a FORTRAN common block rather than the usual meaning. */
284
285#define HASHSIZE 127
286static struct symbol *global_sym_chain[HASHSIZE];
287
288/* Record the symbols defined for each context in a list.
289 We don't create a struct block for the context until we
290 know how long to make it. */
291
292#define PENDINGSIZE 100
293
294struct pending
295{
296 struct pending *next;
297 int nsyms;
298 struct symbol *symbol[PENDINGSIZE];
299};
300
301/* List of free `struct pending' structures for reuse. */
302struct pending *free_pendings;
303
304/* Here are the three lists that symbols are put on. */
305
306struct pending *file_symbols; /* static at top level, and types */
307
308struct pending *global_symbols; /* global functions and variables */
309
310struct pending *local_symbols; /* everything local to lexical context */
311
312/* List of symbols declared since the last BCOMM. This list is a tail
313 of local_symbols. When ECOMM is seen, the symbols on the list
314 are noted so their proper addresses can be filled in later,
315 using the common block base address gotten from the assembler
316 stabs. */
317
318struct pending *common_block;
319int common_block_i;
320
321/* Stack representing unclosed lexical contexts
322 (that will become blocks, eventually). */
323
324struct context_stack
325{
326 struct pending *locals;
327 struct pending_block *old_blocks;
328 struct symbol *name;
329 CORE_ADDR start_addr;
330 CORE_ADDR end_addr; /* Temp slot for exception handling. */
331 int depth;
332};
333
334struct context_stack *context_stack;
335
336/* Index of first unused entry in context stack. */
337int context_stack_depth;
338
339/* Currently allocated size of context stack. */
340
341int context_stack_size;
342
343/* Nonzero if within a function (so symbols should be local,
344 if nothing says specifically). */
345
346int within_function;
347
0c4d2cc2
JG
348#if 0
349/* The type of the function we are currently reading in. This is
350 used by define_symbol to record the type of arguments to a function. */
351
352static struct type *in_function_type;
353#endif
354
bd5635a1
RP
355/* List of blocks already made (lexical contexts already closed).
356 This is used at the end to make the blockvector. */
357
358struct pending_block
359{
360 struct pending_block *next;
361 struct block *block;
362};
363
364struct pending_block *pending_blocks;
365
366extern CORE_ADDR startup_file_start; /* From blockframe.c */
367extern CORE_ADDR startup_file_end; /* From blockframe.c */
368
369/* Global variable which, when set, indicates that we are processing a
370 .o file compiled with gcc */
371
372static unsigned char processing_gcc_compilation;
373
374/* Make a list of forward references which haven't been defined. */
375static struct type **undef_types;
376static int undef_types_allocated, undef_types_length;
377
378/* String table for the main symbol file. It is kept in memory
379 permanently, to speed up symbol reading. Other files' symbol tables
380 are read in on demand. FIXME, this should be cleaner. */
381
382static char *symfile_string_table;
383static int symfile_string_table_size;
384
afe4ca15
JG
385/* The size of each symbol in the symbol file (in external form).
386 This is set by dbx_symfile_read when building psymtabs, and by
387 dbx_psymtab_to_symtab when building symtabs. */
388
389static unsigned symbol_size;
390
391/* Setup a define to deal cleanly with the underscore problem */
bd5635a1
RP
392
393#ifdef NAMES_HAVE_UNDERSCORE
394#define HASH_OFFSET 1
395#else
396#define HASH_OFFSET 0
397#endif
398
399/* Complaints about the symbols we have encountered. */
400
401struct complaint innerblock_complaint =
402 {"inner block not inside outer block in %s", 0, 0};
403
404struct complaint blockvector_complaint =
405 {"block at %x out of order", 0, 0};
406
407struct complaint lbrac_complaint =
408 {"bad block start address patched", 0, 0};
409
410#if 0
411struct complaint dbx_class_complaint =
412 {"encountered DBX-style class variable debugging information.\n\
413You seem to have compiled your program with \
414\"g++ -g0\" instead of \"g++ -g\".\n\
415Therefore GDB will not know about your class variables", 0, 0};
416#endif
417
418struct complaint string_table_offset_complaint =
419 {"bad string table offset in symbol %d", 0, 0};
420
421struct complaint unknown_symtype_complaint =
0c4d2cc2 422 {"unknown symbol type %s", 0, 0};
bd5635a1
RP
423
424struct complaint lbrac_rbrac_complaint =
425 {"block start larger than block end", 0, 0};
426
427struct complaint const_vol_complaint =
9bb30452 428 {"const/volatile indicator missing (ok if using g++ v1.x), got '%c'", 0, 0};
bd5635a1
RP
429
430struct complaint error_type_complaint =
5bc757e2 431 {"debug info mismatch between compiler and debugger", 0, 0};
bd5635a1
RP
432
433struct complaint invalid_member_complaint =
434 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
9bb30452
JG
435
436struct complaint range_type_base_complaint =
437 {"base type %d of range type is not defined", 0, 0};
bd5635a1
RP
438\f
439/* Support for Sun changes to dbx symbol format */
440
441/* For each identified header file, we have a table of types defined
442 in that header file.
443
444 header_files maps header file names to their type tables.
445 It is a vector of n_header_files elements.
446 Each element describes one header file.
447 It contains a vector of types.
448
449 Sometimes it can happen that the same header file produces
450 different results when included in different places.
451 This can result from conditionals or from different
452 things done before including the file.
453 When this happens, there are multiple entries for the file in this table,
454 one entry for each distinct set of results.
455 The entries are distinguished by the INSTANCE field.
456 The INSTANCE field appears in the N_BINCL and N_EXCL symbol table and is
457 used to match header-file references to their corresponding data. */
458
459struct header_file
460{
461 char *name; /* Name of header file */
462 int instance; /* Numeric code distinguishing instances
463 of one header file that produced
464 different results when included.
465 It comes from the N_BINCL or N_EXCL. */
466 struct type **vector; /* Pointer to vector of types */
467 int length; /* Allocated length (# elts) of that vector */
468};
469
470static struct header_file *header_files = 0;
471
472static int n_header_files;
473
474static int n_allocated_header_files;
475
476/* During initial symbol readin, we need to have a structure to keep
477 track of which psymtabs have which bincls in them. This structure
478 is used during readin to setup the list of dependencies within each
479 partial symbol table. */
480
481struct header_file_location
482{
483 char *name; /* Name of header file */
484 int instance; /* See above */
485 struct partial_symtab *pst; /* Partial symtab that has the
486 BINCL/EINCL defs for this file */
487};
488
489/* The actual list and controling variables */
490static struct header_file_location *bincl_list, *next_bincl;
491static int bincls_allocated;
492
493/* Within each object file, various header files are assigned numbers.
494 A type is defined or referred to with a pair of numbers
495 (FILENUM,TYPENUM) where FILENUM is the number of the header file
496 and TYPENUM is the number within that header file.
497 TYPENUM is the index within the vector of types for that header file.
498
499 FILENUM == 1 is special; it refers to the main source of the object file,
500 and not to any header file. FILENUM != 1 is interpreted by looking it up
501 in the following table, which contains indices in header_files. */
502
503static int *this_object_header_files = 0;
504
505static int n_this_object_header_files;
506
507static int n_allocated_this_object_header_files;
508
509/* When a header file is getting special overriding definitions
510 for one source file, record here the header_files index
511 of its normal definition vector.
512 At other times, this is -1. */
513
514static int header_file_prev_index;
515
516/* Free up old header file tables, and allocate new ones.
517 We're reading a new symbol file now. */
518
9bba3334 519static void
bd5635a1
RP
520free_and_init_header_files ()
521{
522 register int i;
523 for (i = 0; i < n_header_files; i++)
524 free (header_files[i].name);
525 if (header_files) /* First time null */
526 free (header_files);
527 if (this_object_header_files) /* First time null */
528 free (this_object_header_files);
529
530 n_allocated_header_files = 10;
531 header_files = (struct header_file *) xmalloc (10 * sizeof (struct header_file));
532 n_header_files = 0;
533
534 n_allocated_this_object_header_files = 10;
535 this_object_header_files = (int *) xmalloc (10 * sizeof (int));
536}
537
538/* Called at the start of each object file's symbols.
539 Clear out the mapping of header file numbers to header files. */
540
541static void
542new_object_header_files ()
543{
544 /* Leave FILENUM of 0 free for builtin types and this file's types. */
545 n_this_object_header_files = 1;
546 header_file_prev_index = -1;
547}
548
549/* Add header file number I for this object file
550 at the next successive FILENUM. */
551
552static void
553add_this_object_header_file (i)
554 int i;
555{
556 if (n_this_object_header_files == n_allocated_this_object_header_files)
557 {
558 n_allocated_this_object_header_files *= 2;
559 this_object_header_files
560 = (int *) xrealloc (this_object_header_files,
561 n_allocated_this_object_header_files * sizeof (int));
562 }
563
564 this_object_header_files[n_this_object_header_files++] = i;
565}
566
567/* Add to this file an "old" header file, one already seen in
568 a previous object file. NAME is the header file's name.
569 INSTANCE is its instance code, to select among multiple
570 symbol tables for the same header file. */
571
572static void
573add_old_header_file (name, instance)
574 char *name;
575 int instance;
576{
577 register struct header_file *p = header_files;
578 register int i;
579
580 for (i = 0; i < n_header_files; i++)
581 if (!strcmp (p[i].name, name) && instance == p[i].instance)
582 {
583 add_this_object_header_file (i);
584 return;
585 }
586 error ("Invalid symbol data: \"repeated\" header file that hasn't been seen before, at symtab pos %d.",
587 symnum);
588}
589
590/* Add to this file a "new" header file: definitions for its types follow.
591 NAME is the header file's name.
592 Most often this happens only once for each distinct header file,
593 but not necessarily. If it happens more than once, INSTANCE has
594 a different value each time, and references to the header file
595 use INSTANCE values to select among them.
596
597 dbx output contains "begin" and "end" markers for each new header file,
598 but at this level we just need to know which files there have been;
599 so we record the file when its "begin" is seen and ignore the "end". */
600
601static void
602add_new_header_file (name, instance)
603 char *name;
604 int instance;
605{
606 register int i;
607 header_file_prev_index = -1;
608
609 /* Make sure there is room for one more header file. */
610
611 if (n_header_files == n_allocated_header_files)
612 {
613 n_allocated_header_files *= 2;
614 header_files = (struct header_file *)
615 xrealloc (header_files,
616 (n_allocated_header_files
617 * sizeof (struct header_file)));
618 }
619
620 /* Create an entry for this header file. */
621
622 i = n_header_files++;
623 header_files[i].name = savestring (name, strlen(name));
624 header_files[i].instance = instance;
625 header_files[i].length = 10;
626 header_files[i].vector
627 = (struct type **) xmalloc (10 * sizeof (struct type *));
628 bzero (header_files[i].vector, 10 * sizeof (struct type *));
629
630 add_this_object_header_file (i);
631}
632
633/* Look up a dbx type-number pair. Return the address of the slot
634 where the type for that number-pair is stored.
635 The number-pair is in TYPENUMS.
636
637 This can be used for finding the type associated with that pair
638 or for associating a new type with the pair. */
639
640static struct type **
641dbx_lookup_type (typenums)
642 int typenums[2];
643{
644 register int filenum = typenums[0], index = typenums[1];
645
646 if (filenum < 0 || filenum >= n_this_object_header_files)
647 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
648 filenum, index, symnum);
649
650 if (filenum == 0)
651 {
652 /* Type is defined outside of header files.
653 Find it in this object file's type vector. */
5b0a744f 654 while (index >= type_vector_length)
bd5635a1
RP
655 {
656 type_vector_length *= 2;
7cefc05e 657 type_vector = (struct type **)
bd5635a1 658 xrealloc (type_vector,
7cefc05e
JG
659 (type_vector_length * sizeof (struct type *)));
660 bzero (&type_vector[type_vector_length / 2],
bd5635a1
RP
661 type_vector_length * sizeof (struct type *) / 2);
662 }
7cefc05e 663 return &type_vector[index];
bd5635a1
RP
664 }
665 else
666 {
667 register int real_filenum = this_object_header_files[filenum];
668 register struct header_file *f;
669 int f_orig_length;
670
671 if (real_filenum >= n_header_files)
672 abort ();
673
674 f = &header_files[real_filenum];
675
676 f_orig_length = f->length;
677 if (index >= f_orig_length)
678 {
679 while (index >= f->length)
680 f->length *= 2;
681 f->vector = (struct type **)
682 xrealloc (f->vector, f->length * sizeof (struct type *));
683 bzero (&f->vector[f_orig_length],
684 (f->length - f_orig_length) * sizeof (struct type *));
685 }
686 return &f->vector[index];
687 }
688}
689
690/* Create a type object. Occaisionally used when you need a type
691 which isn't going to be given a type number. */
692
693static struct type *
694dbx_create_type ()
695{
696 register struct type *type =
697 (struct type *) obstack_alloc (symbol_obstack, sizeof (struct type));
698
699 bzero (type, sizeof (struct type));
700 TYPE_VPTR_FIELDNO (type) = -1;
62c4f98b 701 TYPE_VPTR_BASETYPE (type) = 0;
bd5635a1
RP
702 return type;
703}
704
705/* Make sure there is a type allocated for type numbers TYPENUMS
706 and return the type object.
707 This can create an empty (zeroed) type object.
708 TYPENUMS may be (-1, -1) to return a new type object that is not
709 put into the type vector, and so may not be referred to by number. */
710
711static struct type *
712dbx_alloc_type (typenums)
713 int typenums[2];
714{
715 register struct type **type_addr;
716 register struct type *type;
717
718 if (typenums[1] != -1)
719 {
720 type_addr = dbx_lookup_type (typenums);
721 type = *type_addr;
722 }
723 else
724 {
725 type_addr = 0;
726 type = 0;
727 }
728
729 /* If we are referring to a type not known at all yet,
730 allocate an empty type for it.
731 We will fill it in later if we find out how. */
732 if (type == 0)
733 {
734 type = dbx_create_type ();
735 if (type_addr)
736 *type_addr = type;
737 }
738
739 return type;
740}
741
742#if 0
743static struct type **
744explicit_lookup_type (real_filenum, index)
745 int real_filenum, index;
746{
747 register struct header_file *f = &header_files[real_filenum];
748
749 if (index >= f->length)
750 {
751 f->length *= 2;
752 f->vector = (struct type **)
753 xrealloc (f->vector, f->length * sizeof (struct type *));
754 bzero (&f->vector[f->length / 2],
755 f->length * sizeof (struct type *) / 2);
756 }
757 return &f->vector[index];
758}
759#endif
760\f
761/* maintain the lists of symbols and blocks */
762
763/* Add a symbol to one of the lists of symbols. */
764static void
765add_symbol_to_list (symbol, listhead)
766 struct symbol *symbol;
767 struct pending **listhead;
768{
769 /* We keep PENDINGSIZE symbols in each link of the list.
770 If we don't have a link with room in it, add a new link. */
771 if (*listhead == 0 || (*listhead)->nsyms == PENDINGSIZE)
772 {
773 register struct pending *link;
774 if (free_pendings)
775 {
776 link = free_pendings;
777 free_pendings = link->next;
778 }
779 else
780 link = (struct pending *) xmalloc (sizeof (struct pending));
781
782 link->next = *listhead;
783 *listhead = link;
784 link->nsyms = 0;
785 }
786
787 (*listhead)->symbol[(*listhead)->nsyms++] = symbol;
788}
789
790/* At end of reading syms, or in case of quit,
791 really free as many `struct pending's as we can easily find. */
792
793/* ARGSUSED */
794static void
795really_free_pendings (foo)
796 int foo;
797{
798 struct pending *next, *next1;
e1ce8aa5 799#if 0
bd5635a1 800 struct pending_block *bnext, *bnext1;
e1ce8aa5 801#endif
bd5635a1
RP
802
803 for (next = free_pendings; next; next = next1)
804 {
805 next1 = next->next;
806 free (next);
807 }
808 free_pendings = 0;
809
810#if 0 /* Now we make the links in the symbol_obstack, so don't free them. */
811 for (bnext = pending_blocks; bnext; bnext = bnext1)
812 {
813 bnext1 = bnext->next;
814 free (bnext);
815 }
816#endif
817 pending_blocks = 0;
818
819 for (next = file_symbols; next; next = next1)
820 {
821 next1 = next->next;
822 free (next);
823 }
3f2e006b
JG
824 file_symbols = 0;
825
bd5635a1
RP
826 for (next = global_symbols; next; next = next1)
827 {
828 next1 = next->next;
829 free (next);
830 }
3f2e006b 831 global_symbols = 0;
bd5635a1
RP
832}
833
834/* Take one of the lists of symbols and make a block from it.
835 Keep the order the symbols have in the list (reversed from the input file).
836 Put the block on the list of pending blocks. */
837
838static void
839finish_block (symbol, listhead, old_blocks, start, end)
840 struct symbol *symbol;
841 struct pending **listhead;
842 struct pending_block *old_blocks;
843 CORE_ADDR start, end;
844{
845 register struct pending *next, *next1;
846 register struct block *block;
847 register struct pending_block *pblock;
848 struct pending_block *opblock;
849 register int i;
850
851 /* Count the length of the list of symbols. */
852
853 for (next = *listhead, i = 0; next; i += next->nsyms, next = next->next)
854 /*EMPTY*/;
855
856 block = (struct block *) obstack_alloc (symbol_obstack,
857 (sizeof (struct block)
858 + ((i - 1)
859 * sizeof (struct symbol *))));
860
861 /* Copy the symbols into the block. */
862
863 BLOCK_NSYMS (block) = i;
864 for (next = *listhead; next; next = next->next)
865 {
866 register int j;
867 for (j = next->nsyms - 1; j >= 0; j--)
868 BLOCK_SYM (block, --i) = next->symbol[j];
869 }
870
871 BLOCK_START (block) = start;
872 BLOCK_END (block) = end;
873 BLOCK_SUPERBLOCK (block) = 0; /* Filled in when containing block is made */
874 BLOCK_GCC_COMPILED (block) = processing_gcc_compilation;
875
876 /* Put the block in as the value of the symbol that names it. */
877
878 if (symbol)
879 {
880 SYMBOL_BLOCK_VALUE (symbol) = block;
881 BLOCK_FUNCTION (block) = symbol;
882 }
883 else
884 BLOCK_FUNCTION (block) = 0;
885
886 /* Now "free" the links of the list, and empty the list. */
887
888 for (next = *listhead; next; next = next1)
889 {
890 next1 = next->next;
891 next->next = free_pendings;
892 free_pendings = next;
893 }
894 *listhead = 0;
895
896 /* Install this block as the superblock
897 of all blocks made since the start of this scope
898 that don't have superblocks yet. */
899
900 opblock = 0;
901 for (pblock = pending_blocks; pblock != old_blocks; pblock = pblock->next)
902 {
903 if (BLOCK_SUPERBLOCK (pblock->block) == 0) {
904#if 1
905 /* Check to be sure the blocks are nested as we receive them.
906 If the compiler/assembler/linker work, this just burns a small
907 amount of time. */
908 if (BLOCK_START (pblock->block) < BLOCK_START (block)
909 || BLOCK_END (pblock->block) > BLOCK_END (block)) {
910 complain(&innerblock_complaint, symbol? SYMBOL_NAME (symbol):
911 "(don't know)");
912 BLOCK_START (pblock->block) = BLOCK_START (block);
913 BLOCK_END (pblock->block) = BLOCK_END (block);
914 }
915#endif
916 BLOCK_SUPERBLOCK (pblock->block) = block;
917 }
918 opblock = pblock;
919 }
920
921 /* Record this block on the list of all blocks in the file.
922 Put it after opblock, or at the beginning if opblock is 0.
923 This puts the block in the list after all its subblocks. */
924
925 /* Allocate in the symbol_obstack to save time.
926 It wastes a little space. */
927 pblock = (struct pending_block *)
928 obstack_alloc (symbol_obstack,
929 sizeof (struct pending_block));
930 pblock->block = block;
931 if (opblock)
932 {
933 pblock->next = opblock->next;
934 opblock->next = pblock;
935 }
936 else
937 {
938 pblock->next = pending_blocks;
939 pending_blocks = pblock;
940 }
941}
942
943static struct blockvector *
944make_blockvector ()
945{
946 register struct pending_block *next;
947 register struct blockvector *blockvector;
948 register int i;
949
950 /* Count the length of the list of blocks. */
951
952 for (next = pending_blocks, i = 0; next; next = next->next, i++);
953
954 blockvector = (struct blockvector *)
955 obstack_alloc (symbol_obstack,
956 (sizeof (struct blockvector)
957 + (i - 1) * sizeof (struct block *)));
958
959 /* Copy the blocks into the blockvector.
960 This is done in reverse order, which happens to put
961 the blocks into the proper order (ascending starting address).
962 finish_block has hair to insert each block into the list
963 after its subblocks in order to make sure this is true. */
964
965 BLOCKVECTOR_NBLOCKS (blockvector) = i;
966 for (next = pending_blocks; next; next = next->next) {
967 BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
968 }
969
970#if 0 /* Now we make the links in the obstack, so don't free them. */
971 /* Now free the links of the list, and empty the list. */
972
973 for (next = pending_blocks; next; next = next1)
974 {
975 next1 = next->next;
976 free (next);
977 }
978#endif
979 pending_blocks = 0;
980
981#if 1 /* FIXME, shut this off after a while to speed up symbol reading. */
982 /* Some compilers output blocks in the wrong order, but we depend
983 on their being in the right order so we can binary search.
984 Check the order and moan about it. FIXME. */
985 if (BLOCKVECTOR_NBLOCKS (blockvector) > 1)
986 for (i = 1; i < BLOCKVECTOR_NBLOCKS (blockvector); i++) {
987 if (BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i-1))
988 > BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i))) {
989 complain (&blockvector_complaint,
990 BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i)));
991 }
992 }
993#endif
994
995 return blockvector;
996}
997\f
998/* Manage the vector of line numbers. */
999
1000static void
1001record_line (line, pc)
1002 int line;
1003 CORE_ADDR pc;
1004{
1005 struct linetable_entry *e;
1006 /* Ignore the dummy line number in libg.o */
1007
1008 if (line == 0xffff)
1009 return;
1010
1011 /* Make sure line vector is big enough. */
1012
1013 if (line_vector_index + 1 >= line_vector_length)
1014 {
1015 line_vector_length *= 2;
1016 line_vector = (struct linetable *)
1017 xrealloc (line_vector,
1018 (sizeof (struct linetable)
1019 + line_vector_length * sizeof (struct linetable_entry)));
1020 current_subfile->line_vector = line_vector;
1021 }
1022
1023 e = line_vector->item + line_vector_index++;
1024 e->line = line; e->pc = pc;
1025}
1026\f
1027/* Start a new symtab for a new source file.
1028 This is called when a dbx symbol of type N_SO is seen;
1029 it indicates the start of data for one original source file. */
1030
1031static void
1032start_symtab (name, dirname, start_addr)
1033 char *name;
1034 char *dirname;
1035 CORE_ADDR start_addr;
1036{
1037
1038 last_source_file = name;
1039 last_source_start_addr = start_addr;
1040 file_symbols = 0;
1041 global_symbols = 0;
1042 within_function = 0;
1043
1044 /* Context stack is initially empty, with room for 10 levels. */
1045 context_stack
1046 = (struct context_stack *) xmalloc (10 * sizeof (struct context_stack));
1047 context_stack_size = 10;
1048 context_stack_depth = 0;
1049
1050 new_object_header_files ();
1051
1052 type_vector_length = 160;
7cefc05e
JG
1053 type_vector = (struct type **)
1054 xmalloc (type_vector_length * sizeof (struct type *));
1055 bzero (type_vector, type_vector_length * sizeof (struct type *));
bd5635a1
RP
1056
1057 /* Initialize the list of sub source files with one entry
1058 for this file (the top-level source file). */
1059
1060 subfiles = 0;
1061 current_subfile = 0;
1062 start_subfile (name, dirname);
1063}
1064
1065/* Handle an N_SOL symbol, which indicates the start of
1066 code that came from an included (or otherwise merged-in)
1067 source file with a different name. */
1068
1069static void
1070start_subfile (name, dirname)
1071 char *name;
1072 char *dirname;
1073{
1074 register struct subfile *subfile;
1075
1076 /* Save the current subfile's line vector data. */
1077
1078 if (current_subfile)
1079 {
1080 current_subfile->line_vector_index = line_vector_index;
1081 current_subfile->line_vector_length = line_vector_length;
1082 current_subfile->prev_line_number = prev_line_number;
1083 }
1084
1085 /* See if this subfile is already known as a subfile of the
1086 current main source file. */
1087
1088 for (subfile = subfiles; subfile; subfile = subfile->next)
1089 {
1090 if (!strcmp (subfile->name, name))
1091 {
1092 line_vector = subfile->line_vector;
1093 line_vector_index = subfile->line_vector_index;
1094 line_vector_length = subfile->line_vector_length;
1095 prev_line_number = subfile->prev_line_number;
1096 current_subfile = subfile;
1097 return;
1098 }
1099 }
1100
1101 /* This subfile is not known. Add an entry for it. */
1102
1103 line_vector_index = 0;
1104 line_vector_length = 1000;
1105 prev_line_number = -2; /* Force first line number to be explicit */
1106 line_vector = (struct linetable *)
1107 xmalloc (sizeof (struct linetable)
1108 + line_vector_length * sizeof (struct linetable_entry));
1109
1110 /* Make an entry for this subfile in the list of all subfiles
1111 of the current main source file. */
1112
1113 subfile = (struct subfile *) xmalloc (sizeof (struct subfile));
1114 subfile->next = subfiles;
1115 subfile->name = obsavestring (name, strlen (name));
1116 if (dirname == NULL)
1117 subfile->dirname = NULL;
1118 else
1119 subfile->dirname = obsavestring (dirname, strlen (dirname));
1120
1121 subfile->line_vector = line_vector;
1122 subfiles = subfile;
1123 current_subfile = subfile;
1124}
1125
1126/* Finish the symbol definitions for one main source file,
1127 close off all the lexical contexts for that file
1128 (creating struct block's for them), then make the struct symtab
1129 for that file and put it in the list of all such.
1130
1131 END_ADDR is the address of the end of the file's text. */
1132
9404978d 1133static struct symtab *
bd5635a1
RP
1134end_symtab (end_addr)
1135 CORE_ADDR end_addr;
1136{
1137 register struct symtab *symtab;
1138 register struct blockvector *blockvector;
1139 register struct subfile *subfile;
1140 register struct linetable *lv;
1141 struct subfile *nextsub;
1142
1143 /* Finish the lexical context of the last function in the file;
1144 pop the context stack. */
1145
1146 if (context_stack_depth > 0)
1147 {
1148 register struct context_stack *cstk;
1149 context_stack_depth--;
1150 cstk = &context_stack[context_stack_depth];
1151 /* Make a block for the local symbols within. */
1152 finish_block (cstk->name, &local_symbols, cstk->old_blocks,
1153 cstk->start_addr, end_addr);
1154 }
1155
1156 /* Cleanup any undefined types that have been left hanging around
1157 (this needs to be done before the finish_blocks so that
1158 file_symbols is still good). */
1159 cleanup_undefined_types ();
1160
3f83182d 1161 /* Define the STATIC_BLOCK and GLOBAL_BLOCK, and build the blockvector. */
bd5635a1
RP
1162 finish_block (0, &file_symbols, 0, last_source_start_addr, end_addr);
1163 finish_block (0, &global_symbols, 0, last_source_start_addr, end_addr);
1164 blockvector = make_blockvector ();
1165
1166 current_subfile->line_vector_index = line_vector_index;
1167
1168 /* Now create the symtab objects proper, one for each subfile. */
9404978d 1169 /* (The main file is the last one on the chain.) */
bd5635a1
RP
1170
1171 for (subfile = subfiles; subfile; subfile = nextsub)
1172 {
0c4d2cc2 1173 symtab = allocate_symtab (subfile->name);
bd5635a1
RP
1174
1175 /* Fill in its components. */
1176 symtab->blockvector = blockvector;
1177 lv = subfile->line_vector;
1178 lv->nitems = subfile->line_vector_index;
1179 symtab->linetable = (struct linetable *)
1180 xrealloc (lv, (sizeof (struct linetable)
1181 + lv->nitems * sizeof (struct linetable_entry)));
bd5635a1 1182
bd5635a1
RP
1183 symtab->dirname = subfile->dirname;
1184
1185 symtab->free_code = free_linetable;
1186 symtab->free_ptr = 0;
bd5635a1 1187
f9623881
JG
1188 /* There should never already be a symtab for this name, since
1189 any prev dups have been removed when the psymtab was read in.
1190 FIXME, there ought to be a way to check this here. */
1191 /* FIXME blewit |= free_named_symtabs (symtab->filename); */
bd5635a1
RP
1192
1193 /* Link the new symtab into the list of such. */
1194 symtab->next = symtab_list;
1195 symtab_list = symtab;
1196
1197 nextsub = subfile->next;
1198 free (subfile);
1199 }
1200
7cefc05e 1201 free ((char *) type_vector);
bd5635a1
RP
1202 type_vector = 0;
1203 type_vector_length = -1;
1204 line_vector = 0;
1205 line_vector_length = -1;
1206 last_source_file = 0;
9404978d
MT
1207
1208 return symtab;
bd5635a1
RP
1209}
1210\f
1211/* Handle the N_BINCL and N_EINCL symbol types
1212 that act like N_SOL for switching source files
1213 (different subfiles, as we call them) within one object file,
1214 but using a stack rather than in an arbitrary order. */
1215
1216struct subfile_stack
1217{
1218 struct subfile_stack *next;
1219 char *name;
1220 int prev_index;
1221};
1222
1223struct subfile_stack *subfile_stack;
1224
1225static void
1226push_subfile ()
1227{
1228 register struct subfile_stack *tem
1229 = (struct subfile_stack *) xmalloc (sizeof (struct subfile_stack));
1230
1231 tem->next = subfile_stack;
1232 subfile_stack = tem;
1233 if (current_subfile == 0 || current_subfile->name == 0)
1234 abort ();
1235 tem->name = current_subfile->name;
1236 tem->prev_index = header_file_prev_index;
1237}
1238
1239static char *
1240pop_subfile ()
1241{
1242 register char *name;
1243 register struct subfile_stack *link = subfile_stack;
1244
1245 if (link == 0)
1246 abort ();
1247
1248 name = link->name;
1249 subfile_stack = link->next;
1250 header_file_prev_index = link->prev_index;
1251 free (link);
1252
1253 return name;
1254}
1255\f
9bba3334 1256static void
bd5635a1
RP
1257record_misc_function (name, address, type)
1258 char *name;
1259 CORE_ADDR address;
1260 int type;
1261{
0c4d2cc2
JG
1262 enum misc_function_type misc_type;
1263
1264 switch (type &~ N_EXT) {
1265 case N_TEXT: misc_type = mf_text; break;
1266 case N_DATA: misc_type = mf_data; break;
1267 case N_BSS: misc_type = mf_bss; break;
1268 case N_ABS: misc_type = mf_abs; break;
1269#ifdef N_SETV
1270 case N_SETV: misc_type = mf_data; break;
1271#endif
1272 default: misc_type = mf_unknown; break;
1273 }
bd5635a1
RP
1274
1275 prim_record_misc_function (obsavestring (name, strlen (name)),
1276 address, misc_type);
1277}
1278\f
e1ce8aa5
JK
1279/* The BFD for this file -- only good while we're actively reading
1280 symbols into a psymtab or a symtab. */
1281
1282static bfd *symfile_bfd;
1283
bd5635a1
RP
1284/* Scan and build partial symbols for a symbol file.
1285 We have been initialized by a call to dbx_symfile_init, which
1286 put all the relevant info into a "struct dbx_symfile_info"
1287 hung off the struct sym_fns SF.
1288
1289 ADDR is the address relative to which the symbols in it are (e.g.
1290 the base address of the text segment).
1291 MAINLINE is true if we are reading the main symbol
1292 table (as opposed to a shared lib or dynamically loaded file). */
1293
9bba3334 1294static void
bd5635a1
RP
1295dbx_symfile_read (sf, addr, mainline)
1296 struct sym_fns *sf;
1297 CORE_ADDR addr;
1298 int mainline; /* FIXME comments above */
1299{
1300 struct dbx_symfile_info *info = (struct dbx_symfile_info *) (sf->sym_private);
1301 bfd *sym_bfd = sf->sym_bfd;
1302 int val;
1303 char *filename = bfd_get_filename (sym_bfd);
1304
1305 val = lseek (info->desc, info->symtab_offset, L_SET);
1306 if (val < 0)
1307 perror_with_name (filename);
1308
1309 /* If mainline, set global string table pointers, and reinitialize global
1310 partial symbol list. */
1311 if (mainline) {
1312 symfile_string_table = info->stringtab;
1313 symfile_string_table_size = info->stringtab_size;
bd5635a1
RP
1314 }
1315
66eeea27
JG
1316 /* If we are reinitializing, or if we have never loaded syms yet, init */
1317 if (mainline || global_psymbols.size == 0 || static_psymbols.size == 0)
1318 init_psymbol_list (info->symcount);
1319
bd5635a1
RP
1320 symfile_bfd = sym_bfd; /* Kludge for SWAP_SYMBOL */
1321
afe4ca15
JG
1322 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
1323 symbol_size = obj_symbol_entry_size (sym_bfd);
1324
bd5635a1
RP
1325 pending_blocks = 0;
1326 make_cleanup (really_free_pendings, 0);
1327
1328 init_misc_bunches ();
1329 make_cleanup (discard_misc_bunches, 0);
1330
1331 /* Now that the symbol table data of the executable file are all in core,
1332 process them and define symbols accordingly. */
1333
1334 read_dbx_symtab (filename,
1335 addr - bfd_section_vma (sym_bfd, info->text_sect), /*offset*/
1336 info->desc, info->stringtab, info->stringtab_size,
1337 info->symcount,
1338 bfd_section_vma (sym_bfd, info->text_sect),
1339 bfd_section_size (sym_bfd, info->text_sect));
1340
1341 /* Go over the misc symbol bunches and install them in vector. */
1342
1343 condense_misc_bunches (!mainline);
1344
1345 /* Free up any memory we allocated for ourselves. */
1346
1347 if (!mainline) {
1348 free (info->stringtab); /* Stringtab is only saved for mainline */
1349 }
1350 free (info);
1351 sf->sym_private = 0; /* Zap pointer to our (now gone) info struct */
1352
9404978d
MT
1353 if (!partial_symtab_list) {
1354 wrap_here ("");
1355 printf_filtered ("(no debugging symbols found)...");
1356 wrap_here ("");
1357 }
bd5635a1
RP
1358}
1359
9404978d
MT
1360/* Initialize anything that needs initializing when a completely new
1361 symbol file is specified (not just adding some symbols from another
1362 file, e.g. a shared library). */
bd5635a1 1363
9bba3334 1364static void
9404978d 1365dbx_new_init ()
bd5635a1 1366{
bd5635a1
RP
1367 /* Empty the hash table of global syms looking for values. */
1368 bzero (global_sym_chain, sizeof global_sym_chain);
1369
1370 free_pendings = 0;
1371 file_symbols = 0;
1372 global_symbols = 0;
bd5635a1 1373
bd5635a1 1374 /* Don't put these on the cleanup chain; they need to stick around
9404978d 1375 until the next call to dbx_new_init. *Then* we'll free them. */
bd5635a1
RP
1376 if (symfile_string_table)
1377 {
1378 free (symfile_string_table);
1379 symfile_string_table = 0;
1380 symfile_string_table_size = 0;
1381 }
1382 free_and_init_header_files ();
1383}
1384
1385
1386/* dbx_symfile_init ()
1387 is the dbx-specific initialization routine for reading symbols.
1388 It is passed a struct sym_fns which contains, among other things,
1389 the BFD for the file whose symbols are being read, and a slot for a pointer
1390 to "private data" which we fill with goodies.
1391
1392 We read the string table into malloc'd space and stash a pointer to it.
1393
1394 Since BFD doesn't know how to read debug symbols in a format-independent
1395 way (and may never do so...), we have to do it ourselves. We will never
1396 be called unless this is an a.out (or very similar) file.
1397 FIXME, there should be a cleaner peephole into the BFD environment here. */
1398
9bba3334 1399static void
bd5635a1
RP
1400dbx_symfile_init (sf)
1401 struct sym_fns *sf;
1402{
1403 int val;
1404 int desc;
1405 struct stat statbuf;
1406 bfd *sym_bfd = sf->sym_bfd;
1407 char *name = bfd_get_filename (sym_bfd);
1408 struct dbx_symfile_info *info;
1409 unsigned char size_temp[4];
1410
1411 /* Allocate struct to keep track of the symfile */
1412 sf->sym_private = xmalloc (sizeof (*info)); /* FIXME storage leak */
1413 info = (struct dbx_symfile_info *)sf->sym_private;
1414
1415 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
1416 desc = fileno ((FILE *)(sym_bfd->iostream)); /* Raw file descriptor */
1417#define STRING_TABLE_OFFSET (sym_bfd->origin + obj_str_filepos (sym_bfd))
1418#define SYMBOL_TABLE_OFFSET (sym_bfd->origin + obj_sym_filepos (sym_bfd))
1419 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
1420
1421 info->desc = desc;
1422 info->text_sect = bfd_get_section_by_name (sym_bfd, ".text");
1423 if (!info->text_sect)
1424 abort();
63989338 1425 info->symcount = bfd_get_symcount (sym_bfd);
bd5635a1
RP
1426
1427 /* Read the string table size and check it for bogosity. */
1428 val = lseek (desc, STRING_TABLE_OFFSET, L_SET);
1429 if (val < 0)
1430 perror_with_name (name);
1431 if (fstat (desc, &statbuf) == -1)
1432 perror_with_name (name);
1433
1434 val = myread (desc, size_temp, sizeof (long));
1435 if (val < 0)
1436 perror_with_name (name);
dcc35536 1437 info->stringtab_size = bfd_h_get_32 (sym_bfd, size_temp);
bd5635a1
RP
1438
1439 if (info->stringtab_size >= 0 && info->stringtab_size < statbuf.st_size)
1440 {
1441 info->stringtab = (char *) xmalloc (info->stringtab_size);
1442 /* Caller is responsible for freeing the string table. No cleanup. */
1443 }
1444 else
1445 info->stringtab = NULL;
1446 if (info->stringtab == NULL && info->stringtab_size != 0)
1447 error ("ridiculous string table size: %d bytes", info->stringtab_size);
1448
1449 /* Now read in the string table in one big gulp. */
1450
1451 val = lseek (desc, STRING_TABLE_OFFSET, L_SET);
1452 if (val < 0)
1453 perror_with_name (name);
1454 val = myread (desc, info->stringtab, info->stringtab_size);
1455 if (val < 0)
1456 perror_with_name (name);
1457
1458 /* Record the position of the symbol table for later use. */
1459
1460 info->symtab_offset = SYMBOL_TABLE_OFFSET;
1461}
1462\f
1463/* Buffer for reading the symbol table entries. */
afe4ca15 1464static struct internal_nlist symbuf[4096];
bd5635a1
RP
1465static int symbuf_idx;
1466static int symbuf_end;
1467
1468/* I/O descriptor for reading the symbol table. */
1469static int symtab_input_desc;
1470
1471/* The address in memory of the string table of the object file we are
1472 reading (which might not be the "main" object file, but might be a
1473 shared library or some other dynamically loaded thing). This is set
1474 by read_dbx_symtab when building psymtabs, and by read_ofile_symtab
1475 when building symtabs, and is used only by next_symbol_text. */
1476static char *stringtab_global;
1477
1478/* Refill the symbol table input buffer
1479 and set the variables that control fetching entries from it.
1480 Reports an error if no data available.
1481 This function can read past the end of the symbol table
1482 (into the string table) but this does no harm. */
1483
1484static int
1485fill_symbuf ()
1486{
1487 int nbytes = myread (symtab_input_desc, symbuf, sizeof (symbuf));
1488 if (nbytes < 0)
1489 perror_with_name ("<symbol file>");
1490 else if (nbytes == 0)
1491 error ("Premature end of file reading symbol table");
afe4ca15 1492 symbuf_end = nbytes / symbol_size;
bd5635a1
RP
1493 symbuf_idx = 0;
1494 return 1;
1495}
1496
1497#define SWAP_SYMBOL(symp) \
1498 { \
afe4ca15
JG
1499 (symp)->n_strx = bfd_h_get_32(symfile_bfd, \
1500 (unsigned char *)&(symp)->n_strx); \
dcc35536 1501 (symp)->n_desc = bfd_h_get_16 (symfile_bfd, \
bd5635a1 1502 (unsigned char *)&(symp)->n_desc); \
dcc35536 1503 (symp)->n_value = bfd_h_get_32 (symfile_bfd, \
bd5635a1
RP
1504 (unsigned char *)&(symp)->n_value); \
1505 }
1506
1507/* Invariant: The symbol pointed to by symbuf_idx is the first one
1508 that hasn't been swapped. Swap the symbol at the same time
1509 that symbuf_idx is incremented. */
1510
1511/* dbx allows the text of a symbol name to be continued into the
1512 next symbol name! When such a continuation is encountered
1513 (a \ at the end of the text of a name)
1514 call this function to get the continuation. */
1515
1516static char *
1517next_symbol_text ()
1518{
1519 if (symbuf_idx == symbuf_end)
1520 fill_symbuf ();
1521 symnum++;
1522 SWAP_SYMBOL(&symbuf[symbuf_idx]);
afe4ca15 1523 return symbuf[symbuf_idx++].n_strx + stringtab_global;
bd5635a1
RP
1524}
1525\f
1526/* Initializes storage for all of the partial symbols that will be
1527 created by read_dbx_symtab and subsidiaries. */
1528
1529static void
1530init_psymbol_list (total_symbols)
1531 int total_symbols;
1532{
1533 /* Free any previously allocated psymbol lists. */
1534 if (global_psymbols.list)
1535 free (global_psymbols.list);
1536 if (static_psymbols.list)
1537 free (static_psymbols.list);
1538
1539 /* Current best guess is that there are approximately a twentieth
1540 of the total symbols (in a debugging file) are global or static
1541 oriented symbols */
1542 global_psymbols.size = total_symbols / 10;
1543 static_psymbols.size = total_symbols / 10;
1544 global_psymbols.next = global_psymbols.list = (struct partial_symbol *)
1545 xmalloc (global_psymbols.size * sizeof (struct partial_symbol));
1546 static_psymbols.next = static_psymbols.list = (struct partial_symbol *)
1547 xmalloc (static_psymbols.size * sizeof (struct partial_symbol));
1548}
1549
1550/* Initialize the list of bincls to contain none and have some
1551 allocated. */
1552
1553static void
1554init_bincl_list (number)
1555 int number;
1556{
1557 bincls_allocated = number;
1558 next_bincl = bincl_list = (struct header_file_location *)
1559 xmalloc (bincls_allocated * sizeof(struct header_file_location));
1560}
1561
1562/* Add a bincl to the list. */
1563
1564static void
1565add_bincl_to_list (pst, name, instance)
1566 struct partial_symtab *pst;
1567 char *name;
1568 int instance;
1569{
1570 if (next_bincl >= bincl_list + bincls_allocated)
1571 {
1572 int offset = next_bincl - bincl_list;
1573 bincls_allocated *= 2;
1574 bincl_list = (struct header_file_location *)
1575 xrealloc ((char *)bincl_list,
1576 bincls_allocated * sizeof (struct header_file_location));
1577 next_bincl = bincl_list + offset;
1578 }
1579 next_bincl->pst = pst;
1580 next_bincl->instance = instance;
1581 next_bincl++->name = name;
1582}
1583
1584/* Given a name, value pair, find the corresponding
1585 bincl in the list. Return the partial symtab associated
1586 with that header_file_location. */
1587
9bba3334 1588static struct partial_symtab *
bd5635a1
RP
1589find_corresponding_bincl_psymtab (name, instance)
1590 char *name;
1591 int instance;
1592{
1593 struct header_file_location *bincl;
1594
1595 for (bincl = bincl_list; bincl < next_bincl; bincl++)
1596 if (bincl->instance == instance
1597 && !strcmp (name, bincl->name))
1598 return bincl->pst;
1599
1600 return (struct partial_symtab *) 0;
1601}
1602
1603/* Free the storage allocated for the bincl list. */
1604
1605static void
1606free_bincl_list ()
1607{
1608 free (bincl_list);
1609 bincls_allocated = 0;
1610}
1611
1612static struct partial_symtab *start_psymtab ();
1613static void end_psymtab();
1614
1615#ifdef DEBUG
1616/* This is normally a macro defined in read_dbx_symtab, but this
1617 is a lot easier to debug. */
1618
1619ADD_PSYMBOL_TO_PLIST(NAME, NAMELENGTH, NAMESPACE, CLASS, PLIST, VALUE)
1620 char *NAME;
1621 int NAMELENGTH;
1622 enum namespace NAMESPACE;
1623 enum address_class CLASS;
1624 struct psymbol_allocation_list *PLIST;
1625 unsigned long VALUE;
1626{
1627 register struct partial_symbol *psym;
1628
1629#define LIST *PLIST
1630 do {
1631 if ((LIST).next >=
1632 (LIST).list + (LIST).size)
1633 {
1634 (LIST).list = (struct partial_symbol *)
1635 xrealloc ((LIST).list,
1636 ((LIST).size * 2
1637 * sizeof (struct partial_symbol)));
1638 /* Next assumes we only went one over. Should be good if
1639 program works correctly */
1640 (LIST).next =
1641 (LIST).list + (LIST).size;
1642 (LIST).size *= 2;
1643 }
1644 psym = (LIST).next++;
1645#undef LIST
1646
1647 SYMBOL_NAME (psym) = (char *) obstack_alloc (psymbol_obstack,
1648 (NAMELENGTH) + 1);
1649 strncpy (SYMBOL_NAME (psym), (NAME), (NAMELENGTH));
1650 SYMBOL_NAME (psym)[(NAMELENGTH)] = '\0';
1651 SYMBOL_NAMESPACE (psym) = (NAMESPACE);
1652 SYMBOL_CLASS (psym) = (CLASS);
1653 SYMBOL_VALUE (psym) = (VALUE);
1654 } while (0);
1655}
1656
1657/* Since one arg is a struct, we have to pass in a ptr and deref it (sigh) */
1658#define ADD_PSYMBOL_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \
1659 ADD_PSYMBOL_TO_PLIST(NAME, NAMELENGTH, NAMESPACE, CLASS, &LIST, VALUE)
1660
1661#endif /* DEBUG */
1662
1663/* Given pointers to an a.out symbol table in core containing dbx
1664 style data, setup partial_symtab's describing each source file for
1665 which debugging information is available. NLISTLEN is the number
1666 of symbols in the symbol table. All symbol names are given as
1667 offsets relative to STRINGTAB. STRINGTAB_SIZE is the size of
1668 STRINGTAB. SYMFILE_NAME is the name of the file we are reading from
1669 and ADDR is its relocated address (if incremental) or 0 (if not). */
1670
1671static void
1672read_dbx_symtab (symfile_name, addr,
1673 desc, stringtab, stringtab_size, nlistlen,
1674 text_addr, text_size)
1675 char *symfile_name;
1676 CORE_ADDR addr;
1677 int desc;
1678 register char *stringtab;
1679 register long stringtab_size;
1680 register int nlistlen;
1681 CORE_ADDR text_addr;
1682 int text_size;
1683{
afe4ca15 1684 register struct internal_nlist *bufp;
bd5635a1
RP
1685 register char *namestring;
1686 register struct partial_symbol *psym;
1687 int nsl;
1688 int past_first_source_file = 0;
1689 CORE_ADDR last_o_file_start = 0;
1690 struct cleanup *old_chain;
1691 char *p;
1692
1693 /* End of the text segment of the executable file. */
1694 CORE_ADDR end_of_text_addr;
1695
1696 /* Current partial symtab */
1697 struct partial_symtab *pst;
1698
1699 /* List of current psymtab's include files */
1700 char **psymtab_include_list;
1701 int includes_allocated;
1702 int includes_used;
1703
1704 /* Index within current psymtab dependency list */
1705 struct partial_symtab **dependency_list;
1706 int dependencies_used, dependencies_allocated;
1707
1708 stringtab_global = stringtab;
1709
1710 pst = (struct partial_symtab *) 0;
1711
1712 includes_allocated = 30;
1713 includes_used = 0;
1714 psymtab_include_list = (char **) alloca (includes_allocated *
1715 sizeof (char *));
1716
1717 dependencies_allocated = 30;
1718 dependencies_used = 0;
1719 dependency_list =
1720 (struct partial_symtab **) alloca (dependencies_allocated *
1721 sizeof (struct partial_symtab *));
1722
1723 /* FIXME!! If an error occurs, this blows away the whole symbol table!
1724 It should only blow away the psymtabs created herein. We could
1725 be reading a shared library or a dynloaded file! */
1726 old_chain = make_cleanup (free_all_psymtabs, 0);
1727
1728 /* Init bincl list */
1729 init_bincl_list (20);
1730 make_cleanup (free_bincl_list, 0);
1731
1732 last_source_file = 0;
1733
1734#ifdef END_OF_TEXT_DEFAULT
1735 end_of_text_addr = END_OF_TEXT_DEFAULT;
1736#else
5bc757e2 1737 end_of_text_addr = text_addr + addr + text_size; /* Relocate */
bd5635a1
RP
1738#endif
1739
1740 symtab_input_desc = desc; /* This is needed for fill_symbuf below */
1741 symbuf_end = symbuf_idx = 0;
1742
1743 for (symnum = 0; symnum < nlistlen; symnum++)
1744 {
1745 /* Get the symbol for this run and pull out some info */
1746 QUIT; /* allow this to be interruptable */
1747 if (symbuf_idx == symbuf_end)
1748 fill_symbuf ();
1749 bufp = &symbuf[symbuf_idx++];
1750
1751 /*
1752 * Special case to speed up readin.
1753 */
1754 if (bufp->n_type == (unsigned char)N_SLINE) continue;
1755
1756 SWAP_SYMBOL (bufp);
1757
1758 /* Ok. There is a lot of code duplicated in the rest of this
1759 switch statement (for efficiency reasons). Since I don't
1760 like duplicating code, I will do my penance here, and
1761 describe the code which is duplicated:
1762
1763 *) The assignment to namestring.
1764 *) The call to strchr.
1765 *) The addition of a partial symbol the the two partial
1766 symbol lists. This last is a large section of code, so
1767 I've imbedded it in the following macro.
1768 */
1769
1770/* Set namestring based on bufp. If the string table index is invalid,
1771 give a fake name, and print a single error message per symbol file read,
1772 rather than abort the symbol reading or flood the user with messages. */
1773#define SET_NAMESTRING()\
afe4ca15 1774 if (bufp->n_strx < 0 || bufp->n_strx >= stringtab_size) { \
bd5635a1
RP
1775 complain (&string_table_offset_complaint, symnum); \
1776 namestring = "foo"; \
1777 } else \
afe4ca15 1778 namestring = bufp->n_strx + stringtab
bd5635a1
RP
1779
1780/* Add a symbol with an integer value to a psymtab. */
1781/* This is a macro unless we're debugging. See above this function. */
1782#ifndef DEBUG
1783# define ADD_PSYMBOL_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \
1784 ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, \
1785 SYMBOL_VALUE)
1786#endif /* DEBUG */
1787
1788/* Add a symbol with a CORE_ADDR value to a psymtab. */
1789#define ADD_PSYMBOL_ADDR_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \
1790 ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, \
1791 SYMBOL_VALUE_ADDRESS)
1792
1793/* Add any kind of symbol to a psymtab. */
1794#define ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, VT)\
1795 do { \
1796 if ((LIST).next >= \
1797 (LIST).list + (LIST).size) \
1798 { \
1799 (LIST).list = (struct partial_symbol *) \
1800 xrealloc ((LIST).list, \
1801 ((LIST).size * 2 \
1802 * sizeof (struct partial_symbol))); \
1803 /* Next assumes we only went one over. Should be good if \
1804 program works correctly */ \
1805 (LIST).next = \
1806 (LIST).list + (LIST).size; \
1807 (LIST).size *= 2; \
1808 } \
1809 psym = (LIST).next++; \
1810 \
1811 SYMBOL_NAME (psym) = (char *) obstack_alloc (psymbol_obstack, \
1812 (NAMELENGTH) + 1); \
1813 strncpy (SYMBOL_NAME (psym), (NAME), (NAMELENGTH)); \
1814 SYMBOL_NAME (psym)[(NAMELENGTH)] = '\0'; \
1815 SYMBOL_NAMESPACE (psym) = (NAMESPACE); \
1816 SYMBOL_CLASS (psym) = (CLASS); \
1817 VT (psym) = (VALUE); \
1818 } while (0);
1819
1820/* End of macro definitions, now let's handle them symbols! */
1821
1822 switch (bufp->n_type)
1823 {
1824 /*
1825 * Standard, external, non-debugger, symbols
1826 */
1827
1828 case N_TEXT | N_EXT:
1829 case N_NBTEXT | N_EXT:
1830 case N_NBDATA | N_EXT:
1831 case N_NBBSS | N_EXT:
1832 case N_SETV | N_EXT:
1833 case N_ABS | N_EXT:
1834 case N_DATA | N_EXT:
1835 case N_BSS | N_EXT:
1836
1837 bufp->n_value += addr; /* Relocate */
1838
1839 SET_NAMESTRING();
1840
1841 bss_ext_symbol:
1842 record_misc_function (namestring, bufp->n_value,
1843 bufp->n_type); /* Always */
1844
1845 continue;
1846
1847 /* Standard, local, non-debugger, symbols */
1848
1849 case N_NBTEXT:
1850
1851 /* We need to be able to deal with both N_FN or N_TEXT,
1852 because we have no way of knowing whether the sys-supplied ld
6150cc73
JG
1853 or GNU ld was used to make the executable. Sequents throw
1854 in another wrinkle -- they renumbered N_FN. */
bd5635a1 1855 case N_FN:
6150cc73 1856 case N_FN_SEQ:
bd5635a1
RP
1857 case N_TEXT:
1858 bufp->n_value += addr; /* Relocate */
1859 SET_NAMESTRING();
1860 if ((namestring[0] == '-' && namestring[1] == 'l')
1861 || (namestring [(nsl = strlen (namestring)) - 1] == 'o'
1862 && namestring [nsl - 2] == '.'))
1863 {
1864 if (entry_point < bufp->n_value
1865 && entry_point >= last_o_file_start
1866 && addr == 0) /* FIXME nogood nomore */
1867 {
1868 startup_file_start = last_o_file_start;
1869 startup_file_end = bufp->n_value;
1870 }
1871 if (past_first_source_file && pst
1872 /* The gould NP1 uses low values for .o and -l symbols
1873 which are not the address. */
1874 && bufp->n_value > pst->textlow)
1875 {
1876 end_psymtab (pst, psymtab_include_list, includes_used,
afe4ca15 1877 symnum * symbol_size, bufp->n_value,
bd5635a1
RP
1878 dependency_list, dependencies_used,
1879 global_psymbols.next, static_psymbols.next);
1880 pst = (struct partial_symtab *) 0;
1881 includes_used = 0;
1882 dependencies_used = 0;
1883 }
1884 else
1885 past_first_source_file = 1;
1886 last_o_file_start = bufp->n_value;
1887 }
1888 continue;
1889
1890 case N_DATA:
1891 bufp->n_value += addr; /* Relocate */
1892 SET_NAMESTRING ();
1893 /* Check for __DYNAMIC, which is used by Sun shared libraries.
62c4f98b
JK
1894 Record it even if it's local, not global, so we can find it.
1895 Same with virtual function tables, both global and static. */
1896 if ((namestring[8] == 'C' && (strcmp ("__DYNAMIC", namestring) == 0))
1897 || VTBL_PREFIX_P ((namestring+HASH_OFFSET)))
bd5635a1
RP
1898 {
1899 /* Not really a function here, but... */
1900 record_misc_function (namestring, bufp->n_value,
1901 bufp->n_type); /* Always */
1902 }
1903 continue;
1904
1905 case N_UNDF | N_EXT:
1906 if (bufp->n_value != 0) {
1907 /* This is a "Fortran COMMON" symbol. See if the target
1908 environment knows where it has been relocated to. */
1909
1910 CORE_ADDR reladdr;
1911
1912 SET_NAMESTRING();
1913 if (target_lookup_symbol (namestring, &reladdr)) {
1914 continue; /* Error in lookup; ignore symbol for now. */
1915 }
1916 bufp->n_type ^= (N_BSS^N_UNDF); /* Define it as a bss-symbol */
1917 bufp->n_value = reladdr;
1918 goto bss_ext_symbol;
1919 }
1920 continue; /* Just undefined, not COMMON */
1921
1922 /* Lots of symbol types we can just ignore. */
1923
1924 case N_UNDF:
1925 case N_ABS:
1926 case N_BSS:
1927 case N_NBDATA:
1928 case N_NBBSS:
1929 continue;
1930
1931 /* Keep going . . .*/
1932
1933 /*
1934 * Special symbol types for GNU
1935 */
1936 case N_INDR:
1937 case N_INDR | N_EXT:
1938 case N_SETA:
1939 case N_SETA | N_EXT:
1940 case N_SETT:
1941 case N_SETT | N_EXT:
1942 case N_SETD:
1943 case N_SETD | N_EXT:
1944 case N_SETB:
1945 case N_SETB | N_EXT:
1946 case N_SETV:
1947 continue;
1948
1949 /*
1950 * Debugger symbols
1951 */
1952
1953 case N_SO: {
1954 unsigned long valu = bufp->n_value;
1955 /* Symbol number of the first symbol of this file (i.e. the N_SO
1956 if there is just one, or the first if we have a pair). */
1957 int first_symnum = symnum;
1958
1959 /* End the current partial symtab and start a new one */
1960
1961 SET_NAMESTRING();
1962
1963 /* Peek at the next symbol. If it is also an N_SO, the
1964 first one just indicates the directory. */
1965 if (symbuf_idx == symbuf_end)
1966 fill_symbuf ();
1967 bufp = &symbuf[symbuf_idx];
1968 /* n_type is only a char, so swapping swapping is irrelevant. */
1969 if (bufp->n_type == (unsigned char)N_SO)
1970 {
1971 SWAP_SYMBOL (bufp);
1972 SET_NAMESTRING ();
1973 valu = bufp->n_value;
1974 symbuf_idx++;
1975 symnum++;
1976 }
1977 valu += addr; /* Relocate */
1978
1979 if (pst && past_first_source_file)
1980 {
1981 end_psymtab (pst, psymtab_include_list, includes_used,
afe4ca15 1982 first_symnum * symbol_size, valu,
bd5635a1
RP
1983 dependency_list, dependencies_used,
1984 global_psymbols.next, static_psymbols.next);
1985 pst = (struct partial_symtab *) 0;
1986 includes_used = 0;
1987 dependencies_used = 0;
1988 }
1989 else
1990 past_first_source_file = 1;
1991
1992 pst = start_psymtab (symfile_name, addr,
1993 namestring, valu,
afe4ca15 1994 first_symnum * symbol_size,
bd5635a1 1995 global_psymbols.next, static_psymbols.next);
bd5635a1
RP
1996 continue;
1997 }
1998
1999 case N_BINCL:
2000 /* Add this bincl to the bincl_list for future EXCLs. No
2001 need to save the string; it'll be around until
2002 read_dbx_symtab function returns */
2003
2004 SET_NAMESTRING();
2005
2006 add_bincl_to_list (pst, namestring, bufp->n_value);
2007
2008 /* Mark down an include file in the current psymtab */
2009
2010 psymtab_include_list[includes_used++] = namestring;
2011 if (includes_used >= includes_allocated)
2012 {
2013 char **orig = psymtab_include_list;
2014
2015 psymtab_include_list = (char **)
2016 alloca ((includes_allocated *= 2) *
2017 sizeof (char *));
2018 bcopy (orig, psymtab_include_list,
2019 includes_used * sizeof (char *));
2020 }
2021
2022 continue;
2023
2024 case N_SOL:
2025 /* Mark down an include file in the current psymtab */
2026
2027 SET_NAMESTRING();
2028
2029 /* In C++, one may expect the same filename to come round many
2030 times, when code is coming alternately from the main file
2031 and from inline functions in other files. So I check to see
f9623881
JG
2032 if this is a file we've seen before -- either the main
2033 source file, or a previously included file.
bd5635a1
RP
2034
2035 This seems to be a lot of time to be spending on N_SOL, but
9bb30452 2036 things like "break c-exp.y:435" need to work (I
bd5635a1
RP
2037 suppose the psymtab_include_list could be hashed or put
2038 in a binary tree, if profiling shows this is a major hog). */
4a35d6e9 2039 if (pst && !strcmp (namestring, pst->filename))
f9623881 2040 continue;
bd5635a1
RP
2041 {
2042 register int i;
2043 for (i = 0; i < includes_used; i++)
2044 if (!strcmp (namestring, psymtab_include_list[i]))
2045 {
2046 i = -1;
2047 break;
2048 }
2049 if (i == -1)
2050 continue;
2051 }
2052
2053 psymtab_include_list[includes_used++] = namestring;
2054 if (includes_used >= includes_allocated)
2055 {
2056 char **orig = psymtab_include_list;
2057
2058 psymtab_include_list = (char **)
2059 alloca ((includes_allocated *= 2) *
2060 sizeof (char *));
2061 bcopy (orig, psymtab_include_list,
2062 includes_used * sizeof (char *));
2063 }
2064 continue;
2065
2066 case N_LSYM: /* Typedef or automatic variable. */
9bb30452
JG
2067 case N_STSYM: /* Data seg var -- static */
2068 case N_LCSYM: /* BSS " */
2069 case N_NBSTS: /* Gould nobase. */
2070 case N_NBLCS: /* symbols. */
2071
bd5635a1
RP
2072 SET_NAMESTRING();
2073
2074 p = (char *) strchr (namestring, ':');
2075
2076 /* Skip if there is no :. */
2077 if (!p) continue;
2078
2079 switch (p[1])
2080 {
2081 case 'T':
2082 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
2083 STRUCT_NAMESPACE, LOC_TYPEDEF,
2084 static_psymbols, bufp->n_value);
2085 if (p[2] == 't')
2086 {
2087 /* Also a typedef with the same name. */
2088 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
2089 VAR_NAMESPACE, LOC_TYPEDEF,
2090 static_psymbols, bufp->n_value);
2091 p += 1;
2092 }
2093 goto check_enum;
2094 case 't':
2095 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
2096 VAR_NAMESPACE, LOC_TYPEDEF,
2097 static_psymbols, bufp->n_value);
2098 check_enum:
2099 /* If this is an enumerated type, we need to
2100 add all the enum constants to the partial symbol
2101 table. This does not cover enums without names, e.g.
2102 "enum {a, b} c;" in C, but fortunately those are
2103 rare. There is no way for GDB to find those from the
2104 enum type without spending too much time on it. Thus
2105 to solve this problem, the compiler needs to put out separate
2106 constant symbols ('c' N_LSYMS) for enum constants in
2107 enums without names, or put out a dummy type. */
2108
2109 /* We are looking for something of the form
2110 <name> ":" ("t" | "T") [<number> "="] "e"
2111 {<constant> ":" <value> ","} ";". */
2112
2113 /* Skip over the colon and the 't' or 'T'. */
2114 p += 2;
2115 /* This type may be given a number. Skip over it. */
2116 while ((*p >= '0' && *p <= '9')
2117 || *p == '=')
2118 p++;
2119
2120 if (*p++ == 'e')
2121 {
2122 /* We have found an enumerated type. */
2123 /* According to comments in read_enum_type
2124 a comma could end it instead of a semicolon.
2125 I don't know where that happens.
2126 Accept either. */
2127 while (*p && *p != ';' && *p != ',')
2128 {
2129 char *q;
2130
2131 /* Check for and handle cretinous dbx symbol name
2132 continuation! */
2133 if (*p == '\\')
2134 p = next_symbol_text ();
2135
2136 /* Point to the character after the name
2137 of the enum constant. */
2138 for (q = p; *q && *q != ':'; q++)
2139 ;
2140 /* Note that the value doesn't matter for
2141 enum constants in psymtabs, just in symtabs. */
2142 ADD_PSYMBOL_TO_LIST (p, q - p,
2143 VAR_NAMESPACE, LOC_CONST,
2144 static_psymbols, 0);
2145 /* Point past the name. */
2146 p = q;
2147 /* Skip over the value. */
2148 while (*p && *p != ',')
2149 p++;
2150 /* Advance past the comma. */
2151 if (*p)
2152 p++;
2153 }
2154 }
2155
2156 continue;
2157 case 'c':
2158 /* Constant, e.g. from "const" in Pascal. */
2159 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
2160 VAR_NAMESPACE, LOC_CONST,
2161 static_psymbols, bufp->n_value);
2162 continue;
2163 default:
2164 /* Skip if the thing following the : is
2165 not a letter (which indicates declaration of a local
2166 variable, which we aren't interested in). */
2167 continue;
2168 }
2169
2170 case N_FUN:
2171 case N_GSYM: /* Global (extern) variable; can be
2172 data or bss (sigh). */
bd5635a1
RP
2173
2174 /* Following may probably be ignored; I'll leave them here
2175 for now (until I do Pascal and Modula 2 extensions). */
2176
2177 case N_PC: /* I may or may not need this; I
2178 suspect not. */
2179 case N_M2C: /* I suspect that I can ignore this here. */
2180 case N_SCOPE: /* Same. */
2181
2182 SET_NAMESTRING();
2183
2184 p = (char *) strchr (namestring, ':');
2185 if (!p)
2186 continue; /* Not a debugging symbol. */
2187
2188
2189
2190 /* Main processing section for debugging symbols which
2191 the initial read through the symbol tables needs to worry
2192 about. If we reach this point, the symbol which we are
2193 considering is definitely one we are interested in.
2194 p must also contain the (valid) index into the namestring
2195 which indicates the debugging type symbol. */
2196
2197 switch (p[1])
2198 {
2199 case 'c':
2200 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
2201 VAR_NAMESPACE, LOC_CONST,
2202 static_psymbols, bufp->n_value);
2203 continue;
2204 case 'S':
2205 bufp->n_value += addr; /* Relocate */
2206 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
2207 VAR_NAMESPACE, LOC_STATIC,
2208 static_psymbols, bufp->n_value);
2209 continue;
2210 case 'G':
2211 bufp->n_value += addr; /* Relocate */
c3a21801
JG
2212 /* The addresses in these entries are reported to be
2213 wrong. See the code that reads 'G's for symtabs. */
bd5635a1 2214 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
c3a21801 2215 VAR_NAMESPACE, LOC_STATIC,
bd5635a1
RP
2216 global_psymbols, bufp->n_value);
2217 continue;
2218
2219 case 't':
2220 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
2221 VAR_NAMESPACE, LOC_TYPEDEF,
9bb30452 2222 static_psymbols, bufp->n_value);
bd5635a1
RP
2223 continue;
2224
2225 case 'f':
2226 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
2227 VAR_NAMESPACE, LOC_BLOCK,
2228 static_psymbols, bufp->n_value);
2229 continue;
2230
f9623881
JG
2231 /* Global functions were ignored here, but now they
2232 are put into the global psymtab like one would expect.
2233 They're also in the misc fn vector...
2234 FIXME, why did it used to ignore these? That broke
2235 "i fun" on these functions. */
2236 case 'F':
2237 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
2238 VAR_NAMESPACE, LOC_BLOCK,
2239 global_psymbols, bufp->n_value);
2240 continue;
2241
bd5635a1
RP
2242 /* Two things show up here (hopefully); static symbols of
2243 local scope (static used inside braces) or extensions
2244 of structure symbols. We can ignore both. */
2245 case 'V':
2246 case '(':
2247 case '0':
2248 case '1':
2249 case '2':
2250 case '3':
2251 case '4':
2252 case '5':
2253 case '6':
2254 case '7':
2255 case '8':
2256 case '9':
bd5635a1
RP
2257 continue;
2258
2259 default:
2260 /* Unexpected symbol. Ignore it; perhaps it is an extension
2261 that we don't know about.
2262
2263 Someone says sun cc puts out symbols like
2264 /foo/baz/maclib::/usr/local/bin/maclib,
2265 which would get here with a symbol type of ':'. */
2266 continue;
2267 }
2268
2269 case N_EXCL:
2270
2271 SET_NAMESTRING();
2272
2273 /* Find the corresponding bincl and mark that psymtab on the
2274 psymtab dependency list */
2275 {
2276 struct partial_symtab *needed_pst =
2277 find_corresponding_bincl_psymtab (namestring, bufp->n_value);
2278
2279 /* If this include file was defined earlier in this file,
2280 leave it alone. */
2281 if (needed_pst == pst) continue;
2282
2283 if (needed_pst)
2284 {
2285 int i;
2286 int found = 0;
2287
2288 for (i = 0; i < dependencies_used; i++)
2289 if (dependency_list[i] == needed_pst)
2290 {
2291 found = 1;
2292 break;
2293 }
2294
2295 /* If it's already in the list, skip the rest. */
2296 if (found) continue;
2297
2298 dependency_list[dependencies_used++] = needed_pst;
2299 if (dependencies_used >= dependencies_allocated)
2300 {
2301 struct partial_symtab **orig = dependency_list;
2302 dependency_list =
2303 (struct partial_symtab **)
2304 alloca ((dependencies_allocated *= 2)
2305 * sizeof (struct partial_symtab *));
2306 bcopy (orig, dependency_list,
2307 (dependencies_used
2308 * sizeof (struct partial_symtab *)));
2309#ifdef DEBUG_INFO
2310 fprintf (stderr, "Had to reallocate dependency list.\n");
2311 fprintf (stderr, "New dependencies allocated: %d\n",
2312 dependencies_allocated);
2313#endif
2314 }
2315 }
2316 else
2317 error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.",
2318 symnum);
2319 }
2320 continue;
2321
2322 case N_EINCL:
2323 case N_DSLINE:
2324 case N_BSLINE:
2325 case N_SSYM: /* Claim: Structure or union element.
2326 Hopefully, I can ignore this. */
2327 case N_ENTRY: /* Alternate entry point; can ignore. */
2328 case N_MAIN: /* Can definitely ignore this. */
2329 case N_CATCH: /* These are GNU C++ extensions */
2330 case N_EHDECL: /* that can safely be ignored here. */
2331 case N_LENG:
2332 case N_BCOMM:
2333 case N_ECOMM:
2334 case N_ECOML:
2335 case N_FNAME:
2336 case N_SLINE:
2337 case N_RSYM:
2338 case N_PSYM:
2339 case N_LBRAC:
2340 case N_RBRAC:
2341 case N_NSYMS: /* Ultrix 4.0: symbol count */
0c4d2cc2 2342 case N_DEFD: /* GNU Modula-2 */
bd5635a1
RP
2343 /* These symbols aren't interesting; don't worry about them */
2344
2345 continue;
2346
2347 default:
2348 /* If we haven't found it yet, ignore it. It's probably some
2349 new type we don't know about yet. */
0c4d2cc2 2350 complain (&unknown_symtype_complaint, local_hex_string(bufp->n_type));
bd5635a1
RP
2351 continue;
2352 }
2353 }
2354
2355 /* If there's stuff to be cleaned up, clean it up. */
63989338
JG
2356 if (nlistlen > 0 /* We have some syms */
2357 && entry_point < bufp->n_value
bd5635a1
RP
2358 && entry_point >= last_o_file_start)
2359 {
2360 startup_file_start = last_o_file_start;
2361 startup_file_end = bufp->n_value;
2362 }
2363
2364 if (pst)
2365 {
2366 end_psymtab (pst, psymtab_include_list, includes_used,
afe4ca15 2367 symnum * symbol_size, end_of_text_addr,
bd5635a1
RP
2368 dependency_list, dependencies_used,
2369 global_psymbols.next, static_psymbols.next);
2370 includes_used = 0;
2371 dependencies_used = 0;
2372 pst = (struct partial_symtab *) 0;
2373 }
2374
2375 free_bincl_list ();
2376 discard_cleanups (old_chain);
2377}
2378
4a35d6e9
FF
2379/* Allocate and partially fill a partial symtab. It will be
2380 completely filled at the end of the symbol list.
2381
2382 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
2383 is the address relative to which its symbols are (incremental) or 0
2384 (normal). */
2385
bd5635a1 2386
bd5635a1
RP
2387static struct partial_symtab *
2388start_psymtab (symfile_name, addr,
2389 filename, textlow, ldsymoff, global_syms, static_syms)
2390 char *symfile_name;
2391 CORE_ADDR addr;
2392 char *filename;
2393 CORE_ADDR textlow;
2394 int ldsymoff;
2395 struct partial_symbol *global_syms;
2396 struct partial_symbol *static_syms;
2397{
2398 struct partial_symtab *result =
2399 (struct partial_symtab *) obstack_alloc (psymbol_obstack,
2400 sizeof (struct partial_symtab));
2401
2402 result->addr = addr;
2403
2404 result->symfile_name =
2405 (char *) obstack_alloc (psymbol_obstack,
2406 strlen (symfile_name) + 1);
2407 strcpy (result->symfile_name, symfile_name);
2408
2409 result->filename =
2410 (char *) obstack_alloc (psymbol_obstack,
2411 strlen (filename) + 1);
2412 strcpy (result->filename, filename);
2413
2414 result->textlow = textlow;
4a35d6e9
FF
2415 result->read_symtab_private = (char *) obstack_alloc (psymbol_obstack,
2416 sizeof (struct symloc));
2417 LDSYMOFF(result) = ldsymoff;
bd5635a1
RP
2418
2419 result->readin = 0;
2420 result->symtab = 0;
2421 result->read_symtab = dbx_psymtab_to_symtab;
2422
2423 result->globals_offset = global_syms - global_psymbols.list;
2424 result->statics_offset = static_syms - static_psymbols.list;
2425
2426 result->n_global_syms = 0;
2427 result->n_static_syms = 0;
2428
2429
2430 return result;
2431}
2432
2433static int
2434compare_psymbols (s1, s2)
2435 register struct partial_symbol *s1, *s2;
2436{
2437 register char
2438 *st1 = SYMBOL_NAME (s1),
2439 *st2 = SYMBOL_NAME (s2);
2440
0c4d2cc2
JG
2441 if (st1[0] - st2[0])
2442 return st1[0] - st2[0];
2443 if (st1[1] - st2[1])
2444 return st1[1] - st2[1];
2445 return strcmp (st1 + 1, st2 + 1);
bd5635a1
RP
2446}
2447
2448
2449/* Close off the current usage of a partial_symbol table entry. This
2450 involves setting the correct number of includes (with a realloc),
2451 setting the high text mark, setting the symbol length in the
2452 executable, and setting the length of the global and static lists
2453 of psymbols.
2454
2455 The global symbols and static symbols are then seperately sorted.
2456
2457 Then the partial symtab is put on the global list.
2458 *** List variables and peculiarities of same. ***
2459 */
2460static void
2461end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
2462 capping_text, dependency_list, number_dependencies,
2463 capping_global, capping_static)
2464 struct partial_symtab *pst;
2465 char **include_list;
2466 int num_includes;
2467 int capping_symbol_offset;
2468 CORE_ADDR capping_text;
2469 struct partial_symtab **dependency_list;
2470 int number_dependencies;
2471 struct partial_symbol *capping_global, *capping_static;
2472{
2473 int i;
2474
4a35d6e9 2475 LDSYMLEN(pst) = capping_symbol_offset - LDSYMOFF(pst);
bd5635a1
RP
2476 pst->texthigh = capping_text;
2477
2478 pst->n_global_syms =
2479 capping_global - (global_psymbols.list + pst->globals_offset);
2480 pst->n_static_syms =
2481 capping_static - (static_psymbols.list + pst->statics_offset);
2482
2483 pst->number_of_dependencies = number_dependencies;
2484 if (number_dependencies)
2485 {
2486 pst->dependencies = (struct partial_symtab **)
2487 obstack_alloc (psymbol_obstack,
2488 number_dependencies * sizeof (struct partial_symtab *));
2489 bcopy (dependency_list, pst->dependencies,
2490 number_dependencies * sizeof (struct partial_symtab *));
2491 }
2492 else
2493 pst->dependencies = 0;
2494
2495 for (i = 0; i < num_includes; i++)
2496 {
2497 /* Eventually, put this on obstack */
2498 struct partial_symtab *subpst =
2499 (struct partial_symtab *)
2500 obstack_alloc (psymbol_obstack,
2501 sizeof (struct partial_symtab));
2502
2503 subpst->filename =
2504 (char *) obstack_alloc (psymbol_obstack,
2505 strlen (include_list[i]) + 1);
2506 strcpy (subpst->filename, include_list[i]);
2507
2508 subpst->symfile_name = pst->symfile_name;
2509 subpst->addr = pst->addr;
4a35d6e9
FF
2510 subpst->read_symtab_private = (char *) obstack_alloc (psymbol_obstack,
2511 sizeof (struct symloc));
2512 LDSYMOFF(subpst) =
2513 LDSYMLEN(subpst) =
bd5635a1
RP
2514 subpst->textlow =
2515 subpst->texthigh = 0;
2516
3f83182d
JG
2517 /* We could save slight bits of space by only making one of these,
2518 shared by the entire set of include files. FIXME-someday. */
bd5635a1
RP
2519 subpst->dependencies = (struct partial_symtab **)
2520 obstack_alloc (psymbol_obstack,
2521 sizeof (struct partial_symtab *));
2522 subpst->dependencies[0] = pst;
2523 subpst->number_of_dependencies = 1;
2524
2525 subpst->globals_offset =
2526 subpst->n_global_syms =
2527 subpst->statics_offset =
2528 subpst->n_static_syms = 0;
2529
2530 subpst->readin = 0;
9a822037 2531 subpst->symtab = 0;
bd5635a1
RP
2532 subpst->read_symtab = dbx_psymtab_to_symtab;
2533
2534 subpst->next = partial_symtab_list;
2535 partial_symtab_list = subpst;
2536 }
2537
2538 /* Sort the global list; don't sort the static list */
2539 qsort (global_psymbols.list + pst->globals_offset, pst->n_global_syms,
2540 sizeof (struct partial_symbol), compare_psymbols);
2541
f9623881
JG
2542 /* If there is already a psymtab or symtab for a file of this name, remove it.
2543 (If there is a symtab, more drastic things also happen.)
2544 This happens in VxWorks. */
2545 free_named_symtabs (pst->filename);
2546
bd5635a1
RP
2547 /* Put the psymtab on the psymtab list */
2548 pst->next = partial_symtab_list;
2549 partial_symtab_list = pst;
2550}
2551\f
2552static void
2553psymtab_to_symtab_1 (pst, desc, stringtab, stringtab_size, sym_offset)
2554 struct partial_symtab *pst;
2555 int desc;
2556 char *stringtab;
2557 int stringtab_size;
2558 int sym_offset;
2559{
2560 struct cleanup *old_chain;
2561 int i;
2562
2563 if (!pst)
2564 return;
2565
2566 if (pst->readin)
2567 {
2568 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
2569 pst->filename);
2570 return;
2571 }
2572
afe4ca15 2573 /* Read in all partial symtabs on which this one is dependent */
bd5635a1
RP
2574 for (i = 0; i < pst->number_of_dependencies; i++)
2575 if (!pst->dependencies[i]->readin)
2576 {
2577 /* Inform about additional files that need to be read in. */
2578 if (info_verbose)
2579 {
2580 fputs_filtered (" ", stdout);
2581 wrap_here ("");
2582 fputs_filtered ("and ", stdout);
2583 wrap_here ("");
2584 printf_filtered ("%s...", pst->dependencies[i]->filename);
2585 wrap_here (""); /* Flush output */
2586 fflush (stdout);
2587 }
2588 psymtab_to_symtab_1 (pst->dependencies[i], desc,
2589 stringtab, stringtab_size, sym_offset);
2590 }
2591
4a35d6e9 2592 if (LDSYMLEN(pst)) /* Otherwise it's a dummy */
bd5635a1
RP
2593 {
2594 /* Init stuff necessary for reading in symbols */
2595 free_pendings = 0;
2596 pending_blocks = 0;
2597 file_symbols = 0;
2598 global_symbols = 0;
2599 old_chain = make_cleanup (really_free_pendings, 0);
2600
2601 /* Read in this files symbols */
2602 lseek (desc, sym_offset, L_SET);
9404978d
MT
2603 pst->symtab =
2604 read_ofile_symtab (desc, stringtab, stringtab_size,
4a35d6e9
FF
2605 LDSYMOFF(pst),
2606 LDSYMLEN(pst), pst->textlow,
9404978d
MT
2607 pst->texthigh - pst->textlow, pst->addr);
2608 sort_symtab_syms (pst->symtab);
bd5635a1
RP
2609
2610 do_cleanups (old_chain);
2611 }
2612
2613 pst->readin = 1;
2614}
2615
2616/*
2617 * Read in all of the symbols for a given psymtab for real.
2618 * Be verbose about it if the user wants that.
2619 */
2620static void
2621dbx_psymtab_to_symtab (pst)
2622 struct partial_symtab *pst;
2623{
2624 int desc;
2625 char *stringtab;
2626 int stsize, val;
2627 struct stat statbuf;
2628 struct cleanup *old_chain;
2629 bfd *sym_bfd;
2630 long st_temp;
2631
2632 if (!pst)
2633 return;
2634
2635 if (pst->readin)
2636 {
2637 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
2638 pst->filename);
2639 return;
2640 }
2641
4a35d6e9 2642 if (LDSYMLEN(pst) || pst->number_of_dependencies)
bd5635a1
RP
2643 {
2644 /* Print the message now, before reading the string table,
2645 to avoid disconcerting pauses. */
2646 if (info_verbose)
2647 {
2648 printf_filtered ("Reading in symbols for %s...", pst->filename);
2649 fflush (stdout);
2650 }
2651
2652 /* Open symbol file and read in string table. Symbol_file_command
2653 guarantees that the symbol file name will be absolute, so there is
2654 no need for openp. */
2655 desc = open(pst->symfile_name, O_RDONLY, 0);
2656
2657 if (desc < 0)
2658 perror_with_name (pst->symfile_name);
2659
2660 sym_bfd = bfd_fdopenr (pst->symfile_name, NULL, desc);
2661 if (!sym_bfd)
2662 {
2663 (void)close (desc);
2664 error ("Could not open `%s' to read symbols: %s",
2665 pst->symfile_name, bfd_errmsg (bfd_error));
2666 }
2667 old_chain = make_cleanup (bfd_close, sym_bfd);
2668 if (!bfd_check_format (sym_bfd, bfd_object))
2669 error ("\"%s\": can't read symbols: %s.",
2670 pst->symfile_name, bfd_errmsg (bfd_error));
2671
2672 /* We keep the string table for symfile resident in memory, but
2673 not the string table for any other symbol files. */
66eeea27 2674 if ((symfile == 0) || 0 != strcmp(pst->symfile_name, symfile))
bd5635a1
RP
2675 {
2676 /* Read in the string table */
2677
2678 /* FIXME, this uses internal BFD variables. See above in
2679 dbx_symbol_file_open where the macro is defined! */
2680 lseek (desc, STRING_TABLE_OFFSET, L_SET);
2681
2682 val = myread (desc, &st_temp, sizeof st_temp);
2683 if (val < 0)
2684 perror_with_name (pst->symfile_name);
dcc35536 2685 stsize = bfd_h_get_32 (sym_bfd, (unsigned char *)&st_temp);
bd5635a1
RP
2686 if (fstat (desc, &statbuf) < 0)
2687 perror_with_name (pst->symfile_name);
2688
2689 if (stsize >= 0 && stsize < statbuf.st_size)
2690 {
2691#ifdef BROKEN_LARGE_ALLOCA
2692 stringtab = (char *) xmalloc (stsize);
2693 make_cleanup (free, stringtab);
2694#else
2695 stringtab = (char *) alloca (stsize);
2696#endif
2697 }
2698 else
2699 stringtab = NULL;
2700 if (stringtab == NULL && stsize != 0)
2701 error ("ridiculous string table size: %d bytes", stsize);
2702
2703 /* FIXME, this uses internal BFD variables. See above in
2704 dbx_symbol_file_open where the macro is defined! */
2705 val = lseek (desc, STRING_TABLE_OFFSET, L_SET);
2706 if (val < 0)
2707 perror_with_name (pst->symfile_name);
2708 val = myread (desc, stringtab, stsize);
2709 if (val < 0)
2710 perror_with_name (pst->symfile_name);
2711 }
2712 else
2713 {
2714 stringtab = symfile_string_table;
2715 stsize = symfile_string_table_size;
2716 }
2717
2718 symfile_bfd = sym_bfd; /* Kludge for SWAP_SYMBOL */
afe4ca15
JG
2719 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
2720 symbol_size = obj_symbol_entry_size (sym_bfd);
bd5635a1
RP
2721
2722 /* FIXME, this uses internal BFD variables. See above in
2723 dbx_symbol_file_open where the macro is defined! */
2724 psymtab_to_symtab_1 (pst, desc, stringtab, stsize,
2725 SYMBOL_TABLE_OFFSET);
2726
2727 /* Match with global symbols. This only needs to be done once,
2728 after all of the symtabs and dependencies have been read in. */
2729 scan_file_globals ();
2730
2731 do_cleanups (old_chain);
2732
2733 /* Finish up the debug error message. */
2734 if (info_verbose)
2735 printf_filtered ("done.\n");
2736 }
2737}
2738
2739/*
2740 * Scan through all of the global symbols defined in the object file,
2741 * assigning values to the debugging symbols that need to be assigned
2742 * to. Get these symbols from the misc function list.
2743 */
2744static void
2745scan_file_globals ()
2746{
2747 int hash;
2748 int mf;
2749
2750 for (mf = 0; mf < misc_function_count; mf++)
2751 {
2752 char *namestring = misc_function_vector[mf].name;
2753 struct symbol *sym, *prev;
2754
2755 QUIT;
2756
2757 prev = (struct symbol *) 0;
2758
2759 /* Get the hash index and check all the symbols
2760 under that hash index. */
2761
2762 hash = hashname (namestring);
2763
2764 for (sym = global_sym_chain[hash]; sym;)
2765 {
2766 if (*namestring == SYMBOL_NAME (sym)[0]
2767 && !strcmp(namestring + 1, SYMBOL_NAME (sym) + 1))
2768 {
2769 /* Splice this symbol out of the hash chain and
2770 assign the value we have to it. */
2771 if (prev)
2772 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
2773 else
2774 global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
2775
2776 /* Check to see whether we need to fix up a common block. */
2777 /* Note: this code might be executed several times for
2778 the same symbol if there are multiple references. */
2779 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
2780 fix_common_block (sym, misc_function_vector[mf].address);
2781 else
2782 SYMBOL_VALUE_ADDRESS (sym) = misc_function_vector[mf].address;
2783
2784 if (prev)
2785 sym = SYMBOL_VALUE_CHAIN (prev);
2786 else
2787 sym = global_sym_chain[hash];
2788 }
2789 else
2790 {
2791 prev = sym;
2792 sym = SYMBOL_VALUE_CHAIN (sym);
2793 }
2794 }
2795 }
2796}
2797
2798/* Process a pair of symbols. Currently they must both be N_SO's. */
0c4d2cc2 2799/* ARGSUSED */
bd5635a1
RP
2800static void
2801process_symbol_pair (type1, desc1, value1, name1,
2802 type2, desc2, value2, name2)
2803 int type1;
2804 int desc1;
2805 CORE_ADDR value1;
2806 char *name1;
2807 int type2;
2808 int desc2;
2809 CORE_ADDR value2;
2810 char *name2;
2811{
2812 /* No need to check PCC_SOL_BROKEN, on the assumption that such
2813 broken PCC's don't put out N_SO pairs. */
2814 if (last_source_file)
9404978d 2815 (void)end_symtab (value2);
bd5635a1
RP
2816 start_symtab (name2, name1, value2);
2817}
2818
2819/*
2820 * Read in a defined section of a specific object file's symbols.
2821 *
2822 * DESC is the file descriptor for the file, positioned at the
2823 * beginning of the symtab
2824 * STRINGTAB is a pointer to the files string
2825 * table, already read in
2826 * SYM_OFFSET is the offset within the file of
2827 * the beginning of the symbols we want to read, NUM_SUMBOLS is the
2828 * number of symbols to read
2829 * TEXT_OFFSET is the beginning of the text segment we are reading symbols for
2830 * TEXT_SIZE is the size of the text segment read in.
2831 * OFFSET is a relocation offset which gets added to each symbol
2832 */
2833
9404978d 2834static struct symtab *
bd5635a1
RP
2835read_ofile_symtab (desc, stringtab, stringtab_size, sym_offset,
2836 sym_size, text_offset, text_size, offset)
2837 int desc;
2838 register char *stringtab;
2839 unsigned int stringtab_size;
2840 int sym_offset;
2841 int sym_size;
2842 CORE_ADDR text_offset;
2843 int text_size;
2844 int offset;
2845{
2846 register char *namestring;
afe4ca15 2847 struct internal_nlist *bufp;
bd5635a1 2848 unsigned char type;
afe4ca15 2849 unsigned max_symnum;
bd5635a1
RP
2850 subfile_stack = 0;
2851
2852 stringtab_global = stringtab;
2853 last_source_file = 0;
2854
2855 symtab_input_desc = desc;
2856 symbuf_end = symbuf_idx = 0;
2857
2858 /* It is necessary to actually read one symbol *before* the start
2859 of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
2860 occurs before the N_SO symbol.
2861
2862 Detecting this in read_dbx_symtab
2863 would slow down initial readin, so we look for it here instead. */
afe4ca15 2864 if (sym_offset >= (int)symbol_size)
bd5635a1 2865 {
afe4ca15 2866 lseek (desc, sym_offset - symbol_size, L_INCR);
bd5635a1
RP
2867 fill_symbuf ();
2868 bufp = &symbuf[symbuf_idx++];
2869 SWAP_SYMBOL (bufp);
2870
afe4ca15 2871 SET_NAMESTRING ();
bd5635a1
RP
2872
2873 processing_gcc_compilation =
2874 (bufp->n_type == N_TEXT
2875 && !strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL));
afe4ca15 2876 /* FIXME!!! Check for gcc2_compiled... */
bd5635a1
RP
2877 }
2878 else
2879 {
2880 /* The N_SO starting this symtab is the first symbol, so we
2881 better not check the symbol before it. I'm not this can
2882 happen, but it doesn't hurt to check for it. */
2883 lseek(desc, sym_offset, L_INCR);
2884 processing_gcc_compilation = 0;
2885 }
2886
2887 if (symbuf_idx == symbuf_end)
2888 fill_symbuf();
2889 bufp = &symbuf[symbuf_idx];
2890 if (bufp->n_type != (unsigned char)N_SO)
2891 error("First symbol in segment of executable not a source symbol");
2892
afe4ca15
JG
2893 max_symnum = sym_size / symbol_size;
2894
bd5635a1 2895 for (symnum = 0;
afe4ca15 2896 symnum < max_symnum;
bd5635a1
RP
2897 symnum++)
2898 {
2899 QUIT; /* Allow this to be interruptable */
2900 if (symbuf_idx == symbuf_end)
2901 fill_symbuf();
2902 bufp = &symbuf[symbuf_idx++];
2903 SWAP_SYMBOL (bufp);
2904
2905 type = bufp->n_type & N_TYPE;
2906 if (type == (unsigned char)N_CATCH)
2907 {
2908 /* N_CATCH is not fixed up by the linker, and unfortunately,
2909 there's no other place to put it in the .stab map. */
62c4f98b 2910 bufp->n_value += text_offset + offset;
bd5635a1
RP
2911 }
2912 else if (type == N_TEXT || type == N_DATA || type == N_BSS)
2913 bufp->n_value += offset;
2914
2915 type = bufp->n_type;
afe4ca15 2916 SET_NAMESTRING ();
bd5635a1
RP
2917
2918 if (type & N_STAB)
2919 {
e1ce8aa5 2920 short bufp_n_desc = bufp->n_desc;
bd5635a1
RP
2921 unsigned long valu = bufp->n_value;
2922
2923 /* Check for a pair of N_SO symbols. */
2924 if (type == (unsigned char)N_SO)
2925 {
2926 if (symbuf_idx == symbuf_end)
2927 fill_symbuf ();
2928 bufp = &symbuf[symbuf_idx];
2929 if (bufp->n_type == (unsigned char)N_SO)
2930 {
afe4ca15 2931 char *namestring1 = namestring;
bd5635a1
RP
2932
2933 SWAP_SYMBOL (bufp);
2934 bufp->n_value += offset; /* Relocate */
2935 symbuf_idx++;
2936 symnum++;
afe4ca15 2937 SET_NAMESTRING ();
bd5635a1 2938
afe4ca15 2939 process_symbol_pair (N_SO, bufp_n_desc, valu, namestring1,
bd5635a1 2940 N_SO, bufp->n_desc, bufp->n_value,
afe4ca15 2941 namestring);
bd5635a1
RP
2942 }
2943 else
e1ce8aa5 2944 process_one_symbol(type, bufp_n_desc, valu, namestring);
bd5635a1
RP
2945 }
2946 else
e1ce8aa5 2947 process_one_symbol (type, bufp_n_desc, valu, namestring);
bd5635a1
RP
2948 }
2949 /* We skip checking for a new .o or -l file; that should never
2950 happen in this routine. */
2951 else if (type == N_TEXT
2952 && !strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL))
2953 /* I don't think this code will ever be executed, because
2954 the GCC_COMPILED_FLAG_SYMBOL usually is right before
2955 the N_SO symbol which starts this source file.
2956 However, there is no reason not to accept
2957 the GCC_COMPILED_FLAG_SYMBOL anywhere. */
2958 processing_gcc_compilation = 1;
2959 else if (type & N_EXT || type == (unsigned char)N_TEXT
2960 || type == (unsigned char)N_NBTEXT
0c4d2cc2 2961 ) {
bd5635a1
RP
2962 /* Global symbol: see if we came across a dbx defintion for
2963 a corresponding symbol. If so, store the value. Remove
2964 syms from the chain when their values are stored, but
2965 search the whole chain, as there may be several syms from
2966 different files with the same name. */
2967 /* This is probably not true. Since the files will be read
2968 in one at a time, each reference to a global symbol will
2969 be satisfied in each file as it appears. So we skip this
2970 section. */
2971 ;
0c4d2cc2 2972 }
bd5635a1 2973 }
9404978d
MT
2974
2975 return end_symtab (text_offset + text_size);
bd5635a1
RP
2976}
2977\f
2978static int
2979hashname (name)
2980 char *name;
2981{
2982 register char *p = name;
2983 register int total = p[0];
2984 register int c;
2985
2986 c = p[1];
2987 total += c << 2;
2988 if (c)
2989 {
2990 c = p[2];
2991 total += c << 4;
2992 if (c)
2993 total += p[3] << 6;
2994 }
2995
2996 /* Ensure result is positive. */
2997 if (total < 0) total += (1000 << 6);
2998 return total % HASHSIZE;
2999}
3000
3001\f
3002static void
3003process_one_symbol (type, desc, valu, name)
3004 int type, desc;
3005 CORE_ADDR valu;
3006 char *name;
3007{
3008#ifndef SUN_FIXED_LBRAC_BUG
3009 /* This records the last pc address we've seen. We depend on their being
3010 an SLINE or FUN or SO before the first LBRAC, since the variable does
3011 not get reset in between reads of different symbol files. */
3012 static CORE_ADDR last_pc_address;
3013#endif
3014 register struct context_stack *new;
3015 char *colon_pos;
3016
3017 /* Something is wrong if we see real data before
3018 seeing a source file name. */
3019
3020 if (last_source_file == 0 && type != (unsigned char)N_SO)
3021 {
3022 /* Currently this ignores N_ENTRY on Gould machines, N_NSYM on machines
3023 where that code is defined. */
3024 if (IGNORE_SYMBOL (type))
3025 return;
3026
3027 /* FIXME, this should not be an error, since it precludes extending
3028 the symbol table information in this way... */
3029 error ("Invalid symbol data: does not start by identifying a source file.");
3030 }
3031
3032 switch (type)
3033 {
3034 case N_FUN:
3035 case N_FNAME:
3036 /* Either of these types of symbols indicates the start of
3037 a new function. We must process its "name" normally for dbx,
3038 but also record the start of a new lexical context, and possibly
3039 also the end of the lexical context for the previous function. */
3040 /* This is not always true. This type of symbol may indicate a
3041 text segment variable. */
3042
3043#ifndef SUN_FIXED_LBRAC_BUG
3044 last_pc_address = valu; /* Save for SunOS bug circumcision */
3045#endif
3046
3047 colon_pos = strchr (name, ':');
3048 if (!colon_pos++
3049 || (*colon_pos != 'f' && *colon_pos != 'F'))
3050 {
3051 define_symbol (valu, name, desc, type);
3052 break;
3053 }
3054
3055 within_function = 1;
3056 if (context_stack_depth > 0)
3057 {
3058 new = &context_stack[--context_stack_depth];
3059 /* Make a block for the local symbols within. */
3060 finish_block (new->name, &local_symbols, new->old_blocks,
3061 new->start_addr, valu);
3062 }
3063 /* Stack must be empty now. */
3064 if (context_stack_depth != 0)
3065 error ("Invalid symbol data: unmatched N_LBRAC before symtab pos %d.",
3066 symnum);
3067
3068 new = &context_stack[context_stack_depth++];
3069 new->old_blocks = pending_blocks;
3070 new->start_addr = valu;
3071 new->name = define_symbol (valu, name, desc, type);
3072 local_symbols = 0;
3073 break;
3074
3075 case N_CATCH:
3076 /* Record the address at which this catch takes place. */
3077 define_symbol (valu, name, desc, type);
3078 break;
3079
3080 case N_EHDECL:
3081 /* Don't know what to do with these yet. */
3082 error ("action uncertain for eh extensions");
3083 break;
3084
3085 case N_LBRAC:
3086 /* This "symbol" just indicates the start of an inner lexical
3087 context within a function. */
3088
3089#if !defined (BLOCK_ADDRESS_ABSOLUTE)
3090 /* On most machines, the block addresses are relative to the
3091 N_SO, the linker did not relocate them (sigh). */
3092 valu += last_source_start_addr;
3093#endif
3094
3095#ifndef SUN_FIXED_LBRAC_BUG
3096 if (valu < last_pc_address) {
3097 /* Patch current LBRAC pc value to match last handy pc value */
3098 complain (&lbrac_complaint, 0);
3099 valu = last_pc_address;
3100 }
3101#endif
3102 if (context_stack_depth == context_stack_size)
3103 {
3104 context_stack_size *= 2;
3105 context_stack = (struct context_stack *)
3106 xrealloc (context_stack,
3107 (context_stack_size
3108 * sizeof (struct context_stack)));
3109 }
3110
3111 new = &context_stack[context_stack_depth++];
3112 new->depth = desc;
3113 new->locals = local_symbols;
3114 new->old_blocks = pending_blocks;
3115 new->start_addr = valu;
3116 new->name = 0;
3117 local_symbols = 0;
3118 break;
3119
3120 case N_RBRAC:
3121 /* This "symbol" just indicates the end of an inner lexical
3122 context that was started with N_LBRAC. */
3123
3124#if !defined (BLOCK_ADDRESS_ABSOLUTE)
3125 /* On most machines, the block addresses are relative to the
3126 N_SO, the linker did not relocate them (sigh). */
3127 valu += last_source_start_addr;
3128#endif
3129
3130 new = &context_stack[--context_stack_depth];
3131 if (desc != new->depth)
3132 error ("Invalid symbol data: N_LBRAC/N_RBRAC symbol mismatch, symtab pos %d.", symnum);
3133
3134 /* Some compilers put the variable decls inside of an
3135 LBRAC/RBRAC block. This macro should be nonzero if this
3136 is true. DESC is N_DESC from the N_RBRAC symbol.
3137 GCC_P is true if we've detected the GCC_COMPILED_SYMBOL. */
3138#if !defined (VARIABLES_INSIDE_BLOCK)
3139#define VARIABLES_INSIDE_BLOCK(desc, gcc_p) 0
3140#endif
3141
3142 /* Can only use new->locals as local symbols here if we're in
3143 gcc or on a machine that puts them before the lbrack. */
3144 if (!VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation))
3145 local_symbols = new->locals;
3146
3147 /* If this is not the outermost LBRAC...RBRAC pair in the
3148 function, its local symbols preceded it, and are the ones
3149 just recovered from the context stack. Defined the block for them.
3150
3151 If this is the outermost LBRAC...RBRAC pair, there is no
3152 need to do anything; leave the symbols that preceded it
3153 to be attached to the function's own block. However, if
3154 it is so, we need to indicate that we just moved outside
3155 of the function. */
3156 if (local_symbols
3157 && (context_stack_depth
3158 > !VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation)))
3159 {
3160 /* FIXME Muzzle a compiler bug that makes end < start. */
3161 if (new->start_addr > valu)
3162 {
3163 complain(&lbrac_rbrac_complaint, 0);
3164 new->start_addr = valu;
3165 }
3166 /* Make a block for the local symbols within. */
3167 finish_block (0, &local_symbols, new->old_blocks,
3168 new->start_addr, valu);
3169 }
3170 else
3171 {
3172 within_function = 0;
3173 }
3174 if (VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation))
3175 /* Now pop locals of block just finished. */
3176 local_symbols = new->locals;
3177 break;
3178
9bb30452 3179 case N_FN:
6150cc73 3180 case N_FN_SEQ:
9bb30452 3181 /* This kind of symbol indicates the start of an object file. */
bd5635a1
RP
3182 break;
3183
3184 case N_SO:
3185 /* This type of symbol indicates the start of data
3186 for one source file.
3187 Finish the symbol table of the previous source file
3188 (if any) and start accumulating a new symbol table. */
3189#ifndef SUN_FIXED_LBRAC_BUG
3190 last_pc_address = valu; /* Save for SunOS bug circumcision */
3191#endif
3192
3193#ifdef PCC_SOL_BROKEN
3194 /* pcc bug, occasionally puts out SO for SOL. */
3195 if (context_stack_depth > 0)
3196 {
3197 start_subfile (name, NULL);
3198 break;
3199 }
3200#endif
3201 if (last_source_file)
9404978d 3202 (void)end_symtab (valu);
bd5635a1
RP
3203 start_symtab (name, NULL, valu);
3204 break;
3205
3206 case N_SOL:
3207 /* This type of symbol indicates the start of data for
3208 a sub-source-file, one whose contents were copied or
3209 included in the compilation of the main source file
3210 (whose name was given in the N_SO symbol.) */
3211 start_subfile (name, NULL);
3212 break;
3213
3214 case N_BINCL:
3215 push_subfile ();
3216 add_new_header_file (name, valu);
3217 start_subfile (name, NULL);
3218 break;
3219
3220 case N_EINCL:
3221 start_subfile (pop_subfile (), NULL);
3222 break;
3223
3224 case N_EXCL:
3225 add_old_header_file (name, valu);
3226 break;
3227
3228 case N_SLINE:
3229 /* This type of "symbol" really just records
3230 one line-number -- core-address correspondence.
3231 Enter it in the line list for this symbol table. */
3232#ifndef SUN_FIXED_LBRAC_BUG
3233 last_pc_address = valu; /* Save for SunOS bug circumcision */
3234#endif
3235 record_line (desc, valu);
3236 break;
3237
3238 case N_BCOMM:
3239 if (common_block)
3240 error ("Invalid symbol data: common within common at symtab pos %d",
3241 symnum);
3242 common_block = local_symbols;
3243 common_block_i = local_symbols ? local_symbols->nsyms : 0;
3244 break;
3245
3246 case N_ECOMM:
3247 /* Symbols declared since the BCOMM are to have the common block
3248 start address added in when we know it. common_block points to
3249 the first symbol after the BCOMM in the local_symbols list;
3250 copy the list and hang it off the symbol for the common block name
3251 for later fixup. */
3252 {
3253 int i;
3254 struct symbol *sym =
3255 (struct symbol *) xmalloc (sizeof (struct symbol));
3256 bzero (sym, sizeof *sym);
3257 SYMBOL_NAME (sym) = savestring (name, strlen (name));
3258 SYMBOL_CLASS (sym) = LOC_BLOCK;
3259 SYMBOL_NAMESPACE (sym) = (enum namespace)((long)
3260 copy_pending (local_symbols, common_block_i, common_block));
3261 i = hashname (SYMBOL_NAME (sym));
3262 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
3263 global_sym_chain[i] = sym;
3264 common_block = 0;
3265 break;
3266 }
3267
3268 case N_ECOML:
3269 case N_LENG:
0c4d2cc2 3270 case N_DEFD: /* GNU Modula-2 symbol */
bd5635a1
RP
3271 break;
3272
3273 default:
3274 if (name)
3275 define_symbol (valu, name, desc, type);
3276 }
3277}
3278\f
3279/* Read a number by which a type is referred to in dbx data,
3280 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
3281 Just a single number N is equivalent to (0,N).
3282 Return the two numbers by storing them in the vector TYPENUMS.
3283 TYPENUMS will then be used as an argument to dbx_lookup_type. */
3284
3285static void
3286read_type_number (pp, typenums)
3287 register char **pp;
3288 register int *typenums;
3289{
3290 if (**pp == '(')
3291 {
3292 (*pp)++;
3293 typenums[0] = read_number (pp, ',');
3294 typenums[1] = read_number (pp, ')');
3295 }
3296 else
3297 {
3298 typenums[0] = 0;
3299 typenums[1] = read_number (pp, 0);
3300 }
3301}
3302\f
3303/* To handle GNU C++ typename abbreviation, we need to be able to
3304 fill in a type's name as soon as space for that type is allocated.
3305 `type_synonym_name' is the name of the type being allocated.
3306 It is cleared as soon as it is used (lest all allocated types
3307 get this name). */
3308static char *type_synonym_name;
3309
0c4d2cc2 3310/* ARGSUSED */
bd5635a1
RP
3311static struct symbol *
3312define_symbol (valu, string, desc, type)
3313 unsigned int valu;
3314 char *string;
3315 int desc;
3316 int type;
3317{
3318 register struct symbol *sym;
3319 char *p = (char *) strchr (string, ':');
3320 int deftype;
3321 int synonym = 0;
3322 register int i;
3323
3324 /* Ignore syms with empty names. */
3325 if (string[0] == 0)
3326 return 0;
3327
3328 /* Ignore old-style symbols from cc -go */
3329 if (p == 0)
3330 return 0;
3331
3332 sym = (struct symbol *)obstack_alloc (symbol_obstack, sizeof (struct symbol));
3333
3334 if (processing_gcc_compilation) {
3335 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
3336 number of bytes occupied by a type or object, which we ignore. */
3337 SYMBOL_LINE(sym) = desc;
3338 } else {
3339 SYMBOL_LINE(sym) = 0; /* unknown */
3340 }
aec4cb91 3341
bd5635a1
RP
3342 if (string[0] == CPLUS_MARKER)
3343 {
3344 /* Special GNU C++ names. */
3345 switch (string[1])
3346 {
3347 case 't':
3348 SYMBOL_NAME (sym) = "this";
3349 break;
3350 case 'v': /* $vtbl_ptr_type */
3351 /* Was: SYMBOL_NAME (sym) = "vptr"; */
3352 goto normal;
3353 case 'e':
3354 SYMBOL_NAME (sym) = "eh_throw";
3355 break;
3356
3357 case '_':
3358 /* This was an anonymous type that was never fixed up. */
3359 goto normal;
3360
3361 default:
3362 abort ();
3363 }
3364 }
3365 else
3366 {
3367 normal:
3368 SYMBOL_NAME (sym)
3369 = (char *) obstack_alloc (symbol_obstack, ((p - string) + 1));
3370 /* Open-coded bcopy--saves function call time. */
3371 {
3372 register char *p1 = string;
3373 register char *p2 = SYMBOL_NAME (sym);
3374 while (p1 != p)
3375 *p2++ = *p1++;
3376 *p2++ = '\0';
3377 }
3378 }
3379 p++;
3380 /* Determine the type of name being defined. */
3381 /* The Acorn RISC machine's compiler can put out locals that don't
3382 start with "234=" or "(3,4)=", so assume anything other than the
3383 deftypes we know how to handle is a local. */
3384 /* (Peter Watkins @ Computervision)
3385 Handle Sun-style local fortran array types 'ar...' .
3386 (gnu@cygnus.com) -- this strchr() handles them properly?
3387 (tiemann@cygnus.com) -- 'C' is for catch. */
3388 if (!strchr ("cfFGpPrStTvVXC", *p))
3389 deftype = 'l';
3390 else
3391 deftype = *p++;
3392
3393 /* c is a special case, not followed by a type-number.
3394 SYMBOL:c=iVALUE for an integer constant symbol.
3395 SYMBOL:c=rVALUE for a floating constant symbol.
3396 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
3397 e.g. "b:c=e6,0" for "const b = blob1"
3398 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
3399 if (deftype == 'c')
3400 {
3401 if (*p++ != '=')
3402 error ("Invalid symbol data at symtab pos %d.", symnum);
3403 switch (*p++)
3404 {
3405 case 'r':
3406 {
3407 double d = atof (p);
e1ce8aa5 3408 char *dbl_valu;
bd5635a1
RP
3409
3410 SYMBOL_TYPE (sym) = builtin_type_double;
e1ce8aa5
JK
3411 dbl_valu =
3412 (char *) obstack_alloc (symbol_obstack, sizeof (double));
3413 bcopy (&d, dbl_valu, sizeof (double));
3414 SWAP_TARGET_AND_HOST (dbl_valu, sizeof (double));
3415 SYMBOL_VALUE_BYTES (sym) = dbl_valu;
bd5635a1
RP
3416 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
3417 }
3418 break;
3419 case 'i':
3420 {
3421 SYMBOL_TYPE (sym) = builtin_type_int;
3422 SYMBOL_VALUE (sym) = atoi (p);
3423 SYMBOL_CLASS (sym) = LOC_CONST;
3424 }
3425 break;
3426 case 'e':
3427 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
3428 e.g. "b:c=e6,0" for "const b = blob1"
3429 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
3430 {
3431 int typenums[2];
3432
3433 read_type_number (&p, typenums);
3434 if (*p++ != ',')
3435 error ("Invalid symbol data: no comma in enum const symbol");
3436
3437 SYMBOL_TYPE (sym) = *dbx_lookup_type (typenums);
3438 SYMBOL_VALUE (sym) = atoi (p);
3439 SYMBOL_CLASS (sym) = LOC_CONST;
3440 }
3441 break;
3442 default:
3443 error ("Invalid symbol data at symtab pos %d.", symnum);
3444 }
3445 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3446 add_symbol_to_list (sym, &file_symbols);
3447 return sym;
3448 }
3449
3450 /* Now usually comes a number that says which data type,
3451 and possibly more stuff to define the type
3452 (all of which is handled by read_type) */
3453
3454 if (deftype == 'p' && *p == 'F')
3455 /* pF is a two-letter code that means a function parameter in Fortran.
3456 The type-number specifies the type of the return value.
3457 Translate it into a pointer-to-function type. */
3458 {
3459 p++;
3460 SYMBOL_TYPE (sym)
3461 = lookup_pointer_type (lookup_function_type (read_type (&p)));
3462 }
3463 else
3464 {
e1ce8aa5 3465 struct type *type_read;
bd5635a1
RP
3466 synonym = *p == 't';
3467
3468 if (synonym)
3469 {
3470 p += 1;
3471 type_synonym_name = obsavestring (SYMBOL_NAME (sym),
3472 strlen (SYMBOL_NAME (sym)));
3473 }
3474
e1ce8aa5 3475 type_read = read_type (&p);
bd5635a1
RP
3476
3477 if ((deftype == 'F' || deftype == 'f')
e1ce8aa5 3478 && TYPE_CODE (type_read) != TYPE_CODE_FUNC)
0c4d2cc2
JG
3479 {
3480#if 0
3481/* This code doesn't work -- it needs to realloc and can't. */
3482 struct type *new = (struct type *)
3483 obstack_alloc (symbol_obstack, sizeof (struct type));
3484
3485 /* Generate a template for the type of this function. The
3486 types of the arguments will be added as we read the symbol
3487 table. */
3488 *new = *lookup_function_type (type_read);
3489 SYMBOL_TYPE(sym) = new;
3490 in_function_type = new;
3491#else
e1ce8aa5 3492 SYMBOL_TYPE (sym) = lookup_function_type (type_read);
0c4d2cc2
JG
3493#endif
3494 }
bd5635a1 3495 else
e1ce8aa5 3496 SYMBOL_TYPE (sym) = type_read;
bd5635a1
RP
3497 }
3498
3499 switch (deftype)
3500 {
3501 case 'C':
3502 /* The name of a caught exception. */
3503 SYMBOL_CLASS (sym) = LOC_LABEL;
3504 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3505 SYMBOL_VALUE_ADDRESS (sym) = valu;
3506 add_symbol_to_list (sym, &local_symbols);
3507 break;
3508
3509 case 'f':
3510 SYMBOL_CLASS (sym) = LOC_BLOCK;
3511 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3512 add_symbol_to_list (sym, &file_symbols);
3513 break;
3514
3515 case 'F':
3516 SYMBOL_CLASS (sym) = LOC_BLOCK;
3517 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3518 add_symbol_to_list (sym, &global_symbols);
3519 break;
3520
3521 case 'G':
3522 /* For a class G (global) symbol, it appears that the
3523 value is not correct. It is necessary to search for the
3524 corresponding linker definition to find the value.
3525 These definitions appear at the end of the namelist. */
3526 i = hashname (SYMBOL_NAME (sym));
3527 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
3528 global_sym_chain[i] = sym;
3529 SYMBOL_CLASS (sym) = LOC_STATIC;
3530 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3531 add_symbol_to_list (sym, &global_symbols);
3532 break;
3533
3534 /* This case is faked by a conditional above,
3535 when there is no code letter in the dbx data.
3536 Dbx data never actually contains 'l'. */
3537 case 'l':
3538 SYMBOL_CLASS (sym) = LOC_LOCAL;
3539 SYMBOL_VALUE (sym) = valu;
3540 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3541 add_symbol_to_list (sym, &local_symbols);
3542 break;
3543
3544 case 'p':
3545 /* Normally this is a parameter, a LOC_ARG. On the i960, it
3546 can also be a LOC_LOCAL_ARG depending on symbol type. */
3547#ifndef DBX_PARM_SYMBOL_CLASS
3548#define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
3549#endif
3550 SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
3551 SYMBOL_VALUE (sym) = valu;
3552 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
0c4d2cc2
JG
3553#if 0
3554 /* This doesn't work yet. */
3555 add_param_to_type (&in_function_type, sym);
3556#endif
bd5635a1
RP
3557 add_symbol_to_list (sym, &local_symbols);
3558
3559 /* If it's gcc-compiled, if it says `short', believe it. */
3560 if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
3561 break;
3562
3563#if defined(BELIEVE_PCC_PROMOTION_TYPE)
3564 /* This macro is defined on machines (e.g. sparc) where
3565 we should believe the type of a PCC 'short' argument,
3566 but shouldn't believe the address (the address is
3567 the address of the corresponding int). Note that
3568 this is only different from the BELIEVE_PCC_PROMOTION
3569 case on big-endian machines.
3570
3571 My guess is that this correction, as opposed to changing
3572 the parameter to an 'int' (as done below, for PCC
3573 on most machines), is the right thing to do
3574 on all machines, but I don't want to risk breaking
3575 something that already works. On most PCC machines,
3576 the sparc problem doesn't come up because the calling
3577 function has to zero the top bytes (not knowing whether
3578 the called function wants an int or a short), so there
3579 is no practical difference between an int and a short
3580 (except perhaps what happens when the GDB user types
3581 "print short_arg = 0x10000;").
3582
3583 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
3584 actually produces the correct address (we don't need to fix it
3585 up). I made this code adapt so that it will offset the symbol
3586 if it was pointing at an int-aligned location and not
3587 otherwise. This way you can use the same gdb for 4.0.x and
3588 4.1 systems. */
3589
3590 if (0 == SYMBOL_VALUE (sym) % sizeof (int))
3591 {
3592 if (SYMBOL_TYPE (sym) == builtin_type_char
3593 || SYMBOL_TYPE (sym) == builtin_type_unsigned_char)
3594 SYMBOL_VALUE (sym) += 3;
3595 else if (SYMBOL_TYPE (sym) == builtin_type_short
3596 || SYMBOL_TYPE (sym) == builtin_type_unsigned_short)
3597 SYMBOL_VALUE (sym) += 2;
3598 }
3599 break;
3600
3601#else /* no BELIEVE_PCC_PROMOTION_TYPE. */
3602
3603 /* If PCC says a parameter is a short or a char,
3604 it is really an int. */
3605 if (SYMBOL_TYPE (sym) == builtin_type_char
3606 || SYMBOL_TYPE (sym) == builtin_type_short)
3607 SYMBOL_TYPE (sym) = builtin_type_int;
3608 else if (SYMBOL_TYPE (sym) == builtin_type_unsigned_char
3609 || SYMBOL_TYPE (sym) == builtin_type_unsigned_short)
3610 SYMBOL_TYPE (sym) = builtin_type_unsigned_int;
3611 break;
3612
3613#endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
3614
3615 case 'P':
3616 SYMBOL_CLASS (sym) = LOC_REGPARM;
3617 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
3618 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3619 add_symbol_to_list (sym, &local_symbols);
3620 break;
3621
3622 case 'r':
3623 SYMBOL_CLASS (sym) = LOC_REGISTER;
3624 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
3625 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3626 add_symbol_to_list (sym, &local_symbols);
3627 break;
3628
3629 case 'S':
3630 /* Static symbol at top level of file */
3631 SYMBOL_CLASS (sym) = LOC_STATIC;
3632 SYMBOL_VALUE_ADDRESS (sym) = valu;
3633 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3634 add_symbol_to_list (sym, &file_symbols);
3635 break;
3636
3637 case 't':
3638 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
3639 SYMBOL_VALUE (sym) = valu;
3640 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3641 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0
3642 && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0)
3643 TYPE_NAME (SYMBOL_TYPE (sym)) =
3644 obsavestring (SYMBOL_NAME (sym),
3645 strlen (SYMBOL_NAME (sym)));
3646 /* C++ vagaries: we may have a type which is derived from
3647 a base type which did not have its name defined when the
3648 derived class was output. We fill in the derived class's
3649 base part member's name here in that case. */
3650 else if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
3651 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
3652 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
3653 {
0c4d2cc2
JG
3654 int j;
3655 for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
3656 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
3657 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
3658 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
bd5635a1
RP
3659 }
3660
3661 add_symbol_to_list (sym, &file_symbols);
3662 break;
3663
3664 case 'T':
3665 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
3666 SYMBOL_VALUE (sym) = valu;
3667 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
3668 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0
3669 && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0)
3670 TYPE_NAME (SYMBOL_TYPE (sym))
3671 = obconcat ("",
3672 (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_ENUM
3673 ? "enum "
3674 : (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
3675 ? "struct " : "union ")),
3676 SYMBOL_NAME (sym));
3677 add_symbol_to_list (sym, &file_symbols);
3678
3679 if (synonym)
3680 {
3681 register struct symbol *typedef_sym
3682 = (struct symbol *) obstack_alloc (symbol_obstack, sizeof (struct symbol));
3683 SYMBOL_NAME (typedef_sym) = SYMBOL_NAME (sym);
3684 SYMBOL_TYPE (typedef_sym) = SYMBOL_TYPE (sym);
3685
3686 SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
3687 SYMBOL_VALUE (typedef_sym) = valu;
3688 SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
3689 add_symbol_to_list (typedef_sym, &file_symbols);
3690 }
3691 break;
3692
3693 case 'V':
3694 /* Static symbol of local scope */
3695 SYMBOL_CLASS (sym) = LOC_STATIC;
3696 SYMBOL_VALUE_ADDRESS (sym) = valu;
3697 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3698 add_symbol_to_list (sym, &local_symbols);
3699 break;
3700
3701 case 'v':
3702 /* Reference parameter */
3703 SYMBOL_CLASS (sym) = LOC_REF_ARG;
3704 SYMBOL_VALUE (sym) = valu;
3705 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3706 add_symbol_to_list (sym, &local_symbols);
3707 break;
3708
3709 case 'X':
3710 /* This is used by Sun FORTRAN for "function result value".
3711 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
3712 that Pascal uses it too, but when I tried it Pascal used
3713 "x:3" (local symbol) instead. */
3714 SYMBOL_CLASS (sym) = LOC_LOCAL;
3715 SYMBOL_VALUE (sym) = valu;
3716 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3717 add_symbol_to_list (sym, &local_symbols);
3718 break;
3719
3720 default:
3721 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype, symnum);
3722 }
3723 return sym;
3724}
3725\f
3726/* What about types defined as forward references inside of a small lexical
3727 scope? */
3728/* Add a type to the list of undefined types to be checked through
3729 once this file has been read in. */
3730static void
3731add_undefined_type (type)
3732 struct type *type;
3733{
3734 if (undef_types_length == undef_types_allocated)
3735 {
3736 undef_types_allocated *= 2;
3737 undef_types = (struct type **)
3738 xrealloc (undef_types,
3739 undef_types_allocated * sizeof (struct type *));
3740 }
3741 undef_types[undef_types_length++] = type;
3742}
3743
3744/* Add here something to go through each undefined type, see if it's
3745 still undefined, and do a full lookup if so. */
3746static void
3747cleanup_undefined_types ()
3748{
3749 struct type **type;
3750
3751 for (type = undef_types; type < undef_types + undef_types_length; type++)
3752 {
3753 /* Reasonable test to see if it's been defined since. */
3754 if (TYPE_NFIELDS (*type) == 0)
3755 {
3756 struct pending *ppt;
3757 int i;
3758 /* Name of the type, without "struct" or "union" */
3759 char *typename = TYPE_NAME (*type);
3760
3761 if (!strncmp (typename, "struct ", 7))
3762 typename += 7;
3763 if (!strncmp (typename, "union ", 6))
3764 typename += 6;
3765
3766 for (ppt = file_symbols; ppt; ppt = ppt->next)
3767 for (i = 0; i < ppt->nsyms; i++)
3768 {
3769 struct symbol *sym = ppt->symbol[i];
3770
3771 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
3772 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
3773 && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
3774 TYPE_CODE (*type))
3775 && !strcmp (SYMBOL_NAME (sym), typename))
3776 bcopy (SYMBOL_TYPE (sym), *type, sizeof (struct type));
3777 }
3778 }
3779 else
3780 /* It has been defined; don't mark it as a stub. */
3781 TYPE_FLAGS (*type) &= ~TYPE_FLAG_STUB;
3782 }
3783 undef_types_length = 0;
3784}
3785
3786/* Skip rest of this symbol and return an error type.
3787
3788 General notes on error recovery: error_type always skips to the
3789 end of the symbol (modulo cretinous dbx symbol name continuation).
3790 Thus code like this:
3791
3792 if (*(*pp)++ != ';')
3793 return error_type (pp);
3794
3795 is wrong because if *pp starts out pointing at '\0' (typically as the
3796 result of an earlier error), it will be incremented to point to the
3797 start of the next symbol, which might produce strange results, at least
3798 if you run off the end of the string table. Instead use
3799
3800 if (**pp != ';')
3801 return error_type (pp);
3802 ++*pp;
3803
3804 or
3805
3806 if (**pp != ';')
3807 foo = error_type (pp);
3808 else
3809 ++*pp;
3810
3811 And in case it isn't obvious, the point of all this hair is so the compiler
3812 can define new types and new syntaxes, and old versions of the
3813 debugger will be able to read the new symbol tables. */
3814
3815static struct type *
3816error_type (pp)
3817 char **pp;
3818{
3819 complain (&error_type_complaint, 0);
3820 while (1)
3821 {
3822 /* Skip to end of symbol. */
3823 while (**pp != '\0')
3824 (*pp)++;
3825
3826 /* Check for and handle cretinous dbx symbol name continuation! */
3827 if ((*pp)[-1] == '\\')
3828 *pp = next_symbol_text ();
3829 else
3830 break;
3831 }
3832 return builtin_type_error;
3833}
3834\f
3835/* Read a dbx type reference or definition;
3836 return the type that is meant.
3837 This can be just a number, in which case it references
3838 a type already defined and placed in type_vector.
3839 Or the number can be followed by an =, in which case
3840 it means to define a new type according to the text that
3841 follows the =. */
3842
3843static
3844struct type *
3845read_type (pp)
3846 register char **pp;
3847{
3848 register struct type *type = 0;
3849 struct type *type1;
3850 int typenums[2];
3851 int xtypenums[2];
3852
3853 /* Read type number if present. The type number may be omitted.
3854 for instance in a two-dimensional array declared with type
3855 "ar1;1;10;ar1;1;10;4". */
3856 if ((**pp >= '0' && **pp <= '9')
3857 || **pp == '(')
3858 {
3859 read_type_number (pp, typenums);
3860
3861 /* Detect random reference to type not yet defined.
3862 Allocate a type object but leave it zeroed. */
3863 if (**pp != '=')
3864 return dbx_alloc_type (typenums);
3865
3866 *pp += 2;
3867 }
3868 else
3869 {
3870 /* 'typenums=' not present, type is anonymous. Read and return
3871 the definition, but don't put it in the type vector. */
3872 typenums[0] = typenums[1] = -1;
3873 *pp += 1;
3874 }
3875
3876 switch ((*pp)[-1])
3877 {
3878 case 'x':
3879 {
3880 enum type_code code;
3881
3882 /* Used to index through file_symbols. */
3883 struct pending *ppt;
3884 int i;
3885
3886 /* Name including "struct", etc. */
3887 char *type_name;
3888
3889 /* Name without "struct", etc. */
3890 char *type_name_only;
3891
3892 {
3893 char *prefix;
3894 char *from, *to;
3895
3896 /* Set the type code according to the following letter. */
3897 switch ((*pp)[0])
3898 {
3899 case 's':
3900 code = TYPE_CODE_STRUCT;
3901 prefix = "struct ";
3902 break;
3903 case 'u':
3904 code = TYPE_CODE_UNION;
3905 prefix = "union ";
3906 break;
3907 case 'e':
3908 code = TYPE_CODE_ENUM;
3909 prefix = "enum ";
3910 break;
3911 default:
3912 return error_type (pp);
3913 }
3914
3915 to = type_name = (char *)
3916 obstack_alloc (symbol_obstack,
3917 (strlen (prefix) +
3918 ((char *) strchr (*pp, ':') - (*pp)) + 1));
3919
3920 /* Copy the prefix. */
3921 from = prefix;
3922 while (*to++ = *from++)
3923 ;
3924 to--;
3925
3926 type_name_only = to;
3927
3928 /* Copy the name. */
3929 from = *pp + 1;
3930 while ((*to++ = *from++) != ':')
3931 ;
3932 *--to = '\0';
3933
3934 /* Set the pointer ahead of the name which we just read. */
3935 *pp = from;
3936
3937#if 0
3938 /* The following hack is clearly wrong, because it doesn't
3939 check whether we are in a baseclass. I tried to reproduce
3940 the case that it is trying to fix, but I couldn't get
3941 g++ to put out a cross reference to a basetype. Perhaps
3942 it doesn't do it anymore. */
3943 /* Note: for C++, the cross reference may be to a base type which
3944 has not yet been seen. In this case, we skip to the comma,
3945 which will mark the end of the base class name. (The ':'
3946 at the end of the base class name will be skipped as well.)
3947 But sometimes (ie. when the cross ref is the last thing on
3948 the line) there will be no ','. */
3949 from = (char *) strchr (*pp, ',');
3950 if (from)
3951 *pp = from;
3952#endif /* 0 */
3953 }
3954
3955 /* Now check to see whether the type has already been declared. */
3956 /* This is necessary at least in the case where the
3957 program says something like
3958 struct foo bar[5];
3959 The compiler puts out a cross-reference; we better find
3960 set the length of the structure correctly so we can
3961 set the length of the array. */
3962 for (ppt = file_symbols; ppt; ppt = ppt->next)
3963 for (i = 0; i < ppt->nsyms; i++)
3964 {
3965 struct symbol *sym = ppt->symbol[i];
3966
3967 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
3968 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
3969 && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
3970 && !strcmp (SYMBOL_NAME (sym), type_name_only))
3971 {
3972 obstack_free (symbol_obstack, type_name);
3973 type = SYMBOL_TYPE (sym);
3974 return type;
3975 }
3976 }
3977
3978 /* Didn't find the type to which this refers, so we must
3979 be dealing with a forward reference. Allocate a type
3980 structure for it, and keep track of it so we can
3981 fill in the rest of the fields when we get the full
3982 type. */
3983 type = dbx_alloc_type (typenums);
3984 TYPE_CODE (type) = code;
3985 TYPE_NAME (type) = type_name;
3986
3987 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
3988
3989 add_undefined_type (type);
3990 return type;
3991 }
3992
3993 case '0':
3994 case '1':
3995 case '2':
3996 case '3':
3997 case '4':
3998 case '5':
3999 case '6':
4000 case '7':
4001 case '8':
4002 case '9':
4003 case '(':
4004 (*pp)--;
4005 read_type_number (pp, xtypenums);
4006 type = *dbx_lookup_type (xtypenums);
4007 if (type == 0)
4008 type = builtin_type_void;
4009 if (typenums[0] != -1)
4010 *dbx_lookup_type (typenums) = type;
4011 break;
4012
4013 case '*':
4014 type1 = read_type (pp);
4015 type = lookup_pointer_type (type1);
4016 if (typenums[0] != -1)
4017 *dbx_lookup_type (typenums) = type;
4018 break;
4019
4020 case '@':
4021 {
4022 struct type *domain = read_type (pp);
4023 struct type *memtype;
4024
4025 if (**pp != ',')
4026 /* Invalid member type data format. */
4027 return error_type (pp);
4028 ++*pp;
4029
4030 memtype = read_type (pp);
4031 type = dbx_alloc_type (typenums);
4032 smash_to_member_type (type, domain, memtype);
4033 }
4034 break;
4035
4036 case '#':
4037 if ((*pp)[0] == '#')
4038 {
4039 /* We'll get the parameter types from the name. */
4040 struct type *return_type;
4041
4042 *pp += 1;
4043 return_type = read_type (pp);
4044 if (*(*pp)++ != ';')
4045 complain (&invalid_member_complaint, symnum);
62c4f98b 4046 type = allocate_stub_method (return_type);
bd5635a1
RP
4047 if (typenums[0] != -1)
4048 *dbx_lookup_type (typenums) = type;
bd5635a1
RP
4049 }
4050 else
4051 {
4052 struct type *domain = read_type (pp);
4053 struct type *return_type;
4054 struct type **args;
4055
4056 if (*(*pp)++ != ',')
4057 error ("invalid member type data format, at symtab pos %d.",
4058 symnum);
4059
4060 return_type = read_type (pp);
4061 args = read_args (pp, ';');
4062 type = dbx_alloc_type (typenums);
4063 smash_to_method_type (type, domain, return_type, args);
4064 }
4065 break;
4066
4067 case '&':
4068 type1 = read_type (pp);
4069 type = lookup_reference_type (type1);
4070 if (typenums[0] != -1)
4071 *dbx_lookup_type (typenums) = type;
4072 break;
4073
4074 case 'f':
4075 type1 = read_type (pp);
4076 type = lookup_function_type (type1);
4077 if (typenums[0] != -1)
4078 *dbx_lookup_type (typenums) = type;
4079 break;
4080
4081 case 'r':
4082 type = read_range_type (pp, typenums);
4083 if (typenums[0] != -1)
4084 *dbx_lookup_type (typenums) = type;
4085 break;
4086
4087 case 'e':
4088 type = dbx_alloc_type (typenums);
4089 type = read_enum_type (pp, type);
4090 *dbx_lookup_type (typenums) = type;
4091 break;
4092
4093 case 's':
4094 type = dbx_alloc_type (typenums);
4095 TYPE_NAME (type) = type_synonym_name;
4096 type_synonym_name = 0;
4097 type = read_struct_type (pp, type);
4098 break;
4099
4100 case 'u':
4101 type = dbx_alloc_type (typenums);
4102 TYPE_NAME (type) = type_synonym_name;
4103 type_synonym_name = 0;
4104 type = read_struct_type (pp, type);
4105 TYPE_CODE (type) = TYPE_CODE_UNION;
4106 break;
4107
4108 case 'a':
4109 if (**pp != 'r')
4110 return error_type (pp);
4111 ++*pp;
4112
4113 type = dbx_alloc_type (typenums);
4114 type = read_array_type (pp, type);
4115 break;
4116
4117 default:
5bc757e2
JG
4118 --*pp; /* Go back to the symbol in error */
4119 /* Particularly important if it was \0! */
bd5635a1
RP
4120 return error_type (pp);
4121 }
4122
4123 if (type == 0)
4124 abort ();
4125
4126#if 0
4127 /* If this is an overriding temporary alteration for a header file's
4128 contents, and this type number is unknown in the global definition,
4129 put this type into the global definition at this type number. */
4130 if (header_file_prev_index >= 0)
4131 {
4132 register struct type **tp
4133 = explicit_lookup_type (header_file_prev_index, typenums[1]);
4134 if (*tp == 0)
4135 *tp = type;
4136 }
4137#endif
4138 return type;
4139}
4140\f
4141#if 0
4142/* This would be a good idea, but it doesn't really work. The problem
4143 is that in order to get the virtual context for a particular type,
4144 you need to know the virtual info from all of its basetypes,
4145 and you need to have processed its methods. Since GDB reads
4146 symbols on a file-by-file basis, this means processing the symbols
4147 of all the files that are needed for each baseclass, which
4148 means potentially reading in all the debugging info just to fill
4149 in information we may never need. */
4150
4151/* This page contains subroutines of read_type. */
4152
4153/* FOR_TYPE is a struct type defining a virtual function NAME with type
4154 FN_TYPE. The `virtual context' for this virtual function is the
4155 first base class of FOR_TYPE in which NAME is defined with signature
4156 matching FN_TYPE. OFFSET serves as a hash on matches here.
4157
4158 TYPE is the current type in which we are searching. */
4159
4160static struct type *
4161virtual_context (for_type, type, name, fn_type, offset)
4162 struct type *for_type, *type;
4163 char *name;
4164 struct type *fn_type;
4165 int offset;
4166{
4167 struct type *basetype = 0;
4168 int i;
4169
4170 if (for_type != type)
4171 {
4172 /* Check the methods of TYPE. */
4173 /* Need to do a check_stub_type here, but that breaks
4174 things because we can get infinite regress. */
4175 for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; --i)
4176 if (!strcmp (TYPE_FN_FIELDLIST_NAME (type, i), name))
4177 break;
4178 if (i >= 0)
4179 {
4180 int j = TYPE_FN_FIELDLIST_LENGTH (type, i);
4181 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
4182
4183 while (--j >= 0)
4184 if (TYPE_FN_FIELD_VOFFSET (f, j) == offset-1)
4185 return TYPE_FN_FIELD_FCONTEXT (f, j);
4186 }
4187 }
62c4f98b 4188 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
bd5635a1
RP
4189 {
4190 basetype = virtual_context (for_type, TYPE_BASECLASS (type, i), name,
4191 fn_type, offset);
4192 if (basetype != for_type)
4193 return basetype;
4194 }
4195 return for_type;
4196}
4197#endif
4198
4199/* Read the description of a structure (or union type)
4200 and return an object describing the type. */
4201
4202static struct type *
4203read_struct_type (pp, type)
4204 char **pp;
4205 register struct type *type;
4206{
4207 /* Total number of methods defined in this class.
4208 If the class defines two `f' methods, and one `g' method,
4209 then this will have the value 3. */
4210 int total_length = 0;
4211
4212 struct nextfield
4213 {
4214 struct nextfield *next;
4215 int visibility; /* 0=public, 1=protected, 2=public */
4216 struct field field;
4217 };
4218
4219 struct next_fnfield
4220 {
4221 struct next_fnfield *next;
4222 int visibility; /* 0=public, 1=protected, 2=public */
4223 struct fn_field fn_field;
4224 };
4225
4226 struct next_fnfieldlist
4227 {
4228 struct next_fnfieldlist *next;
4229 struct fn_fieldlist fn_fieldlist;
4230 };
4231
4232 register struct nextfield *list = 0;
4233 struct nextfield *new;
4234 register char *p;
4235 int nfields = 0;
4236 register int n;
4237
4238 register struct next_fnfieldlist *mainlist = 0;
4239 int nfn_fields = 0;
4240
4241 if (TYPE_MAIN_VARIANT (type) == 0)
4242 {
4243 TYPE_MAIN_VARIANT (type) = type;
4244 }
4245
4246 TYPE_CODE (type) = TYPE_CODE_STRUCT;
4247
4248 /* First comes the total size in bytes. */
4249
4250 TYPE_LENGTH (type) = read_number (pp, 0);
4251
4252 /* C++: Now, if the class is a derived class, then the next character
4253 will be a '!', followed by the number of base classes derived from.
4254 Each element in the list contains visibility information,
4255 the offset of this base class in the derived structure,
4256 and then the base type. */
4257 if (**pp == '!')
4258 {
4259 int i, n_baseclasses, offset;
4260 struct type *baseclass;
4261 int via_public;
4262
4263 /* Nonzero if it is a virtual baseclass, i.e.,
4264
4265 struct A{};
4266 struct B{};
4267 struct C : public B, public virtual A {};
4268
4269 B is a baseclass of C; A is a virtual baseclass for C. This is a C++
4270 2.0 language feature. */
4271 int via_virtual;
4272
4273 *pp += 1;
4274
4275 n_baseclasses = read_number (pp, ',');
4276 TYPE_FIELD_VIRTUAL_BITS (type) =
4277 (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (n_baseclasses));
4278 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), n_baseclasses);
4279
4280 for (i = 0; i < n_baseclasses; i++)
4281 {
4282 if (**pp == '\\')
4283 *pp = next_symbol_text ();
4284
4285 switch (**pp)
4286 {
4287 case '0':
4288 via_virtual = 0;
4289 break;
4290 case '1':
4291 via_virtual = 1;
4292 break;
4293 default:
4294 /* Bad visibility format. */
4295 return error_type (pp);
4296 }
4297 ++*pp;
4298
4299 switch (**pp)
4300 {
4301 case '0':
4302 via_public = 0;
4303 break;
4304 case '2':
4305 via_public = 2;
4306 break;
4307 default:
4308 /* Bad visibility format. */
4309 return error_type (pp);
4310 }
4311 if (via_virtual)
4312 SET_TYPE_FIELD_VIRTUAL (type, i);
4313 ++*pp;
4314
4315 /* Offset of the portion of the object corresponding to
4316 this baseclass. Always zero in the absence of
4317 multiple inheritance. */
4318 offset = read_number (pp, ',');
4319 baseclass = read_type (pp);
4320 *pp += 1; /* skip trailing ';' */
4321
bd5635a1
RP
4322 /* Make this baseclass visible for structure-printing purposes. */
4323 new = (struct nextfield *) alloca (sizeof (struct nextfield));
4324 new->next = list;
4325 list = new;
4326 list->visibility = via_public;
4327 list->field.type = baseclass;
4328 list->field.name = type_name_no_tag (baseclass);
4329 list->field.bitpos = offset;
4330 list->field.bitsize = 0; /* this should be an unpacked field! */
4331 nfields++;
4332 }
4333 TYPE_N_BASECLASSES (type) = n_baseclasses;
4334 }
4335
4336 /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
4337 At the end, we see a semicolon instead of a field.
4338
4339 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
4340 a static field.
4341
4342 The `?' is a placeholder for one of '/2' (public visibility),
4343 '/1' (protected visibility), '/0' (private visibility), or nothing
4344 (C style symbol table, public visibility). */
4345
4346 /* We better set p right now, in case there are no fields at all... */
4347 p = *pp;
4348
4349 while (**pp != ';')
4350 {
4351 /* Check for and handle cretinous dbx symbol name continuation! */
4352 if (**pp == '\\') *pp = next_symbol_text ();
4353
4354 /* Get space to record the next field's data. */
4355 new = (struct nextfield *) alloca (sizeof (struct nextfield));
4356 new->next = list;
4357 list = new;
4358
4359 /* Get the field name. */
4360 p = *pp;
4361 if (*p == CPLUS_MARKER)
4362 {
4363 /* Special GNU C++ name. */
4364 if (*++p == 'v')
4365 {
e1ce8aa5
JK
4366 const char *prefix;
4367 char *name = 0;
bd5635a1
RP
4368 struct type *context;
4369
4370 switch (*++p)
4371 {
4372 case 'f':
4373 prefix = vptr_name;
4374 break;
4375 case 'b':
4376 prefix = vb_name;
4377 break;
4378 default:
4379 error ("invalid abbreviation at symtab pos %d.", symnum);
4380 }
4381 *pp = p + 1;
4382 context = read_type (pp);
4383 if (type_name_no_tag (context) == 0)
4384 {
4385 if (name == 0)
4386 error ("type name unknown at symtab pos %d.", symnum);
62c4f98b 4387 /* FIXME-tiemann: when is `name' ever non-0? */
bd5635a1
RP
4388 TYPE_NAME (context) = obsavestring (name, p - name - 1);
4389 }
4390 list->field.name = obconcat (prefix, type_name_no_tag (context), "");
4391 p = ++(*pp);
4392 if (p[-1] != ':')
4393 error ("invalid abbreviation at symtab pos %d.", symnum);
4394 list->field.type = read_type (pp);
4395 (*pp)++; /* Skip the comma. */
4396 list->field.bitpos = read_number (pp, ';');
4397 /* This field is unpacked. */
4398 list->field.bitsize = 0;
4399 }
9404978d
MT
4400 /* GNU C++ anonymous type. */
4401 else if (*p == '_')
4402 break;
bd5635a1
RP
4403 else
4404 error ("invalid abbreviation at symtab pos %d.", symnum);
4405
4406 nfields++;
4407 continue;
4408 }
4409
4410 while (*p != ':') p++;
4411 list->field.name = obsavestring (*pp, p - *pp);
4412
4413 /* C++: Check to see if we have hit the methods yet. */
4414 if (p[1] == ':')
4415 break;
4416
4417 *pp = p + 1;
4418
4419 /* This means we have a visibility for a field coming. */
4420 if (**pp == '/')
4421 {
4422 switch (*++*pp)
4423 {
4424 case '0':
4425 list->visibility = 0; /* private */
4426 *pp += 1;
4427 break;
4428
4429 case '1':
4430 list->visibility = 1; /* protected */
4431 *pp += 1;
4432 break;
4433
4434 case '2':
4435 list->visibility = 2; /* public */
4436 *pp += 1;
4437 break;
4438 }
4439 }
4440 else /* normal dbx-style format. */
4441 list->visibility = 2; /* public */
4442
4443 list->field.type = read_type (pp);
4444 if (**pp == ':')
4445 {
4446 /* Static class member. */
4447 list->field.bitpos = (long)-1;
4448 p = ++(*pp);
4449 while (*p != ';') p++;
4450 list->field.bitsize = (long) savestring (*pp, p - *pp);
4451 *pp = p + 1;
4452 nfields++;
4453 continue;
4454 }
4455 else if (**pp != ',')
4456 /* Bad structure-type format. */
4457 return error_type (pp);
4458
4459 (*pp)++; /* Skip the comma. */
4460 list->field.bitpos = read_number (pp, ',');
4461 list->field.bitsize = read_number (pp, ';');
4462
4463#if 0
62c4f98b
JK
4464 /* FIXME-tiemann: Can't the compiler put out something which
4465 lets us distinguish these? (or maybe just not put out anything
4466 for the field). What is the story here? What does the compiler
bd5635a1
RP
4467 really do? Also, patch gdb.texinfo for this case; I document
4468 it as a possible problem there. Search for "DBX-style". */
4469
4470 /* This is wrong because this is identical to the symbols
4471 produced for GCC 0-size arrays. For example:
4472 typedef union {
4473 int num;
4474 char str[0];
4475 } foo;
4476 The code which dumped core in such circumstances should be
4477 fixed not to dump core. */
4478
4479 /* g++ -g0 can put out bitpos & bitsize zero for a static
4480 field. This does not give us any way of getting its
4481 class, so we can't know its name. But we can just
4482 ignore the field so we don't dump core and other nasty
4483 stuff. */
4484 if (list->field.bitpos == 0
4485 && list->field.bitsize == 0)
4486 {
4487 complain (&dbx_class_complaint, 0);
4488 /* Ignore this field. */
4489 list = list->next;
4490 }
4491 else
4492#endif /* 0 */
4493 {
4494 /* Detect an unpacked field and mark it as such.
4495 dbx gives a bit size for all fields.
4496 Note that forward refs cannot be packed,
4497 and treat enums as if they had the width of ints. */
4498 if (TYPE_CODE (list->field.type) != TYPE_CODE_INT
4499 && TYPE_CODE (list->field.type) != TYPE_CODE_ENUM)
4500 list->field.bitsize = 0;
4501 if ((list->field.bitsize == 8 * TYPE_LENGTH (list->field.type)
4502 || (TYPE_CODE (list->field.type) == TYPE_CODE_ENUM
4503 && (list->field.bitsize
4504 == 8 * TYPE_LENGTH (builtin_type_int))
4505 )
4506 )
4507 &&
4508 list->field.bitpos % 8 == 0)
4509 list->field.bitsize = 0;
4510 nfields++;
4511 }
4512 }
4513
4514 if (p[1] == ':')
4515 /* chill the list of fields: the last entry (at the head)
4516 is a partially constructed entry which we now scrub. */
4517 list = list->next;
4518
4519 /* Now create the vector of fields, and record how big it is.
4520 We need this info to record proper virtual function table information
4521 for this class's virtual functions. */
4522
4523 TYPE_NFIELDS (type) = nfields;
4524 TYPE_FIELDS (type) = (struct field *) obstack_alloc (symbol_obstack,
4525 sizeof (struct field) * nfields);
4526
4527 TYPE_FIELD_PRIVATE_BITS (type) =
4528 (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (nfields));
4529 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
4530
4531 TYPE_FIELD_PROTECTED_BITS (type) =
4532 (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (nfields));
4533 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
4534
4535 /* Copy the saved-up fields into the field vector. */
4536
4537 for (n = nfields; list; list = list->next)
4538 {
4539 n -= 1;
4540 TYPE_FIELD (type, n) = list->field;
4541 if (list->visibility == 0)
4542 SET_TYPE_FIELD_PRIVATE (type, n);
4543 else if (list->visibility == 1)
4544 SET_TYPE_FIELD_PROTECTED (type, n);
4545 }
4546
4547 /* Now come the method fields, as NAME::methods
4548 where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
4549 At the end, we see a semicolon instead of a field.
4550
4551 For the case of overloaded operators, the format is
4552 OPERATOR::*.methods, where OPERATOR is the string "operator",
4553 `*' holds the place for an operator name (such as `+=')
4554 and `.' marks the end of the operator name. */
4555 if (p[1] == ':')
4556 {
4557 /* Now, read in the methods. To simplify matters, we
4558 "unread" the name that has been read, so that we can
4559 start from the top. */
4560
4561 /* For each list of method lists... */
4562 do
4563 {
4564 int i;
4565 struct next_fnfield *sublist = 0;
dcc35536 4566 struct type *look_ahead_type = NULL;
bd5635a1
RP
4567 int length = 0;
4568 struct next_fnfieldlist *new_mainlist =
4569 (struct next_fnfieldlist *)alloca (sizeof (struct next_fnfieldlist));
4570 char *main_fn_name;
4571
4572 p = *pp;
4573
4574 /* read in the name. */
4575 while (*p != ':') p++;
4576 if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && (*pp)[2] == CPLUS_MARKER)
4577 {
4578 /* This lets the user type "break operator+".
4579 We could just put in "+" as the name, but that wouldn't
4580 work for "*". */
62c4f98b
JK
4581 static char opname[32] = {'o', 'p', CPLUS_MARKER};
4582 char *o = opname + 3;
bd5635a1
RP
4583
4584 /* Skip past '::'. */
4585 p += 2;
4586 while (*p != '.')
4587 *o++ = *p++;
4588 main_fn_name = savestring (opname, o - opname);
4589 /* Skip past '.' */
4590 *pp = p + 1;
4591 }
4592 else
4593 {
4594 i = 0;
4595 main_fn_name = savestring (*pp, p - *pp);
4596 /* Skip past '::'. */
4597 *pp = p + 2;
4598 }
4599 new_mainlist->fn_fieldlist.name = main_fn_name;
4600
4601 do
4602 {
4603 struct next_fnfield *new_sublist =
4604 (struct next_fnfield *)alloca (sizeof (struct next_fnfield));
4605
4606 /* Check for and handle cretinous dbx symbol name continuation! */
dcc35536
JG
4607 if (look_ahead_type == NULL) /* Normal case. */
4608 {
4609 if (**pp == '\\') *pp = next_symbol_text ();
bd5635a1 4610
dcc35536
JG
4611 new_sublist->fn_field.type = read_type (pp);
4612 if (**pp != ':')
4613 /* Invalid symtab info for method. */
4614 return error_type (pp);
4615 }
4616 else
4617 { /* g++ version 1 kludge */
4618 new_sublist->fn_field.type = look_ahead_type;
4619 look_ahead_type = NULL;
4620 }
bd5635a1
RP
4621
4622 *pp += 1;
4623 p = *pp;
4624 while (*p != ';') p++;
4625 /* If this is just a stub, then we don't have the
4626 real name here. */
4627 new_sublist->fn_field.physname = savestring (*pp, p - *pp);
4628 *pp = p + 1;
4629 new_sublist->visibility = *(*pp)++ - '0';
4630 if (**pp == '\\') *pp = next_symbol_text ();
bcccec8c
PB
4631 switch (**pp)
4632 {
4633 case 'A': /* Normal functions. */
4634 new_sublist->fn_field.is_const = 0;
4635 new_sublist->fn_field.is_volatile = 0;
4636 (*pp)++;
4637 break;
4638 case 'B': /* `const' member functions. */
4639 new_sublist->fn_field.is_const = 1;
4640 new_sublist->fn_field.is_volatile = 0;
4641 (*pp)++;
4642 break;
4643 case 'C': /* `volatile' member function. */
4644 new_sublist->fn_field.is_const = 0;
4645 new_sublist->fn_field.is_volatile = 1;
4646 (*pp)++;
4647 break;
4648 case 'D': /* `const volatile' member function. */
4649 new_sublist->fn_field.is_const = 1;
4650 new_sublist->fn_field.is_volatile = 1;
4651 (*pp)++;
4652 break;
4653 default:
4654 /* This probably just means we're processing a file compiled
4655 with g++ version 1. */
4656 complain(&const_vol_complaint, **pp);
4657 }
bd5635a1
RP
4658
4659 switch (*(*pp)++)
4660 {
4661 case '*':
4662 /* virtual member function, followed by index. */
4663 /* The sign bit is set to distinguish pointers-to-methods
4664 from virtual function indicies. Since the array is
4665 in words, the quantity must be shifted left by 1
4666 on 16 bit machine, and by 2 on 32 bit machine, forcing
4667 the sign bit out, and usable as a valid index into
4668 the array. Remove the sign bit here. */
4669 new_sublist->fn_field.voffset =
bcccec8c 4670 (0x7fffffff & read_number (pp, ';')) + 2;
bd5635a1 4671
dcc35536
JG
4672 if (**pp == '\\') *pp = next_symbol_text ();
4673
9107291d
JK
4674 if (**pp == ';' || **pp == '\0')
4675 /* Must be g++ version 1. */
4676 new_sublist->fn_field.fcontext = 0;
bd5635a1 4677 else
9107291d
JK
4678 {
4679 /* Figure out from whence this virtual function came.
4680 It may belong to virtual function table of
4681 one of its baseclasses. */
dcc35536
JG
4682 look_ahead_type = read_type (pp);
4683 if (**pp == ':')
4684 { /* g++ version 1 overloaded methods. */ }
9107291d 4685 else
dcc35536
JG
4686 {
4687 new_sublist->fn_field.fcontext = look_ahead_type;
4688 if (**pp != ';')
4689 return error_type (pp);
4690 else
4691 ++*pp;
4692 look_ahead_type = NULL;
4693 }
9107291d 4694 }
bd5635a1
RP
4695 break;
4696
4697 case '?':
4698 /* static member function. */
4699 new_sublist->fn_field.voffset = VOFFSET_STATIC;
4700 break;
4701 default:
4702 /* **pp == '.'. */
4703 /* normal member function. */
4704 new_sublist->fn_field.voffset = 0;
62c4f98b 4705 new_sublist->fn_field.fcontext = 0;
bd5635a1
RP
4706 break;
4707 }
4708
4709 new_sublist->next = sublist;
4710 sublist = new_sublist;
4711 length++;
bcccec8c 4712 if (**pp == '\\') *pp = next_symbol_text ();
bd5635a1 4713 }
9107291d 4714 while (**pp != ';' && **pp != '\0');
bd5635a1
RP
4715
4716 *pp += 1;
4717
4718 new_mainlist->fn_fieldlist.fn_fields =
4719 (struct fn_field *) obstack_alloc (symbol_obstack,
4720 sizeof (struct fn_field) * length);
4721 TYPE_FN_PRIVATE_BITS (new_mainlist->fn_fieldlist) =
4722 (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (length));
4723 B_CLRALL (TYPE_FN_PRIVATE_BITS (new_mainlist->fn_fieldlist), length);
4724
4725 TYPE_FN_PROTECTED_BITS (new_mainlist->fn_fieldlist) =
4726 (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (length));
4727 B_CLRALL (TYPE_FN_PROTECTED_BITS (new_mainlist->fn_fieldlist), length);
4728
4729 for (i = length; (i--, sublist); sublist = sublist->next)
4730 {
4731 new_mainlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
4732 if (sublist->visibility == 0)
4733 B_SET (new_mainlist->fn_fieldlist.private_fn_field_bits, i);
4734 else if (sublist->visibility == 1)
4735 B_SET (new_mainlist->fn_fieldlist.protected_fn_field_bits, i);
4736 }
4737
4738 new_mainlist->fn_fieldlist.length = length;
4739 new_mainlist->next = mainlist;
4740 mainlist = new_mainlist;
4741 nfn_fields++;
4742 total_length += length;
4743 }
4744 while (**pp != ';');
4745 }
4746
4747 *pp += 1;
4748
4749 TYPE_FN_FIELDLISTS (type) =
4750 (struct fn_fieldlist *) obstack_alloc (symbol_obstack,
4751 sizeof (struct fn_fieldlist) * nfn_fields);
4752
4753 TYPE_NFN_FIELDS (type) = nfn_fields;
4754 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
4755
4756 {
4757 int i;
4758 for (i = 0; i < TYPE_N_BASECLASSES (type); ++i)
4759 TYPE_NFN_FIELDS_TOTAL (type) +=
4760 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type, i));
4761 }
4762
4763 for (n = nfn_fields; mainlist; mainlist = mainlist->next)
4764 TYPE_FN_FIELDLISTS (type)[--n] = mainlist->fn_fieldlist;
4765
4766 if (**pp == '~')
4767 {
4768 *pp += 1;
4769
4770 if (**pp == '=')
4771 {
4772 TYPE_FLAGS (type)
4773 |= TYPE_FLAG_HAS_CONSTRUCTOR | TYPE_FLAG_HAS_DESTRUCTOR;
4774 *pp += 1;
4775 }
4776 else if (**pp == '+')
4777 {
4778 TYPE_FLAGS (type) |= TYPE_FLAG_HAS_CONSTRUCTOR;
4779 *pp += 1;
4780 }
4781 else if (**pp == '-')
4782 {
4783 TYPE_FLAGS (type) |= TYPE_FLAG_HAS_DESTRUCTOR;
4784 *pp += 1;
4785 }
4786
4787 /* Read either a '%' or the final ';'. */
4788 if (*(*pp)++ == '%')
4789 {
4790 /* Now we must record the virtual function table pointer's
4791 field information. */
4792
4793 struct type *t;
4794 int i;
4795
4796 t = read_type (pp);
4797 p = (*pp)++;
4798 while (*p != '\0' && *p != ';')
4799 p++;
4800 if (*p == '\0')
4801 /* Premature end of symbol. */
4802 return error_type (pp);
4803
4804 TYPE_VPTR_BASETYPE (type) = t;
4805 if (type == t)
4806 {
4807 if (TYPE_FIELD_NAME (t, TYPE_N_BASECLASSES (t)) == 0)
62c4f98b
JK
4808 {
4809 /* FIXME-tiemann: what's this? */
4810#if 0
4811 TYPE_VPTR_FIELDNO (type) = i = TYPE_N_BASECLASSES (t);
4812#else
4813 error_type (pp);
4814#endif
4815 }
bd5635a1
RP
4816 else for (i = TYPE_NFIELDS (t) - 1; i >= TYPE_N_BASECLASSES (t); --i)
4817 if (! strncmp (TYPE_FIELD_NAME (t, i), vptr_name,
4818 sizeof (vptr_name) -1))
4819 {
4820 TYPE_VPTR_FIELDNO (type) = i;
4821 break;
4822 }
4823 if (i < 0)
4824 /* Virtual function table field not found. */
4825 return error_type (pp);
4826 }
4827 else
4828 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
4829 *pp = p + 1;
4830 }
bd5635a1
RP
4831 }
4832
4833 return type;
4834}
4835
4836/* Read a definition of an array type,
4837 and create and return a suitable type object.
4838 Also creates a range type which represents the bounds of that
4839 array. */
4840static struct type *
4841read_array_type (pp, type)
4842 register char **pp;
4843 register struct type *type;
4844{
4845 struct type *index_type, *element_type, *range_type;
4846 int lower, upper;
4847 int adjustable = 0;
4848
4849 /* Format of an array type:
4850 "ar<index type>;lower;upper;<array_contents_type>". Put code in
4851 to handle this.
4852
4853 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
4854 for these, produce a type like float[][]. */
4855
4856 index_type = read_type (pp);
4857 if (**pp != ';')
4858 /* Improper format of array type decl. */
4859 return error_type (pp);
4860 ++*pp;
4861
4862 if (!(**pp >= '0' && **pp <= '9'))
4863 {
4864 *pp += 1;
4865 adjustable = 1;
4866 }
4867 lower = read_number (pp, ';');
4868
4869 if (!(**pp >= '0' && **pp <= '9'))
4870 {
4871 *pp += 1;
4872 adjustable = 1;
4873 }
4874 upper = read_number (pp, ';');
4875
4876 element_type = read_type (pp);
4877
4878 if (adjustable)
4879 {
4880 lower = 0;
4881 upper = -1;
4882 }
4883
4884 {
4885 /* Create range type. */
4886 range_type = (struct type *) obstack_alloc (symbol_obstack,
4887 sizeof (struct type));
4888 TYPE_CODE (range_type) = TYPE_CODE_RANGE;
4889 TYPE_TARGET_TYPE (range_type) = index_type;
4890
4891 /* This should never be needed. */
4892 TYPE_LENGTH (range_type) = sizeof (int);
4893
4894 TYPE_NFIELDS (range_type) = 2;
4895 TYPE_FIELDS (range_type) =
4896 (struct field *) obstack_alloc (symbol_obstack,
4897 2 * sizeof (struct field));
4898 TYPE_FIELD_BITPOS (range_type, 0) = lower;
4899 TYPE_FIELD_BITPOS (range_type, 1) = upper;
4900 }
4901
4902 TYPE_CODE (type) = TYPE_CODE_ARRAY;
4903 TYPE_TARGET_TYPE (type) = element_type;
4904 TYPE_LENGTH (type) = (upper - lower + 1) * TYPE_LENGTH (element_type);
4905 TYPE_NFIELDS (type) = 1;
4906 TYPE_FIELDS (type) =
4907 (struct field *) obstack_alloc (symbol_obstack,
4908 sizeof (struct field));
4909 TYPE_FIELD_TYPE (type, 0) = range_type;
4910
4911 return type;
4912}
4913
4914
4915/* Read a definition of an enumeration type,
4916 and create and return a suitable type object.
4917 Also defines the symbols that represent the values of the type. */
4918
4919static struct type *
4920read_enum_type (pp, type)
4921 register char **pp;
4922 register struct type *type;
4923{
4924 register char *p;
4925 char *name;
4926 register long n;
4927 register struct symbol *sym;
4928 int nsyms = 0;
4929 struct pending **symlist;
4930 struct pending *osyms, *syms;
4931 int o_nsyms;
4932
4933 if (within_function)
4934 symlist = &local_symbols;
4935 else
4936 symlist = &file_symbols;
4937 osyms = *symlist;
4938 o_nsyms = osyms ? osyms->nsyms : 0;
4939
4940 /* Read the value-names and their values.
4941 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
4942 A semicolon or comman instead of a NAME means the end. */
4943 while (**pp && **pp != ';' && **pp != ',')
4944 {
4945 /* Check for and handle cretinous dbx symbol name continuation! */
4946 if (**pp == '\\') *pp = next_symbol_text ();
4947
4948 p = *pp;
4949 while (*p != ':') p++;
4950 name = obsavestring (*pp, p - *pp);
4951 *pp = p + 1;
4952 n = read_number (pp, ',');
4953
4954 sym = (struct symbol *) obstack_alloc (symbol_obstack, sizeof (struct symbol));
4955 bzero (sym, sizeof (struct symbol));
4956 SYMBOL_NAME (sym) = name;
4957 SYMBOL_CLASS (sym) = LOC_CONST;
4958 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4959 SYMBOL_VALUE (sym) = n;
4960 add_symbol_to_list (sym, symlist);
4961 nsyms++;
4962 }
4963
4964 if (**pp == ';')
4965 (*pp)++; /* Skip the semicolon. */
4966
4967 /* Now fill in the fields of the type-structure. */
4968
4969 TYPE_LENGTH (type) = sizeof (int);
4970 TYPE_CODE (type) = TYPE_CODE_ENUM;
4971 TYPE_NFIELDS (type) = nsyms;
4972 TYPE_FIELDS (type) = (struct field *) obstack_alloc (symbol_obstack, sizeof (struct field) * nsyms);
4973
4974 /* Find the symbols for the values and put them into the type.
4975 The symbols can be found in the symlist that we put them on
4976 to cause them to be defined. osyms contains the old value
4977 of that symlist; everything up to there was defined by us. */
4978 /* Note that we preserve the order of the enum constants, so
4979 that in something like "enum {FOO, LAST_THING=FOO}" we print
4980 FOO, not LAST_THING. */
4981
4982 for (syms = *symlist, n = 0; syms; syms = syms->next)
4983 {
4984 int j = 0;
4985 if (syms == osyms)
4986 j = o_nsyms;
4987 for (; j < syms->nsyms; j++,n++)
4988 {
0c4d2cc2
JG
4989 struct symbol *xsym = syms->symbol[j];
4990 SYMBOL_TYPE (xsym) = type;
4991 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
bd5635a1 4992 TYPE_FIELD_VALUE (type, n) = 0;
0c4d2cc2 4993 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
bd5635a1
RP
4994 TYPE_FIELD_BITSIZE (type, n) = 0;
4995 }
4996 if (syms == osyms)
4997 break;
4998 }
4999
afe4ca15
JG
5000#if 0
5001 /* This screws up perfectly good C programs with enums. FIXME. */
0c4d2cc2
JG
5002 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
5003 if(TYPE_NFIELDS(type) == 2 &&
5004 ((!strcmp(TYPE_FIELD_NAME(type,0),"TRUE") &&
5005 !strcmp(TYPE_FIELD_NAME(type,1),"FALSE")) ||
5006 (!strcmp(TYPE_FIELD_NAME(type,1),"TRUE") &&
5007 !strcmp(TYPE_FIELD_NAME(type,0),"FALSE"))))
5008 TYPE_CODE(type) = TYPE_CODE_BOOL;
afe4ca15 5009#endif
0c4d2cc2 5010
bd5635a1
RP
5011 return type;
5012}
5013
5014/* Read a number from the string pointed to by *PP.
5015 The value of *PP is advanced over the number.
5016 If END is nonzero, the character that ends the
5017 number must match END, or an error happens;
5018 and that character is skipped if it does match.
5019 If END is zero, *PP is left pointing to that character.
5020
5021 If the number fits in a long, set *VALUE and set *BITS to 0.
5022 If not, set *BITS to be the number of bits in the number.
5023
5024 If encounter garbage, set *BITS to -1. */
5025
5026static void
5027read_huge_number (pp, end, valu, bits)
5028 char **pp;
5029 int end;
5030 long *valu;
5031 int *bits;
5032{
5033 char *p = *pp;
5034 int sign = 1;
5035 long n = 0;
5036 int radix = 10;
5037 char overflow = 0;
5038 int nbits = 0;
5039 int c;
d11c44f1 5040 long upper_limit;
bd5635a1
RP
5041
5042 if (*p == '-')
5043 {
5044 sign = -1;
5045 p++;
5046 }
5047
5048 /* Leading zero means octal. GCC uses this to output values larger
5049 than an int (because that would be hard in decimal). */
5050 if (*p == '0')
5051 {
5052 radix = 8;
5053 p++;
5054 }
5055
d11c44f1 5056 upper_limit = LONG_MAX / radix;
bd5635a1
RP
5057 while ((c = *p++) >= '0' && c <= ('0' + radix))
5058 {
d11c44f1 5059 if (n <= upper_limit)
bd5635a1
RP
5060 {
5061 n *= radix;
5062 n += c - '0'; /* FIXME this overflows anyway */
5063 }
5064 else
5065 overflow = 1;
5066
5067 /* This depends on large values being output in octal, which is
5068 what GCC does. */
5069 if (radix == 8)
5070 {
5071 if (nbits == 0)
5072 {
5073 if (c == '0')
5074 /* Ignore leading zeroes. */
5075 ;
5076 else if (c == '1')
5077 nbits = 1;
5078 else if (c == '2' || c == '3')
5079 nbits = 2;
5080 else
5081 nbits = 3;
5082 }
5083 else
5084 nbits += 3;
5085 }
5086 }
5087 if (end)
5088 {
5089 if (c && c != end)
5090 {
5091 if (bits != NULL)
5092 *bits = -1;
5093 return;
5094 }
5095 }
5096 else
5097 --p;
5098
5099 *pp = p;
5100 if (overflow)
5101 {
5102 if (nbits == 0)
5103 {
5104 /* Large decimal constants are an error (because it is hard to
5105 count how many bits are in them). */
5106 if (bits != NULL)
5107 *bits = -1;
5108 return;
5109 }
5110
5111 /* -0x7f is the same as 0x80. So deal with it by adding one to
5112 the number of bits. */
5113 if (sign == -1)
5114 ++nbits;
5115 if (bits)
5116 *bits = nbits;
5117 }
5118 else
5119 {
5120 if (valu)
5121 *valu = n * sign;
5122 if (bits)
5123 *bits = 0;
5124 }
5125}
5126
0c4d2cc2
JG
5127#define MAX_OF_C_TYPE(t) ((1 << (sizeof (t)*8 - 1)) - 1)
5128#define MIN_OF_C_TYPE(t) (-(1 << (sizeof (t)*8 - 1)))
bd5635a1
RP
5129
5130static struct type *
5131read_range_type (pp, typenums)
5132 char **pp;
5133 int typenums[2];
5134{
5135 int rangenums[2];
5136 long n2, n3;
5137 int n2bits, n3bits;
5138 int self_subrange;
5139 struct type *result_type;
5140
5141 /* First comes a type we are a subrange of.
5142 In C it is usually 0, 1 or the type being defined. */
5143 read_type_number (pp, rangenums);
5144 self_subrange = (rangenums[0] == typenums[0] &&
5145 rangenums[1] == typenums[1]);
5146
5147 /* A semicolon should now follow; skip it. */
5148 if (**pp == ';')
5149 (*pp)++;
5150
5151 /* The remaining two operands are usually lower and upper bounds
5152 of the range. But in some special cases they mean something else. */
5153 read_huge_number (pp, ';', &n2, &n2bits);
5154 read_huge_number (pp, ';', &n3, &n3bits);
5155
5156 if (n2bits == -1 || n3bits == -1)
5157 return error_type (pp);
5158
5159 /* If limits are huge, must be large integral type. */
5160 if (n2bits != 0 || n3bits != 0)
5161 {
5162 char got_signed = 0;
5163 char got_unsigned = 0;
5164 /* Number of bits in the type. */
5165 int nbits;
5166
5167 /* Range from 0 to <large number> is an unsigned large integral type. */
5168 if ((n2bits == 0 && n2 == 0) && n3bits != 0)
5169 {
5170 got_unsigned = 1;
5171 nbits = n3bits;
5172 }
5173 /* Range from <large number> to <large number>-1 is a large signed
5174 integral type. */
5175 else if (n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
5176 {
5177 got_signed = 1;
5178 nbits = n2bits;
5179 }
5180
62c4f98b
JK
5181 /* Check for "long long". */
5182 if (got_signed && nbits == TARGET_LONG_LONG_BIT)
5183 return builtin_type_long_long;
5184 if (got_unsigned && nbits == TARGET_LONG_LONG_BIT)
5185 return builtin_type_unsigned_long_long;
5186
bd5635a1
RP
5187 if (got_signed || got_unsigned)
5188 {
5189 result_type = (struct type *) obstack_alloc (symbol_obstack,
5190 sizeof (struct type));
5191 bzero (result_type, sizeof (struct type));
5192 TYPE_LENGTH (result_type) = nbits / TARGET_CHAR_BIT;
5193 TYPE_MAIN_VARIANT (result_type) = result_type;
5194 TYPE_CODE (result_type) = TYPE_CODE_INT;
5195 if (got_unsigned)
5196 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
5197 return result_type;
5198 }
5199 else
5200 return error_type (pp);
5201 }
5202
5203 /* A type defined as a subrange of itself, with bounds both 0, is void. */
5204 if (self_subrange && n2 == 0 && n3 == 0)
5205 return builtin_type_void;
5206
5207 /* If n3 is zero and n2 is not, we want a floating type,
5208 and n2 is the width in bytes.
5209
5210 Fortran programs appear to use this for complex types also,
5211 and they give no way to distinguish between double and single-complex!
5212 We don't have complex types, so we would lose on all fortran files!
5213 So return type `double' for all of those. It won't work right
5214 for the complex values, but at least it makes the file loadable. */
5215
5216 if (n3 == 0 && n2 > 0)
5217 {
5218 if (n2 == sizeof (float))
5219 return builtin_type_float;
5220 return builtin_type_double;
5221 }
5222
5223 /* If the upper bound is -1, it must really be an unsigned int. */
5224
5225 else if (n2 == 0 && n3 == -1)
5226 {
5227 if (sizeof (int) == sizeof (long))
5228 return builtin_type_unsigned_int;
5229 else
5230 return builtin_type_unsigned_long;
5231 }
5232
5233 /* Special case: char is defined (Who knows why) as a subrange of
5234 itself with range 0-127. */
5235 else if (self_subrange && n2 == 0 && n3 == 127)
5236 return builtin_type_char;
5237
5238 /* Assumptions made here: Subrange of self is equivalent to subrange
5239 of int. */
5240 else if (n2 == 0
5241 && (self_subrange ||
5242 *dbx_lookup_type (rangenums) == builtin_type_int))
5243 {
5244 /* an unsigned type */
5245#ifdef LONG_LONG
5246 if (n3 == - sizeof (long long))
5247 return builtin_type_unsigned_long_long;
5248#endif
5249 if (n3 == (unsigned int)~0L)
5250 return builtin_type_unsigned_int;
5251 if (n3 == (unsigned long)~0L)
5252 return builtin_type_unsigned_long;
5253 if (n3 == (unsigned short)~0L)
5254 return builtin_type_unsigned_short;
5255 if (n3 == (unsigned char)~0L)
5256 return builtin_type_unsigned_char;
5257 }
5258#ifdef LONG_LONG
5259 else if (n3 == 0 && n2 == -sizeof (long long))
5260 return builtin_type_long_long;
5261#endif
5262 else if (n2 == -n3 -1)
5263 {
5264 /* a signed type */
5265 if (n3 == (1 << (8 * sizeof (int) - 1)) - 1)
5266 return builtin_type_int;
5267 if (n3 == (1 << (8 * sizeof (long) - 1)) - 1)
5268 return builtin_type_long;
5269 if (n3 == (1 << (8 * sizeof (short) - 1)) - 1)
5270 return builtin_type_short;
5271 if (n3 == (1 << (8 * sizeof (char) - 1)) - 1)
5272 return builtin_type_char;
5273 }
5274
5275 /* We have a real range type on our hands. Allocate space and
5276 return a real pointer. */
5277
5278 /* At this point I don't have the faintest idea how to deal with
5279 a self_subrange type; I'm going to assume that this is used
5280 as an idiom, and that all of them are special cases. So . . . */
5281 if (self_subrange)
5282 return error_type (pp);
5283
5284 result_type = (struct type *) obstack_alloc (symbol_obstack,
5285 sizeof (struct type));
5286 bzero (result_type, sizeof (struct type));
5287
0c4d2cc2
JG
5288 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
5289
5290 TYPE_TARGET_TYPE (result_type) = *dbx_lookup_type(rangenums);
9bb30452
JG
5291 if (TYPE_TARGET_TYPE (result_type) == 0) {
5292 complain (&range_type_base_complaint, rangenums[1]);
5293 TYPE_TARGET_TYPE (result_type) = builtin_type_int;
5294 }
0c4d2cc2
JG
5295
5296 TYPE_NFIELDS (result_type) = 2;
5297 TYPE_FIELDS (result_type) =
5298 (struct field *) obstack_alloc (symbol_obstack,
5299 2 * sizeof (struct field));
5300 bzero (TYPE_FIELDS (result_type), 2 * sizeof (struct field));
5301 TYPE_FIELD_BITPOS (result_type, 0) = n2;
5302 TYPE_FIELD_BITPOS (result_type, 1) = n3;
bd5635a1 5303
0c4d2cc2
JG
5304#if 0
5305/* Note that TYPE_LENGTH (result_type) is just overridden a few
5306 statements down. What do we really need here? */
bd5635a1
RP
5307 /* We have to figure out how many bytes it takes to hold this
5308 range type. I'm going to assume that anything that is pushing
5309 the bounds of a long was taken care of above. */
0c4d2cc2 5310 if (n2 >= MIN_OF_C_TYPE(char) && n3 <= MAX_OF_C_TYPE(char))
bd5635a1 5311 TYPE_LENGTH (result_type) = 1;
0c4d2cc2 5312 else if (n2 >= MIN_OF_C_TYPE(short) && n3 <= MAX_OF_C_TYPE(short))
bd5635a1 5313 TYPE_LENGTH (result_type) = sizeof (short);
0c4d2cc2 5314 else if (n2 >= MIN_OF_C_TYPE(int) && n3 <= MAX_OF_C_TYPE(int))
bd5635a1 5315 TYPE_LENGTH (result_type) = sizeof (int);
0c4d2cc2 5316 else if (n2 >= MIN_OF_C_TYPE(long) && n3 <= MAX_OF_C_TYPE(long))
bd5635a1
RP
5317 TYPE_LENGTH (result_type) = sizeof (long);
5318 else
5319 /* Ranged type doesn't fit within known sizes. */
0c4d2cc2 5320 /* FIXME -- use "long long" here. */
bd5635a1 5321 return error_type (pp);
0c4d2cc2 5322#endif
bd5635a1
RP
5323
5324 TYPE_LENGTH (result_type) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type));
bd5635a1
RP
5325
5326 return result_type;
5327}
5328
5329/* Read a number from the string pointed to by *PP.
5330 The value of *PP is advanced over the number.
5331 If END is nonzero, the character that ends the
5332 number must match END, or an error happens;
5333 and that character is skipped if it does match.
5334 If END is zero, *PP is left pointing to that character. */
5335
5336static long
5337read_number (pp, end)
5338 char **pp;
5339 int end;
5340{
5341 register char *p = *pp;
5342 register long n = 0;
5343 register int c;
5344 int sign = 1;
5345
5346 /* Handle an optional leading minus sign. */
5347
5348 if (*p == '-')
5349 {
5350 sign = -1;
5351 p++;
5352 }
5353
5354 /* Read the digits, as far as they go. */
5355
5356 while ((c = *p++) >= '0' && c <= '9')
5357 {
5358 n *= 10;
5359 n += c - '0';
5360 }
5361 if (end)
5362 {
5363 if (c && c != end)
5364 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c, symnum);
5365 }
5366 else
5367 --p;
5368
5369 *pp = p;
5370 return n * sign;
5371}
5372
5373/* Read in an argument list. This is a list of types, separated by commas
5374 and terminated with END. Return the list of types read in, or (struct type
5375 **)-1 if there is an error. */
5376static struct type **
5377read_args (pp, end)
5378 char **pp;
5379 int end;
5380{
5381 struct type *types[1024], **rval; /* allow for fns of 1023 parameters */
5382 int n = 0;
5383
5384 while (**pp != end)
5385 {
5386 if (**pp != ',')
5387 /* Invalid argument list: no ','. */
5388 return (struct type **)-1;
5389 *pp += 1;
5390
5391 /* Check for and handle cretinous dbx symbol name continuation! */
5392 if (**pp == '\\')
5393 *pp = next_symbol_text ();
5394
5395 types[n++] = read_type (pp);
5396 }
5397 *pp += 1; /* get past `end' (the ':' character) */
5398
5399 if (n == 1)
5400 {
5401 rval = (struct type **) xmalloc (2 * sizeof (struct type *));
5402 }
5403 else if (TYPE_CODE (types[n-1]) != TYPE_CODE_VOID)
5404 {
5405 rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *));
5406 bzero (rval + n, sizeof (struct type *));
5407 }
5408 else
5409 {
5410 rval = (struct type **) xmalloc (n * sizeof (struct type *));
5411 }
5412 bcopy (types, rval, n * sizeof (struct type *));
5413 return rval;
5414}
5415\f
5416/* Copy a pending list, used to record the contents of a common
5417 block for later fixup. */
5418static struct pending *
5419copy_pending (beg, begi, end)
5420 struct pending *beg, *end;
5421 int begi;
5422{
5423 struct pending *new = 0;
5424 struct pending *next;
5425
5426 for (next = beg; next != 0 && (next != end || begi < end->nsyms);
5427 next = next->next, begi = 0)
5428 {
5429 register int j;
5430 for (j = begi; j < next->nsyms; j++)
5431 add_symbol_to_list (next->symbol[j], &new);
5432 }
5433 return new;
5434}
5435
5436/* Add a common block's start address to the offset of each symbol
5437 declared to be in it (by being between a BCOMM/ECOMM pair that uses
5438 the common block name). */
5439
5440static void
5441fix_common_block (sym, valu)
5442 struct symbol *sym;
5443 int valu;
5444{
5445 struct pending *next = (struct pending *) SYMBOL_NAMESPACE (sym);
5446 for ( ; next; next = next->next)
5447 {
5448 register int j;
5449 for (j = next->nsyms - 1; j >= 0; j--)
5450 SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
5451 }
5452}
5453\f
5454/* Register our willingness to decode symbols for SunOS and a.out and
5455 b.out files handled by BFD... */
5456static struct sym_fns sunos_sym_fns = {"sunOs", 6,
9404978d 5457 dbx_new_init, dbx_symfile_init, dbx_symfile_read};
bd5635a1
RP
5458
5459static struct sym_fns aout_sym_fns = {"a.out", 5,
9404978d 5460 dbx_new_init, dbx_symfile_init, dbx_symfile_read};
bd5635a1
RP
5461
5462static struct sym_fns bout_sym_fns = {"b.out", 5,
9404978d 5463 dbx_new_init, dbx_symfile_init, dbx_symfile_read};
bd5635a1
RP
5464
5465void
5466_initialize_dbxread ()
5467{
5468 add_symtab_fns(&sunos_sym_fns);
5469 add_symtab_fns(&aout_sym_fns);
5470 add_symtab_fns(&bout_sym_fns);
5471
5472 undef_types_allocated = 20;
5473 undef_types_length = 0;
5474 undef_types = (struct type **) xmalloc (undef_types_allocated *
5475 sizeof (struct type *));
5476}
This page took 0.258857 seconds and 4 git commands to generate.