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