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