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