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