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