Fixed ".reserve", and added toolversion for sparc + some nitpicks.
[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"
c0302457 58#include "buildsym.h"
afe4ca15
JG
59
60#include "aout64.h"
61#include "stab.gnu.h" /* We always use GNU stabs, not native, now */
bd5635a1 62
c0302457
JG
63/* Information is passed among various dbxread routines for accessing
64 symbol files. A pointer to this structure is kept in the sym_private
65 field of the struct sym_fns passed in by symfile.h. */
66
bd5635a1
RP
67struct dbx_symfile_info {
68 asection *text_sect; /* Text section accessor */
69 int symcount; /* How many symbols are there in the file */
70 char *stringtab; /* The actual string table */
71 int stringtab_size; /* Its size */
72 off_t symtab_offset; /* Offset in file to symbol table */
73 int desc; /* File descriptor of symbol file */
74};
75
c0302457 76
4a35d6e9
FF
77/* Each partial symbol table entry contains a pointer to private data for the
78 read_symtab() function to use when expanding a partial symbol table entry
79 to a full symbol table entry.
80
81 For dbxread this structure contains the offset within the file symbol table
82 of first local symbol for this file, and length (in bytes) of the section
83 of the symbol table devoted to this file's symbols (actually, the section
84 bracketed may contain more than just this file's symbols). If ldsymlen is
85 0, the only reason for this thing's existence is the dependency list.
86 Nothing else will happen when it is read in. */
87
88#define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
89#define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
90
91struct symloc {
92 int ldsymoff;
93 int ldsymlen;
94};
95
bd5635a1
RP
96extern void qsort ();
97extern double atof ();
bd5635a1
RP
98
99/* Forward declarations */
100
bd5635a1
RP
101static void read_dbx_symtab ();
102static void init_psymbol_list ();
103static void process_one_symbol ();
bd5635a1 104static struct symbol *define_symbol ();
c0302457
JG
105void start_subfile ();
106int hashname ();
bd5635a1 107static struct pending *copy_pending ();
9404978d 108static struct symtab *read_ofile_symtab ();
bd5635a1
RP
109static void dbx_psymtab_to_symtab ();
110
9404978d
MT
111static const char vptr_name[] = { '_','v','p','t','r',CPLUS_MARKER,'\0' };
112static const char vb_name[] = { '_','v','b',CPLUS_MARKER,'\0' };
bd5635a1
RP
113
114/* Macro to determine which symbols to ignore when reading the first symbol
115 of a file. Some machines override this definition. */
116#ifndef IGNORE_SYMBOL
117/* This code is used on Ultrix systems. Ignore it */
118#define IGNORE_SYMBOL(type) (type == (int)N_NSYMS)
119#endif
120
121/* Macro for name of symbol to indicate a file compiled with gcc. */
122#ifndef GCC_COMPILED_FLAG_SYMBOL
123#define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
124#endif
125
bd5635a1
RP
126/* Define this as 1 if a pcc declaration of a char or short argument
127 gives the correct address. Otherwise assume pcc gives the
128 address of the corresponding int, which is not the same on a
129 big-endian machine. */
130
131#ifndef BELIEVE_PCC_PROMOTION
132#define BELIEVE_PCC_PROMOTION 0
133#endif
c0302457 134
bd5635a1
RP
135/* Nonzero means give verbose info on gdb action. From main.c. */
136extern int info_verbose;
137
c0302457
JG
138/* The BFD for this file -- only good while we're actively reading
139 symbols into a psymtab or a symtab. */
bd5635a1 140
c0302457 141static bfd *symfile_bfd;
bd5635a1
RP
142
143/* String table for the main symbol file. It is kept in memory
144 permanently, to speed up symbol reading. Other files' symbol tables
145 are read in on demand. FIXME, this should be cleaner. */
146
147static char *symfile_string_table;
148static int symfile_string_table_size;
149
afe4ca15
JG
150/* The size of each symbol in the symbol file (in external form).
151 This is set by dbx_symfile_read when building psymtabs, and by
152 dbx_psymtab_to_symtab when building symtabs. */
153
154static unsigned symbol_size;
155
bd5635a1
RP
156/* Complaints about the symbols we have encountered. */
157
bd5635a1
RP
158struct complaint lbrac_complaint =
159 {"bad block start address patched", 0, 0};
160
bd5635a1
RP
161struct complaint string_table_offset_complaint =
162 {"bad string table offset in symbol %d", 0, 0};
163
164struct complaint unknown_symtype_complaint =
0c4d2cc2 165 {"unknown symbol type %s", 0, 0};
bd5635a1
RP
166
167struct complaint lbrac_rbrac_complaint =
168 {"block start larger than block end", 0, 0};
bd5635a1 169\f
bd5635a1
RP
170/* During initial symbol readin, we need to have a structure to keep
171 track of which psymtabs have which bincls in them. This structure
172 is used during readin to setup the list of dependencies within each
173 partial symbol table. */
174
175struct header_file_location
176{
177 char *name; /* Name of header file */
178 int instance; /* See above */
179 struct partial_symtab *pst; /* Partial symtab that has the
180 BINCL/EINCL defs for this file */
181};
182
183/* The actual list and controling variables */
184static struct header_file_location *bincl_list, *next_bincl;
185static int bincls_allocated;
186
bd5635a1
RP
187/* When a header file is getting special overriding definitions
188 for one source file, record here the header_files index
189 of its normal definition vector.
190 At other times, this is -1. */
191
192static int header_file_prev_index;
193
194/* Free up old header file tables, and allocate new ones.
195 We're reading a new symbol file now. */
196
c0302457 197void
bd5635a1
RP
198free_and_init_header_files ()
199{
200 register int i;
201 for (i = 0; i < n_header_files; i++)
202 free (header_files[i].name);
203 if (header_files) /* First time null */
204 free (header_files);
205 if (this_object_header_files) /* First time null */
206 free (this_object_header_files);
207
208 n_allocated_header_files = 10;
209 header_files = (struct header_file *) xmalloc (10 * sizeof (struct header_file));
210 n_header_files = 0;
211
212 n_allocated_this_object_header_files = 10;
213 this_object_header_files = (int *) xmalloc (10 * sizeof (int));
214}
215
216/* Called at the start of each object file's symbols.
217 Clear out the mapping of header file numbers to header files. */
218
c0302457 219void
bd5635a1
RP
220new_object_header_files ()
221{
222 /* Leave FILENUM of 0 free for builtin types and this file's types. */
223 n_this_object_header_files = 1;
224 header_file_prev_index = -1;
225}
226
227/* Add header file number I for this object file
228 at the next successive FILENUM. */
229
230static void
231add_this_object_header_file (i)
232 int i;
233{
234 if (n_this_object_header_files == n_allocated_this_object_header_files)
235 {
236 n_allocated_this_object_header_files *= 2;
237 this_object_header_files
238 = (int *) xrealloc (this_object_header_files,
239 n_allocated_this_object_header_files * sizeof (int));
240 }
241
242 this_object_header_files[n_this_object_header_files++] = i;
243}
244
245/* Add to this file an "old" header file, one already seen in
246 a previous object file. NAME is the header file's name.
247 INSTANCE is its instance code, to select among multiple
248 symbol tables for the same header file. */
249
250static void
251add_old_header_file (name, instance)
252 char *name;
253 int instance;
254{
255 register struct header_file *p = header_files;
256 register int i;
257
258 for (i = 0; i < n_header_files; i++)
259 if (!strcmp (p[i].name, name) && instance == p[i].instance)
260 {
261 add_this_object_header_file (i);
262 return;
263 }
264 error ("Invalid symbol data: \"repeated\" header file that hasn't been seen before, at symtab pos %d.",
265 symnum);
266}
267
268/* Add to this file a "new" header file: definitions for its types follow.
269 NAME is the header file's name.
270 Most often this happens only once for each distinct header file,
271 but not necessarily. If it happens more than once, INSTANCE has
272 a different value each time, and references to the header file
273 use INSTANCE values to select among them.
274
275 dbx output contains "begin" and "end" markers for each new header file,
276 but at this level we just need to know which files there have been;
277 so we record the file when its "begin" is seen and ignore the "end". */
278
279static void
280add_new_header_file (name, instance)
281 char *name;
282 int instance;
283{
284 register int i;
285 header_file_prev_index = -1;
286
287 /* Make sure there is room for one more header file. */
288
289 if (n_header_files == n_allocated_header_files)
290 {
291 n_allocated_header_files *= 2;
292 header_files = (struct header_file *)
293 xrealloc (header_files,
294 (n_allocated_header_files
295 * sizeof (struct header_file)));
296 }
297
298 /* Create an entry for this header file. */
299
300 i = n_header_files++;
301 header_files[i].name = savestring (name, strlen(name));
302 header_files[i].instance = instance;
303 header_files[i].length = 10;
304 header_files[i].vector
305 = (struct type **) xmalloc (10 * sizeof (struct type *));
306 bzero (header_files[i].vector, 10 * sizeof (struct type *));
307
308 add_this_object_header_file (i);
309}
310
bd5635a1
RP
311#if 0
312static struct type **
313explicit_lookup_type (real_filenum, index)
314 int real_filenum, index;
315{
316 register struct header_file *f = &header_files[real_filenum];
317
318 if (index >= f->length)
319 {
320 f->length *= 2;
321 f->vector = (struct type **)
322 xrealloc (f->vector, f->length * sizeof (struct type *));
323 bzero (&f->vector[f->length / 2],
324 f->length * sizeof (struct type *) / 2);
325 }
326 return &f->vector[index];
327}
328#endif
329\f
c0302457
JG
330/* Handle an N_SOL symbol, which indicates the start of
331 code that came from an included (or otherwise merged-in)
332 source file with a different name. */
bd5635a1 333
c0302457
JG
334void
335start_subfile (name, dirname)
336 char *name;
337 char *dirname;
bd5635a1 338{
c0302457 339 register struct subfile *subfile;
bd5635a1 340
c0302457 341 /* Save the current subfile's line vector data. */
bd5635a1 342
c0302457 343 if (current_subfile)
bd5635a1 344 {
c0302457
JG
345 current_subfile->line_vector_index = line_vector_index;
346 current_subfile->line_vector_length = line_vector_length;
347 current_subfile->prev_line_number = prev_line_number;
bd5635a1 348 }
bd5635a1 349
c0302457
JG
350 /* See if this subfile is already known as a subfile of the
351 current main source file. */
3f2e006b 352
c0302457 353 for (subfile = subfiles; subfile; subfile = subfile->next)
bd5635a1 354 {
c0302457
JG
355 if (!strcmp (subfile->name, name))
356 {
357 line_vector = subfile->line_vector;
358 line_vector_index = subfile->line_vector_index;
359 line_vector_length = subfile->line_vector_length;
360 prev_line_number = subfile->prev_line_number;
361 current_subfile = subfile;
362 return;
363 }
bd5635a1 364 }
bd5635a1 365
c0302457 366 /* This subfile is not known. Add an entry for it. */
bd5635a1 367
c0302457
JG
368 line_vector_index = 0;
369 line_vector_length = 1000;
370 prev_line_number = -2; /* Force first line number to be explicit */
371 line_vector = (struct linetable *)
372 xmalloc (sizeof (struct linetable)
373 + line_vector_length * sizeof (struct linetable_entry));
bd5635a1 374
c0302457
JG
375 /* Make an entry for this subfile in the list of all subfiles
376 of the current main source file. */
bd5635a1 377
c0302457
JG
378 subfile = (struct subfile *) xmalloc (sizeof (struct subfile));
379 subfile->next = subfiles;
380 subfile->name = obsavestring (name, strlen (name));
381 if (dirname == NULL)
382 subfile->dirname = NULL;
bd5635a1 383 else
c0302457
JG
384 subfile->dirname = obsavestring (dirname, strlen (dirname));
385
386 subfile->line_vector = line_vector;
387 subfiles = subfile;
388 current_subfile = subfile;
389}
390\f
391/* Handle the N_BINCL and N_EINCL symbol types
392 that act like N_SOL for switching source files
393 (different subfiles, as we call them) within one object file,
394 but using a stack rather than in an arbitrary order. */
bd5635a1 395
c0302457
JG
396struct subfile_stack
397{
398 struct subfile_stack *next;
399 char *name;
400 int prev_index;
401};
bd5635a1 402
c0302457 403struct subfile_stack *subfile_stack;
bd5635a1
RP
404
405static void
406push_subfile ()
407{
408 register struct subfile_stack *tem
409 = (struct subfile_stack *) xmalloc (sizeof (struct subfile_stack));
410
411 tem->next = subfile_stack;
412 subfile_stack = tem;
413 if (current_subfile == 0 || current_subfile->name == 0)
414 abort ();
415 tem->name = current_subfile->name;
416 tem->prev_index = header_file_prev_index;
417}
418
419static char *
420pop_subfile ()
421{
422 register char *name;
423 register struct subfile_stack *link = subfile_stack;
424
425 if (link == 0)
426 abort ();
427
428 name = link->name;
429 subfile_stack = link->next;
430 header_file_prev_index = link->prev_index;
431 free (link);
432
433 return name;
434}
435\f
9bba3334 436static void
bd5635a1
RP
437record_misc_function (name, address, type)
438 char *name;
439 CORE_ADDR address;
440 int type;
441{
0c4d2cc2
JG
442 enum misc_function_type misc_type;
443
444 switch (type &~ N_EXT) {
445 case N_TEXT: misc_type = mf_text; break;
446 case N_DATA: misc_type = mf_data; break;
447 case N_BSS: misc_type = mf_bss; break;
448 case N_ABS: misc_type = mf_abs; break;
449#ifdef N_SETV
450 case N_SETV: misc_type = mf_data; break;
451#endif
452 default: misc_type = mf_unknown; break;
453 }
bd5635a1
RP
454
455 prim_record_misc_function (obsavestring (name, strlen (name)),
456 address, misc_type);
457}
458\f
459/* Scan and build partial symbols for a symbol file.
460 We have been initialized by a call to dbx_symfile_init, which
461 put all the relevant info into a "struct dbx_symfile_info"
462 hung off the struct sym_fns SF.
463
464 ADDR is the address relative to which the symbols in it are (e.g.
465 the base address of the text segment).
466 MAINLINE is true if we are reading the main symbol
467 table (as opposed to a shared lib or dynamically loaded file). */
468
9bba3334 469static void
bd5635a1
RP
470dbx_symfile_read (sf, addr, mainline)
471 struct sym_fns *sf;
472 CORE_ADDR addr;
473 int mainline; /* FIXME comments above */
474{
475 struct dbx_symfile_info *info = (struct dbx_symfile_info *) (sf->sym_private);
476 bfd *sym_bfd = sf->sym_bfd;
477 int val;
478 char *filename = bfd_get_filename (sym_bfd);
479
480 val = lseek (info->desc, info->symtab_offset, L_SET);
481 if (val < 0)
482 perror_with_name (filename);
483
484 /* If mainline, set global string table pointers, and reinitialize global
485 partial symbol list. */
486 if (mainline) {
487 symfile_string_table = info->stringtab;
488 symfile_string_table_size = info->stringtab_size;
bd5635a1
RP
489 }
490
66eeea27
JG
491 /* If we are reinitializing, or if we have never loaded syms yet, init */
492 if (mainline || global_psymbols.size == 0 || static_psymbols.size == 0)
493 init_psymbol_list (info->symcount);
494
bd5635a1
RP
495 symfile_bfd = sym_bfd; /* Kludge for SWAP_SYMBOL */
496
afe4ca15
JG
497 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
498 symbol_size = obj_symbol_entry_size (sym_bfd);
499
bd5635a1
RP
500 pending_blocks = 0;
501 make_cleanup (really_free_pendings, 0);
502
503 init_misc_bunches ();
504 make_cleanup (discard_misc_bunches, 0);
505
506 /* Now that the symbol table data of the executable file are all in core,
507 process them and define symbols accordingly. */
508
509 read_dbx_symtab (filename,
510 addr - bfd_section_vma (sym_bfd, info->text_sect), /*offset*/
511 info->desc, info->stringtab, info->stringtab_size,
512 info->symcount,
513 bfd_section_vma (sym_bfd, info->text_sect),
514 bfd_section_size (sym_bfd, info->text_sect));
515
516 /* Go over the misc symbol bunches and install them in vector. */
517
518 condense_misc_bunches (!mainline);
519
520 /* Free up any memory we allocated for ourselves. */
521
522 if (!mainline) {
523 free (info->stringtab); /* Stringtab is only saved for mainline */
524 }
525 free (info);
526 sf->sym_private = 0; /* Zap pointer to our (now gone) info struct */
527
9404978d
MT
528 if (!partial_symtab_list) {
529 wrap_here ("");
530 printf_filtered ("(no debugging symbols found)...");
531 wrap_here ("");
532 }
bd5635a1
RP
533}
534
9404978d
MT
535/* Initialize anything that needs initializing when a completely new
536 symbol file is specified (not just adding some symbols from another
537 file, e.g. a shared library). */
bd5635a1 538
9bba3334 539static void
9404978d 540dbx_new_init ()
bd5635a1 541{
c0302457 542 buildsym_new_init ();
bd5635a1 543
bd5635a1 544 /* Don't put these on the cleanup chain; they need to stick around
9404978d 545 until the next call to dbx_new_init. *Then* we'll free them. */
bd5635a1
RP
546 if (symfile_string_table)
547 {
548 free (symfile_string_table);
549 symfile_string_table = 0;
550 symfile_string_table_size = 0;
551 }
552 free_and_init_header_files ();
553}
554
555
556/* dbx_symfile_init ()
557 is the dbx-specific initialization routine for reading symbols.
558 It is passed a struct sym_fns which contains, among other things,
559 the BFD for the file whose symbols are being read, and a slot for a pointer
560 to "private data" which we fill with goodies.
561
562 We read the string table into malloc'd space and stash a pointer to it.
563
564 Since BFD doesn't know how to read debug symbols in a format-independent
565 way (and may never do so...), we have to do it ourselves. We will never
566 be called unless this is an a.out (or very similar) file.
567 FIXME, there should be a cleaner peephole into the BFD environment here. */
568
9bba3334 569static void
bd5635a1
RP
570dbx_symfile_init (sf)
571 struct sym_fns *sf;
572{
573 int val;
574 int desc;
575 struct stat statbuf;
576 bfd *sym_bfd = sf->sym_bfd;
577 char *name = bfd_get_filename (sym_bfd);
578 struct dbx_symfile_info *info;
579 unsigned char size_temp[4];
580
581 /* Allocate struct to keep track of the symfile */
c0302457 582 sf->sym_private = xmalloc (sizeof (*info));
bd5635a1
RP
583 info = (struct dbx_symfile_info *)sf->sym_private;
584
585 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
586 desc = fileno ((FILE *)(sym_bfd->iostream)); /* Raw file descriptor */
587#define STRING_TABLE_OFFSET (sym_bfd->origin + obj_str_filepos (sym_bfd))
588#define SYMBOL_TABLE_OFFSET (sym_bfd->origin + obj_sym_filepos (sym_bfd))
589 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
590
591 info->desc = desc;
592 info->text_sect = bfd_get_section_by_name (sym_bfd, ".text");
593 if (!info->text_sect)
594 abort();
63989338 595 info->symcount = bfd_get_symcount (sym_bfd);
bd5635a1
RP
596
597 /* Read the string table size and check it for bogosity. */
598 val = lseek (desc, STRING_TABLE_OFFSET, L_SET);
599 if (val < 0)
600 perror_with_name (name);
601 if (fstat (desc, &statbuf) == -1)
602 perror_with_name (name);
603
604 val = myread (desc, size_temp, sizeof (long));
605 if (val < 0)
606 perror_with_name (name);
dcc35536 607 info->stringtab_size = bfd_h_get_32 (sym_bfd, size_temp);
bd5635a1
RP
608
609 if (info->stringtab_size >= 0 && info->stringtab_size < statbuf.st_size)
610 {
611 info->stringtab = (char *) xmalloc (info->stringtab_size);
612 /* Caller is responsible for freeing the string table. No cleanup. */
613 }
614 else
615 info->stringtab = NULL;
616 if (info->stringtab == NULL && info->stringtab_size != 0)
617 error ("ridiculous string table size: %d bytes", info->stringtab_size);
618
619 /* Now read in the string table in one big gulp. */
620
621 val = lseek (desc, STRING_TABLE_OFFSET, L_SET);
622 if (val < 0)
623 perror_with_name (name);
624 val = myread (desc, info->stringtab, info->stringtab_size);
625 if (val < 0)
626 perror_with_name (name);
627
628 /* Record the position of the symbol table for later use. */
629
630 info->symtab_offset = SYMBOL_TABLE_OFFSET;
631}
632\f
633/* Buffer for reading the symbol table entries. */
afe4ca15 634static struct internal_nlist symbuf[4096];
bd5635a1
RP
635static int symbuf_idx;
636static int symbuf_end;
637
638/* I/O descriptor for reading the symbol table. */
639static int symtab_input_desc;
640
641/* The address in memory of the string table of the object file we are
642 reading (which might not be the "main" object file, but might be a
643 shared library or some other dynamically loaded thing). This is set
644 by read_dbx_symtab when building psymtabs, and by read_ofile_symtab
645 when building symtabs, and is used only by next_symbol_text. */
646static char *stringtab_global;
647
648/* Refill the symbol table input buffer
649 and set the variables that control fetching entries from it.
650 Reports an error if no data available.
651 This function can read past the end of the symbol table
652 (into the string table) but this does no harm. */
653
654static int
655fill_symbuf ()
656{
657 int nbytes = myread (symtab_input_desc, symbuf, sizeof (symbuf));
658 if (nbytes < 0)
659 perror_with_name ("<symbol file>");
660 else if (nbytes == 0)
661 error ("Premature end of file reading symbol table");
afe4ca15 662 symbuf_end = nbytes / symbol_size;
bd5635a1
RP
663 symbuf_idx = 0;
664 return 1;
665}
666
667#define SWAP_SYMBOL(symp) \
668 { \
afe4ca15
JG
669 (symp)->n_strx = bfd_h_get_32(symfile_bfd, \
670 (unsigned char *)&(symp)->n_strx); \
dcc35536 671 (symp)->n_desc = bfd_h_get_16 (symfile_bfd, \
bd5635a1 672 (unsigned char *)&(symp)->n_desc); \
dcc35536 673 (symp)->n_value = bfd_h_get_32 (symfile_bfd, \
bd5635a1
RP
674 (unsigned char *)&(symp)->n_value); \
675 }
676
677/* Invariant: The symbol pointed to by symbuf_idx is the first one
678 that hasn't been swapped. Swap the symbol at the same time
679 that symbuf_idx is incremented. */
680
681/* dbx allows the text of a symbol name to be continued into the
682 next symbol name! When such a continuation is encountered
683 (a \ at the end of the text of a name)
684 call this function to get the continuation. */
685
c0302457 686char *
bd5635a1
RP
687next_symbol_text ()
688{
689 if (symbuf_idx == symbuf_end)
690 fill_symbuf ();
691 symnum++;
692 SWAP_SYMBOL(&symbuf[symbuf_idx]);
afe4ca15 693 return symbuf[symbuf_idx++].n_strx + stringtab_global;
bd5635a1
RP
694}
695\f
696/* Initializes storage for all of the partial symbols that will be
697 created by read_dbx_symtab and subsidiaries. */
698
699static void
700init_psymbol_list (total_symbols)
701 int total_symbols;
702{
703 /* Free any previously allocated psymbol lists. */
704 if (global_psymbols.list)
705 free (global_psymbols.list);
706 if (static_psymbols.list)
707 free (static_psymbols.list);
708
709 /* Current best guess is that there are approximately a twentieth
710 of the total symbols (in a debugging file) are global or static
711 oriented symbols */
712 global_psymbols.size = total_symbols / 10;
713 static_psymbols.size = total_symbols / 10;
714 global_psymbols.next = global_psymbols.list = (struct partial_symbol *)
715 xmalloc (global_psymbols.size * sizeof (struct partial_symbol));
716 static_psymbols.next = static_psymbols.list = (struct partial_symbol *)
717 xmalloc (static_psymbols.size * sizeof (struct partial_symbol));
718}
719
720/* Initialize the list of bincls to contain none and have some
721 allocated. */
722
723static void
724init_bincl_list (number)
725 int number;
726{
727 bincls_allocated = number;
728 next_bincl = bincl_list = (struct header_file_location *)
729 xmalloc (bincls_allocated * sizeof(struct header_file_location));
730}
731
732/* Add a bincl to the list. */
733
734static void
735add_bincl_to_list (pst, name, instance)
736 struct partial_symtab *pst;
737 char *name;
738 int instance;
739{
740 if (next_bincl >= bincl_list + bincls_allocated)
741 {
742 int offset = next_bincl - bincl_list;
743 bincls_allocated *= 2;
744 bincl_list = (struct header_file_location *)
745 xrealloc ((char *)bincl_list,
746 bincls_allocated * sizeof (struct header_file_location));
747 next_bincl = bincl_list + offset;
748 }
749 next_bincl->pst = pst;
750 next_bincl->instance = instance;
751 next_bincl++->name = name;
752}
753
754/* Given a name, value pair, find the corresponding
755 bincl in the list. Return the partial symtab associated
756 with that header_file_location. */
757
9bba3334 758static struct partial_symtab *
bd5635a1
RP
759find_corresponding_bincl_psymtab (name, instance)
760 char *name;
761 int instance;
762{
763 struct header_file_location *bincl;
764
765 for (bincl = bincl_list; bincl < next_bincl; bincl++)
766 if (bincl->instance == instance
767 && !strcmp (name, bincl->name))
768 return bincl->pst;
769
770 return (struct partial_symtab *) 0;
771}
772
773/* Free the storage allocated for the bincl list. */
774
775static void
776free_bincl_list ()
777{
778 free (bincl_list);
779 bincls_allocated = 0;
780}
781
782static struct partial_symtab *start_psymtab ();
783static void end_psymtab();
784
785#ifdef DEBUG
786/* This is normally a macro defined in read_dbx_symtab, but this
787 is a lot easier to debug. */
788
789ADD_PSYMBOL_TO_PLIST(NAME, NAMELENGTH, NAMESPACE, CLASS, PLIST, VALUE)
790 char *NAME;
791 int NAMELENGTH;
792 enum namespace NAMESPACE;
793 enum address_class CLASS;
794 struct psymbol_allocation_list *PLIST;
795 unsigned long VALUE;
796{
797 register struct partial_symbol *psym;
798
799#define LIST *PLIST
800 do {
801 if ((LIST).next >=
802 (LIST).list + (LIST).size)
803 {
804 (LIST).list = (struct partial_symbol *)
805 xrealloc ((LIST).list,
806 ((LIST).size * 2
807 * sizeof (struct partial_symbol)));
808 /* Next assumes we only went one over. Should be good if
809 program works correctly */
810 (LIST).next =
811 (LIST).list + (LIST).size;
812 (LIST).size *= 2;
813 }
814 psym = (LIST).next++;
815#undef LIST
816
817 SYMBOL_NAME (psym) = (char *) obstack_alloc (psymbol_obstack,
818 (NAMELENGTH) + 1);
819 strncpy (SYMBOL_NAME (psym), (NAME), (NAMELENGTH));
820 SYMBOL_NAME (psym)[(NAMELENGTH)] = '\0';
821 SYMBOL_NAMESPACE (psym) = (NAMESPACE);
822 SYMBOL_CLASS (psym) = (CLASS);
823 SYMBOL_VALUE (psym) = (VALUE);
824 } while (0);
825}
826
827/* Since one arg is a struct, we have to pass in a ptr and deref it (sigh) */
828#define ADD_PSYMBOL_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \
829 ADD_PSYMBOL_TO_PLIST(NAME, NAMELENGTH, NAMESPACE, CLASS, &LIST, VALUE)
830
831#endif /* DEBUG */
832
833/* Given pointers to an a.out symbol table in core containing dbx
834 style data, setup partial_symtab's describing each source file for
835 which debugging information is available. NLISTLEN is the number
836 of symbols in the symbol table. All symbol names are given as
837 offsets relative to STRINGTAB. STRINGTAB_SIZE is the size of
838 STRINGTAB. SYMFILE_NAME is the name of the file we are reading from
839 and ADDR is its relocated address (if incremental) or 0 (if not). */
840
841static void
842read_dbx_symtab (symfile_name, addr,
843 desc, stringtab, stringtab_size, nlistlen,
844 text_addr, text_size)
845 char *symfile_name;
846 CORE_ADDR addr;
847 int desc;
848 register char *stringtab;
849 register long stringtab_size;
850 register int nlistlen;
851 CORE_ADDR text_addr;
852 int text_size;
853{
afe4ca15 854 register struct internal_nlist *bufp;
bd5635a1
RP
855 register char *namestring;
856 register struct partial_symbol *psym;
857 int nsl;
858 int past_first_source_file = 0;
859 CORE_ADDR last_o_file_start = 0;
860 struct cleanup *old_chain;
861 char *p;
862
863 /* End of the text segment of the executable file. */
864 CORE_ADDR end_of_text_addr;
865
866 /* Current partial symtab */
867 struct partial_symtab *pst;
868
869 /* List of current psymtab's include files */
870 char **psymtab_include_list;
871 int includes_allocated;
872 int includes_used;
873
874 /* Index within current psymtab dependency list */
875 struct partial_symtab **dependency_list;
876 int dependencies_used, dependencies_allocated;
877
878 stringtab_global = stringtab;
879
880 pst = (struct partial_symtab *) 0;
881
882 includes_allocated = 30;
883 includes_used = 0;
884 psymtab_include_list = (char **) alloca (includes_allocated *
885 sizeof (char *));
886
887 dependencies_allocated = 30;
888 dependencies_used = 0;
889 dependency_list =
890 (struct partial_symtab **) alloca (dependencies_allocated *
891 sizeof (struct partial_symtab *));
892
893 /* FIXME!! If an error occurs, this blows away the whole symbol table!
894 It should only blow away the psymtabs created herein. We could
895 be reading a shared library or a dynloaded file! */
896 old_chain = make_cleanup (free_all_psymtabs, 0);
897
898 /* Init bincl list */
899 init_bincl_list (20);
900 make_cleanup (free_bincl_list, 0);
901
902 last_source_file = 0;
903
904#ifdef END_OF_TEXT_DEFAULT
905 end_of_text_addr = END_OF_TEXT_DEFAULT;
906#else
5bc757e2 907 end_of_text_addr = text_addr + addr + text_size; /* Relocate */
bd5635a1
RP
908#endif
909
910 symtab_input_desc = desc; /* This is needed for fill_symbuf below */
911 symbuf_end = symbuf_idx = 0;
912
913 for (symnum = 0; symnum < nlistlen; symnum++)
914 {
915 /* Get the symbol for this run and pull out some info */
916 QUIT; /* allow this to be interruptable */
917 if (symbuf_idx == symbuf_end)
918 fill_symbuf ();
919 bufp = &symbuf[symbuf_idx++];
920
921 /*
922 * Special case to speed up readin.
923 */
924 if (bufp->n_type == (unsigned char)N_SLINE) continue;
925
926 SWAP_SYMBOL (bufp);
927
928 /* Ok. There is a lot of code duplicated in the rest of this
929 switch statement (for efficiency reasons). Since I don't
930 like duplicating code, I will do my penance here, and
931 describe the code which is duplicated:
932
933 *) The assignment to namestring.
934 *) The call to strchr.
935 *) The addition of a partial symbol the the two partial
936 symbol lists. This last is a large section of code, so
937 I've imbedded it in the following macro.
938 */
939
940/* Set namestring based on bufp. If the string table index is invalid,
941 give a fake name, and print a single error message per symbol file read,
942 rather than abort the symbol reading or flood the user with messages. */
943#define SET_NAMESTRING()\
afe4ca15 944 if (bufp->n_strx < 0 || bufp->n_strx >= stringtab_size) { \
bd5635a1
RP
945 complain (&string_table_offset_complaint, symnum); \
946 namestring = "foo"; \
947 } else \
afe4ca15 948 namestring = bufp->n_strx + stringtab
bd5635a1
RP
949
950/* Add a symbol with an integer value to a psymtab. */
951/* This is a macro unless we're debugging. See above this function. */
952#ifndef DEBUG
953# define ADD_PSYMBOL_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \
954 ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, \
955 SYMBOL_VALUE)
956#endif /* DEBUG */
957
958/* Add a symbol with a CORE_ADDR value to a psymtab. */
959#define ADD_PSYMBOL_ADDR_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \
960 ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, \
961 SYMBOL_VALUE_ADDRESS)
962
963/* Add any kind of symbol to a psymtab. */
964#define ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, VT)\
965 do { \
966 if ((LIST).next >= \
967 (LIST).list + (LIST).size) \
968 { \
969 (LIST).list = (struct partial_symbol *) \
970 xrealloc ((LIST).list, \
971 ((LIST).size * 2 \
972 * sizeof (struct partial_symbol))); \
973 /* Next assumes we only went one over. Should be good if \
974 program works correctly */ \
975 (LIST).next = \
976 (LIST).list + (LIST).size; \
977 (LIST).size *= 2; \
978 } \
979 psym = (LIST).next++; \
980 \
981 SYMBOL_NAME (psym) = (char *) obstack_alloc (psymbol_obstack, \
982 (NAMELENGTH) + 1); \
983 strncpy (SYMBOL_NAME (psym), (NAME), (NAMELENGTH)); \
984 SYMBOL_NAME (psym)[(NAMELENGTH)] = '\0'; \
985 SYMBOL_NAMESPACE (psym) = (NAMESPACE); \
986 SYMBOL_CLASS (psym) = (CLASS); \
987 VT (psym) = (VALUE); \
988 } while (0);
989
990/* End of macro definitions, now let's handle them symbols! */
991
992 switch (bufp->n_type)
993 {
994 /*
995 * Standard, external, non-debugger, symbols
996 */
997
998 case N_TEXT | N_EXT:
999 case N_NBTEXT | N_EXT:
1000 case N_NBDATA | N_EXT:
1001 case N_NBBSS | N_EXT:
1002 case N_SETV | N_EXT:
1003 case N_ABS | N_EXT:
1004 case N_DATA | N_EXT:
1005 case N_BSS | N_EXT:
1006
1007 bufp->n_value += addr; /* Relocate */
1008
1009 SET_NAMESTRING();
1010
1011 bss_ext_symbol:
1012 record_misc_function (namestring, bufp->n_value,
1013 bufp->n_type); /* Always */
1014
1015 continue;
1016
1017 /* Standard, local, non-debugger, symbols */
1018
1019 case N_NBTEXT:
1020
1021 /* We need to be able to deal with both N_FN or N_TEXT,
1022 because we have no way of knowing whether the sys-supplied ld
6150cc73
JG
1023 or GNU ld was used to make the executable. Sequents throw
1024 in another wrinkle -- they renumbered N_FN. */
bd5635a1 1025 case N_FN:
6150cc73 1026 case N_FN_SEQ:
bd5635a1
RP
1027 case N_TEXT:
1028 bufp->n_value += addr; /* Relocate */
1029 SET_NAMESTRING();
1030 if ((namestring[0] == '-' && namestring[1] == 'l')
1031 || (namestring [(nsl = strlen (namestring)) - 1] == 'o'
1032 && namestring [nsl - 2] == '.'))
1033 {
1034 if (entry_point < bufp->n_value
1035 && entry_point >= last_o_file_start
1036 && addr == 0) /* FIXME nogood nomore */
1037 {
1038 startup_file_start = last_o_file_start;
1039 startup_file_end = bufp->n_value;
1040 }
1041 if (past_first_source_file && pst
1042 /* The gould NP1 uses low values for .o and -l symbols
1043 which are not the address. */
1044 && bufp->n_value > pst->textlow)
1045 {
1046 end_psymtab (pst, psymtab_include_list, includes_used,
afe4ca15 1047 symnum * symbol_size, bufp->n_value,
bd5635a1
RP
1048 dependency_list, dependencies_used,
1049 global_psymbols.next, static_psymbols.next);
1050 pst = (struct partial_symtab *) 0;
1051 includes_used = 0;
1052 dependencies_used = 0;
1053 }
1054 else
1055 past_first_source_file = 1;
1056 last_o_file_start = bufp->n_value;
1057 }
1058 continue;
1059
1060 case N_DATA:
1061 bufp->n_value += addr; /* Relocate */
1062 SET_NAMESTRING ();
1063 /* Check for __DYNAMIC, which is used by Sun shared libraries.
62c4f98b
JK
1064 Record it even if it's local, not global, so we can find it.
1065 Same with virtual function tables, both global and static. */
1066 if ((namestring[8] == 'C' && (strcmp ("__DYNAMIC", namestring) == 0))
1067 || VTBL_PREFIX_P ((namestring+HASH_OFFSET)))
bd5635a1
RP
1068 {
1069 /* Not really a function here, but... */
1070 record_misc_function (namestring, bufp->n_value,
1071 bufp->n_type); /* Always */
1072 }
1073 continue;
1074
1075 case N_UNDF | N_EXT:
1076 if (bufp->n_value != 0) {
1077 /* This is a "Fortran COMMON" symbol. See if the target
1078 environment knows where it has been relocated to. */
1079
1080 CORE_ADDR reladdr;
1081
1082 SET_NAMESTRING();
1083 if (target_lookup_symbol (namestring, &reladdr)) {
1084 continue; /* Error in lookup; ignore symbol for now. */
1085 }
1086 bufp->n_type ^= (N_BSS^N_UNDF); /* Define it as a bss-symbol */
1087 bufp->n_value = reladdr;
1088 goto bss_ext_symbol;
1089 }
1090 continue; /* Just undefined, not COMMON */
1091
1092 /* Lots of symbol types we can just ignore. */
1093
1094 case N_UNDF:
1095 case N_ABS:
1096 case N_BSS:
1097 case N_NBDATA:
1098 case N_NBBSS:
1099 continue;
1100
1101 /* Keep going . . .*/
1102
1103 /*
1104 * Special symbol types for GNU
1105 */
1106 case N_INDR:
1107 case N_INDR | N_EXT:
1108 case N_SETA:
1109 case N_SETA | N_EXT:
1110 case N_SETT:
1111 case N_SETT | N_EXT:
1112 case N_SETD:
1113 case N_SETD | N_EXT:
1114 case N_SETB:
1115 case N_SETB | N_EXT:
1116 case N_SETV:
1117 continue;
1118
1119 /*
1120 * Debugger symbols
1121 */
1122
1123 case N_SO: {
1124 unsigned long valu = bufp->n_value;
1125 /* Symbol number of the first symbol of this file (i.e. the N_SO
1126 if there is just one, or the first if we have a pair). */
1127 int first_symnum = symnum;
1128
1129 /* End the current partial symtab and start a new one */
1130
1131 SET_NAMESTRING();
1132
1133 /* Peek at the next symbol. If it is also an N_SO, the
1134 first one just indicates the directory. */
1135 if (symbuf_idx == symbuf_end)
1136 fill_symbuf ();
1137 bufp = &symbuf[symbuf_idx];
1138 /* n_type is only a char, so swapping swapping is irrelevant. */
1139 if (bufp->n_type == (unsigned char)N_SO)
1140 {
1141 SWAP_SYMBOL (bufp);
1142 SET_NAMESTRING ();
1143 valu = bufp->n_value;
1144 symbuf_idx++;
1145 symnum++;
1146 }
1147 valu += addr; /* Relocate */
1148
1149 if (pst && past_first_source_file)
1150 {
1151 end_psymtab (pst, psymtab_include_list, includes_used,
afe4ca15 1152 first_symnum * symbol_size, valu,
bd5635a1
RP
1153 dependency_list, dependencies_used,
1154 global_psymbols.next, static_psymbols.next);
1155 pst = (struct partial_symtab *) 0;
1156 includes_used = 0;
1157 dependencies_used = 0;
1158 }
1159 else
1160 past_first_source_file = 1;
1161
1162 pst = start_psymtab (symfile_name, addr,
1163 namestring, valu,
afe4ca15 1164 first_symnum * symbol_size,
bd5635a1 1165 global_psymbols.next, static_psymbols.next);
bd5635a1
RP
1166 continue;
1167 }
1168
1169 case N_BINCL:
1170 /* Add this bincl to the bincl_list for future EXCLs. No
1171 need to save the string; it'll be around until
1172 read_dbx_symtab function returns */
1173
1174 SET_NAMESTRING();
1175
1176 add_bincl_to_list (pst, namestring, bufp->n_value);
1177
1178 /* Mark down an include file in the current psymtab */
1179
1180 psymtab_include_list[includes_used++] = namestring;
1181 if (includes_used >= includes_allocated)
1182 {
1183 char **orig = psymtab_include_list;
1184
1185 psymtab_include_list = (char **)
1186 alloca ((includes_allocated *= 2) *
1187 sizeof (char *));
1188 bcopy (orig, psymtab_include_list,
1189 includes_used * sizeof (char *));
1190 }
1191
1192 continue;
1193
1194 case N_SOL:
1195 /* Mark down an include file in the current psymtab */
1196
1197 SET_NAMESTRING();
1198
1199 /* In C++, one may expect the same filename to come round many
1200 times, when code is coming alternately from the main file
1201 and from inline functions in other files. So I check to see
f9623881
JG
1202 if this is a file we've seen before -- either the main
1203 source file, or a previously included file.
bd5635a1
RP
1204
1205 This seems to be a lot of time to be spending on N_SOL, but
9bb30452 1206 things like "break c-exp.y:435" need to work (I
bd5635a1
RP
1207 suppose the psymtab_include_list could be hashed or put
1208 in a binary tree, if profiling shows this is a major hog). */
4a35d6e9 1209 if (pst && !strcmp (namestring, pst->filename))
f9623881 1210 continue;
bd5635a1
RP
1211 {
1212 register int i;
1213 for (i = 0; i < includes_used; i++)
1214 if (!strcmp (namestring, psymtab_include_list[i]))
1215 {
1216 i = -1;
1217 break;
1218 }
1219 if (i == -1)
1220 continue;
1221 }
1222
1223 psymtab_include_list[includes_used++] = namestring;
1224 if (includes_used >= includes_allocated)
1225 {
1226 char **orig = psymtab_include_list;
1227
1228 psymtab_include_list = (char **)
1229 alloca ((includes_allocated *= 2) *
1230 sizeof (char *));
1231 bcopy (orig, psymtab_include_list,
1232 includes_used * sizeof (char *));
1233 }
1234 continue;
1235
1236 case N_LSYM: /* Typedef or automatic variable. */
9bb30452
JG
1237 case N_STSYM: /* Data seg var -- static */
1238 case N_LCSYM: /* BSS " */
1239 case N_NBSTS: /* Gould nobase. */
1240 case N_NBLCS: /* symbols. */
1241
bd5635a1
RP
1242 SET_NAMESTRING();
1243
1244 p = (char *) strchr (namestring, ':');
1245
1246 /* Skip if there is no :. */
1247 if (!p) continue;
1248
1249 switch (p[1])
1250 {
1251 case 'T':
1252 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
1253 STRUCT_NAMESPACE, LOC_TYPEDEF,
1254 static_psymbols, bufp->n_value);
1255 if (p[2] == 't')
1256 {
1257 /* Also a typedef with the same name. */
1258 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
1259 VAR_NAMESPACE, LOC_TYPEDEF,
1260 static_psymbols, bufp->n_value);
1261 p += 1;
1262 }
1263 goto check_enum;
1264 case 't':
1265 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
1266 VAR_NAMESPACE, LOC_TYPEDEF,
1267 static_psymbols, bufp->n_value);
1268 check_enum:
1269 /* If this is an enumerated type, we need to
1270 add all the enum constants to the partial symbol
1271 table. This does not cover enums without names, e.g.
1272 "enum {a, b} c;" in C, but fortunately those are
1273 rare. There is no way for GDB to find those from the
1274 enum type without spending too much time on it. Thus
1275 to solve this problem, the compiler needs to put out separate
1276 constant symbols ('c' N_LSYMS) for enum constants in
1277 enums without names, or put out a dummy type. */
1278
1279 /* We are looking for something of the form
1280 <name> ":" ("t" | "T") [<number> "="] "e"
1281 {<constant> ":" <value> ","} ";". */
1282
1283 /* Skip over the colon and the 't' or 'T'. */
1284 p += 2;
1285 /* This type may be given a number. Skip over it. */
1286 while ((*p >= '0' && *p <= '9')
1287 || *p == '=')
1288 p++;
1289
1290 if (*p++ == 'e')
1291 {
1292 /* We have found an enumerated type. */
1293 /* According to comments in read_enum_type
1294 a comma could end it instead of a semicolon.
1295 I don't know where that happens.
1296 Accept either. */
1297 while (*p && *p != ';' && *p != ',')
1298 {
1299 char *q;
1300
1301 /* Check for and handle cretinous dbx symbol name
1302 continuation! */
1303 if (*p == '\\')
1304 p = next_symbol_text ();
1305
1306 /* Point to the character after the name
1307 of the enum constant. */
1308 for (q = p; *q && *q != ':'; q++)
1309 ;
1310 /* Note that the value doesn't matter for
1311 enum constants in psymtabs, just in symtabs. */
1312 ADD_PSYMBOL_TO_LIST (p, q - p,
1313 VAR_NAMESPACE, LOC_CONST,
1314 static_psymbols, 0);
1315 /* Point past the name. */
1316 p = q;
1317 /* Skip over the value. */
1318 while (*p && *p != ',')
1319 p++;
1320 /* Advance past the comma. */
1321 if (*p)
1322 p++;
1323 }
1324 }
1325
1326 continue;
1327 case 'c':
1328 /* Constant, e.g. from "const" in Pascal. */
1329 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
1330 VAR_NAMESPACE, LOC_CONST,
1331 static_psymbols, bufp->n_value);
1332 continue;
1333 default:
1334 /* Skip if the thing following the : is
1335 not a letter (which indicates declaration of a local
1336 variable, which we aren't interested in). */
1337 continue;
1338 }
1339
1340 case N_FUN:
1341 case N_GSYM: /* Global (extern) variable; can be
1342 data or bss (sigh). */
bd5635a1
RP
1343
1344 /* Following may probably be ignored; I'll leave them here
1345 for now (until I do Pascal and Modula 2 extensions). */
1346
1347 case N_PC: /* I may or may not need this; I
1348 suspect not. */
1349 case N_M2C: /* I suspect that I can ignore this here. */
1350 case N_SCOPE: /* Same. */
1351
1352 SET_NAMESTRING();
1353
1354 p = (char *) strchr (namestring, ':');
1355 if (!p)
1356 continue; /* Not a debugging symbol. */
1357
1358
1359
1360 /* Main processing section for debugging symbols which
1361 the initial read through the symbol tables needs to worry
1362 about. If we reach this point, the symbol which we are
1363 considering is definitely one we are interested in.
1364 p must also contain the (valid) index into the namestring
1365 which indicates the debugging type symbol. */
1366
1367 switch (p[1])
1368 {
1369 case 'c':
1370 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
1371 VAR_NAMESPACE, LOC_CONST,
1372 static_psymbols, bufp->n_value);
1373 continue;
1374 case 'S':
1375 bufp->n_value += addr; /* Relocate */
1376 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
1377 VAR_NAMESPACE, LOC_STATIC,
1378 static_psymbols, bufp->n_value);
1379 continue;
1380 case 'G':
1381 bufp->n_value += addr; /* Relocate */
c3a21801
JG
1382 /* The addresses in these entries are reported to be
1383 wrong. See the code that reads 'G's for symtabs. */
bd5635a1 1384 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
c3a21801 1385 VAR_NAMESPACE, LOC_STATIC,
bd5635a1
RP
1386 global_psymbols, bufp->n_value);
1387 continue;
1388
1389 case 't':
1390 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
1391 VAR_NAMESPACE, LOC_TYPEDEF,
9bb30452 1392 static_psymbols, bufp->n_value);
bd5635a1
RP
1393 continue;
1394
1395 case 'f':
1396 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
1397 VAR_NAMESPACE, LOC_BLOCK,
1398 static_psymbols, bufp->n_value);
1399 continue;
1400
f9623881
JG
1401 /* Global functions were ignored here, but now they
1402 are put into the global psymtab like one would expect.
1403 They're also in the misc fn vector...
1404 FIXME, why did it used to ignore these? That broke
1405 "i fun" on these functions. */
1406 case 'F':
1407 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
1408 VAR_NAMESPACE, LOC_BLOCK,
1409 global_psymbols, bufp->n_value);
1410 continue;
1411
bd5635a1
RP
1412 /* Two things show up here (hopefully); static symbols of
1413 local scope (static used inside braces) or extensions
1414 of structure symbols. We can ignore both. */
1415 case 'V':
1416 case '(':
1417 case '0':
1418 case '1':
1419 case '2':
1420 case '3':
1421 case '4':
1422 case '5':
1423 case '6':
1424 case '7':
1425 case '8':
1426 case '9':
bd5635a1
RP
1427 continue;
1428
1429 default:
1430 /* Unexpected symbol. Ignore it; perhaps it is an extension
1431 that we don't know about.
1432
1433 Someone says sun cc puts out symbols like
1434 /foo/baz/maclib::/usr/local/bin/maclib,
1435 which would get here with a symbol type of ':'. */
1436 continue;
1437 }
1438
1439 case N_EXCL:
1440
1441 SET_NAMESTRING();
1442
1443 /* Find the corresponding bincl and mark that psymtab on the
1444 psymtab dependency list */
1445 {
1446 struct partial_symtab *needed_pst =
1447 find_corresponding_bincl_psymtab (namestring, bufp->n_value);
1448
1449 /* If this include file was defined earlier in this file,
1450 leave it alone. */
1451 if (needed_pst == pst) continue;
1452
1453 if (needed_pst)
1454 {
1455 int i;
1456 int found = 0;
1457
1458 for (i = 0; i < dependencies_used; i++)
1459 if (dependency_list[i] == needed_pst)
1460 {
1461 found = 1;
1462 break;
1463 }
1464
1465 /* If it's already in the list, skip the rest. */
1466 if (found) continue;
1467
1468 dependency_list[dependencies_used++] = needed_pst;
1469 if (dependencies_used >= dependencies_allocated)
1470 {
1471 struct partial_symtab **orig = dependency_list;
1472 dependency_list =
1473 (struct partial_symtab **)
1474 alloca ((dependencies_allocated *= 2)
1475 * sizeof (struct partial_symtab *));
1476 bcopy (orig, dependency_list,
1477 (dependencies_used
1478 * sizeof (struct partial_symtab *)));
1479#ifdef DEBUG_INFO
1480 fprintf (stderr, "Had to reallocate dependency list.\n");
1481 fprintf (stderr, "New dependencies allocated: %d\n",
1482 dependencies_allocated);
1483#endif
1484 }
1485 }
1486 else
1487 error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.",
1488 symnum);
1489 }
1490 continue;
1491
1492 case N_EINCL:
1493 case N_DSLINE:
1494 case N_BSLINE:
1495 case N_SSYM: /* Claim: Structure or union element.
1496 Hopefully, I can ignore this. */
1497 case N_ENTRY: /* Alternate entry point; can ignore. */
1498 case N_MAIN: /* Can definitely ignore this. */
1499 case N_CATCH: /* These are GNU C++ extensions */
1500 case N_EHDECL: /* that can safely be ignored here. */
1501 case N_LENG:
1502 case N_BCOMM:
1503 case N_ECOMM:
1504 case N_ECOML:
1505 case N_FNAME:
1506 case N_SLINE:
1507 case N_RSYM:
1508 case N_PSYM:
1509 case N_LBRAC:
1510 case N_RBRAC:
1511 case N_NSYMS: /* Ultrix 4.0: symbol count */
0c4d2cc2 1512 case N_DEFD: /* GNU Modula-2 */
bd5635a1
RP
1513 /* These symbols aren't interesting; don't worry about them */
1514
1515 continue;
1516
1517 default:
1518 /* If we haven't found it yet, ignore it. It's probably some
1519 new type we don't know about yet. */
0c4d2cc2 1520 complain (&unknown_symtype_complaint, local_hex_string(bufp->n_type));
bd5635a1
RP
1521 continue;
1522 }
1523 }
1524
1525 /* If there's stuff to be cleaned up, clean it up. */
63989338
JG
1526 if (nlistlen > 0 /* We have some syms */
1527 && entry_point < bufp->n_value
bd5635a1
RP
1528 && entry_point >= last_o_file_start)
1529 {
1530 startup_file_start = last_o_file_start;
1531 startup_file_end = bufp->n_value;
1532 }
1533
1534 if (pst)
1535 {
1536 end_psymtab (pst, psymtab_include_list, includes_used,
afe4ca15 1537 symnum * symbol_size, end_of_text_addr,
bd5635a1
RP
1538 dependency_list, dependencies_used,
1539 global_psymbols.next, static_psymbols.next);
1540 includes_used = 0;
1541 dependencies_used = 0;
1542 pst = (struct partial_symtab *) 0;
1543 }
1544
1545 free_bincl_list ();
1546 discard_cleanups (old_chain);
1547}
1548
4a35d6e9
FF
1549/* Allocate and partially fill a partial symtab. It will be
1550 completely filled at the end of the symbol list.
1551
1552 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
1553 is the address relative to which its symbols are (incremental) or 0
1554 (normal). */
1555
bd5635a1 1556
bd5635a1
RP
1557static struct partial_symtab *
1558start_psymtab (symfile_name, addr,
1559 filename, textlow, ldsymoff, global_syms, static_syms)
1560 char *symfile_name;
1561 CORE_ADDR addr;
1562 char *filename;
1563 CORE_ADDR textlow;
1564 int ldsymoff;
1565 struct partial_symbol *global_syms;
1566 struct partial_symbol *static_syms;
1567{
1568 struct partial_symtab *result =
1569 (struct partial_symtab *) obstack_alloc (psymbol_obstack,
1570 sizeof (struct partial_symtab));
1571
1572 result->addr = addr;
1573
1574 result->symfile_name =
1575 (char *) obstack_alloc (psymbol_obstack,
1576 strlen (symfile_name) + 1);
1577 strcpy (result->symfile_name, symfile_name);
1578
1579 result->filename =
1580 (char *) obstack_alloc (psymbol_obstack,
1581 strlen (filename) + 1);
1582 strcpy (result->filename, filename);
1583
1584 result->textlow = textlow;
4a35d6e9
FF
1585 result->read_symtab_private = (char *) obstack_alloc (psymbol_obstack,
1586 sizeof (struct symloc));
1587 LDSYMOFF(result) = ldsymoff;
bd5635a1
RP
1588
1589 result->readin = 0;
1590 result->symtab = 0;
1591 result->read_symtab = dbx_psymtab_to_symtab;
1592
1593 result->globals_offset = global_syms - global_psymbols.list;
1594 result->statics_offset = static_syms - static_psymbols.list;
1595
1596 result->n_global_syms = 0;
1597 result->n_static_syms = 0;
1598
1599
1600 return result;
1601}
1602
1603static int
1604compare_psymbols (s1, s2)
1605 register struct partial_symbol *s1, *s2;
1606{
1607 register char
1608 *st1 = SYMBOL_NAME (s1),
1609 *st2 = SYMBOL_NAME (s2);
1610
0c4d2cc2
JG
1611 if (st1[0] - st2[0])
1612 return st1[0] - st2[0];
1613 if (st1[1] - st2[1])
1614 return st1[1] - st2[1];
1615 return strcmp (st1 + 1, st2 + 1);
bd5635a1
RP
1616}
1617
1618
1619/* Close off the current usage of a partial_symbol table entry. This
1620 involves setting the correct number of includes (with a realloc),
1621 setting the high text mark, setting the symbol length in the
1622 executable, and setting the length of the global and static lists
1623 of psymbols.
1624
1625 The global symbols and static symbols are then seperately sorted.
1626
1627 Then the partial symtab is put on the global list.
1628 *** List variables and peculiarities of same. ***
1629 */
1630static void
1631end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
1632 capping_text, dependency_list, number_dependencies,
1633 capping_global, capping_static)
1634 struct partial_symtab *pst;
1635 char **include_list;
1636 int num_includes;
1637 int capping_symbol_offset;
1638 CORE_ADDR capping_text;
1639 struct partial_symtab **dependency_list;
1640 int number_dependencies;
1641 struct partial_symbol *capping_global, *capping_static;
1642{
1643 int i;
1644
4a35d6e9 1645 LDSYMLEN(pst) = capping_symbol_offset - LDSYMOFF(pst);
bd5635a1
RP
1646 pst->texthigh = capping_text;
1647
1648 pst->n_global_syms =
1649 capping_global - (global_psymbols.list + pst->globals_offset);
1650 pst->n_static_syms =
1651 capping_static - (static_psymbols.list + pst->statics_offset);
1652
1653 pst->number_of_dependencies = number_dependencies;
1654 if (number_dependencies)
1655 {
1656 pst->dependencies = (struct partial_symtab **)
1657 obstack_alloc (psymbol_obstack,
1658 number_dependencies * sizeof (struct partial_symtab *));
1659 bcopy (dependency_list, pst->dependencies,
1660 number_dependencies * sizeof (struct partial_symtab *));
1661 }
1662 else
1663 pst->dependencies = 0;
1664
1665 for (i = 0; i < num_includes; i++)
1666 {
1667 /* Eventually, put this on obstack */
1668 struct partial_symtab *subpst =
1669 (struct partial_symtab *)
1670 obstack_alloc (psymbol_obstack,
1671 sizeof (struct partial_symtab));
1672
1673 subpst->filename =
1674 (char *) obstack_alloc (psymbol_obstack,
1675 strlen (include_list[i]) + 1);
1676 strcpy (subpst->filename, include_list[i]);
1677
1678 subpst->symfile_name = pst->symfile_name;
1679 subpst->addr = pst->addr;
4a35d6e9
FF
1680 subpst->read_symtab_private = (char *) obstack_alloc (psymbol_obstack,
1681 sizeof (struct symloc));
1682 LDSYMOFF(subpst) =
1683 LDSYMLEN(subpst) =
bd5635a1
RP
1684 subpst->textlow =
1685 subpst->texthigh = 0;
1686
3f83182d
JG
1687 /* We could save slight bits of space by only making one of these,
1688 shared by the entire set of include files. FIXME-someday. */
bd5635a1
RP
1689 subpst->dependencies = (struct partial_symtab **)
1690 obstack_alloc (psymbol_obstack,
1691 sizeof (struct partial_symtab *));
1692 subpst->dependencies[0] = pst;
1693 subpst->number_of_dependencies = 1;
1694
1695 subpst->globals_offset =
1696 subpst->n_global_syms =
1697 subpst->statics_offset =
1698 subpst->n_static_syms = 0;
1699
1700 subpst->readin = 0;
9a822037 1701 subpst->symtab = 0;
bd5635a1
RP
1702 subpst->read_symtab = dbx_psymtab_to_symtab;
1703
1704 subpst->next = partial_symtab_list;
1705 partial_symtab_list = subpst;
1706 }
1707
1708 /* Sort the global list; don't sort the static list */
1709 qsort (global_psymbols.list + pst->globals_offset, pst->n_global_syms,
1710 sizeof (struct partial_symbol), compare_psymbols);
1711
f9623881
JG
1712 /* If there is already a psymtab or symtab for a file of this name, remove it.
1713 (If there is a symtab, more drastic things also happen.)
1714 This happens in VxWorks. */
1715 free_named_symtabs (pst->filename);
1716
bd5635a1
RP
1717 /* Put the psymtab on the psymtab list */
1718 pst->next = partial_symtab_list;
1719 partial_symtab_list = pst;
1720}
1721\f
1722static void
1723psymtab_to_symtab_1 (pst, desc, stringtab, stringtab_size, sym_offset)
1724 struct partial_symtab *pst;
1725 int desc;
1726 char *stringtab;
1727 int stringtab_size;
1728 int sym_offset;
1729{
1730 struct cleanup *old_chain;
1731 int i;
1732
1733 if (!pst)
1734 return;
1735
1736 if (pst->readin)
1737 {
1738 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1739 pst->filename);
1740 return;
1741 }
1742
afe4ca15 1743 /* Read in all partial symtabs on which this one is dependent */
bd5635a1
RP
1744 for (i = 0; i < pst->number_of_dependencies; i++)
1745 if (!pst->dependencies[i]->readin)
1746 {
1747 /* Inform about additional files that need to be read in. */
1748 if (info_verbose)
1749 {
1750 fputs_filtered (" ", stdout);
1751 wrap_here ("");
1752 fputs_filtered ("and ", stdout);
1753 wrap_here ("");
1754 printf_filtered ("%s...", pst->dependencies[i]->filename);
1755 wrap_here (""); /* Flush output */
1756 fflush (stdout);
1757 }
1758 psymtab_to_symtab_1 (pst->dependencies[i], desc,
1759 stringtab, stringtab_size, sym_offset);
1760 }
1761
4a35d6e9 1762 if (LDSYMLEN(pst)) /* Otherwise it's a dummy */
bd5635a1
RP
1763 {
1764 /* Init stuff necessary for reading in symbols */
c0302457 1765 buildsym_init ();
bd5635a1
RP
1766 old_chain = make_cleanup (really_free_pendings, 0);
1767
1768 /* Read in this files symbols */
1769 lseek (desc, sym_offset, L_SET);
9404978d
MT
1770 pst->symtab =
1771 read_ofile_symtab (desc, stringtab, stringtab_size,
4a35d6e9
FF
1772 LDSYMOFF(pst),
1773 LDSYMLEN(pst), pst->textlow,
9404978d
MT
1774 pst->texthigh - pst->textlow, pst->addr);
1775 sort_symtab_syms (pst->symtab);
bd5635a1
RP
1776
1777 do_cleanups (old_chain);
1778 }
1779
1780 pst->readin = 1;
1781}
1782
1783/*
1784 * Read in all of the symbols for a given psymtab for real.
1785 * Be verbose about it if the user wants that.
1786 */
1787static void
1788dbx_psymtab_to_symtab (pst)
1789 struct partial_symtab *pst;
1790{
1791 int desc;
1792 char *stringtab;
1793 int stsize, val;
1794 struct stat statbuf;
1795 struct cleanup *old_chain;
1796 bfd *sym_bfd;
1797 long st_temp;
1798
1799 if (!pst)
1800 return;
1801
1802 if (pst->readin)
1803 {
1804 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1805 pst->filename);
1806 return;
1807 }
1808
4a35d6e9 1809 if (LDSYMLEN(pst) || pst->number_of_dependencies)
bd5635a1
RP
1810 {
1811 /* Print the message now, before reading the string table,
1812 to avoid disconcerting pauses. */
1813 if (info_verbose)
1814 {
1815 printf_filtered ("Reading in symbols for %s...", pst->filename);
1816 fflush (stdout);
1817 }
1818
1819 /* Open symbol file and read in string table. Symbol_file_command
1820 guarantees that the symbol file name will be absolute, so there is
1821 no need for openp. */
1822 desc = open(pst->symfile_name, O_RDONLY, 0);
1823
1824 if (desc < 0)
1825 perror_with_name (pst->symfile_name);
1826
1827 sym_bfd = bfd_fdopenr (pst->symfile_name, NULL, desc);
1828 if (!sym_bfd)
1829 {
1830 (void)close (desc);
1831 error ("Could not open `%s' to read symbols: %s",
1832 pst->symfile_name, bfd_errmsg (bfd_error));
1833 }
1834 old_chain = make_cleanup (bfd_close, sym_bfd);
1835 if (!bfd_check_format (sym_bfd, bfd_object))
1836 error ("\"%s\": can't read symbols: %s.",
1837 pst->symfile_name, bfd_errmsg (bfd_error));
1838
1839 /* We keep the string table for symfile resident in memory, but
1840 not the string table for any other symbol files. */
66eeea27 1841 if ((symfile == 0) || 0 != strcmp(pst->symfile_name, symfile))
bd5635a1
RP
1842 {
1843 /* Read in the string table */
1844
1845 /* FIXME, this uses internal BFD variables. See above in
1846 dbx_symbol_file_open where the macro is defined! */
1847 lseek (desc, STRING_TABLE_OFFSET, L_SET);
1848
1849 val = myread (desc, &st_temp, sizeof st_temp);
1850 if (val < 0)
1851 perror_with_name (pst->symfile_name);
dcc35536 1852 stsize = bfd_h_get_32 (sym_bfd, (unsigned char *)&st_temp);
bd5635a1
RP
1853 if (fstat (desc, &statbuf) < 0)
1854 perror_with_name (pst->symfile_name);
1855
1856 if (stsize >= 0 && stsize < statbuf.st_size)
1857 {
1858#ifdef BROKEN_LARGE_ALLOCA
1859 stringtab = (char *) xmalloc (stsize);
1860 make_cleanup (free, stringtab);
1861#else
1862 stringtab = (char *) alloca (stsize);
1863#endif
1864 }
1865 else
1866 stringtab = NULL;
1867 if (stringtab == NULL && stsize != 0)
1868 error ("ridiculous string table size: %d bytes", stsize);
1869
1870 /* FIXME, this uses internal BFD variables. See above in
1871 dbx_symbol_file_open where the macro is defined! */
1872 val = lseek (desc, STRING_TABLE_OFFSET, L_SET);
1873 if (val < 0)
1874 perror_with_name (pst->symfile_name);
1875 val = myread (desc, stringtab, stsize);
1876 if (val < 0)
1877 perror_with_name (pst->symfile_name);
1878 }
1879 else
1880 {
1881 stringtab = symfile_string_table;
1882 stsize = symfile_string_table_size;
1883 }
1884
1885 symfile_bfd = sym_bfd; /* Kludge for SWAP_SYMBOL */
afe4ca15
JG
1886 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
1887 symbol_size = obj_symbol_entry_size (sym_bfd);
bd5635a1
RP
1888
1889 /* FIXME, this uses internal BFD variables. See above in
1890 dbx_symbol_file_open where the macro is defined! */
1891 psymtab_to_symtab_1 (pst, desc, stringtab, stsize,
1892 SYMBOL_TABLE_OFFSET);
1893
1894 /* Match with global symbols. This only needs to be done once,
1895 after all of the symtabs and dependencies have been read in. */
1896 scan_file_globals ();
1897
1898 do_cleanups (old_chain);
1899
1900 /* Finish up the debug error message. */
1901 if (info_verbose)
1902 printf_filtered ("done.\n");
1903 }
1904}
1905
bd5635a1 1906/* Process a pair of symbols. Currently they must both be N_SO's. */
0c4d2cc2 1907/* ARGSUSED */
bd5635a1
RP
1908static void
1909process_symbol_pair (type1, desc1, value1, name1,
1910 type2, desc2, value2, name2)
1911 int type1;
1912 int desc1;
1913 CORE_ADDR value1;
1914 char *name1;
1915 int type2;
1916 int desc2;
1917 CORE_ADDR value2;
1918 char *name2;
1919{
1920 /* No need to check PCC_SOL_BROKEN, on the assumption that such
1921 broken PCC's don't put out N_SO pairs. */
1922 if (last_source_file)
9404978d 1923 (void)end_symtab (value2);
bd5635a1
RP
1924 start_symtab (name2, name1, value2);
1925}
1926
1927/*
1928 * Read in a defined section of a specific object file's symbols.
1929 *
1930 * DESC is the file descriptor for the file, positioned at the
1931 * beginning of the symtab
1932 * STRINGTAB is a pointer to the files string
1933 * table, already read in
1934 * SYM_OFFSET is the offset within the file of
1935 * the beginning of the symbols we want to read, NUM_SUMBOLS is the
1936 * number of symbols to read
1937 * TEXT_OFFSET is the beginning of the text segment we are reading symbols for
1938 * TEXT_SIZE is the size of the text segment read in.
1939 * OFFSET is a relocation offset which gets added to each symbol
1940 */
1941
9404978d 1942static struct symtab *
bd5635a1
RP
1943read_ofile_symtab (desc, stringtab, stringtab_size, sym_offset,
1944 sym_size, text_offset, text_size, offset)
1945 int desc;
1946 register char *stringtab;
1947 unsigned int stringtab_size;
1948 int sym_offset;
1949 int sym_size;
1950 CORE_ADDR text_offset;
1951 int text_size;
1952 int offset;
1953{
1954 register char *namestring;
afe4ca15 1955 struct internal_nlist *bufp;
bd5635a1 1956 unsigned char type;
afe4ca15 1957 unsigned max_symnum;
bd5635a1
RP
1958 subfile_stack = 0;
1959
1960 stringtab_global = stringtab;
1961 last_source_file = 0;
1962
1963 symtab_input_desc = desc;
1964 symbuf_end = symbuf_idx = 0;
1965
1966 /* It is necessary to actually read one symbol *before* the start
1967 of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
1968 occurs before the N_SO symbol.
1969
1970 Detecting this in read_dbx_symtab
1971 would slow down initial readin, so we look for it here instead. */
afe4ca15 1972 if (sym_offset >= (int)symbol_size)
bd5635a1 1973 {
afe4ca15 1974 lseek (desc, sym_offset - symbol_size, L_INCR);
bd5635a1
RP
1975 fill_symbuf ();
1976 bufp = &symbuf[symbuf_idx++];
1977 SWAP_SYMBOL (bufp);
1978
afe4ca15 1979 SET_NAMESTRING ();
bd5635a1
RP
1980
1981 processing_gcc_compilation =
1982 (bufp->n_type == N_TEXT
1983 && !strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL));
afe4ca15 1984 /* FIXME!!! Check for gcc2_compiled... */
bd5635a1
RP
1985 }
1986 else
1987 {
1988 /* The N_SO starting this symtab is the first symbol, so we
1989 better not check the symbol before it. I'm not this can
1990 happen, but it doesn't hurt to check for it. */
1991 lseek(desc, sym_offset, L_INCR);
1992 processing_gcc_compilation = 0;
1993 }
1994
1995 if (symbuf_idx == symbuf_end)
1996 fill_symbuf();
1997 bufp = &symbuf[symbuf_idx];
1998 if (bufp->n_type != (unsigned char)N_SO)
1999 error("First symbol in segment of executable not a source symbol");
2000
afe4ca15
JG
2001 max_symnum = sym_size / symbol_size;
2002
bd5635a1 2003 for (symnum = 0;
afe4ca15 2004 symnum < max_symnum;
bd5635a1
RP
2005 symnum++)
2006 {
2007 QUIT; /* Allow this to be interruptable */
2008 if (symbuf_idx == symbuf_end)
2009 fill_symbuf();
2010 bufp = &symbuf[symbuf_idx++];
2011 SWAP_SYMBOL (bufp);
2012
c0302457 2013 type = bufp->n_type;
bd5635a1
RP
2014 if (type == (unsigned char)N_CATCH)
2015 {
2016 /* N_CATCH is not fixed up by the linker, and unfortunately,
2017 there's no other place to put it in the .stab map. */
62c4f98b 2018 bufp->n_value += text_offset + offset;
bd5635a1 2019 }
c0302457
JG
2020 else {
2021 type &= ~N_EXT; /* Ignore external-bit */
2022 if (type == N_TEXT || type == N_DATA || type == N_BSS)
2023 bufp->n_value += offset;
2024 type = bufp->n_type;
2025 }
bd5635a1 2026
afe4ca15 2027 SET_NAMESTRING ();
bd5635a1
RP
2028
2029 if (type & N_STAB)
2030 {
e1ce8aa5 2031 short bufp_n_desc = bufp->n_desc;
bd5635a1
RP
2032 unsigned long valu = bufp->n_value;
2033
2034 /* Check for a pair of N_SO symbols. */
2035 if (type == (unsigned char)N_SO)
2036 {
2037 if (symbuf_idx == symbuf_end)
2038 fill_symbuf ();
2039 bufp = &symbuf[symbuf_idx];
2040 if (bufp->n_type == (unsigned char)N_SO)
2041 {
afe4ca15 2042 char *namestring1 = namestring;
bd5635a1
RP
2043
2044 SWAP_SYMBOL (bufp);
2045 bufp->n_value += offset; /* Relocate */
2046 symbuf_idx++;
2047 symnum++;
afe4ca15 2048 SET_NAMESTRING ();
bd5635a1 2049
afe4ca15 2050 process_symbol_pair (N_SO, bufp_n_desc, valu, namestring1,
bd5635a1 2051 N_SO, bufp->n_desc, bufp->n_value,
afe4ca15 2052 namestring);
bd5635a1
RP
2053 }
2054 else
e1ce8aa5 2055 process_one_symbol(type, bufp_n_desc, valu, namestring);
bd5635a1
RP
2056 }
2057 else
e1ce8aa5 2058 process_one_symbol (type, bufp_n_desc, valu, namestring);
bd5635a1
RP
2059 }
2060 /* We skip checking for a new .o or -l file; that should never
2061 happen in this routine. */
2062 else if (type == N_TEXT
2063 && !strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL))
2064 /* I don't think this code will ever be executed, because
2065 the GCC_COMPILED_FLAG_SYMBOL usually is right before
2066 the N_SO symbol which starts this source file.
2067 However, there is no reason not to accept
2068 the GCC_COMPILED_FLAG_SYMBOL anywhere. */
2069 processing_gcc_compilation = 1;
2070 else if (type & N_EXT || type == (unsigned char)N_TEXT
2071 || type == (unsigned char)N_NBTEXT
0c4d2cc2 2072 ) {
bd5635a1
RP
2073 /* Global symbol: see if we came across a dbx defintion for
2074 a corresponding symbol. If so, store the value. Remove
2075 syms from the chain when their values are stored, but
2076 search the whole chain, as there may be several syms from
2077 different files with the same name. */
2078 /* This is probably not true. Since the files will be read
2079 in one at a time, each reference to a global symbol will
2080 be satisfied in each file as it appears. So we skip this
2081 section. */
2082 ;
0c4d2cc2 2083 }
bd5635a1 2084 }
9404978d
MT
2085
2086 return end_symtab (text_offset + text_size);
bd5635a1
RP
2087}
2088\f
c0302457 2089int
bd5635a1
RP
2090hashname (name)
2091 char *name;
2092{
2093 register char *p = name;
2094 register int total = p[0];
2095 register int c;
2096
2097 c = p[1];
2098 total += c << 2;
2099 if (c)
2100 {
2101 c = p[2];
2102 total += c << 4;
2103 if (c)
2104 total += p[3] << 6;
2105 }
2106
2107 /* Ensure result is positive. */
2108 if (total < 0) total += (1000 << 6);
2109 return total % HASHSIZE;
2110}
2111
2112\f
2113static void
2114process_one_symbol (type, desc, valu, name)
2115 int type, desc;
2116 CORE_ADDR valu;
2117 char *name;
2118{
2119#ifndef SUN_FIXED_LBRAC_BUG
2120 /* This records the last pc address we've seen. We depend on their being
2121 an SLINE or FUN or SO before the first LBRAC, since the variable does
2122 not get reset in between reads of different symbol files. */
2123 static CORE_ADDR last_pc_address;
2124#endif
2125 register struct context_stack *new;
2126 char *colon_pos;
2127
2128 /* Something is wrong if we see real data before
2129 seeing a source file name. */
2130
2131 if (last_source_file == 0 && type != (unsigned char)N_SO)
2132 {
2133 /* Currently this ignores N_ENTRY on Gould machines, N_NSYM on machines
2134 where that code is defined. */
2135 if (IGNORE_SYMBOL (type))
2136 return;
2137
2138 /* FIXME, this should not be an error, since it precludes extending
2139 the symbol table information in this way... */
2140 error ("Invalid symbol data: does not start by identifying a source file.");
2141 }
2142
2143 switch (type)
2144 {
2145 case N_FUN:
2146 case N_FNAME:
2147 /* Either of these types of symbols indicates the start of
2148 a new function. We must process its "name" normally for dbx,
2149 but also record the start of a new lexical context, and possibly
2150 also the end of the lexical context for the previous function. */
2151 /* This is not always true. This type of symbol may indicate a
2152 text segment variable. */
2153
2154#ifndef SUN_FIXED_LBRAC_BUG
2155 last_pc_address = valu; /* Save for SunOS bug circumcision */
2156#endif
2157
2158 colon_pos = strchr (name, ':');
2159 if (!colon_pos++
2160 || (*colon_pos != 'f' && *colon_pos != 'F'))
2161 {
2162 define_symbol (valu, name, desc, type);
2163 break;
2164 }
2165
2166 within_function = 1;
2167 if (context_stack_depth > 0)
2168 {
2169 new = &context_stack[--context_stack_depth];
2170 /* Make a block for the local symbols within. */
2171 finish_block (new->name, &local_symbols, new->old_blocks,
2172 new->start_addr, valu);
2173 }
2174 /* Stack must be empty now. */
2175 if (context_stack_depth != 0)
2176 error ("Invalid symbol data: unmatched N_LBRAC before symtab pos %d.",
2177 symnum);
2178
2179 new = &context_stack[context_stack_depth++];
2180 new->old_blocks = pending_blocks;
2181 new->start_addr = valu;
2182 new->name = define_symbol (valu, name, desc, type);
2183 local_symbols = 0;
2184 break;
2185
2186 case N_CATCH:
2187 /* Record the address at which this catch takes place. */
2188 define_symbol (valu, name, desc, type);
2189 break;
2190
2191 case N_EHDECL:
2192 /* Don't know what to do with these yet. */
2193 error ("action uncertain for eh extensions");
2194 break;
2195
2196 case N_LBRAC:
2197 /* This "symbol" just indicates the start of an inner lexical
2198 context within a function. */
2199
2200#if !defined (BLOCK_ADDRESS_ABSOLUTE)
2201 /* On most machines, the block addresses are relative to the
2202 N_SO, the linker did not relocate them (sigh). */
2203 valu += last_source_start_addr;
2204#endif
2205
2206#ifndef SUN_FIXED_LBRAC_BUG
2207 if (valu < last_pc_address) {
2208 /* Patch current LBRAC pc value to match last handy pc value */
2209 complain (&lbrac_complaint, 0);
2210 valu = last_pc_address;
2211 }
2212#endif
2213 if (context_stack_depth == context_stack_size)
2214 {
2215 context_stack_size *= 2;
2216 context_stack = (struct context_stack *)
2217 xrealloc (context_stack,
2218 (context_stack_size
2219 * sizeof (struct context_stack)));
2220 }
2221
2222 new = &context_stack[context_stack_depth++];
2223 new->depth = desc;
2224 new->locals = local_symbols;
2225 new->old_blocks = pending_blocks;
2226 new->start_addr = valu;
2227 new->name = 0;
2228 local_symbols = 0;
2229 break;
2230
2231 case N_RBRAC:
2232 /* This "symbol" just indicates the end of an inner lexical
2233 context that was started with N_LBRAC. */
2234
2235#if !defined (BLOCK_ADDRESS_ABSOLUTE)
2236 /* On most machines, the block addresses are relative to the
2237 N_SO, the linker did not relocate them (sigh). */
2238 valu += last_source_start_addr;
2239#endif
2240
2241 new = &context_stack[--context_stack_depth];
2242 if (desc != new->depth)
2243 error ("Invalid symbol data: N_LBRAC/N_RBRAC symbol mismatch, symtab pos %d.", symnum);
2244
2245 /* Some compilers put the variable decls inside of an
2246 LBRAC/RBRAC block. This macro should be nonzero if this
2247 is true. DESC is N_DESC from the N_RBRAC symbol.
2248 GCC_P is true if we've detected the GCC_COMPILED_SYMBOL. */
2249#if !defined (VARIABLES_INSIDE_BLOCK)
2250#define VARIABLES_INSIDE_BLOCK(desc, gcc_p) 0
2251#endif
2252
2253 /* Can only use new->locals as local symbols here if we're in
2254 gcc or on a machine that puts them before the lbrack. */
2255 if (!VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation))
2256 local_symbols = new->locals;
2257
2258 /* If this is not the outermost LBRAC...RBRAC pair in the
2259 function, its local symbols preceded it, and are the ones
2260 just recovered from the context stack. Defined the block for them.
2261
2262 If this is the outermost LBRAC...RBRAC pair, there is no
2263 need to do anything; leave the symbols that preceded it
2264 to be attached to the function's own block. However, if
2265 it is so, we need to indicate that we just moved outside
2266 of the function. */
2267 if (local_symbols
2268 && (context_stack_depth
2269 > !VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation)))
2270 {
2271 /* FIXME Muzzle a compiler bug that makes end < start. */
2272 if (new->start_addr > valu)
2273 {
2274 complain(&lbrac_rbrac_complaint, 0);
2275 new->start_addr = valu;
2276 }
2277 /* Make a block for the local symbols within. */
2278 finish_block (0, &local_symbols, new->old_blocks,
2279 new->start_addr, valu);
2280 }
2281 else
2282 {
2283 within_function = 0;
2284 }
2285 if (VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation))
2286 /* Now pop locals of block just finished. */
2287 local_symbols = new->locals;
2288 break;
2289
9bb30452 2290 case N_FN:
6150cc73 2291 case N_FN_SEQ:
9bb30452 2292 /* This kind of symbol indicates the start of an object file. */
bd5635a1
RP
2293 break;
2294
2295 case N_SO:
2296 /* This type of symbol indicates the start of data
2297 for one source file.
2298 Finish the symbol table of the previous source file
2299 (if any) and start accumulating a new symbol table. */
2300#ifndef SUN_FIXED_LBRAC_BUG
2301 last_pc_address = valu; /* Save for SunOS bug circumcision */
2302#endif
2303
2304#ifdef PCC_SOL_BROKEN
2305 /* pcc bug, occasionally puts out SO for SOL. */
2306 if (context_stack_depth > 0)
2307 {
2308 start_subfile (name, NULL);
2309 break;
2310 }
2311#endif
2312 if (last_source_file)
9404978d 2313 (void)end_symtab (valu);
bd5635a1
RP
2314 start_symtab (name, NULL, valu);
2315 break;
2316
2317 case N_SOL:
2318 /* This type of symbol indicates the start of data for
2319 a sub-source-file, one whose contents were copied or
2320 included in the compilation of the main source file
2321 (whose name was given in the N_SO symbol.) */
2322 start_subfile (name, NULL);
2323 break;
2324
2325 case N_BINCL:
2326 push_subfile ();
2327 add_new_header_file (name, valu);
2328 start_subfile (name, NULL);
2329 break;
2330
2331 case N_EINCL:
2332 start_subfile (pop_subfile (), NULL);
2333 break;
2334
2335 case N_EXCL:
2336 add_old_header_file (name, valu);
2337 break;
2338
2339 case N_SLINE:
2340 /* This type of "symbol" really just records
2341 one line-number -- core-address correspondence.
2342 Enter it in the line list for this symbol table. */
2343#ifndef SUN_FIXED_LBRAC_BUG
2344 last_pc_address = valu; /* Save for SunOS bug circumcision */
2345#endif
2346 record_line (desc, valu);
2347 break;
2348
2349 case N_BCOMM:
2350 if (common_block)
2351 error ("Invalid symbol data: common within common at symtab pos %d",
2352 symnum);
2353 common_block = local_symbols;
2354 common_block_i = local_symbols ? local_symbols->nsyms : 0;
2355 break;
2356
2357 case N_ECOMM:
2358 /* Symbols declared since the BCOMM are to have the common block
2359 start address added in when we know it. common_block points to
2360 the first symbol after the BCOMM in the local_symbols list;
2361 copy the list and hang it off the symbol for the common block name
2362 for later fixup. */
2363 {
2364 int i;
2365 struct symbol *sym =
2366 (struct symbol *) xmalloc (sizeof (struct symbol));
2367 bzero (sym, sizeof *sym);
2368 SYMBOL_NAME (sym) = savestring (name, strlen (name));
2369 SYMBOL_CLASS (sym) = LOC_BLOCK;
2370 SYMBOL_NAMESPACE (sym) = (enum namespace)((long)
2371 copy_pending (local_symbols, common_block_i, common_block));
2372 i = hashname (SYMBOL_NAME (sym));
2373 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
2374 global_sym_chain[i] = sym;
2375 common_block = 0;
2376 break;
2377 }
2378
2379 case N_ECOML:
2380 case N_LENG:
0c4d2cc2 2381 case N_DEFD: /* GNU Modula-2 symbol */
bd5635a1
RP
2382 break;
2383
2384 default:
2385 if (name)
2386 define_symbol (valu, name, desc, type);
2387 }
2388}
2389\f
bd5635a1
RP
2390/* To handle GNU C++ typename abbreviation, we need to be able to
2391 fill in a type's name as soon as space for that type is allocated.
2392 `type_synonym_name' is the name of the type being allocated.
2393 It is cleared as soon as it is used (lest all allocated types
2394 get this name). */
2395static char *type_synonym_name;
2396
0c4d2cc2 2397/* ARGSUSED */
bd5635a1
RP
2398static struct symbol *
2399define_symbol (valu, string, desc, type)
2400 unsigned int valu;
2401 char *string;
2402 int desc;
2403 int type;
2404{
2405 register struct symbol *sym;
2406 char *p = (char *) strchr (string, ':');
2407 int deftype;
2408 int synonym = 0;
2409 register int i;
2410
2411 /* Ignore syms with empty names. */
2412 if (string[0] == 0)
2413 return 0;
2414
2415 /* Ignore old-style symbols from cc -go */
2416 if (p == 0)
2417 return 0;
2418
2419 sym = (struct symbol *)obstack_alloc (symbol_obstack, sizeof (struct symbol));
2420
2421 if (processing_gcc_compilation) {
2422 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
2423 number of bytes occupied by a type or object, which we ignore. */
2424 SYMBOL_LINE(sym) = desc;
2425 } else {
2426 SYMBOL_LINE(sym) = 0; /* unknown */
2427 }
aec4cb91 2428
bd5635a1
RP
2429 if (string[0] == CPLUS_MARKER)
2430 {
2431 /* Special GNU C++ names. */
2432 switch (string[1])
2433 {
2434 case 't':
2435 SYMBOL_NAME (sym) = "this";
2436 break;
2437 case 'v': /* $vtbl_ptr_type */
2438 /* Was: SYMBOL_NAME (sym) = "vptr"; */
2439 goto normal;
2440 case 'e':
2441 SYMBOL_NAME (sym) = "eh_throw";
2442 break;
2443
2444 case '_':
2445 /* This was an anonymous type that was never fixed up. */
2446 goto normal;
2447
2448 default:
2449 abort ();
2450 }
2451 }
2452 else
2453 {
2454 normal:
2455 SYMBOL_NAME (sym)
2456 = (char *) obstack_alloc (symbol_obstack, ((p - string) + 1));
2457 /* Open-coded bcopy--saves function call time. */
2458 {
2459 register char *p1 = string;
2460 register char *p2 = SYMBOL_NAME (sym);
2461 while (p1 != p)
2462 *p2++ = *p1++;
2463 *p2++ = '\0';
2464 }
2465 }
2466 p++;
2467 /* Determine the type of name being defined. */
2468 /* The Acorn RISC machine's compiler can put out locals that don't
2469 start with "234=" or "(3,4)=", so assume anything other than the
2470 deftypes we know how to handle is a local. */
2471 /* (Peter Watkins @ Computervision)
2472 Handle Sun-style local fortran array types 'ar...' .
2473 (gnu@cygnus.com) -- this strchr() handles them properly?
2474 (tiemann@cygnus.com) -- 'C' is for catch. */
2475 if (!strchr ("cfFGpPrStTvVXC", *p))
2476 deftype = 'l';
2477 else
2478 deftype = *p++;
2479
2480 /* c is a special case, not followed by a type-number.
2481 SYMBOL:c=iVALUE for an integer constant symbol.
2482 SYMBOL:c=rVALUE for a floating constant symbol.
2483 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
2484 e.g. "b:c=e6,0" for "const b = blob1"
2485 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
2486 if (deftype == 'c')
2487 {
2488 if (*p++ != '=')
2489 error ("Invalid symbol data at symtab pos %d.", symnum);
2490 switch (*p++)
2491 {
2492 case 'r':
2493 {
2494 double d = atof (p);
e1ce8aa5 2495 char *dbl_valu;
bd5635a1
RP
2496
2497 SYMBOL_TYPE (sym) = builtin_type_double;
e1ce8aa5
JK
2498 dbl_valu =
2499 (char *) obstack_alloc (symbol_obstack, sizeof (double));
2500 bcopy (&d, dbl_valu, sizeof (double));
2501 SWAP_TARGET_AND_HOST (dbl_valu, sizeof (double));
2502 SYMBOL_VALUE_BYTES (sym) = dbl_valu;
bd5635a1
RP
2503 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
2504 }
2505 break;
2506 case 'i':
2507 {
2508 SYMBOL_TYPE (sym) = builtin_type_int;
2509 SYMBOL_VALUE (sym) = atoi (p);
2510 SYMBOL_CLASS (sym) = LOC_CONST;
2511 }
2512 break;
2513 case 'e':
2514 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
2515 e.g. "b:c=e6,0" for "const b = blob1"
2516 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
2517 {
2518 int typenums[2];
2519
2520 read_type_number (&p, typenums);
2521 if (*p++ != ',')
2522 error ("Invalid symbol data: no comma in enum const symbol");
2523
2524 SYMBOL_TYPE (sym) = *dbx_lookup_type (typenums);
2525 SYMBOL_VALUE (sym) = atoi (p);
2526 SYMBOL_CLASS (sym) = LOC_CONST;
2527 }
2528 break;
2529 default:
2530 error ("Invalid symbol data at symtab pos %d.", symnum);
2531 }
2532 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2533 add_symbol_to_list (sym, &file_symbols);
2534 return sym;
2535 }
2536
2537 /* Now usually comes a number that says which data type,
2538 and possibly more stuff to define the type
2539 (all of which is handled by read_type) */
2540
2541 if (deftype == 'p' && *p == 'F')
2542 /* pF is a two-letter code that means a function parameter in Fortran.
2543 The type-number specifies the type of the return value.
2544 Translate it into a pointer-to-function type. */
2545 {
2546 p++;
2547 SYMBOL_TYPE (sym)
2548 = lookup_pointer_type (lookup_function_type (read_type (&p)));
2549 }
2550 else
2551 {
e1ce8aa5 2552 struct type *type_read;
bd5635a1
RP
2553 synonym = *p == 't';
2554
2555 if (synonym)
2556 {
2557 p += 1;
2558 type_synonym_name = obsavestring (SYMBOL_NAME (sym),
2559 strlen (SYMBOL_NAME (sym)));
2560 }
2561
e1ce8aa5 2562 type_read = read_type (&p);
bd5635a1
RP
2563
2564 if ((deftype == 'F' || deftype == 'f')
e1ce8aa5 2565 && TYPE_CODE (type_read) != TYPE_CODE_FUNC)
0c4d2cc2
JG
2566 {
2567#if 0
2568/* This code doesn't work -- it needs to realloc and can't. */
2569 struct type *new = (struct type *)
2570 obstack_alloc (symbol_obstack, sizeof (struct type));
2571
2572 /* Generate a template for the type of this function. The
2573 types of the arguments will be added as we read the symbol
2574 table. */
2575 *new = *lookup_function_type (type_read);
2576 SYMBOL_TYPE(sym) = new;
2577 in_function_type = new;
2578#else
e1ce8aa5 2579 SYMBOL_TYPE (sym) = lookup_function_type (type_read);
0c4d2cc2
JG
2580#endif
2581 }
bd5635a1 2582 else
e1ce8aa5 2583 SYMBOL_TYPE (sym) = type_read;
bd5635a1
RP
2584 }
2585
2586 switch (deftype)
2587 {
2588 case 'C':
2589 /* The name of a caught exception. */
2590 SYMBOL_CLASS (sym) = LOC_LABEL;
2591 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2592 SYMBOL_VALUE_ADDRESS (sym) = valu;
2593 add_symbol_to_list (sym, &local_symbols);
2594 break;
2595
2596 case 'f':
2597 SYMBOL_CLASS (sym) = LOC_BLOCK;
2598 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2599 add_symbol_to_list (sym, &file_symbols);
2600 break;
2601
2602 case 'F':
2603 SYMBOL_CLASS (sym) = LOC_BLOCK;
2604 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2605 add_symbol_to_list (sym, &global_symbols);
2606 break;
2607
2608 case 'G':
2609 /* For a class G (global) symbol, it appears that the
2610 value is not correct. It is necessary to search for the
2611 corresponding linker definition to find the value.
2612 These definitions appear at the end of the namelist. */
2613 i = hashname (SYMBOL_NAME (sym));
2614 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
2615 global_sym_chain[i] = sym;
2616 SYMBOL_CLASS (sym) = LOC_STATIC;
2617 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2618 add_symbol_to_list (sym, &global_symbols);
2619 break;
2620
2621 /* This case is faked by a conditional above,
2622 when there is no code letter in the dbx data.
2623 Dbx data never actually contains 'l'. */
2624 case 'l':
2625 SYMBOL_CLASS (sym) = LOC_LOCAL;
2626 SYMBOL_VALUE (sym) = valu;
2627 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2628 add_symbol_to_list (sym, &local_symbols);
2629 break;
2630
2631 case 'p':
2632 /* Normally this is a parameter, a LOC_ARG. On the i960, it
2633 can also be a LOC_LOCAL_ARG depending on symbol type. */
2634#ifndef DBX_PARM_SYMBOL_CLASS
2635#define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
2636#endif
2637 SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
2638 SYMBOL_VALUE (sym) = valu;
2639 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
0c4d2cc2
JG
2640#if 0
2641 /* This doesn't work yet. */
2642 add_param_to_type (&in_function_type, sym);
2643#endif
bd5635a1
RP
2644 add_symbol_to_list (sym, &local_symbols);
2645
2646 /* If it's gcc-compiled, if it says `short', believe it. */
2647 if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
2648 break;
2649
2650#if defined(BELIEVE_PCC_PROMOTION_TYPE)
2651 /* This macro is defined on machines (e.g. sparc) where
2652 we should believe the type of a PCC 'short' argument,
2653 but shouldn't believe the address (the address is
2654 the address of the corresponding int). Note that
2655 this is only different from the BELIEVE_PCC_PROMOTION
2656 case on big-endian machines.
2657
2658 My guess is that this correction, as opposed to changing
2659 the parameter to an 'int' (as done below, for PCC
2660 on most machines), is the right thing to do
2661 on all machines, but I don't want to risk breaking
2662 something that already works. On most PCC machines,
2663 the sparc problem doesn't come up because the calling
2664 function has to zero the top bytes (not knowing whether
2665 the called function wants an int or a short), so there
2666 is no practical difference between an int and a short
2667 (except perhaps what happens when the GDB user types
2668 "print short_arg = 0x10000;").
2669
2670 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
2671 actually produces the correct address (we don't need to fix it
2672 up). I made this code adapt so that it will offset the symbol
2673 if it was pointing at an int-aligned location and not
2674 otherwise. This way you can use the same gdb for 4.0.x and
2675 4.1 systems. */
2676
2677 if (0 == SYMBOL_VALUE (sym) % sizeof (int))
2678 {
2679 if (SYMBOL_TYPE (sym) == builtin_type_char
2680 || SYMBOL_TYPE (sym) == builtin_type_unsigned_char)
2681 SYMBOL_VALUE (sym) += 3;
2682 else if (SYMBOL_TYPE (sym) == builtin_type_short
2683 || SYMBOL_TYPE (sym) == builtin_type_unsigned_short)
2684 SYMBOL_VALUE (sym) += 2;
2685 }
2686 break;
2687
2688#else /* no BELIEVE_PCC_PROMOTION_TYPE. */
2689
2690 /* If PCC says a parameter is a short or a char,
2691 it is really an int. */
2692 if (SYMBOL_TYPE (sym) == builtin_type_char
2693 || SYMBOL_TYPE (sym) == builtin_type_short)
2694 SYMBOL_TYPE (sym) = builtin_type_int;
2695 else if (SYMBOL_TYPE (sym) == builtin_type_unsigned_char
2696 || SYMBOL_TYPE (sym) == builtin_type_unsigned_short)
2697 SYMBOL_TYPE (sym) = builtin_type_unsigned_int;
2698 break;
2699
2700#endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
2701
2702 case 'P':
2703 SYMBOL_CLASS (sym) = LOC_REGPARM;
2704 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
2705 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2706 add_symbol_to_list (sym, &local_symbols);
2707 break;
2708
2709 case 'r':
2710 SYMBOL_CLASS (sym) = LOC_REGISTER;
2711 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
2712 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2713 add_symbol_to_list (sym, &local_symbols);
2714 break;
2715
2716 case 'S':
2717 /* Static symbol at top level of file */
2718 SYMBOL_CLASS (sym) = LOC_STATIC;
2719 SYMBOL_VALUE_ADDRESS (sym) = valu;
2720 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2721 add_symbol_to_list (sym, &file_symbols);
2722 break;
2723
2724 case 't':
2725 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
2726 SYMBOL_VALUE (sym) = valu;
2727 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2728 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0
2729 && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0)
2730 TYPE_NAME (SYMBOL_TYPE (sym)) =
2731 obsavestring (SYMBOL_NAME (sym),
2732 strlen (SYMBOL_NAME (sym)));
2733 /* C++ vagaries: we may have a type which is derived from
2734 a base type which did not have its name defined when the
2735 derived class was output. We fill in the derived class's
2736 base part member's name here in that case. */
2737 else if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
2738 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
2739 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
2740 {
0c4d2cc2
JG
2741 int j;
2742 for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
2743 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
2744 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
2745 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
bd5635a1
RP
2746 }
2747
2748 add_symbol_to_list (sym, &file_symbols);
2749 break;
2750
2751 case 'T':
2752 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
2753 SYMBOL_VALUE (sym) = valu;
2754 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2755 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0
2756 && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0)
2757 TYPE_NAME (SYMBOL_TYPE (sym))
2758 = obconcat ("",
2759 (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_ENUM
2760 ? "enum "
2761 : (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
2762 ? "struct " : "union ")),
2763 SYMBOL_NAME (sym));
2764 add_symbol_to_list (sym, &file_symbols);
2765
2766 if (synonym)
2767 {
2768 register struct symbol *typedef_sym
2769 = (struct symbol *) obstack_alloc (symbol_obstack, sizeof (struct symbol));
2770 SYMBOL_NAME (typedef_sym) = SYMBOL_NAME (sym);
2771 SYMBOL_TYPE (typedef_sym) = SYMBOL_TYPE (sym);
2772
2773 SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
2774 SYMBOL_VALUE (typedef_sym) = valu;
2775 SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
2776 add_symbol_to_list (typedef_sym, &file_symbols);
2777 }
2778 break;
2779
2780 case 'V':
2781 /* Static symbol of local scope */
2782 SYMBOL_CLASS (sym) = LOC_STATIC;
2783 SYMBOL_VALUE_ADDRESS (sym) = valu;
2784 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2785 add_symbol_to_list (sym, &local_symbols);
2786 break;
2787
2788 case 'v':
2789 /* Reference parameter */
2790 SYMBOL_CLASS (sym) = LOC_REF_ARG;
2791 SYMBOL_VALUE (sym) = valu;
2792 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2793 add_symbol_to_list (sym, &local_symbols);
2794 break;
2795
2796 case 'X':
2797 /* This is used by Sun FORTRAN for "function result value".
2798 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
2799 that Pascal uses it too, but when I tried it Pascal used
2800 "x:3" (local symbol) instead. */
2801 SYMBOL_CLASS (sym) = LOC_LOCAL;
2802 SYMBOL_VALUE (sym) = valu;
2803 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2804 add_symbol_to_list (sym, &local_symbols);
2805 break;
2806
2807 default:
2808 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype, symnum);
2809 }
2810 return sym;
2811}
2812\f
c0302457
JG
2813#if 0
2814/* This would be a good idea, but it doesn't really work. The problem
2815 is that in order to get the virtual context for a particular type,
2816 you need to know the virtual info from all of its basetypes,
2817 and you need to have processed its methods. Since GDB reads
2818 symbols on a file-by-file basis, this means processing the symbols
2819 of all the files that are needed for each baseclass, which
2820 means potentially reading in all the debugging info just to fill
2821 in information we may never need. */
bd5635a1 2822
c0302457 2823/* This page contains subroutines of read_type. */
bd5635a1 2824
c0302457
JG
2825/* FOR_TYPE is a struct type defining a virtual function NAME with type
2826 FN_TYPE. The `virtual context' for this virtual function is the
2827 first base class of FOR_TYPE in which NAME is defined with signature
2828 matching FN_TYPE. OFFSET serves as a hash on matches here.
bd5635a1 2829
c0302457 2830 TYPE is the current type in which we are searching. */
bd5635a1
RP
2831
2832static struct type *
c0302457
JG
2833virtual_context (for_type, type, name, fn_type, offset)
2834 struct type *for_type, *type;
2835 char *name;
2836 struct type *fn_type;
2837 int offset;
bd5635a1 2838{
c0302457
JG
2839 struct type *basetype = 0;
2840 int i;
bd5635a1
RP
2841
2842 if (for_type != type)
2843 {
2844 /* Check the methods of TYPE. */
2845 /* Need to do a check_stub_type here, but that breaks
2846 things because we can get infinite regress. */
2847 for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; --i)
2848 if (!strcmp (TYPE_FN_FIELDLIST_NAME (type, i), name))
2849 break;
2850 if (i >= 0)
2851 {
2852 int j = TYPE_FN_FIELDLIST_LENGTH (type, i);
2853 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
2854
2855 while (--j >= 0)
2856 if (TYPE_FN_FIELD_VOFFSET (f, j) == offset-1)
2857 return TYPE_FN_FIELD_FCONTEXT (f, j);
2858 }
2859 }
62c4f98b 2860 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
bd5635a1
RP
2861 {
2862 basetype = virtual_context (for_type, TYPE_BASECLASS (type, i), name,
2863 fn_type, offset);
2864 if (basetype != for_type)
2865 return basetype;
2866 }
2867 return for_type;
2868}
2869#endif
bd5635a1
RP
2870\f
2871/* Copy a pending list, used to record the contents of a common
2872 block for later fixup. */
2873static struct pending *
2874copy_pending (beg, begi, end)
2875 struct pending *beg, *end;
2876 int begi;
2877{
2878 struct pending *new = 0;
2879 struct pending *next;
2880
2881 for (next = beg; next != 0 && (next != end || begi < end->nsyms);
2882 next = next->next, begi = 0)
2883 {
2884 register int j;
2885 for (j = begi; j < next->nsyms; j++)
2886 add_symbol_to_list (next->symbol[j], &new);
2887 }
2888 return new;
2889}
bd5635a1
RP
2890\f
2891/* Register our willingness to decode symbols for SunOS and a.out and
2892 b.out files handled by BFD... */
2893static struct sym_fns sunos_sym_fns = {"sunOs", 6,
9404978d 2894 dbx_new_init, dbx_symfile_init, dbx_symfile_read};
bd5635a1
RP
2895
2896static struct sym_fns aout_sym_fns = {"a.out", 5,
9404978d 2897 dbx_new_init, dbx_symfile_init, dbx_symfile_read};
bd5635a1
RP
2898
2899static struct sym_fns bout_sym_fns = {"b.out", 5,
9404978d 2900 dbx_new_init, dbx_symfile_init, dbx_symfile_read};
bd5635a1
RP
2901
2902void
2903_initialize_dbxread ()
2904{
2905 add_symtab_fns(&sunos_sym_fns);
2906 add_symtab_fns(&aout_sym_fns);
2907 add_symtab_fns(&bout_sym_fns);
bd5635a1 2908}
This page took 0.162923 seconds and 4 git commands to generate.