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