1 /* Read os9/os9k symbol tables and convert to internal format, for GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3 1996, 1997, 1998, 1999, 2000, 2001
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* This module provides three functions: os9k_symfile_init,
24 which initializes to read a symbol file; os9k_new_init, which
25 discards existing cached information when all symbols are being
26 discarded; and os9k_symfile_read, which reads a symbol table
29 os9k_symfile_read only does the minimum work necessary for letting the
30 user "name" things symbolically; it does not read the entire symtab.
31 Instead, it reads the external and static symbols and puts them in partial
32 symbol tables. When more extensive information is requested of a
33 file, the corresponding partial symbol table is mutated into a full
34 fledged symbol table by going back and reading the symbols
35 for real. os9k_psymtab_to_symtab() is the function that does this */
38 #include "gdb_string.h"
39 #include "gdb_assert.h"
42 #if defined(USG) || defined(__CYGNUSCLIB__)
43 #include <sys/types.h>
50 #include "breakpoint.h"
53 #include "gdbcore.h" /* for bfd stuff */
54 #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
58 #include "gdb-stabs.h"
60 #include "language.h" /* Needed inside partial-stab.h */
61 #include "complaints.h"
63 #include "stabsread.h"
65 extern void _initialize_os9kread (void);
67 /* Each partial symbol table entry contains a pointer to private data for the
68 read_symtab() function to use when expanding a partial symbol table entry
69 to a full symbol table entry.
71 For dbxread this structure contains the offset within the file symbol table
72 of first local symbol for this file, and count of the section
73 of the symbol table devoted to this file's symbols (actually, the section
74 bracketed may contain more than just this file's symbols). It also contains
75 further information needed to locate the symbols if they are in an ELF file.
77 If ldsymcnt is 0, the only reason for this thing's existence is the
78 dependency list. Nothing else will happen when it is read in. */
80 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
81 #define LDSYMCNT(p) (((struct symloc *)((p)->read_symtab_private))->ldsymnum)
89 /* Remember what we deduced to be the source language of this psymtab. */
90 static enum language psymtab_language = language_unknown;
92 /* keep partial symbol table file nested depth */
93 static int psymfile_depth = 0;
95 /* keep symbol table file nested depth */
96 static int symfile_depth = 0;
98 extern int previous_stab_code;
100 /* Name of last function encountered. Used in Solaris to approximate
101 object file boundaries. */
102 static char *last_function_name;
104 /* Complaints about the symbols we have encountered. */
105 extern struct complaint lbrac_complaint;
107 extern struct complaint unknown_symtype_complaint;
109 extern struct complaint unknown_symchar_complaint;
111 extern struct complaint lbrac_rbrac_complaint;
113 extern struct complaint repeated_header_complaint;
115 extern struct complaint repeated_header_name_complaint;
118 static struct complaint lbrac_unmatched_complaint =
119 {"unmatched Increment Block Entry before symtab pos %d", 0, 0};
121 static struct complaint lbrac_mismatch_complaint =
122 {"IBE/IDE symbol mismatch at symtab pos %d", 0, 0};
125 /* Local function prototypes */
127 static void read_minimal_symbols (struct objfile *);
129 static void os9k_read_ofile_symtab (struct partial_symtab *);
131 static void os9k_psymtab_to_symtab (struct partial_symtab *);
133 static void os9k_psymtab_to_symtab_1 (struct partial_symtab *);
135 static void read_os9k_psymtab (struct objfile *, CORE_ADDR, int);
137 static int fill_sym (FILE *, bfd *);
139 static void os9k_symfile_init (struct objfile *);
141 static void os9k_new_init (struct objfile *);
143 static void os9k_symfile_read (struct objfile *, int);
145 static void os9k_symfile_finish (struct objfile *);
148 os9k_process_one_symbol (int, int, CORE_ADDR, char *,
149 struct section_offsets *, struct objfile *);
151 static struct partial_symtab *os9k_start_psymtab (struct objfile *, char *,
153 struct partial_symbol **,
154 struct partial_symbol **);
156 static struct partial_symtab *os9k_end_psymtab (struct partial_symtab *,
157 char **, int, int, CORE_ADDR,
158 struct partial_symtab **,
161 static void record_minimal_symbol (char *, CORE_ADDR, int, struct objfile *);
163 #define HANDLE_RBRAC(val) \
164 if ((val) > pst->texthigh) pst->texthigh = (val);
166 #define SWAP_STBHDR(hdrp, abfd) \
168 (hdrp)->fmtno = bfd_get_16(abfd, (unsigned char *)&(hdrp)->fmtno); \
169 (hdrp)->crc = bfd_get_32(abfd, (unsigned char *)&(hdrp)->crc); \
170 (hdrp)->offset = bfd_get_32(abfd, (unsigned char *)&(hdrp)->offset); \
171 (hdrp)->nsym = bfd_get_32(abfd, (unsigned char *)&(hdrp)->nsym); \
173 #define SWAP_STBSYM(symp, abfd) \
175 (symp)->value = bfd_get_32(abfd, (unsigned char *)&(symp)->value); \
176 (symp)->type = bfd_get_16(abfd, (unsigned char *)&(symp)->type); \
177 (symp)->stroff = bfd_get_32(abfd, (unsigned char *)&(symp)->stroff); \
187 record_minimal_symbol (char *name, CORE_ADDR address, int type,
188 struct objfile *objfile)
190 enum minimal_symbol_type ms_type;
196 address += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
214 ms_type = mst_unknown;
218 prim_record_minimal_symbol (name, address, ms_type, objfile);
221 /* read and process .stb file and store in minimal symbol table */
222 typedef char mhhdr[80];
239 #define STBSYMSIZE 10
242 read_minimal_symbols (struct objfile *objfile)
247 struct stbsymbol sym;
249 char buf[64], buf1[128];
254 abfd = objfile->obfd;
255 fread (&hdr.comhdr[0], sizeof (mhhdr), 1, fp);
270 fread (&hdr.fmtno, sizeof (hdr.fmtno), 1, fp);
271 fread (&hdr.crc, sizeof (hdr.crc), 1, fp);
272 fread (&hdr.offset, sizeof (hdr.offset), 1, fp);
273 fread (&hdr.nsym, sizeof (hdr.nsym), 1, fp);
274 SWAP_STBHDR (&hdr, abfd);
277 init_minimal_symbol_collection ();
279 for (i = hdr.nsym; i > 0; i--)
281 fseek (fp, (long) off, 0);
282 fread (&sym.value, sizeof (sym.value), 1, fp);
283 fread (&sym.type, sizeof (sym.type), 1, fp);
284 fread (&sym.stroff, sizeof (sym.stroff), 1, fp);
285 SWAP_STBSYM (&sym, abfd);
286 fseek (fp, (long) sym.stroff, 0);
297 record_minimal_symbol (buf1, sym.value, sym.type & 7, objfile);
300 install_minimal_symbols (objfile);
304 /* Scan and build partial symbols for a symbol file.
305 We have been initialized by a call to os9k_symfile_init, which
306 put all the relevant info into a "struct os9k_symfile_info",
307 hung off the objfile structure.
309 MAINLINE is true if we are reading the main symbol
310 table (as opposed to a shared lib or dynamically loaded file). */
313 os9k_symfile_read (struct objfile *objfile, int mainline)
316 struct cleanup *back_to;
318 sym_bfd = objfile->obfd;
319 /* If we are reinitializing, or if we have never loaded syms yet, init */
321 || (objfile->global_psymbols.size == 0
322 && objfile->static_psymbols.size == 0))
323 init_psymbol_list (objfile, DBX_SYMCOUNT (objfile));
325 free_pending_blocks ();
326 back_to = make_cleanup (really_free_pendings, 0);
328 make_cleanup_discard_minimal_symbols ();
329 read_minimal_symbols (objfile);
331 /* Now that the symbol table data of the executable file are all in core,
332 process them and define symbols accordingly. */
333 read_os9k_psymtab (objfile,
334 DBX_TEXT_ADDR (objfile),
335 DBX_TEXT_SIZE (objfile));
337 do_cleanups (back_to);
340 /* Initialize anything that needs initializing when a completely new
341 symbol file is specified (not just adding some symbols from another
342 file, e.g. a shared library). */
345 os9k_new_init (struct objfile *ignore)
347 stabsread_new_init ();
348 buildsym_new_init ();
351 init_header_files ();
355 /* os9k_symfile_init ()
356 It is passed a struct objfile which contains, among other things,
357 the BFD for the file whose symbols are being read, and a slot for a pointer
358 to "private data" which we fill with goodies.
360 Since BFD doesn't know how to read debug symbols in a format-independent
361 way (and may never do so...), we have to do it ourselves. We will never
362 be called unless this is an a.out (or very similar) file.
363 FIXME, there should be a cleaner peephole into the BFD environment here. */
366 os9k_symfile_init (struct objfile *objfile)
368 bfd *sym_bfd = objfile->obfd;
369 char *name = bfd_get_filename (sym_bfd);
370 char dbgname[512], stbname[512];
375 strcpy (dbgname, name);
376 strcat (dbgname, ".dbg");
377 strcpy (stbname, name);
378 strcat (stbname, ".stb");
380 if ((symfile = fopen (dbgname, "r")) == NULL)
382 warning ("Symbol file %s not found", dbgname);
384 objfile->auxf2 = symfile;
386 if ((minfile = fopen (stbname, "r")) == NULL)
388 warning ("Symbol file %s not found", stbname);
390 objfile->auxf1 = minfile;
392 /* Allocate struct to keep track of the symfile */
393 objfile->sym_stab_info = (struct dbx_symfile_info *)
394 xmmalloc (objfile->md, sizeof (struct dbx_symfile_info));
395 DBX_SYMFILE_INFO (objfile)->stab_section_info = NULL;
397 text_sect = bfd_get_section_by_name (sym_bfd, ".text");
399 error ("Can't find .text section in file");
400 DBX_TEXT_ADDR (objfile) = bfd_section_vma (sym_bfd, text_sect);
401 DBX_TEXT_SIZE (objfile) = bfd_section_size (sym_bfd, text_sect);
403 DBX_SYMBOL_SIZE (objfile) = 0; /* variable size symbol */
404 DBX_SYMCOUNT (objfile) = 0; /* used to be bfd_get_symcount(sym_bfd) */
405 DBX_SYMTAB_OFFSET (objfile) = 0; /* used to be SYMBOL_TABLE_OFFSET */
408 /* Perform any local cleanups required when we are done with a particular
409 objfile. I.E, we are in the process of discarding all symbol information
410 for an objfile, freeing up all memory held for it, and unlinking the
411 objfile struct from the global list of known objfiles. */
414 os9k_symfile_finish (struct objfile *objfile)
416 if (objfile->sym_stab_info != NULL)
418 mfree (objfile->md, objfile->sym_stab_info);
421 free_header_files ();
434 #define SYNC (int)0xefbefeca
436 #define SWAP_DBGHDR(hdrp, abfd) \
438 (hdrp)->sync = bfd_get_32(abfd, (unsigned char *)&(hdrp)->sync); \
439 (hdrp)->rev = bfd_get_16(abfd, (unsigned char *)&(hdrp)->rev); \
440 (hdrp)->crc = bfd_get_32(abfd, (unsigned char *)&(hdrp)->crc); \
441 (hdrp)->os = bfd_get_16(abfd, (unsigned char *)&(hdrp)->os); \
442 (hdrp)->cpu = bfd_get_16(abfd, (unsigned char *)&(hdrp)->cpu); \
445 #define N_SYM_CMPLR 0
446 #define N_SYM_SLINE 1
448 #define N_SYM_LBRAC 3
449 #define N_SYM_RBRAC 4
452 struct internal_symstruct
459 static struct internal_symstruct symbol;
460 static struct internal_symstruct *symbuf = &symbol;
461 static char strbuf[4096];
462 static struct st_dbghdr dbghdr;
463 static short cmplrid;
465 #define VER_PRE_ULTRAC ((short)4)
466 #define VER_ULTRAC ((short)5)
469 fill_sym (FILE *dbg_file, bfd *abfd)
476 int nbytes = fread (&si, sizeof (si), 1, dbg_file);
480 perror_with_name ("reading .dbg file.");
483 symbuf->n_strx = NULL;
484 symbuf->n_type = bfd_get_16 (abfd, (unsigned char *) &si);
485 symbuf->n_type = 0xf & symbuf->n_type;
486 switch (symbuf->n_type)
489 fread (&si, sizeof (si), 1, dbg_file);
490 symbuf->n_desc = bfd_get_16 (abfd, (unsigned char *) &si);
491 cmplrid = symbuf->n_desc & 0xff;
494 fread (&li, sizeof (li), 1, dbg_file);
495 symbuf->n_value = bfd_get_32 (abfd, (unsigned char *) &li);
496 fread (&li, sizeof (li), 1, dbg_file);
497 li = bfd_get_32 (abfd, (unsigned char *) &li);
498 symbuf->n_strx = (char *) (li >> 12);
499 symbuf->n_desc = li & 0xfff;
502 fread (&li, sizeof (li), 1, dbg_file);
503 symbuf->n_value = bfd_get_32 (abfd, (unsigned char *) &li);
507 ii = getc (dbg_file);
508 strbuf[si++] = (char) ii;
510 while (ii != 0 || si % 2 != 0);
511 symbuf->n_strx = strbuf;
512 p = (char *) strchr (strbuf, ':');
515 if ((p[1] == 'F' || p[1] == 'f') && cmplrid == VER_PRE_ULTRAC)
517 fread (&si, sizeof (si), 1, dbg_file);
518 nmask = bfd_get_16 (abfd, (unsigned char *) &si);
519 for (ii = 0; ii < nmask; ii++)
520 fread (&si, sizeof (si), 1, dbg_file);
524 fread (&li, sizeof (li), 1, dbg_file);
525 symbuf->n_value = bfd_get_32 (abfd, (unsigned char *) &li);
528 fread (&li, sizeof (li), 1, dbg_file);
529 symbuf->n_value = bfd_get_32 (abfd, (unsigned char *) &li);
537 /* Given pointers to an a.out symbol table in core containing dbx
538 style data, setup partial_symtab's describing each source file for
539 which debugging information is available.
540 SYMFILE_NAME is the name of the file we are reading from. */
543 read_os9k_psymtab (struct objfile *objfile, CORE_ADDR text_addr, int text_size)
545 register struct internal_symstruct *bufp = 0; /* =0 avoids gcc -Wall glitch */
546 register char *namestring;
547 int past_first_source_file = 0;
548 CORE_ADDR last_o_file_start = 0;
550 struct cleanup *back_to;
555 /* End of the text segment of the executable file. */
556 static CORE_ADDR end_of_text_addr;
558 /* Current partial symtab */
559 static struct partial_symtab *pst = 0;
561 /* List of current psymtab's include files */
562 char **psymtab_include_list;
563 int includes_allocated;
566 /* Index within current psymtab dependency list */
567 struct partial_symtab **dependency_list;
568 int dependencies_used, dependencies_allocated;
570 includes_allocated = 30;
572 psymtab_include_list = (char **) alloca (includes_allocated *
575 dependencies_allocated = 30;
576 dependencies_used = 0;
578 (struct partial_symtab **) alloca (dependencies_allocated *
579 sizeof (struct partial_symtab *));
581 last_source_file = NULL;
583 #ifdef END_OF_TEXT_DEFAULT
584 end_of_text_addr = END_OF_TEXT_DEFAULT;
586 end_of_text_addr = text_addr + ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile))
587 + text_size; /* Relocate */
590 abfd = objfile->obfd;
595 fread (&dbghdr.sync, sizeof (dbghdr.sync), 1, fp);
596 fread (&dbghdr.rev, sizeof (dbghdr.rev), 1, fp);
597 fread (&dbghdr.crc, sizeof (dbghdr.crc), 1, fp);
598 fread (&dbghdr.os, sizeof (dbghdr.os), 1, fp);
599 fread (&dbghdr.cpu, sizeof (dbghdr.cpu), 1, fp);
600 SWAP_DBGHDR (&dbghdr, abfd);
608 /* Get the symbol for this run and pull out some info */
609 QUIT; /* allow this to be interruptable */
610 cursymoffset = ftell (objfile->auxf2);
611 ret = fill_sym (objfile->auxf2, abfd);
618 /* Special case to speed up readin. */
619 if (bufp->n_type == (short) N_SYM_SLINE)
622 #define CUR_SYMBOL_VALUE bufp->n_value
625 switch (bufp->n_type)
633 CUR_SYMBOL_VALUE += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
634 if (psymfile_depth == 1 && pst)
636 os9k_end_psymtab (pst, psymtab_include_list, includes_used,
637 symnum, CUR_SYMBOL_VALUE,
638 dependency_list, dependencies_used);
639 pst = (struct partial_symtab *) 0;
641 dependencies_used = 0;
646 case N_SYM_SYM: /* Typedef or automatic variable. */
647 namestring = bufp->n_strx;
648 p = (char *) strchr (namestring, ':');
650 continue; /* Not a debugging symbol. */
652 /* Main processing section for debugging symbols which
653 the initial read through the symbol tables needs to worry
654 about. If we reach this point, the symbol which we are
655 considering is definitely one we are interested in.
656 p must also contain the (valid) index into the namestring
657 which indicates the debugging type symbol. */
664 enum language tmp_language;
668 valu = CUR_SYMBOL_VALUE;
670 valu += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
671 past_first_source_file = 1;
673 p = strchr (namestring, ':');
677 n = strlen (namestring);
678 str = alloca (n + 1);
679 strncpy (str, namestring, n);
682 if (psymfile_depth == 0)
685 pst = os9k_start_psymtab (objfile,
689 objfile->global_psymbols.next,
690 objfile->static_psymbols.next);
693 { /* this is a include file */
694 tmp_language = deduce_language_from_filename (str);
695 if (tmp_language != language_unknown
696 && (tmp_language != language_c
697 || psymtab_language != language_cplus))
698 psymtab_language = tmp_language;
701 if (pst && STREQ (str, pst->filename))
705 for (i = 0; i < includes_used; i++)
706 if (STREQ (str, psymtab_include_list[i]))
716 psymtab_include_list[includes_used++] = str;
717 if (includes_used >= includes_allocated)
719 char **orig = psymtab_include_list;
721 psymtab_include_list = (char **)
722 alloca ((includes_allocated *= 2) * sizeof (char *));
723 memcpy ((PTR) psymtab_include_list, (PTR) orig,
724 includes_used * sizeof (char *));
733 add_psymbol_to_list (namestring, p - namestring,
734 VAR_NAMESPACE, LOC_STATIC,
735 &objfile->static_psymbols,
737 psymtab_language, objfile);
740 add_psymbol_to_list (namestring, p - namestring,
741 VAR_NAMESPACE, LOC_STATIC,
742 &objfile->global_psymbols,
744 psymtab_language, objfile);
748 if (p != namestring) /* a name is there, not just :T... */
750 add_psymbol_to_list (namestring, p - namestring,
751 STRUCT_NAMESPACE, LOC_TYPEDEF,
752 &objfile->static_psymbols,
754 psymtab_language, objfile);
757 /* Also a typedef with the same name. */
758 add_psymbol_to_list (namestring, p - namestring,
759 VAR_NAMESPACE, LOC_TYPEDEF,
760 &objfile->static_psymbols,
761 CUR_SYMBOL_VALUE, 0, psymtab_language,
765 /* The semantics of C++ state that "struct foo { ... }"
766 also defines a typedef for "foo". Unfortuantely, cfront
767 never makes the typedef when translating from C++ to C.
768 We make the typedef here so that "ptype foo" works as
769 expected for cfront translated code. */
770 else if (psymtab_language == language_cplus)
772 /* Also a typedef with the same name. */
773 add_psymbol_to_list (namestring, p - namestring,
774 VAR_NAMESPACE, LOC_TYPEDEF,
775 &objfile->static_psymbols,
776 CUR_SYMBOL_VALUE, 0, psymtab_language,
782 if (p != namestring) /* a name is there, not just :T... */
784 add_psymbol_to_list (namestring, p - namestring,
785 VAR_NAMESPACE, LOC_TYPEDEF,
786 &objfile->static_psymbols,
788 psymtab_language, objfile);
791 /* If this is an enumerated type, we need to
792 add all the enum constants to the partial symbol
793 table. This does not cover enums without names, e.g.
794 "enum {a, b} c;" in C, but fortunately those are
795 rare. There is no way for GDB to find those from the
796 enum type without spending too much time on it. Thus
797 to solve this problem, the compiler needs to put out the
798 enum in a nameless type. GCC2 does this. */
800 /* We are looking for something of the form
801 <name> ":" ("t" | "T") [<number> "="] "e" <size>
802 {<constant> ":" <value> ","} ";". */
804 /* Skip over the colon and the 't' or 'T'. */
806 /* This type may be given a number. Also, numbers can come
807 in pairs like (0,26). Skip over it. */
808 while ((*p >= '0' && *p <= '9')
809 || *p == '(' || *p == ',' || *p == ')'
815 /* We have found an enumerated type. skip size */
816 while (*p >= '0' && *p <= '9')
818 /* According to comments in read_enum_type
819 a comma could end it instead of a semicolon.
820 I don't know where that happens.
822 while (*p && *p != ';' && *p != ',')
826 /* Check for and handle cretinous dbx symbol name
829 p = next_symbol_text (objfile);
832 /* Point to the character after the name
833 of the enum constant. */
834 for (q = p; *q && *q != ':'; q++)
836 /* Note that the value doesn't matter for
837 enum constants in psymtabs, just in symtabs. */
838 add_psymbol_to_list (p, q - p,
839 VAR_NAMESPACE, LOC_CONST,
840 &objfile->static_psymbols, 0,
841 0, psymtab_language, objfile);
842 /* Point past the name. */
844 /* Skip over the value. */
845 while (*p && *p != ',')
847 /* Advance past the comma. */
854 /* Constant, e.g. from "const" in Pascal. */
855 add_psymbol_to_list (namestring, p - namestring,
856 VAR_NAMESPACE, LOC_CONST,
857 &objfile->static_psymbols, CUR_SYMBOL_VALUE,
858 0, psymtab_language, objfile);
862 CUR_SYMBOL_VALUE += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
863 if (pst && pst->textlow == 0)
864 pst->textlow = CUR_SYMBOL_VALUE;
866 add_psymbol_to_list (namestring, p - namestring,
867 VAR_NAMESPACE, LOC_BLOCK,
868 &objfile->static_psymbols, CUR_SYMBOL_VALUE,
869 0, psymtab_language, objfile);
873 CUR_SYMBOL_VALUE += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
874 if (pst && pst->textlow == 0)
875 pst->textlow = CUR_SYMBOL_VALUE;
877 add_psymbol_to_list (namestring, p - namestring,
878 VAR_NAMESPACE, LOC_BLOCK,
879 &objfile->global_psymbols, CUR_SYMBOL_VALUE,
880 0, psymtab_language, objfile);
889 /* It is a C++ nested symbol. We don't need to record it
890 (I don't think); if we try to look up foo::bar::baz,
891 then symbols for the symtab containing foo should get
893 /* Someone says sun cc puts out symbols like
894 /foo/baz/maclib::/usr/local/bin/maclib,
895 which would get here with a symbol type of ':'. */
899 /* Unexpected symbol descriptor. The second and subsequent stabs
900 of a continued stab can show up here. The question is
901 whether they ever can mimic a normal stab--it would be
902 nice if not, since we certainly don't want to spend the
903 time searching to the end of every string looking for
906 complain (&unknown_symchar_complaint, p[1]);
911 CUR_SYMBOL_VALUE += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
913 HANDLE_RBRAC (CUR_SYMBOL_VALUE);
920 /* If we haven't found it yet, ignore it. It's probably some
921 new type we don't know about yet. */
922 complain (&unknown_symtype_complaint,
923 local_hex_string ((unsigned long) bufp->n_type));
928 DBX_SYMCOUNT (objfile) = symnum;
930 /* If there's stuff to be cleaned up, clean it up. */
931 if (DBX_SYMCOUNT (objfile) > 0
932 /*FIXME, does this have a bug at start address 0? */
934 && objfile->ei.entry_point < bufp->n_value
935 && objfile->ei.entry_point >= last_o_file_start)
937 objfile->ei.entry_file_lowpc = last_o_file_start;
938 objfile->ei.entry_file_highpc = bufp->n_value;
943 os9k_end_psymtab (pst, psymtab_include_list, includes_used,
944 symnum, end_of_text_addr,
945 dependency_list, dependencies_used);
948 do_cleanups (back_to);
952 /* Allocate and partially fill a partial symtab. It will be
953 completely filled at the end of the symbol list.
955 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
956 is the address relative to which its symbols are (incremental) or 0
960 static struct partial_symtab *
961 os9k_start_psymtab (struct objfile *objfile, char *filename, CORE_ADDR textlow,
962 int ldsymoff, int ldsymcnt,
963 struct partial_symbol **global_syms,
964 struct partial_symbol **static_syms)
966 struct partial_symtab *result =
967 start_psymtab_common (objfile, objfile->section_offsets,
968 filename, textlow, global_syms, static_syms);
970 result->read_symtab_private = (char *)
971 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
973 LDSYMOFF (result) = ldsymoff;
974 LDSYMCNT (result) = ldsymcnt;
975 result->read_symtab = os9k_psymtab_to_symtab;
977 /* Deduce the source language from the filename for this psymtab. */
978 psymtab_language = deduce_language_from_filename (filename);
982 /* Close off the current usage of PST.
983 Returns PST or NULL if the partial symtab was empty and thrown away.
984 FIXME: List variables and peculiarities of same. */
986 static struct partial_symtab *
987 os9k_end_psymtab (struct partial_symtab *pst, char **include_list,
988 int num_includes, int capping_symbol_cnt,
989 CORE_ADDR capping_text,
990 struct partial_symtab **dependency_list,
991 int number_dependencies)
994 struct partial_symtab *p1;
995 struct objfile *objfile = pst->objfile;
997 if (capping_symbol_cnt != -1)
998 LDSYMCNT (pst) = capping_symbol_cnt - LDSYMCNT (pst);
1000 /* Under Solaris, the N_SO symbols always have a value of 0,
1001 instead of the usual address of the .o file. Therefore,
1002 we have to do some tricks to fill in texthigh and textlow.
1003 The first trick is in partial-stab.h: if we see a static
1004 or global function, and the textlow for the current pst
1005 is still 0, then we use that function's address for
1006 the textlow of the pst.
1008 Now, to fill in texthigh, we remember the last function seen
1009 in the .o file (also in partial-stab.h). Also, there's a hack in
1010 bfd/elf.c and gdb/elfread.c to pass the ELF st_size field
1011 to here via the misc_info field. Therefore, we can fill in
1012 a reliable texthigh by taking the address plus size of the
1013 last function in the file.
1015 Unfortunately, that does not cover the case where the last function
1016 in the file is static. See the paragraph below for more comments
1019 Finally, if we have a valid textlow for the current file, we run
1020 down the partial_symtab_list filling in previous texthighs that
1021 are still unknown. */
1023 if (pst->texthigh == 0 && last_function_name)
1027 struct minimal_symbol *minsym;
1029 p = strchr (last_function_name, ':');
1031 p = last_function_name;
1032 n = p - last_function_name;
1034 strncpy (p, last_function_name, n);
1037 minsym = lookup_minimal_symbol (p, NULL, objfile);
1041 pst->texthigh = SYMBOL_VALUE_ADDRESS (minsym) + (long) MSYMBOL_INFO (minsym);
1045 /* This file ends with a static function, and it's
1046 difficult to imagine how hard it would be to track down
1047 the elf symbol. Luckily, most of the time no one will notice,
1048 since the next file will likely be compiled with -g, so
1049 the code below will copy the first fuction's start address
1050 back to our texthigh variable. (Also, if this file is the
1051 last one in a dynamically linked program, texthigh already
1052 has the right value.) If the next file isn't compiled
1053 with -g, then the last function in this file winds up owning
1054 all of the text space up to the next -g file, or the end (minus
1055 shared libraries). This only matters for single stepping,
1056 and even then it will still work, except that it will single
1057 step through all of the covered functions, instead of setting
1058 breakpoints around them as it usualy does. This makes it
1059 pretty slow, but at least it doesn't fail.
1061 We can fix this with a fairly big change to bfd, but we need
1062 to coordinate better with Cygnus if we want to do that. FIXME. */
1064 last_function_name = NULL;
1067 /* this test will be true if the last .o file is only data */
1068 if (pst->textlow == 0)
1069 pst->textlow = pst->texthigh;
1071 /* If we know our own starting text address, then walk through all other
1072 psymtabs for this objfile, and if any didn't know their ending text
1073 address, set it to our starting address. Take care to not set our
1074 own ending address to our starting address, nor to set addresses on
1075 `dependency' files that have both textlow and texthigh zero. */
1078 ALL_OBJFILE_PSYMTABS (objfile, p1)
1080 if (p1->texthigh == 0 && p1->textlow != 0 && p1 != pst)
1082 p1->texthigh = pst->textlow;
1083 /* if this file has only data, then make textlow match texthigh */
1084 if (p1->textlow == 0)
1085 p1->textlow = p1->texthigh;
1090 /* End of kludge for patching Solaris textlow and texthigh. */
1092 pst->n_global_syms =
1093 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
1094 pst->n_static_syms =
1095 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
1097 pst->number_of_dependencies = number_dependencies;
1098 if (number_dependencies)
1100 pst->dependencies = (struct partial_symtab **)
1101 obstack_alloc (&objfile->psymbol_obstack,
1102 number_dependencies * sizeof (struct partial_symtab *));
1103 memcpy (pst->dependencies, dependency_list,
1104 number_dependencies * sizeof (struct partial_symtab *));
1107 pst->dependencies = 0;
1109 for (i = 0; i < num_includes; i++)
1111 struct partial_symtab *subpst =
1112 allocate_psymtab (include_list[i], objfile);
1114 subpst->section_offsets = pst->section_offsets;
1115 subpst->read_symtab_private =
1116 (char *) obstack_alloc (&objfile->psymbol_obstack,
1117 sizeof (struct symloc));
1121 subpst->texthigh = 0;
1123 /* We could save slight bits of space by only making one of these,
1124 shared by the entire set of include files. FIXME-someday. */
1125 subpst->dependencies = (struct partial_symtab **)
1126 obstack_alloc (&objfile->psymbol_obstack,
1127 sizeof (struct partial_symtab *));
1128 subpst->dependencies[0] = pst;
1129 subpst->number_of_dependencies = 1;
1131 subpst->globals_offset =
1132 subpst->n_global_syms =
1133 subpst->statics_offset =
1134 subpst->n_static_syms = 0;
1138 subpst->read_symtab = pst->read_symtab;
1141 sort_pst_symbols (pst);
1143 /* If there is already a psymtab or symtab for a file of this name,
1145 (If there is a symtab, more drastic things also happen.)
1146 This happens in VxWorks. */
1147 free_named_symtabs (pst->filename);
1149 if (num_includes == 0
1150 && number_dependencies == 0
1151 && pst->n_global_syms == 0
1152 && pst->n_static_syms == 0)
1154 /* Throw away this psymtab, it's empty. We can't deallocate it, since
1155 it is on the obstack, but we can forget to chain it on the list. */
1156 /* Indicate that psymtab was thrown away. */
1158 discard_psymtab (pst);
1160 pst = (struct partial_symtab *) NULL;
1166 os9k_psymtab_to_symtab_1 (struct partial_symtab *pst)
1168 struct cleanup *old_chain;
1176 fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1181 /* Read in all partial symtabs on which this one is dependent */
1182 for (i = 0; i < pst->number_of_dependencies; i++)
1183 if (!pst->dependencies[i]->readin)
1185 /* Inform about additional files that need to be read in. */
1188 fputs_filtered (" ", gdb_stdout);
1190 fputs_filtered ("and ", gdb_stdout);
1192 printf_filtered ("%s...", pst->dependencies[i]->filename);
1193 wrap_here (""); /* Flush output */
1194 gdb_flush (gdb_stdout);
1196 os9k_psymtab_to_symtab_1 (pst->dependencies[i]);
1199 if (LDSYMCNT (pst)) /* Otherwise it's a dummy */
1201 /* Init stuff necessary for reading in symbols */
1204 old_chain = make_cleanup (really_free_pendings, 0);
1206 /* Read in this file's symbols */
1207 os9k_read_ofile_symtab (pst);
1208 sort_symtab_syms (pst->symtab);
1209 do_cleanups (old_chain);
1215 /* Read in all of the symbols for a given psymtab for real.
1216 Be verbose about it if the user wants that. */
1219 os9k_psymtab_to_symtab (struct partial_symtab *pst)
1228 fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1233 if (LDSYMCNT (pst) || pst->number_of_dependencies)
1235 /* Print the message now, before reading the string table,
1236 to avoid disconcerting pauses. */
1239 printf_filtered ("Reading in symbols for %s...", pst->filename);
1240 gdb_flush (gdb_stdout);
1243 sym_bfd = pst->objfile->obfd;
1244 os9k_psymtab_to_symtab_1 (pst);
1246 /* Match with global symbols. This only needs to be done once,
1247 after all of the symtabs and dependencies have been read in. */
1248 scan_file_globals (pst->objfile);
1250 /* Finish up the debug error message. */
1252 printf_filtered ("done.\n");
1256 /* Read in a defined section of a specific object file's symbols. */
1258 os9k_read_ofile_symtab (struct partial_symtab *pst)
1260 register struct internal_symstruct *bufp;
1262 unsigned max_symnum;
1264 struct objfile *objfile;
1265 int sym_offset; /* Offset to start of symbols to read */
1266 CORE_ADDR text_offset; /* Start of text segment for symbols */
1267 int text_size; /* Size of text segment for symbols */
1270 objfile = pst->objfile;
1271 sym_offset = LDSYMOFF (pst);
1272 max_symnum = LDSYMCNT (pst);
1273 text_offset = pst->textlow;
1274 text_size = pst->texthigh - pst->textlow;
1276 current_objfile = objfile;
1277 subfile_stack = NULL;
1278 last_source_file = NULL;
1280 abfd = objfile->obfd;
1281 dbg_file = objfile->auxf2;
1284 /* It is necessary to actually read one symbol *before* the start
1285 of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
1286 occurs before the N_SO symbol.
1287 Detecting this in read_dbx_symtab
1288 would slow down initial readin, so we look for it here instead. */
1289 if (!processing_acc_compilation && sym_offset >= (int) symbol_size)
1291 fseek (objefile->auxf2, sym_offset, SEEK_CUR);
1292 fill_sym (objfile->auxf2, abfd);
1295 processing_gcc_compilation = 0;
1296 if (bufp->n_type == N_TEXT)
1298 if (STREQ (namestring, GCC_COMPILED_FLAG_SYMBOL))
1299 processing_gcc_compilation = 1;
1300 else if (STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL))
1301 processing_gcc_compilation = 2;
1304 /* Try to select a C++ demangling based on the compilation unit
1307 if (processing_gcc_compilation)
1309 if (AUTO_DEMANGLING)
1311 set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
1317 /* The N_SO starting this symtab is the first symbol, so we
1318 better not check the symbol before it. I'm not this can
1319 happen, but it doesn't hurt to check for it. */
1320 bfd_seek (symfile_bfd, sym_offset, SEEK_CUR);
1321 processing_gcc_compilation = 0;
1325 fseek (dbg_file, (long) sym_offset, 0);
1327 if (bufp->n_type != (unsigned char)N_SYM_SYM)
1328 error("First symbol in segment of executable not a source symbol");
1331 for (symnum = 0; symnum < max_symnum; symnum++)
1333 QUIT; /* Allow this to be interruptable */
1334 fill_sym (dbg_file, abfd);
1336 type = bufp->n_type;
1338 os9k_process_one_symbol ((int) type, (int) bufp->n_desc,
1339 (CORE_ADDR) bufp->n_value, bufp->n_strx, pst->section_offsets, objfile);
1341 /* We skip checking for a new .o or -l file; that should never
1342 happen in this routine. */
1347 /* I don't think this code will ever be executed, because
1348 the GCC_COMPILED_FLAG_SYMBOL usually is right before
1349 the N_SO symbol which starts this source file.
1350 However, there is no reason not to accept
1351 the GCC_COMPILED_FLAG_SYMBOL anywhere. */
1353 if (STREQ (namestring, GCC_COMPILED_FLAG_SYMBOL))
1354 processing_gcc_compilation = 1;
1355 else if (STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL))
1356 processing_gcc_compilation = 2;
1358 if (AUTO_DEMANGLING)
1360 set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
1363 else if (type & N_EXT || type == (unsigned char) N_TEXT
1364 || type == (unsigned char) N_NBTEXT
1367 /* Global symbol: see if we came across a dbx defintion for
1368 a corresponding symbol. If so, store the value. Remove
1369 syms from the chain when their values are stored, but
1370 search the whole chain, as there may be several syms from
1371 different files with the same name. */
1372 /* This is probably not true. Since the files will be read
1373 in one at a time, each reference to a global symbol will
1374 be satisfied in each file as it appears. So we skip this
1381 current_objfile = NULL;
1383 /* In a Solaris elf file, this variable, which comes from the
1384 value of the N_SO symbol, will still be 0. Luckily, text_offset,
1385 which comes from pst->textlow is correct. */
1386 if (last_source_start_addr == 0)
1387 last_source_start_addr = text_offset;
1388 pst->symtab = end_symtab (text_offset + text_size, objfile, SECT_OFF_TEXT (objfile));
1393 /* This handles a single symbol from the symbol-file, building symbols
1394 into a GDB symtab. It takes these arguments and an implicit argument.
1396 TYPE is the type field of the ".stab" symbol entry.
1397 DESC is the desc field of the ".stab" entry.
1398 VALU is the value field of the ".stab" entry.
1399 NAME is the symbol name, in our address space.
1400 SECTION_OFFSETS is a set of amounts by which the sections of this object
1401 file were relocated when it was loaded into memory.
1402 All symbols that refer
1403 to memory locations need to be offset by these amounts.
1404 OBJFILE is the object file from which we are reading symbols.
1405 It is used in end_symtab. */
1408 os9k_process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
1409 struct section_offsets *section_offsets,
1410 struct objfile *objfile)
1412 register struct context_stack *new;
1413 /* The stab type used for the definition of the last function.
1414 N_STSYM or N_GSYM for SunOS4 acc; N_FUN for other compilers. */
1415 static int function_stab_type = 0;
1418 /* Something is wrong if we see real data before
1419 seeing a source file name. */
1420 if (last_source_file == NULL && type != (unsigned char) N_SO)
1422 /* Ignore any symbols which appear before an N_SO symbol.
1423 Currently no one puts symbols there, but we should deal
1424 gracefully with the case. A complain()t might be in order,
1425 but this should not be an error (). */
1433 /* On most machines, the block addresses are relative to the
1434 N_SO, the linker did not relocate them (sigh). */
1435 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
1436 new = push_context (desc, valu);
1440 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
1441 new = pop_context ();
1443 #if !defined (OS9K_VARIABLES_INSIDE_BLOCK)
1444 #define OS9K_VARIABLES_INSIDE_BLOCK(desc, gcc_p) 1
1447 if (!OS9K_VARIABLES_INSIDE_BLOCK (desc, processing_gcc_compilation))
1448 local_symbols = new->locals;
1450 if (context_stack_depth > 1)
1452 /* This is not the outermost LBRAC...RBRAC pair in the function,
1453 its local symbols preceded it, and are the ones just recovered
1454 from the context stack. Define the block for them (but don't
1455 bother if the block contains no symbols. Should we complain
1456 on blocks without symbols? I can't think of any useful purpose
1458 if (local_symbols != NULL)
1460 /* Muzzle a compiler bug that makes end < start. (which
1461 compilers? Is this ever harmful?). */
1462 if (new->start_addr > valu)
1464 complain (&lbrac_rbrac_complaint);
1465 new->start_addr = valu;
1467 /* Make a block for the local symbols within. */
1468 finish_block (0, &local_symbols, new->old_blocks,
1469 new->start_addr, valu, objfile);
1474 if (context_stack_depth == 0)
1476 within_function = 0;
1477 /* Make a block for the local symbols within. */
1478 finish_block (new->name, &local_symbols, new->old_blocks,
1479 new->start_addr, valu, objfile);
1483 /* attach local_symbols to the end of new->locals */
1485 new->locals = local_symbols;
1493 p->next = local_symbols;
1498 if (OS9K_VARIABLES_INSIDE_BLOCK (desc, processing_gcc_compilation))
1499 /* Now pop locals of block just finished. */
1500 local_symbols = new->locals;
1505 /* This type of "symbol" really just records
1506 one line-number -- core-address correspondence.
1507 Enter it in the line list for this symbol table. */
1508 /* Relocate for dynamic loading and for ELF acc fn-relative syms. */
1509 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
1510 /* FIXME: loses if sizeof (char *) > sizeof (int) */
1511 gdb_assert (sizeof (name) <= sizeof (int));
1512 record_line (current_subfile, (int) name, valu);
1515 /* The following symbol types need to have the appropriate offset added
1516 to their value; then we process symbol definitions in the name. */
1523 char *p = strchr (name, ':');
1533 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
1534 n = strrchr (name, '/');
1547 if (symfile_depth++ == 0)
1549 if (last_source_file)
1551 end_symtab (valu, objfile, SECT_OFF_TEXT (objfile));
1556 start_symtab (n, dirn, valu);
1557 record_debugformat ("OS9");
1562 start_subfile (n, dirn != NULL ? dirn : current_subfile->dirname);
1568 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
1569 function_stab_type = type;
1571 within_function = 1;
1572 new = push_context (0, valu);
1573 new->name = define_symbol (valu, name, desc, type, objfile);
1578 valu += ANOFFSET (section_offsets, SECT_OFF_DATA (objfile));
1579 define_symbol (valu, name, desc, type, objfile);
1583 define_symbol (valu, name, desc, type, objfile);
1590 if (--symfile_depth != 0)
1591 start_subfile (pop_subfile (), current_subfile->dirname);
1595 complain (&unknown_symtype_complaint,
1596 local_hex_string ((unsigned long) type));
1603 previous_stab_code = type;
1606 static struct sym_fns os9k_sym_fns =
1608 bfd_target_os9k_flavour,
1609 os9k_new_init, /* sym_new_init: init anything gbl to entire symtab */
1610 os9k_symfile_init, /* sym_init: read initial info, setup for sym_read() */
1611 os9k_symfile_read, /* sym_read: read a symbol file into symtab */
1612 os9k_symfile_finish, /* sym_finish: finished with file, cleanup */
1613 default_symfile_offsets, /* sym_offsets: parse user's offsets to internal form */
1614 NULL /* next: pointer to next struct sym_fns */
1618 _initialize_os9kread (void)
1620 add_symtab_fns (&os9k_sym_fns);