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