1 /* Read os9/os9k symbol tables and convert to internal format, for GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* This module provides three functions: os9k_symfile_init,
22 which initializes to read a symbol file; os9k_new_init, which
23 discards existing cached information when all symbols are being
24 discarded; and os9k_symfile_read, which reads a symbol table
27 os9k_symfile_read only does the minimum work necessary for letting the
28 user "name" things symbolically; it does not read the entire symtab.
29 Instead, it reads the external and static symbols and puts them in partial
30 symbol tables. When more extensive information is requested of a
31 file, the corresponding partial symbol table is mutated into a full
32 fledged symbol table by going back and reading the symbols
33 for real. os9k_psymtab_to_symtab() is the function that does this */
39 #if defined(USG) || defined(__CYGNUSCLIB__)
40 #include <sys/types.h>
45 #include <sys/param.h>
52 #include "breakpoint.h"
55 #include "gdbcore.h" /* for bfd stuff */
56 #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
60 #include "gdb-stabs.h"
62 #include "language.h" /* Needed inside partial-stab.h */
63 #include "complaints.h"
65 #include "stabsread.h"
67 #if !defined (SEEK_SET)
72 /* Each partial symbol table entry contains a pointer to private data for the
73 read_symtab() function to use when expanding a partial symbol table entry
74 to a full symbol table entry.
76 For dbxread this structure contains the offset within the file symbol table
77 of first local symbol for this file, and count of the section
78 of the symbol table devoted to this file's symbols (actually, the section
79 bracketed may contain more than just this file's symbols). It also contains
80 further information needed to locate the symbols if they are in an ELF file.
82 If ldsymcnt is 0, the only reason for this thing's existence is the
83 dependency list. Nothing else will happen when it is read in. */
85 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
86 #define LDSYMCNT(p) (((struct symloc *)((p)->read_symtab_private))->ldsymnum)
93 /* Remember what we deduced to be the source language of this psymtab. */
94 static enum language psymtab_language = language_unknown;
96 /* keep partial symbol table file nested depth */
97 static int psymfile_depth = 0;
99 /* keep symbol table file nested depth */
100 static int symfile_depth = 0;
102 /* Nonzero means give verbose info on gdb action. From main.c. */
103 extern int info_verbose;
105 extern int previous_stab_code;
107 /* Name of last function encountered. Used in Solaris to approximate
108 object file boundaries. */
109 static char *last_function_name;
111 /* Complaints about the symbols we have encountered. */
112 extern struct complaint lbrac_complaint;
114 extern struct complaint unknown_symtype_complaint;
116 extern struct complaint unknown_symchar_complaint;
118 extern struct complaint lbrac_rbrac_complaint;
120 extern struct complaint repeated_header_complaint;
122 extern struct complaint repeated_header_name_complaint;
125 static struct complaint lbrac_unmatched_complaint =
126 {"unmatched Increment Block Entry before symtab pos %d", 0, 0};
128 static struct complaint lbrac_mismatch_complaint =
129 {"IBE/IDE symbol mismatch at symtab pos %d", 0, 0};
132 /* Local function prototypes */
134 os9k_read_ofile_symtab PARAMS ((struct partial_symtab *));
137 os9k_psymtab_to_symtab PARAMS ((struct partial_symtab *));
140 os9k_psymtab_to_symtab_1 PARAMS ((struct partial_symtab *));
143 read_os9k_psymtab PARAMS ((struct section_offsets *, struct objfile *,
147 init_psymbol_list PARAMS ((struct objfile *));
150 fill_sym PARAMS ((FILE *, bfd *));
153 os9k_symfile_init PARAMS ((struct objfile *));
156 os9k_new_init PARAMS ((struct objfile *));
159 os9k_symfile_read PARAMS ((struct objfile *, struct section_offsets *, int));
162 os9k_symfile_finish PARAMS ((struct objfile *));
165 os9k_process_one_symbol PARAMS ((int, int, CORE_ADDR, char *,
166 struct section_offsets *, struct objfile *));
168 static struct partial_symtab *
169 os9k_start_psymtab PARAMS ((struct objfile *, struct section_offsets *, char *,
170 CORE_ADDR, int, int, struct partial_symbol *,
171 struct partial_symbol *));
173 static struct partial_symtab *
174 os9k_end_psymtab PARAMS ((struct partial_symtab *, char **, int, int, CORE_ADDR,
175 struct partial_symtab **, int));
178 record_minimal_symbol PARAMS ((char *, CORE_ADDR, int, struct objfile *,
179 struct section_offsets *));
181 #define HANDLE_RBRAC(val) \
182 if ((val) > pst->texthigh) pst->texthigh = (val);
184 #define SWAP_STBHDR(hdrp, abfd) \
186 (hdrp)->fmtno = bfd_get_16(abfd, (unsigned char *)&(hdrp)->fmtno); \
187 (hdrp)->crc = bfd_get_32(abfd, (unsigned char *)&(hdrp)->crc); \
188 (hdrp)->offset = bfd_get_32(abfd, (unsigned char *)&(hdrp)->offset); \
189 (hdrp)->nsym = bfd_get_32(abfd, (unsigned char *)&(hdrp)->nsym); \
191 #define SWAP_STBSYM(symp, abfd) \
193 (symp)->value = bfd_get_32(abfd, (unsigned char *)&(symp)->value); \
194 (symp)->type = bfd_get_16(abfd, (unsigned char *)&(symp)->type); \
195 (symp)->stroff = bfd_get_32(abfd, (unsigned char *)&(symp)->stroff); \
205 record_minimal_symbol (name, address, type, objfile, section_offsets)
209 struct objfile *objfile;
210 struct section_offsets *section_offsets;
212 enum minimal_symbol_type ms_type;
218 address += ANOFFSET(section_offsets, SECT_OFF_TEXT);
236 ms_type = mst_unknown; break;
239 prim_record_minimal_symbol
240 (obsavestring (name, strlen(name), &objfile->symbol_obstack),
241 address, ms_type, objfile);
244 /* read and process .stb file and store in minimal symbol table */
245 typedef char mhhdr[80];
260 #define STBSYMSIZE 10
263 read_minimal_symbols(objfile, section_offsets)
264 struct objfile *objfile;
265 struct section_offsets *section_offsets;
270 struct stbsymbol sym;
272 char buf[64], buf1[128];
275 if (fp == NULL) return;
276 abfd = objfile->obfd;
277 fread(&hdr.comhdr[0], sizeof(mhhdr), 1, fp);
286 if (i%2) ch=getc(fp);
289 fread(&hdr.fmtno, sizeof(hdr.fmtno), 1, fp);
290 fread(&hdr.crc, sizeof(hdr.crc), 1, fp);
291 fread(&hdr.offset, sizeof(hdr.offset), 1, fp);
292 fread(&hdr.nsym, sizeof(hdr.nsym), 1, fp);
293 SWAP_STBHDR(&hdr, abfd);
296 init_minimal_symbol_collection();
298 for (i = hdr.nsym; i > 0; i--) {
299 fseek(fp, (long)off, 0);
300 fread(&sym.value, sizeof(sym.value), 1, fp);
301 fread(&sym.type, sizeof(sym.type), 1, fp);
302 fread(&sym.stroff, sizeof(sym.stroff), 1, fp);
303 SWAP_STBSYM (&sym, abfd);
304 fseek(fp, (long)sym.stroff, 0);
313 record_minimal_symbol(buf1, sym.value, sym.type&7, objfile, section_offsets);
316 install_minimal_symbols (objfile);
320 /* Scan and build partial symbols for a symbol file.
321 We have been initialized by a call to os9k_symfile_init, which
322 put all the relevant info into a "struct os9k_symfile_info",
323 hung off the objfile structure.
325 SECTION_OFFSETS contains offsets relative to which the symbols in the
326 various sections are (depending where the sections were actually loaded).
327 MAINLINE is true if we are reading the main symbol
328 table (as opposed to a shared lib or dynamically loaded file). */
331 os9k_symfile_read (objfile, section_offsets, mainline)
332 struct objfile *objfile;
333 struct section_offsets *section_offsets;
334 int mainline; /* FIXME comments above */
337 struct cleanup *back_to;
339 sym_bfd = objfile->obfd;
340 /* If we are reinitializing, or if we have never loaded syms yet, init */
341 if (mainline || objfile->global_psymbols.size == 0 ||
342 objfile->static_psymbols.size == 0)
343 init_psymbol_list (objfile);
346 back_to = make_cleanup (really_free_pendings, 0);
348 make_cleanup (discard_minimal_symbols, 0);
349 read_minimal_symbols (objfile, section_offsets);
351 /* Now that the symbol table data of the executable file are all in core,
352 process them and define symbols accordingly. */
353 read_os9k_psymtab (section_offsets, objfile,
354 bfd_section_vma (sym_bfd, DBX_TEXT_SECT (objfile)),
355 bfd_section_size (sym_bfd, DBX_TEXT_SECT (objfile)));
357 do_cleanups (back_to);
360 /* Initialize anything that needs initializing when a completely new
361 symbol file is specified (not just adding some symbols from another
362 file, e.g. a shared library). */
365 os9k_new_init (ignore)
366 struct objfile *ignore;
368 stabsread_new_init ();
369 buildsym_new_init ();
372 init_header_files ();
376 /* os9k_symfile_init ()
377 It is passed a struct objfile which contains, among other things,
378 the BFD for the file whose symbols are being read, and a slot for a pointer
379 to "private data" which we fill with goodies.
381 Since BFD doesn't know how to read debug symbols in a format-independent
382 way (and may never do so...), we have to do it ourselves. We will never
383 be called unless this is an a.out (or very similar) file.
384 FIXME, there should be a cleaner peephole into the BFD environment here. */
387 os9k_symfile_init (objfile)
388 struct objfile *objfile;
390 bfd *sym_bfd = objfile->obfd;
391 char *name = bfd_get_filename (sym_bfd);
392 char dbgname[512], stbname[512];
397 strcpy(dbgname, name);
398 strcat(dbgname, ".dbg");
399 strcpy(stbname, name);
400 strcat(stbname, ".stb");
402 if ((symfile = fopen(dbgname, "r")) == NULL) {
403 warning("Symbol file %s not found", dbgname);
405 objfile->auxf2 = symfile;
407 if ((minfile = fopen(stbname, "r")) == NULL) {
408 warning("Symbol file %s not found", stbname);
410 objfile->auxf1 = minfile;
412 /* Allocate struct to keep track of the symfile */
413 objfile->sym_stab_info = (PTR)
414 xmmalloc (objfile -> md, sizeof (struct dbx_symfile_info));
415 DBX_SYMFILE_INFO (objfile)->stab_section_info = NULL;
417 DBX_TEXT_SECT (objfile) = bfd_get_section_by_name (sym_bfd, ".text");
418 if (!DBX_TEXT_SECT (objfile))
419 error ("Can't find .text section in file");
421 DBX_SYMBOL_SIZE (objfile) = 0; /* variable size symbol */
422 DBX_SYMCOUNT (objfile) = 0; /* used to be bfd_get_symcount(sym_bfd) */
423 DBX_SYMTAB_OFFSET (objfile) = 0; /* used to be SYMBOL_TABLE_OFFSET */
426 /* Perform any local cleanups required when we are done with a particular
427 objfile. I.E, we are in the process of discarding all symbol information
428 for an objfile, freeing up all memory held for it, and unlinking the
429 objfile struct from the global list of known objfiles. */
432 os9k_symfile_finish (objfile)
433 struct objfile *objfile;
435 if (objfile->sym_stab_info != NULL)
437 mfree (objfile -> md, objfile->sym_stab_info);
440 free_header_files ();
452 #define SYNC (int)0xefbefeca
454 #define SWAP_DBGHDR(hdrp, abfd) \
456 (hdrp)->sync = bfd_get_32(abfd, (unsigned char *)&(hdrp)->sync); \
457 (hdrp)->rev = bfd_get_16(abfd, (unsigned char *)&(hdrp)->rev); \
458 (hdrp)->crc = bfd_get_32(abfd, (unsigned char *)&(hdrp)->crc); \
459 (hdrp)->os = bfd_get_16(abfd, (unsigned char *)&(hdrp)->os); \
460 (hdrp)->cpu = bfd_get_16(abfd, (unsigned char *)&(hdrp)->cpu); \
463 #define N_SYM_CMPLR 0
464 #define N_SYM_SLINE 1
466 #define N_SYM_LBRAC 3
467 #define N_SYM_RBRAC 4
470 struct internal_symstruct {
476 static struct internal_symstruct symbol;
477 static struct internal_symstruct *symbuf = &symbol;
478 static char strbuf[4096];
479 static struct st_dbghdr dbghdr;
480 static short cmplrid;
482 #define VER_PRE_ULTRAC ((short)4)
483 #define VER_ULTRAC ((short)5)
486 fill_sym (dbg_file, abfd)
495 int nbytes = fread(&si, sizeof(si), 1, dbg_file);
499 perror_with_name ("reading .dbg file.");
502 symbuf->n_strx = NULL;
503 symbuf->n_type = bfd_get_16 (abfd, (unsigned char *)&si);
504 symbuf->n_type = 0xf & symbuf->n_type;
505 switch (symbuf->n_type)
508 fread(&si, sizeof(si), 1, dbg_file);
509 symbuf->n_desc = bfd_get_16(abfd, (unsigned char *)&si);
510 cmplrid = symbuf->n_desc & 0xff;
513 fread(&li, sizeof(li), 1, dbg_file);
514 symbuf->n_value = bfd_get_32(abfd, (unsigned char *)&li);
515 fread(&li, sizeof(li), 1, dbg_file);
516 li = bfd_get_32(abfd, (unsigned char *)&li);
517 symbuf->n_strx = (char *)(li >> 12);
518 symbuf->n_desc = li & 0xfff;
521 fread(&li, sizeof(li), 1, dbg_file);
522 symbuf->n_value = bfd_get_32(abfd, (unsigned char *)&li);
526 strbuf[si++] = (char) ii;
527 } while (ii != 0 || si % 2 != 0);
528 symbuf->n_strx = strbuf;
529 p = (char *) strchr (strbuf, ':');
531 if ((p[1] == 'F' || p[1] == 'f') && cmplrid == VER_PRE_ULTRAC)
533 fread(&si, sizeof(si), 1, dbg_file);
534 nmask = bfd_get_16(abfd, (unsigned char *)&si);
535 for (ii=0; ii<nmask; ii++)
536 fread(&si, sizeof(si), 1, dbg_file);
540 fread(&li, sizeof(li), 1, dbg_file);
541 symbuf->n_value = bfd_get_32(abfd, (unsigned char *)&li);
544 fread(&li, sizeof(li), 1, dbg_file);
545 symbuf->n_value = bfd_get_32(abfd, (unsigned char *)&li);
553 /* Initializes storage for all of the partial symbols that will be
554 created by read_dbx_symtab and subsidiaries. */
557 init_psymbol_list (objfile)
558 struct objfile *objfile;
560 /* Free any previously allocated psymbol lists. */
561 if (objfile -> global_psymbols.list)
562 mfree (objfile -> md, (PTR)objfile -> global_psymbols.list);
563 if (objfile -> static_psymbols.list)
564 mfree (objfile -> md, (PTR)objfile -> static_psymbols.list);
566 /* Current best guess is that there are approximately a twentieth
567 of the total symbols (in a debugging file) are global or static
569 objfile -> global_psymbols.size = DBX_SYMCOUNT (objfile) / 10;
570 objfile -> static_psymbols.size = DBX_SYMCOUNT (objfile) / 10;
571 objfile -> global_psymbols.next = objfile -> global_psymbols.list = (struct partial_symbol *)
572 xmmalloc (objfile -> md, objfile -> global_psymbols.size * sizeof (struct partial_symbol));
573 objfile -> static_psymbols.next = objfile -> static_psymbols.list = (struct partial_symbol *)
574 xmmalloc (objfile -> md, objfile -> static_psymbols.size * sizeof (struct partial_symbol));
577 /* Given pointers to an a.out symbol table in core containing dbx
578 style data, setup partial_symtab's describing each source file for
579 which debugging information is available.
580 SYMFILE_NAME is the name of the file we are reading from
581 and SECTION_OFFSETS is the set of offsets for the various sections
582 of the file (a set of zeros if the mainline program). */
585 read_os9k_psymtab (section_offsets, objfile, text_addr, text_size)
586 struct section_offsets *section_offsets;
587 struct objfile *objfile;
591 register struct internal_symstruct *bufp = 0; /* =0 avoids gcc -Wall glitch*/
592 register char *namestring;
593 int past_first_source_file = 0;
594 CORE_ADDR last_o_file_start = 0;
596 struct cleanup *back_to;
601 /* End of the text segment of the executable file. */
602 static CORE_ADDR end_of_text_addr;
604 /* Current partial symtab */
605 static struct partial_symtab *pst = 0;
607 /* List of current psymtab's include files */
608 char **psymtab_include_list;
609 int includes_allocated;
612 /* Index within current psymtab dependency list */
613 struct partial_symtab **dependency_list;
614 int dependencies_used, dependencies_allocated;
616 includes_allocated = 30;
618 psymtab_include_list = (char **) alloca (includes_allocated *
621 dependencies_allocated = 30;
622 dependencies_used = 0;
624 (struct partial_symtab **) alloca (dependencies_allocated *
625 sizeof (struct partial_symtab *));
627 last_source_file = NULL;
629 #ifdef END_OF_TEXT_DEFAULT
630 end_of_text_addr = END_OF_TEXT_DEFAULT;
632 end_of_text_addr = text_addr + section_offsets->offsets[SECT_OFF_TEXT]
633 + text_size; /* Relocate */
636 abfd = objfile->obfd;
640 fread(&dbghdr.sync, sizeof(dbghdr.sync), 1, fp);
641 fread(&dbghdr.rev, sizeof(dbghdr.rev), 1, fp);
642 fread(&dbghdr.crc, sizeof(dbghdr.crc), 1, fp);
643 fread(&dbghdr.os, sizeof(dbghdr.os), 1, fp);
644 fread(&dbghdr.cpu, sizeof(dbghdr.cpu), 1, fp);
645 SWAP_DBGHDR(&dbghdr, abfd);
653 /* Get the symbol for this run and pull out some info */
654 QUIT; /* allow this to be interruptable */
655 cursymoffset = ftell(objfile->auxf2);
656 ret = fill_sym(objfile->auxf2, abfd);
661 /* Special case to speed up readin. */
662 if (bufp->n_type == (short)N_SYM_SLINE) continue;
664 #define CUR_SYMBOL_VALUE bufp->n_value
667 switch (bufp->n_type)
675 CUR_SYMBOL_VALUE += ANOFFSET(section_offsets, SECT_OFF_TEXT);
676 if (psymfile_depth == 1 && pst)
678 os9k_end_psymtab (pst, psymtab_include_list, includes_used,
679 symnum, CUR_SYMBOL_VALUE,
680 dependency_list, dependencies_used);
681 pst = (struct partial_symtab *) 0;
683 dependencies_used = 0;
688 case N_SYM_SYM: /* Typedef or automatic variable. */
689 namestring = bufp->n_strx;
690 p = (char *) strchr (namestring, ':');
692 continue; /* Not a debugging symbol. */
694 /* Main processing section for debugging symbols which
695 the initial read through the symbol tables needs to worry
696 about. If we reach this point, the symbol which we are
697 considering is definitely one we are interested in.
698 p must also contain the (valid) index into the namestring
699 which indicates the debugging type symbol. */
706 enum language tmp_language;
710 valu = CUR_SYMBOL_VALUE;
712 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
713 past_first_source_file = 1;
715 p = strchr(namestring, ':');
716 if (p) n = p-namestring;
717 else n = strlen(namestring);
719 strncpy(str, namestring, n);
722 if (psymfile_depth == 0) {
724 pst = os9k_start_psymtab (objfile, section_offsets,
728 objfile -> global_psymbols.next,
729 objfile -> static_psymbols.next);
730 } else { /* this is a include file */
731 tmp_language = deduce_language_from_filename (str);
732 if (tmp_language != language_unknown
733 && (tmp_language != language_c
734 || psymtab_language != language_cplus))
735 psymtab_language = tmp_language;
738 if (pst && STREQ (str, pst->filename))
742 for (i = 0; i < includes_used; i++)
743 if (STREQ (str, psymtab_include_list[i]))
753 psymtab_include_list[includes_used++] = str;
754 if (includes_used >= includes_allocated)
756 char **orig = psymtab_include_list;
758 psymtab_include_list = (char **)
759 alloca ((includes_allocated *= 2) * sizeof (char *));
760 memcpy ((PTR)psymtab_include_list, (PTR)orig,
761 includes_used * sizeof (char *));
770 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
771 VAR_NAMESPACE, LOC_STATIC,
772 objfile->static_psymbols,
774 psymtab_language, objfile);
777 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
778 VAR_NAMESPACE, LOC_STATIC,
779 objfile->global_psymbols,
781 psymtab_language, objfile);
785 if (p != namestring) /* a name is there, not just :T... */
787 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
788 STRUCT_NAMESPACE, LOC_TYPEDEF,
789 objfile->static_psymbols,
791 psymtab_language, objfile);
794 /* Also a typedef with the same name. */
795 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
796 VAR_NAMESPACE, LOC_TYPEDEF,
797 objfile->static_psymbols,
798 CUR_SYMBOL_VALUE, psymtab_language,
802 /* The semantics of C++ state that "struct foo { ... }"
803 also defines a typedef for "foo". Unfortuantely, cfront
804 never makes the typedef when translating from C++ to C.
805 We make the typedef here so that "ptype foo" works as
806 expected for cfront translated code. */
807 else if (psymtab_language == language_cplus)
809 /* Also a typedef with the same name. */
810 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
811 VAR_NAMESPACE, LOC_TYPEDEF,
812 objfile->static_psymbols,
813 CUR_SYMBOL_VALUE, psymtab_language,
819 if (p != namestring) /* a name is there, not just :T... */
821 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
822 VAR_NAMESPACE, LOC_TYPEDEF,
823 objfile->static_psymbols,
825 psymtab_language, objfile);
828 /* If this is an enumerated type, we need to
829 add all the enum constants to the partial symbol
830 table. This does not cover enums without names, e.g.
831 "enum {a, b} c;" in C, but fortunately those are
832 rare. There is no way for GDB to find those from the
833 enum type without spending too much time on it. Thus
834 to solve this problem, the compiler needs to put out the
835 enum in a nameless type. GCC2 does this. */
837 /* We are looking for something of the form
838 <name> ":" ("t" | "T") [<number> "="] "e" <size>
839 {<constant> ":" <value> ","} ";". */
841 /* Skip over the colon and the 't' or 'T'. */
843 /* This type may be given a number. Also, numbers can come
844 in pairs like (0,26). Skip over it. */
845 while ((*p >= '0' && *p <= '9')
846 || *p == '(' || *p == ',' || *p == ')'
852 /* We have found an enumerated type. skip size */
853 while (*p >= '0' && *p <= '9') p++;
854 /* According to comments in read_enum_type
855 a comma could end it instead of a semicolon.
856 I don't know where that happens.
858 while (*p && *p != ';' && *p != ',')
862 /* Check for and handle cretinous dbx symbol name
865 p = next_symbol_text ();
868 /* Point to the character after the name
869 of the enum constant. */
870 for (q = p; *q && *q != ':'; q++)
872 /* Note that the value doesn't matter for
873 enum constants in psymtabs, just in symtabs. */
874 ADD_PSYMBOL_TO_LIST (p, q - p,
875 VAR_NAMESPACE, LOC_CONST,
876 objfile->static_psymbols, 0,
877 psymtab_language, objfile);
878 /* Point past the name. */
880 /* Skip over the value. */
881 while (*p && *p != ',')
883 /* Advance past the comma. */
890 /* Constant, e.g. from "const" in Pascal. */
891 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
892 VAR_NAMESPACE, LOC_CONST,
893 objfile->static_psymbols, CUR_SYMBOL_VALUE,
894 psymtab_language, objfile);
898 CUR_SYMBOL_VALUE += ANOFFSET(section_offsets, SECT_OFF_TEXT);
899 if (pst && pst->textlow == 0)
900 pst->textlow = CUR_SYMBOL_VALUE;
902 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
903 VAR_NAMESPACE, LOC_BLOCK,
904 objfile->static_psymbols, CUR_SYMBOL_VALUE,
905 psymtab_language, objfile);
909 CUR_SYMBOL_VALUE += ANOFFSET(section_offsets, SECT_OFF_TEXT);
910 if (pst && pst->textlow == 0)
911 pst->textlow = CUR_SYMBOL_VALUE;
913 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
914 VAR_NAMESPACE, LOC_BLOCK,
915 objfile->global_psymbols, CUR_SYMBOL_VALUE,
916 psymtab_language, objfile);
925 /* It is a C++ nested symbol. We don't need to record it
926 (I don't think); if we try to look up foo::bar::baz,
927 then symbols for the symtab containing foo should get
929 /* Someone says sun cc puts out symbols like
930 /foo/baz/maclib::/usr/local/bin/maclib,
931 which would get here with a symbol type of ':'. */
935 /* Unexpected symbol descriptor. The second and subsequent stabs
936 of a continued stab can show up here. The question is
937 whether they ever can mimic a normal stab--it would be
938 nice if not, since we certainly don't want to spend the
939 time searching to the end of every string looking for
942 complain (&unknown_symchar_complaint, p[1]);
947 CUR_SYMBOL_VALUE += ANOFFSET(section_offsets, SECT_OFF_TEXT);
949 HANDLE_RBRAC(CUR_SYMBOL_VALUE);
956 /* If we haven't found it yet, ignore it. It's probably some
957 new type we don't know about yet. */
958 complain (&unknown_symtype_complaint,
959 local_hex_string ((unsigned long) bufp->n_type));
964 DBX_SYMCOUNT (objfile) = symnum;
966 /* If there's stuff to be cleaned up, clean it up. */
967 if (DBX_SYMCOUNT (objfile) > 0
968 /*FIXME, does this have a bug at start address 0? */
970 && objfile -> ei.entry_point < bufp->n_value
971 && objfile -> ei.entry_point >= last_o_file_start)
973 objfile -> ei.entry_file_lowpc = last_o_file_start;
974 objfile -> ei.entry_file_highpc = bufp->n_value;
979 os9k_end_psymtab (pst, psymtab_include_list, includes_used,
980 symnum, end_of_text_addr,
981 dependency_list, dependencies_used);
984 do_cleanups (back_to);
988 /* Allocate and partially fill a partial symtab. It will be
989 completely filled at the end of the symbol list.
991 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
992 is the address relative to which its symbols are (incremental) or 0
996 static struct partial_symtab *
997 os9k_start_psymtab (objfile, section_offsets,
998 filename, textlow, ldsymoff,ldsymcnt, global_syms, static_syms)
999 struct objfile *objfile;
1000 struct section_offsets *section_offsets;
1005 struct partial_symbol *global_syms;
1006 struct partial_symbol *static_syms;
1008 struct partial_symtab *result =
1009 start_psymtab_common(objfile, section_offsets,
1010 filename, textlow, global_syms, static_syms);
1012 result->read_symtab_private = (char *)
1013 obstack_alloc (&objfile -> psymbol_obstack, sizeof (struct symloc));
1015 LDSYMOFF(result) = ldsymoff;
1016 LDSYMCNT(result) = ldsymcnt;
1017 result->read_symtab = os9k_psymtab_to_symtab;
1019 /* Deduce the source language from the filename for this psymtab. */
1020 psymtab_language = deduce_language_from_filename (filename);
1024 /* Close off the current usage of PST.
1025 Returns PST or NULL if the partial symtab was empty and thrown away.
1026 FIXME: List variables and peculiarities of same. */
1028 static struct partial_symtab *
1029 os9k_end_psymtab (pst, include_list, num_includes, capping_symbol_cnt,
1030 capping_text, dependency_list, number_dependencies)
1031 struct partial_symtab *pst;
1032 char **include_list;
1034 int capping_symbol_cnt;
1035 CORE_ADDR capping_text;
1036 struct partial_symtab **dependency_list;
1037 int number_dependencies;
1038 /* struct partial_symbol *capping_global, *capping_static;*/
1041 struct partial_symtab *p1;
1042 struct objfile *objfile = pst -> objfile;
1044 if (capping_symbol_cnt != -1)
1045 LDSYMCNT(pst) = capping_symbol_cnt - LDSYMCNT(pst);
1047 /* Under Solaris, the N_SO symbols always have a value of 0,
1048 instead of the usual address of the .o file. Therefore,
1049 we have to do some tricks to fill in texthigh and textlow.
1050 The first trick is in partial-stab.h: if we see a static
1051 or global function, and the textlow for the current pst
1052 is still 0, then we use that function's address for
1053 the textlow of the pst.
1055 Now, to fill in texthigh, we remember the last function seen
1056 in the .o file (also in partial-stab.h). Also, there's a hack in
1057 bfd/elf.c and gdb/elfread.c to pass the ELF st_size field
1058 to here via the misc_info field. Therefore, we can fill in
1059 a reliable texthigh by taking the address plus size of the
1060 last function in the file.
1062 Unfortunately, that does not cover the case where the last function
1063 in the file is static. See the paragraph below for more comments
1066 Finally, if we have a valid textlow for the current file, we run
1067 down the partial_symtab_list filling in previous texthighs that
1068 are still unknown. */
1070 if (pst->texthigh == 0 && last_function_name) {
1073 struct minimal_symbol *minsym;
1075 p = strchr (last_function_name, ':');
1077 p = last_function_name;
1078 n = p - last_function_name;
1080 strncpy (p, last_function_name, n);
1083 minsym = lookup_minimal_symbol (p, objfile);
1086 pst->texthigh = SYMBOL_VALUE_ADDRESS(minsym)+(long)MSYMBOL_INFO(minsym);
1088 /* This file ends with a static function, and it's
1089 difficult to imagine how hard it would be to track down
1090 the elf symbol. Luckily, most of the time no one will notice,
1091 since the next file will likely be compiled with -g, so
1092 the code below will copy the first fuction's start address
1093 back to our texthigh variable. (Also, if this file is the
1094 last one in a dynamically linked program, texthigh already
1095 has the right value.) If the next file isn't compiled
1096 with -g, then the last function in this file winds up owning
1097 all of the text space up to the next -g file, or the end (minus
1098 shared libraries). This only matters for single stepping,
1099 and even then it will still work, except that it will single
1100 step through all of the covered functions, instead of setting
1101 breakpoints around them as it usualy does. This makes it
1102 pretty slow, but at least it doesn't fail.
1104 We can fix this with a fairly big change to bfd, but we need
1105 to coordinate better with Cygnus if we want to do that. FIXME. */
1107 last_function_name = NULL;
1110 /* this test will be true if the last .o file is only data */
1111 if (pst->textlow == 0)
1112 pst->textlow = pst->texthigh;
1114 /* If we know our own starting text address, then walk through all other
1115 psymtabs for this objfile, and if any didn't know their ending text
1116 address, set it to our starting address. Take care to not set our
1117 own ending address to our starting address, nor to set addresses on
1118 `dependency' files that have both textlow and texthigh zero. */
1120 ALL_OBJFILE_PSYMTABS (objfile, p1) {
1121 if (p1->texthigh == 0 && p1->textlow != 0 && p1 != pst) {
1122 p1->texthigh = pst->textlow;
1123 /* if this file has only data, then make textlow match texthigh */
1124 if (p1->textlow == 0)
1125 p1->textlow = p1->texthigh;
1130 /* End of kludge for patching Solaris textlow and texthigh. */
1132 pst->n_global_syms =
1133 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
1134 pst->n_static_syms =
1135 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
1137 pst->number_of_dependencies = number_dependencies;
1138 if (number_dependencies)
1140 pst->dependencies = (struct partial_symtab **)
1141 obstack_alloc (&objfile->psymbol_obstack,
1142 number_dependencies * sizeof (struct partial_symtab *));
1143 memcpy (pst->dependencies, dependency_list,
1144 number_dependencies * sizeof (struct partial_symtab *));
1147 pst->dependencies = 0;
1149 for (i = 0; i < num_includes; i++)
1151 struct partial_symtab *subpst =
1152 allocate_psymtab (include_list[i], objfile);
1154 subpst->section_offsets = pst->section_offsets;
1155 subpst->read_symtab_private =
1156 (char *) obstack_alloc (&objfile->psymbol_obstack,
1157 sizeof (struct symloc));
1161 subpst->texthigh = 0;
1163 /* We could save slight bits of space by only making one of these,
1164 shared by the entire set of include files. FIXME-someday. */
1165 subpst->dependencies = (struct partial_symtab **)
1166 obstack_alloc (&objfile->psymbol_obstack,
1167 sizeof (struct partial_symtab *));
1168 subpst->dependencies[0] = pst;
1169 subpst->number_of_dependencies = 1;
1171 subpst->globals_offset =
1172 subpst->n_global_syms =
1173 subpst->statics_offset =
1174 subpst->n_static_syms = 0;
1178 subpst->read_symtab = pst->read_symtab;
1181 sort_pst_symbols (pst);
1183 /* If there is already a psymtab or symtab for a file of this name,
1185 (If there is a symtab, more drastic things also happen.)
1186 This happens in VxWorks. */
1187 free_named_symtabs (pst->filename);
1189 if (num_includes == 0
1190 && number_dependencies == 0
1191 && pst->n_global_syms == 0
1192 && pst->n_static_syms == 0) {
1193 /* Throw away this psymtab, it's empty. We can't deallocate it, since
1194 it is on the obstack, but we can forget to chain it on the list. */
1195 struct partial_symtab *prev_pst;
1197 /* First, snip it out of the psymtab chain */
1199 if (pst->objfile->psymtabs == pst)
1200 pst->objfile->psymtabs = pst->next;
1202 for (prev_pst = pst->objfile->psymtabs; prev_pst; prev_pst = pst->next)
1203 if (prev_pst->next == pst)
1204 prev_pst->next = pst->next;
1206 /* Next, put it on a free list for recycling */
1207 pst->next = pst->objfile->free_psymtabs;
1208 pst->objfile->free_psymtabs = pst;
1210 /* Indicate that psymtab was thrown away. */
1211 pst = (struct partial_symtab *)NULL;
1217 os9k_psymtab_to_symtab_1 (pst)
1218 struct partial_symtab *pst;
1220 struct cleanup *old_chain;
1228 fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1233 /* Read in all partial symtabs on which this one is dependent */
1234 for (i = 0; i < pst->number_of_dependencies; i++)
1235 if (!pst->dependencies[i]->readin)
1237 /* Inform about additional files that need to be read in. */
1240 fputs_filtered (" ", gdb_stdout);
1242 fputs_filtered ("and ", gdb_stdout);
1244 printf_filtered ("%s...", pst->dependencies[i]->filename);
1245 wrap_here (""); /* Flush output */
1246 gdb_flush (gdb_stdout);
1248 os9k_psymtab_to_symtab_1 (pst->dependencies[i]);
1251 if (LDSYMCNT(pst)) /* Otherwise it's a dummy */
1253 /* Init stuff necessary for reading in symbols */
1256 old_chain = make_cleanup (really_free_pendings, 0);
1258 /* Read in this file's symbols */
1259 os9k_read_ofile_symtab (pst);
1260 sort_symtab_syms (pst->symtab);
1261 do_cleanups (old_chain);
1267 /* Read in all of the symbols for a given psymtab for real.
1268 Be verbose about it if the user wants that. */
1271 os9k_psymtab_to_symtab (pst)
1272 struct partial_symtab *pst;
1281 fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1286 if (LDSYMCNT(pst) || pst->number_of_dependencies)
1288 /* Print the message now, before reading the string table,
1289 to avoid disconcerting pauses. */
1292 printf_filtered ("Reading in symbols for %s...", pst->filename);
1293 gdb_flush (gdb_stdout);
1296 sym_bfd = pst->objfile->obfd;
1297 os9k_psymtab_to_symtab_1 (pst);
1299 /* Match with global symbols. This only needs to be done once,
1300 after all of the symtabs and dependencies have been read in. */
1301 scan_file_globals (pst->objfile);
1303 /* Finish up the debug error message. */
1305 printf_filtered ("done.\n");
1309 /* Read in a defined section of a specific object file's symbols. */
1311 os9k_read_ofile_symtab (pst)
1312 struct partial_symtab *pst;
1314 register struct internal_symstruct *bufp;
1316 unsigned max_symnum;
1318 struct objfile *objfile;
1319 int sym_offset; /* Offset to start of symbols to read */
1320 CORE_ADDR text_offset; /* Start of text segment for symbols */
1321 int text_size; /* Size of text segment for symbols */
1322 struct section_offsets *section_offsets;
1325 objfile = pst->objfile;
1326 sym_offset = LDSYMOFF(pst);
1327 max_symnum = LDSYMCNT(pst);
1328 text_offset = pst->textlow;
1329 text_size = pst->texthigh - pst->textlow;
1330 section_offsets = pst->section_offsets;
1332 current_objfile = objfile;
1333 subfile_stack = NULL;
1334 last_source_file = NULL;
1336 abfd = objfile->obfd;
1337 dbg_file = objfile->auxf2;
1340 /* It is necessary to actually read one symbol *before* the start
1341 of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
1342 occurs before the N_SO symbol.
1343 Detecting this in read_dbx_symtab
1344 would slow down initial readin, so we look for it here instead. */
1345 if (!processing_acc_compilation && sym_offset >= (int)symbol_size)
1347 fseek (objefile->auxf2, sym_offset, SEEK_CUR);
1348 fill_sym(objfile->auxf2, abfd);
1351 processing_gcc_compilation = 0;
1352 if (bufp->n_type == N_TEXT)
1354 if (STREQ (namestring, GCC_COMPILED_FLAG_SYMBOL))
1355 processing_gcc_compilation = 1;
1356 else if (STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL))
1357 processing_gcc_compilation = 2;
1360 /* Try to select a C++ demangling based on the compilation unit
1363 if (processing_gcc_compilation)
1365 if (AUTO_DEMANGLING)
1367 set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
1373 /* The N_SO starting this symtab is the first symbol, so we
1374 better not check the symbol before it. I'm not this can
1375 happen, but it doesn't hurt to check for it. */
1376 bfd_seek (symfile_bfd, sym_offset, SEEK_CUR);
1377 processing_gcc_compilation = 0;
1381 fseek(dbg_file, (long)sym_offset, 0);
1383 if (bufp->n_type != (unsigned char)N_SYM_SYM)
1384 error("First symbol in segment of executable not a source symbol");
1387 for (symnum = 0; symnum < max_symnum; symnum++)
1389 QUIT; /* Allow this to be interruptable */
1390 fill_sym(dbg_file, abfd);
1392 type = bufp->n_type;
1394 os9k_process_one_symbol ((int)type, (int)bufp->n_desc,
1395 (CORE_ADDR)bufp->n_value, bufp->n_strx, section_offsets, objfile);
1397 /* We skip checking for a new .o or -l file; that should never
1398 happen in this routine. */
1400 else if (type == N_TEXT)
1402 /* I don't think this code will ever be executed, because
1403 the GCC_COMPILED_FLAG_SYMBOL usually is right before
1404 the N_SO symbol which starts this source file.
1405 However, there is no reason not to accept
1406 the GCC_COMPILED_FLAG_SYMBOL anywhere. */
1408 if (STREQ (namestring, GCC_COMPILED_FLAG_SYMBOL))
1409 processing_gcc_compilation = 1;
1410 else if (STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL))
1411 processing_gcc_compilation = 2;
1413 if (AUTO_DEMANGLING)
1415 set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
1418 else if (type & N_EXT || type == (unsigned char)N_TEXT
1419 || type == (unsigned char)N_NBTEXT
1421 /* Global symbol: see if we came across a dbx defintion for
1422 a corresponding symbol. If so, store the value. Remove
1423 syms from the chain when their values are stored, but
1424 search the whole chain, as there may be several syms from
1425 different files with the same name. */
1426 /* This is probably not true. Since the files will be read
1427 in one at a time, each reference to a global symbol will
1428 be satisfied in each file as it appears. So we skip this
1435 current_objfile = NULL;
1437 /* In a Solaris elf file, this variable, which comes from the
1438 value of the N_SO symbol, will still be 0. Luckily, text_offset,
1439 which comes from pst->textlow is correct. */
1440 if (last_source_start_addr == 0)
1441 last_source_start_addr = text_offset;
1442 pst->symtab = end_symtab (text_offset + text_size, 0, 0, objfile,
1448 /* This handles a single symbol from the symbol-file, building symbols
1449 into a GDB symtab. It takes these arguments and an implicit argument.
1451 TYPE is the type field of the ".stab" symbol entry.
1452 DESC is the desc field of the ".stab" entry.
1453 VALU is the value field of the ".stab" entry.
1454 NAME is the symbol name, in our address space.
1455 SECTION_OFFSETS is a set of amounts by which the sections of this object
1456 file were relocated when it was loaded into memory.
1457 All symbols that refer
1458 to memory locations need to be offset by these amounts.
1459 OBJFILE is the object file from which we are reading symbols.
1460 It is used in end_symtab. */
1463 os9k_process_one_symbol (type, desc, valu, name, section_offsets, objfile)
1467 struct section_offsets *section_offsets;
1468 struct objfile *objfile;
1470 register struct context_stack *new;
1471 /* The stab type used for the definition of the last function.
1472 N_STSYM or N_GSYM for SunOS4 acc; N_FUN for other compilers. */
1473 static int function_stab_type = 0;
1476 /* Something is wrong if we see real data before
1477 seeing a source file name. */
1478 if (last_source_file == NULL && type != (unsigned char)N_SO)
1480 /* Ignore any symbols which appear before an N_SO symbol. Currently
1481 no one puts symbols there, but we should deal gracefully with the
1482 case. A complain()t might be in order (if !IGNORE_SYMBOL (type)),
1483 but this should not be an error (). */
1491 /* On most machines, the block addresses are relative to the
1492 N_SO, the linker did not relocate them (sigh). */
1493 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1494 new = push_context (desc, valu);
1498 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1499 new = pop_context();
1501 #if !defined (OS9K_VARIABLES_INSIDE_BLOCK)
1502 #define OS9K_VARIABLES_INSIDE_BLOCK(desc, gcc_p) 1
1505 if (!OS9K_VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation))
1506 local_symbols = new->locals;
1508 if (context_stack_depth > 1)
1510 /* This is not the outermost LBRAC...RBRAC pair in the function,
1511 its local symbols preceded it, and are the ones just recovered
1512 from the context stack. Define the block for them (but don't
1513 bother if the block contains no symbols. Should we complain
1514 on blocks without symbols? I can't think of any useful purpose
1516 if (local_symbols != NULL)
1518 /* Muzzle a compiler bug that makes end < start. (which
1519 compilers? Is this ever harmful?). */
1520 if (new->start_addr > valu)
1522 complain (&lbrac_rbrac_complaint);
1523 new->start_addr = valu;
1525 /* Make a block for the local symbols within. */
1526 finish_block (0, &local_symbols, new->old_blocks,
1527 new->start_addr, valu, objfile);
1532 if (context_stack_depth == 0)
1534 within_function = 0;
1535 /* Make a block for the local symbols within. */
1536 finish_block (new->name, &local_symbols, new->old_blocks,
1537 new->start_addr, valu, objfile);
1541 /* attach local_symbols to the end of new->locals */
1542 if (!new->locals) new->locals = local_symbols;
1547 while (p->next) p = p->next;
1548 p->next = local_symbols;
1553 if (OS9K_VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation))
1554 /* Now pop locals of block just finished. */
1555 local_symbols = new->locals;
1560 /* This type of "symbol" really just records
1561 one line-number -- core-address correspondence.
1562 Enter it in the line list for this symbol table. */
1563 /* Relocate for dynamic loading and for ELF acc fn-relative syms. */
1564 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1565 record_line (current_subfile, (int)name, valu);
1568 /* The following symbol types need to have the appropriate offset added
1569 to their value; then we process symbol definitions in the name. */
1576 char *p = strchr (name, ':');
1586 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1587 n = strrchr(name, '/');
1597 if (symfile_depth++ == 0) {
1598 if (last_source_file) {
1599 end_symtab (valu, 0, 0, objfile, SECT_OFF_TEXT);
1604 start_symtab (n, dirn, valu);
1607 start_subfile (n, dirn!=NULL ? dirn : current_subfile->dirname);
1613 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1614 function_stab_type = type;
1616 within_function = 1;
1617 new = push_context (0, valu);
1618 new->name = define_symbol (valu, name, desc, type, objfile);
1623 valu += ANOFFSET (section_offsets, SECT_OFF_DATA);
1624 define_symbol (valu, name, desc, type, objfile);
1628 define_symbol (valu, name, desc, type, objfile);
1635 if (--symfile_depth != 0)
1636 start_subfile(pop_subfile(), current_subfile->dirname);
1640 complain (&unknown_symtype_complaint,
1641 local_hex_string((unsigned long) type));
1648 previous_stab_code = type;
1651 /* Parse the user's idea of an offset for dynamic linking, into our idea
1652 of how to represent it for fast symbol reading. */
1654 static struct section_offsets *
1655 os9k_symfile_offsets (objfile, addr)
1656 struct objfile *objfile;
1659 struct section_offsets *section_offsets;
1662 objfile->num_sections = SECT_OFF_MAX;
1663 section_offsets = (struct section_offsets *)
1664 obstack_alloc (&objfile -> psymbol_obstack,
1665 sizeof (struct section_offsets)
1666 + sizeof (section_offsets->offsets) * (SECT_OFF_MAX-1));
1668 for (i = 0; i < SECT_OFF_MAX; i++)
1669 ANOFFSET (section_offsets, i) = addr;
1671 return section_offsets;
1674 static struct sym_fns os9k_sym_fns =
1676 bfd_target_os9k_flavour,
1677 os9k_new_init, /* sym_new_init: init anything gbl to entire symtab */
1678 os9k_symfile_init, /* sym_init: read initial info, setup for sym_read() */
1679 os9k_symfile_read, /* sym_read: read a symbol file into symtab */
1680 os9k_symfile_finish, /* sym_finish: finished with file, cleanup */
1681 os9k_symfile_offsets, /* sym_offsets: parse user's offsets to internal form*/
1682 NULL /* next: pointer to next struct sym_fns */
1686 _initialize_os9kread ()
1688 add_symtab_fns(&os9k_sym_fns);