import gdb-1999-05-25 snapshot
[deliverable/binutils-gdb.git] / gdb / os9kread.c
CommitLineData
c906108c
SS
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.
4
5This file is part of GDB.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
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
25 from a file.
26
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 */
34
35#include "defs.h"
36#include "gdb_string.h"
37#include <stdio.h>
38
39#if defined(USG) || defined(__CYGNUSCLIB__)
40#include <sys/types.h>
41#include <fcntl.h>
42#endif
43
44#include "obstack.h"
45#include "gdb_stat.h"
46#include <ctype.h>
47#include "symtab.h"
48#include "breakpoint.h"
49#include "command.h"
50#include "target.h"
51#include "gdbcore.h" /* for bfd stuff */
52#include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
53#include "symfile.h"
54#include "objfiles.h"
55#include "buildsym.h"
56#include "gdb-stabs.h"
57#include "demangle.h"
58#include "language.h" /* Needed inside partial-stab.h */
59#include "complaints.h"
60#include "os9k.h"
61#include "stabsread.h"
62
392a587b
JM
63extern void _initialize_os9kread PARAMS ((void));
64
c906108c
SS
65/* Each partial symbol table entry contains a pointer to private data for the
66 read_symtab() function to use when expanding a partial symbol table entry
67 to a full symbol table entry.
68
69 For dbxread this structure contains the offset within the file symbol table
70 of first local symbol for this file, and count of the section
71 of the symbol table devoted to this file's symbols (actually, the section
72 bracketed may contain more than just this file's symbols). It also contains
73 further information needed to locate the symbols if they are in an ELF file.
74
75 If ldsymcnt is 0, the only reason for this thing's existence is the
76 dependency list. Nothing else will happen when it is read in. */
77
78#define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
79#define LDSYMCNT(p) (((struct symloc *)((p)->read_symtab_private))->ldsymnum)
80
81struct symloc {
82 int ldsymoff;
83 int ldsymnum;
84};
85
86/* Remember what we deduced to be the source language of this psymtab. */
87static enum language psymtab_language = language_unknown;
88
89/* keep partial symbol table file nested depth */
90static int psymfile_depth = 0;
91
92/* keep symbol table file nested depth */
93static int symfile_depth = 0;
94
95/* Nonzero means give verbose info on gdb action. From main.c. */
96extern int info_verbose;
97
98extern int previous_stab_code;
99
100/* Name of last function encountered. Used in Solaris to approximate
101 object file boundaries. */
102static char *last_function_name;
103
104/* Complaints about the symbols we have encountered. */
105extern struct complaint lbrac_complaint;
106
107extern struct complaint unknown_symtype_complaint;
108
109extern struct complaint unknown_symchar_complaint;
110
111extern struct complaint lbrac_rbrac_complaint;
112
113extern struct complaint repeated_header_complaint;
114
115extern struct complaint repeated_header_name_complaint;
116
117#if 0
118static struct complaint lbrac_unmatched_complaint =
119 {"unmatched Increment Block Entry before symtab pos %d", 0, 0};
120
121static struct complaint lbrac_mismatch_complaint =
122 {"IBE/IDE symbol mismatch at symtab pos %d", 0, 0};
123#endif
124\f
125/* Local function prototypes */
126
127static void
128read_minimal_symbols PARAMS ((struct objfile *, struct section_offsets *));
129
130static void
131os9k_read_ofile_symtab PARAMS ((struct partial_symtab *));
132
133static void
134os9k_psymtab_to_symtab PARAMS ((struct partial_symtab *));
135
136static void
137os9k_psymtab_to_symtab_1 PARAMS ((struct partial_symtab *));
138
139static void
140read_os9k_psymtab PARAMS ((struct section_offsets *, struct objfile *,
141 CORE_ADDR, int));
142
143static int
144fill_sym PARAMS ((FILE *, bfd *));
145
146static void
147os9k_symfile_init PARAMS ((struct objfile *));
148
149static void
150os9k_new_init PARAMS ((struct objfile *));
151
152static void
153os9k_symfile_read PARAMS ((struct objfile *, struct section_offsets *, int));
154
155static void
156os9k_symfile_finish PARAMS ((struct objfile *));
157
158static void
159os9k_process_one_symbol PARAMS ((int, int, CORE_ADDR, char *,
160 struct section_offsets *, struct objfile *));
161
162static struct partial_symtab *
163os9k_start_psymtab PARAMS ((struct objfile *, struct section_offsets *, char *,
164 CORE_ADDR, int, int, struct partial_symbol **,
165 struct partial_symbol **));
166
167static struct partial_symtab *
168os9k_end_psymtab PARAMS ((struct partial_symtab *, char **, int, int, CORE_ADDR,
169 struct partial_symtab **, int));
170
171static void
172record_minimal_symbol PARAMS ((char *, CORE_ADDR, int, struct objfile *,
173 struct section_offsets *));
174\f
175#define HANDLE_RBRAC(val) \
176 if ((val) > pst->texthigh) pst->texthigh = (val);
177
178#define SWAP_STBHDR(hdrp, abfd) \
179 { \
180 (hdrp)->fmtno = bfd_get_16(abfd, (unsigned char *)&(hdrp)->fmtno); \
181 (hdrp)->crc = bfd_get_32(abfd, (unsigned char *)&(hdrp)->crc); \
182 (hdrp)->offset = bfd_get_32(abfd, (unsigned char *)&(hdrp)->offset); \
183 (hdrp)->nsym = bfd_get_32(abfd, (unsigned char *)&(hdrp)->nsym); \
184 }
185#define SWAP_STBSYM(symp, abfd) \
186 { \
187 (symp)->value = bfd_get_32(abfd, (unsigned char *)&(symp)->value); \
188 (symp)->type = bfd_get_16(abfd, (unsigned char *)&(symp)->type); \
189 (symp)->stroff = bfd_get_32(abfd, (unsigned char *)&(symp)->stroff); \
190 }
191#define N_DATA 0
192#define N_BSS 1
193#define N_RDATA 2
194#define N_IDATA 3
195#define N_TEXT 4
196#define N_ABS 6
197
198static void
199record_minimal_symbol (name, address, type, objfile, section_offsets)
200 char *name;
201 CORE_ADDR address;
202 int type;
203 struct objfile *objfile;
204 struct section_offsets *section_offsets;
205{
206 enum minimal_symbol_type ms_type;
207
208 switch (type)
209 {
210 case N_TEXT:
211 ms_type = mst_text;
212 address += ANOFFSET(section_offsets, SECT_OFF_TEXT);
213 break;
214 case N_DATA:
215 ms_type = mst_data;
216 break;
217 case N_BSS:
218 ms_type = mst_bss;
219 break;
220 case N_RDATA:
221 ms_type = mst_bss;
222 break;
223 case N_IDATA:
224 ms_type = mst_data;
225 break;
226 case N_ABS:
227 ms_type = mst_abs;
228 break;
229 default:
230 ms_type = mst_unknown; break;
231 }
232
233 prim_record_minimal_symbol (name, address, ms_type, objfile);
234}
235
236/* read and process .stb file and store in minimal symbol table */
237typedef char mhhdr[80];
238struct stbhdr {
239 mhhdr comhdr;
240 char * name;
241 short fmtno;
242 int crc;
243 int offset;
244 int nsym;
245 char *pad;
246};
247struct stbsymbol {
248 int value;
249 short type;
250 int stroff;
251};
252#define STBSYMSIZE 10
253
254static void
255read_minimal_symbols(objfile, section_offsets)
256 struct objfile *objfile;
257 struct section_offsets *section_offsets;
258{
259FILE *fp;
260bfd *abfd;
261struct stbhdr hdr;
262struct stbsymbol sym;
263int ch, i, j, off;
264char buf[64], buf1[128];
265
266 fp = objfile->auxf1;
267 if (fp == NULL) return;
268 abfd = objfile->obfd;
269 fread(&hdr.comhdr[0], sizeof(mhhdr), 1, fp);
270 i = 0;
271 ch = getc(fp);
272 while (ch != -1) {
273 buf[i] = (char)ch;
274 i++;
275 if (ch == 0) break;
276 ch = getc(fp);
277 };
278 if (i%2) ch=getc(fp);
279 hdr.name = &buf[0];
280
281 fread(&hdr.fmtno, sizeof(hdr.fmtno), 1, fp);
282 fread(&hdr.crc, sizeof(hdr.crc), 1, fp);
283 fread(&hdr.offset, sizeof(hdr.offset), 1, fp);
284 fread(&hdr.nsym, sizeof(hdr.nsym), 1, fp);
285 SWAP_STBHDR(&hdr, abfd);
286
287 /* read symbols */
288 init_minimal_symbol_collection();
289 off = hdr.offset;
290 for (i = hdr.nsym; i > 0; i--) {
291 fseek(fp, (long)off, 0);
292 fread(&sym.value, sizeof(sym.value), 1, fp);
293 fread(&sym.type, sizeof(sym.type), 1, fp);
294 fread(&sym.stroff, sizeof(sym.stroff), 1, fp);
295 SWAP_STBSYM (&sym, abfd);
296 fseek(fp, (long)sym.stroff, 0);
297 j = 0;
298 ch = getc(fp);
299 while (ch != -1) {
300 buf1[j] = (char)ch;
301 j++;
302 if (ch == 0) break;
303 ch = getc(fp);
304 };
305 record_minimal_symbol(buf1, sym.value, sym.type&7, objfile, section_offsets);
306 off += STBSYMSIZE;
307 };
308 install_minimal_symbols (objfile);
309 return;
310}
311\f
312/* Scan and build partial symbols for a symbol file.
313 We have been initialized by a call to os9k_symfile_init, which
314 put all the relevant info into a "struct os9k_symfile_info",
315 hung off the objfile structure.
316
317 SECTION_OFFSETS contains offsets relative to which the symbols in the
318 various sections are (depending where the sections were actually loaded).
319 MAINLINE is true if we are reading the main symbol
320 table (as opposed to a shared lib or dynamically loaded file). */
321
322static void
323os9k_symfile_read (objfile, section_offsets, mainline)
324 struct objfile *objfile;
325 struct section_offsets *section_offsets;
326 int mainline; /* FIXME comments above */
327{
328 bfd *sym_bfd;
329 struct cleanup *back_to;
330
331 sym_bfd = objfile->obfd;
332 /* If we are reinitializing, or if we have never loaded syms yet, init */
333 if (mainline || objfile->global_psymbols.size == 0 ||
334 objfile->static_psymbols.size == 0)
335 init_psymbol_list (objfile, DBX_SYMCOUNT (objfile));
336
337 free_pending_blocks ();
338 back_to = make_cleanup ((make_cleanup_func) really_free_pendings, 0);
339
340 make_cleanup ((make_cleanup_func) discard_minimal_symbols, 0);
341 read_minimal_symbols (objfile, section_offsets);
342
343 /* Now that the symbol table data of the executable file are all in core,
344 process them and define symbols accordingly. */
345 read_os9k_psymtab (section_offsets, objfile,
346 DBX_TEXT_ADDR (objfile),
347 DBX_TEXT_SIZE (objfile));
348
349 do_cleanups (back_to);
350}
351
352/* Initialize anything that needs initializing when a completely new
353 symbol file is specified (not just adding some symbols from another
354 file, e.g. a shared library). */
355
356static void
357os9k_new_init (ignore)
358 struct objfile *ignore;
359{
360 stabsread_new_init ();
361 buildsym_new_init ();
362 psymfile_depth = 0;
363/*
364 init_header_files ();
365*/
366}
367
368/* os9k_symfile_init ()
369 It is passed a struct objfile which contains, among other things,
370 the BFD for the file whose symbols are being read, and a slot for a pointer
371 to "private data" which we fill with goodies.
372
373 Since BFD doesn't know how to read debug symbols in a format-independent
374 way (and may never do so...), we have to do it ourselves. We will never
375 be called unless this is an a.out (or very similar) file.
376 FIXME, there should be a cleaner peephole into the BFD environment here. */
377
378static void
379os9k_symfile_init (objfile)
380 struct objfile *objfile;
381{
382 bfd *sym_bfd = objfile->obfd;
383 char *name = bfd_get_filename (sym_bfd);
384 char dbgname[512], stbname[512];
385 FILE *symfile = 0;
386 FILE *minfile = 0;
387 asection *text_sect;
388
389 strcpy(dbgname, name);
390 strcat(dbgname, ".dbg");
391 strcpy(stbname, name);
392 strcat(stbname, ".stb");
393
394 if ((symfile = fopen(dbgname, "r")) == NULL) {
395 warning("Symbol file %s not found", dbgname);
396 }
397 objfile->auxf2 = symfile;
398
399 if ((minfile = fopen(stbname, "r")) == NULL) {
400 warning("Symbol file %s not found", stbname);
401 }
402 objfile->auxf1 = minfile;
403
404 /* Allocate struct to keep track of the symfile */
405 objfile->sym_stab_info = (struct dbx_symfile_info *)
406 xmmalloc (objfile -> md, sizeof (struct dbx_symfile_info));
407 DBX_SYMFILE_INFO (objfile)->stab_section_info = NULL;
408
409 text_sect = bfd_get_section_by_name (sym_bfd, ".text");
410 if (!text_sect)
411 error ("Can't find .text section in file");
412 DBX_TEXT_ADDR (objfile) = bfd_section_vma (sym_bfd, text_sect);
413 DBX_TEXT_SIZE (objfile) = bfd_section_size (sym_bfd, text_sect);
414
415 DBX_SYMBOL_SIZE (objfile) = 0; /* variable size symbol */
416 DBX_SYMCOUNT (objfile) = 0; /* used to be bfd_get_symcount(sym_bfd) */
417 DBX_SYMTAB_OFFSET (objfile) = 0; /* used to be SYMBOL_TABLE_OFFSET */
418}
419
420/* Perform any local cleanups required when we are done with a particular
421 objfile. I.E, we are in the process of discarding all symbol information
422 for an objfile, freeing up all memory held for it, and unlinking the
423 objfile struct from the global list of known objfiles. */
424
425static void
426os9k_symfile_finish (objfile)
427 struct objfile *objfile;
428{
429 if (objfile->sym_stab_info != NULL)
430 {
431 mfree (objfile -> md, objfile->sym_stab_info);
432 }
433/*
434 free_header_files ();
435*/
436}
437
438\f
439struct st_dbghdr {
440 int sync;
441 short rev;
442 int crc;
443 short os;
444 short cpu;
445};
446#define SYNC (int)0xefbefeca
447
448#define SWAP_DBGHDR(hdrp, abfd) \
449 { \
450 (hdrp)->sync = bfd_get_32(abfd, (unsigned char *)&(hdrp)->sync); \
451 (hdrp)->rev = bfd_get_16(abfd, (unsigned char *)&(hdrp)->rev); \
452 (hdrp)->crc = bfd_get_32(abfd, (unsigned char *)&(hdrp)->crc); \
453 (hdrp)->os = bfd_get_16(abfd, (unsigned char *)&(hdrp)->os); \
454 (hdrp)->cpu = bfd_get_16(abfd, (unsigned char *)&(hdrp)->cpu); \
455 }
456
457#define N_SYM_CMPLR 0
458#define N_SYM_SLINE 1
459#define N_SYM_SYM 2
460#define N_SYM_LBRAC 3
461#define N_SYM_RBRAC 4
462#define N_SYM_SE 5
463
464struct internal_symstruct {
465 short n_type;
466 short n_desc;
467 long n_value;
468 char * n_strx;
469};
470static struct internal_symstruct symbol;
471static struct internal_symstruct *symbuf = &symbol;
472static char strbuf[4096];
473static struct st_dbghdr dbghdr;
474static short cmplrid;
475
476#define VER_PRE_ULTRAC ((short)4)
477#define VER_ULTRAC ((short)5)
478
479static int
480fill_sym (dbg_file, abfd)
481 FILE *dbg_file;
482 bfd *abfd;
483{
484short si, nmask;
485long li;
486int ii;
487char *p;
488
489 int nbytes = fread(&si, sizeof(si), 1, dbg_file);
490 if (nbytes == 0)
491 return 0;
492 if (nbytes < 0)
493 perror_with_name ("reading .dbg file.");
494 symbuf->n_desc = 0;
495 symbuf->n_value = 0;
496 symbuf->n_strx = NULL;
497 symbuf->n_type = bfd_get_16 (abfd, (unsigned char *)&si);
498 symbuf->n_type = 0xf & symbuf->n_type;
499 switch (symbuf->n_type)
500 {
501 case N_SYM_CMPLR:
502 fread(&si, sizeof(si), 1, dbg_file);
503 symbuf->n_desc = bfd_get_16(abfd, (unsigned char *)&si);
504 cmplrid = symbuf->n_desc & 0xff;
505 break;
506 case N_SYM_SLINE:
507 fread(&li, sizeof(li), 1, dbg_file);
508 symbuf->n_value = bfd_get_32(abfd, (unsigned char *)&li);
509 fread(&li, sizeof(li), 1, dbg_file);
510 li = bfd_get_32(abfd, (unsigned char *)&li);
511 symbuf->n_strx = (char *)(li >> 12);
512 symbuf->n_desc = li & 0xfff;
513 break;
514 case N_SYM_SYM:
515 fread(&li, sizeof(li), 1, dbg_file);
516 symbuf->n_value = bfd_get_32(abfd, (unsigned char *)&li);
517 si = 0;
518 do {
519 ii = getc(dbg_file);
520 strbuf[si++] = (char) ii;
521 } while (ii != 0 || si % 2 != 0);
522 symbuf->n_strx = strbuf;
523 p = (char *) strchr (strbuf, ':');
524 if (!p) break;
525 if ((p[1] == 'F' || p[1] == 'f') && cmplrid == VER_PRE_ULTRAC)
526 {
527 fread(&si, sizeof(si), 1, dbg_file);
528 nmask = bfd_get_16(abfd, (unsigned char *)&si);
529 for (ii=0; ii<nmask; ii++)
530 fread(&si, sizeof(si), 1, dbg_file);
531 }
532 break;
533 case N_SYM_LBRAC:
534 fread(&li, sizeof(li), 1, dbg_file);
535 symbuf->n_value = bfd_get_32(abfd, (unsigned char *)&li);
536 break;
537 case N_SYM_RBRAC:
538 fread(&li, sizeof(li), 1, dbg_file);
539 symbuf->n_value = bfd_get_32(abfd, (unsigned char *)&li);
540 break;
541 case N_SYM_SE:
542 break;
543 }
544 return 1;
545}
546\f
547/* Given pointers to an a.out symbol table in core containing dbx
548 style data, setup partial_symtab's describing each source file for
549 which debugging information is available.
550 SYMFILE_NAME is the name of the file we are reading from
551 and SECTION_OFFSETS is the set of offsets for the various sections
552 of the file (a set of zeros if the mainline program). */
553
554static void
555read_os9k_psymtab (section_offsets, objfile, text_addr, text_size)
556 struct section_offsets *section_offsets;
557 struct objfile *objfile;
558 CORE_ADDR text_addr;
559 int text_size;
560{
561 register struct internal_symstruct *bufp = 0; /* =0 avoids gcc -Wall glitch*/
562 register char *namestring;
563 int past_first_source_file = 0;
564 CORE_ADDR last_o_file_start = 0;
565#if 0
566 struct cleanup *back_to;
567#endif
568 bfd *abfd;
569 FILE *fp;
570
571 /* End of the text segment of the executable file. */
572 static CORE_ADDR end_of_text_addr;
573
574 /* Current partial symtab */
575 static struct partial_symtab *pst = 0;
576
577 /* List of current psymtab's include files */
578 char **psymtab_include_list;
579 int includes_allocated;
580 int includes_used;
581
582 /* Index within current psymtab dependency list */
583 struct partial_symtab **dependency_list;
584 int dependencies_used, dependencies_allocated;
585
586 includes_allocated = 30;
587 includes_used = 0;
588 psymtab_include_list = (char **) alloca (includes_allocated *
589 sizeof (char *));
590
591 dependencies_allocated = 30;
592 dependencies_used = 0;
593 dependency_list =
594 (struct partial_symtab **) alloca (dependencies_allocated *
595 sizeof (struct partial_symtab *));
596
597 last_source_file = NULL;
598
599#ifdef END_OF_TEXT_DEFAULT
600 end_of_text_addr = END_OF_TEXT_DEFAULT;
601#else
602 end_of_text_addr = text_addr + section_offsets->offsets[SECT_OFF_TEXT]
603 + text_size; /* Relocate */
604#endif
605
606 abfd = objfile->obfd;
607 fp = objfile->auxf2;
608 if (!fp) return;
609
610 fread(&dbghdr.sync, sizeof(dbghdr.sync), 1, fp);
611 fread(&dbghdr.rev, sizeof(dbghdr.rev), 1, fp);
612 fread(&dbghdr.crc, sizeof(dbghdr.crc), 1, fp);
613 fread(&dbghdr.os, sizeof(dbghdr.os), 1, fp);
614 fread(&dbghdr.cpu, sizeof(dbghdr.cpu), 1, fp);
615 SWAP_DBGHDR(&dbghdr, abfd);
616
617 symnum = 0;
618 while(1)
619 {
620 int ret;
621 long cursymoffset;
622
623 /* Get the symbol for this run and pull out some info */
624 QUIT; /* allow this to be interruptable */
625 cursymoffset = ftell(objfile->auxf2);
626 ret = fill_sym(objfile->auxf2, abfd);
627 if (ret <= 0) break;
628 else symnum++;
629 bufp = symbuf;
630
631 /* Special case to speed up readin. */
632 if (bufp->n_type == (short)N_SYM_SLINE) continue;
633
634#define CUR_SYMBOL_VALUE bufp->n_value
635 /* partial-stab.h */
636
637 switch (bufp->n_type)
638 {
639 char *p;
640
641 case N_SYM_CMPLR:
642 continue;
643
644 case N_SYM_SE:
645 CUR_SYMBOL_VALUE += ANOFFSET(section_offsets, SECT_OFF_TEXT);
646 if (psymfile_depth == 1 && pst)
647 {
648 os9k_end_psymtab (pst, psymtab_include_list, includes_used,
649 symnum, CUR_SYMBOL_VALUE,
650 dependency_list, dependencies_used);
651 pst = (struct partial_symtab *) 0;
652 includes_used = 0;
653 dependencies_used = 0;
654 }
655 psymfile_depth--;
656 continue;
657
658 case N_SYM_SYM: /* Typedef or automatic variable. */
659 namestring = bufp->n_strx;
660 p = (char *) strchr (namestring, ':');
661 if (!p)
662 continue; /* Not a debugging symbol. */
663
664 /* Main processing section for debugging symbols which
665 the initial read through the symbol tables needs to worry
666 about. If we reach this point, the symbol which we are
667 considering is definitely one we are interested in.
668 p must also contain the (valid) index into the namestring
669 which indicates the debugging type symbol. */
670
671 switch (p[1])
672 {
673 case 'S' :
674 {
675 unsigned long valu;
676 enum language tmp_language;
677 char *str, *p;
678 int n;
679
680 valu = CUR_SYMBOL_VALUE;
681 if (valu)
682 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
683 past_first_source_file = 1;
684
685 p = strchr(namestring, ':');
686 if (p) n = p-namestring;
687 else n = strlen(namestring);
688 str = alloca(n+1);
689 strncpy(str, namestring, n);
690 str[n] = '\0';
691
692 if (psymfile_depth == 0) {
693 if (!pst)
694 pst = os9k_start_psymtab (objfile, section_offsets,
695 str, valu,
696 cursymoffset,
697 symnum-1,
698 objfile -> global_psymbols.next,
699 objfile -> static_psymbols.next);
700 } else { /* this is a include file */
701 tmp_language = deduce_language_from_filename (str);
702 if (tmp_language != language_unknown
703 && (tmp_language != language_c
704 || psymtab_language != language_cplus))
705 psymtab_language = tmp_language;
706
707/*
708 if (pst && STREQ (str, pst->filename))
709 continue;
710 {
711 register int i;
712 for (i = 0; i < includes_used; i++)
713 if (STREQ (str, psymtab_include_list[i]))
714 {
715 i = -1;
716 break;
717 }
718 if (i == -1)
719 continue;
720 }
721*/
722
723 psymtab_include_list[includes_used++] = str;
724 if (includes_used >= includes_allocated)
725 {
726 char **orig = psymtab_include_list;
727
728 psymtab_include_list = (char **)
729 alloca ((includes_allocated *= 2) * sizeof (char *));
730 memcpy ((PTR)psymtab_include_list, (PTR)orig,
731 includes_used * sizeof (char *));
732 }
733
734 }
735 psymfile_depth++;
736 continue;
737 }
738
739 case 'v':
740 add_psymbol_to_list (namestring, p - namestring,
741 VAR_NAMESPACE, LOC_STATIC,
742 &objfile->static_psymbols,
743 0, CUR_SYMBOL_VALUE,
744 psymtab_language, objfile);
745 continue;
746 case 'V':
747 add_psymbol_to_list (namestring, p - namestring,
748 VAR_NAMESPACE, LOC_STATIC,
749 &objfile->global_psymbols,
750 0, CUR_SYMBOL_VALUE,
751 psymtab_language, objfile);
752 continue;
753
754 case 'T':
755 if (p != namestring) /* a name is there, not just :T... */
756 {
757 add_psymbol_to_list (namestring, p - namestring,
758 STRUCT_NAMESPACE, LOC_TYPEDEF,
759 &objfile->static_psymbols,
760 CUR_SYMBOL_VALUE, 0,
761 psymtab_language, objfile);
762 if (p[2] == 't')
763 {
764 /* Also a typedef with the same name. */
765 add_psymbol_to_list (namestring, p - namestring,
766 VAR_NAMESPACE, LOC_TYPEDEF,
767 &objfile->static_psymbols,
768 CUR_SYMBOL_VALUE, 0, psymtab_language,
769 objfile);
770 p += 1;
771 }
772 /* The semantics of C++ state that "struct foo { ... }"
773 also defines a typedef for "foo". Unfortuantely, cfront
774 never makes the typedef when translating from C++ to C.
775 We make the typedef here so that "ptype foo" works as
776 expected for cfront translated code. */
777 else if (psymtab_language == language_cplus)
778 {
779 /* Also a typedef with the same name. */
780 add_psymbol_to_list (namestring, p - namestring,
781 VAR_NAMESPACE, LOC_TYPEDEF,
782 &objfile->static_psymbols,
783 CUR_SYMBOL_VALUE, 0, psymtab_language,
784 objfile);
785 }
786 }
787 goto check_enum;
788 case 't':
789 if (p != namestring) /* a name is there, not just :T... */
790 {
791 add_psymbol_to_list (namestring, p - namestring,
792 VAR_NAMESPACE, LOC_TYPEDEF,
793 &objfile->static_psymbols,
794 CUR_SYMBOL_VALUE, 0,
795 psymtab_language, objfile);
796 }
797 check_enum:
798 /* If this is an enumerated type, we need to
799 add all the enum constants to the partial symbol
800 table. This does not cover enums without names, e.g.
801 "enum {a, b} c;" in C, but fortunately those are
802 rare. There is no way for GDB to find those from the
803 enum type without spending too much time on it. Thus
804 to solve this problem, the compiler needs to put out the
805 enum in a nameless type. GCC2 does this. */
806
807 /* We are looking for something of the form
808 <name> ":" ("t" | "T") [<number> "="] "e" <size>
809 {<constant> ":" <value> ","} ";". */
810
811 /* Skip over the colon and the 't' or 'T'. */
812 p += 2;
813 /* This type may be given a number. Also, numbers can come
814 in pairs like (0,26). Skip over it. */
815 while ((*p >= '0' && *p <= '9')
816 || *p == '(' || *p == ',' || *p == ')'
817 || *p == '=')
818 p++;
819
820 if (*p++ == 'e')
821 {
822 /* We have found an enumerated type. skip size */
823 while (*p >= '0' && *p <= '9') p++;
824 /* According to comments in read_enum_type
825 a comma could end it instead of a semicolon.
826 I don't know where that happens.
827 Accept either. */
828 while (*p && *p != ';' && *p != ',')
829 {
830 char *q;
831
832 /* Check for and handle cretinous dbx symbol name
833 continuation!
834 if (*p == '\\')
835 p = next_symbol_text (objfile);
836 */
837
838 /* Point to the character after the name
839 of the enum constant. */
840 for (q = p; *q && *q != ':'; q++)
841 ;
842 /* Note that the value doesn't matter for
843 enum constants in psymtabs, just in symtabs. */
844 add_psymbol_to_list (p, q - p,
845 VAR_NAMESPACE, LOC_CONST,
846 &objfile->static_psymbols, 0,
847 0, psymtab_language, objfile);
848 /* Point past the name. */
849 p = q;
850 /* Skip over the value. */
851 while (*p && *p != ',')
852 p++;
853 /* Advance past the comma. */
854 if (*p)
855 p++;
856 }
857 }
858 continue;
859 case 'c':
860 /* Constant, e.g. from "const" in Pascal. */
861 add_psymbol_to_list (namestring, p - namestring,
862 VAR_NAMESPACE, LOC_CONST,
863 &objfile->static_psymbols, CUR_SYMBOL_VALUE,
864 0, psymtab_language, objfile);
865 continue;
866
867 case 'f':
868 CUR_SYMBOL_VALUE += ANOFFSET(section_offsets, SECT_OFF_TEXT);
869 if (pst && pst->textlow == 0)
870 pst->textlow = CUR_SYMBOL_VALUE;
871
872 add_psymbol_to_list (namestring, p - namestring,
873 VAR_NAMESPACE, LOC_BLOCK,
874 &objfile->static_psymbols, CUR_SYMBOL_VALUE,
875 0, psymtab_language, objfile);
876 continue;
877
878 case 'F':
879 CUR_SYMBOL_VALUE += ANOFFSET(section_offsets, SECT_OFF_TEXT);
880 if (pst && pst->textlow == 0)
881 pst->textlow = CUR_SYMBOL_VALUE;
882
883 add_psymbol_to_list (namestring, p - namestring,
884 VAR_NAMESPACE, LOC_BLOCK,
885 &objfile->global_psymbols, CUR_SYMBOL_VALUE,
886 0, psymtab_language, objfile);
887 continue;
888
889 case 'p':
890 case 'l':
891 case 's':
892 continue;
893
894 case ':':
895 /* It is a C++ nested symbol. We don't need to record it
896 (I don't think); if we try to look up foo::bar::baz,
897 then symbols for the symtab containing foo should get
898 read in, I think. */
899 /* Someone says sun cc puts out symbols like
900 /foo/baz/maclib::/usr/local/bin/maclib,
901 which would get here with a symbol type of ':'. */
902 continue;
903
904 default:
905 /* Unexpected symbol descriptor. The second and subsequent stabs
906 of a continued stab can show up here. The question is
907 whether they ever can mimic a normal stab--it would be
908 nice if not, since we certainly don't want to spend the
909 time searching to the end of every string looking for
910 a backslash. */
911
912 complain (&unknown_symchar_complaint, p[1]);
913 continue;
914 }
915
916 case N_SYM_RBRAC:
917 CUR_SYMBOL_VALUE += ANOFFSET(section_offsets, SECT_OFF_TEXT);
918#ifdef HANDLE_RBRAC
919 HANDLE_RBRAC(CUR_SYMBOL_VALUE);
920 continue;
921#endif
922 case N_SYM_LBRAC:
923 continue;
924
925 default:
926 /* If we haven't found it yet, ignore it. It's probably some
927 new type we don't know about yet. */
928 complain (&unknown_symtype_complaint,
929 local_hex_string ((unsigned long) bufp->n_type));
930 continue;
931 }
932 }
933
934 DBX_SYMCOUNT (objfile) = symnum;
935
936 /* If there's stuff to be cleaned up, clean it up. */
937 if (DBX_SYMCOUNT (objfile) > 0
938/*FIXME, does this have a bug at start address 0? */
939 && last_o_file_start
940 && objfile -> ei.entry_point < bufp->n_value
941 && objfile -> ei.entry_point >= last_o_file_start)
942 {
943 objfile -> ei.entry_file_lowpc = last_o_file_start;
944 objfile -> ei.entry_file_highpc = bufp->n_value;
945 }
946
947 if (pst)
948 {
949 os9k_end_psymtab (pst, psymtab_include_list, includes_used,
950 symnum, end_of_text_addr,
951 dependency_list, dependencies_used);
952 }
953/*
954 do_cleanups (back_to);
955*/
956}
957
958/* Allocate and partially fill a partial symtab. It will be
959 completely filled at the end of the symbol list.
960
961 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
962 is the address relative to which its symbols are (incremental) or 0
963 (normal). */
964
965
966static struct partial_symtab *
967os9k_start_psymtab (objfile, section_offsets,
968 filename, textlow, ldsymoff,ldsymcnt, global_syms, static_syms)
969 struct objfile *objfile;
970 struct section_offsets *section_offsets;
971 char *filename;
972 CORE_ADDR textlow;
973 int ldsymoff;
974 int ldsymcnt;
975 struct partial_symbol **global_syms;
976 struct partial_symbol **static_syms;
977{
978 struct partial_symtab *result =
979 start_psymtab_common(objfile, section_offsets,
980 filename, textlow, global_syms, static_syms);
981
982 result->read_symtab_private = (char *)
983 obstack_alloc (&objfile -> psymbol_obstack, sizeof (struct symloc));
984
985 LDSYMOFF(result) = ldsymoff;
986 LDSYMCNT(result) = ldsymcnt;
987 result->read_symtab = os9k_psymtab_to_symtab;
988
989 /* Deduce the source language from the filename for this psymtab. */
990 psymtab_language = deduce_language_from_filename (filename);
991 return result;
992}
993
994/* Close off the current usage of PST.
995 Returns PST or NULL if the partial symtab was empty and thrown away.
996 FIXME: List variables and peculiarities of same. */
997
998static struct partial_symtab *
999os9k_end_psymtab (pst, include_list, num_includes, capping_symbol_cnt,
1000 capping_text, dependency_list, number_dependencies)
1001 struct partial_symtab *pst;
1002 char **include_list;
1003 int num_includes;
1004 int capping_symbol_cnt;
1005 CORE_ADDR capping_text;
1006 struct partial_symtab **dependency_list;
1007 int number_dependencies;
1008 /* struct partial_symbol *capping_global, *capping_static; */
1009{
1010 int i;
1011 struct partial_symtab *p1;
1012 struct objfile *objfile = pst -> objfile;
1013
1014 if (capping_symbol_cnt != -1)
1015 LDSYMCNT(pst) = capping_symbol_cnt - LDSYMCNT(pst);
1016
1017 /* Under Solaris, the N_SO symbols always have a value of 0,
1018 instead of the usual address of the .o file. Therefore,
1019 we have to do some tricks to fill in texthigh and textlow.
1020 The first trick is in partial-stab.h: if we see a static
1021 or global function, and the textlow for the current pst
1022 is still 0, then we use that function's address for
1023 the textlow of the pst.
1024
1025 Now, to fill in texthigh, we remember the last function seen
1026 in the .o file (also in partial-stab.h). Also, there's a hack in
1027 bfd/elf.c and gdb/elfread.c to pass the ELF st_size field
1028 to here via the misc_info field. Therefore, we can fill in
1029 a reliable texthigh by taking the address plus size of the
1030 last function in the file.
1031
1032 Unfortunately, that does not cover the case where the last function
1033 in the file is static. See the paragraph below for more comments
1034 on this situation.
1035
1036 Finally, if we have a valid textlow for the current file, we run
1037 down the partial_symtab_list filling in previous texthighs that
1038 are still unknown. */
1039
1040 if (pst->texthigh == 0 && last_function_name) {
1041 char *p;
1042 int n;
1043 struct minimal_symbol *minsym;
1044
1045 p = strchr (last_function_name, ':');
1046 if (p == NULL)
1047 p = last_function_name;
1048 n = p - last_function_name;
1049 p = alloca (n + 1);
1050 strncpy (p, last_function_name, n);
1051 p[n] = 0;
1052
1053 minsym = lookup_minimal_symbol (p, NULL, objfile);
1054
1055 if (minsym) {
1056 pst->texthigh = SYMBOL_VALUE_ADDRESS(minsym)+(long)MSYMBOL_INFO(minsym);
1057 } else {
1058 /* This file ends with a static function, and it's
1059 difficult to imagine how hard it would be to track down
1060 the elf symbol. Luckily, most of the time no one will notice,
1061 since the next file will likely be compiled with -g, so
1062 the code below will copy the first fuction's start address
1063 back to our texthigh variable. (Also, if this file is the
1064 last one in a dynamically linked program, texthigh already
1065 has the right value.) If the next file isn't compiled
1066 with -g, then the last function in this file winds up owning
1067 all of the text space up to the next -g file, or the end (minus
1068 shared libraries). This only matters for single stepping,
1069 and even then it will still work, except that it will single
1070 step through all of the covered functions, instead of setting
1071 breakpoints around them as it usualy does. This makes it
1072 pretty slow, but at least it doesn't fail.
1073
1074 We can fix this with a fairly big change to bfd, but we need
1075 to coordinate better with Cygnus if we want to do that. FIXME. */
1076 }
1077 last_function_name = NULL;
1078 }
1079
1080 /* this test will be true if the last .o file is only data */
1081 if (pst->textlow == 0)
1082 pst->textlow = pst->texthigh;
1083
1084 /* If we know our own starting text address, then walk through all other
1085 psymtabs for this objfile, and if any didn't know their ending text
1086 address, set it to our starting address. Take care to not set our
1087 own ending address to our starting address, nor to set addresses on
1088 `dependency' files that have both textlow and texthigh zero. */
1089 if (pst->textlow) {
1090 ALL_OBJFILE_PSYMTABS (objfile, p1) {
1091 if (p1->texthigh == 0 && p1->textlow != 0 && p1 != pst) {
1092 p1->texthigh = pst->textlow;
1093 /* if this file has only data, then make textlow match texthigh */
1094 if (p1->textlow == 0)
1095 p1->textlow = p1->texthigh;
1096 }
1097 }
1098 }
1099
1100 /* End of kludge for patching Solaris textlow and texthigh. */
1101
1102 pst->n_global_syms =
1103 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
1104 pst->n_static_syms =
1105 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
1106
1107 pst->number_of_dependencies = number_dependencies;
1108 if (number_dependencies)
1109 {
1110 pst->dependencies = (struct partial_symtab **)
1111 obstack_alloc (&objfile->psymbol_obstack,
1112 number_dependencies * sizeof (struct partial_symtab *));
1113 memcpy (pst->dependencies, dependency_list,
1114 number_dependencies * sizeof (struct partial_symtab *));
1115 }
1116 else
1117 pst->dependencies = 0;
1118
1119 for (i = 0; i < num_includes; i++)
1120 {
1121 struct partial_symtab *subpst =
1122 allocate_psymtab (include_list[i], objfile);
1123
1124 subpst->section_offsets = pst->section_offsets;
1125 subpst->read_symtab_private =
1126 (char *) obstack_alloc (&objfile->psymbol_obstack,
1127 sizeof (struct symloc));
1128 LDSYMOFF(subpst) =
1129 LDSYMCNT(subpst) =
1130 subpst->textlow =
1131 subpst->texthigh = 0;
1132
1133 /* We could save slight bits of space by only making one of these,
1134 shared by the entire set of include files. FIXME-someday. */
1135 subpst->dependencies = (struct partial_symtab **)
1136 obstack_alloc (&objfile->psymbol_obstack,
1137 sizeof (struct partial_symtab *));
1138 subpst->dependencies[0] = pst;
1139 subpst->number_of_dependencies = 1;
1140
1141 subpst->globals_offset =
1142 subpst->n_global_syms =
1143 subpst->statics_offset =
1144 subpst->n_static_syms = 0;
1145
1146 subpst->readin = 0;
1147 subpst->symtab = 0;
1148 subpst->read_symtab = pst->read_symtab;
1149 }
1150
1151 sort_pst_symbols (pst);
1152
1153 /* If there is already a psymtab or symtab for a file of this name,
1154 remove it.
1155 (If there is a symtab, more drastic things also happen.)
1156 This happens in VxWorks. */
1157 free_named_symtabs (pst->filename);
1158
1159 if (num_includes == 0
1160 && number_dependencies == 0
1161 && pst->n_global_syms == 0
1162 && pst->n_static_syms == 0) {
1163 /* Throw away this psymtab, it's empty. We can't deallocate it, since
1164 it is on the obstack, but we can forget to chain it on the list. */
1165 /* Indicate that psymtab was thrown away. */
1166
1167 discard_psymtab (pst);
1168
1169 pst = (struct partial_symtab *)NULL;
1170 }
1171 return pst;
1172}
1173\f
1174static void
1175os9k_psymtab_to_symtab_1 (pst)
1176 struct partial_symtab *pst;
1177{
1178 struct cleanup *old_chain;
1179 int i;
1180
1181 if (!pst)
1182 return;
1183
1184 if (pst->readin)
1185 {
1186 fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1187 pst->filename);
1188 return;
1189 }
1190
1191 /* Read in all partial symtabs on which this one is dependent */
1192 for (i = 0; i < pst->number_of_dependencies; i++)
1193 if (!pst->dependencies[i]->readin)
1194 {
1195 /* Inform about additional files that need to be read in. */
1196 if (info_verbose)
1197 {
1198 fputs_filtered (" ", gdb_stdout);
1199 wrap_here ("");
1200 fputs_filtered ("and ", gdb_stdout);
1201 wrap_here ("");
1202 printf_filtered ("%s...", pst->dependencies[i]->filename);
1203 wrap_here (""); /* Flush output */
1204 gdb_flush (gdb_stdout);
1205 }
1206 os9k_psymtab_to_symtab_1 (pst->dependencies[i]);
1207 }
1208
1209 if (LDSYMCNT(pst)) /* Otherwise it's a dummy */
1210 {
1211 /* Init stuff necessary for reading in symbols */
1212 stabsread_init ();
1213 buildsym_init ();
1214 old_chain = make_cleanup ((make_cleanup_func) really_free_pendings, 0);
1215
1216 /* Read in this file's symbols */
1217 os9k_read_ofile_symtab (pst);
1218 sort_symtab_syms (pst->symtab);
1219 do_cleanups (old_chain);
1220 }
1221
1222 pst->readin = 1;
1223}
1224
1225/* Read in all of the symbols for a given psymtab for real.
1226 Be verbose about it if the user wants that. */
1227
1228static void
1229os9k_psymtab_to_symtab (pst)
1230 struct partial_symtab *pst;
1231{
1232 bfd *sym_bfd;
1233
1234 if (!pst)
1235 return;
1236
1237 if (pst->readin)
1238 {
1239 fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1240 pst->filename);
1241 return;
1242 }
1243
1244 if (LDSYMCNT(pst) || pst->number_of_dependencies)
1245 {
1246 /* Print the message now, before reading the string table,
1247 to avoid disconcerting pauses. */
1248 if (info_verbose)
1249 {
1250 printf_filtered ("Reading in symbols for %s...", pst->filename);
1251 gdb_flush (gdb_stdout);
1252 }
1253
1254 sym_bfd = pst->objfile->obfd;
1255 os9k_psymtab_to_symtab_1 (pst);
1256
1257 /* Match with global symbols. This only needs to be done once,
1258 after all of the symtabs and dependencies have been read in. */
1259 scan_file_globals (pst->objfile);
1260
1261 /* Finish up the debug error message. */
1262 if (info_verbose)
1263 printf_filtered ("done.\n");
1264 }
1265}
1266
1267/* Read in a defined section of a specific object file's symbols. */
1268static void
1269os9k_read_ofile_symtab (pst)
1270 struct partial_symtab *pst;
1271{
1272 register struct internal_symstruct *bufp;
1273 unsigned char type;
1274 unsigned max_symnum;
1275 register bfd *abfd;
1276 struct objfile *objfile;
1277 int sym_offset; /* Offset to start of symbols to read */
1278 CORE_ADDR text_offset; /* Start of text segment for symbols */
1279 int text_size; /* Size of text segment for symbols */
1280 struct section_offsets *section_offsets;
1281 FILE *dbg_file;
1282
1283 objfile = pst->objfile;
1284 sym_offset = LDSYMOFF(pst);
1285 max_symnum = LDSYMCNT(pst);
1286 text_offset = pst->textlow;
1287 text_size = pst->texthigh - pst->textlow;
1288 section_offsets = pst->section_offsets;
1289
1290 current_objfile = objfile;
1291 subfile_stack = NULL;
1292 last_source_file = NULL;
1293
1294 abfd = objfile->obfd;
1295 dbg_file = objfile->auxf2;
1296
1297#if 0
1298 /* It is necessary to actually read one symbol *before* the start
1299 of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
1300 occurs before the N_SO symbol.
1301 Detecting this in read_dbx_symtab
1302 would slow down initial readin, so we look for it here instead. */
1303 if (!processing_acc_compilation && sym_offset >= (int)symbol_size)
1304 {
1305 fseek (objefile->auxf2, sym_offset, SEEK_CUR);
1306 fill_sym(objfile->auxf2, abfd);
1307 bufp = symbuf;
1308
1309 processing_gcc_compilation = 0;
1310 if (bufp->n_type == N_TEXT)
1311 {
1312 if (STREQ (namestring, GCC_COMPILED_FLAG_SYMBOL))
1313 processing_gcc_compilation = 1;
1314 else if (STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL))
1315 processing_gcc_compilation = 2;
1316 }
1317
1318 /* Try to select a C++ demangling based on the compilation unit
1319 producer. */
1320
1321 if (processing_gcc_compilation)
1322 {
1323 if (AUTO_DEMANGLING)
1324 {
1325 set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
1326 }
1327 }
1328 }
1329 else
1330 {
1331 /* The N_SO starting this symtab is the first symbol, so we
1332 better not check the symbol before it. I'm not this can
1333 happen, but it doesn't hurt to check for it. */
1334 bfd_seek (symfile_bfd, sym_offset, SEEK_CUR);
1335 processing_gcc_compilation = 0;
1336 }
1337#endif /* 0 */
1338
1339 fseek(dbg_file, (long)sym_offset, 0);
1340/*
1341 if (bufp->n_type != (unsigned char)N_SYM_SYM)
1342 error("First symbol in segment of executable not a source symbol");
1343*/
1344
1345 for (symnum = 0; symnum < max_symnum; symnum++)
1346 {
1347 QUIT; /* Allow this to be interruptable */
1348 fill_sym(dbg_file, abfd);
1349 bufp = symbuf;
1350 type = bufp->n_type;
1351
1352 os9k_process_one_symbol ((int)type, (int)bufp->n_desc,
1353 (CORE_ADDR)bufp->n_value, bufp->n_strx, section_offsets, objfile);
1354
1355 /* We skip checking for a new .o or -l file; that should never
1356 happen in this routine. */
1357#if 0
1358 else if (type == N_TEXT)
1359 {
1360 /* I don't think this code will ever be executed, because
1361 the GCC_COMPILED_FLAG_SYMBOL usually is right before
1362 the N_SO symbol which starts this source file.
1363 However, there is no reason not to accept
1364 the GCC_COMPILED_FLAG_SYMBOL anywhere. */
1365
1366 if (STREQ (namestring, GCC_COMPILED_FLAG_SYMBOL))
1367 processing_gcc_compilation = 1;
1368 else if (STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL))
1369 processing_gcc_compilation = 2;
1370
1371 if (AUTO_DEMANGLING)
1372 {
1373 set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
1374 }
1375 }
1376 else if (type & N_EXT || type == (unsigned char)N_TEXT
1377 || type == (unsigned char)N_NBTEXT
1378 ) {
1379 /* Global symbol: see if we came across a dbx defintion for
1380 a corresponding symbol. If so, store the value. Remove
1381 syms from the chain when their values are stored, but
1382 search the whole chain, as there may be several syms from
1383 different files with the same name. */
1384 /* This is probably not true. Since the files will be read
1385 in one at a time, each reference to a global symbol will
1386 be satisfied in each file as it appears. So we skip this
1387 section. */
1388 ;
1389 }
1390#endif /* 0 */
1391 }
1392
1393 current_objfile = NULL;
1394
1395 /* In a Solaris elf file, this variable, which comes from the
1396 value of the N_SO symbol, will still be 0. Luckily, text_offset,
1397 which comes from pst->textlow is correct. */
1398 if (last_source_start_addr == 0)
1399 last_source_start_addr = text_offset;
1400 pst->symtab = end_symtab (text_offset + text_size, objfile, SECT_OFF_TEXT);
1401 end_stabs ();
1402}
1403
1404\f
1405/* This handles a single symbol from the symbol-file, building symbols
1406 into a GDB symtab. It takes these arguments and an implicit argument.
1407
1408 TYPE is the type field of the ".stab" symbol entry.
1409 DESC is the desc field of the ".stab" entry.
1410 VALU is the value field of the ".stab" entry.
1411 NAME is the symbol name, in our address space.
1412 SECTION_OFFSETS is a set of amounts by which the sections of this object
1413 file were relocated when it was loaded into memory.
1414 All symbols that refer
1415 to memory locations need to be offset by these amounts.
1416 OBJFILE is the object file from which we are reading symbols.
1417 It is used in end_symtab. */
1418
1419static void
1420os9k_process_one_symbol (type, desc, valu, name, section_offsets, objfile)
1421 int type, desc;
1422 CORE_ADDR valu;
1423 char *name;
1424 struct section_offsets *section_offsets;
1425 struct objfile *objfile;
1426{
1427 register struct context_stack *new;
1428 /* The stab type used for the definition of the last function.
1429 N_STSYM or N_GSYM for SunOS4 acc; N_FUN for other compilers. */
1430 static int function_stab_type = 0;
1431
1432#if 0
1433 /* Something is wrong if we see real data before
1434 seeing a source file name. */
1435 if (last_source_file == NULL && type != (unsigned char)N_SO)
1436 {
1437 /* Ignore any symbols which appear before an N_SO symbol.
1438 Currently no one puts symbols there, but we should deal
1439 gracefully with the case. A complain()t might be in order,
1440 but this should not be an error (). */
1441 return;
1442 }
1443#endif /* 0 */
1444
1445 switch (type)
1446 {
1447 case N_SYM_LBRAC:
1448 /* On most machines, the block addresses are relative to the
1449 N_SO, the linker did not relocate them (sigh). */
1450 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1451 new = push_context (desc, valu);
1452 break;
1453
1454 case N_SYM_RBRAC:
1455 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1456 new = pop_context();
1457
1458#if !defined (OS9K_VARIABLES_INSIDE_BLOCK)
1459#define OS9K_VARIABLES_INSIDE_BLOCK(desc, gcc_p) 1
1460#endif
1461
1462 if (!OS9K_VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation))
1463 local_symbols = new->locals;
1464
1465 if (context_stack_depth > 1)
1466 {
1467 /* This is not the outermost LBRAC...RBRAC pair in the function,
1468 its local symbols preceded it, and are the ones just recovered
1469 from the context stack. Define the block for them (but don't
1470 bother if the block contains no symbols. Should we complain
1471 on blocks without symbols? I can't think of any useful purpose
1472 for them). */
1473 if (local_symbols != NULL)
1474 {
1475 /* Muzzle a compiler bug that makes end < start. (which
1476 compilers? Is this ever harmful?). */
1477 if (new->start_addr > valu)
1478 {
1479 complain (&lbrac_rbrac_complaint);
1480 new->start_addr = valu;
1481 }
1482 /* Make a block for the local symbols within. */
1483 finish_block (0, &local_symbols, new->old_blocks,
1484 new->start_addr, valu, objfile);
1485 }
1486 }
1487 else
1488 {
1489 if (context_stack_depth == 0)
1490 {
1491 within_function = 0;
1492 /* Make a block for the local symbols within. */
1493 finish_block (new->name, &local_symbols, new->old_blocks,
1494 new->start_addr, valu, objfile);
1495 }
1496 else
1497 {
1498 /* attach local_symbols to the end of new->locals */
1499 if (!new->locals) new->locals = local_symbols;
1500 else {
1501 struct pending *p;
1502
1503 p = new->locals;
1504 while (p->next) p = p->next;
1505 p->next = local_symbols;
1506 }
1507 }
1508 }
1509
1510 if (OS9K_VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation))
1511 /* Now pop locals of block just finished. */
1512 local_symbols = new->locals;
1513 break;
1514
1515
1516 case N_SYM_SLINE:
1517 /* This type of "symbol" really just records
1518 one line-number -- core-address correspondence.
1519 Enter it in the line list for this symbol table. */
1520 /* Relocate for dynamic loading and for ELF acc fn-relative syms. */
1521 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1522 /* FIXME: loses if sizeof (char *) > sizeof (int) */
1523 record_line (current_subfile, (int)name, valu);
1524 break;
1525
1526 /* The following symbol types need to have the appropriate offset added
1527 to their value; then we process symbol definitions in the name. */
1528 case N_SYM_SYM:
1529
1530 if (name)
1531 {
1532 char deftype;
1533 char *dirn, *n;
1534 char *p = strchr (name, ':');
1535 if (p == NULL)
1536 deftype = '\0';
1537 else
1538 deftype = p[1];
1539
1540
1541 switch (deftype)
1542 {
1543 case 'S':
1544 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1545 n = strrchr(name, '/');
1546 if (n != NULL) {
1547 *n = '\0';
1548 n++;
1549 dirn = name;
1550 } else {
1551 n = name;
1552 dirn = NULL;
1553 }
1554 *p = '\0';
1555 if (symfile_depth++ == 0) {
1556 if (last_source_file) {
1557 end_symtab (valu, objfile, SECT_OFF_TEXT);
1558 end_stabs ();
1559 }
1560 start_stabs ();
1561 os9k_stabs = 1;
1562 start_symtab (n, dirn, valu);
1563 record_debugformat ("OS9");
1564 } else {
1565 push_subfile();
1566 start_subfile (n, dirn!=NULL ? dirn : current_subfile->dirname);
1567 }
1568 break;
1569
1570 case 'f':
1571 case 'F':
1572 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1573 function_stab_type = type;
1574
1575 within_function = 1;
1576 new = push_context (0, valu);
1577 new->name = define_symbol (valu, name, desc, type, objfile);
1578 break;
1579
1580 case 'V':
1581 case 'v':
1582 valu += ANOFFSET (section_offsets, SECT_OFF_DATA);
1583 define_symbol (valu, name, desc, type, objfile);
1584 break;
1585
1586 default:
1587 define_symbol (valu, name, desc, type, objfile);
1588 break;
1589 }
1590 }
1591 break;
1592
1593 case N_SYM_SE:
1594 if (--symfile_depth != 0)
1595 start_subfile(pop_subfile(), current_subfile->dirname);
1596 break;
1597
1598 default:
1599 complain (&unknown_symtype_complaint,
1600 local_hex_string((unsigned long) type));
1601 /* FALLTHROUGH */
1602 break;
1603
1604 case N_SYM_CMPLR:
1605 break;
1606 }
1607 previous_stab_code = type;
1608}
1609
1610static struct sym_fns os9k_sym_fns =
1611{
1612 bfd_target_os9k_flavour,
1613 os9k_new_init, /* sym_new_init: init anything gbl to entire symtab */
1614 os9k_symfile_init, /* sym_init: read initial info, setup for sym_read() */
1615 os9k_symfile_read, /* sym_read: read a symbol file into symtab */
1616 os9k_symfile_finish, /* sym_finish: finished with file, cleanup */
1617 default_symfile_offsets,
1618 /* sym_offsets: parse user's offsets to internal form*/
1619 NULL /* next: pointer to next struct sym_fns */
1620};
1621
1622void
1623_initialize_os9kread ()
1624{
1625 add_symtab_fns(&os9k_sym_fns);
1626}
This page took 0.082462 seconds and 4 git commands to generate.