1 /* Read os9/os9k symbol tables and convert to internal format, for GDB.
2 Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 96, 1998
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., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* This module provides three functions: os9k_symfile_init,
23 which initializes to read a symbol file; os9k_new_init, which
24 discards existing cached information when all symbols are being
25 discarded; and os9k_symfile_read, which reads a symbol table
28 os9k_symfile_read only does the minimum work necessary for letting the
29 user "name" things symbolically; it does not read the entire symtab.
30 Instead, it reads the external and static symbols and puts them in partial
31 symbol tables. When more extensive information is requested of a
32 file, the corresponding partial symbol table is mutated into a full
33 fledged symbol table by going back and reading the symbols
34 for real. os9k_psymtab_to_symtab() is the function that does this */
37 #include "gdb_string.h"
40 #if defined(USG) || defined(__CYGNUSCLIB__)
41 #include <sys/types.h>
49 #include "breakpoint.h"
52 #include "gdbcore.h" /* for bfd stuff */
53 #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
57 #include "gdb-stabs.h"
59 #include "language.h" /* Needed inside partial-stab.h */
60 #include "complaints.h"
62 #include "stabsread.h"
64 extern void _initialize_os9kread (void);
66 /* Each partial symbol table entry contains a pointer to private data for the
67 read_symtab() function to use when expanding a partial symbol table entry
68 to a full symbol table entry.
70 For dbxread this structure contains the offset within the file symbol table
71 of first local symbol for this file, and count of the section
72 of the symbol table devoted to this file's symbols (actually, the section
73 bracketed may contain more than just this file's symbols). It also contains
74 further information needed to locate the symbols if they are in an ELF file.
76 If ldsymcnt is 0, the only reason for this thing's existence is the
77 dependency list. Nothing else will happen when it is read in. */
79 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
80 #define LDSYMCNT(p) (((struct symloc *)((p)->read_symtab_private))->ldsymnum)
88 /* Remember what we deduced to be the source language of this psymtab. */
89 static enum language psymtab_language
= language_unknown
;
91 /* keep partial symbol table file nested depth */
92 static int psymfile_depth
= 0;
94 /* keep symbol table file nested depth */
95 static int symfile_depth
= 0;
97 /* Nonzero means give verbose info on gdb action. From main.c. */
98 extern int info_verbose
;
100 extern int previous_stab_code
;
102 /* Name of last function encountered. Used in Solaris to approximate
103 object file boundaries. */
104 static char *last_function_name
;
106 /* Complaints about the symbols we have encountered. */
107 extern struct complaint lbrac_complaint
;
109 extern struct complaint unknown_symtype_complaint
;
111 extern struct complaint unknown_symchar_complaint
;
113 extern struct complaint lbrac_rbrac_complaint
;
115 extern struct complaint repeated_header_complaint
;
117 extern struct complaint repeated_header_name_complaint
;
120 static struct complaint lbrac_unmatched_complaint
=
121 {"unmatched Increment Block Entry before symtab pos %d", 0, 0};
123 static struct complaint lbrac_mismatch_complaint
=
124 {"IBE/IDE symbol mismatch at symtab pos %d", 0, 0};
127 /* Local function prototypes */
129 static void read_minimal_symbols (struct objfile
*);
131 static void os9k_read_ofile_symtab (struct partial_symtab
*);
133 static void os9k_psymtab_to_symtab (struct partial_symtab
*);
135 static void os9k_psymtab_to_symtab_1 (struct partial_symtab
*);
137 static void read_os9k_psymtab (struct objfile
*, CORE_ADDR
, int);
139 static int fill_sym (FILE *, bfd
*);
141 static void os9k_symfile_init (struct objfile
*);
143 static void os9k_new_init (struct objfile
*);
145 static void os9k_symfile_read (struct objfile
*, int);
147 static void os9k_symfile_finish (struct objfile
*);
150 os9k_process_one_symbol (int, int, CORE_ADDR
, char *,
151 struct section_offsets
*, struct objfile
*);
153 static struct partial_symtab
*os9k_start_psymtab (struct objfile
*, char *,
155 struct partial_symbol
**,
156 struct partial_symbol
**);
158 static struct partial_symtab
*os9k_end_psymtab (struct partial_symtab
*,
159 char **, int, int, CORE_ADDR
,
160 struct partial_symtab
**,
163 static void record_minimal_symbol (char *, CORE_ADDR
, int, struct objfile
*);
165 #define HANDLE_RBRAC(val) \
166 if ((val) > pst->texthigh) pst->texthigh = (val);
168 #define SWAP_STBHDR(hdrp, abfd) \
170 (hdrp)->fmtno = bfd_get_16(abfd, (unsigned char *)&(hdrp)->fmtno); \
171 (hdrp)->crc = bfd_get_32(abfd, (unsigned char *)&(hdrp)->crc); \
172 (hdrp)->offset = bfd_get_32(abfd, (unsigned char *)&(hdrp)->offset); \
173 (hdrp)->nsym = bfd_get_32(abfd, (unsigned char *)&(hdrp)->nsym); \
175 #define SWAP_STBSYM(symp, abfd) \
177 (symp)->value = bfd_get_32(abfd, (unsigned char *)&(symp)->value); \
178 (symp)->type = bfd_get_16(abfd, (unsigned char *)&(symp)->type); \
179 (symp)->stroff = bfd_get_32(abfd, (unsigned char *)&(symp)->stroff); \
189 record_minimal_symbol (char *name
, CORE_ADDR address
, int type
,
190 struct objfile
*objfile
)
192 enum minimal_symbol_type ms_type
;
198 address
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
216 ms_type
= mst_unknown
;
220 prim_record_minimal_symbol (name
, address
, ms_type
, objfile
);
223 /* read and process .stb file and store in minimal symbol table */
224 typedef char mhhdr
[80];
241 #define STBSYMSIZE 10
244 read_minimal_symbols (struct objfile
*objfile
)
249 struct stbsymbol sym
;
251 char buf
[64], buf1
[128];
256 abfd
= objfile
->obfd
;
257 fread (&hdr
.comhdr
[0], sizeof (mhhdr
), 1, fp
);
272 fread (&hdr
.fmtno
, sizeof (hdr
.fmtno
), 1, fp
);
273 fread (&hdr
.crc
, sizeof (hdr
.crc
), 1, fp
);
274 fread (&hdr
.offset
, sizeof (hdr
.offset
), 1, fp
);
275 fread (&hdr
.nsym
, sizeof (hdr
.nsym
), 1, fp
);
276 SWAP_STBHDR (&hdr
, abfd
);
279 init_minimal_symbol_collection ();
281 for (i
= hdr
.nsym
; i
> 0; i
--)
283 fseek (fp
, (long) off
, 0);
284 fread (&sym
.value
, sizeof (sym
.value
), 1, fp
);
285 fread (&sym
.type
, sizeof (sym
.type
), 1, fp
);
286 fread (&sym
.stroff
, sizeof (sym
.stroff
), 1, fp
);
287 SWAP_STBSYM (&sym
, abfd
);
288 fseek (fp
, (long) sym
.stroff
, 0);
299 record_minimal_symbol (buf1
, sym
.value
, sym
.type
& 7, objfile
);
302 install_minimal_symbols (objfile
);
306 /* Scan and build partial symbols for a symbol file.
307 We have been initialized by a call to os9k_symfile_init, which
308 put all the relevant info into a "struct os9k_symfile_info",
309 hung off the objfile structure.
311 MAINLINE is true if we are reading the main symbol
312 table (as opposed to a shared lib or dynamically loaded file). */
315 os9k_symfile_read (objfile
, mainline
)
316 struct objfile
*objfile
;
317 int mainline
; /* FIXME comments above */
320 struct cleanup
*back_to
;
322 sym_bfd
= objfile
->obfd
;
323 /* If we are reinitializing, or if we have never loaded syms yet, init */
324 if (mainline
|| objfile
->global_psymbols
.size
== 0 ||
325 objfile
->static_psymbols
.size
== 0)
326 init_psymbol_list (objfile
, DBX_SYMCOUNT (objfile
));
328 free_pending_blocks ();
329 back_to
= make_cleanup (really_free_pendings
, 0);
331 make_cleanup_discard_minimal_symbols ();
332 read_minimal_symbols (objfile
);
334 /* Now that the symbol table data of the executable file are all in core,
335 process them and define symbols accordingly. */
336 read_os9k_psymtab (objfile
,
337 DBX_TEXT_ADDR (objfile
),
338 DBX_TEXT_SIZE (objfile
));
340 do_cleanups (back_to
);
343 /* Initialize anything that needs initializing when a completely new
344 symbol file is specified (not just adding some symbols from another
345 file, e.g. a shared library). */
348 os9k_new_init (struct objfile
*ignore
)
350 stabsread_new_init ();
351 buildsym_new_init ();
354 init_header_files ();
358 /* os9k_symfile_init ()
359 It is passed a struct objfile which contains, among other things,
360 the BFD for the file whose symbols are being read, and a slot for a pointer
361 to "private data" which we fill with goodies.
363 Since BFD doesn't know how to read debug symbols in a format-independent
364 way (and may never do so...), we have to do it ourselves. We will never
365 be called unless this is an a.out (or very similar) file.
366 FIXME, there should be a cleaner peephole into the BFD environment here. */
369 os9k_symfile_init (struct objfile
*objfile
)
371 bfd
*sym_bfd
= objfile
->obfd
;
372 char *name
= bfd_get_filename (sym_bfd
);
373 char dbgname
[512], stbname
[512];
378 strcpy (dbgname
, name
);
379 strcat (dbgname
, ".dbg");
380 strcpy (stbname
, name
);
381 strcat (stbname
, ".stb");
383 if ((symfile
= fopen (dbgname
, "r")) == NULL
)
385 warning ("Symbol file %s not found", dbgname
);
387 objfile
->auxf2
= symfile
;
389 if ((minfile
= fopen (stbname
, "r")) == NULL
)
391 warning ("Symbol file %s not found", stbname
);
393 objfile
->auxf1
= minfile
;
395 /* Allocate struct to keep track of the symfile */
396 objfile
->sym_stab_info
= (struct dbx_symfile_info
*)
397 xmmalloc (objfile
->md
, sizeof (struct dbx_symfile_info
));
398 DBX_SYMFILE_INFO (objfile
)->stab_section_info
= NULL
;
400 text_sect
= bfd_get_section_by_name (sym_bfd
, ".text");
402 error ("Can't find .text section in file");
403 DBX_TEXT_ADDR (objfile
) = bfd_section_vma (sym_bfd
, text_sect
);
404 DBX_TEXT_SIZE (objfile
) = bfd_section_size (sym_bfd
, text_sect
);
406 DBX_SYMBOL_SIZE (objfile
) = 0; /* variable size symbol */
407 DBX_SYMCOUNT (objfile
) = 0; /* used to be bfd_get_symcount(sym_bfd) */
408 DBX_SYMTAB_OFFSET (objfile
) = 0; /* used to be SYMBOL_TABLE_OFFSET */
411 /* Perform any local cleanups required when we are done with a particular
412 objfile. I.E, we are in the process of discarding all symbol information
413 for an objfile, freeing up all memory held for it, and unlinking the
414 objfile struct from the global list of known objfiles. */
417 os9k_symfile_finish (struct objfile
*objfile
)
419 if (objfile
->sym_stab_info
!= NULL
)
421 mfree (objfile
->md
, objfile
->sym_stab_info
);
424 free_header_files ();
437 #define SYNC (int)0xefbefeca
439 #define SWAP_DBGHDR(hdrp, abfd) \
441 (hdrp)->sync = bfd_get_32(abfd, (unsigned char *)&(hdrp)->sync); \
442 (hdrp)->rev = bfd_get_16(abfd, (unsigned char *)&(hdrp)->rev); \
443 (hdrp)->crc = bfd_get_32(abfd, (unsigned char *)&(hdrp)->crc); \
444 (hdrp)->os = bfd_get_16(abfd, (unsigned char *)&(hdrp)->os); \
445 (hdrp)->cpu = bfd_get_16(abfd, (unsigned char *)&(hdrp)->cpu); \
448 #define N_SYM_CMPLR 0
449 #define N_SYM_SLINE 1
451 #define N_SYM_LBRAC 3
452 #define N_SYM_RBRAC 4
455 struct internal_symstruct
462 static struct internal_symstruct symbol
;
463 static struct internal_symstruct
*symbuf
= &symbol
;
464 static char strbuf
[4096];
465 static struct st_dbghdr dbghdr
;
466 static short cmplrid
;
468 #define VER_PRE_ULTRAC ((short)4)
469 #define VER_ULTRAC ((short)5)
472 fill_sym (FILE *dbg_file
, bfd
*abfd
)
479 int nbytes
= fread (&si
, sizeof (si
), 1, dbg_file
);
483 perror_with_name ("reading .dbg file.");
486 symbuf
->n_strx
= NULL
;
487 symbuf
->n_type
= bfd_get_16 (abfd
, (unsigned char *) &si
);
488 symbuf
->n_type
= 0xf & symbuf
->n_type
;
489 switch (symbuf
->n_type
)
492 fread (&si
, sizeof (si
), 1, dbg_file
);
493 symbuf
->n_desc
= bfd_get_16 (abfd
, (unsigned char *) &si
);
494 cmplrid
= symbuf
->n_desc
& 0xff;
497 fread (&li
, sizeof (li
), 1, dbg_file
);
498 symbuf
->n_value
= bfd_get_32 (abfd
, (unsigned char *) &li
);
499 fread (&li
, sizeof (li
), 1, dbg_file
);
500 li
= bfd_get_32 (abfd
, (unsigned char *) &li
);
501 symbuf
->n_strx
= (char *) (li
>> 12);
502 symbuf
->n_desc
= li
& 0xfff;
505 fread (&li
, sizeof (li
), 1, dbg_file
);
506 symbuf
->n_value
= bfd_get_32 (abfd
, (unsigned char *) &li
);
510 ii
= getc (dbg_file
);
511 strbuf
[si
++] = (char) ii
;
513 while (ii
!= 0 || si
% 2 != 0);
514 symbuf
->n_strx
= strbuf
;
515 p
= (char *) strchr (strbuf
, ':');
518 if ((p
[1] == 'F' || p
[1] == 'f') && cmplrid
== VER_PRE_ULTRAC
)
520 fread (&si
, sizeof (si
), 1, dbg_file
);
521 nmask
= bfd_get_16 (abfd
, (unsigned char *) &si
);
522 for (ii
= 0; ii
< nmask
; ii
++)
523 fread (&si
, sizeof (si
), 1, dbg_file
);
527 fread (&li
, sizeof (li
), 1, dbg_file
);
528 symbuf
->n_value
= bfd_get_32 (abfd
, (unsigned char *) &li
);
531 fread (&li
, sizeof (li
), 1, dbg_file
);
532 symbuf
->n_value
= bfd_get_32 (abfd
, (unsigned char *) &li
);
540 /* Given pointers to an a.out symbol table in core containing dbx
541 style data, setup partial_symtab's describing each source file for
542 which debugging information is available.
543 SYMFILE_NAME is the name of the file we are reading from. */
546 read_os9k_psymtab (struct objfile
*objfile
, CORE_ADDR text_addr
, int text_size
)
548 register struct internal_symstruct
*bufp
= 0; /* =0 avoids gcc -Wall glitch */
549 register char *namestring
;
550 int past_first_source_file
= 0;
551 CORE_ADDR last_o_file_start
= 0;
553 struct cleanup
*back_to
;
558 /* End of the text segment of the executable file. */
559 static CORE_ADDR end_of_text_addr
;
561 /* Current partial symtab */
562 static struct partial_symtab
*pst
= 0;
564 /* List of current psymtab's include files */
565 char **psymtab_include_list
;
566 int includes_allocated
;
569 /* Index within current psymtab dependency list */
570 struct partial_symtab
**dependency_list
;
571 int dependencies_used
, dependencies_allocated
;
573 includes_allocated
= 30;
575 psymtab_include_list
= (char **) alloca (includes_allocated
*
578 dependencies_allocated
= 30;
579 dependencies_used
= 0;
581 (struct partial_symtab
**) alloca (dependencies_allocated
*
582 sizeof (struct partial_symtab
*));
584 last_source_file
= NULL
;
586 #ifdef END_OF_TEXT_DEFAULT
587 end_of_text_addr
= END_OF_TEXT_DEFAULT
;
589 end_of_text_addr
= text_addr
+ ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
))
590 + text_size
; /* Relocate */
593 abfd
= objfile
->obfd
;
598 fread (&dbghdr
.sync
, sizeof (dbghdr
.sync
), 1, fp
);
599 fread (&dbghdr
.rev
, sizeof (dbghdr
.rev
), 1, fp
);
600 fread (&dbghdr
.crc
, sizeof (dbghdr
.crc
), 1, fp
);
601 fread (&dbghdr
.os
, sizeof (dbghdr
.os
), 1, fp
);
602 fread (&dbghdr
.cpu
, sizeof (dbghdr
.cpu
), 1, fp
);
603 SWAP_DBGHDR (&dbghdr
, abfd
);
611 /* Get the symbol for this run and pull out some info */
612 QUIT
; /* allow this to be interruptable */
613 cursymoffset
= ftell (objfile
->auxf2
);
614 ret
= fill_sym (objfile
->auxf2
, abfd
);
621 /* Special case to speed up readin. */
622 if (bufp
->n_type
== (short) N_SYM_SLINE
)
625 #define CUR_SYMBOL_VALUE bufp->n_value
628 switch (bufp
->n_type
)
636 CUR_SYMBOL_VALUE
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
637 if (psymfile_depth
== 1 && pst
)
639 os9k_end_psymtab (pst
, psymtab_include_list
, includes_used
,
640 symnum
, CUR_SYMBOL_VALUE
,
641 dependency_list
, dependencies_used
);
642 pst
= (struct partial_symtab
*) 0;
644 dependencies_used
= 0;
649 case N_SYM_SYM
: /* Typedef or automatic variable. */
650 namestring
= bufp
->n_strx
;
651 p
= (char *) strchr (namestring
, ':');
653 continue; /* Not a debugging symbol. */
655 /* Main processing section for debugging symbols which
656 the initial read through the symbol tables needs to worry
657 about. If we reach this point, the symbol which we are
658 considering is definitely one we are interested in.
659 p must also contain the (valid) index into the namestring
660 which indicates the debugging type symbol. */
667 enum language tmp_language
;
671 valu
= CUR_SYMBOL_VALUE
;
673 valu
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
674 past_first_source_file
= 1;
676 p
= strchr (namestring
, ':');
680 n
= strlen (namestring
);
681 str
= alloca (n
+ 1);
682 strncpy (str
, namestring
, n
);
685 if (psymfile_depth
== 0)
688 pst
= os9k_start_psymtab (objfile
,
692 objfile
->global_psymbols
.next
,
693 objfile
->static_psymbols
.next
);
696 { /* this is a include file */
697 tmp_language
= deduce_language_from_filename (str
);
698 if (tmp_language
!= language_unknown
699 && (tmp_language
!= language_c
700 || psymtab_language
!= language_cplus
))
701 psymtab_language
= tmp_language
;
704 if (pst && STREQ (str, pst->filename))
708 for (i = 0; i < includes_used; i++)
709 if (STREQ (str, psymtab_include_list[i]))
719 psymtab_include_list
[includes_used
++] = str
;
720 if (includes_used
>= includes_allocated
)
722 char **orig
= psymtab_include_list
;
724 psymtab_include_list
= (char **)
725 alloca ((includes_allocated
*= 2) * sizeof (char *));
726 memcpy ((PTR
) psymtab_include_list
, (PTR
) orig
,
727 includes_used
* sizeof (char *));
736 add_psymbol_to_list (namestring
, p
- namestring
,
737 VAR_NAMESPACE
, LOC_STATIC
,
738 &objfile
->static_psymbols
,
740 psymtab_language
, objfile
);
743 add_psymbol_to_list (namestring
, p
- namestring
,
744 VAR_NAMESPACE
, LOC_STATIC
,
745 &objfile
->global_psymbols
,
747 psymtab_language
, objfile
);
751 if (p
!= namestring
) /* a name is there, not just :T... */
753 add_psymbol_to_list (namestring
, p
- namestring
,
754 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
755 &objfile
->static_psymbols
,
757 psymtab_language
, objfile
);
760 /* Also a typedef with the same name. */
761 add_psymbol_to_list (namestring
, p
- namestring
,
762 VAR_NAMESPACE
, LOC_TYPEDEF
,
763 &objfile
->static_psymbols
,
764 CUR_SYMBOL_VALUE
, 0, psymtab_language
,
768 /* The semantics of C++ state that "struct foo { ... }"
769 also defines a typedef for "foo". Unfortuantely, cfront
770 never makes the typedef when translating from C++ to C.
771 We make the typedef here so that "ptype foo" works as
772 expected for cfront translated code. */
773 else if (psymtab_language
== language_cplus
)
775 /* Also a typedef with the same name. */
776 add_psymbol_to_list (namestring
, p
- namestring
,
777 VAR_NAMESPACE
, LOC_TYPEDEF
,
778 &objfile
->static_psymbols
,
779 CUR_SYMBOL_VALUE
, 0, psymtab_language
,
785 if (p
!= namestring
) /* a name is there, not just :T... */
787 add_psymbol_to_list (namestring
, p
- namestring
,
788 VAR_NAMESPACE
, LOC_TYPEDEF
,
789 &objfile
->static_psymbols
,
791 psymtab_language
, objfile
);
794 /* If this is an enumerated type, we need to
795 add all the enum constants to the partial symbol
796 table. This does not cover enums without names, e.g.
797 "enum {a, b} c;" in C, but fortunately those are
798 rare. There is no way for GDB to find those from the
799 enum type without spending too much time on it. Thus
800 to solve this problem, the compiler needs to put out the
801 enum in a nameless type. GCC2 does this. */
803 /* We are looking for something of the form
804 <name> ":" ("t" | "T") [<number> "="] "e" <size>
805 {<constant> ":" <value> ","} ";". */
807 /* Skip over the colon and the 't' or 'T'. */
809 /* This type may be given a number. Also, numbers can come
810 in pairs like (0,26). Skip over it. */
811 while ((*p
>= '0' && *p
<= '9')
812 || *p
== '(' || *p
== ',' || *p
== ')'
818 /* We have found an enumerated type. skip size */
819 while (*p
>= '0' && *p
<= '9')
821 /* According to comments in read_enum_type
822 a comma could end it instead of a semicolon.
823 I don't know where that happens.
825 while (*p
&& *p
!= ';' && *p
!= ',')
829 /* Check for and handle cretinous dbx symbol name
832 p = next_symbol_text (objfile);
835 /* Point to the character after the name
836 of the enum constant. */
837 for (q
= p
; *q
&& *q
!= ':'; q
++)
839 /* Note that the value doesn't matter for
840 enum constants in psymtabs, just in symtabs. */
841 add_psymbol_to_list (p
, q
- p
,
842 VAR_NAMESPACE
, LOC_CONST
,
843 &objfile
->static_psymbols
, 0,
844 0, psymtab_language
, objfile
);
845 /* Point past the name. */
847 /* Skip over the value. */
848 while (*p
&& *p
!= ',')
850 /* Advance past the comma. */
857 /* Constant, e.g. from "const" in Pascal. */
858 add_psymbol_to_list (namestring
, p
- namestring
,
859 VAR_NAMESPACE
, LOC_CONST
,
860 &objfile
->static_psymbols
, CUR_SYMBOL_VALUE
,
861 0, psymtab_language
, objfile
);
865 CUR_SYMBOL_VALUE
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
866 if (pst
&& pst
->textlow
== 0)
867 pst
->textlow
= CUR_SYMBOL_VALUE
;
869 add_psymbol_to_list (namestring
, p
- namestring
,
870 VAR_NAMESPACE
, LOC_BLOCK
,
871 &objfile
->static_psymbols
, CUR_SYMBOL_VALUE
,
872 0, psymtab_language
, objfile
);
876 CUR_SYMBOL_VALUE
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
877 if (pst
&& pst
->textlow
== 0)
878 pst
->textlow
= CUR_SYMBOL_VALUE
;
880 add_psymbol_to_list (namestring
, p
- namestring
,
881 VAR_NAMESPACE
, LOC_BLOCK
,
882 &objfile
->global_psymbols
, CUR_SYMBOL_VALUE
,
883 0, psymtab_language
, objfile
);
892 /* It is a C++ nested symbol. We don't need to record it
893 (I don't think); if we try to look up foo::bar::baz,
894 then symbols for the symtab containing foo should get
896 /* Someone says sun cc puts out symbols like
897 /foo/baz/maclib::/usr/local/bin/maclib,
898 which would get here with a symbol type of ':'. */
902 /* Unexpected symbol descriptor. The second and subsequent stabs
903 of a continued stab can show up here. The question is
904 whether they ever can mimic a normal stab--it would be
905 nice if not, since we certainly don't want to spend the
906 time searching to the end of every string looking for
909 complain (&unknown_symchar_complaint
, p
[1]);
914 CUR_SYMBOL_VALUE
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
916 HANDLE_RBRAC (CUR_SYMBOL_VALUE
);
923 /* If we haven't found it yet, ignore it. It's probably some
924 new type we don't know about yet. */
925 complain (&unknown_symtype_complaint
,
926 local_hex_string ((unsigned long) bufp
->n_type
));
931 DBX_SYMCOUNT (objfile
) = symnum
;
933 /* If there's stuff to be cleaned up, clean it up. */
934 if (DBX_SYMCOUNT (objfile
) > 0
935 /*FIXME, does this have a bug at start address 0? */
937 && objfile
->ei
.entry_point
< bufp
->n_value
938 && objfile
->ei
.entry_point
>= last_o_file_start
)
940 objfile
->ei
.entry_file_lowpc
= last_o_file_start
;
941 objfile
->ei
.entry_file_highpc
= bufp
->n_value
;
946 os9k_end_psymtab (pst
, psymtab_include_list
, includes_used
,
947 symnum
, end_of_text_addr
,
948 dependency_list
, dependencies_used
);
951 do_cleanups (back_to);
955 /* Allocate and partially fill a partial symtab. It will be
956 completely filled at the end of the symbol list.
958 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
959 is the address relative to which its symbols are (incremental) or 0
963 static struct partial_symtab
*
964 os9k_start_psymtab (struct objfile
*objfile
, char *filename
, CORE_ADDR textlow
,
965 int ldsymoff
, int ldsymcnt
,
966 struct partial_symbol
**global_syms
,
967 struct partial_symbol
**static_syms
)
969 struct partial_symtab
*result
=
970 start_psymtab_common (objfile
, objfile
->section_offsets
,
971 filename
, textlow
, global_syms
, static_syms
);
973 result
->read_symtab_private
= (char *)
974 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct symloc
));
976 LDSYMOFF (result
) = ldsymoff
;
977 LDSYMCNT (result
) = ldsymcnt
;
978 result
->read_symtab
= os9k_psymtab_to_symtab
;
980 /* Deduce the source language from the filename for this psymtab. */
981 psymtab_language
= deduce_language_from_filename (filename
);
985 /* Close off the current usage of PST.
986 Returns PST or NULL if the partial symtab was empty and thrown away.
987 FIXME: List variables and peculiarities of same. */
989 static struct partial_symtab
*
990 os9k_end_psymtab (pst
, include_list
, num_includes
, capping_symbol_cnt
,
991 capping_text
, dependency_list
, number_dependencies
)
992 struct partial_symtab
*pst
;
995 int capping_symbol_cnt
;
996 CORE_ADDR capping_text
;
997 struct partial_symtab
**dependency_list
;
998 int number_dependencies
;
999 /* struct partial_symbol *capping_global, *capping_static; */
1002 struct partial_symtab
*p1
;
1003 struct objfile
*objfile
= pst
->objfile
;
1005 if (capping_symbol_cnt
!= -1)
1006 LDSYMCNT (pst
) = capping_symbol_cnt
- LDSYMCNT (pst
);
1008 /* Under Solaris, the N_SO symbols always have a value of 0,
1009 instead of the usual address of the .o file. Therefore,
1010 we have to do some tricks to fill in texthigh and textlow.
1011 The first trick is in partial-stab.h: if we see a static
1012 or global function, and the textlow for the current pst
1013 is still 0, then we use that function's address for
1014 the textlow of the pst.
1016 Now, to fill in texthigh, we remember the last function seen
1017 in the .o file (also in partial-stab.h). Also, there's a hack in
1018 bfd/elf.c and gdb/elfread.c to pass the ELF st_size field
1019 to here via the misc_info field. Therefore, we can fill in
1020 a reliable texthigh by taking the address plus size of the
1021 last function in the file.
1023 Unfortunately, that does not cover the case where the last function
1024 in the file is static. See the paragraph below for more comments
1027 Finally, if we have a valid textlow for the current file, we run
1028 down the partial_symtab_list filling in previous texthighs that
1029 are still unknown. */
1031 if (pst
->texthigh
== 0 && last_function_name
)
1035 struct minimal_symbol
*minsym
;
1037 p
= strchr (last_function_name
, ':');
1039 p
= last_function_name
;
1040 n
= p
- last_function_name
;
1042 strncpy (p
, last_function_name
, n
);
1045 minsym
= lookup_minimal_symbol (p
, NULL
, objfile
);
1049 pst
->texthigh
= SYMBOL_VALUE_ADDRESS (minsym
) + (long) MSYMBOL_INFO (minsym
);
1053 /* This file ends with a static function, and it's
1054 difficult to imagine how hard it would be to track down
1055 the elf symbol. Luckily, most of the time no one will notice,
1056 since the next file will likely be compiled with -g, so
1057 the code below will copy the first fuction's start address
1058 back to our texthigh variable. (Also, if this file is the
1059 last one in a dynamically linked program, texthigh already
1060 has the right value.) If the next file isn't compiled
1061 with -g, then the last function in this file winds up owning
1062 all of the text space up to the next -g file, or the end (minus
1063 shared libraries). This only matters for single stepping,
1064 and even then it will still work, except that it will single
1065 step through all of the covered functions, instead of setting
1066 breakpoints around them as it usualy does. This makes it
1067 pretty slow, but at least it doesn't fail.
1069 We can fix this with a fairly big change to bfd, but we need
1070 to coordinate better with Cygnus if we want to do that. FIXME. */
1072 last_function_name
= NULL
;
1075 /* this test will be true if the last .o file is only data */
1076 if (pst
->textlow
== 0)
1077 pst
->textlow
= pst
->texthigh
;
1079 /* If we know our own starting text address, then walk through all other
1080 psymtabs for this objfile, and if any didn't know their ending text
1081 address, set it to our starting address. Take care to not set our
1082 own ending address to our starting address, nor to set addresses on
1083 `dependency' files that have both textlow and texthigh zero. */
1086 ALL_OBJFILE_PSYMTABS (objfile
, p1
)
1088 if (p1
->texthigh
== 0 && p1
->textlow
!= 0 && p1
!= pst
)
1090 p1
->texthigh
= pst
->textlow
;
1091 /* if this file has only data, then make textlow match texthigh */
1092 if (p1
->textlow
== 0)
1093 p1
->textlow
= p1
->texthigh
;
1098 /* End of kludge for patching Solaris textlow and texthigh. */
1100 pst
->n_global_syms
=
1101 objfile
->global_psymbols
.next
- (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1102 pst
->n_static_syms
=
1103 objfile
->static_psymbols
.next
- (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1105 pst
->number_of_dependencies
= number_dependencies
;
1106 if (number_dependencies
)
1108 pst
->dependencies
= (struct partial_symtab
**)
1109 obstack_alloc (&objfile
->psymbol_obstack
,
1110 number_dependencies
* sizeof (struct partial_symtab
*));
1111 memcpy (pst
->dependencies
, dependency_list
,
1112 number_dependencies
* sizeof (struct partial_symtab
*));
1115 pst
->dependencies
= 0;
1117 for (i
= 0; i
< num_includes
; i
++)
1119 struct partial_symtab
*subpst
=
1120 allocate_psymtab (include_list
[i
], objfile
);
1122 subpst
->section_offsets
= pst
->section_offsets
;
1123 subpst
->read_symtab_private
=
1124 (char *) obstack_alloc (&objfile
->psymbol_obstack
,
1125 sizeof (struct symloc
));
1129 subpst
->texthigh
= 0;
1131 /* We could save slight bits of space by only making one of these,
1132 shared by the entire set of include files. FIXME-someday. */
1133 subpst
->dependencies
= (struct partial_symtab
**)
1134 obstack_alloc (&objfile
->psymbol_obstack
,
1135 sizeof (struct partial_symtab
*));
1136 subpst
->dependencies
[0] = pst
;
1137 subpst
->number_of_dependencies
= 1;
1139 subpst
->globals_offset
=
1140 subpst
->n_global_syms
=
1141 subpst
->statics_offset
=
1142 subpst
->n_static_syms
= 0;
1146 subpst
->read_symtab
= pst
->read_symtab
;
1149 sort_pst_symbols (pst
);
1151 /* If there is already a psymtab or symtab for a file of this name,
1153 (If there is a symtab, more drastic things also happen.)
1154 This happens in VxWorks. */
1155 free_named_symtabs (pst
->filename
);
1157 if (num_includes
== 0
1158 && number_dependencies
== 0
1159 && pst
->n_global_syms
== 0
1160 && pst
->n_static_syms
== 0)
1162 /* Throw away this psymtab, it's empty. We can't deallocate it, since
1163 it is on the obstack, but we can forget to chain it on the list. */
1164 /* Indicate that psymtab was thrown away. */
1166 discard_psymtab (pst
);
1168 pst
= (struct partial_symtab
*) NULL
;
1174 os9k_psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1176 struct cleanup
*old_chain
;
1184 fprintf_unfiltered (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1189 /* Read in all partial symtabs on which this one is dependent */
1190 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
1191 if (!pst
->dependencies
[i
]->readin
)
1193 /* Inform about additional files that need to be read in. */
1196 fputs_filtered (" ", gdb_stdout
);
1198 fputs_filtered ("and ", gdb_stdout
);
1200 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
1201 wrap_here (""); /* Flush output */
1202 gdb_flush (gdb_stdout
);
1204 os9k_psymtab_to_symtab_1 (pst
->dependencies
[i
]);
1207 if (LDSYMCNT (pst
)) /* Otherwise it's a dummy */
1209 /* Init stuff necessary for reading in symbols */
1212 old_chain
= make_cleanup (really_free_pendings
, 0);
1214 /* Read in this file's symbols */
1215 os9k_read_ofile_symtab (pst
);
1216 sort_symtab_syms (pst
->symtab
);
1217 do_cleanups (old_chain
);
1223 /* Read in all of the symbols for a given psymtab for real.
1224 Be verbose about it if the user wants that. */
1227 os9k_psymtab_to_symtab (struct partial_symtab
*pst
)
1236 fprintf_unfiltered (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1241 if (LDSYMCNT (pst
) || pst
->number_of_dependencies
)
1243 /* Print the message now, before reading the string table,
1244 to avoid disconcerting pauses. */
1247 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1248 gdb_flush (gdb_stdout
);
1251 sym_bfd
= pst
->objfile
->obfd
;
1252 os9k_psymtab_to_symtab_1 (pst
);
1254 /* Match with global symbols. This only needs to be done once,
1255 after all of the symtabs and dependencies have been read in. */
1256 scan_file_globals (pst
->objfile
);
1258 /* Finish up the debug error message. */
1260 printf_filtered ("done.\n");
1264 /* Read in a defined section of a specific object file's symbols. */
1266 os9k_read_ofile_symtab (struct partial_symtab
*pst
)
1268 register struct internal_symstruct
*bufp
;
1270 unsigned max_symnum
;
1272 struct objfile
*objfile
;
1273 int sym_offset
; /* Offset to start of symbols to read */
1274 CORE_ADDR text_offset
; /* Start of text segment for symbols */
1275 int text_size
; /* Size of text segment for symbols */
1278 objfile
= pst
->objfile
;
1279 sym_offset
= LDSYMOFF (pst
);
1280 max_symnum
= LDSYMCNT (pst
);
1281 text_offset
= pst
->textlow
;
1282 text_size
= pst
->texthigh
- pst
->textlow
;
1284 current_objfile
= objfile
;
1285 subfile_stack
= NULL
;
1286 last_source_file
= NULL
;
1288 abfd
= objfile
->obfd
;
1289 dbg_file
= objfile
->auxf2
;
1292 /* It is necessary to actually read one symbol *before* the start
1293 of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
1294 occurs before the N_SO symbol.
1295 Detecting this in read_dbx_symtab
1296 would slow down initial readin, so we look for it here instead. */
1297 if (!processing_acc_compilation
&& sym_offset
>= (int) symbol_size
)
1299 fseek (objefile
->auxf2
, sym_offset
, SEEK_CUR
);
1300 fill_sym (objfile
->auxf2
, abfd
);
1303 processing_gcc_compilation
= 0;
1304 if (bufp
->n_type
== N_TEXT
)
1306 if (STREQ (namestring
, GCC_COMPILED_FLAG_SYMBOL
))
1307 processing_gcc_compilation
= 1;
1308 else if (STREQ (namestring
, GCC2_COMPILED_FLAG_SYMBOL
))
1309 processing_gcc_compilation
= 2;
1312 /* Try to select a C++ demangling based on the compilation unit
1315 if (processing_gcc_compilation
)
1317 if (AUTO_DEMANGLING
)
1319 set_demangling_style (GNU_DEMANGLING_STYLE_STRING
);
1325 /* The N_SO starting this symtab is the first symbol, so we
1326 better not check the symbol before it. I'm not this can
1327 happen, but it doesn't hurt to check for it. */
1328 bfd_seek (symfile_bfd
, sym_offset
, SEEK_CUR
);
1329 processing_gcc_compilation
= 0;
1333 fseek (dbg_file
, (long) sym_offset
, 0);
1335 if (bufp->n_type != (unsigned char)N_SYM_SYM)
1336 error("First symbol in segment of executable not a source symbol");
1339 for (symnum
= 0; symnum
< max_symnum
; symnum
++)
1341 QUIT
; /* Allow this to be interruptable */
1342 fill_sym (dbg_file
, abfd
);
1344 type
= bufp
->n_type
;
1346 os9k_process_one_symbol ((int) type
, (int) bufp
->n_desc
,
1347 (CORE_ADDR
) bufp
->n_value
, bufp
->n_strx
, pst
->section_offsets
, objfile
);
1349 /* We skip checking for a new .o or -l file; that should never
1350 happen in this routine. */
1355 /* I don't think this code will ever be executed, because
1356 the GCC_COMPILED_FLAG_SYMBOL usually is right before
1357 the N_SO symbol which starts this source file.
1358 However, there is no reason not to accept
1359 the GCC_COMPILED_FLAG_SYMBOL anywhere. */
1361 if (STREQ (namestring
, GCC_COMPILED_FLAG_SYMBOL
))
1362 processing_gcc_compilation
= 1;
1363 else if (STREQ (namestring
, GCC2_COMPILED_FLAG_SYMBOL
))
1364 processing_gcc_compilation
= 2;
1366 if (AUTO_DEMANGLING
)
1368 set_demangling_style (GNU_DEMANGLING_STYLE_STRING
);
1371 else if (type
& N_EXT
|| type
== (unsigned char) N_TEXT
1372 || type
== (unsigned char) N_NBTEXT
1375 /* Global symbol: see if we came across a dbx defintion for
1376 a corresponding symbol. If so, store the value. Remove
1377 syms from the chain when their values are stored, but
1378 search the whole chain, as there may be several syms from
1379 different files with the same name. */
1380 /* This is probably not true. Since the files will be read
1381 in one at a time, each reference to a global symbol will
1382 be satisfied in each file as it appears. So we skip this
1389 current_objfile
= NULL
;
1391 /* In a Solaris elf file, this variable, which comes from the
1392 value of the N_SO symbol, will still be 0. Luckily, text_offset,
1393 which comes from pst->textlow is correct. */
1394 if (last_source_start_addr
== 0)
1395 last_source_start_addr
= text_offset
;
1396 pst
->symtab
= end_symtab (text_offset
+ text_size
, objfile
, SECT_OFF_TEXT (objfile
));
1401 /* This handles a single symbol from the symbol-file, building symbols
1402 into a GDB symtab. It takes these arguments and an implicit argument.
1404 TYPE is the type field of the ".stab" symbol entry.
1405 DESC is the desc field of the ".stab" entry.
1406 VALU is the value field of the ".stab" entry.
1407 NAME is the symbol name, in our address space.
1408 SECTION_OFFSETS is a set of amounts by which the sections of this object
1409 file were relocated when it was loaded into memory.
1410 All symbols that refer
1411 to memory locations need to be offset by these amounts.
1412 OBJFILE is the object file from which we are reading symbols.
1413 It is used in end_symtab. */
1416 os9k_process_one_symbol (int type
, int desc
, CORE_ADDR valu
, char *name
,
1417 struct section_offsets
*section_offsets
,
1418 struct objfile
*objfile
)
1420 register struct context_stack
*new;
1421 /* The stab type used for the definition of the last function.
1422 N_STSYM or N_GSYM for SunOS4 acc; N_FUN for other compilers. */
1423 static int function_stab_type
= 0;
1426 /* Something is wrong if we see real data before
1427 seeing a source file name. */
1428 if (last_source_file
== NULL
&& type
!= (unsigned char) N_SO
)
1430 /* Ignore any symbols which appear before an N_SO symbol.
1431 Currently no one puts symbols there, but we should deal
1432 gracefully with the case. A complain()t might be in order,
1433 but this should not be an error (). */
1441 /* On most machines, the block addresses are relative to the
1442 N_SO, the linker did not relocate them (sigh). */
1443 valu
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
1444 new = push_context (desc
, valu
);
1448 valu
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
1449 new = pop_context ();
1451 #if !defined (OS9K_VARIABLES_INSIDE_BLOCK)
1452 #define OS9K_VARIABLES_INSIDE_BLOCK(desc, gcc_p) 1
1455 if (!OS9K_VARIABLES_INSIDE_BLOCK (desc
, processing_gcc_compilation
))
1456 local_symbols
= new->locals
;
1458 if (context_stack_depth
> 1)
1460 /* This is not the outermost LBRAC...RBRAC pair in the function,
1461 its local symbols preceded it, and are the ones just recovered
1462 from the context stack. Define the block for them (but don't
1463 bother if the block contains no symbols. Should we complain
1464 on blocks without symbols? I can't think of any useful purpose
1466 if (local_symbols
!= NULL
)
1468 /* Muzzle a compiler bug that makes end < start. (which
1469 compilers? Is this ever harmful?). */
1470 if (new->start_addr
> valu
)
1472 complain (&lbrac_rbrac_complaint
);
1473 new->start_addr
= valu
;
1475 /* Make a block for the local symbols within. */
1476 finish_block (0, &local_symbols
, new->old_blocks
,
1477 new->start_addr
, valu
, objfile
);
1482 if (context_stack_depth
== 0)
1484 within_function
= 0;
1485 /* Make a block for the local symbols within. */
1486 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1487 new->start_addr
, valu
, objfile
);
1491 /* attach local_symbols to the end of new->locals */
1493 new->locals
= local_symbols
;
1501 p
->next
= local_symbols
;
1506 if (OS9K_VARIABLES_INSIDE_BLOCK (desc
, processing_gcc_compilation
))
1507 /* Now pop locals of block just finished. */
1508 local_symbols
= new->locals
;
1513 /* This type of "symbol" really just records
1514 one line-number -- core-address correspondence.
1515 Enter it in the line list for this symbol table. */
1516 /* Relocate for dynamic loading and for ELF acc fn-relative syms. */
1517 valu
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
1518 /* FIXME: loses if sizeof (char *) > sizeof (int) */
1519 record_line (current_subfile
, (int) name
, valu
);
1522 /* The following symbol types need to have the appropriate offset added
1523 to their value; then we process symbol definitions in the name. */
1530 char *p
= strchr (name
, ':');
1540 valu
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
1541 n
= strrchr (name
, '/');
1554 if (symfile_depth
++ == 0)
1556 if (last_source_file
)
1558 end_symtab (valu
, objfile
, SECT_OFF_TEXT (objfile
));
1563 start_symtab (n
, dirn
, valu
);
1564 record_debugformat ("OS9");
1569 start_subfile (n
, dirn
!= NULL
? dirn
: current_subfile
->dirname
);
1575 valu
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
1576 function_stab_type
= type
;
1578 within_function
= 1;
1579 new = push_context (0, valu
);
1580 new->name
= define_symbol (valu
, name
, desc
, type
, objfile
);
1585 valu
+= ANOFFSET (section_offsets
, SECT_OFF_DATA (objfile
));
1586 define_symbol (valu
, name
, desc
, type
, objfile
);
1590 define_symbol (valu
, name
, desc
, type
, objfile
);
1597 if (--symfile_depth
!= 0)
1598 start_subfile (pop_subfile (), current_subfile
->dirname
);
1602 complain (&unknown_symtype_complaint
,
1603 local_hex_string ((unsigned long) type
));
1610 previous_stab_code
= type
;
1613 static struct sym_fns os9k_sym_fns
=
1615 bfd_target_os9k_flavour
,
1616 os9k_new_init
, /* sym_new_init: init anything gbl to entire symtab */
1617 os9k_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
1618 os9k_symfile_read
, /* sym_read: read a symbol file into symtab */
1619 os9k_symfile_finish
, /* sym_finish: finished with file, cleanup */
1620 default_symfile_offsets
, /* sym_offsets: parse user's offsets to internal form */
1621 NULL
/* next: pointer to next struct sym_fns */
1625 _initialize_os9kread (void)
1627 add_symtab_fns (&os9k_sym_fns
);