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